[vtkusers] does returning "vtkPolyData" work?

Rocco Gasteiger post at rocco-gasteiger.de
Mon Jan 4 02:55:02 EST 2010


Hello Zein,

I have two assumptions according to your smart pointer usage (I'm not very
familiar with them until yet):

1. Maybe your polydata-pointer "polyData" is not valid outside of your
function " MyClass::GenerateCont(...)". Your solution could be in returning
"cutter->GetOutput()" directly instead of " vtkSmartPointer<vtkPolyData>
polyData = cutter->GetOutput(); return polyData;"

2. According to this VTK-Documentation:
http://www.vtk.org/Wiki/Smart_Pointers, the return type of your function
could not be correct. Maybe you can try "vtkSmartPointer<vtkPolyData>
MyClass::GenerateCont(...)" instead, additionally with "return
cutter->GetOutput();" (like above) in combination with
"vtkSmartPointer<vtkPolyData> MyPolydata = MyClass::GenerateCont(..)".

I hope this gives you a little help.

Best regards, Rocco


-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
Of Zein Salah
Sent: Sunday, January 03, 2010 5:41 PM
To: vtkusers at vtk.org
Subject: [vtkusers] does returning "vtkPolyData" work?

Hallo ,
In my class, I have a function that SHOULD return a vtkPolyData, which is
the result of a vtkCutter, as shown below:


vtkPolyData* MyClass::GenerateCont(double cntr[], double nrml[])
{

    vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
    plane->SetOrigin(cntr[0], cntr[1], cntr[2]);
    plane->SetNormal(nrml[0], nrml[1], nrml[2]);
	
    vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();

    cutter->SetInput(....); // some input vtkpolydata
    cutter->SetCutFunction(plane);
    cutter->Update();


    vtkSmartPointer<vtkPolyData> polyData = cutter->GetOutput();
    return polyData;
}


Now I have an array of struct, cArray, where one field of the struct is of
type vtkPolyData*. When I call the GenerateCont function on the elements
of the array, as follows


for (int i= 0; i<num; i++) {
     double       cntr[3];      cntr[0] = ...; 	   cntr[1] = ...;
      cntr[2] = ...;
     double       zdir[3];      zdir[0] = ...;            zdir[1] =
...;             zdir[2] = ...;

     cArray[i].polyData = GenerateCont(cntr, zdir);
}

I noticed that the cArray is not updated. I.e. calling function GenerateCont
does not return the supposed vtkPolyData. By testing whether the function
GenerateCont works itself, I found that is the vtkCutter generates the
output as required, only the output value is not returned.

What is wrong I am doing? Is returning a vtkPolyData semantically wrong?


Much thanks,
Zein
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list