[vtkusers] vtkDistanceWidget constrained to PolyData?

agerlach agerlach at gmail.com
Tue Jun 28 13:53:06 EDT 2011


All I am trying to do distance measurements on a 3D polydata actor in my
application, so I would like to use the vtkDistanceWidget and have it
constrain its end point selections to points on the surface of the polyData. 

I have tried the following without any success. I tried to set the point
placer to a vtkPolyDataPointPlacer for the vtkHandle for the widget
representation Any advice will be greatly appreciated.

#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>

#include <vtkDistanceWidget.h>
#include <vtkDistanceRepresentation2D.h>
#include <vtkDistanceRepresentation3D.h>
#include <vtkPolyDataPointPlacer.h>
#include <vtkPolygonalSurfacePointPlacer.h>
#include <vtkPointHandleRepresentation2D.h>
#include <vtkPointHandleRepresentation3D.h>
#include <vtkProperty.h>




int main(int, char *[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();

  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);


  // A renderer and render window
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  renderer->AddActor(actor);

  // An interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkPolyDataPointPlacer> pointPlacer = 
    vtkSmartPointer<vtkPolyDataPointPlacer>::New();
  pointPlacer->AddProp(actor);

  vtkSmartPointer<vtkPointHandleRepresentation3D> handleRep = 
    vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
  handleRep->SetHandleSize(50);
  handleRep->GetProperty()->SetColor(1.,0.,0.);
  handleRep->SetPointPlacer(pointPlacer);

  vtkSmartPointer<vtkDistanceRepresentation3D> distanceRep = 
    vtkSmartPointer<vtkDistanceRepresentation3D>::New();
  distanceRep->SetHandleRepresentation(handleRep);


  vtkSmartPointer<vtkDistanceWidget> distanceWidget = 
    vtkSmartPointer<vtkDistanceWidget>::New();

  distanceWidget->SetRepresentation(distanceRep);
  distanceWidget->SetInteractor(renderWindowInteractor);


  renderWindowInteractor->Initialize();
  renderWindow->Render();
  distanceWidget->EnabledOn();
  renderWindow->Render();


  // Begin mouse interaction
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}


--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkDistanceWidget-constrained-to-PolyData-tp4532597p4532597.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list