[vtkusers] vtkDenseArray with custom type?
Jeff Baumes
jeff.baumes at kitware.com
Fri Nov 6 11:27:19 EST 2009
> So since the vtkDenseArray stores everything internally as a
> vtkVariant I guess I'd have to read up on vtkVariant and write a
> conversion function from my type to vtkVariant? Is this the way to go?
Forwarded from vtkArray expert Tim Shead:
First-and-foremost, vtkDenseArray *does not* use vtkVariant for storage.
The vtkArray interface has GetVariantValue(), GetVariantValueN(),
SetVariantValue(), and SetVariantValueN() methods that the concrete array
types must implement. The vtkDenseArray and vtkSparseArray implementations
assume that your type is implicitly-convertible to vtkVariant, which is true
of all the "official" VTK types defined in vtkType.h. These methods are
there as a convenience, and for consistency with vtkAbstractArray.
So, I see several possible avenues to explore:
* Make your type implicitly convertible to vtkVariant. As long as you
aren't actually using the vtkVariant get and set methods, this conversion
doesn't have to actually do anything ... i.e. it could be as simple as
struct Point
{
// Other stuff here ...
operator vtkVariant() { return vtkVariant(); }
};
* Copy-and-paste vtkDenseArray to create your own array implementation, and
replace the vtkVariant get and set methods with non-functioning stubs.
* Convince the VTK developers to get rid of the vtkVariant get and set
methods, since they're imposing the conversion-to-vtkVariant requirement.
* Convince the VTK developers to refactor vtkVariant so it can contain any
type, not just "official" types. boost::any is an example of how it's done.
Cheers,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091106/c9c9a8a9/attachment.htm>
More information about the vtkusers
mailing list