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