[vtkusers] How to pass a triangle without its point set?

David Doria daviddoria+vtk at gmail.com
Fri Oct 23 11:25:50 EDT 2009


If I make a triangle like this:
	vtkSmartPointer<vtkTriangle> T = vtkSmartPointer<vtkTriangle>::New();

	//setup points
	vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();
	Points->InsertNextPoint ( 1.0, 2.0, 3.0 );
	Points->InsertNextPoint ( 4.0, 5.0, 6.0 );
	Points->InsertNextPoint ( 7.0, 8.0, 9.0 );

	vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
	triangle->GetPointIds()->SetId ( 0, 0 );
	triangle->GetPointIds()->SetId ( 1, 1 );
	triangle->GetPointIds()->SetId ( 2, 2 );

Then I want to do something with it in a function, I tried to do this:

void TriangleInfo ( vtkTriangle* Triangle )
{
	vtkPoints* Points = Triangle->GetPoints();

	for ( unsigned int i = 0; i < 3; i++ )
	{
		double p[3];
		Points->GetPoint ( i,p );
		std::cout << "p" << i << ": " << p[0] << " " << p[1] << " " << p[2]
<< std::endl;
	}
}

but the points are all zero.

This works:

void TriangleInfo (vtkPoints* Points, vtkTriangle* Triangle)
{
  for ( unsigned int i = 0; i < 3; i++ )
  {
    double p[3];
    unsigned int id = Triangle->GetPointId(i);
    Points->GetPoint(id, p);
    std::cout << "p" << i << ": " << p[0] << " " << p[1] << " " <<
p[2] << std::endl;
  }
}

but it seems kind of annoying to have to pass around the points
everywhere you need a triangle. Is there a way to get the coordinates
of a triangles points without having access to the original points
array?

Thanks,

David



More information about the vtkusers mailing list