OgreVolumeCSGSource.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_Volume_CSGSource_H__
#define __Ogre_Volume_CSGSource_H__
#include "OgreVolumeSource.h"
#include "OgreVector3.h"
#include "OgreAxisAlignedBox.h"
#include "OgreVolumePrerequisites.h"
#include "OgreVolumeSimplexNoise.h"
namespace Ogre {
namespace Volume {
class _OgreVolumeExport CSGSphereSource : public Source
{
protected:
const Real mR;
const Vector3 mCenter;
public:
CSGSphereSource(const Real r, const Vector3 &center);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGPlaneSource : public Source
{
protected:
const Real mD;
Vector3 mNormal;
public:
CSGPlaneSource(const Real d, const Vector3 &normal);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGCubeSource : public Source
{
protected:
static Vector3 mBoxNormals[6];
AxisAlignedBox mBox;
inline Real distanceTo(const Vector3 &position) const
{
Real distance;
const Vector3 dMin = position - mBox.getMinimum();
const Vector3 dMax = mBox.getMaximum() - position;
// Check if inside of the box
if (dMin.x >= (Real)0.0 && dMin.y >= (Real)0.0 && dMin.z >= (Real)0.0 &&
dMax.x >= (Real)0.0 && dMax.y >= (Real)0.0 && dMax.z >= (Real)0.0)
{
const Real d[6] = {dMin.x, dMin.y, dMin.z, dMax.x, dMax.y, dMax.z};
distance = Math::POS_INFINITY;
for (size_t i = 0; i < 6; ++i)
{
if (d[i] < distance)
{
distance = d[i];
}
}
}
else
{
distance = -mBox.distance(position);
}
return distance;
}
public:
CSGCubeSource(const Vector3 &min, const Vector3 &max);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGOperationSource : public Source
{
protected:
const Source *mA;
const Source *mB;
CSGOperationSource(const Source *a, const Source *b);
CSGOperationSource(void);
public:
virtual const Source* getSourceA() const;
virtual void setSourceA(Source *a);
virtual const Source* getSourceB(void) const;
virtual void setSourceB(Source *b);
};
class _OgreVolumeExport CSGIntersectionSource : public CSGOperationSource
{
public:
CSGIntersectionSource(const Source *a, const Source *b);
CSGIntersectionSource(void);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGUnionSource : public CSGOperationSource
{
public:
CSGUnionSource(const Source *a, const Source *b);
CSGUnionSource(void);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGDifferenceSource : public CSGOperationSource
{
public:
CSGDifferenceSource(const Source *a, const Source *b);
CSGDifferenceSource(void);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGUnarySource : public Source
{
protected:
const Source *mSrc;
CSGUnarySource(const Source *src);
CSGUnarySource(void);
public:
virtual const Source* getSource(void) const;
virtual void setSource(Source *a);
};
class _OgreVolumeExport CSGNegateSource : public CSGUnarySource
{
public:
explicit CSGNegateSource(const Source *src);
CSGNegateSource(void);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGScaleSource : public CSGUnarySource
{
protected:
Real mScale;
public:
CSGScaleSource(const Source *src, const Real scale);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
};
class _OgreVolumeExport CSGNoiseSource: public CSGUnarySource
{
protected:
Real *mFrequencies;
Real *mAmplitudes;
size_t mNumOctaves;
SimplexNoise mNoise;
Real mGradientOff;
long mSeed;
void setData(void);
/* Gets the density value.
@param position
The position of the value.
@return
The value.
*/
inline Real getInternalValue(const Vector3 &position) const
{
Real toAdd = (Real)0.0;
for (size_t i = 0; i < mNumOctaves; ++i)
{
toAdd += mNoise.noise(position.x * mFrequencies[i], position.y * mFrequencies[i], position.z * mFrequencies[i]) * mAmplitudes[i];
}
return mSrc->getValue(position) + toAdd;
}
public:
CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves, long seed);
CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
long getSeed(void) const;
};
}
}
#endif
Ogre::Vector3::z
Real z
Definition: OgreVector3.h:54
Ogre::Volume::CSGPlaneSource::mNormal
Vector3 mNormal
The normal of the plane.
Definition: OgreVolumeCSGSource.h:81
Ogre::Volume::CSGSphereSource::mR
const Real mR
The radius.
Definition: OgreVolumeCSGSource.h:47
Ogre::Volume::CSGPlaneSource
A plane.
Definition: OgreVolumeCSGSource.h:73
OgreAxisAlignedBox.h
OgreVector3.h
Ogre::Volume::SimplexNoise::noise
Real noise(Real xIn, Real yIn, Real zIn) const
3D noise function.
Ogre::AxisAlignedBox::getMaximum
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
Definition: OgreAxisAlignedBox.h:165
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::CSGNoiseSource::mGradientOff
Real mGradientOff
To calculate the gradient.
Definition: OgreVolumeCSGSource.h:403
Ogre::Volume::CSGDifferenceSource
Builds the difference between two sources.
Definition: OgreVolumeCSGSource.h:273
Ogre::Volume::CSGUnarySource::mSrc
const Source * mSrc
The first operant.
Definition: OgreVolumeCSGSource.h:306
Ogre::Volume::CSGNoiseSource::mNumOctaves
size_t mNumOctaves
The amount of octaves.
Definition: OgreVolumeCSGSource.h:397
Ogre::Volume::CSGNoiseSource::mNoise
SimplexNoise mNoise
To make some noise.
Definition: OgreVolumeCSGSource.h:400
Ogre::Volume::CSGNoiseSource::mFrequencies
Real * mFrequencies
The frequencies of the octaves.
Definition: OgreVolumeCSGSource.h:391
Ogre::Volume::CSGSphereSource::mCenter
const Vector3 mCenter
The center.
Definition: OgreVolumeCSGSource.h:51
Ogre::Volume::CSGNoiseSource
Definition: OgreVolumeCSGSource.h:386
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::CSGCubeSource::distanceTo
Real distanceTo(const Vector3 &position) const
Gets the distance of a point to the nearest cube element.
Definition: OgreVolumeCSGSource.h:120
Ogre::Volume::CSGScaleSource::mScale
Real mScale
Holds the dimensions of the volume.
Definition: OgreVolumeCSGSource.h:366
Ogre::Volume::CSGOperationSource::mA
const Source * mA
The first operant.
Definition: OgreVolumeCSGSource.h:173
Ogre::Vector3::y
Real y
Definition: OgreVector3.h:54
Ogre::Math::POS_INFINITY
static const Real POS_INFINITY
Definition: OgreMath.h:704
OgreVolumeSimplexNoise.h
Ogre::Volume::CSGScaleSource
Scales the given volume source.
Definition: OgreVolumeCSGSource.h:361
Ogre::Volume::CSGNoiseSource::mSeed
long mSeed
The initial seed.
Definition: OgreVolumeCSGSource.h:406
Ogre::AxisAlignedBox::distance
Real distance(const Vector3 &v) const
Returns the minimum distance between a given point and any part of the box.
Definition: OgreAxisAlignedBox.h:793
Ogre::Volume::CSGCubeSource
A not rotated cube.
Definition: OgreVolumeCSGSource.h:104
OgreVolumePrerequisites.h
Ogre::Volume::CSGSphereSource
A sphere.
Definition: OgreVolumeCSGSource.h:42
OgreVolumeSource.h
Ogre::Volume::CSGOperationSource::mB
const Source * mB
The second operant.
Definition: OgreVolumeCSGSource.h:176
Ogre::Volume::CSGNoiseSource::getInternalValue
Real getInternalValue(const Vector3 &position) const
Definition: OgreVolumeCSGSource.h:417
Ogre::Vector3::x
Real x
Definition: OgreVector3.h:54
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::CSGCubeSource::mBox
AxisAlignedBox mBox
The box.
Definition: OgreVolumeCSGSource.h:112
Ogre::Volume::CSGUnarySource
Source which does a unary operation to another one.
Definition: OgreVolumeCSGSource.h:301
Ogre::Volume::SimplexNoise
Simplex Noise ported from public domain Java Implementation http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java Thanks Stefan Gustavson!
Definition: OgreVolumeSimplexNoise.h:42
Ogre::Volume::CSGUnionSource
Builds the union between two sources.
Definition: OgreVolumeCSGSource.h:246
Ogre::Volume::CSGNegateSource
Negates the given volume.
Definition: OgreVolumeCSGSource.h:336
Ogre::Volume::Source
Abstract class defining the density function.
Definition: OgreVolumeSource.h:41
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::Volume::CSGPlaneSource::mD
const Real mD
The distance to zero of the plane.
Definition: OgreVolumeCSGSource.h:78
Ogre::Volume::CSGNoiseSource::mAmplitudes
Real * mAmplitudes
The amplitudes of the octaves.
Definition: OgreVolumeCSGSource.h:394
Ogre::AxisAlignedBox::getMinimum
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
Definition: OgreAxisAlignedBox.h:150
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::Volume::CSGIntersectionSource
Builds the intersection between two sources.
Definition: OgreVolumeCSGSource.h:219
Ogre::Volume::CSGOperationSource
Abstract operation volume source holding two sources as operants.
Definition: OgreVolumeCSGSource.h:168

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.