[vtkusers] Export mesh of cutting plane
Fernando Nellmeldin
f.nellmeldin at open-engineering.com
Thu Sep 28 10:43:46 EDT 2017
Hello.
I have a method to cut a volume in a vtkUnstructuredGrid given a vtkPlane.
I'm using vtkTableBasedClipDataSet to extract half of the model, also as
vtkUnstructuredGrid. This is working.
Now, I would like to obtain ONLY the surface of the cut, than means: I want
a vtkUnstructuredGrid with the nodes and faces being on the surface of the
cut.
How can this be achieved?
I tried using vtkCutter with vtkStripper but the mesh I get doesn't have
any cells, only the points and their associated data.
Here's how my code looks like.
Thank You!
vtkSmartPointer<vtkUnstructuredGrid> model =
vtkSmartPointer<vtkUnstructuredGrid>::New();
// fill the ugrid ...
// Create The Plane to cut
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(0.0, 0.0, 0.0);
plane->SetNormal(1.0, 0, 0);
// Code to cut the model in half
vtkSmartPointer<vtkTableBasedClipDataSet> clipDataSet =
vtkSmartPointer<vtkTableBasedClipDataSet>::New();
clipDataSet->SetClipFunction(plane);
clipDataSet->InsideOutOn();
clipDataSet->GenerateClippedOutputOn();
clipDataSet->SetInputConnection(model->GetProducerPort());
clipDataSet->Update();
// This has half the model, this is Ok but not what I want
vtkSmartPointer<vtkUnstructuredGrid> halfModel = clipDataSet->GetOutput();
////****////
// BEGINS code not working to extract the surface of the cut
vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
cutter->SetCutFunction(plane);
cutter->SetInputConnection(model->GetProducerPort());
cutter->Update();
vtkSmartPointer<vtkStripper> stripper = vtkSmartPointer<vtkStripper>::New();
stripper->SetInputConnection(cutter->GetOutputPort());
stripper->Update();
vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
pd->SetPoints(stripper->GetOutput()->GetPoints());
pd->SetPolys(stripper->GetOutput()->GetLines());
vtkSmartPointer<vtkUnstructuredGrid> clipped =
vtkSmartPointer<vtkUnstructuredGrid>::New();
clipped->ShallowCopy(pd);
// Here I see that there is no Cells
clipped->Print(std::cout);
// ENDS code to extract the surface of the cut
////****////
// Write the unstructured grid
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName("d:/unstructuredGrid.vtu");
writer->SetInput(clipped);
writer->SetDataModeToAscii();
writer->Write();
// file doesnt have any cell, only points and pointdata
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/1e6f66bb/attachment.html>
More information about the vtkusers
mailing list