]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkPointPicker.cxx
3150 creaVtk Feature New Normal - PointPicker box
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkPointPicker.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 "bbcreaVtkPointPicker.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include <vtkPropPicker.h>
8 #include <vtkCellPicker.h>
9 #include <vtkRenderWindow.h>
10 #include <vtkRenderWindowInteractor.h>
11 #include <vtkRendererCollection.h>
12
13 namespace bbcreaVtk
14 {
15
16
17
18 void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*)
19 {
20                 printf("creaVtkCallbackPointPicker EED Picker\n");
21                 vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
22
23                 int* pos = iren->GetEventPosition();
24         vtkCellPicker *picker = vtkCellPicker::New();
25         picker->SetTolerance(0.0005);
26         picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() );
27
28                 if(picker->GetCellId() != -1)
29         {
30                         printf("creaVtkCallbackPointPicker EED picker OK\n");
31                 } else {
32                         printf("creaVtkCallbackPointPicker EED picker --\n");
33                 } // if
34
35
36 /*
37 {
38  
39         std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
40                   << " " << worldPosition[2] << endl;
41  
42         vtkSmartPointer<vtkIdTypeArray> ids =
43           vtkSmartPointer<vtkIdTypeArray>::New();
44         ids->SetNumberOfComponents(1);
45         ids->InsertNextValue(picker->GetCellId());
46  
47         vtkSmartPointer<vtkSelectionNode> selectionNode =
48           vtkSmartPointer<vtkSelectionNode>::New();
49         selectionNode->SetFieldType(vtkSelectionNode::CELL);
50         selectionNode->SetContentType(vtkSelectionNode::INDICES);
51         selectionNode->SetSelectionList(ids);
52  
53         vtkSmartPointer<vtkSelection> selection =
54           vtkSmartPointer<vtkSelection>::New();
55         selection->AddNode(selectionNode);
56  
57         vtkSmartPointer<vtkExtractSelection> extractSelection =
58           vtkSmartPointer<vtkExtractSelection>::New();
59 #if VTK_MAJOR_VERSION <= 5
60         extractSelection->SetInput(0, this->Data);
61         extractSelection->SetInput(1, selection);
62 #else
63         extractSelection->SetInputData(0, this->Data);
64         extractSelection->SetInputData(1, selection);
65 #endif
66         extractSelection->Update();
67  
68         // In selection
69         vtkSmartPointer<vtkUnstructuredGrid> selected =
70           vtkSmartPointer<vtkUnstructuredGrid>::New();
71         selected->ShallowCopy(extractSelection->GetOutput());
72  
73         std::cout << "There are " << selected->GetNumberOfPoints()
74                   << " points in the selection." << std::endl;
75         std::cout << "There are " << selected->GetNumberOfCells()
76                   << " cells in the selection." << std::endl;
77  
78  
79 #if VTK_MAJOR_VERSION <= 5
80         selectedMapper->SetInputConnection(
81           selected->GetProducerPort());
82 #else
83         selectedMapper->SetInputData(selected);
84 #endif
85  
86         selectedActor->SetMapper(selectedMapper);
87         selectedActor->GetProperty()->EdgeVisibilityOn();
88         selectedActor->GetProperty()->SetEdgeColor(1,0,0);
89         selectedActor->GetProperty()->SetLineWidth(3);
90  
91         this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
92  
93         }
94 */
95
96
97
98 }
99
100
101 //--------------------------------------------------------
102 //--------------------------------------------------------
103 //--------------------------------------------------------
104
105
106 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPicker)
107 BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox);
108 //===== 
109 // 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)
110 //===== 
111 void PointPicker::Process()
112 {
113
114 // THE MAIN PROCESSING METHOD BODY
115 //   Here we simply set the input 'In' value to the output 'Out'
116 //   And print out the output value
117 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
118 //    void bbSet{Input|Output}NAME(const TYPE&)
119 //    const TYPE& bbGet{Input|Output}NAME() const 
120 //    Where :
121 //    * NAME is the name of the input/output
122 //      (the one provided in the attribute 'name' of the tag 'input')
123 //    * TYPE is the C++ type of the input/output
124 //      (the one provided in the attribute 'type' of the tag 'input')
125
126 //    bbSetOutputOut( bbGetInputIn() );
127 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
128   
129         if (firsttime==true)
130         {
131
132 printf("EED PointPicker::Process Firsttime \n");
133                 firsttime = false;
134 //              vtkCellPicker *picker = vtkCellPicker::New();
135 //              vtkPropPicker *picker = vtkCellPicker::New();
136 //              picker->SetTolerance(0.005);
137
138 //              picker->AddObserver("EndPickEvent", annotatePick)
139 //              iren = vtk.vtkRenderWindowInteractor()
140 //              iren.SetPicker(picker)
141
142 /*
143                 creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New();
144                 picker->AddObserver( vtkCommand::EndPickEvent , callPicker );
145                 picker->AddObserver( vtkCommand::StartPickEvent , callPicker );
146                 picker->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
147                 bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker);
148 */
149
150                 creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New();
151                 callPicker->_renderer =  bbGetInputRenderer();
152                 vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor();
153                 vrwi->AddObserver( vtkCommand::EndPickEvent , callPicker );
154                 vrwi->AddObserver( vtkCommand::StartPickEvent , callPicker );
155                 vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
156
157         } // if firsttime
158
159 }
160 //===== 
161 // 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)
162 //===== 
163 void PointPicker::bbUserSetDefaultValues()
164 {
165
166 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
167 //    Here we initialize the input 'In' to 0
168 //   bbSetInputIn(0);
169   
170         firsttime=true;
171 }
172 //===== 
173 // 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)
174 //===== 
175 void PointPicker::bbUserInitializeProcessing()
176 {
177
178 //  THE INITIALIZATION METHOD BODY :
179 //    Here does nothing 
180 //    but this is where you should allocate the internal/output pointers 
181 //    if any 
182
183   
184 }
185 //===== 
186 // 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)
187 //===== 
188 void PointPicker::bbUserFinalizeProcessing()
189 {
190
191 //  THE FINALIZATION METHOD BODY :
192 //    Here does nothing 
193 //    but this is where you should desallocate the internal/output pointers 
194 //    if any
195   
196 }
197 }
198 // EO namespace bbcreaVtk
199
200