Files
OpenSceneGraph/include/osg/Image
Robert Osfield f612924a45 Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying.  The old functionality of clone() which was clone of type has
been renamed to cloneType().

Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc.  A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.

Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.

Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData.  These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.

method
2002-01-28 21:17:01 +00:00

119 lines
4.2 KiB
C++

//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
// -*-c++-*-
#ifndef OSG_IMAGE
#define OSG_IMAGE 1
#include <osg/Object>
#include <string>
namespace osg {
/** Image class for encapsulating the storage texture image data.*/
class SG_EXPORT Image : public Object
{
public :
Image();
/** Copy constructor using Cloner to manage deep vs shallow copy.*/
Image(const Image& image,const Cloner& cloner=ShallowCopy());
virtual Object* cloneType() const { return new Image(); }
virtual Object* clone(const Cloner& cloner) const { return new Image(*this,cloner); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Image*>(obj)!=0; }
virtual const char* className() const { return "Image"; }
inline const std::string& getFileName() const { return _fileName; }
void setFileName(const std::string& fileName);
/** set the image data and format.
* note, when the packing value is negative (the default is -1) this method assumes
* a _packing width of 1 if the width is not a multiple of 4,
* otherwise automatically sets to _packing to 4. If a positive
* value of packing is supplied than _packing is simply set to that value.
*/
void setImage(const int s,const int t,const int r,
const int internalFormat,
const unsigned int pixelFormat,
const unsigned int dataType,
unsigned char *data,
const int packing=-1);
/** Width of image.*/
inline const int s() const { return _s; }
/** Height of image.*/
inline const int t() const { return _t; }
/** Depth of image.*/
inline const int r() const { return _r; }
inline const int internalFormat() const { return _internalFormat; }
inline const unsigned int pixelFormat() const { return _pixelFormat; }
inline const unsigned int dataType() const { return _dataType; }
inline const unsigned int packing() const { return _packing; }
/** raw image data.*/
inline unsigned char *data() { return _data; }
/** raw const image data.*/
inline const unsigned char *data() const { return _data; }
/** Scale image to specified size. */
void scaleImage(const int s,const int t,const int r);
/** Ensure image dimensions are a power of two.
* Mip Mapped texture require the image dimensions to be
* power of two.
*/
void ensureDimensionsArePowerOfTwo();
/** Dirty the image, which increments the modified flag, to force osg::Texture to reload the image.*/
inline void dirty() { ++_modifiedTag; }
/** Set the modified tag value, only used by osg::Texture when using texture subloading. */
inline void setModifiedTag(const unsigned int value) { _modifiedTag=value; }
/** Get modified tag value, only used by osg::Texture when using texture subloading. */
inline const unsigned int getModifiedTag() const { return _modifiedTag; }
protected :
virtual ~Image();
// Image(const Image&) {}
// Image& operator = (const Image& image) {}
std::string _fileName;
int _s, _t, _r;
int _internalFormat;
unsigned int _pixelFormat;
unsigned int _dataType;
unsigned int _packing;
unsigned char *_data;
unsigned int _modifiedTag;
};
class Geode;
/** Convenience function to be used by images loaders to generate a valid geode
* to return for readNode().
* Use the images s and t values scale the dimensions of the image.
*/
SG_EXPORT extern Geode* createGeodeForImage(Image* image);
/** Convenience function to be used by images loaders to generate a valid geode
* to return for readNode().
* Use the specified s and t values scale the dimensions of the image.
*/
SG_EXPORT extern Geode* createGeodeForImage(Image* image,const float s,const float t);
};
#endif // __SG_IMAGE_H