]> Creatis software - creaImageIO.git/blob - bbtk_Transform3Ddicom_PKG/src/bbTransform3DdicomRotateDICOM.cxx
#3326 bbtk_Transform3Ddicom_PKG
[creaImageIO.git] / bbtk_Transform3Ddicom_PKG / src / bbTransform3DdicomRotateDICOM.cxx
1 #include "bbTransform3DdicomRotateDICOM.h"\r
2 #include "bbTransform3DdicomPackage.h"\r
3 \r
4 #include <vtkMatrix4x4.h>\r
5 #include <vtkTransform.h>\r
6 \r
7 #include "matrixRotation.h"\r
8 \r
9 namespace bbTransform3Ddicom\r
10 {\r
11 \r
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(Transform3Ddicom,RotateDICOM)\r
13 BBTK_BLACK_BOX_IMPLEMENTATION(RotateDICOM,bbtk::AtomicBlackBox);\r
14 void RotateDICOM::Process()\r
15 {\r
16         vtkTransform* transform1 = vtkTransform::New();\r
17         matrixRotation matrot1;\r
18         if (bbGetInputSpacing1().size()==3)\r
19         {\r
20             matrot1.SetSpacing( bbGetInputSpacing1()[0],bbGetInputSpacing1()[1] ,bbGetInputSpacing1()[2]  );\r
21         }\r
22         if (bbGetInputPosition1().size()==3)\r
23         {\r
24             matrot1.SetOrigin( bbGetInputPosition1()[0],bbGetInputPosition1()[1] ,bbGetInputPosition1()[2]  );\r
25         }\r
26         if ((bbGetInputOrientation1Vec1().size()==3) && (bbGetInputOrientation1Vec2().size()==3) )\r
27         {\r
28             matrot1.SetVector1( bbGetInputOrientation1Vec1()[0],bbGetInputOrientation1Vec1()[1] ,bbGetInputOrientation1Vec1()[2]  );\r
29             matrot1.SetVector2( bbGetInputOrientation1Vec2()[0],bbGetInputOrientation1Vec2()[1] ,bbGetInputOrientation1Vec2()[2]  );\r
30         }\r
31         if ((bbGetInputOrientation1Vec12().size()==6) )\r
32         {\r
33             matrot1.SetVector1( bbGetInputOrientation1Vec12()[0],bbGetInputOrientation1Vec12()[1] ,bbGetInputOrientation1Vec12()[2]  );\r
34             matrot1.SetVector2( bbGetInputOrientation1Vec12()[3],bbGetInputOrientation1Vec12()[4] ,bbGetInputOrientation1Vec12()[5]  );\r
35         }\r
36         matrot1.GetTransformation(transform1);\r
37     \r
38         matrixRotation matrot2;\r
39         if (bbGetInputSpacing2().size()==3)\r
40         {\r
41             matrot2.SetSpacing( bbGetInputSpacing2()[0],bbGetInputSpacing2()[1] ,bbGetInputSpacing2()[2]  );\r
42         }\r
43         if (bbGetInputPosition2().size()==3)\r
44         {\r
45             matrot2.SetOrigin( bbGetInputPosition2()[0],bbGetInputPosition2()[1] ,bbGetInputPosition2()[2]  );\r
46         }\r
47         if ((bbGetInputOrientation2Vec1().size()==3) && (bbGetInputOrientation2Vec2().size()==3) )\r
48         {\r
49             matrot2.SetVector1( bbGetInputOrientation2Vec1()[0],bbGetInputOrientation2Vec1()[1] ,bbGetInputOrientation2Vec1()[2]  );\r
50             matrot2.SetVector2( bbGetInputOrientation2Vec2()[0],bbGetInputOrientation2Vec2()[1] ,bbGetInputOrientation2Vec2()[2]  );\r
51         }\r
52         if ((bbGetInputOrientation2Vec12().size()==6) )\r
53         {\r
54             matrot2.SetVector1( bbGetInputOrientation2Vec12()[0],bbGetInputOrientation2Vec12()[1] ,bbGetInputOrientation2Vec12()[2]  );\r
55             matrot2.SetVector2( bbGetInputOrientation2Vec12()[3],bbGetInputOrientation2Vec12()[4] ,bbGetInputOrientation2Vec12()[5]  );\r
56         }\r
57         vtkTransform* transform2 = (vtkTransform*)bbGetOutputOut();\r
58         transform2->PostMultiply ();\r
59         matrot2.GetTransformation(transform2);\r
60         vtkMatrix4x4 *invers1 =  vtkMatrix4x4::New();\r
61         transform1->GetInverse(invers1);\r
62         transform2->Concatenate(invers1);\r
63     bbSetOutputOut( transform2 );\r
64         transform1->Delete();\r
65 }\r
66 \r
67 /*\r
68 void RotateDICOM::bbUserConstructor()\r
69 {\r
70       std::vector<double> spacing;\r
71      spacing.push_back(1.0);\r
72      spacing.push_back(1.0);\r
73      spacing.push_back(1.0);\r
74      bbSetInputSpacing1(spacing);\r
75      bbSetInputSpacing2(spacing);\r
76 \r
77      std::vector<double> position;\r
78      position.push_back(0.0);\r
79      position.push_back(0.0);\r
80      position.push_back(0.0);\r
81      bbSetInputPosition1(position);\r
82      bbSetInputPosition2(position);\r
83 \r
84      std::vector<double> orientationVec1;\r
85      orientationVec1.push_back(1.0);\r
86      orientationVec1.push_back(0.0);\r
87      orientationVec1.push_back(0.0);\r
88      bbSetInputOrientation1Vec1(orientationVec1);\r
89      bbSetInputOrientation2Vec1(orientationVec1);\r
90 \r
91      std::vector<double> orientationVec2;\r
92      orientationVec2.push_back(0.0);\r
93      orientationVec2.push_back(1.0);\r
94      orientationVec2.push_back(0.0);\r
95      bbSetInputOrientation1Vec2(orientationVec2);\r
96      bbSetInputOrientation2Vec2(orientationVec2);\r
97 \r
98          bbSetOutputOut( vtkTransform::New() );\r
99   \r
100 }\r
101 \r
102 void RotateDICOM::bbUserCopyConstructor(bbtk::BlackBox::Pointer)\r
103 {\r
104 }\r
105 \r
106 void RotateDICOM::bbUserDestructor()\r
107 {\r
108         vtkTransform* transform = (vtkTransform*)bbGetOutputOut();\r
109         if (transform!=NULL)\r
110         {\r
111                 transform->Delete();\r
112         } \r
113 }\r
114 */\r
115 \r
116 \r
117 //===== \r
118 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)\r
119 //===== \r
120 void RotateDICOM::bbUserSetDefaultValues()\r
121 {\r
122       std::vector<double> spacing;\r
123      spacing.push_back(1.0);\r
124      spacing.push_back(1.0);\r
125      spacing.push_back(1.0);\r
126      bbSetInputSpacing1(spacing);\r
127      bbSetInputSpacing2(spacing);\r
128 \r
129      std::vector<double> position;\r
130      position.push_back(0.0);\r
131      position.push_back(0.0);\r
132      position.push_back(0.0);\r
133      bbSetInputPosition1(position);\r
134      bbSetInputPosition2(position);\r
135 \r
136      std::vector<double> orientationVec1;\r
137      orientationVec1.push_back(1.0);\r
138      orientationVec1.push_back(0.0);\r
139      orientationVec1.push_back(0.0);\r
140      bbSetInputOrientation1Vec1(orientationVec1);\r
141      bbSetInputOrientation2Vec1(orientationVec1);\r
142 \r
143      std::vector<double> orientationVec2;\r
144      orientationVec2.push_back(0.0);\r
145      orientationVec2.push_back(1.0);\r
146      orientationVec2.push_back(0.0);\r
147      bbSetInputOrientation1Vec2(orientationVec2);\r
148      bbSetInputOrientation2Vec2(orientationVec2);\r
149          bbSetOutputOut( vtkTransform::New() );\r
150 \r
151 }\r
152 \r
153 //===== \r
154 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)\r
155 //===== \r
156 void RotateDICOM::bbUserInitializeProcessing()\r
157 {\r
158 //  THE INITIALIZATION METHOD BODY :\r
159 //    Here does nothing \r
160 //    but this is where you should allocate the internal/output pointers \r
161 //    if any\r
162 }\r
163 \r
164 //===== \r
165 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)\r
166 //===== \r
167 void RotateDICOM::bbUserFinalizeProcessing()\r
168 {\r
169 //  THE FINALIZATION METHOD BODY :\r
170 //    Here does nothing \r
171 //    but this is where you should desallocate the internal/output pointers \r
172 //    if any\r
173         vtkTransform* transform = (vtkTransform*)bbGetOutputOut();\r
174         if (transform!=NULL)\r
175         {\r
176                 transform->Delete();\r
177         }\r
178 }\r
179 \r
180 } // EO namespace bbTransform3Ddicom\r
181 \r
182 \r