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

David Doria daviddoria+vtk at gmail.com
Sat Oct 24 12:34:54 EDT 2009


On Sat, Oct 24, 2009 at 12:13 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> Try this:
> #include "vtkSmartPointer.h"
> #include "vtkTriangle.h"
> #include "vtkPoints.h"
>
> void TriangleInfo ( vtkTriangle* Triangle );
>
> main (int, char*[])
> {
>
>  vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
>  triangle->GetPointIds()->SetId ( 0, 0 );
>  triangle->GetPointIds()->SetId ( 1, 1 );
>  triangle->GetPointIds()->SetId ( 2, 2 );
>
>  triangle->GetPoints()->InsertPoint ( 0, 1.0, 2.0, 3.0 );
>  triangle->GetPoints()->InsertPoint ( 1, 4.0, 5.0, 6.0 );
>  triangle->GetPoints()->InsertPoint ( 2, 7.0, 8.0, 9.0 );
>
>
>  TriangleInfo(triangle);
>  return EXIT_SUCCESS;
> }
>
> 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;
>    }
> }


Yea, that works.  Can you explain a little bit about what is going on?
The way I had done it, I thought SetPoints() was doing the same thing
as what you've done here with InsertPoint(...)? Is this actually
demonstrating two very different functionalities?: 1) the ability to
have a bunch of triangles that simply index into a giant point list
and 2) the ability to have a triangle which actually contains the data
about itself?

Also, I changed Your InsertPoint calls to SetPoint with the same
arguments and it still worked. That seems more intuitive to me, as it
makes it seem like the triangle already has 3 slots for points and you
just have to set them. I thought "Insert*" was always for when you
wanted to add to a list, like an "InsertNext*"? What does it mean to
Insert into an already existing slot, as done here with InsertPoint(0,
...)? How is it different than SetPoint(0,...)?

Thanks for your help,

David



More information about the vtkusers mailing list