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 //pojedyncza zaczytana wartosc
80 //clitk::skipComment(is);
83 //typ piksela - bo wykorzystujemy strukture itk::Image
84 typedef unsigned char PixelType;
90 //Ddefinicja typu obrazu: zawiera rozmiar danych, typ piksela
92 unsigned int Dimension_temp = (unsigned int)x;
96 if (Dimension_temp==2)
98 const unsigned int Dimension = 2;
99 typedef itk::Image< PixelType, Dimension > ImageType;
100 typedef float VectorComponentType;
101 typedef itk::Vector< VectorComponentType, Dimension > VectorType;
102 //Typ LandmarkBasedTransormInitializer
103 typedef itk::Rigid2DTransform< double > Rigid2DTransformType;
104 typedef itk::LandmarkBasedTransformInitializer< Rigid2DTransformType,ImageType, ImageType>
105 LandmarkBasedTransformInitializerType;
107 LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
109 // Create source and target landmarks.
110 typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer LandmarkContainerType;
111 typedef LandmarkBasedTransformInitializerType::LandmarkPointType LandmarkPointType;
113 //bufory na zaczyt wspolrzedncyh
114 LandmarkContainerType imageLandmarks;
115 LandmarkContainerType trackerLandmarks;
117 //bufory na pojedyncze punkty
118 LandmarkPointType imagePoint; // dane z CT
119 LandmarkPointType trackerPoint; //dane z tracking system
124 while (is && !is.eof()) {
126 is >> trackerPoint[1];
127 //is >> trackerPoint[2];
131 //is >> imagePoint[2];
133 imageLandmarks.push_back(imagePoint );
134 trackerLandmarks.push_back(trackerPoint );
142 landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
143 landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
145 Rigid2DTransformType::Pointer transform = Rigid2DTransformType::New();
147 transform->SetIdentity();
149 // Versor rotacji i macierz translacji
150 landmarkBasedTransformInitializer->SetTransform(transform);
151 landmarkBasedTransformInitializer->InitializeTransform();
153 Rigid2DTransformType::MatrixType matrix = transform->GetMatrix();
154 Rigid2DTransformType::OffsetType offset = transform->GetOffset();
158 clitk::openFileForWriting(out, args_info.output_arg);
160 out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << offset[0] << std::endl;
161 out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << offset[1] << std::endl;
162 out << 0.0 << ' ' << 0.0 << ' ' << 1.0;
167 else if (Dimension_temp==3)
170 std::cout << "to ja";
171 const unsigned int Dimension = 3;
172 typedef itk::Image< PixelType, Dimension > ImageType;
173 typedef float VectorComponentType;
174 typedef itk::Vector< VectorComponentType, Dimension > VectorType;
175 //Typ LandmarkBasedTransormInitializer
176 typedef itk::VersorRigid3DTransform< double > Rigid3DTransformType;
177 typedef itk::LandmarkBasedTransformInitializer< Rigid3DTransformType,ImageType, ImageType>
178 LandmarkBasedTransformInitializerType;
180 LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
182 // Create source and target landmarks.
183 typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer LandmarkContainerType;
184 typedef LandmarkBasedTransformInitializerType::LandmarkPointType LandmarkPointType;
186 //bufory na zaczyt wspolrzedncyh
187 LandmarkContainerType imageLandmarks;
188 LandmarkContainerType trackerLandmarks;
190 //bufory na pojedyncze punkty
191 LandmarkPointType imagePoint; // dane z CT
192 LandmarkPointType trackerPoint; //dane z tracking system
196 while (is && !is.eof()) {
198 is >> trackerPoint[1];
199 is >> trackerPoint[2];
205 imageLandmarks.push_back(imagePoint );
206 trackerLandmarks.push_back(trackerPoint );
213 landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
214 landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
216 Rigid3DTransformType::Pointer transform = Rigid3DTransformType::New();
218 transform->SetIdentity();
220 // Versor rotacji i macierz translacji
221 landmarkBasedTransformInitializer->SetTransform(transform);
222 landmarkBasedTransformInitializer->InitializeTransform();
224 Rigid3DTransformType::MatrixType matrix = transform->GetMatrix();
225 Rigid3DTransformType::OffsetType offset = transform->GetOffset();
229 clitk::openFileForWriting(out, args_info.output_arg);
231 out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << matrix[0][2] << ' '<< offset[0] << std::endl;
232 out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << matrix[1][2] << ' '<< offset[1] << std::endl;
233 out << matrix[2][0] << ' ' << matrix[2][1] << ' ' << matrix[2][2] << ' '<< offset[2] << std::endl;
234 out << 0.0 << ' ' << 0.0 << ' ' << 0.0 << ' ' << 1.0;
253 //--------------------------------------------------------------------