[vtk-developers] Trouble with vtkTemplateMacro
David Doria
daviddoria+vtk at gmail.com
Thu Apr 1 12:55:35 EDT 2010
On Thu, Apr 1, 2010 at 12:24 PM, Moreland, Kenneth <kmorel at sandia.gov> wrote:
> I think the main problem is that the declaration
>
> void* point[3];
>
> is not doing what you think it is doing. This is creating an array of
> arrays. What you want is a single array of three values, but you can’t do
> that with void for obvious reasons.
>
> I don’t think using a templated function to return a type is really what you
> want to do. In fact, all you’re really trying to do is equivalent to
> calling GetVoidPointer(i*3). Using this template only makes sense of your
> are copying into another vtkDataArray of the same type or accumulated things
> to a known type (like double). Based on your recent emails, I think you
> want something like this.
>
> template<typename T>
> void ComputePointsCentroid(const T *data, vtkIdType numpoints, double
> centroid[3])
> {
> centroid[0] = centroid[1] = centroid[2] = 0.0;
> for (vtkIdType i = 0; i < numpoints; i++)
> {
> centroid[0] += data[0];
> centroid[1] += data[1];
> centroid[2] += data[2];
> data += 3;
> }
> centroid[0] /= numpoints;
> centroid[1] /= numpoints;
> centroid[2] /= numpoints;
> }
>
> ...
>
> double centroid[3];
> switch(this->Data->GetDataType())
> {
> vtkTemplateMacro(ComputePointsCentroid(static_cast<VTK_TT*>(this->Data->GetVoidPointer(0)),
> this->GetNumberOfPoints(), centroid));
> }
>
> Hope that helps.
>
> -Ken
I see - I was trying to get the vtkXYZArray and then call
GetTupleValue. This way seems reasonable (and works!). Thanks Ken!
Thanks,
David
More information about the vtk-developers
mailing list