Skip to content

Instantly share code, notes, and snippets.

@sytsereitsma
Last active August 29, 2015 14:05
Show Gist options
  • Save sytsereitsma/73cb7afc1ddcdb374641 to your computer and use it in GitHub Desktop.
Save sytsereitsma/73cb7afc1ddcdb374641 to your computer and use it in GitHub Desktop.
virtual void OnKeyPress() {
vtkRenderWindowInteractor *rwi = this->Interactor;
const char* ch = rwi->GetKeySym ();
if (strcmp (ch, "Delete") == 0) {
vtkPlanes* frustum = static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
vtkSmartPointer<vtkExtractGeometry> extractGeometry =
vtkSmartPointer<vtkExtractGeometry>::New();
extractGeometry->SetImplicitFunction(frustum);
extractGeometry->SetInputData(this->Points);
extractGeometry->SetExtractInside(0); //We want all points outside the geometry
extractGeometry->Update();
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
glyphFilter->Update();
vtkPolyData* selected = glyphFilter->GetOutput ();
vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray("OriginalIds"));
vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
for(vtkIdType i = 0; i < ids->GetNumberOfTuples(); i++) {
newPoints->InsertPoint(ids->GetValue(i), this->Points->GetPoint (ids->GetValue(i)));
}
this->Points->SetPoints (newPoints);
this->GetInteractor()->GetRenderWindow()->Render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment