ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMeshProcrustesAlignFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
19#ifndef itkMeshProcrustesAlignFilter_h
20#define itkMeshProcrustesAlignFilter_h
21
22#include "itkMacro.h"
23#include "itkProcessObject.h"
24#include "itkAffineTransform.h"
26
27#include "vnl/vnl_matrix.h"
28
29#include <fstream>
30
31namespace itk
32{
61template <class TInputMesh, class TOutputMesh>
62class ITK_TEMPLATE_EXPORT MeshProcrustesAlignFilter : public ProcessObject
63{
64
65public:
71
73 typedef TInputMesh InputMeshType;
74 typedef TOutputMesh OutputMeshType;
75 typedef typename InputMeshType::Pointer InputMeshPointer;
76 typedef typename OutputMeshType::Pointer OutputMeshPointer;
77 typedef typename InputMeshType::PointType InputPointType;
78 typedef typename OutputMeshType::PointType OutputPointType;
79 typedef typename OutputMeshType::PointsContainer OutputPointsContainer;
80 typedef typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer;
82 typedef typename OutputPointType::ValueType CoordinateType;
84 typedef vnl_matrix<CoordinateType> MatrixType;
89 typedef std::vector<TransformMeshPointer> TransformMeshArray;
92
94 itkNewMacro(Self);
95
97 itkOverrideGetNameOfClassMacro(MeshProcrustesAlignFilter);
98
102 void
103 SetNumberOfInputs(unsigned int num);
104
106
108 void
109 SetInput(unsigned int idx, InputMeshType * mesh);
110
113 GetInput(unsigned int idx)
114 {
115 return static_cast<InputMeshType *>(this->ProcessObject::GetInput(idx));
116 }
117
119 OutputMeshType *
120 GetOutput(unsigned int idx);
121
123 itkGetConstObjectMacro(Mean, OutputMeshType);
124
127 GetTransform(unsigned int idx)
128 {
129 return m_MeshTransform[idx]->GetModifiableTransform();
130 }
131
132 // bp2009
133 TranslationType
135 {
136 TranslationType rotationXYZ = transform->GetTranslation();
137 RotationType rotation = transform->GetMatrix();
138 double rotX, cosY, rotY, rotZ;
139
140 rotY = (-1) * (asin(rotation(0, 2))); // C++ functions need radians
141 rotY = rotY / itk::Math::pi_over_180; // I should have degrees here
142 cosY = cos(rotY / itk::Math::pi_over_180); // I have radians here
143 rotX = acos((rotation(2, 2)) / cosY);
144 rotX = rotX / itk::Math::pi_over_180; // I should have degrees here
145 rotZ = acos((rotation(0, 0)) / cosY);
146 rotZ = rotZ / itk::Math::pi_over_180; // I should have degrees here
147 // std::cout << rotX << std::endl;
148 // std::cout << rotY << std::endl;
149 // std::cout << rotZ << std::endl;
150
151 rotationXYZ.SetElement(0, rotX);
152 rotationXYZ.SetElement(1, rotY);
153 rotationXYZ.SetElement(2, rotZ);
154
155 return rotationXYZ;
156 }
157
159 void
160 PrintTransform(const TransformType * transform)
161 {
162 TranslationType trans = transform->GetTranslation();
163 TranslationType rots = GetRotationDegrees(transform);
164 RotationType rotation = transform->GetMatrix();
165 // std::cout << "Shape " << i << std::endl;
166 std::ofstream output;
167
168 output.open("Transform.info", std::ios::out);
169 output << "ROTATION MATRIX" << std::endl;
170 for (unsigned dim1 = 0; dim1 < 3; dim1++)
171 {
172 for (unsigned dim2 = 0; dim2 < 3; dim2++)
173 {
174 output << "Position " << dim1 << " " << dim2 << " : " << rotation(dim1, dim2) << std::endl;
175 }
176 }
177
178 output << "TRANSLATION VECTOR" << std::endl;
179 for (unsigned dim1 = 0; dim1 < 3; dim1++)
180 {
181 output << "Position " << dim1 << " : " << trans.GetElement(dim1) << std::endl;
182 }
183
184 output << "ROTATION VECTOR" << std::endl;
185 for (unsigned dim1 = 0; dim1 < 3; dim1++)
186 {
187 output << "Position " << dim1 << " : " << rots.GetElement(dim1) << std::endl;
188 }
189
190 output.close();
191 }
192
193 // bp2009
194
199 itkGetConstMacro(Convergence, double);
200 itkSetMacro(Convergence, double);
201
204
207
209 void
211 {
212 this->SetUseScaling(true);
213 }
214
216 void
218 {
219 this->SetUseScaling(false);
220 }
221
223 itkSetMacro(UseScaling, bool);
224 itkGetMacro(UseScaling, bool);
225
227 void
229 {
230 this->SetUseInitialAverage(true);
231 }
232
234 void
236 {
237 this->SetUseInitialAverage(false);
238 }
239
241 itkSetMacro(UseInitialAverage, bool);
242 itkGetMacro(UseInitialAverage, bool);
243
245 void
247 {
248 this->SetUseNormalization(true);
249 }
250
251 void
253 {
254 this->SetUseNormalization(false);
255 }
256
257 itkSetMacro(UseNormalization, bool);
258 itkGetMacro(UseNormalization, bool);
259
261 void
263 {
264 this->SetUseSingleIteration(true);
265 }
266
268 void
270 {
271 this->SetUseSingleIteration(false);
272 }
273
275 itkSetMacro(UseSingleIteration, bool);
276 itkGetMacro(UseSingleIteration, bool);
277
279 void
281 {
282 this->SetAlignRotation(true);
283 }
284
285 void
287 {
288 this->SetAlignRotation(false);
289 }
290
291 itkSetMacro(AlignRotation, bool);
292 itkGetMacro(AlignRotation, bool);
293
294 itkGetConstMacro(MeanPointsDifference, double);
295
296protected:
299
302
304 virtual void
305 GenerateData() override;
306
309 GetMeshCenter(unsigned int idx);
310
312 void
314
320 GetProcrustesMatch(unsigned int idx, OutputMeshType * targetMesh, TranslationType targetCenter);
321
322private:
329 std::vector<TranslationType> m_Center;
340
343
346
349
352
355};
356
357} // namespace itk
358
359#ifndef ITK_MANUAL_INSTANTIATION
360# include "itkMeshProcrustesAlignFilter.hxx"
361#endif
362
363#endif // itkMeshProcrustesAlignFilter
Matrix< double, Self::OutputSpaceDimension, Self::InputSpaceDimension > MatrixType
SmartPointer< Self > Pointer
const_reference GetElement(unsigned int index) const
ITK_GCC_PRAGMA_POP void SetElement(unsigned int index, const_reference value)
const OutputVectorType & GetTranslation() const
virtual const MatrixType & GetMatrix() const
virtual void GenerateData() override
TranslationType GetMeshCenter(unsigned int idx)
vnl_matrix< CoordinateType > MatrixType
TransformPointer GetProcrustesMatch(unsigned int idx, OutputMeshType *targetMesh, TranslationType targetCenter)
TransformMeshFilter< OutputMeshType, OutputMeshType, TransformType > TransformMeshType
OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
TransformType * GetTransform(unsigned int idx)
virtual void SetUseScaling(bool _arg)
AffineTransform< double, 3 > TransformType
TransformMeshType::Pointer TransformMeshPointer
OutputMeshType * GetOutput(unsigned int idx)
TranslationType GetRotationDegrees(const TransformType *transform)
OutputMeshType::PointsContainer OutputPointsContainer
virtual void SetAlignRotation(bool _arg)
void PrintTransform(const TransformType *transform)
std::vector< TransformMeshPointer > TransformMeshArray
InputMeshType * GetInput(unsigned int idx)
std::vector< TranslationType > m_Center
virtual itk::ProcessObject::DataObjectPointer MakeOutput(itk::ProcessObject::DataObjectPointerArraySizeType idx) override
Make a DataObject of the correct type to used as the specified output.
virtual void SetUseInitialAverage(bool _arg)
void SetNumberOfInputs(unsigned int num)
void SetInput(unsigned int idx, InputMeshType *mesh)
virtual void SetUseSingleIteration(bool _arg)
virtual void SetUseNormalization(bool _arg)
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject::Pointer DataObjectPointer
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
Implements transparent reference counting.
TransformMeshFilter applies a transform to all the points of a mesh.
constexpr double pi_over_180
Definition itkMath.h:73
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
#define itkSetMacro(name, type)