Removed files.... synching witn 0.8.42

This commit is contained in:
Don BURNS 2001-09-19 21:51:06 +00:00
parent bc739f47a9
commit 77494207fb
37 changed files with 0 additions and 6019 deletions

View File

@ -1,45 +0,0 @@
#ifndef OSG_DCS
#define OSG_DCS 1
#include <osg/Group>
#include <osg/Matrix>
namespace osg {
/** DCS - Dynamic Coordinate System a is group which all children
are transformed by the the DCS's osg::Matrix. Typical uses
of the DCS is for positioning objects within a scene or
producing trakerball functionality.
*/
class SG_EXPORT DCS : public Group
{
public :
DCS();
DCS(const Matrix& matix);
virtual Object* clone() const { return new DCS(); }
virtual bool isSameKindAs(Object* obj) { return dynamic_cast<DCS*>(obj)!=NULL; }
virtual const char* className() const { return "DCS"; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
void setMatrix(const Matrix& mat );
Matrix* getMatrix() { return _mat; }
void preTranslate( float tx, float ty, float tz );
void preRotate( float deg, float x, float y, float z );
bool computeBound();
protected :
virtual ~DCS();
virtual bool readLocalData(Input& fr);
virtual bool writeLocalData(Output& fw);
Matrix *_mat;
};
};
#endif

View File

@ -1,51 +0,0 @@
#ifndef OSG_DYNAMICLIBRARY
#define OSG_DYNAMICLIBRARY 1
#include <string>
#include <osg/Referenced>
#ifdef WIN32
//#include <Windows.h>
#endif
namespace osg {
/** DynamicLibrary - encapsulates the loading and unloading of dynamic libraries,
typically used for loading ReaderWriter plug-ins.
*/
class SG_EXPORT DynamicLibrary : public Referenced
{
public:
#ifdef WIN32
// from Snados.h
typedef void* HANDLE;
// from Delayimp.h
typedef void* PROC_ADDRESS;
#else
typedef void* HANDLE;
typedef void* PROC_ADDRESS;
#endif
static DynamicLibrary* loadLibrary(const std::string& libraryName);
const std::string& getName() const { return _name; }
const std::string& getFullName() const { return _fullName; }
HANDLE getHandle() const { return _handle; }
PROC_ADDRESS getProcAddress(const std::string& procName);
protected:
DynamicLibrary(const std::string& name,HANDLE handle);
~DynamicLibrary();
HANDLE _handle;
std::string _name;
std::string _fullName;
};
};
#endif // __DYNAMIC_LIBRARY_H

View File

@ -1,15 +0,0 @@
#ifndef OSG_EXTENSIONSUPPORTED
#define OSG_EXTENSIONSUPPORTED 1
#include <osg/Export>
namespace osg {
/** return true if OpenGL "extension" is supported.
note: Must only called within a valid OpenGL context,
undefined behaviour may occur otherwise.*/
SG_EXPORT extern bool ExtensionSupported(const char *extension);
};
#endif

View File

@ -1,100 +0,0 @@
#ifndef OSG_FIELD
#define OSG_FIELD 1
#include <osg/Export>
#include <string>
#include <stdlib.h>
namespace osg {
class SG_EXPORT Field
{
public:
enum {
MIN_CACHE_SIZE = 256
};
Field();
Field(const Field& field);
virtual ~Field();
virtual Field& operator = (const Field& ic);
void reset();
void addChar(char c);
int getNoCharacters() const { return _fieldCacheSize; }
void setWithinQuotes(bool withinQuotes=true);
bool getWithinQuotes();
void setNoNestedBrackets(int no);
int getNoNestedBrackets();
enum FieldType
{
OPEN_BRACKET,
CLOSE_BRACKET,
STRING,
WORD,
REAL,
INTEGER,
BLANK,
UNINTIALISED
};
FieldType getFieldType() const;
bool isValid() const;
bool isOpenBracket() const;
bool isCloseBracket() const;
bool isWord() const;
bool matchWord(const char* str) const;
bool matchWord(const char* str,int noCharacters) const;
bool isString() const;
bool matchString(const char* str) const;
bool matchString(const char* str,int noCharacters) const;
bool isQuotedString() const;
const char* getStr() const;
char* takeStr();
bool isInt() const;
bool matchInt(int i) const;
bool getInt(int& i) const;
bool isFloat() const;
bool matchFloat(float f) const;
bool getFloat(float& f) const;
bool isDouble() const;
bool matchDouble(double f) const;
bool getDouble(double& d) const;
static FieldType calculateFieldType(const char* str,bool withinQuotes=false);
protected:
void _init();
void _free();
void _copy(const Field& ic);
int _fieldCacheCapacity;
int _fieldCacheSize;
char* _fieldCache;
mutable FieldType _fieldType;
bool _withinQuotes;
int _noNestedBrackets;
};
};
#endif // __SG_FIELD_H

View File

@ -1,62 +0,0 @@
#ifndef OSG_FIELDREADER
#define OSG_FIELDREADER 1
#include <osg/Export>
#include <string.h>
#include <stdlib.h>
#ifdef OSG_USE_IO_DOT_H
#include <iostream.h>
#else
#include <iostream>
using namespace std;
#endif
namespace osg {
class Field;
class SG_EXPORT FieldReader
{
public:
FieldReader();
FieldReader(const FieldReader& ic);
virtual ~FieldReader();
virtual FieldReader& operator = (const FieldReader& ic);
void attach(istream* input);
void detach();
virtual bool eof() const;
bool readField(Field& fieldPtr);
void ignoreField();
/** no of unmatched `{' encounterd so far in file*/
int getNoNestedBrackets() const;
private:
bool _readField(Field* fieldPtr);
void _init();
void _free();
void _copy(const FieldReader& ic);
istream* _fin;
bool _eof;
bool findStartOfNextField();
int _noNestedBrackets;
bool _delimatorEatLookUp[256];
bool _delimatorKeepLookUp[256];
};
};
#endif // __SG_FIELD_READER_H

View File

@ -1,68 +0,0 @@
#ifndef OSG_FIELDREADERITERATOR
#define OSG_FIELDREADERITERATOR 1
#include <osg/Field>
#include <osg/FieldReader>
namespace osg {
class SG_EXPORT FieldReaderIterator
{
public:
enum {
MINIMUM_FIELD_READER_QUEUE_SIZE = 10
};
FieldReaderIterator();
FieldReaderIterator(const FieldReaderIterator& ic);
virtual ~FieldReaderIterator();
virtual FieldReaderIterator& operator = (const FieldReaderIterator& ic);
void attach(istream* input);
void detach();
virtual bool eof() const;
FieldReader& getFieldReader() { return _reader; }
void insert(int pos,Field* field);
void insert(int pos,const char* str);
Field& operator [] (int pos);
Field& field (int pos);
FieldReaderIterator& operator ++ ();
FieldReaderIterator& operator += (int no);
/** increments the itetor of the next simple field or
whole block if the current field[0] is an open bracket */
void advanceOverCurrentFieldOrBlock();
void advanceToEndOfCurrentBlock();
void advanceToEndOfBlock(int noNestBrackets);
bool matchSequence(const char* str);
private:
void _init();
void _free();
void _copy(const FieldReaderIterator& ic);
FieldReader _reader;
Field _blank;
Field* _previousField;
Field** _fieldQueue;
int _fieldQueueSize;
int _fieldQueueCapacity;
};
};
#endif // __OSG_FIELD_READER_QUEUE_H

View File

@ -1,18 +0,0 @@
#ifndef OSG_FILENAMEUTILS
#define OSG_FILENAMEUTILS 1
#include <osg/Export>
#include <string>
namespace osg {
SG_EXPORT extern std::string getFilePath(const std::string& filename);
SG_EXPORT extern std::string getFileExtension(const std::string& filename);
SG_EXPORT extern std::string getLowerCaseFileExtension(const std::string& filename);
SG_EXPORT extern std::string getSimpleFileName(const std::string& fileName);
SG_EXPORT extern std::string getStrippedName(const std::string& fileName);
};
#endif

View File

@ -1,150 +0,0 @@
#ifndef OSG_GEOSTATE
#define OSG_GEOSTATE 1
#include <osg/OSG>
#include <osg/Texture>
#include <osg/TexGen>
#include <osg/Light>
#include <osg/Material>
#include <osg/TexEnv>
#include <osg/Transparency>
#include <osg/Lighting>
#include <osg/Fog>
#include <osg/TexMat>
#include <osg/CullFace>
#include <osg/Point>
#include <osg/PolygonOffset>
#include <osg/AlphaFunc>
namespace osg {
class Input;
class Output;
/**
Encapsulates OpenGL state modes and attributes.
Used to specificy textures etc of osg::GeoSet's which hold references
to a single osg::GeoState. GeoState can be shared between GeoSet's
and is recommend if possible as it minimize expensive state changes
in the graphics pipeline.
*/
class SG_EXPORT GeoState : public Object
{
public :
enum AttributeType
{
ANTIALIAS,
FACE_CULL,
FOG,
LIGHTING,
MATERIAL,
POINT,
POLYGON_OFFSET,
TEXENV,
TEXGEN,
TEXMAT,
TEXTURE,
TRANSPARENCY,
WIREFRAME,
ALPHAFUNC
};
enum AttributeMode
{
INHERIT,
OFF,
ON,
OVERRIDE_OFF,
OVERRIDE_ON,
};
GeoState();
static GeoState* instance();
virtual Object* clone() const { return new GeoState(); }
virtual bool isSameKindAs(Object* obj) { return dynamic_cast<GeoState*>(obj)!=NULL; }
const char* className() const { return "GeoState"; }
/** set all the modes to on or off so that it defines a
complete state, typically used for a default global state.*/
void setGlobalDefaults();
/** set all the modes to inherit, typically used to signifiy
nodes which inherit all of their modes for the global state.*/
void setAllToInherit();
void setMode(AttributeType type, AttributeMode mode);
AttributeMode getMode(AttributeType type) const;
void setAttribute(AttributeType type, Object *attribute);
Object* getAttribute(AttributeType type) const;
bool isTransparent() { return _transparencing==ON; }
void apply();
void apply(GeoState* global,GeoState* prev);
bool check();
static AttributeMode combineMode(const AttributeMode g,const AttributeMode p,const AttributeMode c)
{
AttributeMode gp = mergeMode(g,p);
AttributeMode gc = mergeMode(g,c);
if (gc==gp) return INHERIT;
else return gc;
}
static AttributeMode mergeMode(const AttributeMode lhs,const AttributeMode rhs)
{
AttributeMode mode;
if (rhs==INHERIT || lhs==OVERRIDE_OFF || lhs==OVERRIDE_ON) mode = lhs;
else mode = rhs;
if (mode==OVERRIDE_OFF) return OFF;
else if (mode==OVERRIDE_OFF) return ON;
return mode;
}
protected :
virtual ~GeoState();
GeoState(const GeoState&):Object() {}
GeoState& operator = (const GeoState&) { return *this; }
virtual bool readLocalData(Input& fr);
virtual bool writeLocalData(Output& fw);
bool matchModeStr(const char* str, AttributeMode& mode);
const char* getModeStr(AttributeMode flag);
// Modes
AttributeMode _transparencing;
AttributeMode _face_culling;
AttributeMode _lighting;
AttributeMode _texturing;
AttributeMode _fogging;
AttributeMode _texgening;
AttributeMode _antialiasing;
AttributeMode _colortable;
AttributeMode _pointSmoothing;
AttributeMode _polygonOffsetting;
AttributeMode _alphaTesting;
// Attributes
ref_ptr<Texture> _texture;
ref_ptr<TexGen> _texgen;
ref_ptr<Material> _material;
ref_ptr<TexEnv> _texenv;
ref_ptr<Transparency> _transparency;
ref_ptr<TexMat> _texmat;
ref_ptr<Fog> _fog;
ref_ptr<Point> _point;
ref_ptr<PolygonOffset> _polygonOffset;
ref_ptr<CullFace> _cullFace;
ref_ptr<AlphaFunc> _alphaFunc;
};
};
#endif

View File

@ -1,49 +0,0 @@
#ifndef OSG_INPUT
#define OSG_INPUT 1
#include <osg/FieldReaderIterator>
#include <map>
#include <string>
namespace osg {
class Object;
class Image;
class Node;
/** Class for managing the reading of ASCII .osg files.*/
class SG_EXPORT Input : public FieldReaderIterator
{
public:
// Will extend to handle #DEF and use
// functionality similar to Inventor,
// and add the ability to handle #include
// from within the OSG file format.
Input();
virtual ~Input();
virtual Object* readObject();
virtual Object* readObject(const std::string& fileName);
virtual Image* readImage();
virtual Image* readImage(const std::string& fileName);
virtual Node* readNode();
virtual Node* readNode(const std::string& fileName);
virtual Object* getObjectForUniqueID(const std::string& uniqueID);
virtual void regisiterUniqueIDForObject(const std::string& uniqueID,Object* obj);
private:
typedef std::map<std::string,Object*> UniqueIDToObjectMapping;
UniqueIDToObjectMapping _uniqueIDToObjectMap;
};
};
#endif // __SG_INPUT_H

View File

@ -1,21 +0,0 @@
#ifndef OSG_LIGHTING
#define OSG_LIGHTING 1
#include <osg/Export>
namespace osg {
/** Class to globally control OpenGL's lighting.*/
class SG_EXPORT Lighting
{
public :
/** Enable lighting.*/
static void enable();
/** Disable lighting.*/
static void disable();
};
};
#endif

View File

@ -1,15 +0,0 @@
#ifndef OSG_OSG
#define OSG_OSG 1
#include <osg/Node>
namespace osg {
SG_EXPORT extern void Init( void );
SG_EXPORT extern void SetFilePath( const char *_path );
SG_EXPORT extern char *FindFile( const char *file );
SG_EXPORT extern char *findDSO( const char *name );
};
#endif

View File

@ -1,98 +0,0 @@
#ifndef OSG_OUTPUT
#define OSG_OUTPUT 1
#include <osg/Export>
#include <string>
#include <map>
#ifdef OSG_USE_IO_DOT_H
#include <fstream.h>
#else
#include <fstream>
using namespace std;
#endif
namespace osg {
class Object;
/** ofstream wrapper class for adding support for indenting.
Used in output of .osg ASCII files to improve their readability.*/
class SG_EXPORT Output : public ofstream
{
public:
Output();
virtual ~Output();
Output& indent();
int getIndentStep() const { return _indentStep; }
void setIndentStep(int step) { _indentStep = step; }
int getIndent() const { return _indent; }
void setIndent(int indent) { _indent = indent; }
int getNumIndicesPerLine() const { return _numIndicesPerLine; }
void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; }
void moveIn();
void moveOut();
bool getUniqueIDForObject(Object* obj,std::string& uniqueID);
bool createUniqueIDForObject(Object* obj,std::string& uniqueID);
bool registerUniqueIDForObject(Object* obj,std::string& uniqueID);
protected:
// prevent copy construction and assignment.
Output(const Output&) : ofstream() {}
Output& operator = (const Output&) { return *this; }
virtual void _init();
virtual void _free();
int _indent;
int _indentStep;
int _numIndicesPerLine;
typedef std::map<Object*,std::string> UniqueIDToLabelMapping;
UniqueIDToLabelMapping _objectToUniqueIDMap;
};
template<class T>
bool writeArrayBlock(Output& fw,T* start,T* finish)
{
fw.indent() << "{" << endl;
fw.moveIn();
int numIndicesThisLine = 0;
for(T* itr=start;itr!=finish;++itr)
{
if (numIndicesThisLine>=fw.getNumIndicesPerLine())
{
fw << endl;
numIndicesThisLine = 0;
}
if (numIndicesThisLine==0) fw.indent();
else fw << " ";
fw << *itr;
++numIndicesThisLine;
}
fw << endl;
fw.moveOut();
fw.indent() << "}" << endl;
return true;
}
};
#endif // __SG_OUTPUT_H

View File

