Updates for osgdem. Including new read/writeHeightField() methods.

This commit is contained in:
Robert Osfield
2003-10-29 11:11:17 +00:00
parent b9775a1a3e
commit f1c4dc3b0d
17 changed files with 557 additions and 63 deletions

View File

@@ -436,7 +436,12 @@ class SG_EXPORT HeightField : public Shape
META_Shape(osg, HeightField)
void allocateGrid(unsigned int numColumns,unsigned int numRows);
typedef std::vector<float> HeightList;
void allocate(unsigned int numColumns,unsigned int numRows);
// deprecated.
void allocateGrid(unsigned int numColumns,unsigned int numRows) { allocate(numColumns,numRows); }
inline unsigned int getNumColumns() const { return _columns; }
inline unsigned int getNumRows() const { return _rows; }
@@ -466,6 +471,9 @@ class SG_EXPORT HeightField : public Shape
return _heights[c+r*_columns];
}
HeightList& getHeightList() { return _heights; }
const HeightList& getHeightList() const { return _heights; }
Vec3 getNormal(unsigned int c,unsigned int r) const;
inline void setRotation(const Quat& quat) { _rotation = quat; }
@@ -484,15 +492,17 @@ class SG_EXPORT HeightField : public Shape
float _dy;
Quat _rotation;
typedef std::vector<float> HeightList;
HeightList _heights;
};
typedef HeightField Grid;
class CompositeShape : public Shape
{
public:
typedef std::vector< ref_ptr<Shape> > ChildList;

View File

@@ -67,6 +67,26 @@ inline osg::Image* readImageFile(const std::string& filename)
return readImageFile(filename,Registry::instance()->getUseObjectCacheHint());
}
/** Read an osg::HeightField from file.
* Return valid osg::HeightField on success,
* return NULL on failure.
* Use the useObjectCache flag to override the osgDB::Regisytr::getUseObjectCacheHint().
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::HeightField* readHeightFieldFile(const std::string& filename,bool useObjectCache);
/** Read an osg::HeightField from file.
* Return valid osg::HeightField on success,
* return NULL on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::HeightField* readHeightFieldFile(const std::string& filename)
{
return readHeightFieldFile(filename,Registry::instance()->getUseObjectCacheHint());
}
/** Read an osg::Node from file.
* Return valid osg::Node on success,
* return NULL on failure.

View File

@@ -16,6 +16,7 @@
#include <osg/Referenced>
#include <osg/Image>
#include <osg/Shape>
#include <osg/Node>
#include <osgDB/Export>
@@ -73,14 +74,17 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
osg::Object* getObject() { return _object.get(); }
osg::Image* getImage() { return dynamic_cast<osg::Image*>(_object.get()); }
osg::HeightField* getHeightField() { return dynamic_cast<osg::HeightField*>(_object.get()); }
osg::Node* getNode() { return dynamic_cast<osg::Node*>(_object.get()); }
bool validObject() { return _object.valid(); }
bool validImage() { return getImage()!=0; }
bool validHeightField() { return getHeightField()!=0; }
bool validNode() { return getNode()!=0; }
osg::Object* takeObject() { osg::Object* obj = _object.get(); if (obj) { obj->ref(); _object=NULL; obj->unref_nodelete(); } return obj; }
osg::Image* takeImage() { osg::Image* image=dynamic_cast<osg::Image*>(_object.get()); if (image) { image->ref(); _object=NULL; image->unref_nodelete(); } return image; }
osg::HeightField* takeHeightField() { osg::HeightField* hf=dynamic_cast<osg::HeightField*>(_object.get()); if (hf) { hf->ref(); _object=NULL; hf->unref_nodelete(); } return hf; }
osg::Node* takeNode() { osg::Node* node=dynamic_cast<osg::Node*>(_object.get()); if (node) { node->ref(); _object=NULL; node->unref_nodelete(); } return node; }
const std::string& message() const { return _message; }
@@ -129,18 +133,22 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }

View File

@@ -120,6 +120,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced
ReaderWriter::ReadResult readImage(const std::string& fileName,bool useObjectCache);
ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName);
ReaderWriter::ReadResult readHeightField(const std::string& fileName,bool useObjectCache);
ReaderWriter::WriteResult writeHeightField(const osg::HeightField& obj, const std::string& fileName);
ReaderWriter::ReadResult readNode(const std::string& fileName,bool useObjectCache);
ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& fileName);
@@ -231,6 +234,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
ReaderWriter::ReadResult readObject(const std::string& fileName);
ReaderWriter::ReadResult readImage(const std::string& fileName);
ReaderWriter::ReadResult readHeightField(const std::string& fileName);
ReaderWriter::ReadResult readNode(const std::string& fileName);
DotOsgWrapperMap _objectWrapperMap;

View File

@@ -15,6 +15,7 @@
#define OSGDB_WRITEFILE 1
#include <osg/Image>
#include <osg/Shape>
#include <osg/Node>
#include <osgDB/Export>
@@ -40,6 +41,14 @@ extern OSGDB_EXPORT bool writeObjectFile(const osg::Object& object, const std::s
* to write the specified file.*/
extern OSGDB_EXPORT bool writeImageFile(const osg::Image& image, const std::string& filename);
/** Write an osg::HeightField to file.
* Return true on success,
* return false on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to write the specified file.*/
extern OSGDB_EXPORT bool writeHeightFieldFile(const osg::HeightField& hf, const std::string& filename);
/** Write an osg::Node to file.
* Return true on success,
* return false on failure.