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

Bill Lorensen bill.lorensen at gmail.com
Sat Oct 24 12:13:58 EDT 2009


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;
    }
}


On Fri, Oct 23, 2009 at 11:25 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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