[vtkusers] Problem with vtkXMLPImageDataWriter

Paul McGuinness mcguinpg at maths.tcd.ie
Fri Jul 25 11:17:00 EDT 2003


Hi All,

I am writing data to a file using vtkXMLPImageDataWriter with number of
pieces set to 4. Shouldn't I get the follwing data files:
voldata.pvti
voldata0.vti
voldata1.vti
voldata2.vti
voldata3.vti

but only the first two of these get created, I have tried doing the
program in parallel but I stil have the same problem, only the first two
files get created.

voldata.pvti looks like:

<?xml version="1.0"?>
<VTKFile type="PImageData" version="0.1" byte_order="LittleEndian"
compressor="vtkZLibDataCompressor">
  <PImageData WholeExtent="0 25 0 25 0 25" GhostLevel="0" Origin="-0.5
-0.5 -0.5" Spacing="0.04 0.04 0.04">
    <PPointData Scalars="Scalars_">
      <PDataArray type="Float32" Name="Scalars_"/>
    </PPointData>
    <Piece Extent="0 25 0 12 0 12" Source="voldata0.vti"/>
    <Piece Extent="0 25 12 25 0 12" Source="voldata1.vti"/>
    <Piece Extent="0 25 0 12 12 25" Source="voldata2.vti"/>
    <Piece Extent="0 25 12 25 12 25" Source="voldata3.vti"/>
  </PImageData>
</VTKFile>

and voldata0.vti looks like:
<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian"
compressor="vtkZLibDataCompressor">
  <ImageData WholeExtent="0 25 0 12 0 12" Origin="-0.5 -0.5 -0.5"
Spacing="0.04 0.04 0.04">
    <Piece Extent="0 25 0 12 0 12">
      <PointData Scalars="Scalars_">
        <DataArray type="Float32" Name="Scalars_" format="appended"
offset="0"           />
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </ImageData>
  <AppendedData encoding="base64">
-----I left the data out because it took up too much space----
  </AppendedData>
</VTKFile>

Can anyone help me with this, I don't know if the there is a problem with
vtkXMLPImageDataWriter or if I am doing something incorrectly. My source
code is below so you can see what I am doing. Has anyone used
vtkXMLPImageDataWriter before?

Thanks
Paul.



#include "vtkImageWriter.h"
#include "vtkImageReader.h"
#include "vtkPointData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkFloatArray.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkXMLImageDataWriter.h"
#include "vtkXMLImageDataReader.h"
#include "vtkXMLPImageDataWriter.h"
#include "vtkXMLPImageDataReader.h"
#include "vtkImageData.h"
#include "vtkImageWriter.h"
#include "vtkImageReader.h"
#include "vtkDataSet.h"
#include "vtkExtentTranslator.h"

main ()
{

  float sp, z, y, x, s;
int i, j, k,  kOffset, jOffset, offset,h;

  vtkImageData *vol = vtkImageData::New();
  vol->SetDimensions(26,26,26);
  vol->SetOrigin(-0.5,-0.5,-0.5);
  sp =1.0/25.0;
  vol->SetSpacing(sp,sp,sp);

  vtkFloatArray *scalars =vtkFloatArray::New();
                     for(k=0;k<26;k++)
                     {
                     z = -0.5 + k*sp;
                     kOffset = k*26*26;

                     for(j=0; j<26; j++)
                     {
                     y = -0.5 +j*sp;
                     jOffset = j*26;

                     for(i=0;i<26;i++)
                     {
                     x = -0.5 + i*sp;
                     s = x*x + y*y + z*z - (0.4*0.4);
                     offset = i + jOffset + kOffset;
                     scalars->InsertTuple1(offset,s);
                     }
                     }
                     }

  vol->GetPointData()->SetScalars(scalars);

//------------------ Write Data ---------------------------

vtkXMLPImageDataWriter *writer =   vtkXMLPImageDataWriter::New();
    writer->SetInput(vol);
    writer->SetNumberOfPieces(4);

writer->SetFileName("voldata.pvti");
    writer->Write();


//----------------- Read Data ---------------------------
vtkXMLPImageDataReader *reader  = vtkXMLPImageDataReader::New();
reader->SetFileName("voldata.pvti");


  vtkContourFilter *contour = vtkContourFilter::New();
      contour->SetInput(reader->GetOutput());
      contour->SetValue(0,0);

  vtkPolyDataMapper *volMapper = vtkPolyDataMapper::New();
      volMapper->SetInput(contour->GetOutput());
      volMapper->ScalarVisibilityOff();
  vtkActor *volActor = vtkActor::New();
      volActor->SetMapper(volMapper);



  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);


  renderer->AddActor(volActor);
      renderer->SetBackground(1,1,1);
  renWin->SetSize(200,200);

  // interact with data

  renWin->Render();
  iren->Start();

  // Clean up
  renderer->Delete();
  renWin->Delete();
  iren->Delete();
  vol->Delete();
  scalars->Delete();
  contour->Delete();
  volMapper->Delete();
  volActor->Delete();
}






More information about the vtkusers mailing list