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

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 @@
class VTK_IO_EXPORT vtkParticleReader : public vtkPolyDataAlgorithm
......@@ -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.
int GetSwapBytes() {return this->SwapBytes;}
// Description:
// Default: 1. If 1 then each particle has a value associated with it.
// 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.
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);}
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 );
// 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>
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;
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