[vtkusers] The proper way to return vtkPolyData from a function?

Jothybasu Selvaraj jothybasu at gmail.com
Mon Jul 2 06:40:27 EDT 2012


It works with these modifications

1) vtkSmartPointer<vtkPolyData> make_vtkPolyData()

2)return triFilter->GetOutput();

3)complete_model=getvtk.make_vtkPolyData();

Jothy



On Mon, Jul 2, 2012 at 11:28 AM, Alex Southern <mrapsouthern at gmail.com>wrote:

> Hi,
>
> Ive tried numerous things to achieve this but however i do it the result
> is the same as that produced by the code below. The vtkPolydata
> complete_model is always empty, despite the line in the class member
> function, output = triFilter->GetOutput(); containing the correct output
> vtkPolyData.
>
> The issue I suspect is related to going out of scope but, no run time
> errors are being thrown. The render window is just empty.
>
> Thanks
> Alex
>
> include <vtkSmartPointer.h>
> #include <vtkActor.h>
> #include <vtkCubeSource.h>
> #include <vtkPolyData.h>
> #include <vtkCellArray.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkRenderer.h>
> #include <vtkPointData.h>
> #include <vtkDelaunay2D.h>
>
> using namespace std;
>
> class getPolyData {
>     public:
>
>         void make_vtkPolyData(vtkPolyData *output)
>         {
>             vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::*
> *New();
>             vtkSmartPointer<vtkCellArray> cellArray =
> vtkSmartPointer<vtkCellArray>:**:New();
>             vtkSmartPointer<vtkDelaunay2D> triFilter =
> vtkSmartPointer<vtkDelaunay2D>**::New();
>             vtkSmartPointer<vtkPolyData> pd1 =
> vtkSmartPointer<vtkPolyData>::**New();
>
>             // Generate a concave polygon that is NOT flat (in one plane)
>             pts->InsertNextPoint( 1.00, 2.48, 0.00 );
>             pts->InsertNextPoint( 1.00, 0.00, 0.00 );
>             pts->InsertNextPoint( 1.00, 1.24, 0.29 );
>             pts->InsertNextPoint( 0.00, 0.00, 0.00 );
>             pts->InsertNextPoint( 0.00, 2.48, 0.00 );
>             int p[5] = {0, 1, 2, 3, 4};
>             cellArray->InsertNextCell(5,p)**;
>
>             pd1->SetPoints( pts );
>             pd1->SetPolys( cellArray );
>
>             triFilter->SetInput( pd1 );
>             triFilter->Update();
>             output = triFilter->GetOutput();
>
>
>             /*writer->SetFileName("g:\\**testwrite.vtk");
>             writer->SetFileTypeToASCII();
>             writer->SetInputConnection( tmp );*/
>         }
> };
>
> int main()
> {
>
>     vtkSmartPointer<vtkPolyData> complete_model =
> vtkSmartPointer<vtkPolyData>::**New();
>
>     getPolyData getvtk;
>     getvtk.make_vtkPolyData( complete_model );
>
>     //  Create a renderer, render window, and interactor
>     vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::
> **New();
>     vtkSmartPointer<**vtkRenderWindow> renderWindow = vtkSmartPointer<**
> vtkRenderWindow>::New();
>     vtkSmartPointer<**vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<**vtkRenderWindowInteractor>::**New();
>
>     renderWindow->AddRenderer(**renderer);
>     renderWindowInteractor->**SetRenderWindow(renderWindow);
>
>     // map filtered data
>     vtkSmartPointer<**vtkPolyDataMapper> mapper = vtkSmartPointer<**
> vtkPolyDataMapper>::New();
>     vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::**New();
>
>     mapper->SetInput( complete_model );  // change to pd1 to see bad
> polygon
>     actor->SetMapper( mapper );
>     renderer->AddActor( actor );
>
>     renderer->SetBackground(.5, .1, .1);
>
>     //// Render and interact
>     renderWindow->Render();
>     renderWindowInteractor->Start(**);
>
>     return 0;
> }
> ______________________________**_________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/**
> opensource/opensource.html<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 <http://www.vtk.org/Wiki/VTK_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/**listinfo/vtkusers<http://www.vtk.org/mailman/listinfo/vtkusers>
>



-- 
Jothybasu Selvaraj
PhD Student
University of Liverpool
UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120702/7610a6bd/attachment.htm>


More information about the vtkusers mailing list