OgreVolumeGridSource.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_GridSource_H__
#define __Ogre_Volume_GridSource_H__
#include "OgreVector4.h"
#include "OgreVolumePrerequisites.h"
#include "OgreVolumeSource.h"
#include "OgreVolumeCSGSource.h"
namespace Ogre {
namespace Volume {
class _OgreVolumeExport GridSource : public Source
{
protected:
size_t mWidth;
size_t mHeight;
size_t mDepth;
Real mPosXScale;
Real mPosYScale;
Real mPosZScale;
bool mTrilinearValue;
const bool mTrilinearGradient;
const bool mSobelGradient;
Real mVolumeSpaceToWorldSpaceFactor;
virtual Vector3 getIntersectionStart(const Ray &ray, Real maxDistance) const;
virtual Vector3 getIntersectionEnd(const Ray &ray, Real maxDistance) const;
virtual float getVolumeGridValue(size_t x, size_t y, size_t z) const = 0;
virtual void setVolumeGridValue(int x, int y, int z, float value) = 0;
inline const Vector3 getGradient(size_t x, size_t y, size_t z) const
{
if (mSobelGradient)
{
// Calculate gradient like in the original MC paper but mix a bit of Sobel in
return Vector3(
(getVolumeGridValue(x + 1, y - 1, z) - getVolumeGridValue(x - 1, y - 1, z))
+ (Real)2.0 * (getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z))
+ (getVolumeGridValue(x + 1, y + 1, z) - getVolumeGridValue(x - 1, y + 1, z)),
(getVolumeGridValue(x, y + 1, z - 1) - getVolumeGridValue(x, y - 1, z - 1))
+ (Real)2.0 * (getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z))
+ (getVolumeGridValue(x, y + 1, z + 1) - getVolumeGridValue(x, y - 1, z + 1)),
(getVolumeGridValue(x - 1, y, z + 1) - getVolumeGridValue(x - 1, y, z - 1))
+ (Real)2.0 * (getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1))
+ (getVolumeGridValue(x + 1, y, z + 1) - getVolumeGridValue(x + 1, y, z - 1))) / (Real)4.0;
}
// Calculate gradient like in the original MC paper
return Vector3(
getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z),
getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z),
getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1));
}
public:
GridSource(bool trilinearValue, bool trilinearGradient, bool sobelGradient);
virtual ~GridSource(void);
virtual Vector4 getValueAndGradient(const Vector3 &position) const;
virtual Real getValue(const Vector3 &position) const;
size_t getWidth(void) const;
size_t getHeight(void) const;
size_t getDepth(void) const;
virtual void combineWithSource(CSGOperationSource *operation, Source *source, const Vector3 &center, Real radius);
Real getVolumeSpaceToWorldSpaceFactor(void) const;
};
}
}
#endif
OgreVector4.h
Ogre::Volume::GridSource::mPosYScale
Real mPosYScale
The scale of the position based on the world height.
Definition: OgreVolumeGridSource.h:59
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Volume::GridSource::mTrilinearValue
bool mTrilinearValue
Whether to use trilinear filtering or not for the value.
Definition: OgreVolumeGridSource.h:65
Ogre::Volume::GridSource::getGradient
const Vector3 getGradient(size_t x, size_t y, size_t z) const
Gets a gradient of a point with optional sobel blurring.
Definition: OgreVolumeGridSource.h:116
Ogre::Volume::GridSource
A volume source from a discrete 3d grid.
Definition: OgreVolumeGridSource.h:42
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::GridSource::mHeight
size_t mHeight
The texture height.
Definition: OgreVolumeGridSource.h:50
OgreVolumePrerequisites.h
OgreVolumeCSGSource.h
OgreVolumeSource.h
Ogre::Volume::GridSource::mPosXScale
Real mPosXScale
The scale of the position based on the world width.
Definition: OgreVolumeGridSource.h:56
Ogre::Volume::GridSource::mPosZScale
Real mPosZScale
The scale of the position based on the world depth.
Definition: OgreVolumeGridSource.h:62
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::GridSource::mSobelGradient
const bool mSobelGradient
Whether to blur the gradient a bit Sobel like.
Definition: OgreVolumeGridSource.h:71
Ogre::Volume::GridSource::mDepth
size_t mDepth
The texture depth.
Definition: OgreVolumeGridSource.h:53
Ogre::Volume::GridSource::mWidth
size_t mWidth
The texture width.
Definition: OgreVolumeGridSource.h:47
Ogre::Volume::GridSource::mVolumeSpaceToWorldSpaceFactor
Real mVolumeSpaceToWorldSpaceFactor
Factor to come from volume coordinate to world coordinate.
Definition: OgreVolumeGridSource.h:74
Ogre::Volume::Source
Abstract class defining the density function.
Definition: OgreVolumeSource.h:41
Ogre::Volume::GridSource::mTrilinearGradient
const bool mTrilinearGradient
Whether to use trilinear filtering or not for the gradient.
Definition: OgreVolumeGridSource.h:68
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
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.