Commit 91ae34bd authored by Andrew Maclean's avatar Andrew Maclean

ENH: The functionality of vktParticleReader has been extended as follows:

1) Either ASCII text files or binary data files of particles can be read.
2) The file type is automatically detected (this can be overridden by the user).
3) A particle’s scalar value is now optional.
4) The data types that can be read are now float or double.
5) Progress updates are provided.
6) vtkSmartPointer is used.
parent 395383c1
This diff is collapsed.
......@@ -12,16 +12,21 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkParticleReader - Read raw particle data and one array.
// .NAME vtkParticleReader - Read ASCII or binary particle
// data and (optionally) one scalar
// value associated with each particle.
// .SECTION Description
// vtkParticleReader reads a raw file with particles. It supports
// random access into the file to read pieces. The format is:
// x, y, z, value (all floats). This class was developed with a
// specific file in mind, but may be made more general in the future.
// Here are a couple of features I am considering:
// any data types could be used,
// arbitrary list of arrays to read (extended to vectors as well),
// and time serries based on file names.
// vtkParticleReader reads either a binary or a text file of
// particles. Each particle can have associated with it an optional
// scalar value. So the format is format is: x, y, z, scalar
// (all floats or doubles). The text file can consist of a comma
// delimited set of values. In most cases vtkParticleReader can
// automatically determine whether the file is text or binary.
// The data can be either float or double.
// Progress updates are provided.
// With respect to binary files, random access into the file to read
// pieces is supported.
//
#ifndef __vtkParticleReader_h
#define __vtkParticleReader_h
......@@ -31,6 +36,7 @@
#define VTK_FILE_BYTE_ORDER_BIG_ENDIAN 0
#define VTK_FILE_BYTE_ORDER_LITTLE_ENDIAN 1
class VTK_IO_EXPORT vtkParticleReader : public vtkPolyDataAlgorithm
{
public:
......@@ -54,7 +60,8 @@ public:
// As a quick note most UNIX machines are BigEndian while PC's
// and VAX tend to be LittleEndian. So if the file you are reading
// in was generated on a VAX or PC, SetDataByteOrderToLittleEndian
// otherwise SetDataByteOrderToBigEndian.
// otherwise SetDataByteOrderToBigEndian. Not used when reading
// text files.
void SetDataByteOrderToBigEndian();
void SetDataByteOrderToLittleEndian();
int GetDataByteOrder();
......@@ -63,24 +70,115 @@ public:
// Description:
// Set/Get the byte swapping to explicitly swap the bytes of a file.
// Not used when reading text files.
vtkSetMacro(SwapBytes,int);
int GetSwapBytes() {return this->SwapBytes;}
vtkBooleanMacro(SwapBytes,int);
// Description:
// Default: 1. If 1 then each particle has a value associated with it.
vtkSetMacro(HasScalar,int);
vtkGetMacro(HasScalar,int);
vtkBooleanMacro(HasScalar,int);
// Description:
// Get/Set the file type. The options are:
// - FILE_TYPE_IS_UNKNOWN (default) the class
// will attempt to determine the file type.
// If this fails then you should set the file type
// yourself.
// - FILE_TYPE_IS_TEXT the file type is text.
// - FILE_TYPE_IS_BINARY the file type is binary.
vtkSetClampMacro(FileType, int, FILE_TYPE_IS_UNKNOWN, FILE_TYPE_IS_BINARY);
vtkGetMacro(FileType, int);
void SetFileTypeToUnknown() {this->SetFileType(FILE_TYPE_IS_UNKNOWN);}
void SetFileTypeToText() {this->SetFileType(FILE_TYPE_IS_TEXT);}
void SetFileTypeToBinary() {this->SetFileType(FILE_TYPE_IS_BINARY);}
// Description:
// Get/Set the data type. The options are:
// - VTK_FLOAT (default) single precision floating point.
// - VTK_DOUBLE double precision floating point.
vtkSetClampMacro(DataType, int, VTK_FLOAT, VTK_DOUBLE);
vtkGetMacro(DataType, int);
void SetDataTypeToFloat() {this->SetDataType(VTK_FLOAT);}
void SetDataTypeToDouble() {this->SetDataType(VTK_DOUBLE);}
protected:
vtkParticleReader();
~vtkParticleReader();
private:
void OpenFile();
char *FileName;
ifstream *File;
int SwapBytes;
unsigned long NumberOfPoints;
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
// Description:
// The format that will be read if the file is a text file is:
// x, y, z, s (where s is some scalar value associated with the particle).
// Each line corresponding to a particle is terminated with a line feed.
// If y, z, or s is missing, zero is substituted for them.
// Comment lines in the file are handled as follows:
// 1) Any line containing "//" "#" "%" anywhere in the line is discarded.
// 2) Lines containing "/*" are discarded until a "*/" is found. The line
// following the "*/" will be read.
int ProduceOutputFromTextFileDouble(vtkInformationVector *outputVector);
int ProduceOutputFromTextFileFloat(vtkInformationVector *outputVector);
// Description:
// This reader assumes that the file is binary and consists of floating
// point values by default.
int ProduceOutputFromBinaryFileDouble(vtkInformationVector *outputVector);
int ProduceOutputFromBinaryFileFloat(vtkInformationVector *outputVector);
// Description:
// Determine the type of file based on an analysis of its contents.
// Up to 5000 bytes of the file are read and classified. The classification
// of a file as either binary or text is based on the proportions of bytes in
// various classifications. The classification of the file is not infallible
// but should work correctly most of the time. If it fails, use SetFileTypeToText()
// or SetFileTypeToBinary() to set the file type.
// This algorithm probaably only identifies ASCII text correctly and will not
// work for UTF-8 UCS-2 (or UTF-16) or UCS-4 or EBCIDIC.
int DetermineFileType();
// Description:
// Update of the progress.
void DoProgressUpdate( size_t & bytesRead, size_t & fileLength );
private:
//BTX
// Description:
// Enumerate the supported file types.
// <pre>
// - FILE_TYPE_IS_UNKNOWN, (default) the class will attempt to determine the file type.
// - FILE_TYPE_IS_TEXT, the file type is text.
// - FILE_TYPE_IS_BINARY, the file type is binary.
// </pre>
enum FILE_TYPE { FILE_TYPE_IS_UNKNOWN = 0,
FILE_TYPE_IS_TEXT, FILE_TYPE_IS_BINARY };
//ETX
int HasScalar;
// Used to decide which reader should be used.
int FileType;
// Used to specify the data type.
int DataType;
// Set an alliquot of bytes.
size_t alliquot;
// Count of the number of alliquots processed.
size_t count;
int SwapBytes;
size_t numberOfPoints;
private:
vtkParticleReader(const vtkParticleReader&); // Not implemented.
void operator=(const vtkParticleReader&); // Not implemented.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment