CubeMapGenerator
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_CUBEMAPGENERATOR_
#define OSGUTIL_CUBEMAPGENERATOR_
#include <osgUtil/Export>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/CopyOp>
#include <osg/Referenced>
#include <osg/TextureCubeMap>
#include <osg/Image>
#include <osg/Notify>
#include <vector>
namespace osgUtil
{
class OSGUTIL_EXPORT CubeMapGenerator: public osg::Referenced {
public:
explicit CubeMapGenerator(int texture_size = 64);
CubeMapGenerator(const CubeMapGenerator &copy, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
inline osg::Image *getImage(osg::TextureCubeMap::Face face);
inline const osg::Image *getImage(osg::TextureCubeMap::Face face) const;
void generateMap(bool use_osg_system = true);
protected:
virtual ~CubeMapGenerator() {}
CubeMapGenerator &operator=(const CubeMapGenerator &) { return *this; }
inline void set_pixel(int index, int c, int r, const osg::Vec4 &color);
inline static osg::Vec4 vector_to_color(const osg::Vec3 &vec);
virtual osg::Vec4 compute_color(const osg::Vec3 &R) const = 0;
private:
int texture_size_;
typedef std::vector<osg::ref_ptr<osg::Image> > Image_list;
Image_list images_;
};
// INLINE METHODS
inline osg::Image *CubeMapGenerator::getImage(osg::TextureCubeMap::Face face)
{
switch (face) {
case osg::TextureCubeMap::POSITIVE_X: return images_[0].get();
case osg::TextureCubeMap::NEGATIVE_X: return images_[1].get();
case osg::TextureCubeMap::POSITIVE_Y: return images_[2].get();
case osg::TextureCubeMap::NEGATIVE_Y: return images_[3].get();
case osg::TextureCubeMap::POSITIVE_Z: return images_[4].get();
case osg::TextureCubeMap::NEGATIVE_Z: return images_[5].get();
default: return 0;
}
}
inline const osg::Image *CubeMapGenerator::getImage(osg::TextureCubeMap::Face face) const
{
switch (face) {
case osg::TextureCubeMap::POSITIVE_X: return images_[0].get();
case osg::TextureCubeMap::NEGATIVE_X: return images_[1].get();
case osg::TextureCubeMap::POSITIVE_Y: return images_[2].get();
case osg::TextureCubeMap::NEGATIVE_Y: return images_[3].get();
case osg::TextureCubeMap::POSITIVE_Z: return images_[4].get();
case osg::TextureCubeMap::NEGATIVE_Z: return images_[5].get();
default: return 0;
}
}
inline void CubeMapGenerator::set_pixel(int index, int c, int r, const osg::Vec4 &color)
{
osg::Image *i = images_[index].get();
if (i) {
*(i->data(c, r)+0) = static_cast<unsigned char>(osg::clampBetween(color.x(),0.0f,1.0f) * 255);
*(i->data(c, r)+1) = static_cast<unsigned char>(osg::clampBetween(color.y(),0.0f,1.0f) * 255);
*(i->data(c, r)+2) = static_cast<unsigned char>(osg::clampBetween(color.z(),0.0f,1.0f) * 255);
*(i->data(c, r)+3) = static_cast<unsigned char>(osg::clampBetween(color.w(),0.0f,1.0f) * 255);
} else {
osg::notify(osg::WARN) << "Warning: CubeMapGenerator::set_pixel(): invalid image index\n";
}
}
inline osg::Vec4 CubeMapGenerator::vector_to_color(const osg::Vec3 &vec)
{
return osg::Vec4(
vec.x() / vec.length() / 2 + 0.5f,
vec.y() / vec.length() / 2 + 0.5f,
vec.z() / vec.length() / 2 + 0.5f,
1);
}
}
#endif
CopyOp
Image
Notify
Referenced
TextureCubeMap
Vec3
Vec4
osgUtil::CubeMapGenerator::CubeMapGenerator
CubeMapGenerator(int texture_size=64)
osgUtil::CubeMapGenerator::getImage
osg::Image * getImage(osg::TextureCubeMap::Face face)
Definition CubeMapGenerator:71
osgUtil::CubeMapGenerator::CubeMapGenerator
CubeMapGenerator(const CubeMapGenerator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgUtil::CubeMapGenerator::generateMap
void generateMap(bool use_osg_system=true)
osgUtil::CubeMapGenerator::operator=
CubeMapGenerator & operator=(const CubeMapGenerator &)
Definition CubeMapGenerator:51
osgUtil::CubeMapGenerator::compute_color
virtual osg::Vec4 compute_color(const osg::Vec3 &R) const =0
osgUtil::CubeMapGenerator::~CubeMapGenerator
virtual ~CubeMapGenerator()
Definition CubeMapGenerator:50
osgUtil::CubeMapGenerator::set_pixel
void set_pixel(int index, int c, int r, const osg::Vec4 &color)
Definition CubeMapGenerator:97
osgUtil::CubeMapGenerator::vector_to_color
static osg::Vec4 vector_to_color(const osg::Vec3 &vec)
Definition CubeMapGenerator:110
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Image
Definition Image:179
osg::Image::data
unsigned char * data()
Definition Image:352
osg::Referenced
Definition Referenced:44
osg::TextureCubeMap::Face
Face
Definition TextureCubeMap:40
osg::TextureCubeMap::POSITIVE_X
@ POSITIVE_X
Definition TextureCubeMap:41
osg::TextureCubeMap::NEGATIVE_Y
@ NEGATIVE_Y
Definition TextureCubeMap:44
osg::TextureCubeMap::POSITIVE_Y
@ POSITIVE_Y
Definition TextureCubeMap:43
osg::TextureCubeMap::NEGATIVE_X
@ NEGATIVE_X
Definition TextureCubeMap:42
osg::TextureCubeMap::POSITIVE_Z
@ POSITIVE_Z
Definition TextureCubeMap:45
osg::TextureCubeMap::NEGATIVE_Z
@ NEGATIVE_Z
Definition TextureCubeMap:46
osg::Vec3f::z
value_type & z()
Definition Vec3f:82
osg::Vec3f::y
value_type & y()
Definition Vec3f:81
osg::Vec3f::x
value_type & x()
Definition Vec3f:80
osg::Vec3f::length
value_type length() const
Definition Vec3f:176
osg::Vec4f::y
value_type & y()
Definition Vec4f:88
osg::Vec4f::x
value_type & x()
Definition Vec4f:87
osg::Vec4f::z
value_type & z()
Definition Vec4f:89
osg::Vec4f::w
value_type & w()
Definition Vec4f:90
osgUtil
Definition NodeVisitor:25
osg::WARN
@ WARN
Definition Notify:33
osg::clampBetween
T clampBetween(T v, T minimum, T maximum)
Definition Math:97
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
osg::notify
std::ostream & notify(void)
Definition Notify:80
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40