Commit f1cadb05 authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH: Final tweaks.

parent 0ee7611f
......@@ -27,7 +27,7 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
#include "DSSrc.hh"
#include "vlDataR.hh"
class vlDataSetReader : public vlDataSetSource, public vlDataReader
class vlDataSetReader : public vlDataSetSource
{
public:
vlDataSetReader();
......@@ -43,7 +43,7 @@ public:
protected:
void Execute();
char *Filename;
vlDataReader Reader;
};
#endif
......
......@@ -23,38 +23,83 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
#define __vlDataReader_hh
#include <stdio.h>
#include "Object.hh"
#include "PointSet.hh"
#define ASCII 1
#define BINARY 2
// Special read macros
#define vlReadDebugMacro(x) \
cerr << "Debug: In " __FILE__ << ", line " << __LINE__ << "\n" << "vlDataReader" << " (" << this << "): " x << "\n\n"
#define vlReadWarningMacro(x) \
cerr << "Warning: In " __FILE__ << ", line " << __LINE__ << "\n" << "vlDataReader" << " (" << this << "): " x << "\n\n"
#define vlReadErrorMacro(x) \
cerr << "ERROR In " __FILE__ << ", line " << __LINE__ << "\n" << "vlDataReader" << " (" << this << "): " x << "\n\n"
class vlDataReader
class vlDataReader : public vlObject
{
public:
vlDataReader() {};
~vlDataReader() {};
vlDataReader();
~vlDataReader();
void PrintSelf(ostream& os, vlIndent indent);
// Description:
// Set the name of the scalar data to extract. If not specified, first
// scalar data encountered is extracted.
vlSetStringMacro(ScalarsName);
vlGetStringMacro(ScalarsName);
// Description:
// Set the name of the vector data to extract. If not specified, first
// vector data encountered is extracted.
vlSetStringMacro(VectorsName);
vlGetStringMacro(VectorsName);
// Description:
// Set the name of the tensor data to extract. If not specified, first
// tensor data encountered is extracted.
vlSetStringMacro(TensorsName);
vlGetStringMacro(TensorsName);
// Description:
// Set the name of the normal data to extract. If not specified, first
// normal data encountered is extracted.
vlSetStringMacro(NormalsName);
vlGetStringMacro(NormalsName);
// Description:
// Set the name of the texture coordinate data to extract. If not specified,
// first texture coordinate data encountered is extracted.
vlSetStringMacro(TCoordsName);
vlGetStringMacro(TCoordsName);
// Description:
// Set the name of the lookup table data to extract. If not specified, uses
// lookup table named by scalar. Otherwise, this specification supersedes.
vlSetStringMacro(LookupTableName);
vlGetStringMacro(LookupTableName);
// Special methods
// Description:
// Get the type of file (ASCII or BINARY)
vlSetMacro(FileType,int);
vlGetMacro(FileType,int);
char *LowerCase(char *);
FILE *OpenVLFile(char *filename, int debug);
int ReadHeader(FILE *fp, int debug);
int ReadPointData(FILE *fp, vlDataSet *ds, int numPts, int debug);
int ReadPoints(FILE *fp, vlPointSet *ps, int numPts);
int ReadCells(FILE *fp, int size, int *data);
protected:
char *ScalarsName;
char *VectorsName;
char *TensorsName;
char *TCoordsName;
char *NormalsName;
char *LookupTableName;
char *ScalarLut;
int FileType;
char *LowerCase(char *);
vlLookupTable *Lut;
int ReadPoints(FILE *fp, vlPointSet *ps, int numPts);
vlSetStringMacro(ScalarLut);
vlGetStringMacro(ScalarLut);
int ReadScalarData(FILE *fp, vlDataSet *ds, int numPts);
int ReadVectorData(FILE *fp, vlDataSet *ds, int numPts);
int ReadNormalData(FILE *fp, vlDataSet *ds, int numPts);
......
......@@ -26,7 +26,7 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
#include "PolySrc.hh"
#include "vlDataR.hh"
class vlPolyReader : public vlPolySource, vlDataReader
class vlPolyReader : public vlPolySource
{
public:
vlPolyReader();
......@@ -39,9 +39,13 @@ public:
vlSetStringMacro(Filename);
vlGetStringMacro(Filename);
// overload because of vlDataReader ivar
unsigned long int GetMTime();
protected:
void Execute();
char *Filename;
vlDataReader Reader;
};
#endif
......
......@@ -36,6 +36,7 @@ void vlSource::UpdateFilter()
{
if ( this->StartMethod ) (*this->StartMethod)(this->StartMethodArg);
this->Execute();
this->_MTime.Modified();
this->ExecuteTime.Modified();
this->SetDataReleased(0);
if ( this->EndMethod ) (*this->EndMethod)(this->EndMethodArg);
......
......@@ -14,6 +14,11 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "vlDSRead.hh"
#include "vlPolyR.hh"
#include "vlSPtsR.hh"
#include "vlSGridR.hh"
#include "vlUGridR.hh"
vlDataSetReader::vlDataSetReader()
{
......@@ -27,7 +32,80 @@ vlDataSetReader::~vlDataSetReader()
void vlDataSetReader::Execute()
{
FILE *fp;
int retStat;
char line[257];
vlDataSet *reader;
vlDebugMacro(<<"Reading vl dataset...");
this->Initialize();
if ( !(fp=this->Reader.OpenVLFile(this->Filename, this->Debug)) ||
! this->Reader.ReadHeader(fp,this->Debug) )
return;
//
// Read polygonal data specific stuff
//
if ( (retStat=fscanf(fp,"%256s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( !strncmp(this->Reader.LowerCase(line),"dataset",(unsigned long)7) )
{
//
// Make sure we're reading right type of geometry
//
if ( (retStat=fscanf(fp,"%256s",line)) == EOF || retStat < 1 )
goto PREMATURE;
rewind(fp);
if ( ! strncmp(this->Reader.LowerCase(line),"polydata",8) )
{
vlPolyReader *preader = new vlPolyReader;
preader->SetFilename(this->Filename);
preader->Update();
reader = (vlDataSet *)preader;
}
else if ( ! strncmp(line,"structured_points",17) )
{
vlStructuredPointsReader *preader = new vlStructuredPointsReader;
preader->SetFilename(this->Filename);
preader->Update();
reader = (vlDataSet *)preader;
}
else if ( ! strncmp(line,"structured_grid",15) )
{
vlStructuredGridReader *preader = new vlStructuredGridReader;
preader->SetFilename(this->Filename);
preader->Update();
reader = (vlDataSet *)preader;
}
else if ( ! strncmp(line,"unstructured_grid",17) )
{
vlUnstructuredGridReader *preader = new vlUnstructuredGridReader;
preader->SetFilename(this->Filename);
preader->Update();
reader = (vlDataSet *)preader;
}
else
{
vlErrorMacro(<< "Cannot read dataset type: " << line);
return;
}
}
//
// Create appropriate dataset
//
if ( this->DataSet ) delete this->DataSet;
this->DataSet = reader;
return;
PREMATURE:
vlErrorMacro(<< "Premature EOF");
return;
}
void vlDataSetReader::PrintSelf(ostream& os, vlIndent indent)
......
This diff is collapsed.
......@@ -25,12 +25,156 @@ vlPolyReader::~vlPolyReader()
if ( this->Filename ) delete [] this->Filename;
}
unsigned long int vlPolyReader::GetMTime()
{
unsigned long dtime = this->vlPolySource::GetMTime();
unsigned long rtime = this->Reader.GetMTime();
return (dtime > rtime ? dtime : rtime);
}
void vlPolyReader::Execute()
{
FILE *fp;
int numPts=0;
int retStat;
char line[257];
int npts, size, ncells;
vlDebugMacro(<<"Reading vl polygonal data...");
this->Initialize();
if ( !(fp=this->Reader.OpenVLFile(this->Filename, this->Debug)) ||
! this->Reader.ReadHeader(fp,this->Debug) )
return;
//
// Read polygonal data specific stuff
//
if ( (retStat=fscanf(fp,"%256s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( !strncmp(this->Reader.LowerCase(line),"dataset",(unsigned long)7) )
{
//
// Make sure we're reading right type of geometry
//
if ( (retStat=fscanf(fp,"%256s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( strncmp(this->Reader.LowerCase(line),"polydata",8) )
{
vlErrorMacro(<< "Cannot read dataset type: " << line);
return;
}
//
// Might find points, vertices, lines, polygons, or triangle strips
//
while (1)
{
if ( (retStat=fscanf(fp,"%256s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( ! strncmp(this->Reader.LowerCase(line),"points",6) )
{
if ( (retStat=fscanf(fp,"%d", &numPts)) == EOF || retStat < 1 )
goto PREMATURE;
this->Reader.ReadPoints(fp, (vlPointSet *)this, numPts);
}
else if ( ! strncmp(line,"vertices",8) )
{
vlCellArray *verts = new vlCellArray;
if ( (retStat=fscanf(fp,"%d %d", &ncells, &size)) == EOF || retStat < 2 )
goto PREMATURE;
this->Reader.ReadCells(fp, size, verts->WritePtr(ncells,size));
verts->WrotePtr();
this->SetVerts(verts);
}
else if ( ! strncmp(line,"lines",5) )
{
vlCellArray *lines = new vlCellArray;
if ( (retStat=fscanf(fp,"%d %d", &ncells, &size)) == EOF || retStat < 2 )
goto PREMATURE;
this->Reader.ReadCells(fp, size, lines->WritePtr(ncells,size));
lines->WrotePtr();
this->SetLines(lines);
}
else if ( ! strncmp(line,"polygons",8) )
{
vlCellArray *polys = new vlCellArray;
if ( (retStat=fscanf(fp,"%d %d", &ncells, &size)) == EOF || retStat < 2 )
goto PREMATURE;
this->Reader.ReadCells(fp, size, polys->WritePtr(ncells,size));
polys->WrotePtr();
this->SetPolys(polys);
}
else if ( ! strncmp(line,"triangle_strips",15) )
{
vlCellArray *tris = new vlCellArray;
if ( (retStat=fscanf(fp,"%d %d", &ncells, &size)) == EOF || retStat < 2 )
goto PREMATURE;
this->Reader.ReadCells(fp, size, tris->WritePtr(ncells,size));
tris->WrotePtr();
this->SetStrips(tris);
}
else if ( ! strncmp(line, "point_data", 10) )
{
if ( (retStat=fscanf(fp,"%d", &npts)) == EOF || retStat < 1 )
goto PREMATURE;
if ( npts != numPts )
{
vlErrorMacro(<<"Number of points don't match!");
return;
}
break; //out of this loop
}
else
goto UNRECOGNIZED;
}
}
else if ( !strncmp(line, "point_data", 10) )
{
if ( (retStat=fscanf(fp,"%d", &numPts)) == EOF || retStat < 1 )
goto PREMATURE;
numPts = 0;
vlWarningMacro(<<"Not reading any dataset geometry...");
}
else
goto UNRECOGNIZED;
//
// Now read the point data
//
this->Reader.ReadPointData(fp, (vlDataSet *)this, numPts, this->Debug);
return;
PREMATURE:
vlErrorMacro(<< "Premature EOF");
return;
UNRECOGNIZED:
vlErrorMacro(<< "Unrecognized keyord: " << line);
return;
}
void vlPolyReader::PrintSelf(ostream& os, vlIndent indent)
{
vlPolySource::PrintSelf(os,indent);
os << indent << "Filename: " << this->Filename << "\n";
this->Reader.PrintSelf(os,indent.GetNextIndent());
}
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