@ -1,168 +0,0 @@
#ifndef OSG_REGISTRY
#define OSG_REGISTRY 1
#include <vector>
#include <string>
#include <osg/Referenced>
#include <osg/DynamicLibrary>
namespace osg {
// forward declare referenced classes to help avoid mutiple includes
class Object;
class Image;
class Node;
class Input;
SG_EXPORT extern Object* loadObjectFile(const char *name);
SG_EXPORT extern Image* loadImageFile(const char *name);
SG_EXPORT extern Node* loadNodeFile(const char *name);
SG_EXPORT extern bool saveObjectFile(Object& object, const char *name);
SG_EXPORT extern bool saveImageFile(Image& image, const char *name);
SG_EXPORT extern bool saveNodeFile(Node& node, const char *name);
/** pure virtual base class for reading and writing of non native formats. */
class SG_EXPORT ReaderWriter : public Referenced
{
public:
virtual ~ReaderWriter() {}
virtual const char* className() = 0;
virtual bool acceptsExtension(const std::string& /*extension*/) { return false; }
virtual Object* readObject(const std::string& /*fileName*/) { return NULL; }
virtual Image* readImage(const std::string& /*fileName*/) { return NULL; }
virtual Node* readNode(const std::string& /*fileName*/) { return NULL; }
virtual bool writeObject(Object& /*obj*/,const std::string& /*fileName*/) {return false; }
virtual bool writeImage(Image& /*image*/,const std::string& /*fileName*/) {return false; }
virtual bool writeNode(Node& /*node*/,const std::string& /*fileName*/) { return false; }
};
/**
Registry is a singleton factory which stores
the Objects types available at runtime for loading,
and any Object reader or writers which are linked in
at runtime for reading non-native file formats.
The RegisterObjectProxy defined in Object.h can be
used to automatically register at runtime a Object
with the Registry.
The RegisterReaderWriterProxy defined in ReaderWriter.h can
be used to automatically register at runtime a reader/writer
with the Registry.
*/
class SG_EXPORT Registry
{
public:
~Registry();
static Registry* instance();
void addPrototype(Object* obj);
void removePrototype(Object* obj);
void addReaderWriter(ReaderWriter* rw);
void removeReaderWriter(ReaderWriter* rw);
/** create the platform specific library name associated with file.*/
std::string createLibraryNameForFile(const std::string& fileName);
/** create the platform specific library name associated with file extension.*/
std::string createLibraryNameForExt(const std::string& ext);
/** find the library in the SG_LIBRARY_PATH and load it.*/
bool loadLibrary(const std::string& fileName);
/** close the attached library with specified name.*/
bool closeLibrary(const std::string& fileName);
Object* readObject(Input& fr);
Object* readObject(const std::string& fileName);
bool writeObject(Object& obj, const std::string& fileName);
Image* readImage(Input& fr);
Image* readImage(const std::string& fileName);
bool writeImage(Image& obj, const std::string& fileName);
Node* readNode(Input& fr);
Node* readNode(const std::string& fileName);
bool writeNode(Node& node, const std::string& fileName);
private:
typedef std::vector<ref_ptr<Object> > PrototypeList;
typedef std::vector<ref_ptr<ReaderWriter> > ReaderWriterList;
typedef std::vector<ref_ptr<DynamicLibrary> > DynamicLibraryList;
/** constructor is private, as its a singleton, preventing
construction other than via the instance() method and
therefore ensuring only one copy is ever constructed*/
Registry();
/** get the attached library with specified name.*/
DynamicLibraryList::iterator getLibraryItr(const std::string& fileName);
DynamicLibrary* getLibrary(const std::string& fileName);
PrototypeList _protoList;
ReaderWriterList _rwList;
DynamicLibraryList _dlList;
std::vector<int> _nodeProtoList;
std::vector<int> _imageProtoList;
bool _openingLibrary;
};
/** Proxy class for automatic registration of reader/writers with the
Registry.*/
template<class T>
class RegisterObjectProxy
{
public:
RegisterObjectProxy()
{
_obj = new T;
_obj->ref();
Registry::instance()->addPrototype(_obj);
}
~RegisterObjectProxy()
{
Registry::instance()->removePrototype(_obj);
_obj->unref();
}
protected:
T* _obj;
};
/** Proxy class for automatic registration of reader/writers with the
Registry.*/
template<class T>
class RegisterReaderWriterProxy
{
public:
RegisterReaderWriterProxy()
{
_rw = new T;
_rw->ref();
Registry::instance()->addReaderWriter(_rw);
}
~RegisterReaderWriterProxy()
{
Registry::instance()->removeReaderWriter(_rw);
_rw->unref();
}
protected:
T* _rw;
};
};
#endif // __SG_OBJECT_FACTORY_H

View File

@ -1,39 +0,0 @@
#ifndef OSG_SCENE
#define OSG_SCENE 1
#include <osg/Group>
#include <osg/GeoState>
namespace osg {
/** The top level group node in a scene graph. */
class SG_EXPORT Scene : public Group
{
public :
Scene();
virtual Object* clone() const { return new Scene(); }
virtual bool isSameKindAs(Object* obj) { return dynamic_cast<Scene*>(obj)!=NULL; }
virtual const char* className() const { return "Scene"; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
/** set the scene's GeoState.*/
void setGState(osg::GeoState* gstate);
/** return the scene's GeoState.*/
osg::GeoState* getGState() { return _gstate; }
protected :
virtual ~Scene();
virtual bool readLocalData(Input& fr);
virtual bool writeLocalData(Output& fw);
osg::GeoState* _gstate;
};
};
#endif

View File

@ -1,63 +0,0 @@
#ifndef OSG_SEG
#define OSG_SEG 1
#include <osg/Vec3>
#include <osg/Types>
#include <osg/Matrix>
#include <osg/Referenced>
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
namespace osg {
/** Segment class for representing a line segment.*/
class SG_EXPORT Seg : public Referenced
{
public:
Seg() {};
Seg(const Seg& seg) : Referenced(),_s(seg._s),_e(seg._e) {}
Seg(const Vec3& s,const Vec3& e) : _s(s),_e(e) {}
virtual ~Seg() {}
Seg& operator = (const Seg& seg) { _s = seg._s; _e = seg._e; return *this; }
void set(const Vec3& s,const Vec3& e) { _s=s; _e=e; }
const Vec3& start() const { return _s; }
Vec3& start() { return _s; }
const Vec3& end() const { return _e; }
Vec3& end() { return _e; }
/** return true if segment intersects BoundingBox.*/
bool intersect(const BoundingBox& bb) const;
/** return true if segment intersects BoundingSphere and return the intersection ratio's.*/
bool intersect(const BoundingBox& bb,float& r1,float& r2) const;
/** return true if segment intersects BoundingSphere.*/
bool intersect(const BoundingSphere& bs) const;
/** return true if segment intersects BoundingSphere and return the intersection ratio's.*/
bool intersect(const BoundingSphere& bs,float& r1,float& r2) const;
/** return true if segment intersects triangle and set ratio long segment. */
bool intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r);
/** post multiply a segment by matrix.*/
void mult(const Seg& seg,const Matrix& m) { _s = seg._s*m; _e = seg._e*m; }
/** pre multiply a segment by matrix.*/
void mult(const Matrix& m,const Seg& seg) { _s = m*seg._s; _e = m*seg._e; }
protected:
static bool intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb);
Vec3 _s;
Vec3 _e;
};
};
#endif

View File

@ -1,28 +0,0 @@
#ifndef OSG_SEQUENCE
#define OSG_SEQUENCE 1
#include <osg/Switch>
namespace osg {
/** Sequence - Switch node which allows iterators between children.
Note: has not been implemented yet!
*/
class SG_EXPORT Sequence : public Group
{
public :
Sequence() {}
virtual Object* clone() const { return new Sequence(); }
virtual bool isSameKindAs(Object* obj) { return dynamic_cast<Sequence*>(obj)!=NULL; }
virtual const char* className() const { return "Sequence"; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
protected :
virtual ~Sequence() {}
};
};
#endif

View File

@ -1,196 +0,0 @@
#ifndef OSGUTIL_RENDERVISITOR
#define OSGUTIL_RENDERVISITOR 1
#include <osg/NodeVisitor>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/Matrix>
#include <osg/GeoSet>
#include <osg/GeoState>
#include <osg/Camera>
#include <osgUtil/Export>
#include <map>
#include <vector>
namespace osgUtil {
/** Container class for encapsulating the viewing state in local
coordinates, during the cull traversal.
*/
class OSGUTIL_EXPORT ViewState : public osg::Referenced
{
public:
ViewState();
osg::Matrix* _matrix;
osg::Matrix* _inverse;
osg::Vec3 _eyePoint;
osg::Vec3 _centerPoint;
osg::Vec3 _lookVector;
osg::Vec3 _upVector;
osg::Vec3 _frustumTopNormal;
osg::Vec3 _frustumBottomNormal;
osg::Vec3 _frustumLeftNormal;
osg::Vec3 _frustumRightNormal;
float _ratio;
bool _viewFrustumCullingActive;
bool _smallFeatureCullingActive;
bool isCulled(const osg::BoundingSphere& sp);
bool isCulled(const osg::BoundingBox& bb);
protected:
~ViewState();
};
/**
* Basic NodeVisitor implementation for rendering a scene.
* This visitor traverses the scene graph, collecting transparent and
* opaque osg::GeoSets into a depth sorted transparent bin and a state
* sorted opaque bin. The opaque bin is rendered first, and then the
* transparent bin in rendered in order from the furthest osg::GeoSet
* from the eye to the one nearest the eye.
*/
class OSGUTIL_EXPORT RenderVisitor : public osg::NodeVisitor
{
public:
RenderVisitor();
virtual ~RenderVisitor();
void reset();
virtual void apply(osg::Node&);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::LightSource& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::DCS& node);
virtual void apply(osg::Switch& node);
virtual void apply(osg::LOD& node);
virtual void apply(osg::Scene& node);
void setGlobalState(osg::GeoState* global);
void setPerspective(const osg::Camera& camera);
void setPerspective(float fovy,float aspect,float znear,float zfar);
void setLookAt(const osg::Camera& camera);
void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& upVector);
void setLookAt(double eyeX,double eyeY,double eyeZ,
double centerX,double centerY,double centerZ,
double upX,double upY,double upZ);
void setLODBias(float bias) { _LODBias = bias; }
float getLODBias() { return _LODBias; }
enum TransparencySortMode {
LOOK_VECTOR_DISTANCE,
OBJECT_EYE_POINT_DISTANCE
};
void setTransparencySortMode(TransparencySortMode tsm) { _tsm = tsm; }
enum CullingType {
VIEW_FRUSTUM_CULLING,
SMALL_FEATURE_CULLING
};
/**
* Enables/disables the specified culling type.
* @param ct The culling type to enable/disable.
* @param active true enables the culling type, false disables.
*/
void setCullingActive(CullingType ct, bool active);
/**
* Returns the state of the specified culling type.
* @result true, if culling type is enabled, false otherwise.
*/
bool getCullingActive(CullingType ct);
/**
* Calculates the near_plane and the far_plane for the current
* camera view depending on the objects currently stored in the
* opaque and transparent bins.
* @param near_plane reference to a variable that can store the
* near plane result.
* @param far_plane reference to a variable that can store the
* far plane result.
* @result true, if near_plane and far_plane contain valid values,
* false otherwise.
*/
bool calcNearFar(double& near_plane, double& far_plane);
/**
* Renders the osg::GeoSets that were collected in the opaque and
* transparent bins before.
*/
void render();
protected:
void pushMatrix(const osg::Matrix& matrix);
void popMatrix();
osg::Matrix* getCurrentMatrix();
osg::Matrix* getInverseCurrentMatrix();
const osg::Vec3& getEyeLocal();
const osg::Vec3& getCenterLocal();
const osg::Vec3& getLookVectorLocal();
bool _viewFrustumCullingActive;
bool _smallFeatureCullingActive;
bool isCulled(const osg::BoundingSphere& sp);
bool isCulled(const osg::BoundingBox& bb);
typedef std::pair<osg::Matrix*,osg::GeoSet*> MatrixGeoSet;
typedef std::vector<ViewState*> ViewStateStack;
ViewStateStack _viewStateStack;
ViewState* _tvs;
ViewState* _cvs;
typedef std::multimap<osg::GeoState*,MatrixGeoSet> OpaqueList;
typedef std::multimap<float,MatrixGeoSet> TransparentList;
typedef std::map<osg::Matrix*,osg::Light*> LightList;
OpaqueList _opaqueGeoSets;
TransparentList _transparentGeoSets;
LightList _lights;
osg::GeoState* _globalState;
float _LODBias;
float _fovy;
float _aspect;
float _znear;
float _zfar;
void calculateClippingPlanes();
// frustum clipping normals.
osg::Vec3 _frustumTop;
osg::Vec3 _frustumBottom;
osg::Vec3 _frustumLeft;
osg::Vec3 _frustumRight;
TransparencySortMode _tsm;
};
};
#endif

View File

