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

Bill Lorensen bill.lorensen at gmail.com
Sat Oct 24 12:47:33 EDT 2009


vtkTriangle is a vtkCell. It only has 3 points and 3 point ids. The
points and ids are created as construction. In your original example,
how would expect triangle to know about the points you created.

SetPoint and InsertPoint have different semantics. In this case,
SetPoint is better, since range checking is not required.

>From the vtkPoints.h
  // Description:
  // Insert point into object. No range checking performed (fast!).
  // Make sure you use SetNumberOfPoints() to allocate memory prior
  // to using SetPoint().
  void SetPoint(vtkIdType id, const float x[3]) { this->Data->SetTuple(id,x);};
  void SetPoint(vtkIdType id, const double x[3]) { this->Data->SetTuple(id,x);};
  void SetPoint(vtkIdType id, double x, double y, double z);

  // Description:
  // Insert point into object. Range checking performed and memory
  // allocated as necessary.
  void InsertPoint(vtkIdType id, const float x[3])
    { this->Data->InsertTuple(id,x);};
  void InsertPoint(vtkIdType id, const double x[3])
    {this->Data->InsertTuple(id,x);};
  void InsertPoint(vtkIdType id, double x, double y, double z);

vtkPolyData has a large array of points that can be indexed.
vtkTriangle is about working with an individual to do things like
compute areas, normals, etc.

Bill

On Sat, Oct 24, 2009 at 12:34 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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
> _______________________________________________
> 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