[vtkusers] Problems with massProperties at getting area from ContourWidget

Rodrigo Lovera lobo.theslayer at gmail.com
Mon Dec 3 15:40:48 EST 2012


OK, I got that poly data but one I got that into the trianglefilter and
then to the massproperties is where that error shows up, so what I don't
get is that step between applying

contourRep->GetContourRepresentationAsPolyData()

and getting the poly into the trianglefilter.

For example in these contourwidget code:

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

int main(int, char *[])
{
  // Create a renderer and render window
  vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

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

vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
      vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
  contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red


  // Create a contour widget
  vtkSmartPointer<vtkContourWidget> contourWidget =
      vtkSmartPointer<vtkContourWidget>::New();
  contourWidget->SetInteractor(renderWindowInteractor);
  contourWidget->SetRepresentation(contourRep);

  renderWindow->Render();
  renderWindowInteractor->Initialize();
  renderWindow->Render();
  contourWidget->On();

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

  return EXIT_SUCCESS;
}

you start setting that points and defining the contour by mouse interaction.

Im trying to achieve that once you're done you get that contour as a
polygon so the surface area could be measured. I'm for sure missing
something, but really can't see it what it is. Sorry to bother with my
newbie questions but I really need to get these to work.

  vtkSmartPointer< vtkTriangleFilter > triangles =
  vtkSmartPointer< vtkTriangleFilter >::New();
  triangles->SetInput(contourRep->GetContourRepresentationAsPolyData());
  vtkSmartPointer< vtkMassProperties > massProp =
  vtkSmartPointer< vtkMassProperties >::New();
  massProp->SetInput(triangles->GetOutput());
  double area = massProp->GetSurfaceArea();

  std::cout<< area;


2012/12/3 David Doria <daviddoria at gmail.com>

> On Mon, Dec 3, 2012 at 3:26 PM, Rodrigo Lovera <lobo.theslayer at gmail.com>
> wrote:
> > But, how could I get the polygon out of a contour?? I mean applying the
> > contour widget lets you define points and you can close that to forma a
> 2D
> > contour. Once that's finished how to get the polygon out of that
> contour??
>
> Like you had done, right?
>
> contourRep->GetContourRepresentationAsPolyData()
>
> David
>



-- 
*Rodrigo aka WarHearT*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121203/fe9dcf3c/attachment.htm>


More information about the vtkusers mailing list