@ -1,112 +0,0 @@
#include "osg/DCS"
#include "osg/Registry"
#include "osg/Input"
#include "osg/Output"
using namespace osg;
RegisterObjectProxy<DCS> g_DCSProxy;
DCS::DCS()
{
_mat = new Matrix(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
_mat->ref();
}
DCS::DCS(const Matrix& mat )
{
_mat = new Matrix(mat);
_mat->ref();
}
DCS::~DCS()
{
_mat->unref();
}
void DCS::setMatrix(const Matrix& mat )
{
*_mat = mat;
dirtyBound();
}
void DCS::preTranslate( float tx, float ty, float tz )
{
_mat->preTrans( tx, ty, tz );
dirtyBound();
}
void DCS::preRotate( float deg, float x, float y, float z )
{
_mat->preRot( deg, x, y, z );
dirtyBound();
}
bool DCS::readLocalData(Input& fr)
{
bool iteratorAdvanced = false;
if (Matrix* tmpMatrix = static_cast<Matrix*>(Matrix::instance()->readClone(fr)))
{
if (_mat) _mat->unref();
_mat = tmpMatrix;
_mat->ref();
iteratorAdvanced = true;
}
if (Group::readLocalData(fr)) iteratorAdvanced = true;
return iteratorAdvanced;
}
bool DCS::writeLocalData(Output& fw)
{
if (_mat) _mat->write(fw);
return Group::writeLocalData(fw);
}
bool DCS::computeBound( void )
{
if (!Group::computeBound()) return false;
Vec3 xdash = _bsphere._center;
xdash.x() += _bsphere._radius;
xdash = xdash*(*_mat);
Vec3 ydash = _bsphere._center;
ydash.y() += _bsphere._radius;
ydash = ydash*(*_mat);
Vec3 zdash = _bsphere._center;
zdash.y() += _bsphere._radius;
zdash = zdash*(*_mat);
_bsphere._center = _bsphere._center*(*_mat);
xdash -= _bsphere._center;
float len_xdash = xdash.length();
ydash -= _bsphere._center;
float len_ydash = ydash.length();
zdash -= _bsphere._center;
float len_zdash = zdash.length();
_bsphere._radius = len_xdash;
if (_bsphere._radius<len_ydash) _bsphere._radius = len_ydash;
if (_bsphere._radius<len_zdash) _bsphere._radius = len_zdash;
return true;
}

View File

@ -1,66 +0,0 @@
#ifdef WIN32
#include <Io.h>
#include <Windows.h>
#include <Winbase.h>
#else
#include <unistd.h>
#include <dlfcn.h>
#endif
#ifndef OSG_USE_IO_DOT_H
#include <iostream>
using namespace std;
#endif
#include "osg/DynamicLibrary"
#include "osg/OSG"
#include "osg/Notify"
using namespace osg;
DynamicLibrary::DynamicLibrary(const std::string& name,HANDLE handle)
{
_name = name;
_handle = handle;
}
DynamicLibrary::~DynamicLibrary()
{
if (_handle)
{
#ifdef WIN32
FreeLibrary((HMODULE)_handle);
#else
dlclose(_handle);
#endif
}
}
DynamicLibrary* DynamicLibrary::loadLibrary(const std::string& libraryName)
{
char* fullLibraryName = osg::findDSO( libraryName.c_str() );
if (fullLibraryName==NULL) return NULL;
#ifdef WIN32
HANDLE handle = LoadLibrary( fullLibraryName );
if (handle) return new DynamicLibrary(libraryName,handle);
notify(WARN) << "DynamicLibrary::failed loading "<<fullLibraryName<<endl;
#else
HANDLE handle = dlopen( fullLibraryName, RTLD_LAZY );
if (handle) return new DynamicLibrary(libraryName,handle);
notify(WARN) << "DynamicLibrary::failed loading "<<fullLibraryName<<endl;
notify(WARN) << "DynamicLibrary::error "<<dlerror()<<endl;
#endif
return NULL;
}
DynamicLibrary::PROC_ADDRESS DynamicLibrary::getProcAddress(const std::string& procName)
{
if (_handle==NULL) return NULL;
#ifdef WIN32
return GetProcAddress( (HMODULE)_handle, procName.c_str() );
#else
return dlsym( _handle, procName.c_str() );
#endif
}

View File

@ -1,45 +0,0 @@
#include "osg/GL"
#include "osg/ExtensionSupported"
#include <stdlib.h>
#include <string.h>
// copied form glut_ext.c
// to be rewritten... Robert Osfield, November 2000.
bool osg::ExtensionSupported(const char *extension)
{
static const GLubyte *extensions = NULL;
const GLubyte *start;
GLubyte *where, *terminator;
/* Extension names should not have spaces. */
where = (GLubyte *) strchr(extension, ' ');
if (where || *extension == '\0')
return 0;
if (!extensions) {
extensions = glGetString(GL_EXTENSIONS);
}
/* It takes a bit of care to be fool-proof about parsing the
OpenGL extensions string. Don't be fooled by sub-strings,
etc. */
start = extensions;
for (;;) {
/* If your application crashes in the strstr routine below,
you are probably calling glutExtensionSupported without
having a current window. Calling glGetString without
a current OpenGL context has unpredictable results.
Please fix your program. */
where = (GLubyte *) strstr((const char *) start, extension);
if (!where)
break;
terminator = where + strlen(extension);
if (where == start || *(where - 1) == ' ') {
if (*terminator == ' ' || *terminator == '\0') {
return true;
}
}
start = terminator;
}
return false;
}

View File

@ -1,422 +0,0 @@
#include "osg/Field"
using namespace osg;
Field::Field()
{
_init();
}
Field::Field(const Field& ic)
{
_copy(ic);
}
Field::~Field()
{
_free();
}
Field& Field::operator = (const Field& ic)
{
if (this==&ic) return *this;
_free();
_copy(ic);
return *this;
}
void Field::_free()
{
// free all data
if (_fieldCache) delete [] _fieldCache;
_init();
}
void Field::_init()
{
_fieldCacheCapacity = 256;
_fieldCacheSize = 0;
_fieldCache = NULL;
_fieldType = UNINTIALISED;
_withinQuotes = false;
_noNestedBrackets = 0;
}
void Field::_copy(const Field& ic)
{
// copy string cache.
if (ic._fieldCache)
{
_fieldCacheCapacity = ic._fieldCacheCapacity;
_fieldCacheSize = ic._fieldCacheSize;
_fieldCache = new char [_fieldCacheCapacity];
strncpy(_fieldCache,ic._fieldCache,_fieldCacheCapacity);
}
else
{
_fieldCacheCapacity = 0;
_fieldCacheSize = 0;
_fieldCache = NULL;
}
_fieldType = ic._fieldType;
_withinQuotes = ic._withinQuotes;
_noNestedBrackets = ic._noNestedBrackets;
}
void Field::setWithinQuotes(bool withinQuotes)
{
_withinQuotes=withinQuotes;
_fieldType = UNINTIALISED;
}
bool Field::getWithinQuotes()
{
return _withinQuotes;
}
void Field::setNoNestedBrackets(int no)
{
_noNestedBrackets=no;
}
int Field::getNoNestedBrackets()
{
return _noNestedBrackets;
}
const char* Field::getStr() const
{
if (_fieldCacheSize!=0) return _fieldCache;
else return NULL;
}
char* Field::takeStr()
{
char* field = _fieldCache;
_fieldCache = NULL;
_fieldCacheSize = 0;
_fieldType = UNINTIALISED;
_withinQuotes = false;
return field;
}
void Field::reset()
{
_fieldCacheSize = 0;
if (_fieldCache)
{
_fieldCache[_fieldCacheSize] = 0;
}
_withinQuotes = false;
_noNestedBrackets = 0;
}
void Field::addChar(char c)
{
if (_fieldCache==NULL)
{
if (_fieldCacheCapacity<MIN_CACHE_SIZE) _fieldCacheCapacity=MIN_CACHE_SIZE;
_fieldCache = new char[_fieldCacheCapacity];
_fieldCacheSize = 0;
}
else if (_fieldCacheSize>=_fieldCacheCapacity-1)
{
if (_fieldCacheCapacity<MIN_CACHE_SIZE) _fieldCacheCapacity=MIN_CACHE_SIZE;
while (_fieldCacheSize>=_fieldCacheCapacity-1) _fieldCacheCapacity *= 2;
char* tmp_str = _fieldCache;
_fieldCache = new char[_fieldCacheCapacity];
strncpy(_fieldCache,tmp_str,_fieldCacheSize);
delete [] tmp_str;
}
_fieldCache[_fieldCacheSize++] = c;
_fieldCache[_fieldCacheSize] = 0;
_fieldType = UNINTIALISED;
}
Field::FieldType Field::getFieldType() const
{
if (_fieldType==UNINTIALISED && _fieldCache)
{
_fieldType = calculateFieldType(_fieldCache,_withinQuotes);
}
return _fieldType;
}
bool Field::isValid() const
{
if (_fieldCacheSize>0 && !_withinQuotes) return true;
else return false;
}
bool Field::isOpenBracket() const
{
if (_fieldCacheSize==1) return _fieldCache[0]=='{';
else return false;
}
bool Field::isCloseBracket() const
{
if (_fieldCacheSize==1) return _fieldCache[0]=='}';
else return false;
}
bool Field::isWord() const
{
getFieldType();
return (_fieldType==WORD);
}
bool Field::matchWord(const char* str) const
{
getFieldType();
return _fieldType==WORD && strcmp(_fieldCache,str)==0;
}
bool Field::matchWord(const char* str,int noCharacters) const
{
getFieldType();
return _fieldType==WORD && strncmp(_fieldCache,str,noCharacters)==0;
}
bool Field::isString() const
{
return getNoCharacters()!=0;
}
bool Field::matchString(const char* str) const
{
return strcmp(_fieldCache,str)==0;
}
bool Field::matchString(const char* str,int noCharacters) const
{
return strncmp(_fieldCache,str,noCharacters)==0;
}
bool Field::isQuotedString() const
{
return _withinQuotes;
}
bool Field::isInt() const
{
getFieldType();
return _fieldType==INTEGER;
}
bool Field::matchInt(int i) const
{
getFieldType();
if (_fieldType==INTEGER)
{
return atoi(_fieldCache)==i;
}
else
{
return false;
}
}
bool Field::getInt(int& i) const
{
getFieldType();
if (_fieldType==INTEGER)
{
i = atoi(_fieldCache);
return true;
}
else
{
return false;
}
}
bool Field::isFloat() const
{
getFieldType();
return _fieldType==REAL || _fieldType==INTEGER;
}
bool Field::matchFloat(float f) const
{
getFieldType();
if (_fieldType==REAL || _fieldType==INTEGER)
{
return (float)atof(_fieldCache)==f;
}
else
{
return false;
}
}
bool Field::getFloat(float& f) const
{
getFieldType();
if (_fieldType==REAL || _fieldType==INTEGER)
{
f = (float)atof(_fieldCache);
return true;
}
else
{
return false;
}
}
bool Field::isDouble() const
{
getFieldType();
return _fieldType==REAL || _fieldType==INTEGER;
}
bool Field::matchDouble(double d) const
{
getFieldType();
if (_fieldType==REAL || _fieldType==INTEGER)
{
return atof(_fieldCache)==d;
}
else
{
return false;
}
}
bool Field::getDouble(double& d) const
{
getFieldType();
if (_fieldType==REAL || _fieldType==INTEGER)
{
d = atof(_fieldCache);
return true;
}
else
{
return false;
}
}
Field::FieldType Field::calculateFieldType(const char* str,bool withinQuotes)
{
if (str==NULL) return BLANK;
if (*str==0) return BLANK;
if (withinQuotes) return STRING;
bool hadPlusMinus = false;
bool hadDecimalPlace = false;
bool hadExponent = false;
bool couldBeInt = true;
bool couldBeFloat = true;
int noZeroToNine = 0;
const char* ptr = str;
while (*ptr!=0 && couldBeFloat)
{
if (*ptr=='+' || *ptr=='-')
{
if (hadPlusMinus)
{
couldBeInt = false;
couldBeFloat = false;
} else hadPlusMinus = true;
}
else if (*ptr>='0' && *ptr<='9')
{
noZeroToNine++;
}
else if (*ptr=='.')
{
if (hadDecimalPlace)
{
couldBeInt = false;
couldBeFloat = false;
}
else
{
hadDecimalPlace = true;
couldBeInt = false;
}
}
else if (*ptr=='e' || *ptr=='E')
{
if (hadExponent || noZeroToNine==0)
{
couldBeInt = false;
couldBeFloat = false;
}
else
{
hadExponent = true;
couldBeInt = false;
hadDecimalPlace = false;
hadPlusMinus = false;
noZeroToNine=0;
}
}
else
{
couldBeInt = false;
couldBeFloat = false;
}
++ptr;
}
if (couldBeInt && noZeroToNine>0) return INTEGER;
if (couldBeFloat && noZeroToNine>0) return REAL;
if (str[0]=='{') return OPEN_BRACKET;
if (str[0]=='}') return CLOSE_BRACKET;
return WORD;
}

View File

@ -1,269 +0,0 @@
#include "osg/FieldReader"
#include "osg/Field"
using namespace osg;
FieldReader::FieldReader()
{
_init();
}
FieldReader::FieldReader(const FieldReader& ic)
{
_copy(ic);
}
FieldReader::~FieldReader()
{
_free();
}
FieldReader& FieldReader::operator = (const FieldReader& ic)
{
if (this==&ic) return *this;
_free();
_copy(ic);
return *this;
}
void FieldReader::_free()
{
// free all data
_init();
}
void FieldReader::_init()
{
_fin = NULL;
_eof = true;
_noNestedBrackets = 0;
int i;
for(i=0;i<256;++i) _delimatorEatLookUp[i]=false;
_delimatorEatLookUp[' '] = true;
_delimatorEatLookUp['\t'] = true;
_delimatorEatLookUp['\n'] = true;
_delimatorEatLookUp['\r'] = true;
for(i=0;i<256;++i) _delimatorKeepLookUp[i]=false;
_delimatorKeepLookUp['{'] = true;
_delimatorKeepLookUp['}'] = true;
_delimatorKeepLookUp['"'] = true;
_delimatorKeepLookUp['\''] = true;
}
void FieldReader::_copy(const FieldReader& ic)
{
_fin = ic._fin;
_eof = ic._eof;
_noNestedBrackets = ic._noNestedBrackets;
int i;
for(i=0;i<256;++i) _delimatorEatLookUp[i]=ic._delimatorEatLookUp[i];
for(i=0;i<256;++i) _delimatorKeepLookUp[i]=ic._delimatorKeepLookUp[i];
}
void FieldReader::attach(istream* input)
{
_fin = input;
if (_fin)
{
_eof = _fin->eof()!=0;
}
else
{
_eof = true;
}
}
void FieldReader::detach()
{
_fin = NULL;
_eof = true;
}
bool FieldReader::eof() const
{
return _eof;
}
bool FieldReader::findStartOfNextField()
{
int ch = 0;
while (true)
{
ch = _fin->peek();
if (ch==EOF)
{
_eof = true;
return false;
}
else if (_delimatorEatLookUp[ch])
{
_fin->ignore(1);
}
else
{
return true;
}
}
}
bool FieldReader::readField(Field& fieldPtr)
{
return _readField(&fieldPtr);
}
void FieldReader::ignoreField()
{
_readField(NULL);
}
bool FieldReader::_readField(Field* fieldPtr)
{
if (fieldPtr) fieldPtr->reset();
if (!eof() && findStartOfNextField())
{
int ch = _fin->peek();
if (ch==EOF)
{
_eof = true;
if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets());
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
else if (ch=='"')
{
if (fieldPtr)
{
fieldPtr->setWithinQuotes(true);
fieldPtr->setNoNestedBrackets(getNoNestedBrackets());
}
_fin->ignore(1);
char c;
while (true)
{
ch = _fin->peek();
if (ch==EOF)
{
_eof = true;
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
c = ch;
if (ch=='"')
{
_fin->ignore(1);
//return fieldPtr && fieldPtr->getNoCharacters()!=0;
return fieldPtr!=NULL;
}
else
{
_fin->get(c);
if (fieldPtr) fieldPtr->addChar(c);
}
}
}
else if (ch=='\'')
{
if (fieldPtr)
{
fieldPtr->setWithinQuotes(true);
fieldPtr->setNoNestedBrackets(getNoNestedBrackets());
}
_fin->ignore(1);
char c;
while (true)
{
ch = _fin->peek();
if (ch==EOF)
{
_eof = true;
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
c = ch;
if (ch=='\'')
{
_fin->ignore(1);
//return fieldPtr && fieldPtr->getNoCharacters()!=0;
return fieldPtr!=NULL;
}
else
{
_fin->get(c);
if (fieldPtr) fieldPtr->addChar(c);
}
}
}
else if (_delimatorKeepLookUp[ch])
{
char c;
_fin->get(c);
if (fieldPtr) fieldPtr->addChar(c);
if (c=='{') ++_noNestedBrackets;
else if (c=='}') --_noNestedBrackets;
if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets());
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
else
{
if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets());
char c;
while (true)
{
ch = _fin->peek();
if (ch==EOF)
{
_eof = true;
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
c = ch;
if (_delimatorEatLookUp[c])
{
_fin->ignore(1);
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
if (_delimatorKeepLookUp[c])
{
return fieldPtr && fieldPtr->getNoCharacters()!=0;
}
else
{
_fin->get(c);
if (fieldPtr) fieldPtr->addChar(c);
}
}
}
}
else
{
return false;
}
}
int FieldReader::getNoNestedBrackets() const
{
return _noNestedBrackets;
}

View File

@ -1,361 +0,0 @@
#include "osg/FieldReaderIterator"
using namespace osg;
FieldReaderIterator::FieldReaderIterator()
{
_init();
}
FieldReaderIterator::FieldReaderIterator(const FieldReaderIterator& ic)
{
_copy(ic);
}
FieldReaderIterator::~FieldReaderIterator()
{
_free();
}
FieldReaderIterator& FieldReaderIterator::operator = (const FieldReaderIterator& ic)
{
if (this==&ic) return *this;
_free();
_copy(ic);
return *this;
}
void FieldReaderIterator::_free()
{
// free all data
if (_previousField)
{
delete _previousField;
}
if (_fieldQueue)
{
for(int i=0;i<_fieldQueueCapacity;++i)
{
if (_fieldQueue[i]) delete _fieldQueue[i];
_fieldQueue[i] = NULL;
}
delete [] _fieldQueue;
}
_init();
}
void FieldReaderIterator::_init()
{
_previousField = NULL;
_fieldQueue = NULL;
_fieldQueueSize = 0;
_fieldQueueCapacity = 0;
}
void FieldReaderIterator::_copy(const FieldReaderIterator& ic)
{
_reader = ic._reader;
if (ic._previousField)
{
_previousField = new Field(*ic._previousField);
}
if (ic._fieldQueue && ic._fieldQueueCapacity>0)
{
_fieldQueue = new Field* [ic._fieldQueueCapacity];
for(int i=0;i<ic._fieldQueueCapacity;++i)
{
if (ic._fieldQueue[i])
{
_fieldQueue[i] = new Field(*ic._fieldQueue[i]);
}
else
{
_fieldQueue[i] = NULL;
}
}
_fieldQueueSize = ic._fieldQueueSize;
_fieldQueueCapacity = ic._fieldQueueCapacity;
}
else
{
_fieldQueue = NULL;
_fieldQueueSize = 0;
_fieldQueueCapacity = 0;
}
}
void FieldReaderIterator::attach(istream* input)
{
_reader.attach(input);
}
void FieldReaderIterator::detach()
{
_reader.detach();
}
bool FieldReaderIterator::eof() const
{
return _fieldQueueSize==0 && _reader.eof();
}
void FieldReaderIterator::insert(int pos,Field* field)
{
if (field==NULL) return;
if (pos<0) pos=0;
if (pos>_fieldQueueSize) pos=_fieldQueueSize;
int i;
if (_fieldQueueSize>=_fieldQueueCapacity) // need to reallocate the stack
{
int newCapacity = _fieldQueueCapacity*2;
if (newCapacity<MINIMUM_FIELD_READER_QUEUE_SIZE) newCapacity = MINIMUM_FIELD_READER_QUEUE_SIZE;
while(_fieldQueueSize>=newCapacity) newCapacity*=2;
Field** newFieldStack = new Field* [newCapacity];
for(i=0;i<_fieldQueueCapacity;++i)
{
newFieldStack[i] = _fieldQueue[i];
}
for(;i<newCapacity;++i)
{
newFieldStack[i] = NULL;
}
_fieldQueue = newFieldStack;
_fieldQueueCapacity = newCapacity;
}
for(i=_fieldQueueSize-1;i>=pos;++i)
{
_fieldQueue[i+1]=_fieldQueue[i];
}
_fieldQueue[pos] = field;
++_fieldQueueSize;
}
void FieldReaderIterator::insert(int pos,const char* str)
{
if (str)
{
Field* field = new Field;
while(*str!=0)
{
field->addChar(*str);
++str;
}
insert(pos,field);
}
}
Field& FieldReaderIterator::operator [] (int pos)
{
return field(pos);
}
Field& FieldReaderIterator::field (int pos)
{
if (pos<0)
{
_blank.setNoNestedBrackets(_reader.getNoNestedBrackets());
return _blank;
} // can directly access field
else if (pos<_fieldQueueSize)
{
return *_fieldQueue[pos];
} // need to read the new fields.
else
{
if (pos>=_fieldQueueCapacity) // need to reallocate the stack
{
int newCapacity = _fieldQueueCapacity*2;
if (newCapacity<MINIMUM_FIELD_READER_QUEUE_SIZE) newCapacity = MINIMUM_FIELD_READER_QUEUE_SIZE;
while(_fieldQueueSize>=newCapacity) newCapacity*=2;
Field** newFieldStack = new Field* [newCapacity];
int i;
for(i=0;i<_fieldQueueCapacity;++i)
{
newFieldStack[i] = _fieldQueue[i];
}
for(;i<newCapacity;++i)
{
newFieldStack[i] = NULL;
}
_fieldQueue = newFieldStack;
_fieldQueueCapacity = newCapacity;
}
while(!_reader.eof() && pos>=_fieldQueueSize)
{
if (_fieldQueue[_fieldQueueSize]==NULL) _fieldQueue[_fieldQueueSize] = new Field;
if (_reader.readField(*_fieldQueue[_fieldQueueSize]))
{
++_fieldQueueSize;
}
}
if (pos<_fieldQueueSize)
{
return *_fieldQueue[pos];
}
else
{
_blank.setNoNestedBrackets(_reader.getNoNestedBrackets());
return _blank;
}
}
}
FieldReaderIterator& FieldReaderIterator::operator ++ ()
{
return (*this)+=1;
}
FieldReaderIterator& FieldReaderIterator::operator += (int no)
{
if (no>_fieldQueueSize)
{
while (!_reader.eof() && no>_fieldQueueSize)
{
_reader.ignoreField();
--no;
}
_fieldQueueSize=0;
}
else if (no>0)
{
Field** tmpFields = new Field* [no];
int i;
for(i=0;i<no;++i)
{
tmpFields[i] = _fieldQueue[i];
}
for(i=no;i<_fieldQueueSize;++i)
{
_fieldQueue[i-no] = _fieldQueue[i];
}
_fieldQueueSize -= no;
for(i=0;i<no;++i)
{
_fieldQueue[_fieldQueueSize+i] = tmpFields[i];
}
delete [] tmpFields;
}
return *this;
}
// increments the itetor of the next simple field or
// whole block if the current field[0] is an open bracket
void FieldReaderIterator::advanceOverCurrentFieldOrBlock()
{
if (field(0).isOpenBracket()) advanceToEndOfCurrentBlock();
else ++(*this);
}
void FieldReaderIterator::advanceToEndOfCurrentBlock()
{
int entry = field(0).getNoNestedBrackets();
while(!eof() && field(0).getNoNestedBrackets()>=entry)
{
++(*this);
}
}
void FieldReaderIterator::advanceToEndOfBlock(int noNestedBrackets)
{
while(!eof() && field(0).getNoNestedBrackets()>=noNestedBrackets)
{
++(*this);
}
}
bool FieldReaderIterator::matchSequence(const char* str)
{
if (str==NULL) return false;
if (*str==0) return false;
int fieldCount = 0;
const char* end = str;
while((*end)!=0 && (*end)==' ') ++end;
const char* start = end;
while((*start)!=0)
{
if (*end!=' ' && *end!=0)
{
++end;
}
else
{
if (start!=end)
{
if (end-start>1 && *start=='%')
{
const char type = *(start+1);
switch(type)
{
case('i') : // expecting an integer
{
if (!field(fieldCount).isInt()) return false;
break;
}
case('f') : // expecting an floating point number
{
if (!field(fieldCount).isFloat()) return false;
break;
}
case('s') : // expecting an quoted string
{
if (!field(fieldCount).isQuotedString()) return false;
break;
}
default : // expecting an word
{
if (!field(fieldCount).isWord()) return false;
break;
}
}
}
else
{
if (*start=='{')
{
if (!field(fieldCount).isOpenBracket()) return false;
}
else if (*start=='}')
{
if (!field(fieldCount).isCloseBracket()) return false;
}
else
{
if (!field(fieldCount).matchWord(start,end-start)) return false;
}
}
fieldCount++;
}
while((*end)==' ') ++end;
start = end;
}
}
return true;
}

View File

@ -1,50 +0,0 @@
#include "osg/FileNameUtils"
std::string osg::getFilePath(const std::string& fileName)
{
std::string::size_type slash = fileName.find_last_of('/');
if (slash==std::string::npos) return std::string("");
return std::string(fileName.begin(),fileName.begin()+slash+1);
}
std::string osg::getSimpleFileName(const std::string& fileName)
{
std::string::size_type slash = fileName.find_last_of('/');
if (slash==std::string::npos) return fileName;
return std::string(fileName.begin()+slash+1,fileName.end());
}
std::string osg::getFileExtension(const std::string& fileName)
{
std::string::size_type dot = fileName.find_last_of('.');
if (dot==std::string::npos) return std::string("");
return std::string(fileName.begin()+dot+1,fileName.end());
}
std::string osg::getLowerCaseFileExtension(const std::string& filename)
{
std::string ext = osg::getFileExtension(filename);
for(std::string::iterator itr=ext.begin();
itr!=ext.end();
++itr)
{
*itr = (char)tolower(*itr);
}
return ext;
}
std::string osg::getStrippedName(const std::string& fileName)
{
std::string::size_type slash = fileName.find_last_of('/');
std::string::size_type dot = fileName.find_last_of('.');
if (slash==std::string::npos) {
if (dot==std::string::npos) return fileName;
else return std::string(fileName.begin(),fileName.begin()+dot);
}
else
{
if (dot==std::string::npos) return std::string(fileName.begin()+slash+1,fileName.end());
else return std::string(fileName.begin()+slash+1,fileName.begin()+dot);
}
}

View File

@ -1,850 +0,0 @@
#include <stdio.h>
#include "osg/GeoState"
#include "osg/Input"
#include "osg/Output"
#include "osg/Notify"
using namespace osg;
GeoState::GeoState()
{
_transparencing = INHERIT;
_face_culling = INHERIT;
_lighting = INHERIT;
_texturing = INHERIT;
_fogging = INHERIT;
_texgening = INHERIT;
_antialiasing = INHERIT;
_colortable = INHERIT;
_pointSmoothing = INHERIT;
_polygonOffsetting = INHERIT;
_alphaTesting = INHERIT;
_transparency = 0L;
_cullFace = 0L;
_texture = 0L;
_fog = 0L;
_texgen = 0L;
_material = 0L;
_texenv = 0L;
_texmat = 0L;
_point = 0L;
_polygonOffset = 0L;
_alphaFunc = 0L;
}
GeoState::~GeoState()
{
// note, all attached state attributes will be automatically
// unreferenced by ref_ptr<> and therefore there is now need to
// delete the memory manually.
}
GeoState* GeoState::instance()
{
static ref_ptr<GeoState> s_geostate(new GeoState);
return s_geostate.get();
}
void GeoState::setGlobalDefaults()
{
_transparencing = OFF;
_face_culling = ON;
_lighting = OFF;
_texturing = OFF;
_fogging = OFF;
_texgening = OFF;
_antialiasing = OFF;
_colortable = OFF;
_pointSmoothing = OFF;
_polygonOffsetting = OFF;
_alphaTesting = OFF;
_transparency = new Transparency;
_cullFace = new CullFace;
_texture = 0L;
_fog = 0L;
_texgen = 0L;
_material = new Material;
_material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
_texenv = 0L;
_texmat = 0L;
_point = 0L;
_polygonOffset = 0L;
_alphaFunc = new AlphaFunc;
}
void GeoState::setAllToInherit()
{
_transparencing = INHERIT;
_face_culling = INHERIT;
_lighting = INHERIT;
_texturing = INHERIT;
_fogging = INHERIT;
_texgening = INHERIT;
_antialiasing = INHERIT;
_colortable = INHERIT;
_pointSmoothing = INHERIT;
_polygonOffsetting = INHERIT;
_alphaTesting = INHERIT;
_transparency = 0L;
_cullFace = 0L;
_texture = 0L;
_fog = 0L;
_texgen = 0L;
_material = 0L;
_texenv = 0L;
_texmat = 0L;
_point = 0L;
_polygonOffset = 0L;
_alphaFunc = 0L;
}
bool GeoState::readLocalData(Input& fr)
{
bool iteratorAdvanced = false;
AttributeMode mode;
if (fr[0].matchWord("transparency") && matchModeStr(fr[1].getStr(),mode))
{
_transparencing = mode;
fr+=2;
iteratorAdvanced = true;
}
if (Transparency* transTmp = static_cast<Transparency*>(Transparency::instance()->readClone(fr)))
{
_transparency = transTmp;
iteratorAdvanced = true;
}
if (fr[0].matchWord("antialiasing") && matchModeStr(fr[1].getStr(),mode))
{
_antialiasing = mode;
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("face_culling") && matchModeStr(fr[1].getStr(),mode))
{
_face_culling = mode;
fr+=2;
iteratorAdvanced = true;
}
if (CullFace* cullTmp = static_cast<CullFace*>(CullFace::instance()->readClone(fr)))
{
_cullFace = cullTmp;
iteratorAdvanced = true;
}
if (fr[0].matchWord("lighting") && matchModeStr(fr[1].getStr(),mode))
{
_lighting = mode;
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("texturing") && matchModeStr(fr[1].getStr(),mode))
{
_texturing = mode;
fr+=2;
iteratorAdvanced = true;
}
if (Texture* textTmp = static_cast<Texture*>(Texture::instance()->readClone(fr)))
{
_texture = textTmp;
iteratorAdvanced = true;
}
if (fr[0].matchWord("fogging") && matchModeStr(fr[1].getStr(),mode))
{
_fogging = mode;
fr+=2;
iteratorAdvanced = true;
}
if (Fog* fogTmp = static_cast<Fog*>(Fog::instance()->readClone(fr)))
{
_fog = fogTmp;
iteratorAdvanced = true;
}
if (fr[0].matchWord("colortable") && matchModeStr(fr[1].getStr(),mode))
{
_colortable = mode;
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("texgening") && matchModeStr(fr[1].getStr(),mode))
{
_texgening = mode;
fr+=2;
iteratorAdvanced = true;
}
if (TexGen* tmpTexgen = static_cast<TexGen*>(TexGen::instance()->readClone(fr)))
{
_texgen = tmpTexgen;
iteratorAdvanced = true;
}
if (fr[0].matchWord("point_smoothing") && matchModeStr(fr[1].getStr(),mode))
{
_pointSmoothing = mode;
fr+=2;
iteratorAdvanced = true;
}
if (Point* tmpPoint = static_cast<Point*>(Point::instance()->readClone(fr)))
{
_point = tmpPoint;
iteratorAdvanced = true;
}
if (fr[0].matchWord("polygon_offset") && matchModeStr(fr[1].getStr(),mode))
{
_polygonOffsetting = mode;
fr+=2;
iteratorAdvanced = true;
}
if (PolygonOffset* tmpPolygonOffset = static_cast<PolygonOffset*>(PolygonOffset::instance()->readClone(fr)))
{
_polygonOffset = tmpPolygonOffset;
iteratorAdvanced = true;
}
if (fr[0].matchWord("alpha_test") && matchModeStr(fr[1].getStr(),mode))
{
_alphaTesting = mode;
fr+=2;
iteratorAdvanced = true;
}
if (AlphaFunc* tmpAlphaFunc = static_cast<AlphaFunc*>(AlphaFunc::instance()->readClone(fr)))
{
_alphaFunc = tmpAlphaFunc;
iteratorAdvanced = true;
}
if (Material* tmpMaterial = static_cast<Material*>(Material::instance()->readClone(fr)))
{
_material = tmpMaterial;
iteratorAdvanced = true;
}
/*
* Decided that texmatting does not make sense. If a Texture matrix
* is present, just apply it. No need for a mode. Don.
*
if (fr[0].matchWord("texmating") && matchModeStr(fr[1].getStr(),mode)) {
_texmating = mode;
fr+=2;
iteratorAdvanced = true;
}
*/
return iteratorAdvanced;
}
bool GeoState::writeLocalData(Output& fw)
{
fw.indent() << "transparency " << getModeStr(_transparencing) << endl;
if (_transparency.valid()) _transparency->write(fw);
fw.indent() << "antialiasing " << getModeStr(_antialiasing) << endl;
fw.indent() << "face_culling " << getModeStr(_face_culling) << endl;
if (_cullFace.valid()) _cullFace->write(fw);
fw.indent() << "lighting " << getModeStr(_lighting) << endl;
fw.indent() << "texturing " << getModeStr(_texturing) << endl;
if (_texture.valid()) _texture->write(fw);
fw.indent() << "fogging " << getModeStr(_fogging) << endl;
if (_fog.valid()) _fog->write(fw);
fw.indent() << "colortable " << getModeStr(_colortable) << endl;
fw.indent() << "texgening " << getModeStr(_texgening) << endl;
if (_texgen.valid()) _texgen->write(fw);
if (_texenv.valid()) _texenv->write(fw);
fw.indent() << "point_smoothing " << getModeStr(_pointSmoothing) << endl;
if (_point.valid()) _point->write(fw);
fw.indent() << "polygon_offset " << getModeStr(_polygonOffsetting) << endl;
if (_polygonOffset.valid()) _polygonOffset->write(fw);
fw.indent() << "alpha_test " << getModeStr(_alphaTesting) << endl;
if (_alphaFunc.valid()) _alphaFunc->write(fw);
if (_material.valid()) _material->write(fw);
/*
fw.indent() << "texmating " << getModeStr(_texmating) << endl;
*/
return true;
}
bool GeoState::matchModeStr(const char* str,AttributeMode& mode)
{
if (strcmp(str,"INHERIT")==0) mode = INHERIT;
else if (strcmp(str,"ON")==0) mode = ON;
else if (strcmp(str,"OFF")==0) mode = OFF;
else if (strcmp(str,"OVERRIDE_ON")==0) mode = OVERRIDE_ON;
else if (strcmp(str,"OVERRIDE_OFF")==0) mode = OVERRIDE_OFF;
else return false;
return true;
}
const char* GeoState::getModeStr(AttributeMode mode)
{
switch(mode)
{
case(INHERIT): return "INHERIT";
case(ON): return "ON";
case(OFF): return "OFF";
case(OVERRIDE_ON): return "OVERRIDE_ON";
case(OVERRIDE_OFF): return "OVERRIDE_OFF";
}
return "";
}
void GeoState::setMode( AttributeType type, AttributeMode mode )
{
switch( type )
{
case ANTIALIAS : _antialiasing = mode; break;
case FACE_CULL: _face_culling = mode; break;
case FOG : _fogging = mode; break;
case LIGHTING: _lighting = mode; break;
case POINT : _pointSmoothing = mode; break;
case POLYGON_OFFSET : _polygonOffsetting = mode; break;
case TEXGEN : _texgening = mode; break;
case TEXTURE : _texturing = mode; break;
case TRANSPARENCY: _transparencing = mode; break;
case ALPHAFUNC: _alphaTesting = mode; break;
default : notify(WARN) << "GeoState::setMode("<<(int)type<<","<<(int)mode<<") not handled."<<endl;
}
}
GeoState::AttributeMode GeoState::getMode( AttributeType type) const
{
switch( type )
{
case ANTIALIAS : return _antialiasing;
case FACE_CULL: return _face_culling;
case FOG : return _fogging;
case LIGHTING: return _lighting;
case POINT : return _pointSmoothing;
case POLYGON_OFFSET : return _polygonOffsetting;
case TEXTURE : return _texturing;
case TEXGEN : return _texgening;
case TRANSPARENCY: return _transparencing;
case ALPHAFUNC: return _alphaTesting;
default : notify(WARN) << "GeoState::getMode("<<(int)type<<") not handled."<<endl;
}
return INHERIT;
}
void GeoState::setAttribute( AttributeType type, Object *attribute )
{
switch( type )
{
case FACE_CULL : _cullFace = dynamic_cast<CullFace*>(attribute); break;
case FOG : _fog = dynamic_cast<Fog*>(attribute); break;
case LIGHTING: break; /*_light = (Light *)attribute;*/
case MATERIAL: _material = dynamic_cast<Material*>(attribute); break;
case POINT : _point = dynamic_cast<Point*>(attribute); break;
case POLYGON_OFFSET: _polygonOffset = dynamic_cast<PolygonOffset*>(attribute); break;
case TEXENV : _texenv = dynamic_cast<TexEnv*>(attribute); break;
case TEXGEN : _texgen = dynamic_cast<TexGen*>(attribute); break;
case TEXMAT : _texmat = dynamic_cast<TexMat*>(attribute); break;
case TEXTURE : _texture = dynamic_cast<Texture*>(attribute); break;
case TRANSPARENCY: _transparency = dynamic_cast<Transparency*>(attribute); break;
case ALPHAFUNC: _alphaFunc = dynamic_cast<AlphaFunc*>(attribute); break;
default : notify(WARN) << "GeoState::setAttribute("<<(int)type<<","<<attribute<<") not handled."<<endl;
}
}
Object* GeoState::getAttribute( AttributeType type) const
{
switch( type )
{
case FOG : return _fog.get();
case LIGHTING: return NULL; /*_light*/
case MATERIAL: return _material.get();
case POINT : return _point.get();
case POLYGON_OFFSET: return _polygonOffset.get();
case TEXENV : return _texenv.get();
case TEXGEN : return _texgen.get();
case TEXMAT : return _texmat.get();
case TEXTURE : return _texture.get();
case TRANSPARENCY: return _transparency.get();
case ALPHAFUNC: return _alphaFunc.get();
default : notify(WARN) << "GeoState::getAttribute("<<(int)type<<") not handled."<<endl;
}
return NULL;
}
void GeoState::apply()
{
switch(_transparencing)
{
case(ON):
case(OVERRIDE_ON):
Transparency::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Transparency::disable();
break;
case(INHERIT):
break;
}
switch(_face_culling)
{
case(ON):
case(OVERRIDE_ON):
CullFace::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
CullFace::disable();
break;
case(INHERIT):
break;
}
switch(_lighting)
{
case(ON):
case(OVERRIDE_ON):
Lighting::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Lighting::disable();
break;
case(INHERIT):
break;
}
switch(_texturing)
{
case(ON):
case(OVERRIDE_ON):
Texture::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Texture::disable();
break;
case(INHERIT):
break;
}
switch(_texgening)
{
case(ON):
case(OVERRIDE_ON):
TexGen::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
TexGen::disable();
break;
case(INHERIT):
break;
}
switch(_fogging)
{
case(ON):
case(OVERRIDE_ON):
Fog::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Fog::disable();
break;
case(INHERIT):
break;
}
switch(_pointSmoothing)
{
case(ON):
case(OVERRIDE_ON):
Point::enableSmooth();
break;
case(OFF):
case(OVERRIDE_OFF):
Point::disableSmooth();
break;
case(INHERIT):
break;
}
switch(_polygonOffsetting)
{
case(ON):
case(OVERRIDE_ON):
PolygonOffset::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
PolygonOffset::disable();
break;
case(INHERIT):
break;
}
switch(_alphaTesting)
{
case(ON):
case(OVERRIDE_ON):
AlphaFunc::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
AlphaFunc::disable();
break;
case(INHERIT):
break;
}
if( _transparency.valid())
_transparency->apply();
if( _cullFace.valid())
_cullFace->apply();
if( _texenv.valid())
_texenv->apply();
if( _texgen.valid())
_texgen->apply();
if( _texture.valid())
_texture->apply();
if( _material.valid())
_material->apply();
if( _fog.valid())
_fog->apply();
if( _texmat.valid())
_texmat->apply();
if( _point.valid())
_point->apply();
if( _polygonOffset.valid())
_polygonOffset->apply();
if( _alphaFunc.valid())
_alphaFunc->apply();
}
void GeoState::apply(GeoState* global,GeoState* prev)
{
if (global==NULL || prev==NULL)
{
apply();
return;
}
switch(GeoState::combineMode(global->_transparencing,prev->_transparencing,_transparencing))
{
case(ON):
case(OVERRIDE_ON):
Transparency::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Transparency::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_face_culling,prev->_face_culling,_face_culling))
{
case(ON):
case(OVERRIDE_ON):
CullFace::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
CullFace::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_lighting,prev->_lighting,_lighting))
{
case(ON):
case(OVERRIDE_ON):
Lighting::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Lighting::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_texturing,prev->_texturing,_texturing))
{
case(ON):
case(OVERRIDE_ON):
Texture::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Texture::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_texgening,prev->_texgening,_texgening))
{
case(ON):
case(OVERRIDE_ON):
TexGen::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
TexGen::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_fogging,prev->_fogging,_fogging))
{
case(ON):
case(OVERRIDE_ON):
Fog::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
Fog::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_pointSmoothing,prev->_pointSmoothing,_pointSmoothing))
{
case(ON):
case(OVERRIDE_ON):
Point::enableSmooth();
break;
case(OFF):
case(OVERRIDE_OFF):
Point::disableSmooth();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_polygonOffsetting,prev->_polygonOffsetting,_polygonOffsetting))
{
case(ON):
case(OVERRIDE_ON):
PolygonOffset::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
PolygonOffset::disable();
break;
case(INHERIT):
break;
}
switch(GeoState::combineMode(global->_alphaTesting,prev->_alphaTesting,_alphaTesting))
{
case(ON):
case(OVERRIDE_ON):
AlphaFunc::enable();
break;
case(OFF):
case(OVERRIDE_OFF):
AlphaFunc::disable();
break;
case(INHERIT):
break;
}
if (prev->_transparency!=_transparency)
{
osg::Transparency* new_transparency;
if (_transparency.valid()) new_transparency = _transparency.get();
else new_transparency = global->_transparency.get();
if (new_transparency) new_transparency->apply();
}
if (prev->_cullFace!=_cullFace)
{
osg::CullFace* new_cullFace;
if (_cullFace.valid()) new_cullFace = _cullFace.get();
else new_cullFace = global->_cullFace.get();
if (new_cullFace) new_cullFace->apply();
}
if (prev->_texenv!=_texenv)
{
osg::TexEnv* new_texenv;
if (_texenv.valid()) new_texenv = _texenv.get();
else new_texenv = global->_texenv.get();
if (new_texenv) new_texenv->apply();
}
if (prev->_texgen!=_texgen)
{
osg::TexGen* new_texgen;
if (_texgen.valid()) new_texgen = _texgen.get();
else new_texgen = global->_texgen.get();
if (new_texgen) new_texgen->apply();
}
if (prev->_texture!=_texture)
{
osg::Texture* new_texture;
if (_texture.valid()) new_texture = _texture.get();
else new_texture = global->_texture.get();
if (new_texture) new_texture->apply();
}
if (prev->_material!=_material)
{
osg::Material* new_material;
if (_material.valid()) new_material = _material.get();
else new_material = global->_material.get();
if (new_material) new_material->apply();
}
if (prev->_fog!=_fog)
{
osg::Fog* new_fog;
if (_fog.valid()) new_fog = _fog.get();
else new_fog = global->_fog.get();
if (new_fog) new_fog->apply();
}
if (prev->_texmat!=_texmat)
{
osg::TexMat* new_texmat;
if (_texmat.valid()) new_texmat = _texmat.get();
else new_texmat = global->_texmat.get();
if (new_texmat) new_texmat->apply();
}
if (prev->_point!=_point)
{
osg::Point* new_point;
if (_point.valid()) new_point = _point.get();
else new_point = global->_point.get();
if (new_point) new_point->apply();
}
if (prev->_polygonOffset!=_polygonOffset)
{
osg::PolygonOffset* new_polygonOffset;
if (_polygonOffset.valid()) new_polygonOffset = _polygonOffset.get();
else new_polygonOffset = global->_polygonOffset.get();
if (new_polygonOffset) new_polygonOffset->apply();
}
if (prev->_alphaFunc!=_alphaFunc)
{
osg::AlphaFunc* new_AlphaFunc;
if (_alphaFunc.valid()) new_AlphaFunc = _alphaFunc.get();
else new_AlphaFunc = global->_alphaFunc.get();
if (new_AlphaFunc) new_AlphaFunc->apply();
}
}
bool GeoState::check()
{
return true;
}
/*
#if 0 // [ NOTES on how apply should work
Each Scene must have a global initial GeoState, current GeoState, and current request state. The current definition of GeoState
should really become an GeoState. The global initial State can have modes set to
SG_ON,
SG_OFF,
and may be or'ed with
SG_OVERRIDE.
All attributes are set to the default. Defaults can be set at start up by querying hardware
and determining best parameters (for example, do we have hardware texture mapping?, if so enable texture and create a texture environment).
The current GeoState and the request GeoState begin as a copy of the initial state. The request state is subsequently changed by each GeoState,
during traversal. It is the current state that will actually issue the GL commands at apply time.
Attributes for the GeoStates may be
SG_ON -explicitely
SG_OFF -explicitely
SG_INHERIT
and may be or'ed with
SG_PERSIST
During traversal, each GeoState's attribute set to INHERIT does nothing. Each attribute set to ON or OFF sets the subsequent request state
to the same before drawing and unsets it after. If the attribute is or'ed with SG_PERSIST, then the mode is not unset after drawing.
Just before drawing the request state is compared to the current state. If an attribute or mode has changed, it is changed in the current
state then applied. Only at this application will the actual GL calls be issued.
For exammple, if two subsequent geosets have lighting on the sequence will be as follows
geostate 1 sets lighting on in request state
at draw:
if current state has lighting off it is changed to on and applied.
geostate1 unsets lighting in request state.
geosate2 resets lighting to on in request state
at draw:
current state has lighting set to on from previous draw therefore nothing changes
geostate2
Addendum 10/22 - Use this method for traversal. Currently we shall do dumb apply().
Upon implementation of a CULL traversal, which creates a DRAW display list, then we
shall implement the "smart" state change described above.
#endif // ]
*/

