1 #include "bbPackRecalageTransform3D2PointsBox.h"
2 #include "bbPackRecalagePackage.h"
3 namespace bbPackRecalage
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,Transform3D2PointsBox)
7 BBTK_BLACK_BOX_IMPLEMENTATION(Transform3D2PointsBox,bbtk::AtomicBlackBox);
8 void Transform3D2PointsBox::Process()
10 if(!bbGetInputInX1().empty() && bbGetInputInX1().size() >= 2 && !bbGetInputInX2().empty() && bbGetInputInX2().size() >= 2)
18 //In case there is an order in the points
19 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)
22 for(i = 0; i < 2; i++)
24 if(bbGetInputLabels1()[i].compare("1") == 0)
26 O1[0] = bbGetInputInX1()[i];
27 O1[1] = bbGetInputInY1()[i];
28 O1[2] = bbGetInputInZ1()[i];
30 else if(bbGetInputLabels1()[i].compare("2") == 0)
32 A1[0] = bbGetInputInX1()[i];
33 A1[1] = bbGetInputInY1()[i];
34 A1[2] = bbGetInputInZ1()[i];
37 for(i = 0; i < 2; i++)
39 if(bbGetInputLabels2()[i].compare("1") == 0)
41 O2[0] = bbGetInputInX2()[i];
42 O2[1] = bbGetInputInY2()[i];
43 O2[2] = bbGetInputInZ2()[i];
45 else if(bbGetInputLabels2()[i].compare("2") == 0)
47 A2[0] = bbGetInputInX2()[i];
48 A2[1] = bbGetInputInY2()[i];
49 A2[2] = bbGetInputInZ2()[i];
55 O1[0] = bbGetInputInX1()[0];
56 O1[1] = bbGetInputInY1()[0];
57 O1[2] = bbGetInputInZ1()[0];
59 A1[0] = bbGetInputInX1()[1];
60 A1[1] = bbGetInputInY1()[1];
61 A1[2] = bbGetInputInZ1()[1];
63 O2[0] = bbGetInputInX2()[0];
64 O2[1] = bbGetInputInY2()[0];
65 O2[2] = bbGetInputInZ2()[0];
67 A2[0] = bbGetInputInX2()[1];
68 A2[1] = bbGetInputInY2()[1];
69 A2[2] = bbGetInputInZ2()[1];
72 //Create the new center point
74 centerPoint = new double[3];
76 centerPoint[0] = O2[0];
77 centerPoint[1] = O2[1];
78 centerPoint[2] = O2[2];
80 transformer->SetFirstTranslation(centerPoint);
82 centerPoint[0] = O1[0];
83 centerPoint[1] = O1[1];
84 centerPoint[2] = O1[2];
86 transformer->SetSecondTranslation(centerPoint);
88 //Create the first vector
90 vector1 = planes->makeVector(O1, A1);
92 //create the second vector
94 vector2 = planes->makeVector(O2, A2);
97 double* axis = planes->getCrossProduct(vector2, vector1);
100 axis = planes->getNormal(axis);
102 //Normalize the 2 vectors for calculating the dot product
103 vector1 = planes->getNormal(vector1);
104 vector2 = planes->getNormal(vector2);
107 double angle = planes->getDotProduct(vector2, vector1);
109 //Convert the dot product to radians
112 //Convert from Radians to Degrees (necesary for the transformation)
113 angle = vtkMath::DegreesFromRadians(angle);
115 //Set the cross product and dot product of the first rotation
116 transformer->SetRotationAxis(axis);
117 transformer->SetAngle(angle);
119 //Sets the second rotation axis (defined by the first vector) and the second angle as input
120 transformer->SetSecondRotationAxis(vector1);
121 transformer->SetSecondAngle(bbGetInputSecondAngle());
123 // The calculation of the transformations are made
126 // We get the results of transformer and set it as result of this box
127 bbSetOutputOut( transformer->GetResult() );
131 bbSetOutputOut( NULL );
134 void Transform3D2PointsBox::bbUserSetDefaultValues()
136 std::vector<int> empty;
137 std::vector<std::string> emptyString;
138 bbSetInputInX1(empty);
139 bbSetInputInY1(empty);
140 bbSetInputInZ1(empty);
141 bbSetInputInX2(empty);
142 bbSetInputInY2(empty);
143 bbSetInputInZ2(empty);
144 bbSetInputLabels1(emptyString);
145 bbSetInputLabels2(emptyString);
146 bbSetInputSecondAngle(0);
147 bbSetOutputOut(NULL);
149 void Transform3D2PointsBox::bbUserInitializeProcessing()
151 //We initialize the transformer
152 transformer=new Transformer3D();
154 //We initialize the plane operator
155 planes=new PlanesOperations();
157 void Transform3D2PointsBox::bbUserFinalizeProcessing()
159 //We delete the transformer
162 //We delete the plane operator
166 // EO namespace bbPackRecalage