OGRE  1.9.0
OgreVolumeGridSource.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __Ogre_Volume_GridSource_H__
29#define __Ogre_Volume_GridSource_H__
30
31#include "OgreVector4.h"
32
34#include "OgreVolumeSource.h"
35#include "OgreVolumeCSGSource.h"
36
37namespace Ogre {
38namespace Volume {
39
43 {
44 protected:
45
47 size_t mWidth;
48
50 size_t mHeight;
51
53 size_t mDepth;
54
57
60
63
66
69
71 const bool mSobelGradient;
72
75
78 virtual Vector3 getIntersectionStart(const Ray &ray, Real maxDistance) const;
79
82 virtual Vector3 getIntersectionEnd(const Ray &ray, Real maxDistance) const;
83
94 virtual float getVolumeGridValue(size_t x, size_t y, size_t z) const = 0;
95
106 virtual void setVolumeGridValue(int x, int y, int z, float value) = 0;
107
116 inline const Vector3 getGradient(size_t x, size_t y, size_t z) const
117 {
118 if (mSobelGradient)
119 {
120 // Calculate gradient like in the original MC paper but mix a bit of Sobel in
121 return Vector3(
122 (getVolumeGridValue(x + 1, y - 1, z) - getVolumeGridValue(x - 1, y - 1, z))
123 + (Real)2.0 * (getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z))
124 + (getVolumeGridValue(x + 1, y + 1, z) - getVolumeGridValue(x - 1, y + 1, z)),
125 (getVolumeGridValue(x, y + 1, z - 1) - getVolumeGridValue(x, y - 1, z - 1))
126 + (Real)2.0 * (getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z))
127 + (getVolumeGridValue(x, y + 1, z + 1) - getVolumeGridValue(x, y - 1, z + 1)),
128 (getVolumeGridValue(x - 1, y, z + 1) - getVolumeGridValue(x - 1, y, z - 1))
129 + (Real)2.0 * (getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1))
130 + (getVolumeGridValue(x + 1, y, z + 1) - getVolumeGridValue(x + 1, y, z - 1))) / (Real)4.0;
131 }
132 // Calculate gradient like in the original MC paper
133 return Vector3(
134 getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z),
135 getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z),
136 getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1));
137 }
138
139 public:
140
142
145 virtual ~GridSource(void);
146
149 virtual Vector4 getValueAndGradient(const Vector3 &position) const;
150
153 virtual Real getValue(const Vector3 &position) const;
154
159 size_t getWidth(void) const;
160
165 size_t getHeight(void) const;
166
171 size_t getDepth(void) const;
172
187 virtual void combineWithSource(CSGOperationSource *operation, Source *source, const Vector3 &center, Real radius);
188
189
193
194 };
195
196}
197}
198
199#endif
#define _OgreVolumeExport
Representation of a ray in space, i.e.
Definition OgreRay.h:47
Reference-counted shared pointer, used for objects where implicit destruction is required.
Standard 3-dimensional vector.
Definition OgreVector3.h:52
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
Abstract operation volume source holding two sources as operants.
A volume source from a discrete 3d grid.
Real mPosYScale
The scale of the position based on the world height.
GridSource(bool trilinearValue, bool trilinearGradient, bool sobelGradient)
virtual Vector3 getIntersectionStart(const Ray &ray, Real maxDistance) const
Overridden from VolumeSource.
size_t mWidth
The texture width.
virtual float getVolumeGridValue(size_t x, size_t y, size_t z) const =0
Gets the volume value of a position.
size_t getDepth(void) const
Gets the depth of the texture.
bool mTrilinearValue
Whether to use trilinear filtering or not for the value.
const Vector3 getGradient(size_t x, size_t y, size_t z) const
Gets a gradient of a point with optional sobel blurring.
size_t mHeight
The texture height.
virtual Real getValue(const Vector3 &position) const
Overridden from VolumeSource.
const bool mSobelGradient
Whether to blur the gradient a bit Sobel like.
Real mPosZScale
The scale of the position based on the world depth.
size_t mDepth
The texture depth.
virtual Vector3 getIntersectionEnd(const Ray &ray, Real maxDistance) const
Overridden from VolumeSource.
Real mVolumeSpaceToWorldSpaceFactor
Factor to come from volume coordinate to world coordinate.
virtual ~GridSource(void)
Destructor.
Real mPosXScale
The scale of the position based on the world width.
size_t getHeight(void) const
Gets the height of the texture.
size_t getWidth(void) const
Gets the width of the texture.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from VolumeSource.
virtual void combineWithSource(CSGOperationSource *operation, Source *source, const Vector3 &center, Real radius)
Updates this grid with another source in a certain area.
Real getVolumeSpaceToWorldSpaceFactor(void) const
Overridden from VolumeSource.
virtual void setVolumeGridValue(int x, int y, int z, float value)=0
Sets the volume value of a position.
const bool mTrilinearGradient
Whether to use trilinear filtering or not for the gradient.
Abstract class defining the density function.
float Real
Software floating point type.