[vtkusers] how to convert AppendFilter output to polyData?

David E DeMarle dave.demarle at kitware.com
Wed Sep 13 06:41:37 EDT 2017


Use vtkappendpolydata instead of vtkappendfilter.

Alternatively you could extract surface on the unstructured grid you have
now yo convert to polydata but that would be less direct.

On Sep 13, 2017 1:12 AM, "vinmean" <iamdpak at gmail.com> wrote:

> Below is an c++ code I wrote for combining two polygon source. I tweaked an
> existing example so my code is at the end. Problem is, after combining two
> polygon data (using appendFilter),  I am not able to access the polyData of
> the combined actor. It throws a segmentation fault when I access the
> polyData points using GetPoints() function
>
>
>
> #include <vtkSmartPointer.h>
> #include <vtkSphereSource.h>
> #include <vtkPolyData.h>
> #include <vtkTransform.h>
> #include <vtkTransformPolyDataFilter.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkDataSetMapper.h>
> #include <vtkActor.h>
> #include <vtkProperty.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkAssembly.h>
> #include <vtkAppendFilter.h>
> #include <vtkUnstructuredGrid.h>
> #include <vtkRenderWindowInteractor.h>
>
>
>
>
> void merge_polyData_in_viz(int actor_strt_ID,vtkSmartPointer<vtkRenderer>
> renderer, vtkSmartPointer<vtkAppendFilter> appendFilter
> ,vtkSmartPointer<vtkAssembly> assembly)
> {
>         vtkSmartPointer<vtkActorCollection> actors =
> vtkSmartPointer<vtkActorCollection>::New();
>         actors = renderer->GetActors();
>         actors->InitTraversal();
>
>         //skip the first actor_strt_ID actors
>         for (vtkIdType a = 0; a < actor_strt_ID; ++a)
>         {
>           vtkActor * actor = actors->GetNextActor();
>         }
>
>         for (vtkIdType a = actor_strt_ID; a < actors->GetNumberOfItems();
> ++a)
>         {
>           vtkActor * actor = actors->GetNextActor();
>           assembly->AddPart(actor);
>           vtkSmartPointer<vtkPolyData>  pd =
> vtkPolyData::SafeDownCast(actor->GetMapper()->GetInput());
>           vtkSmartPointer<vtkUnstructuredGrid> ug =
> vtkSmartPointer<vtkUnstructuredGrid>::New();
>           ug->SetPoints(pd->GetPoints());
>           appendFilter->AddInputData(pd);
>           appendFilter->AddInputData(ug);
>           appendFilter->Update();
>         }
>
>
> }
>
>
> int main(int, char *[])
> {
>
>         // Create the polydata geometry
>
>   vtkSmartPointer<vtkSphereSource> sphereSource =
>     vtkSmartPointer<vtkSphereSource>::New();
>   sphereSource->Update();
>
>   // Set up the actor to display the untransformed polydata
>
>   vtkSmartPointer<vtkPolyDataMapper> originalMapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>   originalMapper->SetInputConnection(sphereSource->GetOutputPort());
>
>   vtkSmartPointer<vtkActor> originalActor =
>     vtkSmartPointer<vtkActor>::New();
>   originalActor->SetMapper(originalMapper);
>   originalActor->GetProperty()->SetColor(1,0,0);
>
>   // Set up the transform filter
>
>   vtkSmartPointer<vtkTransform> translation =
>     vtkSmartPointer<vtkTransform>::New();
>   translation->Translate(1.0, 2.0, 3.0);
>
>   vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
>     vtkSmartPointer<vtkTransformPolyDataFilter>::New();
>   transformFilter->SetInputConnection(sphereSource->GetOutputPort());
>   transformFilter->SetTransform(translation);
>   transformFilter->Update();
>
>   // Set up the actor to display the transformed polydata
>
>   vtkSmartPointer<vtkPolyDataMapper> transformedMapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>   transformedMapper->SetInputConnection(transformFilter->GetOutputPort());
>
>   vtkSmartPointer<vtkActor> transformedActor =
>     vtkSmartPointer<vtkActor>::New();
>   transformedActor->SetMapper(transformedMapper);
>   transformedActor->GetProperty()->SetColor(0,1,0);
>
>
>   // Set up the rest of the visualization pipeline
>   vtkSmartPointer<vtkRenderer> renderer =
>      vtkSmartPointer<vtkRenderer>::New();
>    renderer->AddActor(originalActor);
>    renderer->AddActor(transformedActor);
>    renderer->SetBackground(.3, .6, .3); // Set renderer's background color
> to green
>
>    vtkSmartPointer<vtkRenderWindow> renderWindow =
>      vtkSmartPointer<vtkRenderWindow>::New();
>    renderWindow->AddRenderer(renderer);
>
>    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>      vtkSmartPointer<vtkRenderWindowInteractor>::New();
>    renderWindowInteractor->SetRenderWindow(renderWindow);
>
>    renderWindowInteractor->Start();
>
>    /////////////////////////////////////////addional code
> /////////////////////////////////////////////////
>
>    //merge two actors to create a new actor
>    vtkSmartPointer<vtkActor> merged_actor =
> vtkSmartPointer<vtkActor>::New();
>    vtkSmartPointer<vtkAppendFilter> appendFilter =
> vtkSmartPointer<vtkAppendFilter>::New();
>    vtkSmartPointer<vtkAssembly> asmbly =
> vtkSmartPointer<vtkAssembly>::New();
>    merge_polyData_in_viz(0,renderer, appendFilter,asmbly);
>
>         //new actor and mapper
>         vtkSmartPointer<vtkDataSetMapper> merged_mapper =
> vtkSmartPointer<vtkDataSetMapper>::New();
>         merged_mapper->SetInputConnection(appendFilter->GetOutputPort());
>         merged_actor->SetMapper(merged_mapper);
>
>         //trying to get points of new polyData
>         vtkSmartPointer<vtkPolyData>  pd =
> vtkPolyData::SafeDownCast(merged_actor->GetMapper()->GetInput());
>         pd->GetPoints();
>
>
>
>
>    return EXIT_SUCCESS;
>
> }
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170913/0bcdec70/attachment.html>


More information about the vtkusers mailing list