[vtkusers] Generic vtkMatrix

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Dec 2 12:02:42 EST 2009


On Wednesday 02 December 2009 11:42:16 Jeff Baumes wrote:
> > You mentioned we may be able to add some of these simple things to
> > vtkMath. These may be a few functions to kick things off:
> >
> > void MultiplyScalar(double a[3], const double s)
> >    {
> >   for(unsigned int i = 0; i < 3; i++)
> >      {
> >      a[i] *= s;
> >      }
> >    }
> >
> > void Add(double a[3], double b[3], double c[3])
> >    {
> >    //c = a+b
> >   for(unsigned int i = 0; i < 3; i++)
> >      {
> >      c[i] = a[i] + b[i];
> >      }
> >    }
> >
> > void Subtract(double a[3], double b[3], double c[3])
> >    {
> >    //c = a-b
> >   for(unsigned int i = 0; i < 3; i++)
> >      {
> >      c[i] = a[i] - b[i];
> >      }
> >    }
> 
> I've added these methods (float and double versions) to CVS.
> 
> /cvsroot/VTK/VTK/Common/Testing/Cxx/TestMath.cxx,v  <--
> Common/Testing/Cxx/TestMath.cxx
> new revision: 1.15; previous revision: 1.14
> /cvsroot/VTK/VTK/Common/vtkMath.h,v  <--  Common/vtkMath.h
> new revision: 1.136; previous revision: 1.135
> 
> That said, if someone wants to create a nicely polished vtkPoint
> object with operators, I think it should be considered for inclusion
> in VTK. I think it should be stack-based for efficiency (i.e. not a
> vtkObject subclass). It would have issues with wrapping in other
> languages, but could be nice for C++ developers. Major issues I see:
> 
>  - Will it need to support double and float?

A templated class with typedefs might be best - that way we could typedef the 
common types, keep the possibility of others open.

Something like vtkVector3d, vtkVector3f for 3D points of type double and 
float.

>  - How would it be integrated with the existing VTK API (vtkPoints, etc.)?

If the classes have something along the lines of, double data[3] as their only 
internal data, then a vtkVector3f points[5] would be a float[15] in memory - 
this could be assigned as the underlying data of a vtkPoints object of type 
VTK_FLOAT. If the class had a GetData() function that returned a pointer to 
its first element that would provide a way to give a vtkPoints object access 
to the same in-memory array. At that point reference counting would be an 
issue that would have to be dealt with if we were to allow that. 

Pure template libraries such as Eigen already use that data structure too, and 
so it would allow us to work with those libraries. Would we just want a subset 
of what something much more general, such as Eigen, supports?

If we were to relax the requirements down a little and allow it to be stack 
based then I think the integration of frequently used types would be 
relatively easy and could be excluded from wrapping.

Marcus
-- 
Marcus D. Hanwell, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4937



More information about the vtkusers mailing list