[vtkusers] example of vtkPolyDataConnectivityFilter
Jinyoung Hwang
hwangjinyoung at gmail.com
Wed Dec 23 20:42:32 EST 2009
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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091224/db5062b2/attachment.htm>
More information about the vtkusers
mailing list