View File

@ -1,69 +0,0 @@
#include "osg/Input"
#include "osg/Registry"
#include "osg/Object"
#ifdef __sgi
using std::string;
#endif
using namespace osg;
// Will extend to handle #DEF and use
// functionality similar to Inventor,
// and add the ability to handle #include
// from within the OSG file format.
Input::Input()
{
}
Input::~Input()
{
}
Object* Input::getObjectForUniqueID(const std::string& uniqueID)
{
UniqueIDToObjectMapping::iterator fitr = _uniqueIDToObjectMap.find(uniqueID);
if (fitr != _uniqueIDToObjectMap.end()) return (*fitr).second;
else return NULL;
}
void Input::regisiterUniqueIDForObject(const std::string& uniqueID,Object* obj)
{
_uniqueIDToObjectMap[uniqueID] = obj;
}
Object* Input::readObject()
{
return Registry::instance()->readObject(*this);
}
Object* Input::readObject(const string& fileName)
{
return Registry::instance()->readObject(fileName);
}
Image* Input::readImage()
{
return Registry::instance()->readImage(*this);
}
Image* Input::readImage(const string& fileName)
{
return Registry::instance()->readImage(fileName);
}
Node* Input::readNode()
{
return Registry::instance()->readNode(*this);
}
Node* Input::readNode(const string& fileName)
{
return Registry::instance()->readNode(fileName);
}

