Shapeworks Studio  2.1
Shape analysis software suite
itkPSMProcrustesFunction.h
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkPSMProcrustesFunction_h
19 #define __itkPSMProcrustesFunction_h
20 
21 #include <vector>
22 #include <vnl/vnl_matrix.h>
23 #include <vnl/vnl_vector_fixed.h>
24 #include <vnl/vnl_matrix_fixed.h>
25 #include "itkSmartPointer.h"
26 #include "itkMacro.h"
27 #include "itkObject.h"
28 #include "itkObjectFactory.h"
29 #include "itkPoint.h"
30 
31 namespace itk
32 {
33 
42 template <unsigned int VDimension>
43 class ITK_EXPORT PSMProcrustesFunction : public itk::Object
44 {
47  struct SimilarityTransform3D
48  {
49  vnl_matrix_fixed<double, VDimension, VDimension> rotation;
50  double scale;
51  vnl_vector_fixed<double, VDimension> translation;
52  };
53 
54 public:
55  typedef double RealType;
56  typedef vnl_vector_fixed<double, VDimension> PointType;
57  typedef std::vector<PointType> ShapeType;
58  typedef typename ShapeType::iterator ShapeIteratorType;
59  typedef std::vector<ShapeType> ShapeListType;
60  typedef typename ShapeListType::iterator ShapeListIteratorType;
61  typedef std::vector<SimilarityTransform3D> SimilarityTransformListType;
62  typedef typename SimilarityTransformListType::iterator SimilarityTransformListIteratorType;
63 
66  typedef Object Superclass;
67  typedef SmartPointer< Self > Pointer;
68  typedef SmartPointer< const Self > ConstPointer;
69 
71  itkNewMacro(Self);
72 
74  itkTypeMacro(PSMProcrustesFunction, Object);
75 
77  void RunGeneralizedProcrustes(SimilarityTransformListType & transform,
78  ShapeListType & shapes);
79 
83  RealType ComputeSumOfSquares(ShapeListType & shapes);
84 
86  ShapeType TransformShape(ShapeType shape, SimilarityTransform3D & transform);
87 
88 private:
90  bool CheckDegenerateCase(PointType ssqShape, PointType ssqMean, PointType muShape,
91  PointType muMean, int rows);
92 
94  void LeaveOneOutMean(ShapeType & mean, ShapeListType & shapeList,
95  ShapeListIteratorType & leaveOutIt);
96 
99  ShapeType RunProcrustes(SimilarityTransform3D & transform, ShapeType mean,
100  ShapeListIteratorType & leaveOutIt);
101 };
102 } // end namespace itk
103 #endif
Generalized Procrustes Analysis is the rigid registration between different input shapes represented ...