]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkPointPickerNearest.cxx
PointPickerNearest box
[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
35     std::vector<double> lstNormal;
36     std::vector<double> refPoint = bbGetInputPoint();
37
38     if ((bbGetInputActive()==true) && ( bbGetInputMesh()!=NULL) && (refPoint.size()==3) )
39     {
40         double      p[3];
41         double      min;
42         double      minBack=100000000;
43         double      dx,dy,dz;
44         long        i,iBack=-1;
45         vtkPoints   *points = bbGetInputMesh()->GetPoints();
46         long        size    = points->GetNumberOfPoints();
47         double      border = bbGetInputBorder() * bbGetInputBorder();
48         for ( i=0 ; i<size ; i++)
49         {
50             points->GetPoint(i,p);
51             dx  = p[0]-refPoint[0];
52             dy  = p[1]-refPoint[1];
53             dz  = p[2]-refPoint[2];
54             min = dx*dx + dy*dy + dz*dz;
55             if (min<border){
56                 if (min<minBack)
57                 {
58                     minBack = min;
59                     iBack   = i;
60                 }// if minBack
61             } // if distMax
62         } // for i
63
64         if (iBack>=0)
65         {
66             vtkPointData    *pointdata  = bbGetInputMesh()->GetPointData();
67             vtkDataArray    *dataarray;
68             double          *pValue;
69             /*
70             int i,size=pointdata->GetNumberOfArrays();
71             for(i=0;i<size;i++)
72             {
73                 dataarray=pointdata->GetArray(i);
74                 printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s  n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
75             } // for i
76             */
77             dataarray   = pointdata->GetNormals();
78             if (dataarray!=NULL)
79             {
80                 pValue      = dataarray->GetTuple3( iBack );
81                 lstNormal.push_back(pValue[0]);
82                 lstNormal.push_back(pValue[1]);
83                 lstNormal.push_back(pValue[2]);
84             } // if dataarray
85         } // if iBack
86         bbSetOutputPointId( iBack );
87         bbSetOutputNormal( lstNormal );
88     } else {
89         bbSetOutputPointId( -1 );
90         bbSetOutputNormal( lstNormal );
91     }
92 }
93 //===== 
94 // 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)
95 //===== 
96 void PointPickerNearest::bbUserSetDefaultValues()
97 {
98
99 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
100 //    Here we initialize the input 'In' to 0
101     bbSetInputActive(false);
102     bbSetInputMesh(NULL);
103     bbSetInputBorder(10);
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 PointPickerNearest::bbUserInitializeProcessing()
109 {
110
111 //  THE INITIALIZATION METHOD BODY :
112 //    Here does nothing 
113 //    but this is where you should allocate the internal/output pointers 
114 //    if any 
115
116   
117 }
118 //===== 
119 // 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)
120 //===== 
121 void PointPickerNearest::bbUserFinalizeProcessing()
122 {
123
124 //  THE FINALIZATION METHOD BODY :
125 //    Here does nothing 
126 //    but this is where you should desallocate the internal/output pointers 
127 //    if any
128   
129 }
130 }
131 // EO namespace bbcreaVtk
132
133