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)
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);
36 picker->Pick(pos[0], pos[1], 0, iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer() );
39 if(picker->GetCellId() != -1)
41 printf("creaVtkCallbackPointPicker EED picker OK\n");
42 picker->GetPickPosition(point);
43 std::vector<double> vecPoint;
44 vecPoint.push_back( point[0] );
45 vecPoint.push_back( point[1] );
46 vecPoint.push_back( point[2] );
47 boxPointPicker->bbSetOutputPoint( vecPoint );
48 boxPointPicker->bbSetOutputMesh( picker->GetProp3D() );
49 boxPointPicker->bbSetOutputPointId( picker->GetPointId() );
50 boxPointPicker->bbSetOutputCellId( picker->GetCellId() );
51 boxPointPicker->bbSignalOutputModification();
53 printf("creaVtkCallbackPointPicker EED picker --\n");
56 } // if boxPoiintPicker
61 std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
62 << " " << worldPosition[2] << endl;
64 vtkSmartPointer<vtkIdTypeArray> ids =
65 vtkSmartPointer<vtkIdTypeArray>::New()creaVtkCallbackPointPicker *callPicker;
66 ids->SetNumberOfComponents(1);
67 ids->InsertNextValue(picker->GetCellId());
69 vtkSmartPointer<vtkSelectionNode> selectionNode =
70 vtkSmartPointer<vtkSelectionNode>::New();
71 selectionNode->SetFieldType(vtkSelectionNode::CELL);
72 selectionNode->SetContentType(vtkSelectionNode::INDICES);
73 selectionNode->SetSelectionList(ids);
75 vtkSmartPointer<vtkSelection> selection =
76 vtkSmartPointer<vtkSelection>::New();
77 selection->AddNode(selectionNode);
79 vtkSmartPointer<vtkExtractSelection> extractSelection =
80 vtkSmartPointer<vtkExtractSelection>::New();
81 #if VTK_MAJOR_VERSION <= 5
82 extractSelection->SetInput(0, this->Data);
83 extractSelection->SetInput(1, selection);
85 extractSelection->SetInputData(0, this->Data);
86 extractSelection->SetInputData(1, selection);
88 extractSelection->Update();
91 vtkSmartPointer<vtkUnstructuredGrid> selected =
92 vtkSmartPointer<vtkUnstructuredGrid>::New();
93 selected->ShallowCopy(extractSelection->GetOutput());
95 std::cout << "There are " << selected->GetNumberOfPoints()
96 << " points in the selection." << std::endl;
97 std::cout << "There are " << selected->GetNumberOfCells()
98 << " cells in the selection." << std::endl;
101 #if VTK_MAJOR_VERSION <= 5
102 selectedMapper->SetInputConnection(
103 selected->GetProducerPort());
105 selectedMapper->SetInputData(selected);
108 selectedActor->SetMapper(selectedMapper);
109 selectedActor->GetProperty()->EdgeVisibilityOn();
110 selectedActor->GetProperty()->SetEdgeColor(1,0,0);
111 selectedActor->GetProperty()->SetLineWidth(3);
113 this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
123 //--------------------------------------------------------
124 //--------------------------------------------------------
125 //--------------------------------------------------------
128 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPicker)
129 BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox);
131 // 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)
133 void PointPicker::Process()
136 // THE MAIN PROCESSING METHOD BODY
137 // Here we simply set the input 'In' value to the output 'Out'
138 // And print out the output value
139 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
140 // void bbSet{Input|Output}NAME(const TYPE&)
141 // const TYPE& bbGet{Input|Output}NAME() const
143 // * NAME is the name of the input/output
144 // (the one provided in the attribute 'name' of the tag 'input')
145 // * TYPE is the C++ type of the input/output
146 // (the one provided in the attribute 'type' of the tag 'input')
148 // bbSetOutputOut( bbGetInputIn() );
149 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
154 // vtkCellPicker *picker = vtkCellPicker::New();
155 // vtkPropPicker *picker = vtkCellPicker::New();
156 // picker->SetTolerance(0.005);
158 // picker->AddObserver("EndPickEvent", annotatePick)
159 // iren = vtk.vtkRenderWindowInteractor()
160 // iren.SetPicker(picker)
163 creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New();
164 picker->AddObserver( vtkCommand::EndPickEvent , callPicker );
165 picker->AddObserver( vtkCommand::StartPickEvent , callPicker );
166 picker->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
167 bbGetInputRenderer()->GetRenderWindow()->GetInteractor()->SetPicker(picker);
170 callPicker = creaVtkCallbackPointPicker::New();
171 callPicker->setBox( this );
176 if (bbGetInputRenderer()!=NULL)
178 vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor();
179 vrwi->RemoveObserver( callPicker );
181 if (bbGetInputTypeEvent()==0)
184 } else if (bbGetInputTypeEvent()==1)
186 vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
187 } else if (bbGetInputTypeEvent()==2)
189 vrwi->AddObserver( vtkCommand::LeftButtonPressEvent , callPicker );
190 } else if (bbGetInputTypeEvent()==3)
192 #if VTK_MAJOR_VERSION >= 9
193 vrwi->AddObserver( vtkCommand::LeftButtonDoubleClickEvent , callPicker );
195 printf("EED Warnning! PointPicker LeftButtonPressEvent since vtk 9 \n");
198 // ....See vtkCommand EventIds
199 } // if bbGetInputRenderer()
206 // 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)
208 void PointPicker::bbUserSetDefaultValues()
210 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
211 // Here we initialize the input 'In' to 0
213 bbSetInputActive(true);
214 bbSetInputTypeEvent(0);
215 bbSetOutputMesh(NULL);
216 bbSetOutputPointId(-1);
217 bbSetOutputCellId(-1);
222 // 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)
224 void PointPicker::bbUserInitializeProcessing()
227 // THE INITIALIZATION METHOD BODY :
229 // but this is where you should allocate the internal/output pointers
235 // 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)
237 void PointPicker::bbUserFinalizeProcessing()
240 // THE FINALIZATION METHOD BODY :
242 // but this is where you should desallocate the internal/output pointers
247 // EO namespace bbcreaVtk