[vtkusers] Render Triangles from cell data (vtk)
vacingforo
vacingforo at gmail.com
Wed Mar 28 09:54:53 EDT 2018
Testing the following funcion I only get one triangle of a polydata model
with the following assigned ids:
* triangle->GetPointIds()->InsertNextId(0);
triangle->GetPointIds()->InsertNextId(1);
triangle->GetPointIds()->InsertNextId(2);*
I would like to render all triangles of a polydata model in funtion of
*
trianglePoints = polydata->GetCell(tuple)->GetPoints();
vtkSmartPointer<vtkIdList> trianglePointIds =
polydata->GetCell(tuple)->GetPointIds(*);
The problem is that it only render one triangle.
*void Test::TestPolyData(vtkSmartPointer<vtkPolyData> polydata)
{
auto normals = polydata->GetCellData()->GetNormals();
vtkPoints * trianglePoints{nullptr};
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
int index = 0;
for (auto tuple = 0; tuple < normals->GetNumberOfTuples(); ++tuple)
{
trianglePoints = polydata->GetCell(tuple)->GetPoints();
vtkSmartPointer<vtkIdList> trianglePointIds =
polydata->GetCell(tuple)->GetPointIds();
vtkSmartPointer<vtkTriangle> triangle =
vtkSmartPointer<vtkTriangle>::New();
//triangle->GetPointIds()->InsertNextId(trianglePointIds->GetId(0));
//triangle->GetPointIds()->InsertNextId(trianglePointIds->GetId(1));
//triangle->GetPointIds()->InsertNextId(trianglePointIds->GetId(2));
triangle->GetPointIds()->InsertNextId(0);
triangle->GetPointIds()->InsertNextId(1);
triangle->GetPointIds()->InsertNextId(2);
vtkSmartPointer<vtkCellArray> triangles =
vtkSmartPointer<vtkCellArray>::New();
triangles->InsertNextCell ( triangle );
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(trianglePoints);
polydata->SetPolys ( triangles );
// Visualize
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polydata);
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
renderer->AddActor(actor);
}
renderer->SetBackground(.1, .2, .4); // Background color dark blue
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
}
*
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list