View File

@ -1,228 +0,0 @@
#ifndef WIN32
#include <unistd.h>
#include <dlfcn.h>
#else
#include <Io.h>
#include <Windows.h>
#include <Winbase.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "osg/Notify"
#include "osg/OSG"
#include "osg/Node"
#include "osg/Geode"
#include "osg/Group"
#include "osg/Input"
#include "osg/Output"
#include "osg/Registry"
using namespace osg;
#ifdef WIN32
char *PathDelimitor = ";";
static const char *s_default_file_path = ".;D:/OpenSceneGraph/Data;D:/OpenSceneGraph/Data/Images;D:/OpenSceneGraph/lib";
//static char *s_filePath = (char *)s_default_file_path;
static char *s_filePath = ".;";
#else
char *PathDelimitor = ":";
static const char *s_default_file_path = ".:";
#ifdef __sgi
static const char *s_default_dso_path = "/usr/lib32/osgPlugins/";
#else
static const char *s_default_dso_path = "/usr/lib/osgPlugins/";
#endif
static char *s_filePath = ".:";
//static char *s_filePath = s_default_file_path;
#endif
#include <vector>
#include <algorithm>
using std::vector;
using std::find_if;
void osg::Init( void )
{
char *ptr;
if( (ptr = getenv( "OSGFILEPATH" )) )
{
notify(DEBUG) << "osg::Init("<<ptr<<")"<<endl;
SetFilePath( ptr );
}
else
{
notify(DEBUG) << "osg::Init(NULL)"<<endl;
}
}
void osg::SetFilePath( const char *_path )
{
notify(DEBUG) << "In osg::SetFilePath("<<s_filePath<<")"<<endl;
if( s_filePath != s_default_file_path )
delete s_filePath;
s_filePath = strdup( _path );
notify(DEBUG) << "Out osg::SetFilePath("<<s_filePath<<")"<<endl;
}
static char *FindFileInPath( const char *_file, const char * filePath )
{
char pathbuff[1024];
char *tptr, *tmppath;
char *path = 0L;
notify(DEBUG) << "FindFileInPath() : trying " << _file << " ...\n";
#ifdef WIN32
if( _access( _file, 4 ) == 0 ) return (char *)_file;
#else
if( access( _file, F_OK ) == 0 ) return (char *)_file;
#endif
tptr = strdup( filePath );
tmppath = strtok( tptr, PathDelimitor );
do
{
sprintf( pathbuff, "%s/%s", tmppath, _file );
notify(DEBUG) << "FindFileInPath() : trying " << pathbuff << " ...\n";
#ifdef WIN32
if( _access( pathbuff, 4 ) == 0 ) break;
#else
if( access( pathbuff, F_OK ) == 0 ) break;
#endif
} while( (tmppath = strtok( 0, PathDelimitor )) );
if( tmppath != (char *)0L )
path = strdup( pathbuff );
::free(tptr);
notify( DEBUG ) << "FindFileInPath() : returning " << path << "\n";
return path;
}
char *osg::FindFile( const char *file )
{
return FindFileInPath( file, s_filePath );
}
/*
Order of precedence for
./
OSG_LD_LIBRARY_PATH
s_default_dso_path
LD_LIBRARY*_PATH
*/
char *osg::findDSO( const char *name )
{
char path[1024];
char *ptr;
strcpy( path, "./" );
if((ptr = getenv( "OSG_LD_LIBRARY_PATH" )))
{
strcat( path, PathDelimitor );
strcat( path, ptr );
}
strcat( path, PathDelimitor );
strcat( path, s_default_dso_path );
#ifdef __sgi // [
// bloody mess see rld(1) man page
# if (_MIPS_SIM == _MIPS_SIM_ABI32) // [
if( (ptr = getenv( "LD_LIBRARY_PATH" )))
{
strcat( path, PathDelimitor );
strcat( path, ptr );
}
# elif (_MIPS_SIM == _MIPS_SIM_NABI32) // ][
if( !(ptr = getenv( "LD_LIBRARYN32_PATH" )))
ptr = getenv( "LD_LIBRARY_PATH" );
if( ptr )
{
strcat( path, PathDelimitor );
strcat( path, ptr );
}
# elif (_MIPS_SIM == _MIPS_SIM_ABI64) // ][
if( !(ptr = getenv( "LD_LIBRARYN32_PATH" )))
ptr = getenv( "LD_LIBRARY_PATH" );
if( ptr )
{
strcat( path, PathDelimitor );
strcat( path, ptr );
}
# endif // ]
#else // ][
# ifdef WIN32 // [
if ((ptr = getenv( "PATH" )))
{
notify(DEBUG) << "PATH = "<<ptr<<endl;
strcat( path, PathDelimitor );
strcat( path, ptr );
}
# else // ][
if( (ptr = getenv( "LD_LIBRARY_PATH" )))
{
strcat( path, PathDelimitor );
strcat( path, ptr );
}
#endif // ]
#endif // ]
#ifndef WIN32
// #ifdef __sgi
// strcat( path, PathDelimitor );
// strcat( path, "/usr/lib32/osgPlugins" );
// #else
// strcat( path, PathDelimitor );
// strcat( path, "/usr/lib/osgPlugins" );
// #endif
#endif
strcat( path ,PathDelimitor );
strcat( path, s_filePath );
char* fileFound = NULL;
fileFound = FindFileInPath( name , path );
if (fileFound) return fileFound;
// now try prepending the filename with "osgPlugins/"
char* prependosgPlugins = new char[strlen(name)+12];
strcpy(prependosgPlugins,"osgPlugins/");
strcat(prependosgPlugins,name);
fileFound = FindFileInPath( prependosgPlugins , path );
delete prependosgPlugins;
return fileFound;
}

View File

@ -1,75 +0,0 @@
#include <stdio.h>
#include "osg/Output"
#include "osg/Object"
using namespace osg;
Output::Output()
{
_init();
}
Output::~Output()
{
_free();
}
void Output::_init()
{
_indent = 0;
_indentStep = 2;
_numIndicesPerLine = 10;
}
void Output::_free()
{
// should I be calling ofstream's free as well???
}
Output& Output::indent()
{
for(int i=0;i<_indent;++i) *this<<' ';
return *this;
}
void Output::moveIn()
{
_indent += _indentStep;
}
void Output::moveOut()
{
_indent -= _indentStep;
if (_indent<0) _indent=0;
}
bool Output::getUniqueIDForObject(Object* obj,std::string& uniqueID)
{
UniqueIDToLabelMapping::iterator fitr = _objectToUniqueIDMap.find(obj);
if (fitr != _objectToUniqueIDMap.end())
{
uniqueID = (*fitr).second;
return true;
}
else return false;
}
bool Output::createUniqueIDForObject(Object* obj,std::string& uniqueID)
{
char str[256];
sprintf(str,"%s_%i",obj->className(),_objectToUniqueIDMap.size());
uniqueID = str;
return true;
}
bool Output::registerUniqueIDForObject(Object* obj,std::string& uniqueID)
{
_objectToUniqueIDMap[obj] = uniqueID;
return true;
}

View File

@ -1,101 +0,0 @@
#include "osg/Registry"
#include "osg/Object"
#include "osg/Image"
#include "osg/Node"
#include "osg/Group"
#include "osg/Input"
#include "osg/Output"
#ifdef __sgi
using std::string;
#endif
using namespace osg;
class DefaultReaderWriter : public ReaderWriter
{
public:
virtual const char* className() { return "Default OSG Reader/Writer"; }
virtual bool acceptsExtension(const string& extension) { return extension=="osg" || extension=="OSG"; }
virtual Object* readObject(const string& fileName) { return readNode(fileName); }
virtual Node* readNode(const string& fileName)
{
ifstream fin(fileName.c_str());
if (fin)
{
Input fr;
fr.attach(&fin);
Group* group = new Group;
group->setName("import group");
// load all nodes in file, placing them in a group.
while(!fr.eof())
{
Node *node = fr.readNode();
if (node) group->addChild(node);
else fr.advanceOverCurrentFieldOrBlock();
}
if (group->getNumChildren()>1)
{
return group;
}
else if (group->getNumChildren()==1)
{
// only one node loaded so just return that one node,
// and delete the redundent group. Note, the
// child must be referenced before defrencing
// the group so to avoid delete its children.
Node* node = group->getChild(0);
node->ref();
group->unref();
return node;
} // group->getNumChildren()==0
else
{
return 0L;
}
}
else
{
return 0L;
}
}
virtual bool writeObject(Object& obj,const string& fileName)
{
Output fout;
fout.open(fileName.c_str());
if (fout)
{
obj.write(fout);
fout.close();
return true;
}
return false;
}
virtual bool writeNode(Node& node,const string& fileName)
{
Output fout;
fout.open(fileName.c_str());
if (fout)
{
node.write(fout);
fout.close();
return true;
}
return false;
}
};
// now register with Registry to instantiate the above
// reader/writer.
RegisterReaderWriterProxy<DefaultReaderWriter> g_defaultReaderWriterProxy;

