[vtkusers] Vol.cxx example + vtkImageWriter + vtkImageReader

Mathieu Malaterre Mathieu.Malaterre at creatis.insa-lyon.fr
Thu Jul 24 07:31:03 EDT 2003


Paul McGuinness wrote:
> Mathieu,
> 
> The reason why I am interested in using vtkImageReader/Writer is to create
> data files like the data files headsq/quarter.* such I can use them in
> data parallelism. I have tried your method below but the data from one
> file 'voldata.vtk' cannot be divided among multiple processors to my
> knowledge. Do you know how I can create data files like headsq/quarter?

Ah ok ! I understand now.
But why don't you take advantage of the new classes introduced by Brad 
King: vtkXMLImageDataWriter

http://www.vtk.org/doc/nightly/html/classvtkXMLImageDataWriter.html

<quote>
vtkXMLImageDataWriter writes the VTK XML ImageData file format. One 
image data input can be written into one file in any number of streamed 
pieces. The standard extension for this writer's file format is "vti". 
This writer is also used to write a single piece of the parallel file 
format.
</quote>

BTW this is going to be the new default files in VTK, so moving toward 
it is good thing !

> This is what I am trying to do exactly:
> Use vtkImageWriter to write a sphere (or any object) of a specific
> size to mulitple files like the files of headsq/quarter.*
> 
> Then use a data parallelism program similar to that of ParallelIso.cxx to
> read in these files, and measure the time difference between this
> parallel program and a similar serial program.
> 
> Use the vtkImageWriter again to write the same object of a different size,
> and do the whole procedure again.
> 
> I hope to get a graphs of data size, number of processors, and time.

Excellent work !
Could you please try with vtkXMLImageDataWriter and let me know if this 
work ?

Thanks
mathieu

> 
> Paul
> 
> 
> 
> On Wed, 23 Jul 2003, Mathieu Malaterre wrote:
> 
> 
>>Paul,
>>	Is there any particular reason why you are using vtkImageReader/Writer ?
>>
>>Try this instead:
>>
>><snip>
>>//------------------ Write Data ---------------------------
>>//vtkImageWriter *writer =   vtkImageWriter::New();
>>vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
>>    writer->SetInput(vol);
>>    writer->SetFileName("voldata.vtk");
>>    writer->Write();
>>
>>//----------------- Read Data ---------------------------
>>//vtkImageReader *reader  = vtkImageReader::New();
>>vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
>>//   reader->SetDataExtent(0,25, 0, 25, 0, 25);
>>    reader->SetFileName("voldata.vtk");
>>//   reader->SetDataSpacing(sp, sp, sp);
>>//   reader->SetDataOrigin(-0.5,-0.5,-0.5);
>><snip>
>>
>>HTH
>>mathieu
>>
>>Paul McGuinness wrote:
>>
>>>Hi vtk users,
>>>
>>>I am creating a sphere using vtkImageData and then using vtkContourFilter.
>>>This is the simple example Vol.cxx that can be found from the vtk website.
>>>The problem I am having is to write the vtkImageData using vtkImageWriter
>>>to files, and then reading these files back using vtkImageReader and then
>>>contouring the data. I don't obtain the sphere I originally got but a
>>>cubic shape that looks like a sponge.
>>>Can someone please help me understand what I am doing wrong and how I can
>>>fix this.
>>>I have attached the code below so you can see what I am talking about.
>>>
>>>Many thanks,
>>>Paul
>>>
>>>
>>>#include "vtkImageWriter.h"
>>>#include "vtkImageReader.h"
>>>#include "vtkPointData.h"
>>>#include "vtkRenderer.h"
>>>#include "vtkRenderWindow.h"
>>>#include "vtkRenderWindowInteractor.h"
>>>#include "vtkStructuredPoints.h"
>>>#include "vtkFloatArray.h"
>>>#include "vtkContourFilter.h"
>>>#include "vtkPolyDataMapper.h"
>>>#include "vtkActor.h"
>>>#include "vtkImageCast.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 ---------------------------
>>>vtkImageWriter *writer =   vtkImageWriter::New();
>>>  writer->SetInput(vol);
>>>  writer->SetFilePrefix("voldata");
>>>  writer->Write();
>>>
>>>//----------------- Read Data ---------------------------
>>>vtkImageReader *reader  = vtkImageReader::New();
>>>   reader->SetDataExtent(0,25, 0, 25, 0, 25);
>>>   reader->SetFilePrefix("voldata");
>>>   reader->SetDataSpacing(sp, sp, sp);
>>>   reader->SetDataOrigin(-0.5,-0.5,-0.5);
>>>
>>>
>>>
>>>  vtkContourFilter *contour = vtkContourFilter::New();
>>>//    contour->SetInput(vol);            //original
>>>      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();
>>>}
>>>
>>>
>>>
>>>
>>>_______________________________________________
>>>This is the private VTK discussion list.
>>>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>>>Follow this link to subscribe/unsubscribe:
>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>>
>>--
>>Mathieu Malaterre
>>CREATIS
>>28 Avenue du Doyen LEPINE
>>B.P. Lyon-Montchat
>>69394 Lyon Cedex 03
>>http://www.creatis.insa-lyon.fr/~malaterre/
>>
>>_______________________________________________
>>This is the private VTK discussion list.
>>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>>Follow this link to subscribe/unsubscribe:
>>http://www.vtk.org/mailman/listinfo/vtkusers
>>
> 
> 


-- 
Mathieu Malaterre
CREATIS
28 Avenue du Doyen LEPINE
B.P. Lyon-Montchat
69394 Lyon Cedex 03
http://www.creatis.insa-lyon.fr/~malaterre/




More information about the vtkusers mailing list