[vtkusers] Attaching additional metadata information to vtkDoubleArray

Alexander Pletzer pletzer at txcorp.com
Mon Feb 6 13:21:29 EST 2012


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




More information about the vtkusers mailing list