[vtkusers] does returning "vtkPolyData" work?
David Doria
daviddoria+vtk at gmail.com
Sun Jan 3 17:48:29 EST 2010
On Sun, Jan 3, 2010 at 5:11 PM, Aashish Chaudhary
<aashish.chaudhary at kitware.com> wrote:
> Zein,
>
> Use the smart pointers all the way (for return value and for the lvalue) if
> you want to use smart pointers like this.
>
> For some more information on smart pointers .. look here.
>
> http://www.vtk.org/Wiki/Smart_Pointers
>
> Hope I helped.
>
> ~Regards
>
>
> On Sun, Jan 3, 2010 at 11:40 AM, Zein Salah <zeinsalah at gmail.com> wrote:
>>
>> 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
>
>
>
> --
> | Aashish Chaudhary
> | R&D Engineer
> | Kitware Inc.
> | www.kitware.com
This little section is actually quite confusing:
http://www.vtk.org/Wiki/Smart_Pointers#Returning_a_Smart_Pointer
If the following is correct, I will update the page to only show this
and simply say "just do it this way":
----------
vtkSmartPointer<vtkPolyData> MyFunction()
{
vtkSmartPointer<vtkPolyData> myObject = vtkSmartPointer<vtkPolyData>::New();
return myObject;
}
And call the function using:
vtkSmartPointer<vtkPolyData> MyPolydata = MyFunction();
---------
Can someone verify this is how it should be done?
Thanks,
David
More information about the vtkusers
mailing list