Commit 009c40a5 authored by Brad King's avatar Brad King

ENH: Adding XML reader/writer classes. Moving from ParaView/Packages.

parent be1a9d57
......@@ -3,7 +3,10 @@ vtkBMPReader.cxx
vtkBMPWriter.cxx
vtkBYUReader.cxx
vtkBYUWriter.cxx
vtkBase64InputStream.cxx
vtkBase64OutputStream.cxx
vtkDEMReader.cxx
vtkDataCompressor.cxx
vtkDataObjectReader.cxx
vtkDataObjectWriter.cxx
vtkDataReader.cxx
......@@ -24,12 +27,14 @@ vtkImageReader2.cxx
vtkImageReader2Collection.cxx
vtkImageReader2Factory.cxx
vtkImageWriter.cxx
vtkInputStream.cxx
vtkJPEGReader.cxx
vtkJPEGWriter.cxx
vtkMCubesReader.cxx
vtkMCubesWriter.cxx
vtkMedicalImageReader2.cxx
vtkOBJReader.cxx
vtkOutputStream.cxx
vtkPLOT3DReader.cxx
vtkPLY.cxx
vtkPLYReader.cxx
......@@ -59,13 +64,67 @@ vtkUnstructuredGridWriter.cxx
vtkVolume16Reader.cxx
vtkVolumeReader.cxx
vtkWriter.cxx
vtkXMLDataElement.cxx
vtkXMLDataParser.cxx
vtkXMLDataReader.cxx
vtkXMLDataSetWriter.cxx
vtkXMLFileReadTester.cxx
vtkXMLImageDataReader.cxx
vtkXMLImageDataWriter.cxx
vtkXMLPDataReader.cxx
vtkXMLPDataSetWriter.cxx
vtkXMLPDataWriter.cxx
vtkXMLPImageDataReader.cxx
vtkXMLPImageDataWriter.cxx
vtkXMLPPolyDataReader.cxx
vtkXMLPPolyDataWriter.cxx
vtkXMLPRectilinearGridReader.cxx
vtkXMLPRectilinearGridWriter.cxx
vtkXMLPStructuredDataReader.cxx
vtkXMLPStructuredDataWriter.cxx
vtkXMLPStructuredGridReader.cxx
vtkXMLPStructuredGridWriter.cxx
vtkXMLPUnstructuredDataReader.cxx
vtkXMLPUnstructuredDataWriter.cxx
vtkXMLPUnstructuredGridReader.cxx
vtkXMLPUnstructuredGridWriter.cxx
vtkXMLParser.cxx
vtkXMLPolyDataReader.cxx
vtkXMLPolyDataWriter.cxx
vtkXMLReader.cxx
vtkXMLRectilinearGridReader.cxx
vtkXMLRectilinearGridWriter.cxx
vtkXMLStructuredDataReader.cxx
vtkXMLStructuredDataWriter.cxx
vtkXMLStructuredGridReader.cxx
vtkXMLStructuredGridWriter.cxx
vtkXMLUnstructuredDataReader.cxx
vtkXMLUnstructuredDataWriter.cxx
vtkXMLUnstructuredGridReader.cxx
vtkXMLUnstructuredGridWriter.cxx
vtkXMLWriter.cxx
vtkZLibDataCompressor.cxx
)
SET_SOURCE_FILES_PROPERTIES(
vtkDataCompressor
vtkEnSightReader
vtkVolumeReader
vtkWriter
vtkXMLDataReader
vtkXMLPDataReader
vtkXMLPDataWriter
vtkXMLPStructuredDataReader
vtkXMLPStructuredDataWriter
vtkXMLPUnstructuredDataReader
vtkXMLPUnstructuredDataWriter
vtkXMLReader
vtkXMLStructuredDataReader
vtkXMLStructuredDataWriter
vtkXMLUnstructuredDataReader
vtkXMLUnstructuredDataWriter
vtkXMLWriter
ABSTRACT
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBase64InputStream.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkBase64InputStream.h"
#include "vtkObjectFactory.h"
#include "vtkBase64Utility.h"
//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkBase64InputStream, "1.1");
vtkStandardNewMacro(vtkBase64InputStream);
//----------------------------------------------------------------------------
vtkBase64InputStream::vtkBase64InputStream()
{
this->BufferLength = 0;
}
//----------------------------------------------------------------------------
vtkBase64InputStream::~vtkBase64InputStream()
{
}
//----------------------------------------------------------------------------
void vtkBase64InputStream::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkBase64InputStream::StartReading()
{
this->Superclass::StartReading();
this->BufferLength = 0;
}
//----------------------------------------------------------------------------
void vtkBase64InputStream::EndReading()
{
}
//----------------------------------------------------------------------------
int vtkBase64InputStream::Seek(unsigned long offset)
{
unsigned long triplet = offset/3;
int skipLength = offset%3;
// Seek to the beginning of the encoded triplet containing the
// offset.
if(!this->Stream->seekg(this->StreamStartPosition+(triplet*4)))
{
return 0;
}
// Decode the first triplet if it is paritally skipped.
if(skipLength == 0)
{
this->BufferLength = 0;
}
else if(skipLength == 1)
{
unsigned char c;
this->BufferLength =
this->DecodeTriplet(c, this->Buffer[0], this->Buffer[1]) - 1;
}
else
{
unsigned char c[2];
this->BufferLength =
this->DecodeTriplet(c[0], c[1], this->Buffer[0]) - 2;
}
// A DecodeTriplet call may have failed to read the stream.
// If so, the current buffer length will be negative.
return ((this->BufferLength >= 0) ? 1:0);
}
//----------------------------------------------------------------------------
unsigned long vtkBase64InputStream::Read(unsigned char* data,
unsigned long length)
{
unsigned char* out = data;
unsigned char* end = data + length;
// If the previous read ended before filling buffer, don't read
// more.
if(this->BufferLength < 0) { return 0; }
// Use leftover characters from a previous decode.
if((out != end) && (this->BufferLength == 2))
{
*out++ = this->Buffer[0];
this->Buffer[0] = this->Buffer[1];
this->BufferLength = 1;
}
if((out != end) && (this->BufferLength == 1))
{
*out++ = this->Buffer[0];
this->BufferLength = 0;
}
// Decode all complete triplets.
while((end - out) >= 3)
{
int len = this->DecodeTriplet(out[0], out[1], out[2]);
out += len;
if(len < 3)
{
this->BufferLength = len-3;
return (out-data);
}
}
// Decode the last triplet and save leftover characters in the buffer.
if((end - out) == 2)
{
int len = this->DecodeTriplet(out[0], out[1], this->Buffer[0]);
this->BufferLength = len-2;
if(len > 2) { out += 2; }
else { out += len; }
}
else if((end - out) == 1)
{
int len = this->DecodeTriplet(out[0], this->Buffer[0], this->Buffer[1]);
this->BufferLength = len-1;
if(len > 1) { out += 1; }
else { out += len; }
}
return (out-data);
}
//----------------------------------------------------------------------------
inline int vtkBase64InputStream::DecodeTriplet(unsigned char& c0,
unsigned char& c1,
unsigned char& c2)
{
// Read the 4 bytes encoding this triplet from the stream.
unsigned char in[4];
this->Stream->read(reinterpret_cast<char*>(in), 4);
if(this->Stream->gcount() < 4) { return 0; }
return vtkBase64Utility::DecodeTriplet(in[0], in[1], in[2], in[3],
&c0, &c1, &c2);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBase64InputStream.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkBase64InputStream - Reads base64-encoded input from a stream.
// .SECTION Description
// vtkBase64InputStream implements base64 decoding with the
// vtkInputStream interface.
#ifndef __vtkBase64InputStream_h
#define __vtkBase64InputStream_h
#include "vtkInputStream.h"
class VTK_IO_EXPORT vtkBase64InputStream : public vtkInputStream
{
public:
vtkTypeRevisionMacro(vtkBase64InputStream,vtkInputStream);
static vtkBase64InputStream *New();
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Called after the stream position has been set by the caller, but
// before any Seek or Read calls. The stream position should not be
// adjusted by the caller until after an EndReading call.
void StartReading();
// Description:
// Seek to the given offset in the input data. Returns 1 for
// success, 0 for failure.
int Seek(unsigned long offset);
// Description:
// Read input data of the given length. Returns amount actually
// read.
unsigned long Read(unsigned char* data, unsigned long length);
// Description:
// Called after all desired calls to Seek and Read have been made.
// After this call, the caller is free to change the position of the
// stream. Additional reads should not be done until after another
// call to StartReading.
void EndReading();
protected:
vtkBase64InputStream();
~vtkBase64InputStream();
// Number of decoded bytes left in Buffer from last call to Read.
int BufferLength;
unsigned char Buffer[2];
// Reads 4 bytes from the input stream and decodes them into 3 bytes.
int DecodeTriplet(unsigned char& c0, unsigned char& c1, unsigned char& c2);
private:
vtkBase64InputStream(const vtkBase64InputStream&); // Not implemented.
void operator=(const vtkBase64InputStream&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBase64OutputStream.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkBase64OutputStream.h"
#include "vtkObjectFactory.h"
#include "vtkBase64Utility.h"
//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkBase64OutputStream, "1.1");
vtkStandardNewMacro(vtkBase64OutputStream);
//----------------------------------------------------------------------------
vtkBase64OutputStream::vtkBase64OutputStream()
{
this->BufferLength = 0;
}
//----------------------------------------------------------------------------
vtkBase64OutputStream::~vtkBase64OutputStream()
{
}
//----------------------------------------------------------------------------
void vtkBase64OutputStream::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkBase64OutputStream::StartWriting()
{
if(!this->Superclass::StartWriting())
{
return 0;
}
this->BufferLength = 0;
return 1;
}
//----------------------------------------------------------------------------
int vtkBase64OutputStream::EndWriting()
{
if(this->BufferLength == 1)
{
if(!this->EncodeEnding(this->Buffer[0])) { return 0; }
this->BufferLength = 0;
}
else if(this->BufferLength == 2)
{
if(!this->EncodeEnding(this->Buffer[0], this->Buffer[1])) { return 0; }
this->BufferLength = 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkBase64OutputStream::Write(const unsigned char* data,
unsigned long length)
{
unsigned long totalLength = this->BufferLength + length;
const unsigned char* in = data;
const unsigned char* end = data+length;
if(totalLength >= 3)
{
if(this->BufferLength == 1)
{
if(!this->EncodeTriplet(this->Buffer[0], in[0], in[1])) { return 0; }
in += 2;
this->BufferLength = 0;
}
else if(this->BufferLength == 2)
{
if(!this->EncodeTriplet(this->Buffer[0], this->Buffer[1], in[0]))
{ return 0; }
in += 1;
this->BufferLength = 0;
}
}
while((end - in) >= 3)
{
if(!this->EncodeTriplet(in[0], in[1], in[2])) { return 0; }
in += 3;
}
while(in != end)
{
this->Buffer[this->BufferLength++] = *in++;
}
return 1;
}
//----------------------------------------------------------------------------
inline int vtkBase64OutputStream::EncodeTriplet(unsigned char c0,
unsigned char c1,
unsigned char c2)
{
// Encodes 3 bytes into 4 bytes and writes them to the output stream.
unsigned char out[4];
vtkBase64Utility::EncodeTriplet(c0, c1, c2,
&out[0], &out[1], &out[2], &out[3]);
return (this->Stream->write(reinterpret_cast<char*>(out), 4)? 1:0);
}
//----------------------------------------------------------------------------
inline int vtkBase64OutputStream:: EncodeEnding(unsigned char c0,
unsigned char c1)
{
// Encodes a 2-byte ending into 3 bytes and 1 pad byte and writes.
unsigned char out[4];
vtkBase64Utility::EncodePair(c0, c1,
&out[0], &out[1], &out[2], &out[3]);
return (this->Stream->write(reinterpret_cast<char*>(out), 4)? 1:0);
}
//----------------------------------------------------------------------------
inline int vtkBase64OutputStream::EncodeEnding(unsigned char c0)
{
// Encodes a 1-byte ending into 2 bytes and 2 pad bytes and writes.
unsigned char out[4];
vtkBase64Utility::EncodeSingle(c0,
&out[0], &out[1], &out[2], &out[3]);
return (this->Stream->write(reinterpret_cast<char*>(out), 4)? 1:0);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBase64OutputStream.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkBase64OutputStream - Writes base64-encoded output to a stream.
// .SECTION Description
// vtkBase64OutputStream implements base64 encoding with the
// vtkOutputStream interface.
#ifndef __vtkBase64OutputStream_h
#define __vtkBase64OutputStream_h
#include "vtkOutputStream.h"
class VTK_IO_EXPORT vtkBase64OutputStream : public vtkOutputStream
{
public:
vtkTypeRevisionMacro(vtkBase64OutputStream,vtkOutputStream);
static vtkBase64OutputStream *New();
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Called after the stream position has been set by the caller, but
// before any Write calls. The stream position should not be
// adjusted by the caller until after an EndWriting call.
int StartWriting();
// Description:
// Write output data of the given length.
int Write(const unsigned char* data, unsigned long length);
// Description:
// Called after all desired calls to Write have been made. After
// this call, the caller is free to change the position of the
// stream. Additional writes should not be done until after another
// call to StartWriting.
int EndWriting();
protected:
vtkBase64OutputStream();
~vtkBase64OutputStream();
// Number of un-encoded bytes left in Buffer from last call to Write.
unsigned int BufferLength;
unsigned char Buffer[2];
// Methods to encode and write data.
int EncodeTriplet(unsigned char c0, unsigned char c1, unsigned char c2);
int EncodeEnding(unsigned char c0, unsigned char c1);
int EncodeEnding(unsigned char c0);
private:
vtkBase64OutputStream(const vtkBase64OutputStream&); // Not implemented.
void operator=(const vtkBase64OutputStream&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataCompressor.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkDataCompressor.h"
#include "vtkUnsignedCharArray.h"
vtkCxxRevisionMacro(vtkDataCompressor, "1.1");
//----------------------------------------------------------------------------
vtkDataCompressor::vtkDataCompressor()
{
}
//----------------------------------------------------------------------------
vtkDataCompressor::~vtkDataCompressor()
{
}
//----------------------------------------------------------------------------
void vtkDataCompressor::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
unsigned long
vtkDataCompressor::Compress(const unsigned char* uncompressedData,
unsigned long uncompressedSize,
unsigned char* compressedData,
unsigned long compressionSpace)
{
return this->CompressBuffer(uncompressedData, uncompressedSize,
compressedData, compressionSpace);
}
//----------------------------------------------------------------------------
unsigned long
vtkDataCompressor::Uncompress(const unsigned char* compressedData,
unsigned long compressedSize,
unsigned char* uncompressedData,
unsigned long uncompressedSize)
{
return this->UncompressBuffer(compressedData, compressedSize,
uncompressedData, uncompressedSize);
}
//----------------------------------------------------------------------------
vtkUnsignedCharArray*
vtkDataCompressor::Compress(const unsigned char* uncompressedData,
unsigned long uncompressedSize)
{
// Get the amount of space needed for compressed data.
unsigned long compressionSpace =
this->GetMaximumCompressionSpace(uncompressedSize);
// Allocate a buffer.
vtkUnsignedCharArray* outputArray = vtkUnsignedCharArray::New();
outputArray->SetNumberOfComponents(1);
outputArray->SetNumberOfTuples(compressionSpace);
unsigned char* compressedData = outputArray->GetPointer(0);
// Compress the data.
unsigned long compressedSize =
this->CompressBuffer(uncompressedData, uncompressedSize,
compressedData, compressionSpace);
// Make sure compression succeeded.
if(!compressedSize)
{
outputArray->Delete();
return 0;
}
// Store the actual size.
outputArray->SetNumberOfTuples(compressedSize);
return outputArray;
}
//----------------------------------------------------------------------------
vtkUnsignedCharArray*
vtkDataCompressor::Uncompress(const unsigned char* compressedData,
unsigned long compressedSize,
unsigned long uncompressedSize)
{
// Allocate a buffer.
vtkUnsignedCharArray* outputArray = vtkUnsignedCharArray::New();
outputArray->SetNumberOfComponents(1);
outputArray->SetNumberOfTuples(uncompressedSize);
unsigned char* uncompressedData = outputArray->GetPointer(0);
// Decompress the data.
unsigned long decSize =
this->UncompressBuffer(compressedData, compressedSize,
uncompressedData, uncompressedSize);
// Make sure the decompression succeeded.
if(!decSize)
{
outputArray->Delete();
return 0;
}
// Store the actual size.
outputArray->SetNumberOfTuples(decSize);
return outputArray;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataCompressor.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkDataCompressor - Abstract interface for data compression classes.
// .SECTION Description
// vtkDataCompressor provides a universal interface for data
// compression. Subclasses provide one compression method and one
// decompression method. The public interface to all compressors
// remains the same, and is defined by this class.
#ifndef __vtkDataCompressor_h
#define __vtkDataCompressor_h
#include "vtkObject.h"
class vtkUnsignedCharArray;
class VTK_IO_EXPORT vtkDataCompressor : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkDataCompressor,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the maximum space that may be needed to store data of the
// given uncompressed size after compression. This is the minimum
// size of the output buffer that can be passed to the four-argument
// Compress method.
virtual unsigned long GetMaximumCompressionSpace(unsigned long size)=0;
// Description:
// Compress the given input data buffer into the given output
// buffer. The size of the output buffer must be at least as large
// as the value given by GetMaximumCompressionSpace for the given
// input size.
unsigned long Compress(</