View File

@ -1,380 +0,0 @@
#include "osg/Image"
#include "osg/Input"
#include "osg/Output"
#include "osg/Notify"
#include "osg/FileNameUtils"
#include "osg/Registry"
#include <osg/Geode>
#include <osg/GeoSet>
#include <osg/GeoState>
#include <osg/Texture>
#include "osg/GL"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
using namespace osg;
typedef struct _rawImageRec
{
unsigned short imagic;
unsigned short type;
unsigned short dim;
unsigned short sizeX, sizeY, sizeZ;
unsigned long min, max;
unsigned long wasteBytes;
char name[80];
unsigned long colorMap;
FILE *file;
unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA;
unsigned long rleEnd;
GLuint *rowStart;
GLint *rowSize;
} rawImageRec;
static void ConvertShort(unsigned short *array, long length)
{
unsigned long b1, b2;
unsigned char *ptr;
ptr = (unsigned char *)array;
while (length--)
{
b1 = *ptr++;
b2 = *ptr++;
*array++ = (unsigned short) ((b1 << 8) | (b2));
}
}
static void ConvertLong(GLuint *array, long length)
{
unsigned long b1, b2, b3, b4;
unsigned char *ptr;
ptr = (unsigned char *)array;
while (length--)
{
b1 = *ptr++;
b2 = *ptr++;
b3 = *ptr++;
b4 = *ptr++;
*array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
}
}
static rawImageRec *RawImageOpen(const char *fileName)
{
union
{
int testWord;
char testByte[4];
} endianTest;
rawImageRec *raw;
GLenum swapFlag;
int x;
endianTest.testWord = 1;
if (endianTest.testByte[0] == 1)
{
swapFlag = GL_TRUE;
}
else
{
swapFlag = GL_FALSE;
}
raw = (rawImageRec *)malloc(sizeof(rawImageRec));
if (raw == NULL)
{
notify(WARN)<< "Out of memory!"<<endl;
return NULL;
}
if ((raw->file = fopen(fileName, "rb")) == NULL)
{
perror(fileName);
return NULL;
}
fread(raw, 1, 12, raw->file);
if (swapFlag)
{
ConvertShort(&raw->imagic, 6);
}
raw->tmp = raw->tmpR = raw->tmpG = raw->tmpB = raw->tmpA = 0L;
raw->tmp = (unsigned char *)malloc(raw->sizeX*256);
if (raw->tmp == NULL )
{
notify(FATAL)<< "Out of memory!"<<endl;
return NULL;
}
if( raw->sizeZ >= 1 )
{
if( (raw->tmpR = (unsigned char *)malloc(raw->sizeX)) == NULL )
{
notify(FATAL)<< "Out of memory!"<<endl;
free( raw->tmp );
return NULL;
}
}
if( raw->sizeZ >= 2 )
{
if( (raw->tmpG = (unsigned char *)malloc(raw->sizeX)) == NULL )
{
notify(FATAL)<< "Out of memory!"<<endl;
free( raw->tmp );
free( raw->tmpR );
return NULL;
}
}
if( raw->sizeZ >= 3 )
{
if( (raw->tmpB = (unsigned char *)malloc(raw->sizeX)) == NULL )
{
notify(FATAL)<< "Out of memory!"<<endl;
free( raw->tmp );
free( raw->tmpR );
free( raw->tmpG );
return NULL;
}
}
if (raw->sizeZ >= 4)
{
if( (raw->tmpA = (unsigned char *)malloc(raw->sizeX)) == NULL )
{
notify(FATAL)<< "Out of memory!"<<endl;
free( raw->tmp );
free( raw->tmpR );
free( raw->tmpG );
free( raw->tmpB );
return NULL;
}
}
if ((raw->type & 0xFF00) == 0x0100)
{
x = raw->sizeY * raw->sizeZ * sizeof(GLuint);
raw->rowStart = (GLuint *)malloc(x);
raw->rowSize = (GLint *)malloc(x);
if (raw->rowStart == NULL || raw->rowSize == NULL)
{
notify(FATAL)<< "Out of memory!"<<endl;
return NULL;
}
raw->rleEnd = 512 + (2 * x);
fseek(raw->file, 512, SEEK_SET);
fread(raw->rowStart, 1, x, raw->file);
fread(raw->rowSize, 1, x, raw->file);
if (swapFlag)
{
ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint)));
ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint)));
}
}
return raw;
}
static void RawImageClose(rawImageRec *raw)
{
fclose(raw->file);
free(raw->tmp);
if( raw->tmpR )
free(raw->tmpR);
if( raw->tmpG )
free(raw->tmpG);
if( raw->tmpB )
free(raw->tmpB);
if( raw->tmpA )
free(raw->tmpA);
free(raw);
}
static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z)
{
unsigned char *iPtr, *oPtr, pixel;
int count, done = 0;
if ((raw->type & 0xFF00) == 0x0100)
{
fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET);
fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY],
raw->file);
iPtr = raw->tmp;
oPtr = buf;
while (!done)
{
pixel = *iPtr++;
count = (int)(pixel & 0x7F);
if (!count)
{
done = 1;
return;
}
if (pixel & 0x80)
{
while (count--)
{
*oPtr++ = *iPtr++;
}
}
else
{
pixel = *iPtr++;
while (count--)
{
*oPtr++ = pixel;
}
}
}
}
else
{
fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY),
SEEK_SET);
fread(buf, 1, raw->sizeX, raw->file);
}
}
static void RawImageGetData(rawImageRec *raw, unsigned char **data )
{
unsigned char *ptr;
int i, j;
// // round the width to a factor 4
// int width = (int)(floorf((float)raw->sizeX/4.0f)*4.0f);
// if (width!=raw->sizeX) width += 4;
*data = (unsigned char *)malloc(2 * (raw->sizeX+1)*(raw->sizeY+1)*4);
// *data = (unsigned char *)malloc(2 * (width+1)*(raw->sizeY+1)*4);
ptr = *data;
for (i = 0; i < (int)(raw->sizeY); i++)
{
if( raw->sizeZ >= 1 )
RawImageGetRow(raw, raw->tmpR, i, 0);
if( raw->sizeZ >= 2 )
RawImageGetRow(raw, raw->tmpG, i, 1);
if( raw->sizeZ >= 3 )
RawImageGetRow(raw, raw->tmpB, i, 2);
if( raw->sizeZ >= 4 )
RawImageGetRow(raw, raw->tmpA, i, 3);
for (j = 0; j < (int)(raw->sizeX); j++)
{
if( raw->sizeZ >= 1 )
*ptr++ = *(raw->tmpR + j);
if( raw->sizeZ >= 2 )
*ptr++ = *(raw->tmpG + j);
if( raw->sizeZ >= 3 )
*ptr++ = *(raw->tmpB + j);
if( raw->sizeZ >= 4 )
*ptr++ = *(raw->tmpA + j);
}
// // pad the image width with blanks to bring it up to the rounded width.
// for(;j<width;++j) *ptr++ = 0;
}
}
class ReaderWriterRGB : public ReaderWriter
{
public:
virtual const char* className() { return "Default RGB Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
{
return extension=="rgb" || extension=="rgba" ||
extension=="int" || extension=="inta" ||
extension=="bw";
}
virtual Node* readNode(const std::string& fileName)
{
Image* image = readImage(fileName);
if (image)
{
Geode* geode = createGeodeForImage(image);
if (geode==NULL) image->unref();
return geode;
}
else
{
return NULL;
}
}
virtual Image* readImage(const std::string& fileName)
{
std::string ext = getLowerCaseFileExtension(fileName);
if (!acceptsExtension(ext)) return NULL;
rawImageRec *raw;
if( (raw = RawImageOpen(fileName.c_str())) == NULL )
{
notify(FATAL)<< "Unable to open \""<<fileName<<"\""<<endl;
return NULL;
}
int s = raw->sizeX;
int t = raw->sizeY;
int r = 1;
#if 0
int internalFormat = raw->sizeZ == 3 ? GL_RGB5 :
raw->sizeZ == 4 ? GL_RGB5_A1 : GL_RGB;
#else
int internalFormat = raw->sizeZ;
#endif
unsigned int pixelFormat =
raw->sizeZ == 1 ? GL_LUMINANCE :
raw->sizeZ == 2 ? GL_LUMINANCE_ALPHA :
raw->sizeZ == 3 ? GL_RGB :
raw->sizeZ == 4 ? GL_RGBA : (GLenum)-1;
unsigned int dataType = GL_UNSIGNED_BYTE;
unsigned char *data;
RawImageGetData(raw, &data);
RawImageClose(raw);
Image* image = new Image();
image->setFileName(fileName.c_str());
image->setImage(s,t,r,
internalFormat,
pixelFormat,
dataType,
data);
notify(INFO) << "image read ok "<<s<<" "<<t<<endl;
return image;
}
virtual bool writeImage(Image& ,const std::string& )
{
return false;
}
};
// now register with Registry to instantiate the above
// reader/writer.
RegisterReaderWriterProxy<ReaderWriterRGB> g_readerWriter_RGB_Proxy;

View File

@ -1,543 +0,0 @@
#include "osg/Registry"
#include "osg/Notify"
#include "osg/Object"
#include "osg/Image"
#include "osg/Node"
#include "osg/Group"
#include "osg/Input"
#include "osg/Output"
#include "osg/FileNameUtils"
#include <stdio.h>
#include <algorithm>
#include <set>
using namespace osg;
Object* osg::loadObjectFile(const char *name)
{
return Registry::instance()->readObject(name);
}
Image* osg::loadImageFile(const char *name)
{
return Registry::instance()->readImage(name);
}
Node* osg::loadNodeFile(const char *name)
{
return Registry::instance()->readNode(name);
}
bool osg::saveObjectFile(Object& object,const char *name)
{
return Registry::instance()->writeObject(object,name);
}
bool osg::saveImageFile(Image& image,const char *name)
{
return Registry::instance()->writeImage(image,name);
}
bool osg::saveNodeFile(Node& node,const char *name)
{
return Registry::instance()->writeNode(node,name);
}
// definition of the Registry
Registry::Registry()
{
notify(INFO) << "Constructing osg::Registry"<<endl;
_openingLibrary = false;
osg::Init();
}
Registry::~Registry()
{
// Don't write to notify() in here. Destruction order is indeterminate
// (I think) and the notify stream may have been destroyed before this
// is called.
// note, do not need to unregister attached prototype and reader/writers
// as they will be automatically unreferenced by the std::vector
// destructor & ref_ptr combination.
}
Registry* Registry::instance()
{
static Registry s_nodeFactory;
return &s_nodeFactory;
}
void Registry::addPrototype(Object* obj)
{
if (obj==0L) return;
// works under win32, good old C :-)
if (_openingLibrary) notify(INFO) << "Opening Library : ";
notify(INFO) << "osg::Registry::addPrototype("<<obj->className()<<")"<<endl;
int newPos = _nodeProtoList.size();
_protoList.push_back(obj);
if (dynamic_cast<Node*>(obj))
{
_nodeProtoList.push_back(newPos);
}
if (dynamic_cast<Image*>(obj))
{
_imageProtoList.push_back(newPos);
}
}
void Registry::removePrototype(Object* obj)
{
if (obj==0L) return;
notify(INFO) << "osg::Registry::removePrototype()"<<endl;
PrototypeList::iterator pitr = std::find(_protoList.begin(),_protoList.end(),obj);
if (pitr!=_protoList.end())
{
_protoList.erase(pitr);
// note need to handle the node and image lists,
// to be implemented...
}
}
void Registry::addReaderWriter(ReaderWriter* rw)
{
if (rw==0L) return;
if (_openingLibrary) notify(INFO) << "Opening Library : "<<endl;
notify(INFO) << "osg::Registry::addReaderWriter("<<rw->className()<<")"<<endl;
_rwList.push_back(rw);
}
void Registry::removeReaderWriter(ReaderWriter* rw)
{
if (rw==0L) return;
notify(INFO) << "osg::Registry::removeReaderWriter();"<<endl;
ReaderWriterList::iterator rwitr = std::find(_rwList.begin(),_rwList.end(),rw);
if (rwitr!=_rwList.end())
{
_rwList.erase(rwitr);
}
}
std::string Registry::createLibraryNameForFile(const std::string& fileName)
{
std::string ext = getLowerCaseFileExtension(fileName);
return createLibraryNameForExt(ext);
}
std::string Registry::createLibraryNameForExt(const std::string& ext)
{
#ifdef WIN32
# ifdef _DEBUG
return "osgdb_"+ext+"d.dll";
# else
return "osgdb_"+ext+".dll";
# endif
#else
return "osgdb_"+ext+".so";
#endif
}
bool Registry::loadLibrary(const std::string& fileName)
{
DynamicLibrary* dl = getLibrary(fileName);
if (dl) return false;
_openingLibrary=true;
dl = DynamicLibrary::loadLibrary(fileName);
_openingLibrary=false;
if (dl)
{
dl->ref();
_dlList.push_back(dl);
return true;
}
return false;
}
bool Registry::closeLibrary(const std::string& fileName)
{
DynamicLibraryList::iterator ditr = getLibraryItr(fileName);
if (ditr!=_dlList.end())
{
(*ditr)->unref();
_dlList.erase(ditr);
return true;
}
return false;
}
Registry::DynamicLibraryList::iterator Registry::getLibraryItr(const std::string& fileName)
{
DynamicLibraryList::iterator ditr = _dlList.begin();
for(;ditr!=_dlList.end();++ditr)
{
if ((*ditr)->getName()==fileName) return ditr;
}
return _dlList.end();
}
DynamicLibrary* Registry::getLibrary(const std::string& fileName)
{
DynamicLibraryList::iterator ditr = getLibraryItr(fileName);
if (ditr!=_dlList.end()) return ditr->get();
else return NULL;
}
Object* Registry::readObject(Input& fr)
{
if (fr[0].matchWord("Use"))
{
if (fr[1].isString()) {
Object* obj = fr.getObjectForUniqueID(fr[1].getStr());
if (obj) fr+=2;
return obj;
}
else return NULL;
}
for(unsigned int i=0;i<_protoList.size();++i)
{
Object* obj = _protoList[i]->readClone(fr);
if (obj) return obj;
}
return 0L;
}
Object* Registry::readObject(const std::string& fileName)
{
char *file = FindFile( fileName.c_str() );
if (file==NULL) return NULL;
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
Object* obj = (*itr)->readObject(file);
if (obj) return obj;
}
// now look for a plug-in to load the file.
std::string libraryName = createLibraryNameForFile(fileName);
if (Registry::instance()->loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
Object* obj = (*itr)->readObject(file);
if (obj) return obj;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
return NULL;
}
bool Registry::writeObject(Object& obj,const std::string& fileName)
{
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
if ((*itr)->writeObject(obj,fileName)) return true;
}
// now look for a plug-in to save the file.
std::string libraryName = createLibraryNameForFile(fileName);
if (loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
if ((*itr)->writeObject(obj,fileName)) return true;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
return false;
}
Image* Registry::readImage(Input& fr)
{
if (fr[0].matchWord("Use"))
{
if (fr[1].isString()) {
Image* image = dynamic_cast<Image*>(fr.getObjectForUniqueID(fr[1].getStr()));
if (image) fr+=2;
return image;
}
else return NULL;
}
for(std::vector<int>::iterator itr=_imageProtoList.begin();
itr!=_imageProtoList.end();
++itr)
{
int i=*itr;
Object* obj = _protoList[i]->readClone(fr);
if (obj)
{
Image* image = static_cast<Image*>(obj);
return image;
}
}
return 0L;
}
Image* Registry::readImage(const std::string& fileName)
{
char *file = FindFile( fileName.c_str() );
if (file==NULL) return NULL;
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
Image* image = (*itr)->readImage(file);
if (image) return image;
}
// now look for a plug-in to load the file.
std::string libraryName = createLibraryNameForFile(fileName);
if (loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
Image* image = (*itr)->readImage(file);
if (image) return image;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
return NULL;
}
bool Registry::writeImage(Image& image,const std::string& fileName)
{
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
if ((*itr)->writeImage(image,fileName)) return true;
}
// now look for a plug-in to save the file.
std::string libraryName = createLibraryNameForFile(fileName);
if (loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
if ((*itr)->writeImage(image,fileName)) return true;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
return false;
}
Node* Registry::readNode(Input& fr)
{
if (fr[0].matchWord("Use"))
{
if (fr[1].isString()) {
Node* node = dynamic_cast<Node*>(fr.getObjectForUniqueID(fr[1].getStr()));
if (node) fr+=2;
return node;
}
else return NULL;
}
std::vector<int>::iterator itr=_nodeProtoList.begin();
for(;itr!=_nodeProtoList.end();++itr)
{
int i=*itr;
Object* obj = _protoList[i]->readClone(fr);
if (obj)
{
Node* node = static_cast<Node*>(obj);
return node;
}
}
return 0L;
}
Node* Registry::readNode(const std::string& fileName)
{
char *file = FindFile( fileName.c_str() );
if (file==NULL) return NULL;
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
Node* node = (*itr)->readNode(file);
if (node) return node;
}
// now look for a plug-in to load the file.
std::string libraryName = createLibraryNameForFile(fileName);
notify(INFO) << "Now checking for plug-in "<<libraryName<<endl;
if (loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
Node* node = (*itr)->readNode(file);
if (node) return node;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
return NULL;
}
bool Registry::writeNode(Node& node,const std::string& fileName)
{
// record the existing reader writer.
std::set<ReaderWriter*> rwOriginal;
// first attempt to load the file from existing ReaderWriter's
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
rwOriginal.insert(itr->get());
if ((*itr)->writeNode(node,fileName)) return true;
}
// now look for a plug-in to save the file.
std::string libraryName = createLibraryNameForFile(fileName);
if (Registry::instance()->loadLibrary(libraryName))
{
for(ReaderWriterList::iterator itr=_rwList.begin();
itr!=_rwList.end();
++itr)
{
if (rwOriginal.find(itr->get())==rwOriginal.end())
{
if ((*itr)->writeNode(node,fileName)) return true;
}
}
}
else
{
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
<<getLowerCaseFileExtension(fileName)<<endl;
}
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
return false;
}

