18 #ifndef __itkPSMEntropyModelFilter_h 19 #define __itkPSMEntropyModelFilter_h 21 #include "itkInPlaceImageFilter.h" 22 #include "itkPSMParticleSystem.h" 23 #include "itkPSMImplicitSurfaceDomain.h" 24 #include "itkPSMShapeEntropyFunction.h" 25 #include "itkPSMParticleEntropyFunction.h" 26 #include "itkPSMGradientDescentOptimizer.h" 27 #include "itkPSMContainerArrayAttribute.h" 29 #include "itkPSMSurfaceNeighborhood.h" 30 #include "itkPSMTwoCostFunction.h" 31 #include "itkCommand.h" 77 template <
class TImage,
class TShapeMatrix = PSMShapeMatrixAttribute<
double, TImage::ImageDimension> >
79 :
public InPlaceImageFilter<TImage,TImage>
84 typedef InPlaceImageFilter<TImage,TImage> Superclass;
85 typedef SmartPointer<Self> Pointer;
86 typedef SmartPointer<const Self> ConstPointer;
89 itkStaticConstMacro(Dimension,
unsigned int, TImage::ImageDimension);
96 typedef typename ShapeMatrixType::Pointer ShapeMatrixPointerType;
116 vnl_vector_fixed<double,Dimension> x;
117 vnl_vector_fixed<double,Dimension> y;
118 vnl_vector_fixed<double,Dimension> z;
132 void SetInput(
const std::string& s, itk::DataObject *o)
134 Superclass::SetInput(s,o);
136 void SetInput(
const TImage *image)
138 this->SetInput(0, image);
140 void SetInput(
unsigned int index,
const TImage * image )
142 if (this->GetNumberOfInputs() < index+1)
144 this->SetNumberOfRequiredInputs(index+1);
147 this->ProcessObject::SetNthInput(index, const_cast< TImage *>( image ) );
168 m_NumberOfScales = n;
169 if (m_Tolerances.size() < n)
171 m_Tolerances.resize(n);
173 if (m_MaximumNumberOfIterations.size() < n)
175 m_MaximumNumberOfIterations.resize(n);
177 if (m_RegularizationInitial.size() < n)
179 m_RegularizationInitial.resize(n);
181 if (m_RegularizationFinal.size() < n)
183 m_RegularizationFinal.resize(n);
185 if (m_RegularizationDecaySpan.size() < n)
187 m_RegularizationDecaySpan.resize(n);
191 itkGetMacro(NumberOfScales,
unsigned int);
192 itkSetMacro(CurrentScale,
unsigned int);
193 itkGetMacro(CurrentScale,
unsigned int);
204 if (m_InputCorrespondencePoints.size() < (index+1))
206 m_InputCorrespondencePoints.resize(index+1);
208 m_InputCorrespondencePoints[index] = corr;
212 itkGetObjectMacro(ParticleSystem, ParticleSystemType);
213 itkGetConstObjectMacro(ParticleSystem, ParticleSystemType);
222 return m_ParticleEntropyFunction;
231 return m_ShapeEntropyFunction;
235 itkGetObjectMacro(Optimizer, OptimizerType);
236 itkGetConstObjectMacro(Optimizer, OptimizerType);
245 m_MaximumNumberOfIterations = n;
247 void SetMaximumNumberOfIterations(
unsigned int n,
unsigned int i = 0)
250 if (m_MaximumNumberOfIterations.size() < i+1)
252 itkExceptionMacro(
"Specified scale does not exist. Call SetNumberOfScales before SetMaximumNumberOfIterations");
254 m_MaximumNumberOfIterations[i] = n;
256 if (m_CurrentScale == i)
258 m_Optimizer->SetMaximumNumberOfIterations(n);
262 unsigned int GetMaximumNumberOfIterations(
unsigned int i = 0)
const 264 if (m_MaximumNumberOfIterations.size() < i+1)
266 itkExceptionMacro(
"Specified scale does not exist.");
268 return m_MaximumNumberOfIterations[i];
276 return m_Optimizer->GetNumberOfIterations();
282 itkGetMacro(Initialized,
bool);
289 itkGetMacro(Initializing,
bool);
290 itkSetMacro(Initializing,
bool);
301 m_CostFunction->SetRelativeGradientScaling(w);
303 double GetShapeEntropyWeighting()
const 305 return m_CostFunction->GetRelativeGradientScaling();
344 return m_ShapeEntropyFunction->GetShapePCAVariances();
369 if (v.size() != m_RegularizationInitial.size())
371 itkExceptionMacro(
"Number of variables does not match number of scales. Call SetNumberOfScales first.");
373 m_RegularizationInitial = v;
375 void SetRegularizationInitial(
double t,
unsigned int i=0)
378 if (m_RegularizationInitial.size() < i+1)
380 itkExceptionMacro(
"Specified scale does not exist. Call SetNumberOfScales before SetTolerance");
382 m_RegularizationInitial[i] = t;
384 if (m_CurrentScale == i)
386 m_Optimizer->SetTolerance(t);
389 double GetRegularizationInitial(
unsigned int i=0)
const 391 if (m_RegularizationInitial.size() < i+1)
393 itkExceptionMacro(
"Specified scale does not exist");
395 else return m_RegularizationInitial[i];
397 void SetRegularizationFinal(
const std::vector<double> &v)
399 if (v.size() != m_RegularizationFinal.size())
401 itkExceptionMacro(
"Number of variables does not match number of scales. Call SetNumberOfScales first.");
403 m_RegularizationFinal = v;
405 void SetRegularizationFinal(
double t,
unsigned int i=0)
408 if (m_RegularizationFinal.size() < i+1)
410 itkExceptionMacro(
"Specified scale does not exist. Call SetNumberOfScales before SetTolerance");
412 m_RegularizationFinal[i] = t;
414 if (m_CurrentScale == i)
416 m_Optimizer->SetTolerance(t);
419 double GetRegularizationFinal(
unsigned int i=0)
const 421 if (m_RegularizationFinal.size() < i+1)
423 itkExceptionMacro(
"Specified scale does not exist");
425 else return m_RegularizationFinal[i];
427 void SetRegularizationDecaySpan(
const std::vector<double> &v)
429 if (v.size() != m_RegularizationDecaySpan.size())
431 itkExceptionMacro(
"Number of variables does not match number of scales. Call SetNumberOfScales first.");
433 m_RegularizationDecaySpan = v;
435 void SetRegularizationDecaySpan(
double t,
unsigned int i=0)
438 if (m_RegularizationDecaySpan.size() < i+1)
440 itkExceptionMacro(
"Specified scale does not exist. Call SetNumberOfScales before SetTolerance");
442 m_RegularizationDecaySpan[i] = t;
444 if (m_CurrentScale == i)
446 m_Optimizer->SetTolerance(t);
449 double GetRegularizationDecaySpan(
unsigned int i=0)
const 451 if (m_RegularizationDecaySpan.size() < i+1)
453 itkExceptionMacro(
"Specified scale does not exist");
455 else return m_RegularizationDecaySpan[i];
463 m_ShapeEntropyFunction->SetMinimumVariance(r);
465 void SetMinimumVariance(
double r)
467 m_ShapeEntropyFunction->SetMinimumVariance(r);
469 double GetRegularizationConstant()
const 471 return m_ShapeEntropyFunction->GetMinimumVariance();
473 double GetMinimumVariance()
const 475 return m_ShapeEntropyFunction->GetMinimumVariance();
488 if (v.size() != m_Tolerances.size())
490 itkExceptionMacro(
"Number of variables does not match number of scales. Call SetNumberOfScales first.");
494 void SetTolerance(
double t,
unsigned int i = 0)
497 if (m_Tolerances.size() < i+1)
499 itkExceptionMacro(
"Specified scale does not exist. Call SetNumberOfScales before SetTolerance");
503 if (m_CurrentScale == i)
505 m_Optimizer->SetTolerance(t);
508 double GetTolerance(
unsigned int i = 0)
const 510 if (m_Tolerances.size() > i)
512 return m_Tolerances[i];
516 itkExceptionMacro(
"Specified scale does not exist.");
525 itkGetMacro(ShapeMatrix, ShapeMatrixPointerType);
526 const ShapeMatrixType *GetShapeMatrix()
const 528 return m_ShapeMatrix;
534 bool CreateSingleCorrespondence();
539 void SetDomainName(
const std::string &s,
unsigned int i);
544 unsigned int GetDomainIndexByName(
const std::string &name);
548 void AddCuttingPlane(
const vnl_vector_fixed<double,3> &x,
549 const vnl_vector_fixed<double,3> &y,
550 const vnl_vector_fixed<double,3> &z,
551 unsigned int domain);
552 void AddCuttingPlane(
const vnl_vector_fixed<double,3> &x,
553 const vnl_vector_fixed<double,3> &y,
554 const vnl_vector_fixed<double,3> &z,
555 const std::string &s)
557 this->AddCuttingPlane(x,y,z,this->GetDomainIndexByName(s));
564 void PrintSelf(std::ostream& os, Indent indent)
const 566 Superclass::PrintSelf(os, indent);
575 virtual void AllocateDataCaches();
580 virtual void AllocateWorkingImages();
585 virtual void AllocateDomainsAndNeighborhoods();
590 void InitializeCorrespondences();
595 itkSetMacro(Initialized,
bool);
599 void OptimizerIterateCallback(Object *,
const EventObject &);
604 typename ImageType::PixelType, Dimension>::Pointer
607 return this->GetDomain(this->GetDomainIndexByName(name));
612 typename ImageType::PixelType, Dimension>::Pointer
615 if (i >= m_DomainList.size())
616 { itkExceptionMacro(
"Requested domain not available"); }
617 return m_DomainList[i];
622 void operator=(
const Self&);
624 std::vector<typename TImage::Pointer> m_WorkingImages;
625 typename OptimizerType::Pointer m_Optimizer;
628 std::vector<unsigned int> m_MaximumNumberOfIterations;
634 std::vector<double> m_RegularizationInitial;
635 std::vector<double> m_RegularizationFinal;
636 std::vector<double> m_RegularizationDecaySpan;
653 virtual void InitializeOptimizationFunctions();
666 m_ParticleEntropyFunction;
674 ShapeMatrixPointerType m_ShapeMatrix;
678 typename itk::MemberCommand< PSMEntropyModelFilter<TImage,TShapeMatrix> >
679 ::Pointer m_IterateCallback;
682 typename ParticleSystemType::Pointer m_ParticleSystem;
687 std::vector<std::vector<PointType> > m_InputCorrespondencePoints;
691 std::vector<std::string> m_DomainListNames;
695 typename ImageType::PixelType, Dimension>::Pointer> m_DomainList;
699 std::vector<typename PSMSurfaceNeighborhood<ImageType>::Pointer> m_NeighborhoodList;
703 unsigned int m_NumberOfScales;
708 unsigned int m_CurrentScale;
712 std::vector<double> m_Tolerances;
715 std::vector<CuttingPlaneType> m_CuttingPlanes;
720 #ifndef ITK_MANUAL_INSTANTIATION 721 #include "itkPSMEntropyModelFilter.hxx" PSMImplicitSurfaceDomain< typename ImageType::PixelType, Dimension >::Pointer & GetDomain(unsigned int i)
PSMShapeEntropyFunction< Dimension > * ShapeEntropyFunction()
void SetMaximumNumberOfIterations(const std::vector< unsigned int > &n)
TShapeMatrix ShapeMatrixType
void SetNumberOfScales(unsigned int n)
unsigned int GetNumberOfElapsedIterations() const
PSMParticleSystem< Dimension > ParticleSystemType
PSMEntropyModelFilter Self
void SetShapeEntropyWeighting(double w)
PSMGradientDescentOptimizer< typename ImageType::PixelType, Dimension > OptimizerType
void SetInputCorrespondencePoints(unsigned int index, const std::vector< PointType > &corr)
ImageType::PointType PointType
PSMImplicitSurfaceDomain< typename ImageType::PixelType, Dimension >::Pointer & GetDomainByName(const std::string &name)
const std::vector< double > & GetShapePCAVariances() const
void SetRegularizationInitial(const std::vector< double > &v)
A facade class that manages interactions with a particle system.
void SetInput(const std::string &s, itk::DataObject *o)
void SetRegularizationConstant(double r)
This the most basic of all PSM model optimization filters. This filter assembles all of the necessary...
PSMParticleEntropyFunction< typename ImageType::PixelType, Dimension > * GetParticleEntropyFunction()
void SetTolerance(const std::vector< double > &v)