vtkDenseArray with custom type?

View: New views
7 Messages — Rating Filter:   Alert me  

vtkDenseArray with custom type?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I get a "no matching function" error when trying to do this:

#include <vtkSmartPointer.h>
#include <vtkDenseArray.h>

struct Point
{
  double x,y,z;
};

int main(int argc, char *argv[])
{
  Point MyPoint;
  MyPoint.x = 1.0;
  MyPoint.x = 2.0;
  MyPoint.x = 3.0;

  vtkSmartPointer<vtkDenseArray<Point> > array =
vtkSmartPointer<vtkDenseArray<double> >::New();
  array->Resize(5,5);

  array->SetValue(4,4, MyPoint);

  return 0;
}

Is this not allowed?

Thanks,

David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by Jeff Baumes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 vtkSmartPointer<vtkDenseArray<Point> > array =
vtkSmartPointer<vtkDenseArray<double> >::New();

Shouldn't this line be 

 vtkSmartPointer<vtkDenseArray<Point> > array =
vtkSmartPointer<vtkDenseArray<Point> >::New();

Jeff


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 5, 2009 at 10:08 AM, Jeff Baumes <jeff.baumes@...> wrote:
>>  vtkSmartPointer<vtkDenseArray<Point> > array =
>> vtkSmartPointer<vtkDenseArray<double> >::New();
>
> Shouldn't this line be
>  vtkSmartPointer<vtkDenseArray<Point> > array =
> vtkSmartPointer<vtkDenseArray<Point> >::New();
> Jeff
>

Yes, sorry Jeff. However, now it says
error: conversion from 'const Point' to non-scalar type 'vtkVariant' requested

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?

Thanks,

David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by Jeff Baumes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Yes, sorry Jeff. However, now it says
error: conversion from 'const Point' to non-scalar type 'vtkVariant' requested

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?

Hm. Didn't realize the dependency on vtkVariant conversions. Not sure exactly how this would work. If you figure out how to write the conversion code for your new type without editing vtkVariant (or if anyone else has ideas), let the list know. It would be nice if the new vtkArray classes could handle arbitrary data types.

Jeff 

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by Jeff Baumes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 6, 2009 at 11:27 AM, Jeff Baumes <jeff.baumes@...> wrote:

>> 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

Tim and Jeff,

Excellent, simply adding a vtkVariant() operator worked perfectly (it
has to be const though).

It is just a bit awkward to have to do this, but it surely is not a
good enough argument to have someone implement boost::any haha.

Thanks for the help - here's a demo for anyone else interested:

#include <vtkSmartPointer.h>
#include <vtkDenseArray.h>

struct Point
{
  double x,y,z;

  operator vtkVariant() const { return vtkVariant(); }
};

int main(int argc, char *argv[])
{
  Point MyPoint;
  MyPoint.x = 1.0;
  MyPoint.y = 2.0;
  MyPoint.z = 3.0;
  vtkstd::cout << MyPoint.x << " " << MyPoint.y << " " << MyPoint.z <<
vtkstd::endl;

  vtkSmartPointer<vtkDenseArray<Point> > array =
vtkSmartPointer<vtkDenseArray<Point> >::New();
  array->Resize(5,5);

  array->SetValue(4,4, MyPoint);

  Point RetrievedPoint = array->GetValue(4,4);
  vtkstd::cout << RetrievedPoint.x << " " << RetrievedPoint.y << " "
<< RetrievedPoint.z << vtkstd::endl;
  return 0;
}

Thanks,

David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

Re: vtkDenseArray with custom type?

by David Doria-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 12, 2009 at 1:50 PM, David Doria <daviddoria+vtk@...> wrote:

> On Fri, Nov 6, 2009 at 11:27 AM, Jeff Baumes <jeff.baumes@...> wrote:
>>> 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
>
> Tim and Jeff,
>
> Excellent, simply adding a vtkVariant() operator worked perfectly (it
> has to be const though).
>
> It is just a bit awkward to have to do this, but it surely is not a
> good enough argument to have someone implement boost::any haha.
>
> Thanks for the help - here's a demo for anyone else interested:
>
> #include <vtkSmartPointer.h>
> #include <vtkDenseArray.h>
>
> struct Point
> {
>  double x,y,z;
>
>  operator vtkVariant() const { return vtkVariant(); }
> };
>
> int main(int argc, char *argv[])
> {
>  Point MyPoint;
>  MyPoint.x = 1.0;
>  MyPoint.y = 2.0;
>  MyPoint.z = 3.0;
>  vtkstd::cout << MyPoint.x << " " << MyPoint.y << " " << MyPoint.z <<
> vtkstd::endl;
>
>  vtkSmartPointer<vtkDenseArray<Point> > array =
> vtkSmartPointer<vtkDenseArray<Point> >::New();
>  array->Resize(5,5);
>
>  array->SetValue(4,4, MyPoint);
>
>  Point RetrievedPoint = array->GetValue(4,4);
>  vtkstd::cout << RetrievedPoint.x << " " << RetrievedPoint.y << " "
> << RetrievedPoint.z << vtkstd::endl;
>  return 0;
> }
>
> Thanks,
>
> David
>

Another observation - it seems to work fine without adding anything
about Variant if you make a vtkDenseArray of a VTK class (derived from
vtkObject).

Thanks,

David
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers