[vtkusers] Attaching additional metadata information to vtkDoubleArray

David E DeMarle dave.demarle at kitware.com
Tue Feb 7 13:39:44 EST 2012


Keys are usually created through a static method in a particular
class, and thus are tied to that class. Location is the name of the
class.

Read vtkInformationKey.h carefully, especially the macros at the
bottom. Most or maybe all of VTK uses those macros to create the keys
it uses rather than doing it by hand like you are so far.

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909



On Tue, Feb 7, 2012 at 11:22 AM, Alexander Pletzer <pletzer at txcorp.com> wrote:
> Hi David,
>
> Thanks, that worked! I'm appending the example code below for future
> reference.
>
> Do we know what char *location mean below? This argument is required when
> creating the key.
>
> Best,
>
>
> --Alex
>
> // vtk includes
> #include <vtkDoubleArray.h>
> #include <vtkInformation.h>
> #include <vtkInformationDoubleVectorKey.h>
>
>
> // std includes
> #include <iostream>
>
> int main() {
>
> // create a 2-element array
>
> vtkDoubleArray* array = vtkDoubleArray::New();
> array->SetName("array");
> array->SetNumberOfComponents(1);
> array->SetNumberOfTuples(2);
> array->SetValue(0, 1.);
> array->SetValue(1, 2.);
>
> // access the info (presently none stored)
>
> vtkInformation* info = array->GetInformation();
>
> // add one attribute, a double vector
>
> const char *name = "mykey";
> const char *location = ""; // not sure what this is?
> xint length = 3;
>
> vtkInformationDoubleVectorKey *key = new vtkInformationDoubleVectorKey(name,
> location,
> length);
> double values[] = {0.1, 0.2, 0.3};
> info->Set(key, values[0], values[1],values[2]);
>
>
> info->Print(std::cout);
> array->Delete();
> // array->Delete will also delete key (do not call delete key)
>
> }
>
>
>
> On 02/06/2012 04:56 PM, David E DeMarle wrote:
>>
>> Add #include "vtkInformationDoubleVectorKey.h" and #2 should work.
>>
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 21 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-881-4909
>>
>>
>>
>> On Mon, Feb 6, 2012 at 1:21 PM, Alexander Pletzer<pletzer at txcorp.com>
>>  wrote:
>>>
>>> Hi VTK'ians,
>>>
>>> I'm trying to figure out how additional (metadata) information can be
>>> attached to vtk objects such as vtkDoubleArray. Specifically I would like
>>> to
>>> attach a vector of 3 doubles.
>>> It looks like vtkInformation acts as a hash map and is designed for that
>>> purpose. Although it is straightforward to access the vtkInformation
>>> pointer
>>> to the array using the GetInformation method, I've been unable to set
>>> key/value pairs to the vtkInformation object, mainly because I cannot
>>> figure
>>> out how to build the key, see code below.
>>>
>>> Thanks in advance for any help!
>>>
>>> Cheers,
>>>
>>> --Alex
>>>
>>> // vtk includes
>>> #include<vtkDoubleArray.h>
>>> #include<vtkInformation.h>
>>>
>>> // std includes
>>> #include<iostream>
>>>
>>>
>>> int main() {
>>> // creation of a simple array
>>> vtkDoubleArray* array = vtkDoubleArray::New();
>>> array->SetName("array");
>>> array->SetNumberOfComponents(1);
>>> array->SetNumberOfTuples(2);
>>> array->SetValue(0, 1.);
>>> array->SetValue(1, 2.);
>>>
>>> access the pointer to the info
>>> vtkInformation* info = array->GetInformation();
>>>
>>> // don't know how to create the key and values
>>>
>>> // THIS WON'T COMPILE
>>> vtkInformationDoubleVectorKey *key =
>>> vtkInformationDoubleVectorKey::New();
>>> /// error: no New
>>>
>>> // THIS WON'T COMPILE
>>> const char *name = "mykey";
>>> const char *location = "";
>>> int length = 3;
>>> vtkInformationDoubleVectorKey *key = new
>>> vtkInformationDoubleVectorKey(name,
>>> location,
>>> length); // invalid use of incomplete type ‘struct
>>> vtkInformationDoubleVectorKey’
>>>
>>> // build values
>>> double values[] = {1., 2., 3.};
>>>
>>> // Once I have key and values built, I want to call....
>>> info->Set(key, values, 3);
>>>
>>> info->Print(std::cout);
>>> array->Delete();
>>> }
>>>
>>>
>>>
>>>
>>> std::cout<<  "array has info "<<  array->HasInformation()<<  '\n';
>>>
>>> _______________________________________________
>>> 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
>
>



More information about the vtkusers mailing list