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