1 #include "bbPackRecalagePlaneReorientationBox.h"
2 #include "bbPackRecalagePackage.h"
3 namespace bbPackRecalage
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,PlaneReorientationBox)
7 BBTK_BLACK_BOX_IMPLEMENTATION(PlaneReorientationBox,bbtk::AtomicBlackBox);
8 void PlaneReorientationBox::Process()
10 if(!bbGetInputInX().empty() && bbGetInputInX().size() == 3 && !bbGetInputInY().empty() && bbGetInputInY().size() == 3 && !bbGetInputInZ().empty() && bbGetInputInZ().size() == 3)
15 a[0] = bbGetInputInX()[1]-bbGetInputInX()[0];
16 a[1] = bbGetInputInY()[1]-bbGetInputInY()[0];
17 a[2] = bbGetInputInZ()[1]-bbGetInputInZ()[0];
22 b[0] = bbGetInputInX()[2]-bbGetInputInX()[0];
23 b[1] = bbGetInputInY()[2]-bbGetInputInY()[0];
24 b[2] = bbGetInputInZ()[2]-bbGetInputInZ()[0];
28 normal[0]=(a[1]*b[2])-(a[2]*b[1]);
29 normal[1]=(a[2]*b[0])-(a[0]*b[2]);
30 normal[2]=(a[0]*b[1])-(a[1]*b[0]);
32 vtkMath::Normalize(normal);
34 std::cout << "Normal axis : " << "X: " << normal[0] << " Y: " << normal[1] << " Z: " << normal[2] << std::endl;
36 /*Unitary Vector in Y*/
42 /*Unitary Vector in X*/
48 /*Normal vector without its z factor*/
50 normalZ[0] = normal[0];
51 normalZ[1] = normal[1];
54 /*Normal vector without its y factor*/
56 normalY[0] = normal[0];
58 normalY[2] = normal[2];
60 /*Angle for the rotation in Z*/
61 double angleZ = acos(vtkMath::Dot(normalZ,y)/vtkMath::Norm(normalZ));
63 /*Angle for the rotation in Y*/
64 double angleY = acos(vtkMath::Dot(x,normalY)/vtkMath::Norm(normalY));
66 /*Convert from Radians to Degrees*/
67 angleZ = vtkMath::DegreesFromRadians(angleZ);
68 angleY = vtkMath::DegreesFromRadians(angleY);
69 std::cout << "Angle for Z: " << angleZ << std::endl;
70 std::cout << "Angle for Y: " << angleY << std::endl;
72 transform->Identity();
75 transform->RotateWXYZ(angleZ,0,0,1);
79 transform->RotateWXYZ(angleZ,0,0,-1);
83 transform->RotateWXYZ(angleY,0,1,0);
87 if(angleY != 180){transform->RotateWXYZ(angleY,0,-1,0);}
89 //transform->Translate(bbGetInputCenterPoint()[0],bbGetInputCenterPoint()[1],bbGetInputCenterPoint()[2]);
92 /*Set output and pray to god that it works :P*/
93 bbSetOutputOut(transform);
97 transform->Identity();
99 bbSetOutputOut(transform);
102 void PlaneReorientationBox::bbUserSetDefaultValues()
104 std::vector<int> nullVector;
105 bbSetInputInX(nullVector);
106 bbSetInputInY(nullVector);
107 bbSetInputInZ(nullVector);
109 void PlaneReorientationBox::bbUserInitializeProcessing()
111 transform = vtkTransform::New();
113 void PlaneReorientationBox::bbUserFinalizeProcessing()
118 // EO namespace bbPackRecalage