[Paraview] vtu file format

Dominik Szczerba domi at vision.ee.ethz.ch
Tue Jan 3 05:24:18 EST 2006


this is really basic VTK stuff, probabely you could do it also in a
script like tcl or python. An example sketch (just change i/o formats):

#include <cassert>
#include <vtkCell.h>
#include <vtkCellData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUnstructuredGridReader.h>
#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredGridReader.h>
#include <vtkXMLStructuredGridWriter.h>
#include <vtkZLibDataCompressor.h>

int main(int argc, char *argv[]){
  assert(argc>=3);
  cout << "Reading vtk-file\n";
  vtkStructuredGridReader* reader = vtkStructuredGridReader::New();
  reader->SetFileName(argv[1]);

  //vtkUnstructuredGrid* grid = reader->GetOutput();
  vtkStructuredGrid* grid = reader->GetOutput();
  grid->Update();

  vtkZLibDataCompressor* myZlibCompressor  = vtkZLibDataCompressor::New();
  myZlibCompressor->SetCompressionLevel(9);

  //write
  //vtkXMLUnstructuredGridWriter* writer
vtkXMLUnstructuredGridWriter::New();
  vtkXMLStructuredGridWriter* writer = vtkXMLStructuredGridWriter::New();
  cout << "Writing vtk xml file\n";
  writer->SetInput(grid);
  writer->SetFileName(argv[2]);
  //writer->SetDataModeToBinary();
  writer->SetCompressor(myZlibCompressor);
  writer->Write();

  reader->Delete();
  writer->Delete();
  return 0;
}

Npow it works OK but I am suspicious about compression. Dunno why the
output is WAY bigger than original legacy gzipped. This shouldnt be the
case, should it?
Dominik

Thierry Dubuis wrote:
> Please, could you send the C++ code.
> 
> THierry Dubuis
> 
> Dominik Szczerba wrote:
> 
>> what I do is export legacy binary files from my C++ code and then
>> writing a small external vtkConvert* (10 lines of VTK code) utility to
>> convert the legacy files into xml. This works 100%.
>> --dsz
>>
>> Thierry Dubuis wrote:
>>  
>>
>>> No, sorry I did't find any information about that.
>>> There are information about XML part, binary datas must be encryted with
>>> Base64 algorithm and they could be compressed or not,
>>> but no information about datas organization.
>>>
>>> But perhaps must I ask this question to the VTK developpers group ?
>>>
>>> Thanks again for your help,
>>>
>>> Thierry Dubuis
>>>
>>> Dominik Szczerba wrote:
>>>
>>>   
>>>
>>>> on vtk.org in tech docs there is a pdf decribing the vtk formats. does
>>>> it not provide answers to your questions?
>>>> --dsz
>>>>
>>>> Thierry Dubuis wrote:
>>>>
>>>>
>>>>     
>>>>
>>>>> Hello,
>>>>>
>>>>> I made the test and it's the same thing in Little and Big Endian.
>>>>> I made another test, in Little Endian I add the size of the data block
>>>>> at the beginnig of this block In the PointData and CellData
>>>>> Paraview load my case and the results are Ok.
>>>>>
>>>>> Is it the same organization in the Coordinates, Connectivity,
>>>>> Offset and
>>>>> Types Blocks ?
>>>>>
>>>>> Bests regards,
>>>>> Thierry Dubuis
>>>>>
>>>>> Dominik Szczerba wrote:
>>>>>
>>>>>  
>>>>>
>>>>>       
>>>>>
>>>>>> I though you said you had used little endian when producing your
>>>>>> files.
>>>>>> If you get errors the first thing I would try is swapping bytes to
>>>>>> big
>>>>>> endian arrangement.
>>>>>> --dsz
>>>>>>
>>>>>> Thierry Dubuis wrote:
>>>>>>
>>>>>>
>>>>>>   
>>>>>>         
>>>>>>
>>>>>>> Why ?
>>>>>>>
>>>>>>> With the big endian I need no size information ?
>>>>>>>
>>>>>>> Thierry Dubuis
>>>>>>>
>>>>>>> Dominik Szczerba wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     
>>>>>>>           
>>>>>>>
>>>>>>>> VTK uses big endian
>>>>>>>> --dsz
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>  
>>>>>>>>       
>>>>>>>>             
>>>>>>>>
>>>>>>>>> So first I try to write my data on PC in Little Endian and
>>>>>>>>> crypted in
>>>>>>>>> Base64.
>>>>>>>>> When I try to load it in Paraview 2.5 I have an error, I debug and
>>>>>>>>> find
>>>>>>>>> Paraview reads 4 characters which is the size of the following
>>>>>>>>> binary
>>>>>>>>> block ???
>>>>>>>>>
>>>>>>>>> Have a doc which more precision about this file format than the
>>>>>>>>> vtk
>>>>>>>>> file
>>>>>>>>> formats for VTK Version 4.2 (where I don't find the information
>>>>>>>>> about
>>>>>>>>> this block size) ?
>>>>>>>>>
>>>>>>>>> Thanks for your help.
>>>>>>>>>
>>>>>>>>> Best regards,
>>>>>>>>> Thierry Dubuis
>>>>>>>>> _______________________________________________
>>>>>>>>> ParaView mailing list
>>>>>>>>> ParaView at paraview.org
>>>>>>>>> http://www.paraview.org/mailman/listinfo/paraview
>>>>>>>>>
>>>>>>>>>                             
>>>>>>>>
>>>>>>>>                       
>>>>>>
>>>>>>
>>>>>>            
>>>>
>>>>
>>>>
>>>>     
>>
>>
>>  
>>

-- 
Dominik Szczerba, Dr.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi


More information about the ParaView mailing list