[vtkusers] How to pass a triangle without its point set?
Yang, Jinzhong
jinzhong76 at gmail.com
Fri Oct 23 13:03:06 EDT 2009
You need to set the points to the triangle when you build it up.
triangle->SetPoints(Points);
-Jinzhong
-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
Of David Doria
Sent: Friday, October 23, 2009 10:26 AM
To: vtkusers at vtk.org
Subject: [vtkusers] How to pass a triangle without its point set?
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
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the VTK FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list