View File

@ -1,69 +0,0 @@
#include "osg/Scene"
#include "osg/Registry"
#include "osg/Input"
#include "osg/Output"
using namespace osg;
RegisterObjectProxy<Scene> g_SceneProxy;
Scene::Scene()
{
_gstate = NULL;
}
Scene::~Scene()
{
if (_gstate) _gstate->unref();
}
void Scene::setGState(osg::GeoState* gstate)
{
if (gstate==_gstate) return;
if (_gstate) _gstate->unref();
_gstate = gstate;
if (_gstate) _gstate->ref();
}
bool Scene::readLocalData(Input& fr)
{
bool iteratorAdvanced = false;
if (fr[0].matchWord("Use"))
{
if (fr[1].isString()) {
GeoState* geostate = dynamic_cast<GeoState*>(fr.getObjectForUniqueID(fr[1].getStr()));
if (geostate) {
fr+=2;
_gstate = geostate;
_gstate->ref();
iteratorAdvanced = true;
}
}
}
if (GeoState* readState = static_cast<GeoState*>(GeoState::instance()->readClone(fr)))
{
_gstate = readState;
_gstate->ref();
iteratorAdvanced = true;
}
if (Group::readLocalData(fr)) iteratorAdvanced = true;
return iteratorAdvanced;
}
bool Scene::writeLocalData(Output& fw)
{
if (_gstate)
{
_gstate->write(fw);
}
Group::writeLocalData(fw);
return true;
}

View File

@ -1,270 +0,0 @@
#include "osg/Seg"
using namespace osg;
bool Seg::intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb)
{
// compate s and e against the xMin to xMax range of bb.
if (s.x()<=e.x())
{
// trivial reject of segment wholely outside.
if (e.x()<bb.xMin()) return false;
if (s.x()>bb.xMax()) return false;
if (s.x()<bb.xMin())
{
// clip s to xMin.
s = s+(e-s)*(bb.xMin()-s.x())/(e.x()-s.x());
}
if (e.x()>bb.xMax())
{
// clip e to xMax.
e = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x());
}
}
else
{
if (s.x()<bb.xMin()) return false;
if (e.x()>bb.xMax()) return false;
if (e.x()<bb.xMin())
{
// clip s to xMin.
e = s+(e-s)*(bb.xMin()-s.x())/(e.x()-s.x());
}
if (s.x()>bb.xMax())
{
// clip e to xMax.
s = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x());
}
}
// compate s and e against the yMin to yMax range of bb.
if (s.y()<=e.y())
{
// trivial reject of segment wholely outside.
if (e.y()<bb.yMin()) return false;
if (s.y()>bb.yMax()) return false;
if (s.y()<bb.yMin())
{
// clip s to yMin.
s = s+(e-s)*(bb.yMin()-s.y())/(e.y()-s.y());
}
if (e.y()>bb.yMax())
{
// clip e to yMax.
e = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y());
}
}
else
{
if (s.y()<bb.yMin()) return false;
if (e.y()>bb.yMax()) return false;
if (e.y()<bb.yMin())
{
// clip s to yMin.
e = s+(e-s)*(bb.yMin()-s.y())/(e.y()-s.y());
}
if (s.y()>bb.yMax())
{
// clip e to yMax.
s = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y());
}
}
// compate s and e against the zMin to zMax range of bb.
if (s.z()<=e.z())
{
// trivial reject of segment wholely outside.
if (e.z()<bb.zMin()) return false;
if (s.z()>bb.zMax()) return false;
if (s.z()<bb.zMin())
{
// clip s to zMin.
s = s+(e-s)*(bb.zMin()-s.z())/(e.z()-s.z());
}
if (e.z()>bb.zMax())
{
// clip e to zMax.
e = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z());
}
}
else
{
if (s.z()<bb.zMin()) return false;
if (e.z()>bb.zMax()) return false;
if (e.z()<bb.zMin())
{
// clip s to zMin.
e = s+(e-s)*(bb.zMin()-s.z())/(e.z()-s.z());
}
if (s.z()>bb.zMax())
{
// clip e to zMax.
s = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z());
}
}
return true;
}
bool Seg::intersect(const BoundingBox& bb) const
{
if (!bb.isValid()) return false;
Vec3 s=_s,e=_e;
return intersectAndClip(s,e,bb);
}
bool Seg::intersect(const BoundingBox& bb,float& r1,float& r2) const
{
if (!bb.isValid()) return false;
Vec3 s=_s,e=_e;
return intersectAndClip(s,e,bb);
}
bool Seg::intersect(const BoundingSphere& bs,float& r1,float& r2) const
{
Vec3 sm = _s-bs._center;
float c = sm.length2()-bs._radius*bs._radius;
Vec3 se = _e-_s;
float a = se.length2();
float b = sm*se*2.0f;
float d = b*b-4.0f*a*c;
if (d<0.0f) return false;
d = sqrtf(d);
float div = 1.0f/(2.0f*a);
r1 = (-b-d)*div;
r2 = (-b+d)*div;
if (r1<=0.0f && r2<=0.0f) return false;
if (r1>=1.0f && r2>=1.0f) return false;
return true;
}
bool Seg::intersect(const BoundingSphere& bs) const
{
Vec3 sm = _s-bs._center;
float c = sm.length2()-bs._radius*bs._radius;
if (c<0.0f) return true;
Vec3 se = _e-_s;
float a = se.length2();
float b = (sm*se)*2.0f;
float d = b*b-4.0f*a*c;
if (d<0.0f) return false;
d = sqrtf(d);
float div = 1.0f/(2.0f*a);
float r1 = (-b-d)*div;
float r2 = (-b+d)*div;
if (r1<=0.0f && r2<=0.0f) return false;
if (r1>=1.0f && r2>=1.0f) return false;
return true;
}
bool Seg::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r)
{
if (v1==v2 || v2==v3 || v1==v3) return false;
Vec3 vse = _e-_s;
Vec3 v12 = v2-v1;
Vec3 n12 = v12^vse;
float ds12 = (_s-v1)*n12;
float d312 = (v3-v1)*n12;
if (d312>=0.0f)
{
if (ds12<0.0f) return false;
if (ds12>d312) return false;
}
else // d312 < 0
{
if (ds12>0.0f) return false;
if (ds12<d312) return false;
}
Vec3 v23 = v3-v2;
Vec3 n23 = v23^vse;
float ds23 = (_s-v2)*n23;
float d123 = (v1-v2)*n23;
if (d123>=0.0f)
{
if (ds23<0.0f) return false;
if (ds23>d123) return false;
}
else // d123 < 0
{
if (ds23>0.0f) return false;
if (ds23<d123) return false;
}
Vec3 v31 = v1-v3;
Vec3 n31 = v31^vse;
float ds31 = (_s-v3)*n31;
float d231 = (v2-v3)*n31;
if (d231>=0.0f)
{
if (ds31<0.0f) return false;
if (ds31>d231) return false;
}
else // d231 < 0
{
if (ds31>0.0f) return false;
if (ds31<d231) return false;
}
float r3 = ds12/d312;
float r1 = ds23/d123;
float r2 = ds31/d231;
// float rt = r1+r2+r3;
Vec3 in = v1*r1+v2*r2+v3*r3;
float length = vse.length();
vse /= length;
float d = (in-_s)*vse;
if (d<0.0f) return false;
if (d>length) return false;
r = d/length;
return true;
}

View File

@ -1,8 +0,0 @@
#include "osg/Sequence"
#include "osg/Registry"
using namespace osg;
RegisterObjectProxy<Sequence> g_SequenceProxy;
// to be written :-)

View File

@ -1,22 +0,0 @@
#ifndef __FLT_EXPORT_H
#define __FLT_EXPORT_H
#define FLT_DLL
#ifdef WIN32
#pragma warning( disable : 4251 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4786 )
#endif
#if defined(FLT_DLL) && defined(_MSC_VER)
# ifdef FLT_LIBRARY
# define FLT_EXPORT __declspec(dllexport)
# else
# define FLT_EXPORT __declspec(dllimport)
# endif /* FLT_LIBRARY */
#else
# define FLT_EXPORT
#endif /* FLT_DLL && _MSC_VER */
#endif

View File

