[vtkusers] Saving custom array class instance to *.vti file with time information

lorieul gael.lorieul at uclouvain.be
Thu Nov 12 13:24:37 EST 2015


Hello,

I wanted to know the cleanest way to save a custom array class instance
to a *.vti file with time information. I searched through the
documentation and found some threads in the mailing list archives but
could not find compelling answers (quite to my surprise… I'm sure the
information must be there somewhere…).

I am designing a C++ software that performs CFD (Computational Fluid
Dynamics) simulations. I start from known initial conditions and iterate
in time. After each iteration, I know the definition of each of the flow
variables (e.g. I know the velocity field at each time step). I want to
save this information into a *.vti file so that I can visualise it with
paraview and (for instance) animate it.

My code uses its own array class which I'll call DblArr. Hence when I
want to save a field to a file, I need to use a vtkImageData object and
copy all the data from the DblArr object into it. This means that for
each DblArr array I want to save, I need a corresponding vtkImageData
object (hence additional memory and computation costs). Is that the best
way to do so ?

Besides, how do I store the time information ? Should I call :

myImgData->GetInformation()->Set(
    vtkDataObject::DATA_TIME_STEPS(), & currentTime, 1);

Or is there a better way to do so ? (I found very little reference to
DATA_TIME_STEPS() in the documentation)

Gael Lorieul
PhD student at Université catholique de Louvain





Getting more into details :

for each DblArr that I might want to save, I instanciate a Svr_vti
object (which is another custom class). The purpose of this class is to
perform the save operation to a *.vti file. It does three things :
 1. allocating memory i.e. instanciation of vtkImageData object at the
beginning of the simulation
 2. handling the copying of data from the DblArr object to the
vtkImageData
object
 3. writing the *.vti file.

Once again, I have strong doubts that this is the best solution to my
problem…

Currently I have a class called Svr_vti which holds : (amongst other
things)
  @ a constructor 
  @ a save() member function
  @ a vtkImageData member object called _ImgData
  @ a vtkXMLImageDataWriter object called _Wrtr
  @ a reference to a DblArr called _Arr

Constructor(DblArr & MyArr) performs :

    _ImgData = vtkSmartPointer<vtkImageData>::New()
    _Wrtr    = vtkSmartPointer<vtkXMLImageDataWriter>::New()
    _Arr     = MyArr
    //
    _ImgData->SetDimensions(***,***,***);
    _ImgData->AllocateScalars( VTK_DOUBLE, * );
    _ImgData->SetOrigin(***, ***, ***);
    _ImgData->SetSpacing(***, ***, ***)
    //
    _Wrtr->SetInputData( _ImgData );


save(DblArr &) member function performs :

    for each node (i,j,k) in domain :
        double * pxl = _ImgData->GetScalarPointer(i,j,k)
        for each component in vector<DblArr *> :
            pxl[ind] = Arr(i,j,k, ind)
        }
    }
    //
    //The file name embeds the number of current time step
    //Hence the file name is different each time save() is called
    _Wrtr->SetFileName( *** ); 
    _Wrtr->Write();

Note : this is pseudo-code, it might contain syntax errors and/or
abreviations


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 863 bytes
Desc: This is a digitally signed message part
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151112/d25d9c40/attachment.sig>


More information about the vtkusers mailing list