[vtkusers] example of vtkPolyDataConnectivityFilter

David Doria daviddoria+vtk at gmail.com
Wed Dec 23 21:15:00 EST 2009


On Wed, Dec 23, 2009 at 8:42 PM, Jinyoung Hwang <hwangjinyoung at gmail.com> wrote:
> Hi all,
>
> I implemented an example of vtkPolyDataConnectivityFilter, because
> vtk wiki do not provide it yet.
> You can use it as below codes.
>
> Thanks,
>
> Jinyoung
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> #include "vtkSmartPointer.h"
> #include "vtkStructuredPointsReader.h"
> #include "vtkMarchingCubes.h"
> #include "vtkPolyDataConnectivityFilter.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkActor.h"
> #include "vtkProperty.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
>
> int main(int argc, char* argv[])
> {
>  // data load
>  vtkSmartPointer<vtkStructuredPointsReader> reader =
> vtkSmartPointer<vtkStructuredPointsReader>::New();
>  reader->SetFileName("test.vtk");
>  reader->Update();
>  // MC is used to display in 3D
>  vtkSmartPointer<vtkMarchingCubes> cubes =
> vtkSmartPointer<vtkMarchingCubes>::New();
>  cubes->SetInputConnection(reader->GetOutputPort());
>  cubes->ComputeNormalsOn();
>  cubes->ComputeGradientsOn();
>  cubes->SetValue(0, 20);
>  cubes->Update();
>  // this is to use remove other parts of largest region
>  // you can set specific region using
> 'SetExtractionModeToPointSeededRegions' function
>  vtkSmartPointer<vtkPolyDataConnectivityFilter> cfilter =
> vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
>  cfilter->SetInputConnection(cubes->GetOutputPort());
>  cfilter->SetExtractionModeToLargestRegion();
>  //cfilter->SetExtractionModeToPointSeededRegions();
>  //cfilter->SetClosestPoint(x,y,z);
>  cfilter->Update();
>  // create a mapper
>  vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
>  mapper->SetInputConnection(cfilter->GetOutputPort());
>  mapper->ScalarVisibilityOn();
>  mapper->Update();
>  // create an actor
>  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
>  actor->GetProperty()->SetColor(1,1,1);
>  actor->SetMapper(mapper);
>
>  // create a renderer
>  vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
>  renderer->AddActor(actor);
>  // create a render window
>  vtkSmartPointer<vtkRenderWindow> renwin =
> vtkSmartPointer<vtkRenderWindow>::New();
>  renwin->AddRenderer(renderer);
>
>  // create an interactor
>  vtkSmartPointer<vtkRenderWindowInteractor> iren =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>  iren->SetRenderWindow(renwin);
>  iren->Initialize();
>  iren->Start();
>  reader->Delete();
>  cubes->Delete();
>  cfilter->Delete();
>  mapper->Delete();
>  actor->Delete();
>  renderer->Delete();
>  renwin->Delete();
>  iren->Delete();
>
>  return 0;
> }
> _______________________________________________
> 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
>
>

Excellent! I have added it to the wiki here:
http://www.cmake.org/Wiki/VTK/Examples/vtkPolyDataConnectivityFilter

Note that you do not have to call Delete() on objects that you have
created with smart pointers, that is part of their power :)

I think this type of contribution back to VTK will really make a difference!

Thanks,

David



More information about the vtkusers mailing list