2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
27 #include "bbPackRecalageTransform3D2PointsBox.h"
28 #include "bbPackRecalagePackage.h"
29 namespace bbPackRecalage
32 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,Transform3D2PointsBox)
33 BBTK_BLACK_BOX_IMPLEMENTATION(Transform3D2PointsBox,bbtk::AtomicBlackBox);
34 void Transform3D2PointsBox::Process()
36 if(!bbGetInputInX1().empty() && bbGetInputInX1().size() >= 2 && !bbGetInputInX2().empty() && bbGetInputInX2().size() >= 2)
44 //In case there is an order in the points
45 if(!bbGetInputLabels1().empty() && !bbGetInputLabels2().empty() && bbGetInputLabels1()[0].compare("1") == 0 && bbGetInputLabels1()[1].compare("2") == 0 && bbGetInputLabels2()[0].compare("1") == 0 && bbGetInputLabels2()[1].compare("2") == 0)
48 for(i = 0; i < 2; i++)
50 if(bbGetInputLabels1()[i].compare("1") == 0)
52 O1[0] = bbGetInputInX1()[i];
53 O1[1] = bbGetInputInY1()[i];
54 O1[2] = bbGetInputInZ1()[i];
56 else if(bbGetInputLabels1()[i].compare("2") == 0)
58 A1[0] = bbGetInputInX1()[i];
59 A1[1] = bbGetInputInY1()[i];
60 A1[2] = bbGetInputInZ1()[i];
63 for(i = 0; i < 2; i++)
65 if(bbGetInputLabels2()[i].compare("1") == 0)
67 O2[0] = bbGetInputInX2()[i];
68 O2[1] = bbGetInputInY2()[i];
69 O2[2] = bbGetInputInZ2()[i];
71 else if(bbGetInputLabels2()[i].compare("2") == 0)
73 A2[0] = bbGetInputInX2()[i];
74 A2[1] = bbGetInputInY2()[i];
75 A2[2] = bbGetInputInZ2()[i];
81 O1[0] = bbGetInputInX1()[0];
82 O1[1] = bbGetInputInY1()[0];
83 O1[2] = bbGetInputInZ1()[0];
85 A1[0] = bbGetInputInX1()[1];
86 A1[1] = bbGetInputInY1()[1];
87 A1[2] = bbGetInputInZ1()[1];
89 O2[0] = bbGetInputInX2()[0];
90 O2[1] = bbGetInputInY2()[0];
91 O2[2] = bbGetInputInZ2()[0];
93 A2[0] = bbGetInputInX2()[1];
94 A2[1] = bbGetInputInY2()[1];
95 A2[2] = bbGetInputInZ2()[1];
98 //Create the new center point
100 centerPoint = new double[3];
102 centerPoint[0] = O2[0];
103 centerPoint[1] = O2[1];
104 centerPoint[2] = O2[2];
106 transformer->SetFirstTranslation(centerPoint);
108 centerPoint[0] = O1[0];
109 centerPoint[1] = O1[1];
110 centerPoint[2] = O1[2];
112 transformer->SetSecondTranslation(centerPoint);
114 //Create the first vector
116 vector1 = planes->makeVector(O1, A1);
118 //create the second vector
120 vector2 = planes->makeVector(O2, A2);
123 double* axis = planes->getCrossProduct(vector2, vector1);
126 axis = planes->getNormal(axis);
128 //Normalize the 2 vectors for calculating the dot product
129 vector1 = planes->getNormal(vector1);
130 vector2 = planes->getNormal(vector2);
133 double angle = planes->getDotProduct(vector2, vector1);
135 //Convert the dot product to radians
138 //Convert from Radians to Degrees (necesary for the transformation)
139 angle = vtkMath::DegreesFromRadians(angle);
141 //Set the cross product and dot product of the first rotation
142 transformer->SetRotationAxis(axis);
143 transformer->SetAngle(angle);
145 //Sets the second rotation axis (defined by the first vector) and the second angle as input
146 transformer->SetSecondRotationAxis(vector1);
147 transformer->SetSecondAngle(bbGetInputSecondAngle());
149 // The calculation of the transformations are made
152 // We get the results of transformer and set it as result of this box
153 bbSetOutputOut( transformer->GetResult() );
157 bbSetOutputOut( NULL );
160 void Transform3D2PointsBox::bbUserSetDefaultValues()
162 std::vector<int> empty;
163 std::vector<std::string> emptyString;
164 bbSetInputInX1(empty);
165 bbSetInputInY1(empty);
166 bbSetInputInZ1(empty);
167 bbSetInputInX2(empty);
168 bbSetInputInY2(empty);
169 bbSetInputInZ2(empty);
170 bbSetInputLabels1(emptyString);
171 bbSetInputLabels2(emptyString);
172 bbSetInputSecondAngle(0);
173 bbSetOutputOut(NULL);
175 void Transform3D2PointsBox::bbUserInitializeProcessing()
177 //We initialize the transformer
178 transformer=new Transformer3D();
180 //We initialize the plane operator
181 planes=new PlanesOperations();
183 void Transform3D2PointsBox::bbUserFinalizeProcessing()
185 //We delete the transformer
188 //We delete the plane operator
192 // EO namespace bbPackRecalage