[vtk-developers] Trouble with vtkTemplateMacro

David Doria daviddoria+vtk at gmail.com
Thu Apr 1 12:10:21 EDT 2010


I am trying to write a function which efficiently gets the values of
all of the points in a vtkPoints.

The non-efficient, virtual calls, assuming doubles version would look like this:

    for(vtkIdType i = 0; i < this->GetNumberOfPoints(); i++)
      {
      double point[3];
      this->GetPoint(i, point);
      }

My attempt to use vtkTemplateMacro looks like this:


template<class T>
void vtkPoints::GetTypedPoint(T* data, vtkIdType i, T point[3])
{
  data->GetTupleValue(i, point);
}

void vtkPoints::GetCentroidFast(double center[3])
{
  for(vtkIdType i = 0; i < this->GetNumberOfPoints(); i++)
    {
    void* point[3];

    switch(this->Data->GetDataType())
      {
      vtkTemplateMacro(this->GetTypedPoint(static_cast<VTK_TT*>(this->Data->GetVoidPointer(0)),
i, static_cast<VTK_TT*>(point)));
      }
    }

}

I am trying to use the type of the vtkDataArray (named 'Data') to get
the correct type of the ith tuple and store it in 'point'.

For example, if Data is actually a vtkFloatArray, I'd want this to achieve:

  for(vtkIdType i = 0; i < this->GetNumberOfPoints(); i++)
    {
    float point[3];
    vtkFloatArray::SafeDownCast(Data)->GetTupleValue(i, point);
    }

Any pointers on where this has gone astray?

Thanks,

David



More information about the vtk-developers mailing list