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 <vtkRenderWindowInteractor.h>
11 #include <vtkRendererCollection.h>
18 void creaVtkCallbackPointPicker::Execute(vtkObject *caller, unsigned long, void*)
20 printf("creaVtkCallbackPointPicker EED Picker\n");
21 vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
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() );
28 if(picker->GetCellId() != -1)
30 printf("creaVtkCallbackPointPicker EED picker OK\n");
32 printf("creaVtkCallbackPointPicker EED picker --\n");
39 std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
40 << " " << worldPosition[2] << endl;
42 vtkSmartPointer<vtkIdTypeArray> ids =
43 vtkSmartPointer<vtkIdTypeArray>::New();
44 ids->SetNumberOfComponents(1);
45 ids->InsertNextValue(picker->GetCellId());
47 vtkSmartPointer<vtkSelectionNode> selectionNode =
48 vtkSmartPointer<vtkSelectionNode>::New();
49 selectionNode->SetFieldType(vtkSelectionNode::CELL);
50 selectionNode->SetContentType(vtkSelectionNode::INDICES);
51 selectionNode->SetSelectionList(ids);
53 vtkSmartPointer<vtkSelection> selection =
54 vtkSmartPointer<vtkSelection>::New();
55 selection->AddNode(selectionNode);
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);
63 extractSelection->SetInputData(0, this->Data);
64 extractSelection->SetInputData(1, selection);
66 extractSelection->Update();
69 vtkSmartPointer<vtkUnstructuredGrid> selected =
70 vtkSmartPointer<vtkUnstructuredGrid>::New();
71 selected->ShallowCopy(extractSelection->GetOutput());
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;
79 #if VTK_MAJOR_VERSION <= 5
80 selectedMapper->SetInputConnection(
81 selected->GetProducerPort());
83 selectedMapper->SetInputData(selected);
86 selectedActor->SetMapper(selectedMapper);
87 selectedActor->GetProperty()->EdgeVisibilityOn();
88 selectedActor->GetProperty()->SetEdgeColor(1,0,0);
89 selectedActor->GetProperty()->SetLineWidth(3);
91 this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(selectedActor);
101 //--------------------------------------------------------
102 //--------------------------------------------------------
103 //--------------------------------------------------------
106 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PointPicker)
107 BBTK_BLACK_BOX_IMPLEMENTATION(PointPicker,bbtk::AtomicBlackBox);
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)
111 void PointPicker::Process()
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
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')
126 // bbSetOutputOut( bbGetInputIn() );
127 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
132 printf("EED PointPicker::Process Firsttime \n");
134 // vtkCellPicker *picker = vtkCellPicker::New();
135 // vtkPropPicker *picker = vtkCellPicker::New();
136 // picker->SetTolerance(0.005);
138 // picker->AddObserver("EndPickEvent", annotatePick)
139 // iren = vtk.vtkRenderWindowInteractor()
140 // iren.SetPicker(picker)
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);
150 creaVtkCallbackPointPicker *callPicker = creaVtkCallbackPointPicker::New();
151 vtkRenderWindowInteractor *vrwi = bbGetInputRenderer()->GetRenderWindow()->GetInteractor();
152 vrwi->AddObserver( vtkCommand::EndPickEvent , callPicker );
153 vrwi->AddObserver( vtkCommand::StartPickEvent , callPicker );
154 vrwi->AddObserver( vtkCommand::MouseMoveEvent , callPicker );
160 // 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 void PointPicker::bbUserSetDefaultValues()
165 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
166 // Here we initialize the input 'In' to 0
172 // 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 void PointPicker::bbUserInitializeProcessing()
177 // THE INITIALIZATION METHOD BODY :
179 // but this is where you should allocate the internal/output pointers
185 // 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 void PointPicker::bbUserFinalizeProcessing()
190 // THE FINALIZATION METHOD BODY :
192 // but this is where you should desallocate the internal/output pointers
197 // EO namespace bbcreaVtk