Seg3D  2.4
Seg3D is a free volume segmentation and processing tool developed by the NIH Center for Integrative Biomedical Computing at the University of Utah Scientific Computing and Imaging (SCI) Institute.
optimizer_observer.hxx
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2016 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 #ifndef OPTIMIZER_OBSERVER_HXX_
30 #define OPTIMIZER_OBSERVER_HXX_
31 
32 #include <sstream>
33 
34 // ITK includes:
35 #include <itkCommand.h>
36 
37 #include <Core/Utils/Log.h>
38 
39 
40 //----------------------------------------------------------------
41 // optimizer_observer_t
42 //
43 template <typename TOptimizer>
44 class optimizer_observer_t : public itk::Command
45 {
46 public:
47  typedef optimizer_observer_t Self;
48  typedef itk::Command Superclass;
49  typedef itk::SmartPointer<Self> Pointer;
50 
51  itkNewMacro(Self);
52 
53  void Execute(itk::Object *caller, const itk::EventObject & event)
54  { Execute((const itk::Object *)(caller), event); }
55 
56  void Execute(const itk::Object * object, const itk::EventObject & event)
57  {
58  if (typeid(event) != typeid(itk::IterationEvent)) return;
59 
60  const TOptimizer * optimizer = dynamic_cast<const TOptimizer *>(object);
61  std::ostringstream oss;
62  oss << static_cast<unsigned int>(optimizer->GetCurrentIteration()) << '\t'
63  << optimizer->GetValue() << '\t'
64  << optimizer->GetCurrentPosition() << std::endl;
65  CORE_LOG_MESSAGE(oss.str());
66  }
67 
68 protected:
70 };
71 
72 
73 #endif // OPTIMIZER_OBSERVER_HXX_
Definition: optimizer_observer.hxx:44