[vtkusers] vtkWriter Subclass

Mike Jackson maillist at bluequartz.net
Mon Nov 21 09:44:20 EST 2005


Once the data was loaded, meta data did not indicate the correct  
values. The filter menu was NOT available so I could not do anything  
with the data. I tried all the different representations and nothing  
seemed to show anything except the outline of which the extents did  
not seem correct. My guess is that I am not writing out some header  
or something?

Additionally, when I try to open the file in paraview ("/tmp/ 
phasefield.vti") I get an error dialog stating "Could not find an  
appropriate reader for file "/tmp/phasefield.vti. Would you like to  
manually select the reader for this file?". I select OK and proceed  
to select the "VTKImageFiles Reader" from the list.
    Now in Paraview, I go to the "Information" tab and get:
Type: Volume (Uniform Rectilinear)
Number of Datasets: 1
Number of Cells: 0
Number of Points: 0
Memory: 0 MBytes
Empty Bounds
Empty Extent.

I believe I can forward the data (I'll have to check with my  
supervisior) if you want to try this yourself.

Following is the method that I am using to read the original data,  
then write the "vtk" data:
///Assume _size = 256
///Assume _voi.empty() returns TRUE
vtkImageData* PhaseFieldReader::_read( std::istream& in )
{
   if ( _voi.empty() )
     this->setVOI( 0, _size - 1, 0, _size - 1, 0, _size -1 );

   unsigned char byte;

   // First read the file into a temp image
   vtkSmartPointer < vtkImageData > temp ( vtkImageData::New() );
   temp->SetSpacing ( 1.0, 1.0, 1.0 );
   temp->SetOrigin ( 0.0, 0.0, 0.0 );
   temp->SetDimensions ( _size, _size, _size );
   temp->SetNumberOfScalarComponents(1);
   temp->SetScalarTypeToUnsignedChar();
   temp->AllocateScalars();

   {
     unsigned char *data = static_cast < unsigned char* > ( temp- 
 >GetScalarPointer( ) );
     ::memset ( data, 0,  _size * _size * _size );
   }

   for ( unsigned int x = 0; x < _size; ++x )
   {
     for ( unsigned int y = 0; y < _size; ++y )
     {
       for ( unsigned int z = 0; z < _size; ++z )
       {
         in >> byte;

         unsigned char *data = static_cast < unsigned char* > ( temp- 
 >GetScalarPointer( x, y , z ) );
         unsigned char value ( ( byte - 48 ) * 255 ) ;
         *data = value;
       }
     }
   }

   // Size of each dimension of the final image.
   unsigned int xSize ( _voi[ X_MAX ] - _voi[ X_MIN ] + 1 );
   unsigned int ySize ( _voi[ Y_MAX ] - _voi[ Y_MIN ] + 1 );
   unsigned int zSize ( _voi[ Z_MAX ] - _voi[ Z_MIN ] + 1 );

   // Start and finish values for the for loops.
   unsigned int xStart  ( 0 );
   unsigned int xFinish ( xSize );
   unsigned int yStart  ( 0 );
   unsigned int yFinish ( ySize );
   unsigned int zStart  ( 0 );
   unsigned int zFinish ( zSize );

   // If we need to add padding for capping, adjust the values.
   if( _addPadding )
   {
     xSize += 2;
     ySize += 2;
     zSize += 2;
     xStart++;
     xFinish++;
     yStart++;
     yFinish++;
     zStart++;
     zFinish++;
   }

   // Copy the volume of interest into the image.
   vtkImageData *image ( vtkImageData::New() );
   image->SetSpacing ( 1.0, 1.0, 1.0 );
   image->SetOrigin ( 0.0, 0.0, 0.0 );
   image->SetDimensions ( xSize, ySize, zSize );
   image->SetNumberOfScalarComponents(1);
   image->SetScalarTypeToUnsignedChar();
   image->AllocateScalars();

   // Set the data to all zeros.
   unsigned char *data = static_cast < unsigned char* > ( image- 
 >GetScalarPointer( ) );
   ::memset ( data, 0,  xSize * ySize * zSize );

   // Offsets into the temp image that we read previously
   const unsigned int xOffset ( _voi[ X_MIN ] );
   const unsigned int yOffset ( _voi[ Y_MIN ] );
   const unsigned int zOffset ( _voi[ Z_MIN ] );

   // Create the final image.
   for ( unsigned int x = xStart; x < xFinish; ++x )
   {
     for ( unsigned int y = yStart; y < yFinish; ++y )
     {
       for ( unsigned int z = zStart; z < zFinish; ++z )
       {
         unsigned char *tempData = static_cast < unsigned char* >  
( temp->GetScalarPointer( x + xOffset, y + yOffset, z + zOffset ) );
         unsigned char *data = static_cast < unsigned char* > ( image- 
 >GetScalarPointer( x, y , z ) );

         *data = *tempData;
       }
     }
   }

#if __APPLE__
   vtkSmartPointer < vtkImageWriter > writer;
   writer       = vtkImageWriter::New();
   writer->SetFileDimensionality(3);
   writer->SetFileName("/tmp/phasefield.vts");
   writer->SetInput(image);
   writer->Write();
   std::cout << "writing done..." << std::endl;
#endif

   return image;
}

---
Mike Jackson
mike _at_ bluequartz dot net


On Nov 21, 2005, at 9:25 AM, Amy Squillacote wrote:

> Hi Mike,
>
> In ParaView, the default representation of a vtkImageData object is  
> an outline cube.  If you've gotten this far, you have likely loaded  
> your data correctly into ParaView.  To change to something other  
> than the wireframe view, go to the Display tab, and change the  
> value in the representation menu.  After you loaded your data (and  
> got a wireframe cube), did you look at the Information tab to see  
> if the meta-data for this vtkImageData object was correct (i.e.,  
> bounds, extents, spacing, range of values in data array)? Did you  
> try running a filter on your data?
>
> - Amy
>
> At 12:28 AM 11/21/2005, Mike Jackson wrote:
>> I would like to look at some data that has been given to me. The
>> format is in ASCII and is a special format (gotta love researchers).
>> We have written a parser to get it out of the file and into a
>> vtkImageData object. The data represents voxels in a 256x256x256
>> grid. The values are either 1 or 0.
>>
>> Once I get the data exported into some vtk specific file I would like
>> to load it up into paraview. I have tried several of the vtk*writer
>> classes all with no luck trying to load the file into paraview. The
>> most I get is an outline of the model ( a wireframe cube). Could
>> anyone offer some ideas on what I might use to accomplish this?
>>
>> Don't even suggest to write a paraview plugin. I am running OS X
>> 10.4.3 and I am lucky to just have paraview running, let alone build
>> a module for it.
>> ---
>> Mike Jackson
>> mike _at_ bluequartz dot net
>>
>>
>> _______________________________________________
>> This is the private VTK discussion list. Please keep messages on- 
>> topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>







More information about the vtkusers mailing list