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)
4 #include "bbcreaVtkPointPicker.h"
5 #include "bbcreaVtkPackage.h"
7 #include <vtkPropPicker.h>
8 #include <vtkCellPicker.h>
9 #include <vtkRenderWindow.h>
10 #include <vtkRendererCollection.h>
15 creaVtkCallbackPointPicker::creaVtkCallbackPointPicker(void)
17 boxPointPicker = NULL;
20 void creaVtkCallbackPointPicker::setBox(PointPicker *box)
25 void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*)
27 if (boxPointPicker!=NULL)
29 if (boxPointPicker->bbGetInputActive()==true)
31 // printf("creaVtkCallbackPointPicker EED Picker\n");
32 vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
33 int* pos = iren->GetEventPosition();
34 vtkCellPicker *picker = vtkCellPicker::New();
35 picker->SetTolerance(0.0005);
37 if (boxPointPicker->bbGetInputProp3D()!=NULL )
39 picker->AddPickList( boxPointPicker->bbGetInputProp3D() );
40 picker->PickFromListOn();
43 picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() );
46 if(picker->GetCellId() != -1)
48 // printf("creaVtkCallbackPointPicker EED picker OK\n");
49 picker->GetPickPosition(point);
50 std::vector<double> vecPoint;
51 vecPoint.push_back( point[0] );
52 vecPoint.push_back( point[1] );
53 vecPoint.push_back( point[2] );
54 boxPointPicker->bbSetOutputPoint( vecPoint );
55 boxPointPicker->bbSetOutputMesh( picker->GetProp3D() );
56 boxPointPicker->bbSetOutputPointId( picker->GetPointId() );
57 boxPointPicker->bbSetOutputCellId( picker->GetCellId() );
58 boxPointPicker->bbSignalOutputModification();
60 // printf("creaVtkCallbackPointPicker EED picker --\n");
63 } // if boxPoiintPicker
68 std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
69 << " " << worldPosition[2] << endl;
71 vtkSmartPointer<vtkIdTypeArray> ids =
72 vtkSmartPointer<vtkIdTypeArray>::New()creaVtkCallbackPointPicker *callPicker;
73 ids->SetNumberOfComponents(1);
74 ids->InsertNextValue(picker->GetCellId());
76 vtkSmartPointer<vtkSelectionNode> selectionNode =
77 vtkSmartPointer<vtkSelectionNode>::New();
78 selectionNode->SetFieldType(vtkSelectionNode::CELL);
79 selectionNode->SetContentType(vtkSelectionNode::INDICES);
80 selectionNode->SetSelectionList(ids);
82 vtkSmartPointer<vtkSelection> selection =
83 vtkSmartPointer<vtkSelection>::New();
84 selection->AddNode(selectionNode);
86 vtkSmartPointer<vtkExtractSelection> extractSelection =
87 vtkSmartPointer<vtkExtractSelection>::New();
88 #if VTK_MAJOR_VERSION <= 5
89 extractSelection->SetInput(0, this->Data);
90 extractSelection->SetInput(1, selection);
92 extractSelection->SetInputData(0, this->Data);
93 extractSelection->SetInputData(1, selection);
95 extractSelection->Update();
98 vtkSmartPointer<vtkUnstructuredGrid> selected =
99 vtkSmartPointer<vtkUnstructuredGrid>::New();
100 selected->ShallowCopy(extractSelection->GetOutput());
102 std::cout << "There are " << selected->GetNumberOfPoints()
103 << " points in the selection." << std::endl;
104 std::cout << "There are " << selected->GetNumberOfCells()
105 << " cells in the selection." << std::endl;
108 #if VTK_MAJOR_VERSION <= 5
109 selectedMapper->SetInputConnection(
110 selected->GetProducerPort());
112 selectedMapper->SetInputData(selected);
115 selectedActor->SetMapper(selectedMapper);
116 selectedActor->GetProperty()->EdgeVisibilityOn();
117 selectedActor->GetProperty()->SetEdgeColor(1,0,0);
118 selectedActor->GetProperty()->SetLineWidth(3);
120 this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
130 //--------------------------------------------------------
131 //--------------------------------------------------------
132 //--------------------------------------------------------
135 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPicker)
136 BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox);
138 // 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)
140 void PointPicker::Process()
143 // THE MAIN PROCESSING METHOD BODY
144 // Here we simply set the input 'In' value to the output 'Out'
145 // And print out the output value
146 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
147 // void bbSet{Input|Output}NAME(const TYPE&)
148 // const TYPE& bbGet{Input|Output}NAME() const
150 // * NAME is the name of the input/output
151 // (the one provided in the attribute 'name' of the tag 'input')
152 // * TYPE is the C++ type of the input/output
153 // (the one provided in the attribute 'type' of the tag 'input')
155 // bbSetOutputOut( bbGetInputIn() );
156 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
161 // vtkCellPicker *picker = vtkCellPicker::New();
162 // vtkPropPicker *picker = vtkCellPicker::New();
163 // picker->SetTolerance(0.005);
165 // picker->AddObserver("EndPickEvent", annotatePick)
166 // iren = vtk.vtkRenderWindowInteractor()
167 // iren.SetPicker(picker)
170 creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New();
171 picker->AddObserver( vtkCommand::EndPickEvent , callPicker );
172 picker->AddObserver( vtkCommand::StartPickEvent , callPicker );
173 picker->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
174 bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker);
177 callPicker = creaVtkCallbackPointPicker::New();
178 callPicker->setBox( this );
183 if (bbGetInputRenderer()!=NULL)
185 vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor();
186 vrwi->RemoveObserver( callPicker );
188 if (bbGetInputTypeEvent()==0)
191 } else if (bbGetInputTypeEvent()==1)
193 vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
194 } else if (bbGetInputTypeEvent()==2)
196 vrwi->AddObserver( vtkCommand::LeftButtonPressEvent , callPicker );
197 } else if (bbGetInputTypeEvent()==3)
199 #if VTK_MAJOR_VERSION >= 9
200 vrwi->AddObserver( vtkCommand::LeftButtonDoubleClickEvent , callPicker );
202 printf("EED Warnning! PointPicker LeftButtonPressEvent since vtk 9 \n");
205 // ....See vtkCommand EventIds
206 } // if bbGetInputRenderer()
213 // 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)
215 void PointPicker::bbUserSetDefaultValues()
217 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
218 // Here we initialize the input 'In' to 0
220 bbSetInputActive(true);
221 bbSetInputTypeEvent(0);
222 bbSetOutputMesh(NULL);
223 bbSetOutputPointId(-1);
224 bbSetOutputCellId(-1);
227 bbSetInputProp3D(NULL);
230 // 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)
232 void PointPicker::bbUserInitializeProcessing()
235 // THE INITIALIZATION METHOD BODY :
237 // but this is where you should allocate the internal/output pointers
243 // 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)
245 void PointPicker::bbUserFinalizeProcessing()
248 // THE FINALIZATION METHOD BODY :
250 // but this is where you should desallocate the internal/output pointers
255 // EO namespace bbcreaVtk