[vtkusers] vtkcontourwidget: extract contour as polydata (GetContourRepresentationAsPolyData)

Miguel Sotaquirá msotaquira at gmail.com
Thu Jun 16 03:33:05 EDT 2011


Hi! I'm a newbie on VTK and I'm using vtkContourWidget to manually draw a
contour on a polydata surface.

I've managed to draw the contour and also, via callbacks, to print
(std::cout) the polydata contour info (using the syntax
polyData->GetNumberOfPoints(), where "polyData" is the contour obtained as
vtkPolyData *polyData = rep->GetContourRepresentationAsPolyData();).

The problem: up to know I only have access to this polydata from within the
class implementation and not from the calling function (in my case the main
function).

What I'd like to do: to return the polydata pointer (from the callback) to
the main function, in order to have access to the contour. Does any of you
know how to do that?

Here's part of my code:

//
// Callback class
//
class callbackContourWidget : public vtkCommand
{
  public:
    static callbackContourWidget *New()
    {
      return new callbackContourWidget;
    }
    callbackContourWidget(){}

    virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
      vtkContourWidget *contourWidget =
reinterpret_cast<vtkContourWidget*>(caller);
      vtkContourRepresentation* rep = static_cast<vtkContourRepresentation
*>(contourWidget->GetRepresentation());

      vtkPolyData *polyData = rep->GetContourRepresentationAsPolyData();
      std::cout<< "The contour has " << polyData->GetNumberOfPoints() <<
"points." << std::endl;
    }

  void SetMeshSource(vtkSmartPointer<vtkTriangleFilter> triangleMesh)
{this->MeshSource = triangleMesh;}

  // Metodo para obtener el polydata
  void GetPolydataContour(<vtkContourRepresentation> rep) {}

  private:
    vtkSmartPointer<vtkTriangleFilter> MeshSource;
};

//
// Calling the callback from the main function
//

int main(int argc, char *argv[]){
...
...
vtkSmartPointer<callbackContourWidget> callback =
vtkSmartPointer<callbackContourWidget>::New();
callback->SetMeshSource(triangleFilter);
contourWidget->AddObserver(vtkCommand::InteractionEvent,callback);
...
...
}

Thanks!
Miguel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110616/8819ede5/attachment.htm>


More information about the vtkusers mailing list