[vtkusers] Write triangulated mesh from a set of points
acimpo
andrei.cimpoeru at cfms.org.uk
Thu Aug 30 12:18:15 EDT 2018
Hi folks,
I have the code below which generates a set of of points (5 in each
direction) and then connects them in triangles. I played with the
connectivity but it seems that I am getting the ordering wrong. Do you have
any suggestions on how to connect those points without getting any
overlapping/intersections? Any help will be much appreciated. Please see the
code below.
*#include <vtkCellArray.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkTriangle.h>
int main(int argc, char *argv[])
{
//setup points (geometry)
int numPoints=5;
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> triangles =
vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkTriangle> triangle =
vtkSmartPointer<vtkTriangle>::New();
//int pid=0;
for (unsigned int j =0; j<numPoints;j++)
{
for (unsigned int i =0; i<numPoints;i++)
{
points->InsertNextPoint ( i, j,0 );
}
}
//pid = pid + 1;
for (int i=0; i<6;i++)
{
vtkIdType pid[1];
std::cout<<pid[1]<<std::endl;
//vtkSmartPointer<vtkTriangle> triangle =
vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId ( 0, i );
triangle->GetPointIds()->SetId ( 1, i+1 );
triangle->GetPointIds()->SetId ( 2, i+2 );
triangles->InsertNextCell ( triangle );
}
//triangles->InsertNextCell ( triangle );
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
//set the points and vertices we created as the geometry and topology of
the polydata
polydata->SetPoints ( points );
polydata->SetPolys ( triangles );
std::cout << "There are " << polydata->GetNumberOfCells() << " cells." <<
std::endl;
std::cout << "There are " << polydata->GetNumberOfPoints() << " points."
<< std::endl;
//write the polydata to a file
vtkSmartPointer<vtkXMLPolyDataWriter> writer =
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName ( "triangles.vtp" );
#if VTK_MAJOR_VERSION <= 5
writer->SetInput ( polydata );
#else
writer->SetInputData ( polydata );
#endif
writer->Write();
return EXIT_SUCCESS;
}
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list