Storing Metadata with VTK objects

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Storing Metadata with VTK objects

zmantorn
I have tried asking this question before without response so i am going to try to explain one of my use cases in hopes of clarifying the question.

I have vtkactors that are polyline and/or polygon objects that I am rendering. These polyline/polygons represent National Weather Service watch and warning areas. I would like to allow the user to pick a polygon and I will pop up a window with the watch/warning information text. I need a way to store some kind of ID with the actor so that when it is picked I am able to look up the correct informative text from my database. I am struggling with finding a way to store some kind of metadata with the vtkactor that can be referenced when picked. Any help would be appreciated.

Thanks.

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Storing Metadata with VTK objects

David Gobbi
Hi Donny,

The usual way of doing this is by adding FieldData arrays to the VTK data objects:

The field data can be retrieved from the data object during a pick.

 - David


On Tue, Jun 27, 2017 at 1:56 PM, Donny Zimmerman <[hidden email]> wrote:
I have tried asking this question before without response so i am going to try to explain one of my use cases in hopes of clarifying the question.

I have vtkactors that are polyline and/or polygon objects that I am rendering. These polyline/polygons represent National Weather Service watch and warning areas. I would like to allow the user to pick a polygon and I will pop up a window with the watch/warning information text. I need a way to store some kind of ID with the actor so that when it is picked I am able to look up the correct informative text from my database. I am struggling with finding a way to store some kind of metadata with the vtkactor that can be referenced when picked. Any help would be appreciated.

Thanks.


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Storing Metadata with VTK objects

zmantorn
Thanks David! That was exactly what I was looking for. Can I store a string array into FieldData?

On Tue, Jun 27, 2017 at 3:17 PM, David Gobbi <[hidden email]> wrote:
Hi Donny,

The usual way of doing this is by adding FieldData arrays to the VTK data objects:

The field data can be retrieved from the data object during a pick.

 - David


On Tue, Jun 27, 2017 at 1:56 PM, Donny Zimmerman <[hidden email]> wrote:
I have tried asking this question before without response so i am going to try to explain one of my use cases in hopes of clarifying the question.

I have vtkactors that are polyline and/or polygon objects that I am rendering. These polyline/polygons represent National Weather Service watch and warning areas. I would like to allow the user to pick a polygon and I will pop up a window with the watch/warning information text. I need a way to store some kind of ID with the actor so that when it is picked I am able to look up the correct informative text from my database. I am struggling with finding a way to store some kind of metadata with the vtkactor that can be referenced when picked. Any help would be appreciated.

Thanks.



_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Storing Metadata with VTK objects

David Gobbi
Yes, you can store any kind of array in the FieldData, and you can give each array any name that you want.

On Tue, Jun 27, 2017 at 2:49 PM, Donny Zimmerman <[hidden email]> wrote:
Thanks David! That was exactly what I was looking for. Can I store a string array into FieldData?

On Tue, Jun 27, 2017 at 3:17 PM, David Gobbi <[hidden email]> wrote:
Hi Donny,

The usual way of doing this is by adding FieldData arrays to the VTK data objects:

The field data can be retrieved from the data object during a pick.

 - David


On Tue, Jun 27, 2017 at 1:56 PM, Donny Zimmerman <[hidden email]> wrote:
I have tried asking this question before without response so i am going to try to explain one of my use cases in hopes of clarifying the question.

I have vtkactors that are polyline and/or polygon objects that I am rendering. These polyline/polygons represent National Weather Service watch and warning areas. I would like to allow the user to pick a polygon and I will pop up a window with the watch/warning information text. I need a way to store some kind of ID with the actor so that when it is picked I am able to look up the correct informative text from my database. I am struggling with finding a way to store some kind of metadata with the vtkactor that can be referenced when picked. Any help would be appreciated.

Thanks.




_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Storing Metadata with VTK objects

zmantorn
David your solution is working great. I am using C++/CLI (.NET) so I am going to post my code in case anyone else needs this functionality with .NET strings.

#include <msclr\marshal_cppstd.h>

using namespace msclr::interop;     

String^ idnstr = cap->Identifier; 

std::string idstr = marshal_as<std::string>(idnstr);

vtkSmartPointer<vtkStringArray> idarray = vtkSmartPointer<vtkStringArray>::New();
idarray->SetName("CapId");
idarray->InsertNextValue(idstr.c_str());

polyData->GetFieldData()->AddArray(idarray);

Here is the code to retrieve:

int* clickPos = m_iren->GetEventPosition();

// Pick from this location.
vtkSmartPointer<vtkPropPicker>  picker = vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, m_caprenderer->GetRenderer());


if (picker->GetActor() != NULL)
{
   vtkStringArray* strarr = reinterpret_cast<vtkStringArray*>(picker->GetActor()->GetMapper()->GetInput()->GetFieldData()->GetAbstractArray("CapId"));
   String^ capid = gcnew String(strarr->GetValue(0));
   System::Diagnostics::Debug::WriteLine("Cap ID from pick: " + capid);
}

Not sure if there is a better way to retrieve the array than "picker->GetActor()->GetMapper()->GetInput()->GetFieldData()->GetAbstractArray("CapId")" but it works.

Thanks

On Tue, Jun 27, 2017 at 5:39 PM, David Gobbi <[hidden email]> wrote:
Yes, you can store any kind of array in the FieldData, and you can give each array any name that you want.

On Tue, Jun 27, 2017 at 2:49 PM, Donny Zimmerman <[hidden email]> wrote:
Thanks David! That was exactly what I was looking for. Can I store a string array into FieldData?

On Tue, Jun 27, 2017 at 3:17 PM, David Gobbi <[hidden email]> wrote:
Hi Donny,

The usual way of doing this is by adding FieldData arrays to the VTK data objects:

The field data can be retrieved from the data object during a pick.

 - David


On Tue, Jun 27, 2017 at 1:56 PM, Donny Zimmerman <[hidden email]> wrote:
I have tried asking this question before without response so i am going to try to explain one of my use cases in hopes of clarifying the question.

I have vtkactors that are polyline and/or polygon objects that I am rendering. These polyline/polygons represent National Weather Service watch and warning areas. I would like to allow the user to pick a polygon and I will pop up a window with the watch/warning information text. I need a way to store some kind of ID with the actor so that when it is picked I am able to look up the correct informative text from my database. I am struggling with finding a way to store some kind of metadata with the vtkactor that can be referenced when picked. Any help would be appreciated.

Thanks.





_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...