Commit bc91337d authored by hrchilds's avatar hrchilds

Update from March 29, 2005

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@440 18c085ea-50e0-402c-830e-de6fd14e8384
parent e410476d
......@@ -144,6 +144,10 @@
# Jeremy Meredith, Thu Mar 10 12:37:54 PST 2005
# Renamed SimDB to SimV1 to make versioning explicit.
#
# Brad Whitlock, Tue Mar 29 09:40:08 PDT 2005
# Added Shapefile reader for ESRI shape files, which are popular in
# GIS visualization.
#
##############################################################################
@SET_MAKE@
......@@ -161,7 +165,7 @@ PDB=KullLite PDB
SAF=SAF
SAMPLES=Rect Hex
REQUIRED=ANALYZE BOV CMAT Curve2D Dune EnSight Image Lines OVERFLOW \
PLOT2D PLOT3D Point3D SAR STL Silo SimV1 Spheral TFT Tecplot Vista \
PLOT2D PLOT3D Point3D SAR STL Shapefile Silo SimV1 Spheral TFT Tecplot Vista \
VTK WavefrontOBJ
VISUS=ViSUS
......
<?xml version="1.0"?>
<Plugin name="Shapefile" type="database" label="ESRI Shapefile" version="1.0" enabled="true" mdspecificcode="true" onlyengine="false" noengine="false" dbtype="STSD" haswriter="false">
<Extensions>
shp
shx
dbf
</Extensions>
<Files components="M">
avtShapefileFileFormat.C
esriShapefile.C
dbfFile.C
</Files>
<Files components="E">
avtShapefileFileFormat.C
esriShapefile.C
dbfFile.C
</Files>
<Attribute name="" purpose="" persistent="false">
</Attribute>
</Plugin>
#include <ShapefilePluginInfo.h>
#include <avtShapefileFileFormat.h>
#include <avtSTSDFileFormatInterface.h>
#include <avtGenericDatabase.h>
// ****************************************************************************
// Method: ShapefileCommonPluginInfo::GetDatabaseType
//
// Purpose:
// Returns the type of a Shapefile database.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
DatabaseType
ShapefileCommonPluginInfo::GetDatabaseType()
{
return DB_TYPE_STSD;
}
// ****************************************************************************
// Method: ShapefileCommonPluginInfo::GetDefaultExtensions
//
// Purpose:
// Returns the default extensions for a Shapefile database.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
std::vector<std::string>
ShapefileCommonPluginInfo::GetDefaultExtensions()
{
std::vector<std::string> defaultExtensions;
defaultExtensions.push_back("shp");
defaultExtensions.push_back("shx");
defaultExtensions.push_back("dbf");
return defaultExtensions;
}
// ****************************************************************************
// Method: ShapefileCommonPluginInfo::SetUpShapefileDatabase
//
// Purpose:
// Sets up a Shapefile database.
//
// Arguments:
// list A list of file names.
// nList The number of timesteps in list.
// nBlocks The number of blocks in the list.
//
// Returns: A Shapefile database from list.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
avtDatabase *
ShapefileCommonPluginInfo::SetupDatabase(const char *const *list,
int nList, int nBlock)
{
avtSTSDFileFormat ***ffl = new avtSTSDFileFormat**[nList];
int nTimestep = nList / nBlock;
for (int i = 0 ; i < nTimestep ; i++)
{
ffl[i] = new avtSTSDFileFormat*[nBlock];
for (int j = 0 ; j < nBlock ; j++)
{
ffl[i][j] = new avtShapefileFileFormat(list[i*nBlock + j]);
}
}
avtSTSDFileFormatInterface *inter
= new avtSTSDFileFormatInterface(ffl, nTimestep, nBlock);
return new avtGenericDatabase(inter);
}
#include <ShapefilePluginInfo.h>
#if defined(__APPLE__)
#define GetEngineInfo Shapefile_GetEngineInfo
#endif
// ****************************************************************************
// Function: GetEngineInfo
//
// Purpose:
// Return a new EnginePluginInfo for the Shapefile database.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
extern "C" EngineDatabasePluginInfo* GetEngineInfo()
{
return new ShapefileEnginePluginInfo;
}
// ****************************************************************************
// Method: ShapefileCommonPluginInfo::GetWriter
//
// Purpose:
// Sets up a Shapefile writer.
//
// Returns: A Shapefile writer.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
avtDatabaseWriter *
ShapefileEnginePluginInfo::GetWriter(void)
{
return NULL;
}
#include <ShapefilePluginInfo.h>
#if defined(__APPLE__)
#define GetMDServerInfo Shapefile_GetMDServerInfo
#endif
// ****************************************************************************
// Function: GetMDServerInfo
//
// Purpose:
// Return a new MDServerPluginInfo for the Shapefile database.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
extern "C" MDServerDatabasePluginInfo* GetMDServerInfo()
{
return new ShapefileMDServerPluginInfo;
}
// this makes compilers happy... remove if we ever have functions here
void ShapefileMDServerPluginInfo::dummy()
{
}
// ************************************************************************* //
// File: ShapefilePluginInfo.C
// ************************************************************************* //
#include <ShapefilePluginInfo.h>
#include <visit-config.h>
#if defined(__APPLE__)
extern "C" const char *ShapefileVisItPluginVersion = VERSION;
#else
extern "C" const char *VisItPluginVersion = VERSION;
#endif
#if defined(__APPLE__)
#define GetGeneralInfo Shapefile_GetGeneralInfo
#endif
// ****************************************************************************
// Function: GetGeneralInfo
//
// Purpose:
// Return a new GeneralPluginInfo for the Shapefile database.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
extern "C" GeneralDatabasePluginInfo* GetGeneralInfo()
{
return new ShapefileGeneralPluginInfo;
}
// ****************************************************************************
// Method: ShapefileGeneralPluginInfo::GetName
//
// Purpose:
// Return the name of the database plugin.
//
// Returns: A pointer to the name of the database plugin.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
char *
ShapefileGeneralPluginInfo::GetName() const
{
return "Shapefile";
}
// ****************************************************************************
// Method: ShapefileGeneralPluginInfo::GetVersion
//
// Purpose:
// Return the version of the database plugin.
//
// Returns: A pointer to the version of the database plugin.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
char *
ShapefileGeneralPluginInfo::GetVersion() const
{
return "1.0";
}
// ****************************************************************************
// Method: ShapefileGeneralPluginInfo::GetID
//
// Purpose:
// Return the id of the database plugin.
//
// Returns: A pointer to the id of the database plugin.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
char *
ShapefileGeneralPluginInfo::GetID() const
{
return "Shapefile_1.0";
}
// ****************************************************************************
// Method: ShapefileGeneralPluginInfo::EnabledByDefault
//
// Purpose:
// Return true if this plugin should be enabled by default; false otherwise.
//
// Returns: true/false
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
bool
ShapefileGeneralPluginInfo::EnabledByDefault() const
{
return true;
}
// ****************************************************************************
// Method: ShapefileGeneralPluginInfo::HasWriter
//
// Purpose:
// Return true if this plugin has a database writer.
//
// Returns: true/false
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// ****************************************************************************
bool
ShapefileGeneralPluginInfo::HasWriter() const
{
return false;
}
// ****************************************************************************
// ShapefilePluginInfo.h
// ****************************************************************************
#ifndef SHAPEFILE_PLUGIN_INFO_H
#define SHAPEFILE_PLUGIN_INFO_H
#include <DatabasePluginInfo.h>
#include <database_plugin_exports.h>
class avtDatabase;
class avtDatabaseWriter;
// ****************************************************************************
// Class: ShapefileDatabasePluginInfo
//
// Purpose:
// Classes that provide all the information about the Shapefile plugin.
// Portions are separated into pieces relevant to the appropriate
// components of VisIt.
//
// Programmer: whitlocb -- generated by xml2info
// Creation: Mon Mar 28 03:13:03 PDT 2005
//
// Modifications:
//
// ****************************************************************************
class ShapefileGeneralPluginInfo : public virtual GeneralDatabasePluginInfo
{
public:
virtual char *GetName() const;
virtual char *GetVersion() const;
virtual char *GetID() const;
virtual bool EnabledByDefault() const;
virtual bool HasWriter() const;
};
class ShapefileCommonPluginInfo : public virtual CommonDatabasePluginInfo, public virtual ShapefileGeneralPluginInfo
{
public:
virtual DatabaseType GetDatabaseType();
virtual std::vector<std::string> GetDefaultExtensions();
virtual avtDatabase *SetupDatabase(const char * const *list,
int nList, int nBlock);
};
class ShapefileMDServerPluginInfo : public virtual MDServerDatabasePluginInfo, public virtual ShapefileCommonPluginInfo
{
public:
// this makes compilers happy... remove if we ever have functions here
virtual void dummy();
};
class ShapefileEnginePluginInfo : public virtual EngineDatabasePluginInfo, public virtual ShapefileCommonPluginInfo
{
public:
virtual avtDatabaseWriter *GetWriter(void);
};
#endif
This diff is collapsed.
// ************************************************************************* //
// avtShapefileFileFormat.h //
// ************************************************************************* //
#ifndef AVT_Shapefile_FILE_FORMAT_H
#define AVT_Shapefile_FILE_FORMAT_H
#include <avtSTSDFileFormat.h>
#include <esriShapefile.h>
#include <dbfFile.h>
#include <vector>
// ****************************************************************************
// Class: avtShapefileFileFormat
//
// Purpose:
// Reads in ESRI Shapefile files as a plugin to VisIt.
//
// Programmer: Brad Whitlock
// Creation: Thu Mar 24 12:18:02 PDT 2005
//
// Modifications:
//
// ****************************************************************************
class avtShapefileFileFormat : public avtSTSDFileFormat
{
public:
avtShapefileFileFormat(const char *filename);
virtual ~avtShapefileFileFormat();
//
// This is used to return unconvention data -- ranging from material
// information to information about block connectivity.
//
// virtual void &GetAuxiliaryData(const char *var, const char *type,
// void *args, DestructorFunction &);
//
//
// These are used to declare what the current time and cycle are for the
// file. These should only be defined if the file format knows what the
// time and/or cycle is.
//
// virtual bool ReturnsValidCycle() const { return true; };
// virtual int GetCycle(void);
// virtual bool ReturnsValidTime() const { return true; };
// virtual double GetTime(void);
//
virtual const char *GetType(void) { return "ESRI Shapefile"; };
virtual void FreeUpResources(void);
virtual void ActivateTimestep(void);
virtual vtkDataSet *GetMesh(const char *);
virtual vtkDataArray *GetVar(const char *);
virtual vtkDataArray *GetVectorVar(const char *);
protected:
struct esriShape
{
esriShapeType_t shapeType;
void *shape;
};
typedef std::vector<esriShape> esriShapeVector;
void Initialize();
int CountMemberPoints(esriShapeType_t) const;
int CountShapes(esriShapeType_t) const;
int CountCellsForShape(esriShapeType_t) const;
bool initialized;
esriShapeVector shapes;
int numShapeTypes;
dbfFile_t *dbfFile;
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *);
};
#endif
This diff is collapsed.
#ifndef DBF_FILE_H
#define DBF_FILE_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
// ****************************************************************************
// Purpose: This header provides functions and types that can be used to
// read fields from a DBASE file used by ESRI shape files.
//
//
// Notes:
//
// Programmer: Brad Whitlock
// Creation: Sun Mar 27 23:51:03 PST 2005
//
// Modifications:
//
// ****************************************************************************
typedef struct
{
unsigned char month;
unsigned char day;
unsigned int year;
} dbfDate_t;
typedef enum
{
dbfFieldChar,
dbfFieldDate,
dbfFieldFloatingPointNumber,
dbfFieldFixedPointNumber,
dbfFieldLogical,
dbfFieldMemo,
dbfFieldVariable,
dbfFieldPicture,
dbfFieldBinary,
dbfFieldGeneral,
dbfFieldShortInt,
dbfFieldInt,
dbfFieldDouble,
} dbfFieldType_t;
typedef struct
{
char fieldName[11];
dbfFieldType_t fieldType;
unsigned int fieldOffset;
unsigned char fieldLength;
unsigned char decimalCount;
unsigned char workAreaId;
unsigned char multiUser[2];
unsigned char setFields;
unsigned char fieldIsIndexed;
} dbfFieldDescriptor_t;
typedef struct
{
unsigned char format;
dbfDate_t lastUpdate;
unsigned long numRecords;
unsigned short headerSize;
unsigned short recordSize;
unsigned char transaction;
unsigned char encrypted;
unsigned char multiUser[12];
unsigned char indexExists;
unsigned char languageDriver;
unsigned int numFieldDescriptors;
dbfFieldDescriptor_t *fieldDescriptors;
} dbfFileHeader_t;
typedef struct
{
FILE *fp;
char *filename;
dbfFileHeader_t header;
} dbfFile_t;
typedef enum
{
dbfFileErrorSuccess,
dbfFileErrorInvalidFile,
dbfFileErrorNotFound
} dbfFileError_t;
typedef enum
{
dbfReadErrorSuccess,
dbfReadErrorFailure,
dbfReadErrorInvalidRequest
} dbfReadError_t;
/* Memory allocation, deallocation routines. */
#define dbfMalloc(S) dbfMallocEx(__FILE__,__LINE__, #S,S)
#define dbfFree(P) dbfFreeEx(__FILE__,__LINE__, #P, P)
void *dbfMallocEx(const char *f, const int line, const char *src, size_t s);
void dbfFreeEx(const char *f, const int line, const char *src, void *ptr);
void dbfInitialize(int commonStorage,
void*(*user_malloc)(size_t),
void (*user_free)(void *));
void dbfFinalize();
dbfFile_t *dbfFileOpen(const char *filename, dbfFileError_t *);
void dbfFileClose(dbfFile_t *);
int dbfGetFieldStorageSize(dbfFieldDescriptor_t *);
dbfFieldDescriptor_t *dbfGetFieldDescriptor(dbfFile_t *, const char *field,
unsigned int *offset);
void dbfSetForceFloat(int);
void *dbfFileReadField(dbfFile_t *, const char *field, dbfReadError_t *rcError);
void *dbfFileReadField2(dbfFile_t *, const char *field, void *data,
dbfReadError_t *rcError);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
#include <dbfFile.h>
int
main(int argc, char *argv[])
{
dbfFile_t *f = 0;
dbfFileError_t fileError;
dbfReadError_t rcError;
void *data = 0;
dbfInitialize(1, 0, 0);
#if 1
#define DATABASE "m195mbsp.dbf"
#define VARIABLE "EPA_NO"
#else
#define DATABASE "GebcoDepthContours.dbf"
#define VARIABLE "DEPTH"
#endif
f = dbfFileOpen(DATABASE, &fileError);
if(f != 0)
{
/* Try and read some data */
data = dbfFileReadField(f, VARIABLE, &rcError);
if(rcError == dbfReadErrorSuccess)
{
printf("We were able to read the %s field.\n", VARIABLE);
dbfFree(data);
}
else if(rcError == dbfReadErrorFailure)
printf("We were NOT able to read the %s field!\n", VARIABLE);
else
printf("%s is not a valid field name.\n", VARIABLE);
}
dbfFileClose(f);
dbfFinalize();
return 0;
}
#include <esriShapefile.h>
int
main(int argc, char *argv[])
{
FILE *outputLog = 0;
esriShapefile_t *f = 0;
esriFileError_t code;
int keepReading = 1;
if(argc < 2)
{
fprintf(stderr, "Usage: %s filename\n", argv[0]);
return -1;
}
/* Open the output log file. */
outputLog = fopen("output.log", "wt");
if(outputLog == 0)
return -1;
esriInitialize(1, 0);
f = esriShapefileOpen(argv[1], &code);
if(code == esriFileErrorSuccess)
fprintf(outputLog, "Opened the file!\n");
else if(code == esriFileErrorInvalidFile)
{
fprintf(outputLog, "The file was not an ESRI shape file!\n");
return -1;
}
else
{
fprintf(outputLog, "Could not open the file!\n");
return -1;
}
// Process the file.
do
{
void *s = 0;
// Read the record header.
esriShapefileRecordHeader_t header;
esriReadError_t rcErr;
esriShapefileReadRecordHeader(f, &header, &rcErr);
if(rcErr == esriReadErrorSuccess)
{
/*fprintf(stderr, "Record %d: ", header.recordNumber);*/
switch(header.shapeType)
{
case esriNullShape:
break;
case esriPoint:
s = esriMalloc(sizeof(esriPoint_t));
esriShapefileReadPoint(&header, (esriPoint_t *)s, &rcErr);
esriPrintPoint(outputLog, (esriPoint_t *)s);
break;