19 #include <vtkAlgorithmOutput.h>
20 #include <vtkCamera.h>
21 #include <vtkCellData.h>
22 #include <vtkCellPicker.h>
23 #include <vtkDataSetMapper.h>
24 #include <vtkExtractSelection.h>
25 #include <vtkIdTypeArray.h>
26 #include <vtkObjectFactory.h>
28 #include <vtkProperty.h>
29 #include <vtkRenderWindow.h>
30 #include <vtkRenderWindowInteractor.h>
31 #include <vtkRendererCollection.h>
32 #include <vtkSelection.h>
33 #include <vtkSelectionNode.h>
34 #include <vtkSmartPointer.h>
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkUnstructuredGridAlgorithm.h>
63 switch (Interactor->GetKeyCode())
66 INFO(
"The 3 key was pressed.");
71 vtkInteractorStyleTrackballCamera::OnChar();
77 switch (Interactor->GetKeyCode())
84 vtkInteractorStyleTrackballCamera::OnKeyDown();
90 switch (Interactor->GetKeyCode())
97 vtkInteractorStyleTrackballCamera::OnKeyUp();
105 HighlightProp((vtkProp*)actor);
111 this->Interactor->GetRenderWindow()
122 HighlightProp((vtkProp*)
nullptr);
131 this->Interactor->GetRenderWindow()
144 return vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
150 int* pos = this->GetInteractor()->GetEventPosition();
152 vtkSmartPointer<vtkCellPicker> picker =
153 vtkSmartPointer<vtkCellPicker>::New();
154 picker->SetTolerance(0.0005);
157 picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
159 double* worldPosition = picker->GetPickPosition();
160 INFO(
"Cell id is: {:d}", picker->GetCellId());
162 if (picker->GetCellId() != -1)
164 INFO(
"Pick position is: {:f} {:f} {:f}", worldPosition[0],
165 worldPosition[1], worldPosition[2]);
167 vtkSmartPointer<vtkIdTypeArray> ids =
168 vtkSmartPointer<vtkIdTypeArray>::New();
169 ids->SetNumberOfValues(1);
170 ids->SetValue(0, picker->GetCellId());
172 vtkSmartPointer<vtkSelectionNode> selectionNode =
173 vtkSmartPointer<vtkSelectionNode>::New();
174 selectionNode->SetFieldType(vtkSelectionNode::CELL);
175 selectionNode->SetContentType(vtkSelectionNode::INDICES);
176 selectionNode->SetSelectionList(ids);
178 vtkSmartPointer<vtkSelection> selection =
179 vtkSmartPointer<vtkSelection>::New();
180 selection->AddNode(selectionNode);
182 vtkSmartPointer<vtkExtractSelection> extractSelection =
183 vtkSmartPointer<vtkExtractSelection>::New();
184 extractSelection->SetInputData(0,
_data);
185 extractSelection->SetInputData(1, selection);
186 extractSelection->Update();
189 vtkSmartPointer<vtkUnstructuredGrid> selected =
190 vtkSmartPointer<vtkUnstructuredGrid>::New();
191 selected->ShallowCopy(extractSelection->GetOutput());
193 INFO(
"There are {:d} points in the selection.",
194 selected->GetNumberOfPoints());
195 INFO(
"There are {:d} cells in the selection.",
196 selected->GetNumberOfCells());
201 vtkAlgorithm* data_set = picker->GetActor()
203 ->GetInputConnection(0, 0)
205 ->GetInputConnection(0, 0)
208 dynamic_cast<vtkUnstructuredGridAlgorithm*
>(data_set);
212 static_cast<unsigned>(picker->GetCellId()));
220 this->Interactor->GetRenderWindow()
228 this->Interactor->GetRenderWindow()
238 vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
246 return vtkInteractorStyleTrackballCamera::OnRightButtonDown();
252 int* pos = this->GetInteractor()->GetEventPosition();
254 vtkSmartPointer<vtkCellPicker> picker =
255 vtkSmartPointer<vtkCellPicker>::New();
256 picker->SetTolerance(0.0005);
259 picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
261 double* worldPosition = picker->GetPickPosition();
262 INFO(
"Cell id is: {:d}", picker->GetCellId());
264 if (picker->GetCellId() != -1)
266 vtkRenderer* renderer = this->Interactor->GetRenderWindow()
268 ->GetFirstRenderer();
269 vtkCamera* cam = renderer->GetActiveCamera();
270 cam->SetFocalPoint(worldPosition);
277 vtkInteractorStyleTrackballCamera::OnRightButtonDown();
void INFO(char const *fmt, Args const &... args)
Definition of the VtkCompositeSelectionFilter class.
vtkStandardNewMacro(VtkCustomInteractorStyle)
Definition of the VtkCustomInteractorStyle class.
void setHighlightActor(bool on)
vtkDataSetMapper * _selectedMapper
The mapper for highlighting the selected cell.
void OnChar() override
Handles key press events.
void OnKeyDown() override
Handles key down events.
void elementPicked(vtkUnstructuredGridAlgorithm const *const, unsigned)
Emitted when a mesh element has been picked.
void cursorChanged(Qt::CursorShape)
Emitted when the cursor shape was changed due to alternate mouse action mode.
void clearElementView()
Emitted when the current object type cannot be handled by the element model.
void pickableDataObject(vtkDataObject *object)
Sets the highlightable vtk object.
vtkDataObject * _data
The vtk object to pick.
void removeHighlightActor()
Removes the highlight actor from the visible scene.
~VtkCustomInteractorStyle() override
vtkActor * _selectedActor
The actor for highlighting the selected cell.
VtkCustomInteractorStyle()
void highlightActor(vtkProp3D *actor)
bool _alternateMouseActions
void requestViewUpdate()
Emitted when something was picked.
void OnLeftButtonDown() override
Handles left mouse button events (picking).
void OnKeyUp() override
Handles key up events.
void OnRightButtonDown() override
Handles middle mouse button events (rotation point picking).