[vtkusers] Generic vtkMatrix

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Nov 25 11:28:30 EST 2009


On Wednesday 25 November 2009 11:07:01 David Doria wrote:
> On Wed, Nov 25, 2009 at 10:44 AM, Aashish Chaudhary <
> 
> aashish.chaudhary at kitware.com> wrote:
> > I think it will be really useful to have it. Last week I was looking for
> > something similar...
> >
> > Also Passing array (pointers) is not the best thing without passing the
> > size of the array which I think will be gone if we pass the vectors (or
> > there references)
> >
> > Regards
> 
> That is a very good point. Also, you could then even return objects
> 
> vtkPoint GetPoint(int index);
> 
> instead of
> void GetPoint(int index, double* point);

With the current VTK this would not work, as vtkObjects are allocated from the 
heap. It would be great to have lightweight objects for points and colors for 
example. They could be returned by value, and the API would be simpler but 
this API cannot be wrapped as far as I know. 
> 
> Another thing is that code readability is tremendously improved. From my
> example above, the math equations map directly to the c++ code:
> 
> c = a-b;

Wouldn't it be *c = (*a) - (*b); right now if they were vtkObject derived 
classes following the current heap based semantics?
> 
> rather than having to interpret what is going on when you see something
>  like this (or typically even much more complicated):
> 
> for(unsigned int i = 0; i < 3; i++)
> {
> c[i] = a[i] - b[i];
> }
> 
I agree that the code is more expressive. I spent a lot of time using Eigen 
inside the Avogadro project. Eigen allows for a very expressive syntax. 
Because of the data structure they employ it also allowed for,

std::vector<Eigen::Vector3f> points.
points.resize(3);
points[0] = Eigen::Vector3f(0.0, 1.0, 2.0);
....

You could then grab a pointer to the data, i.e. points[0].data(), and pass 
that straight to glVertexPointer as in memory it was a float[] of length n*3. 
Currently I don't think any of this could be wrapped, and so would be of less 
use. It would also not fit well with the API currently in use in VTK.

You can use vtkPoints (and now vtkPoints2D) in a similar way, but the syntax 
is not as expressive due to dealing with pointers and needing to check the 
underlying type of the array.

I will be pushing more of my work with 2D in VTK which will demonstrate some 
of the progress I have made whilst accommodating the VTK API.

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



More information about the vtkusers mailing list