[vtkusers] Delete highlighted points (extending HighlightSelectedPoints example)

Sytse Reitsma vtk at sreitsma.nl
Sun Aug 17 15:41:25 EDT 2014


Hi,

I'm trying to extend the HighlightSelectedPoints 
(http://www.vtk.org/Wiki/VTK/Examples/Cxx/Picking/HighlightSelectedPoints) 
example to delete the selected points. So far I'm not very succesful.
I manage to delete the points and update the view, but as soon as I 
switch back to the normal (rotate) mouse interaction all my points 
disappear after the first mouse click. Also the remaining points are 
highlighted once I deleted the points (still in select mode).
The code I use can be found below (added to InteractorStyle class of the 
example).

Does anyone know what I'm doing wrong? Am I taking the right approach at 
all? It does not seem a very efficient way of removing points.

Thanks in advance.

Regards,

Sytse

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->GetNumberOfTu ples(); i++) {
newPoints->InsertPoint(ids->GetValue(i), this->Points->GetPoint 
(ids->GetValue(i)));
}
this->Points->SetPoints (newPoints);
this->GetInteractor()->GetRenderWindow()->Render();
}
}




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140817/4f91be99/attachment.html>


More information about the vtkusers mailing list