Commit 195ba4da authored by Will Schroeder's avatar Will Schroeder

ENH:Reparented readers to vtkDataReader; vtkDataReader is now a subclass of vtkSource

parent ad3c75a1
......@@ -11,18 +11,15 @@ source $VTK_TCL/vtkInt.tcl
# create pipeline
#
vtkDataReader infoReader
infoReader SetFileName "$VTK_DATA/polyEx.vtk"
set numScalars [infoReader GetNumberOfScalarsInFile]
set numVectors [infoReader GetNumberOfVectorsInFile]
set numNormals [infoReader GetNumberOfNormalsInFile]
infoReader Modified
set numScalars [infoReader GetNumberOfScalarsInFile]
set scalar0 [infoReader GetScalarsNameInFile 1]
vtkPolyDataReader reader
reader SetFileName "$VTK_DATA/polyEx.vtk"
reader SetScalarsName $scalar0
set numScalars [reader GetNumberOfScalarsInFile]
set numVectors [reader GetNumberOfVectorsInFile]
set numNormals [reader GetNumberOfNormalsInFile]
reader Modified
set numScalars [reader GetNumberOfScalarsInFile]
set scalar0 [reader GetScalarsNameInFile 1]
vtkPolyDataMapper mapper
mapper SetInput [reader GetOutput]
......
......@@ -42,9 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkDataObjectReader.h"
#include "vtkObjectFactory.h"
//------------------------------------------------------------------------------
//-------------------------------------------------------------------------
vtkDataObjectReader* vtkDataObjectReader::New()
{
// First try to create the object from the vtkObjectFactory
......@@ -57,41 +55,34 @@ vtkDataObjectReader* vtkDataObjectReader::New()
return new vtkDataObjectReader;
}
vtkDataObjectReader::vtkDataObjectReader()
{
this->Reader = vtkDataReader::New();
this->Reader->SetSource(this);
this->SetOutput(vtkDataObject::New());
// Releasing data for pipeline parallism.
// Filters will know it is empty.
this->Outputs[0]->ReleaseData();
this->Outputs[0]->Delete();
}
vtkDataObjectReader::~vtkDataObjectReader()
{
this->Reader->Delete();
}
unsigned long int vtkDataObjectReader::GetMTime()
//----------------------------------------------------------------------------
vtkDataObject *vtkDataObjectReader::GetOutput()
{
unsigned long dtime = this->vtkDataObjectSource::GetMTime();
unsigned long rtime = this->Reader->GetMTime();
return (dtime > rtime ? dtime : rtime);
}
// Specify file name of vtk field data file to read.
void vtkDataObjectReader::SetFileName(const char *name)
{
this->Reader->SetFileName(name);
}
char *vtkDataObjectReader::GetFileName()
{
return this->Reader->GetFileName();
if (this->NumberOfOutputs < 1)
{
return NULL;
}
return (vtkDataObject *)(this->Outputs[0]);
}
// Get the type of file (ASCII or BINARY)
int vtkDataObjectReader::GetFileType()
//----------------------------------------------------------------------------
void vtkDataObjectReader::SetOutput(vtkDataObject *output)
{
return this->Reader->GetFileType();
this->vtkSource::SetNthOutput(0, output);
}
void vtkDataObjectReader::Execute()
......@@ -101,27 +92,18 @@ void vtkDataObjectReader::Execute()
vtkDebugMacro(<<"Reading vtk field data...");
if ( this->Debug )
{
this->Reader->DebugOn();
}
else
{
this->Reader->DebugOff();
}
if ( !(this->Reader->OpenVTKFile()) || !this->Reader->ReadHeader())
if ( !(this->OpenVTKFile()) || !this->ReadHeader())
{
return;
}
// Read field data until end-of-file
//
while (this->Reader->ReadString(line) && !field )
while (this->ReadString(line) && !field )
{
if ( !strncmp(this->Reader->LowerCase(line),"field",(unsigned long)5) )
if ( !strncmp(this->LowerCase(line),"field",(unsigned long)5) )
{
field = this->Reader->ReadFieldData(); //reads named field (or first found)
field = this->ReadFieldData(); //reads named field (or first found)
if ( field != NULL )
{
this->GetOutput()->SetFieldData(field);
......@@ -129,58 +111,26 @@ void vtkDataObjectReader::Execute()
}
}
else if ( !strncmp(this->Reader->LowerCase(line),"dataset",(unsigned long)7) )
else if ( !strncmp(this->LowerCase(line),"dataset",(unsigned long)7) )
{
vtkErrorMacro(<<"Field reader cannot read datasets");
this->Reader->CloseVTKFile();
this->CloseVTKFile();
return;
}
else
{
vtkErrorMacro(<< "Unrecognized keyword: " << line);
this->Reader->CloseVTKFile();
this->CloseVTKFile();
return;
}
}
//while field not read
this->Reader->CloseVTKFile();
}
// Set the name of the field data to extract. If not specified, uses
// first field data encountered in file.
void vtkDataObjectReader::SetFieldDataName(char *name)
{
this->Reader->SetFieldDataName(name);
}
char *vtkDataObjectReader::GetFieldDataName()
{
return this->Reader->GetFieldDataName();
this->CloseVTKFile();
}
void vtkDataObjectReader::PrintSelf(ostream& os, vtkIndent indent)
{
vtkDataObjectSource::PrintSelf(os,indent);
os << indent << "File Name: "
<< (this->Reader->GetFileName() ? this->Reader->GetFileName() : "(none)") << "\n";
if ( this->Reader->GetFileType() == VTK_BINARY )
{
os << indent << "File Type: BINARY\n";
}
else
{
os << indent << "File Type: ASCII\n";
}
if ( this->Reader->GetFieldDataName() )
{
os << indent << "Field Data Name: " << this->Reader->GetFieldDataName() << "\n";
}
else
{
os << indent << "Field Data Name: (None)\n";
}
vtkDataReader::PrintSelf(os,indent);
}
......@@ -41,60 +41,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// .NAME vtkDataObjectReader - read vtk field data file
// .SECTION Description
// vtkDataObjectReader is a source object that reads ASCII or binary
// field data files in vtk format. Fields are general matrix structures used
// represent complex data.
// vtkDataObjectReader is a source object that reads ASCII or binary field
// data files in vtk format. Fields are general matrix structures used
// represent complex data. (See text for format details). The output of this
// reader is a single vtkDataObject. The superclass of this class,
// vtkDataReader, provides many methods for controlling the reading of the
// data file, see vtkDataReader for more information.
// .SECTION Caveats
// Binary files written on one system may not be readable on other systems.
// .SECTION See Also
// vtkFieldData vtkFieldDataWriter
// vtkFieldData vtkDataObjectWriter
#ifndef __vtkDataObjectReader_h
#define __vtkDataObjectReader_h
#include "vtkDataObjectSource.h"
#include "vtkDataReader.h"
#include "vtkDataObject.h"
class VTK_EXPORT vtkDataObjectReader : public vtkDataObjectSource
class VTK_EXPORT vtkDataObjectReader : public vtkDataReader
{
public:
static vtkDataObjectReader *New();
vtkTypeMacro(vtkDataObjectReader,vtkDataObjectSource);
vtkTypeMacro(vtkDataObjectReader,vtkDataReader);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Return the MTime also considering the vtkDataReader ivar
unsigned long GetMTime();
// Description:
// Set / get file name of vtk field data file to read.
void SetFileName(const char *name);
char *GetFileName();
// Description:
// Set / get the InputString for use when reading from a character array.
void SetInputString(const char *in) {this->Reader->SetInputString(in);}
void SetInputString(const char *in,int len) {this->Reader->SetInputString(in,len);}
char *GetInputString() { return this->Reader->GetInputString();}
// Description:
// Set/Get reading from an InputString instead of the default, a file.
void SetReadFromInputString(int i) {this->Reader->SetReadFromInputString(i);}
int GetReadFromInputString() {return this->Reader->GetReadFromInputString();}
vtkBooleanMacro(ReadFromInputString,int);
// Description:
// Get the type of file (ASCII or BINARY)
int GetFileType();
// Description:
// Set / get the name of the field data to extract. If not specified, uses
// first field data encountered in file.
void SetFieldDataName(char *name);
char *GetFieldDataName();
// Get the output field of this reader.
vtkDataObject *GetOutput();
void SetOutput(vtkDataObject *);
protected:
vtkDataObjectReader();
~vtkDataObjectReader();
......@@ -102,7 +77,6 @@ protected:
void operator=(const vtkDataObjectReader&) {};
void Execute();
vtkDataReader *Reader;
};
#endif
......
......@@ -98,7 +98,6 @@ vtkDataReader::vtkDataReader()
this->InputStringPos = 0;
this->ReadFromInputString = 0;
this->IS = NULL;
this->Source = NULL;
this->Header = NULL;
this->NumberOfScalarsInFile = 0;
......@@ -178,17 +177,6 @@ vtkDataReader::~vtkDataReader()
this->InitializeCharacteristics();
}
// no reference counting
void vtkDataReader::SetSource(vtkSource *source)
{
if (this->Source != source)
{
this->Source = source;
this->Modified();
}
}
void vtkDataReader::SetInputString(const char *in)
{
if (in != NULL)
......@@ -496,11 +484,8 @@ int vtkDataReader::ReadHeader()
this->ReadString(line);
}
if (this->Source)
{
float progress=this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress=this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1103,11 +1088,8 @@ int vtkDataReader::ReadPoints(vtkPointSet *ps, int numPts)
}
vtkDebugMacro(<<"Read " << ps->GetNumberOfPoints() << " points");
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1157,11 +1139,8 @@ int vtkDataReader::ReadCoordinates(vtkRectilinearGrid *rg, int axes,
coords->Delete();
vtkDebugMacro(<<"Read " << coords->GetNumberOfScalars() << " coordinates");
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1244,11 +1223,8 @@ int vtkDataReader::ReadScalarData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1292,11 +1268,8 @@ int vtkDataReader::ReadVectorData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1341,11 +1314,8 @@ int vtkDataReader::ReadNormalData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1388,11 +1358,8 @@ int vtkDataReader::ReadTensorData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1436,11 +1403,8 @@ int vtkDataReader::ReadGhostLevelData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1525,11 +1489,8 @@ int vtkDataReader::ReadCoScalarData(vtkDataSetAttributes *a, int numPts)
}
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1583,11 +1544,8 @@ int vtkDataReader::ReadTCoordsData(vtkDataSetAttributes *a, int numPts)
return 0;
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1653,12 +1611,8 @@ int vtkDataReader::ReadLutData(vtkDataSetAttributes *a)
}
lut->Delete();
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1696,11 +1650,8 @@ int vtkDataReader::ReadCells(int size, int *data)
}
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -1807,11 +1758,8 @@ int vtkDataReader::ReadCells(int size, int *data,
}
}
if ( this->Source )
{
float progress = this->Source->GetProgress();
this->Source->UpdateProgress(progress + 0.5*(1.0 - progress));
}
float progress = this->GetProgress();
this->UpdateProgress(progress + 0.5*(1.0 - progress));
return 1;
}
......@@ -2167,7 +2115,7 @@ const char *vtkDataReader::GetGhostLevelsNameInFile(int i)
void vtkDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
vtkObject::PrintSelf(os,indent);
vtkSource::PrintSelf(os,indent);
os << indent << "File Name: "
<< (this->FileName ? this->FileName : "(none)") << "\n";
......@@ -2191,15 +2139,6 @@ void vtkDataReader::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Header: (None)\n";
}
if ( this->Source )
{
this->Source->PrintSelf(os,indent);
}
else
{
os << indent << "Source: (none)\n";
}
os << indent << "ReadFromInputString: " << (this->ReadFromInputString ? "On\n" : "Off\n");
if ( this->InputString )
{
......
......@@ -39,17 +39,20 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// .NAME vtkDataReader - helper class for objects that read vtk data files
// .NAME vtkDataReader - helper superclass for objects that read vtk data files
// .SECTION Description
// vtkDataReader is a helper class that reads the vtk data file header,
// vtkDataReader is a helper superclass that reads the vtk data file header,
// dataset type, and attribute data (point and cell attributes such as
// scalars, vectors, normals, etc.) from a vtk data file. See text for
// format.
// the format of the various vtk file types.
//
// .SECTION See Also
// vtkPolyDataReader vtkStructuredPointsReader vtkStructuredGridReader
// vtkUnsutructuredGridReader vtkRectilinearGridReader
#ifndef __vtkDataReader_h
#define __vtkDataReader_h
#include "vtkObject.h"
#include "vtkSource.h"
#include "vtkDataSetAttributes.h"
......@@ -60,7 +63,7 @@ class vtkDataSet;
class vtkPointSet;
class vtkRectilinearGrid;
class VTK_EXPORT vtkDataReader : public vtkObject
class VTK_EXPORT vtkDataReader : public vtkSource
{
public:
static vtkDataReader *New();
......@@ -114,7 +117,9 @@ public:
// Description:
// How many attributes of various types are in this file? This
// requires reading the file, so the filename must be set prior
// to invoking this operation.
// to invoking this operation. (Note: file characteristics are
// cached, so only a single read is necessary to return file
// characteristics.)
int GetNumberOfScalarsInFile()
{this->CharacterizeFile(); return this->NumberOfScalarsInFile;}
int GetNumberOfVectorsInFile()
......@@ -131,7 +136,7 @@ public:
{this->CharacterizeFile(); return this->NumberOfGhostLevelsInFile;}
// Description:
// What is the name of the ith attribute of a certain type are
// What is the name of the ith attribute of a certain type
// in this file? This requires reading the file, so the filename
// must be set prior to invoking this operation.
const char *GetScalarsNameInFile(int i);
......@@ -190,15 +195,6 @@ public:
vtkSetStringMacro(FieldDataName);
vtkGetStringMacro(FieldDataName);
//BTX
// Description:
// Set/Get the name of the source object that owns this helper instance.
// It is meant to be used by the source object, and does not reference
// count the source.
void SetSource(vtkSource *source);
vtkGetObjectMacro(Source,vtkSource);
//ETX
// Description:
// Open a vtk data file. Returns zero if error.
int OpenVTKFile();
......@@ -236,6 +232,8 @@ public:
// which coordinate axes (0,1,2) is being read.
int ReadCoordinates(vtkRectilinearGrid *rg, int axes, int numCoords);
// Description:
// Helper functions for reading data.
vtkDataArray *ReadArray(const char *dataType, int numTuples, int numComp);
vtkFieldData *ReadFieldData();
......@@ -254,7 +252,7 @@ public:
int Read(double *);
// Description:
// Close a vtk file.
// Close the vtk file.
void CloseVTKFile();
// Description:
......@@ -303,7 +301,6 @@ protected:
vtkSetStringMacro(ScalarLut);
vtkGetStringMacro(ScalarLut);
vtkSource *Source;
char *Header;
int ReadScalarData(vtkDataSetAttributes *a, int num);
......
This diff is collapsed.
......@@ -41,16 +41,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// .NAME vtkDataSetReader - class to read any type of vtk dataset
// .SECTION Description
// vtkDataSetReader is a class that provides instance variables
// and methods to read any type of dataset in Visualization Toolkit (vtk) format.
// The output type of this class will vary depending upon the type of data
// vtkDataSetReader is a class that provides instance variables and methods
// to read any type of dataset in Visualization Toolkit (vtk) format. The
// output type of this class will vary depending upon the type of data
// file. Convenience methods are provided to keep the data as a particular
// type.
// type. (See text for format description details).
// The superclass of this class, vtkDataReader, provides many methods for
// controlling the reading of the data file, see vtkDataReader for more
// information.
// .SECTION Caveats
// Binary files written on one system may not be readable on other systems.
// .SECTION See Also
// vtkDataReader vtkPolyDataReader vtkRectilinearGridReader
// vtkStructuredPointsReader vtkStructuredGridReader vtkUnstructuredGridReader
#ifndef __vtkDataSetReader_h
#define __vtkDataSetReader_h
#include "vtkSource.h"
#include "vtkDataReader.h"
class vtkPolyData;
......@@ -59,77 +66,12 @@ class vtkStructuredGrid;
class vtkUnstructuredGrid;
class vtkRectilinearGrid;
class VTK_EXPORT vtkDataSetReader : public vtkSource
class VTK_EXPORT vtkDataSetReader : public vtkDataReader
{
public:
static vtkDataSetReader *New();
vtkTypeMacro(vtkDataSetReader,vtkSource);
void PrintSelf(ostream& os, vtkIndent indent);
unsigned long int GetMTime();
// Description:
// Set / get the file name of vtk data file to read.
void SetFileName(const char *name);
const char *GetFileName();
// Description:
// Specify the InputString for use when reading from a character array.
void SetInputString(const char *in) {this->Reader->SetInputString(in);}
void SetInputString(const char *in,int len) {this->Reader->SetInputString(in,len);}
const char *GetInputString() { return this->Reader->GetInputString();}
// Description:
// Set/Get reading from an InputString instead of the default, a file.
void SetReadFromInputString(int i){this->Reader->SetReadFromInputString(i);}
int GetReadFromInputString() {return this->Reader->GetReadFromInputString();}
vtkBooleanMacro(ReadFromInputString,int);
// Description:
// Get the type of file (VTK_ASCII or VTK_BINARY).
int GetFileType();
// Description:
// Set / get the name of the scalar data to extract. If not specified,
// first scalar data encountered is extracted.
void SetScalarsName(const char *name);
const char *GetScalarsName();
// Description:
// Set / get the name of the vector data to extract. If not specified,
// first vector data encountered is extracted.
void SetVectorsName(const char *name);
const char *GetVectorsName();
// Description:
// Set / get the name of the tensor data to extract. If not specified,
// first tensor data encountered is extracted.
void SetTensorsName(const char *name);
const char *GetTensorsName();
// Description:
// Set / get the name of the normal data to extract. If not specified,
// first normal data encountered is extracted.
void SetNormalsName(const char *name);
const char *GetNormalsName();
// Description:
// Set / get the name of the texture coordinate data to extract. If not
// specified, first texture coordinate data encountered is extracted.
void SetTCoordsName(const char *name);
const char *GetTCoordsName();
// Description:
// Set / get the name of the lookup table data to extract. If not
// specified, uses lookup table named by scalar. Otherwise, this
// specification supersedes.
void SetLookupTableName(const char *name);
const char *GetLookupTableName();
// Description:
// Set / get the name of the field data to extract. If not specified, uses
// first field data encountered in file.
void SetFieldDataName(const char *name);
const char *GetFieldDataName();
// Description:
// Get the output of this source as a general vtkDataSet. Since we need
......@@ -142,9 +84,9 @@ public:
// Description:
// Get the output as various concrete types. This method is typically used
// when you know exactly what type of data is being read. Otherwise, use
// the general GetOutput() method. If the wrong type is used NULL is returned.
// (You must also set the filename of the object prior
// to getting the output.)
// the general GetOutput() method. If the wrong type is used NULL is
// returned. (You must also set the filename of the object prior to
// getting the output.)
vtkPolyData *GetPolyDataOutput();
vtkStructuredPoints *GetStructuredPointsOutput();
vtkStructuredGrid *GetStructuredGridOutput();
......
This diff is collapsed.
......@@ -42,97 +42,33 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// .NAME vtkPolyDataReader - read vtk polygonal data file
// .SECTION Description
// vtkPolyDataReader is a source object that reads ASCII or binary
// polygonal data files in vtk format. See text for format details.
// polygonal data files in vtk format (see text for format details).
// The output of this reader is a single vtkPolyData data object.
// The superclass of this class, vtkDataReader, provides many methods for
// controlling the reading of the data file, see vtkDataReader for more
// information.
// .SECTION Caveats
// Binary files written on one system may not be readable on other systems.
// .SECTION See Also
// vtkPolyData vtkDataReader
#ifndef __vtkPolyDataReader_h
#define __vtkPolyDataReader_h
#include "vtkPolyDataSource.h"
#include "vtkDataReader.h"
#include "vtkPolyData.h"
class VTK_EXPORT vtkPolyDataReader : public vtkPolyDataSource
class VTK_EXPORT vtkPolyDataReader : public vtkDataReader