File: itkMeanShiftModeSeekerBase.h

package info (click to toggle)
insighttoolkit 3.18.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 110,432 kB
  • ctags: 74,559
  • sloc: cpp: 412,627; ansic: 196,210; fortran: 28,000; python: 3,852; tcl: 2,005; sh: 1,186; java: 583; makefile: 458; csh: 220; perl: 193; xml: 20
file content (135 lines) | stat: -rw-r--r-- 4,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkMeanShiftModeSeekerBase.h,v $
  Language:  C++
  Date:      $Date: 2009-03-04 15:24:01 $
  Version:   $Revision: 1.10 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#ifndef __itkMeanShiftModeSeekerBase_h
#define __itkMeanShiftModeSeekerBase_h

#include "itkObject.h"
#include "itkVector.h"
#include "itkMatrix.h"
#include "itkNumericTraits.h"
#include "itkMeanShiftModeCacheMethod.h"

namespace itk { 
namespace Statistics {
  
/** \class MeanShiftModeSeekerBase
 * \brief Evolves the mode. This is the base class for any mean shift
 * mode seeking algorithm classes.
 *
 * Any subclass of this class should implement the ComputeMode
 * method. That is the only one requirement. To use this class, user
 * should plug in the input sample using SetInputSample, then call
 * Evolve function with a measurement vector (query point).
 *
 * There are some operational options. Users can set a cache method to
 * accelates the evolving process. If the cache method already has a
 * pair of a query point and its new mode point, the ComputeMode uses
 * the cached value insteady recalculating the mode. By setting the
 * maximum iteration number (SetMaximumIteration method), when the
 * evolving process exceedes, the process will stop and return the
 * current mode point as the result. With this option turned off (by
 * setting it to 0 or leave it alone after instantiating this class), the
 * evolving process runs until it converges.
 *
 * <b>Recent API changes:</b>
 * The static const macro to get the length of a measurement vector,
 * \c MeasurementVectorSize  has been removed to allow the length of a measurement
 * vector to be specified at run time. It is now obtained at run time from the
 * sample set as input. 
 *
 * \sa MeanShiftModeCacheMethod, SampleMeanShiftBlurringFilter,
 * SampleSelectiveMeanShiftBlurringFilter, SampleMeanShiftClusteringFilter
 */

template< class TSample >
class MeanShiftModeSeekerBase :
    public Object
{
public:
  /** Standard class typedefs. */
  typedef MeanShiftModeSeekerBase  Self;
  typedef Object                   Superclass;
  typedef SmartPointer<Self>       Pointer;
  typedef SmartPointer<const Self> ConstPointer;

  /** Standard Macros */
  itkTypeMacro(MeanShiftModeSeekerBase, Object);
  
  /** Typedefs from the TSample template argument */
  typedef typename TSample::MeasurementVectorType     MeasurementVectorType;
  typedef typename TSample::MeasurementVectorSizeType MeasurementVectorSizeType;
  typedef typename TSample::MeasurementType           MeasurementType;
  typedef typename TSample::InstanceIdentifier        InstanceIdentifier;

  typedef std::vector< InstanceIdentifier >                 SearchResultVectorType;
  typedef MeanShiftModeCacheMethod< MeasurementVectorType > CacheMethodType;

  void SetInputSample(const TSample* sample);

  const TSample* GetInputSample() const
    { return m_InputSample.GetPointer(); }

  void SetMaximumIteration(unsigned int number)
    { m_MaximumIteration = number; }

  unsigned int GetMaximumIteration()
    { return m_MaximumIteration; }

  void SetCacheMethod(CacheMethodType* method);

  CacheMethodType* GetCacheMethod()
    { return m_CacheMethod.GetPointer(); }

  /** Returns the covariance matrix of the target sample data */ 
  MeasurementVectorType Evolve(MeasurementVectorType instance);

  /** Get the length of a measurement vector */
  virtual MeasurementVectorSizeType GetMeasurementVectorSize() const
    {
    if( m_InputSample.GetPointer() )
      {
      return m_InputSample.GetPointer()->GetMeasurementVectorSize();
      }
    else
      {
      return 0;
      }
    }

protected:
  MeanShiftModeSeekerBase();
  virtual ~MeanShiftModeSeekerBase();
  void PrintSelf(std::ostream& os, Indent indent) const;

  virtual bool ComputeMode(MeasurementVectorType queryPoint,
                           MeasurementVectorType& newPoint) = 0;

private:
  typename TSample::ConstPointer    m_InputSample;
  unsigned int                      m_MaximumIteration;
  typename CacheMethodType::Pointer m_CacheMethod;
}; // end of class
    
} // end of namespace Statistics 
} // end of namespace itk 

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkMeanShiftModeSeekerBase.txx"
#endif

#endif