]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkVectorsExtraction.cxx
#3110 creaVtk Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkVectorsExtraction.cxx
1 //===== 
2 // 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)
3 //===== 
4 #include "bbcreaVtkVectorsExtraction.h"
5 #include "bbcreaVtkPackage.h"
6 #include "vtkDoubleArray.h"
7
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,VectorsExtraction)
13 BBTK_BLACK_BOX_IMPLEMENTATION(VectorsExtraction,bbtk::AtomicBlackBox);
14 //===== 
15 // 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)
16 //===== 
17 void VectorsExtraction::Process()
18 {
19
20 // THE MAIN PROCESSING METHOD BODY
21 //   Here we simply set the input 'In' value to the output 'Out'
22 //   And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 //    void bbSet{Input|Output}NAME(const TYPE&)
25 //    const TYPE& bbGet{Input|Output}NAME() const 
26 //    Where :
27 //    * NAME is the name of the input/output
28 //      (the one provided in the attribute 'name' of the tag 'input')
29 //    * TYPE is the C++ type of the input/output
30 //      (the one provided in the attribute 'type' of the tag 'input')
31 std::cout<< "MLER VectorsExtraction Process Start" << std::endl;
32     if(bbGetInputVectorsFieldImage() != NULL )
33         {
34                 vtkImageData            *m_VectorImage = bbGetInputVectorsFieldImage();
35                 vtkIdType               m_idType;
36         vtkDoubleArray          *velocity      = vtkDoubleArray::New();
37         std::vector<double>     coord          = bbGetInputCoordinates();
38         std::vector<double>     vec;
39         vec.push_back(0);
40         vec.push_back(0);
41         vec.push_back(0);
42         double ang1 = 0;//Angle 1
43         double ang2 = 0;//ANgle 2
44         double comp = 0;//Component x + y
45         //Find coordinate into the image      
46 std::cout << "ups ." << std::endl;
47         m_idType = m_VectorImage->FindPoint(coord[0],coord[1],coord[2]);
48 std::cout << "m_idType" << m_idType << std::endl;
49         //Recuperate vector of vectorFieldImage
50                 m_VectorImage->Print(std::cout);
51
52
53                 int sizeArrays= m_VectorImage->GetPointData()->GetNumberOfArrays();
54                 for (int iArray=0; iArray<sizeArrays;iArray++)
55                 {
56                         printf("%s\n", m_VectorImage->GetPointData()->GetArrayName(iArray) );
57                 } // for iArrays
58
59 vtkDataArray *dataArray = m_VectorImage->GetPointData()->GetArray("velocity");
60 if (dataArray!=NULL)
61 {
62         printf("DataArrya ok \n");      
63         double *vecData;
64         vecData=dataArray->GetTuple3(m_idType);
65         printf("info data: %f %f %f \n", vecData[0], vecData[1], vecData[2] );
66         vec[0]=vecData[0];
67         vec[1]=vecData[1];
68         vec[2]=vecData[2];
69         bbSetOutputVector(vec);
70
71 } // if dataArray
72
73                 velocity = vtkDoubleArray::SafeDownCast(m_VectorImage->GetPointData()->GetArray("velocity"));
74         //velocity->Print(std::cout);
75                 if (velocity!=NULL)
76                 {
77         std::cout<< "# components velocity: " << velocity->GetNumberOfComponents()<<std::endl;
78         std::cout<< "# tuples velocity: " << velocity->GetNumberOfTuples()<<std::endl;
79                         vec[0] = velocity->GetComponent(m_idType,0);
80                         vec[1] = velocity->GetComponent(m_idType,1);
81                         vec[2] = velocity->GetComponent(m_idType,2);
82         std::cout << "velocity :" << vec[0] << "," <<vec[1] << ","<< vec[2] << std::endl;
83                         //Miss calcule of angles -----
84                         comp = sqrt((vec[0]*vec[0])+(vec[1]*vec[1]));
85                         ang1 = atan2(vec[2],comp) * 180 / PI;
86                         ang2 = atan2(vec[1],vec[0]) * 180 / PI;
87                         //m_VectorImage->Print(std::cout);
88         std::cout << "ang1: " << ang1 << std::endl;
89         std::cout << "ang2: " << ang2 << std::endl;
90                         bbSetOutputAngle1(ang1);
91                         bbSetOutputAngle2(ang2);
92                         bbSetOutputVector(vec);
93                         bbSetOutputX(coord[0]);
94                         bbSetOutputY(coord[1]);
95                         bbSetOutputZ(coord[2]);
96
97                 } else {
98                         bbSetOutputAngle1(ang1);
99                         bbSetOutputAngle2(ang2);
100                         bbSetOutputVector(vec);
101                 }// if velocity
102         }// if image != NULL
103 std::cout<< "MLER VectorsExtraction Process END" << std::endl;  
104 }
105 //===== 
106 // 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)
107 //===== 
108 void VectorsExtraction::bbUserSetDefaultValues()
109 {
110
111 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
112 //    Here we initialize the input 'In' to 0
113    bbSetInputVectorsFieldImage(NULL);
114   
115 }
116 //===== 
117 // 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)
118 //===== 
119 void VectorsExtraction::bbUserInitializeProcessing()
120 {
121
122 //  THE INITIALIZATION METHOD BODY :
123 //    Here does nothing 
124 //    but this is where you should allocate the internal/output pointers 
125 //    if any 
126
127   
128 }
129 //===== 
130 // 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)
131 //===== 
132 void VectorsExtraction::bbUserFinalizeProcessing()
133 {
134
135 //  THE FINALIZATION METHOD BODY :
136 //    Here does nothing 
137 //    but this is where you should desallocate the internal/output pointers 
138 //    if any
139   
140 }
141 }
142 // EO namespace bbcreaVtk
143
144