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

ENH: First cut...

parent e9db7dc6
......@@ -25,6 +25,20 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
#include <stdio.h>
#include "DataSet.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
{
public:
......@@ -34,6 +48,11 @@ public:
FILE *OpenVLFile(char *filename, int debug);
int ReadHeader(FILE *fp, int debug);
int ReadPointData(FILE *fp, vlDataSet *ds, int numPts, int debug);
protected:
int FileType;
char *LowerCase(char *);
};
#endif
......
......@@ -14,22 +14,91 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "vlDataR.hh"
#include <ctype.h>
#define ASCII 1
#define BINARY 2
#include "BScalars.hh"
#include "CScalars.hh"
#include "FScalars.hh"
#include "SScalars.hh"
#include "FPoints.hh"
#include "IPoints.hh"
#include "FNormals.hh"
#include "FTensors.hh"
#include "FTCoords.hh"
#include "Graymap.hh"
#include "AGraymap.hh"
#include "Pixmap.hh"
#include "APixmap.hh"
#include "Lut.hh"
// Description:
// Open a vl data file. Returns NULL if error.
FILE *vlDataReader::OpenVLFile(char *filename, int debug)
{
return NULL;
FILE *fptr=NULL;
if ( debug )
{
vlReadDebugMacro(<< "Opening vl file");
}
if ( !filename || (fptr=fopen(filename, "rb")) == NULL )
{
vlReadErrorMacro(<< "Unable to open file: "<< filename);
}
return fptr;
}
// Description:
// Read the header of a vl data file. Returns 0 if error.
int vlDataReader::ReadHeader(FILE *fp, int debug)
{
char line[257];
int retStat;
if ( debug )
{
vlReadDebugMacro(<< "Reading vl file header");
}
//
// read header
//
if ( fgets (line, 256, fp) == NULL ) goto PREMATURE;
line[256] = '\0';
if ( strncmp ("# vl DataSet Version", line, 20) )
{
vlReadErrorMacro(<< "Unrecognized header: "<< line);
return 0;
}
//
// read title
//
if ( fgets (line, 256, fp) == NULL ) goto PREMATURE;
line[256] = '\0';
if ( debug )
{
vlReadDebugMacro(<< "Reading vl file entitled: " << line);
}
//
// read type
//
if ( (retStat=fscanf(fp,"%s",line)) == EOF || retStat < 1 ) goto PREMATURE;
if ( !strncmp(this->LowerCase(line),"ascii",5) ) this->FileType = ASCII;
else if ( !strncmp(line,"binary",6) ) this->FileType = BINARY;
else
{
vlReadErrorMacro(<< "Unrecognized file type: "<< line);
this->FileType == NULL;
return 0;
}
return 1;
PREMATURE:
vlReadErrorMacro(<< "Premature EOF");
return 0;
}
// Description:
......@@ -39,5 +108,120 @@ int vlDataReader::ReadHeader(FILE *fp, int debug)
// error.
int vlDataReader::ReadPointData(FILE *fp, vlDataSet *ds, int numPts, int debug)
{
int retStat;
char line[257];
if ( debug )
{
vlReadDebugMacro(<< "Reading vl point data");
}
//
// Read keywords until end-of-file
//
while ( (retStat=fscanf(fp, "%s", line)) != EOF && retStat == 1 )
{
//
// read scalar data
//
if ( ! strncmp(this->LowerCase(line), "scalars", 7) )
{
fscanf(fp, "%s", line);
if ( ! strncmp(line, "bit", 3) )
{
}
else if ( ! strncmp(line, "char", 4) )
{
vlCharScalars *scalars = new vlCharScalars(numPts);
unsigned char *ptr = scalars->WritePtr(0,numPts);
if ( this->FileType == BINARY)
{
fgets(line,256,fp); //suck up newline
fread(ptr,sizeof(unsigned char),numPts,fp);
}
else // ascii
{
}
ds->GetPointData()->SetScalars(scalars);
}
else if ( ! strncmp(line, "short", 5) )
{
}
else if ( ! strncmp(line, "int", 3) )
{
}
else if ( ! strncmp(line, "float", 5) )
{
}
else if ( ! strncmp(line, "double", 6) )
{
}
else
goto UNSUPPORTED;
}
//
// read vector data
//
else if ( ! strncmp(line, "vectors", 7) )
{
}
//
// read 3x3 tensor data
//
else if ( ! strncmp(line, "tensors", 7) )
{
}
//
// read normals data
//
else if ( ! strncmp(line, "normals", 7) )
{
}
//
// read texture coordinates data
//
else if ( ! strncmp(line, "texture_coordinates", 19) )
{
}
//
// read color scalars data
//
else if ( ! strncmp(line, "color_scalars", 13) )
{
}
//
// read lookup table. Associate with scalar data.
//
else if ( ! strncmp(line, "lookup_table", 12) )
{
}
else
{
vlReadErrorMacro(<< "Unsupported point attribute type: " << line);
return 0;
}
}
return 1;
PREMATURE:
vlReadErrorMacro(<< "Premature EOF");
return 0;
UNSUPPORTED:
vlReadErrorMacro(<< "Unsupported data type: " << line);
return 0;
}
char *vlDataReader::LowerCase(char *str)
{
for ( char *s=str; *s != '\0'; s++) *s = tolower(*s);
return str;
}
......@@ -27,9 +27,124 @@ vlStructuredPointsReader::~vlStructuredPointsReader()
void vlStructuredPointsReader::Execute()
{
FILE *fp;
int numPts=0;
int retStat;
char line[257];
int npts;
vlDebugMacro(<<"Reading vl structured points file...");
this->Initialize();
if ( !(fp=this->OpenVLFile(this->Filename, this->Debug)) ||
! this->ReadHeader(fp,this->Debug) )
return;
//
// Read structured points specific stuff
//
if ( (retStat=fscanf(fp,"%s",line)) == EOF || retStat < 1 ) goto PREMATURE;
if ( !strncmp(this->LowerCase(line),"dataset",(unsigned long)7) )
{
//
// Make sure we're reading right type of geometry
//
if ( (retStat=fscanf(fp,"%s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( strncmp(this->LowerCase(line),"structured_points",17) )
{
vlReadErrorMacro(<< "Cannot read dataset type: " << line);
return;
}
//
// Read keyword and number of points
//
numPts = this->GetNumberOfPoints(); // get default
while (1)
{
if ( (retStat=fscanf(fp,"%s",line)) == EOF || retStat < 1 )
goto PREMATURE;
if ( ! strncmp(this->LowerCase(line),"dimensions",10) )
{
int dim[3];
if ( (retStat=fscanf(fp,"%d %d %d",dim, dim+1, dim+2)) == EOF
|| retStat < 3 )
goto PREMATURE;
numPts = dim[0] * dim[1] * dim[2];
this->SetDimensions(dim);
}
else if ( ! strncmp(line,"aspect_ratio",12) )
{
float ar[3];
if ( (retStat=fscanf(fp,"%f %f %f",ar, ar+1, ar+2)) == EOF
|| retStat < 3 )
goto PREMATURE;
this->SetAspectRatio(ar);
}
else if ( ! strncmp(line,"origin",6) )
{
float origin[3];
if ( (retStat=fscanf(fp,"%f %f %f",origin, origin+1, origin+2)) == EOF
|| retStat < 3 )
goto PREMATURE;
this->SetOrigin(origin);
}
else if ( ! strncmp(line, "point_data", 16) )
{
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_attributes",16) )
{
if ( (retStat=fscanf(fp,"%d", &npts)) == EOF || retStat < 1 )
goto PREMATURE;
numPts = 0;
vlWarningMacro(<<"Not reading any dataset geometry...");
}
else
goto UNRECOGNIZED;
//
// Now read the point data
//
this->ReadPointData(fp, (vlDataSet *)this, numPts, this->Debug);
return;
PREMATURE:
vlReadErrorMacro(<< "Premature EOF");
return;
UNRECOGNIZED:
vlReadErrorMacro(<< "Unrecognized keyord: " << line);
return;
}
void vlStructuredPointsReader::PrintSelf(ostream& os, vlIndent indent)
{
vlStructuredPointsSource::PrintSelf(os,indent);
......
Supports Markdown
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