@ -1,94 +0,0 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <osg/OSG>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Registry>
#include <osg/Notify>
#include "osg/FileNameUtils"
using namespace osg;
#ifdef __sgi
static int dirent_select( dirent *dent )
#else
static int dirent_select( const dirent *dent )
#endif
{
if( strlen( dent->d_name) < 4 )
return 0;
return !strncmp( ".osg", &dent->d_name[strlen(dent->d_name)-4], 4 );
}
class sgReaderWriterOSGTGZ : public ReaderWriter {
public:
virtual const char* className() { return "Default OSGTGZ Database Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension) { return extension=="osgtgz"; }
virtual Node* readNode(const std::string& fileName)
{
std::string ext = getLowerCaseFileExtension(fileName);
if (!acceptsExtension(ext)) return NULL;
osg::notify(osg::INFO)<< "sgReaderWriterOSGTGZ::readNode( "<<fileName.c_str()<<" )\n";
char dirname[128];
char command[1024];
struct dirent **dent;
int ndent;
sprintf( dirname, "/tmp/.osg%06d", getpid());
#ifdef __linux
sprintf( command,
"tar xfCz %s %s",
fileName.c_str(), dirname );
#endif
#ifdef __sgi
sprintf( command,
"cp %s %s; cd %s;"
"gzcat %s | tar xf -",
fileName.c_str(), dirname, dirname,
fileName.c_str() );
#endif
mkdir( dirname, 0700 );
system( command );
ndent = scandir( dirname, &dent, dirent_select, alphasort );
osg::Group *grp = new osg::Group;
osg::SetFilePath( dirname );
for( int i = 0; i < ndent; i++ )
{
osg::Node *node = osg::loadNodeFile( dent[i]->d_name );
grp->addChild( node );
}
sprintf( command, "rm -rf %s", dirname );
system( command );
if( grp->getNumChildren() == 0 )
{
grp->unref();
return NULL;
}
else
return grp;
}
virtual bool writeNode(Node& obj,const std::string& fileName) {
return false;
}
};
// now register with sgRegistry to instantiate the above
// reader/writer.
RegisterReaderWriterProxy<sgReaderWriterOSGTGZ> g_readerWriter_OSGTGZ_Proxy;

View File

@ -1,799 +0,0 @@
#include "osgUtil/RenderVisitor"
#include "osg/DCS"
#include "osg/Geode"
#include "osg/LOD"
#include "osg/Billboard"
#include "osg/LightSource"
#include "osg/Notify"
#include <float.h>
#include <algorithm>
#ifndef OSG_USE_IO_DOT_H
#include <iostream>
using namespace std;
#endif
using namespace osg;
using namespace osgUtil;
static bool g_debugging = false;
ViewState::ViewState()
{
_matrix = NULL;
_inverse = NULL;
_ratio = 0.002f;
_viewFrustumCullingActive=true;
_smallFeatureCullingActive=true;
}
ViewState::~ViewState()
{
if (_matrix) _matrix->unref();
if (_inverse) _inverse->unref();
}
bool ViewState::isCulled(const BoundingSphere& sp)
{
if (!sp.isValid()) return true;
Vec3 delta = sp._center-_eyePoint;
if (_smallFeatureCullingActive)
{
if (sp._radius<delta.length()*_ratio)
{
return true;
}
}
if (_viewFrustumCullingActive)
{
if (delta*_frustumTopNormal>sp._radius)
{
return true;
}
if (delta*_frustumBottomNormal>sp._radius)
{
return true;
}
if (delta*_frustumLeftNormal>sp._radius)
{
return true;
}
if (delta*_frustumRightNormal>sp._radius)
{
return true;
}
}
return false;
}
bool ViewState::isCulled(const BoundingBox& bb)
{
if (!bb.isValid()) return true;
if (_viewFrustumCullingActive)
{
unsigned int c;
for(c=0;c<8;++c)
{
if ((bb.corner(c)-_eyePoint)*_frustumLeftNormal<=0.0f) break;
}
// if all corners have been checked, therefore all points are
// and the far side of the left clipping plane and hence should be culled.
if (c==8) return true;
for(c=0;c<8;++c)
{
if ((bb.corner(c)-_eyePoint)*_frustumRightNormal<=0.0f) break;
}
// if all corners have been checked, therefore all points are
// and the far side of the right clipping plane and hence should be culled.
if (c==8) return true;
for(c=0;c<8;++c)
{
if ((bb.corner(c)-_eyePoint)*_frustumTopNormal<=0.0f) break;
}
// if all corners have been checked, therefore all points are
// and the far side of the top clipping plane and hence should be culled.
if (c==8) return true;
for(c=0;c<8;++c)
{
if ((bb.corner(c)-_eyePoint)*_frustumBottomNormal<=0.0f) break;
}
// if all corners have been checked, therefore all points are
// and the far side of the bottom clipping plane and hence should be culled.
if (c==8) return true;
}
return false;
}
RenderVisitor::RenderVisitor()
{
// overide the default node visitor mode.
setTraverseMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
_globalState=NULL;
_LODBias = 1.0f;
_fovy=60.0f;
_aspect=1.0f;
_znear=1.0f;
_zfar=1000.0f;
_tvs = new ViewState;
_tvs->_eyePoint.set(0.0f,0.0f,1.0f);
_tvs->_centerPoint.set(0.0f,0.0f,0.0f);
_tvs->_lookVector.set(0.0f,0.0f,-1.0f);
_tvs->_upVector.set(0.0f,1.0f,0.0f);
_tvs->ref();
_cvs = _tvs;
_cvs->ref();
_tsm = LOOK_VECTOR_DISTANCE;
_tsm = OBJECT_EYE_POINT_DISTANCE;
_viewFrustumCullingActive=true;
_smallFeatureCullingActive=true;
calculateClippingPlanes();
}
RenderVisitor::~RenderVisitor()
{
reset();
// if a global geostate is attached simply unref it.
if (_globalState)
{
_globalState->unref();
_globalState = NULL;
}
if (_tvs) _tvs->unref();
if (_cvs) _cvs->unref();
}
void RenderVisitor::reset()
{
//
// first unref all referenced objects and then empty the containers.
//
std::for_each(_viewStateStack.begin(),_viewStateStack.end(),UnrefOp<ViewState>());
_viewStateStack.erase(_viewStateStack.begin(),_viewStateStack.end());
if (_cvs!=_tvs)
{
if (_cvs) _cvs->unref();
_cvs = _tvs;
_cvs->ref();
}
for(std::multimap<float,MatrixGeoSet>::iterator titr= _transparentGeoSets.begin();
titr!= _transparentGeoSets.end();
++titr)
{
if ((*titr).second.first) (*titr).second.first->unref();
}
_transparentGeoSets.erase(_transparentGeoSets.begin(),_transparentGeoSets.end());
for(std::multimap<GeoState*,MatrixGeoSet>::iterator oitr= _opaqueGeoSets.begin();
oitr!= _opaqueGeoSets.end();
++oitr)
{
if ((*oitr).second.first) (*oitr).second.first->unref();
}
_opaqueGeoSets.erase(_opaqueGeoSets.begin(),_opaqueGeoSets.end());
_lights.erase(_lights.begin(),_lights.end());
}
void RenderVisitor::setGlobalState(GeoState* global)
{
if (global==_globalState) return;
if (_globalState) _globalState->unref();
_globalState = global;
_globalState->ref();
}
void RenderVisitor::setPerspective(const osg::Camera& camera)
{
_fovy=camera.getFieldOfViewY();
_aspect=camera.getAspectRatio();
_znear=camera.getNearPlane();
_zfar=camera.getFarPlane();
calculateClippingPlanes();
}
void RenderVisitor::setPerspective(float fovy,float aspect,float znear,float zfar)
{
_fovy=fovy;
_aspect=aspect;
_znear=znear;
_zfar=zfar;
calculateClippingPlanes();
}
void RenderVisitor::setLookAt(const Camera& camera)
{
setLookAt(camera.getEyePoint(),camera.getLookPoint(),camera.getUpVector());
}
void RenderVisitor::setLookAt(const Vec3& eye,const Vec3& center,const Vec3& upVector)
{
_tvs->_eyePoint = eye;
_tvs->_centerPoint = center;
_tvs->_lookVector = center-eye;
_tvs->_lookVector.normalize();
_tvs->_upVector = upVector;
calculateClippingPlanes();
}
void RenderVisitor::setLookAt(double eyeX,double eyeY,double eyeZ,
double centerX,double centerY,double centerZ,
double upX,double upY,double upZ)
{
_tvs->_eyePoint[0] = eyeX;
_tvs->_eyePoint[1] = eyeY;
_tvs->_eyePoint[2] = eyeZ;
_tvs->_centerPoint[0] = centerX;
_tvs->_centerPoint[1] = centerY;
_tvs->_centerPoint[2] = centerZ;
_tvs->_lookVector[0] = centerX-eyeX;
_tvs->_lookVector[1] = centerY-eyeY;
_tvs->_lookVector[2] = centerZ-eyeZ;
_tvs->_lookVector.normalize();
_tvs->_upVector[0] = upX;
_tvs->_upVector[1] = upY;
_tvs->_upVector[2] = upZ;
calculateClippingPlanes();
}
void RenderVisitor::setCullingActive(CullingType ct,bool active)
{
switch(ct)
{
case(VIEW_FRUSTUM_CULLING):_viewFrustumCullingActive=active;break;
case(SMALL_FEATURE_CULLING):_smallFeatureCullingActive=active;break;
}
}
bool RenderVisitor::getCullingActive(CullingType ct)
{
switch(ct)
{
case(VIEW_FRUSTUM_CULLING):return _viewFrustumCullingActive;
case(SMALL_FEATURE_CULLING):return _smallFeatureCullingActive;
}
return false;
}
void RenderVisitor::calculateClippingPlanes()
{
float half_fovy = _fovy*0.5f;
float s = sinf(half_fovy*M_PI/180.0f);
float c = cosf(half_fovy*M_PI/180.0f);
Vec3 lv = _tvs->_lookVector;
Vec3 up = _tvs->_upVector;
Vec3 sv = lv ^ up;
sv.normalize();
_tvs->_frustumTopNormal = -lv*s + up*c;
_tvs->_frustumTopNormal.normalize();
_tvs->_frustumBottomNormal = -lv*s - up*c;
_tvs->_frustumBottomNormal.normalize();
_tvs->_frustumLeftNormal = -sv*c - lv*(s*_aspect);
_tvs->_frustumLeftNormal.normalize();
_tvs->_frustumRightNormal = sv*c - lv*(s*_aspect);
_tvs->_frustumRightNormal.normalize();
// notify(INFO) << "_frustumTopNormal = "<<_tvs->_frustumTopNormal[0]<<"\t"<<_tvs->_frustumTopNormal[1]<<"\t"<<_tvs->_frustumTopNormal[2]<<endl;
// notify(INFO) << "_frustumBottomNormal = "<<_tvs->_frustumBottomNormal[0]<<"\t"<<_tvs->_frustumBottomNormal[1]<<"\t"<<_tvs->_frustumBottomNormal[2]<<endl;
// notify(INFO) << "_frustumLeftNormal = "<<_tvs->_frustumLeftNormal[0]<<"\t"<<_tvs->_frustumLeftNormal[1]<<"\t"<<_tvs->_frustumLeftNormal[2]<<endl;
// notify(INFO) << "_frustumRightNormal = "<<_tvs->_frustumRightNormal[0]<<"\t"<<_tvs->_frustumRightNormal[1]<<"\t"<<_tvs->_frustumRightNormal[2]<<endl;
}
void RenderVisitor::pushMatrix(const Matrix& matrix)
{
ViewState* nvs = new ViewState;
nvs->ref();
nvs->_viewFrustumCullingActive=_viewFrustumCullingActive;
nvs->_smallFeatureCullingActive=_smallFeatureCullingActive;
if (_cvs && _cvs->_matrix)
{
nvs->_matrix = new Matrix;
nvs->_matrix->mult(matrix,*(_cvs->_matrix));
}
else
{
nvs->_matrix = new Matrix(matrix);
}
nvs->_matrix->ref();
Matrix* inverse_world = new Matrix;
inverse_world->ref();
inverse_world->invert(*(nvs->_matrix));
nvs->_inverse = inverse_world;
nvs->_eyePoint = _tvs->_eyePoint*(*inverse_world);
nvs->_centerPoint = _tvs->_centerPoint*(*inverse_world);
nvs->_lookVector = nvs->_centerPoint - nvs->_eyePoint;
nvs->_lookVector.normalize();
nvs->_frustumTopNormal = (_tvs->_eyePoint + _tvs->_frustumTopNormal)*(*inverse_world)-nvs->_eyePoint;
nvs->_frustumTopNormal.normalize();
nvs->_frustumBottomNormal = (_tvs->_eyePoint + _tvs->_frustumBottomNormal)*(*inverse_world)-nvs->_eyePoint;
nvs->_frustumBottomNormal.normalize();
nvs->_frustumLeftNormal = (_tvs->_eyePoint + _tvs->_frustumLeftNormal)*(*inverse_world)-nvs->_eyePoint;
nvs->_frustumLeftNormal.normalize();
nvs->_frustumRightNormal = (_tvs->_eyePoint + _tvs->_frustumRightNormal)*(*inverse_world)-nvs->_eyePoint;
nvs->_frustumRightNormal.normalize();
if (_cvs) _cvs->unref();
_cvs = nvs;
if (_cvs) _cvs->ref();
_viewStateStack.push_back(nvs);
}
void RenderVisitor::popMatrix()
{
// pop the top of the view stack and unref it.
ViewState* pvs = _viewStateStack.back();
_viewStateStack.pop_back();
pvs->unref();
// unref previous cvs
if (_cvs) _cvs->unref();
// to new cvs and ref it.
if (_viewStateStack.empty())
{
_cvs = _tvs;
if (_cvs) _cvs->ref();
}
else
{
_cvs = _viewStateStack.back();
if (_cvs) _cvs->ref();
}
}
Matrix* RenderVisitor::getCurrentMatrix()
{
return _cvs->_matrix;
}
Matrix* RenderVisitor::getInverseCurrentMatrix()
{
return _cvs->_inverse;
}
const Vec3& RenderVisitor::getEyeLocal()
{
return _cvs->_eyePoint;
}
const Vec3& RenderVisitor::getCenterLocal()
{
return _cvs->_centerPoint;
}
const Vec3& RenderVisitor::getLookVectorLocal()
{
return _cvs->_lookVector;
}
bool RenderVisitor::isCulled(const BoundingSphere& sp)
{
return _cvs->isCulled(sp);
}
bool RenderVisitor::isCulled(const BoundingBox& bb)
{
return _cvs->isCulled(bb);
}
void RenderVisitor::apply(Node& node)
{
if (isCulled(node.getBound())) return;
traverse(node);
}
void RenderVisitor::apply(Geode& node)
{
if (isCulled(node.getBound())) return;
Matrix* matrix = getCurrentMatrix();
for(int i=0;i<node.getNumGeosets();++i)
{
GeoSet* gset = node.getGeoSet(i);
if (isCulled(gset->getBound())) continue;
GeoState* gstate = gset->getGeoState();
bool isTransparent = gstate && gstate->isTransparent();
if (isTransparent)
{
Vec3 center;
if (matrix)
{
center = (gset->getBound().center())*(*matrix);
}
else
{
center = gset->getBound().center();
}
Vec3 delta_center = center-_tvs->_eyePoint;
if (g_debugging)
{
notify(INFO) << "center ["<<center.x()<<","<<center.y()<<","<<center.z()<<"]"<<endl;
notify(INFO) << "delta_center ["<<delta_center.x()<<","<<delta_center.y()<<","<<delta_center.z()<<"]"<<endl;
notify(INFO) << "_lookVector ["<<_tvs->_lookVector.x()<<","<<_tvs->_lookVector.y()<<","<<_tvs->_lookVector.z()<<"]"<<endl;
}
float depth;
switch(_tsm)
{
case(LOOK_VECTOR_DISTANCE):depth = _tvs->_lookVector*delta_center;break;
case(OBJECT_EYE_POINT_DISTANCE):
default: depth = delta_center.length2();break;
}
if (matrix) matrix->ref();
_transparentGeoSets.insert(
std::pair<float,MatrixGeoSet>(depth,MatrixGeoSet(matrix,gset))
);
}
else
{
if (matrix) matrix->ref();
_opaqueGeoSets.insert(
std::pair<GeoState*,MatrixGeoSet>(gstate,MatrixGeoSet(matrix,gset))
);
}
}
}
void RenderVisitor::apply(Billboard& node)
{
if (isCulled(node.getBound())) return;
Vec3 eye_local = getEyeLocal();
for(int i=0;i<node.getNumGeosets();++i)
{
Vec3 pos;
node.getPos(i,pos);
GeoSet* gset = node.getGeoSet(i);
// need to modify isCulled to handle the billboard offset.
// if (isCulled(gset->getBound())) continue;
Matrix local_mat;
node.calcTransform(eye_local,pos,local_mat);
Matrix* matrix = NULL;
if (_cvs->_matrix)
{
matrix = new Matrix();
matrix->mult(local_mat,*(_cvs->_matrix));
}
else
{
matrix = new Matrix(local_mat);
}
GeoState* gstate = gset->getGeoState();
bool isTransparent = gstate && gstate->isTransparent();
if (isTransparent)
{
Vec3 center;
if (matrix)
{
center = (gset->getBound().center())*(*matrix);
}
else
{
center = gset->getBound().center();
}
Vec3 delta_center = center-_tvs->_eyePoint;
if (g_debugging)
{
notify(INFO) << "center ["<<center.x()<<","<<center.y()<<","<<center.z()<<"]"<<endl;
notify(INFO) << "delta_center ["<<delta_center.x()<<","<<delta_center.y()<<","<<delta_center.z()<<"]"<<endl;
notify(INFO) << "_lookVector ["<<_tvs->_lookVector.x()<<","<<_tvs->_lookVector.y()<<","<<_tvs->_lookVector.z()<<"]"<<endl;
}
float depth;
switch(_tsm)
{
case(LOOK_VECTOR_DISTANCE):depth = _tvs->_lookVector*delta_center;break;
case(OBJECT_EYE_POINT_DISTANCE):
default: depth = delta_center.length2();break;
}
if (matrix) matrix->ref();
_transparentGeoSets.insert(
std::pair<float,MatrixGeoSet>(depth,MatrixGeoSet(matrix,gset))
);
}
else
{
if (matrix) matrix->ref();
_opaqueGeoSets.insert(
std::pair<GeoState*,MatrixGeoSet>(gstate,MatrixGeoSet(matrix,gset))
);
}
}
}
void RenderVisitor::apply(LightSource& node)
{
Matrix* matrix = getCurrentMatrix();
Light* light = node.getLight();
if (light)
{
if (matrix) matrix->ref();
_lights.insert(std::pair<Matrix*,Light*>(matrix,light));
}
}
void RenderVisitor::apply(Group& node)
{
if (isCulled(node.getBound())) return;
traverse(node);
}
void RenderVisitor::apply(DCS& node)
{
if (isCulled(node.getBound())) return;
pushMatrix(*node.getMatrix());
traverse(node);
popMatrix();
}
void RenderVisitor::apply(Switch& node)
{
apply((Group&)node);
}
void RenderVisitor::apply(LOD& node)
{
if (isCulled(node.getBound())) return;
int eval = node.evaluate(getEyeLocal(),_LODBias);
if (eval<0)
{
//notify(INFO) << "culled LOD"<<endl;
return;
}
else
{
//notify(INFO) << "selecting child "<<eval<<endl;
node.getChild(eval)->accept(*this);
}
}
void RenderVisitor::apply(Scene& node)
{
apply((Group&)node);
}
bool RenderVisitor::calcNearFar(double& near_plane,double& far_plane)
{
if (_opaqueGeoSets.empty() && _transparentGeoSets.empty()) return false;
near_plane = FLT_MAX;
far_plane = -FLT_MAX;
Vec3 eyePoint = getEyeLocal();
Vec3 lookVector = getLookVectorLocal();
for(OpaqueList::iterator oitr = _opaqueGeoSets.begin();
oitr != _opaqueGeoSets.end();
++oitr)
{
Matrix* matrix = (oitr->second).first;
GeoSet* gset = (oitr->second).second;
const BoundingBox& bb = gset->getBound();
for(int c=0;c<8;++c)
{
float d;
if (matrix) d = ((bb.corner(c)*(*matrix))-eyePoint)*lookVector;
else d = (bb.corner(c)-eyePoint)*lookVector;
if (d<near_plane) near_plane = d;
if (d>far_plane) far_plane = d;
}
}
for(TransparentList::iterator titr = _transparentGeoSets.begin();
titr != _transparentGeoSets.end();
++titr)
{
Matrix* matrix = (titr->second).first;
GeoSet* gset = (titr->second).second;
const BoundingBox& bb = gset->getBound();
for(int c=0;c<8;++c)
{
float d;
if (matrix) d = ((bb.corner(c)*(*matrix))-eyePoint)*lookVector;
else d = (bb.corner(c)-eyePoint)*lookVector;
if (d<near_plane) near_plane = d;
if (d>far_plane) far_plane = d;
}
}
return true;
}
void RenderVisitor::render()
{
Matrix* prevMatrix = NULL;
Matrix* currMatrix = NULL;
GeoState* currGeoState = NULL;
GeoState* prevGeoState = NULL;
if (g_debugging) notify(INFO) << "start of render"<<endl;
if (_globalState)
{
_globalState->apply();
prevGeoState=_globalState;
}
// apply the lists.
for(LightList::iterator litr=_lights.begin();
litr!=_lights.end();
++litr)
{
currMatrix = litr->first;
if (currMatrix!=prevMatrix)
{
if (prevMatrix) glPopMatrix();
if (currMatrix)
{
glPushMatrix();
glMultMatrixf( (GLfloat *)(currMatrix->_mat) );
}
prevMatrix = currMatrix;
}
(litr->second)->apply();
}
// draw the opaque bin.
for(std::multimap<GeoState*,MatrixGeoSet>::iterator oitr= _opaqueGeoSets.begin();
oitr!= _opaqueGeoSets.end();
++oitr)
{
if (g_debugging)
{
notify(INFO) << " drawing opaque matrix["<<(*oitr).second.first<<"]"
<< " geoset["<<(*oitr).second.second<<"]"
<< " geostate["<<(*oitr).second.second->getGeoState()<<"]"<<endl;
}
currMatrix = (*oitr).second.first;
if (currMatrix!=prevMatrix)
{
if (prevMatrix) glPopMatrix();
if (currMatrix)
{
glPushMatrix();
glMultMatrixf( (GLfloat *)(currMatrix->_mat) );
}
prevMatrix = currMatrix;
}
currGeoState = (*oitr).first;
if (currGeoState!=prevGeoState)
{
if (currGeoState) currGeoState->apply(_globalState,prevGeoState);
prevGeoState = currGeoState;
}
(*oitr).second.second->draw();
}
// glPushAttrib( GL_DEPTH_TEST );
// glDisable( GL_DEPTH_TEST );
// render the transparent geoset in reverse order, so to render the
// deepest transparent objects, relative to the look vector, first.
for(std::multimap<float,MatrixGeoSet>::reverse_iterator titr= _transparentGeoSets.rbegin();
titr!= _transparentGeoSets.rend();
++titr)
{
if (g_debugging)
{
notify(INFO) << " drawing transparent matrix["<<(*titr).second.first<<"]"
<< " geoset["<<(*titr).second.second<<"]"
<< " geostate["<<(*titr).second.second->getGeoState()<<"]"
<< " depth["<<(*titr).first<<"]"<<endl;
}
currMatrix = (*titr).second.first;
if (currMatrix!=prevMatrix)
{
if (prevMatrix) glPopMatrix();
if (currMatrix)
{
glPushMatrix();
glMultMatrixf( (GLfloat *)(currMatrix->_mat) );
}
prevMatrix = currMatrix;
}
currGeoState = (*titr).second.second->getGeoState();
if (currGeoState!=prevGeoState)
{
if (currGeoState) currGeoState->apply(_globalState,prevGeoState);
prevGeoState = currGeoState;
}
(*titr).second.second->draw();
}
// glPopAttrib();
if (currMatrix) glPopMatrix();
if (g_debugging)
{
notify(INFO) << "end of render"<<endl<<endl;
notify(INFO).flush();
}
}