]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkPointPickerNearest.cxx
#3478 PointPickerNearest
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkPointPickerNearest.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 "bbcreaVtkPointPickerNearest.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkPoints.h"
8 #include <vtkPointData.h>
9 #include <vtkDataArray.h>
10
11 namespace bbcreaVtk
12 {
13
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPickerNearest)
15 BBTK_BLACK_BOX_IMPLEMENTATION(PointPickerNearest,bbtk::AtomicBlackBox);
16 //===== 
17 // 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)
18 //===== 
19 void PointPickerNearest::Process()
20 {
21
22 // THE MAIN PROCESSING METHOD BODY
23 //   Here we simply set the input 'In' value to the output 'Out'
24 //   And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 //    void bbSet{Input|Output}NAME(const TYPE&)
27 //    const TYPE& bbGet{Input|Output}NAME() const 
28 //    Where :
29 //    * NAME is the name of the input/output
30 //      (the one provided in the attribute 'name' of the tag 'input')
31 //    * TYPE is the C++ type of the input/output
32 //      (the one provided in the attribute 'type' of the tag 'input')
33
34     printf ("EED PointPickerNearest::Process Start\n");
35
36     std::vector<double> lstNormal;
37     std::vector<double> refPoint = bbGetInputPoint();
38
39     printf ("EED PointPickerNearest::Process 1\n");
40
41     if ((bbGetInputActive()==true) && ( bbGetInputMesh()!=NULL) && (refPoint.size()==3) )
42     {
43         double      p[3];
44         double      min;
45         double      minBack=100000000;
46         double      dx,dy,dz;
47         long        i,iBack=-1;
48         vtkPoints   *points = bbGetInputMesh()->GetPoints();
49         long        size    = points->GetNumberOfPoints();
50         double      border = bbGetInputBorder() * bbGetInputBorder();
51         printf ("EED PointPickerNearest::Process 2\n");
52         for ( i=0 ; i<size ; i++)
53         {
54             points->GetPoint(i,p);
55             dx  = p[0]-refPoint[0];
56             dy  = p[1]-refPoint[1];
57             dz  = p[2]-refPoint[2];
58             min = dx*dx + dy*dy + dz*dz;
59             if (min<border){
60                 if (min<minBack)
61                 {
62                     minBack = min;
63                     iBack   = i;
64                 }// if minBack
65             } // if distMax
66         } // for i
67
68         printf ("EED PointPickerNearest::Process 3\n");
69         if (iBack>=0)
70         {
71             vtkPointData    *pointdata  = bbGetInputMesh()->GetPointData();
72             vtkDataArray    *dataarray;
73             double          *pValue;
74             /*
75             int i,size=pointdata->GetNumberOfArrays();
76             for(i=0;i<size;i++)
77             {
78                 dataarray=pointdata->GetArray(i);
79                 printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s  n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
80             } // for i
81             */
82             printf ("EED PointPickerNearest::Process 4\n");
83             dataarray   = pointdata->GetNormals();
84             if (dataarray!=NULL)
85             {
86                 pValue      = dataarray->GetTuple3( iBack );
87                 printf ("EED PointPickerNearest::Process 5\n");
88                 lstNormal.push_back(pValue[0]);
89                 lstNormal.push_back(pValue[1]);
90                 lstNormal.push_back(pValue[2]);
91             } // if dataarray
92         } // if iBack
93         bbSetOutputPointId( iBack );
94         bbSetOutputNormal( lstNormal );
95         printf ("EED PointPickerNearest::Process 6 %ld\n", iBack);
96         std::vector<double> lstPointOut;
97         if (iBack>=0){
98             points->GetPoint(iBack,p);
99             lstPointOut.push_back(p[0]);
100             lstPointOut.push_back(p[1]);
101             lstPointOut.push_back(p[2]);
102             printf ("EED PointPickerNearest::Process 7 pointOut=%f %f %f\n", lstPointOut[0],lstPointOut[1],lstPointOut[2]);
103         }// if iBack
104         bbSetOutputPointOut( lstPointOut );
105     } else {
106         bbSetOutputPointId( -1 );
107         lstNormal.push_back(0);
108         lstNormal.push_back(1);
109         lstNormal.push_back(2);
110         bbSetOutputNormal( lstNormal );
111         bbSetOutputPointOut( bbGetInputPoint() );
112     }
113     
114     printf ("EED PointPickerNearest::Process END\n");
115
116 }
117 //===== 
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)
119 //===== 
120 void PointPickerNearest::bbUserSetDefaultValues()
121 {
122
123 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
124 //    Here we initialize the input 'In' to 0
125     bbSetInputActive(false);
126     bbSetInputMesh(NULL);
127     bbSetInputBorder(5);
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 PointPickerNearest::bbUserInitializeProcessing()
133 {
134
135 //  THE INITIALIZATION METHOD BODY :
136 //    Here does nothing 
137 //    but this is where you should allocate the internal/output pointers 
138 //    if any 
139
140   
141 }
142 //===== 
143 // 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)
144 //===== 
145 void PointPickerNearest::bbUserFinalizeProcessing()
146 {
147
148 //  THE FINALIZATION METHOD BODY :
149 //    Here does nothing 
150 //    but this is where you should desallocate the internal/output pointers 
151 //    if any
152   
153 }
154 }
155 // EO namespace bbcreaVtk
156
157