1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 /* =================================================
20 * @file clitkPointRigidRegistrationGenericFilter.txx
21 * @author xxx <xxx@creatis.insa-lyon.fr>
24 * @brief PointRigidRegistration an image
26 ===================================================*/
29 #include "clitkPointRigidRegistration_ggo.h"
30 #include "clitkPointRigidRegistrationGenericFilter.h"
32 //paste from RigidRegistration
33 #include "itkImageFileReader.h"
34 #include "itkImageFileWriter.h"
36 #include "itkVector.h"
37 #include "itkResampleImageFilter.h"
38 #include "itkLandmarkBasedTransformInitializer.h"
39 #include "itkRigid2DTransform.h"
40 #include "itkVersorRigid3DTransform.h"
43 //paste from /home/dspinczyk/dev/clitk_superbuild_Agata/Source/clitk/common/clitkTransformUtilities.h
44 #include "itkMatrix.h"
47 #include "clitkImageCommon.h"
48 #include "clitkCommon.h"
49 //#define VTK_EXCLUDE_STRSTREAM_HEADERS
50 #include <vtkMatrix4x4.h>
51 #include <vtkSmartPointer.h>
53 //for open file for reading
55 #include "clitkImageCommon.h"
56 #include "clitkCommon.h"
59 //--------------------------------------------------------------------
60 int main(int argc, char * argv[])
64 GGO(clitkPointRigidRegistration, args_info);
72 //open stream to reading
74 clitk::openFileForReading(is, args_info.input_arg);
78 //reading first line of input file to chck thw dimension of data
80 //clitk::skipComment(is);
83 typedef unsigned char PixelType;
89 unsigned int Dimension_temp = (unsigned int)x;
93 if (Dimension_temp==2)
95 const unsigned int Dimension = 2;
96 typedef itk::Image< PixelType, Dimension > ImageType;
97 typedef float VectorComponentType;
98 typedef itk::Vector< VectorComponentType, Dimension > VectorType;
99 //Typ LandmarkBasedTransormInitializer
100 typedef itk::Rigid2DTransform< double > Rigid2DTransformType;
101 typedef itk::LandmarkBasedTransformInitializer< Rigid2DTransformType,ImageType, ImageType>
102 LandmarkBasedTransformInitializerType;
104 LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
106 // Create source and target landmarks.
107 typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer LandmarkContainerType;
108 typedef LandmarkBasedTransformInitializerType::LandmarkPointType LandmarkPointType;
110 LandmarkContainerType imageLandmarks;
111 LandmarkContainerType trackerLandmarks;
113 LandmarkPointType imagePoint;
114 LandmarkPointType trackerPoint;
119 while (is && !is.eof()) {
121 is >> trackerPoint[1];
127 imageLandmarks.push_back(imagePoint );
128 trackerLandmarks.push_back(trackerPoint );
136 landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
137 landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
139 Rigid2DTransformType::Pointer transform = Rigid2DTransformType::New();
141 transform->SetIdentity();
143 landmarkBasedTransformInitializer->SetTransform(transform);
144 landmarkBasedTransformInitializer->InitializeTransform();
146 Rigid2DTransformType::MatrixType matrix = transform->GetMatrix();
147 Rigid2DTransformType::OffsetType offset = transform->GetOffset();
151 clitk::openFileForWriting(out, args_info.output_arg);
153 out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << offset[0] << std::endl;
154 out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << offset[1] << std::endl;
155 out << 0.0 << ' ' << 0.0 << ' ' << 1.0;
160 else if (Dimension_temp==3)
163 const unsigned int Dimension = 3;
164 typedef itk::Image< PixelType, Dimension > ImageType;
165 typedef float VectorComponentType;
166 typedef itk::Vector< VectorComponentType, Dimension > VectorType;
167 //Typ LandmarkBasedTransormInitializer
168 typedef itk::VersorRigid3DTransform< double > Rigid3DTransformType;
169 typedef itk::LandmarkBasedTransformInitializer< Rigid3DTransformType,ImageType, ImageType>
170 LandmarkBasedTransformInitializerType;
172 LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
174 // Create source and target landmarks.
175 typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer LandmarkContainerType;
176 typedef LandmarkBasedTransformInitializerType::LandmarkPointType LandmarkPointType;
178 LandmarkContainerType imageLandmarks;
179 LandmarkContainerType trackerLandmarks;
181 LandmarkPointType imagePoint;
182 LandmarkPointType trackerPoint;
186 while (is && !is.eof()) {
188 is >> trackerPoint[1];
189 is >> trackerPoint[2];
195 imageLandmarks.push_back(imagePoint );
196 trackerLandmarks.push_back(trackerPoint );
203 landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
204 landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
206 Rigid3DTransformType::Pointer transform = Rigid3DTransformType::New();
208 transform->SetIdentity();
210 landmarkBasedTransformInitializer->SetTransform(transform);
211 landmarkBasedTransformInitializer->InitializeTransform();
213 Rigid3DTransformType::MatrixType matrix = transform->GetMatrix();
214 Rigid3DTransformType::OffsetType offset = transform->GetOffset();
218 clitk::openFileForWriting(out, args_info.output_arg);
220 out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << matrix[0][2] << ' '<< offset[0] << std::endl;
221 out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << matrix[1][2] << ' '<< offset[1] << std::endl;
222 out << matrix[2][0] << ' ' << matrix[2][1] << ' ' << matrix[2][2] << ' '<< offset[2] << std::endl;
223 out << 0.0 << ' ' << 0.0 << ' ' << 0.0 << ' ' << 1.0;
242 //--------------------------------------------------------------------