OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreVolumeGridSource.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
36 namespace Ogre {
37 namespace Volume {
38 
39  class CSGOperationSource;
40 
44  {
45  protected:
46 
48  size_t mWidth;
49 
51  size_t mHeight;
52 
54  size_t mDepth;
55 
58 
61 
64 
67 
69  const bool mTrilinearGradient;
70 
72  const bool mSobelGradient;
73 
76 
79  virtual Vector3 getIntersectionStart(const Ray &ray, Real maxDistance) const;
80 
83  virtual Vector3 getIntersectionEnd(const Ray &ray, Real maxDistance) const;
84 
95  virtual float getVolumeGridValue(size_t x, size_t y, size_t z) const = 0;
96 
107  virtual void setVolumeGridValue(int x, int y, int z, float value) = 0;
108 
117  inline const Vector3 getGradient(size_t x, size_t y, size_t z) const
118  {
119  if (mSobelGradient)
120  {
121  // Calculate gradient like in the original MC paper but mix a bit of Sobel in
122  return Vector3(
123  (getVolumeGridValue(x + 1, y - 1, z) - getVolumeGridValue(x - 1, y - 1, z))
124  + (Real)2.0 * (getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z))
125  + (getVolumeGridValue(x + 1, y + 1, z) - getVolumeGridValue(x - 1, y + 1, z)),
126  (getVolumeGridValue(x, y + 1, z - 1) - getVolumeGridValue(x, y - 1, z - 1))
127  + (Real)2.0 * (getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z))
128  + (getVolumeGridValue(x, y + 1, z + 1) - getVolumeGridValue(x, y - 1, z + 1)),
129  (getVolumeGridValue(x - 1, y, z + 1) - getVolumeGridValue(x - 1, y, z - 1))
130  + (Real)2.0 * (getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1))
131  + (getVolumeGridValue(x + 1, y, z + 1) - getVolumeGridValue(x + 1, y, z - 1))) / (Real)4.0;
132  }
133  // Calculate gradient like in the original MC paper
134  return Vector3(
135  getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z),
136  getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z),
137  getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1));
138  }
139 
140  public:
141 
142  GridSource(bool trilinearValue, bool trilinearGradient, bool sobelGradient);
143 
146  virtual ~GridSource(void);
147 
150  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
151 
154  virtual Real getValue(const Vector3 &position) const;
155 
160  size_t getWidth(void) const;
161 
166  size_t getHeight(void) const;
167 
172  size_t getDepth(void) const;
173 
188  virtual void combineWithSource(CSGOperationSource *operation, Source *source, const Vector3 &center, Real radius);
189 
190 
193  Real getVolumeSpaceToWorldSpaceFactor(void) const;
194 
195  };
196 
197 }
198 }
199 
200 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:45
float Real
Software floating point type.
size_t mDepth
The texture depth.
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.
const bool mTrilinearGradient
Whether to use trilinear filtering or not for the gradient.
Real mPosYScale
The scale of the position based on the world height.
Abstract operation volume source holding two sources as operants.
Abstract class defining the density function.
Real mPosXScale
The scale of the position based on the world width.
const bool mSobelGradient
Whether to blur the gradient a bit Sobel like.
Real mPosZScale
The scale of the position based on the world depth.
Real mVolumeSpaceToWorldSpaceFactor
Factor to come from volume coordinate to world coordinate.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
size_t mHeight
The texture height.
A volume source from a discrete 3d grid.
size_t mWidth
The texture width.
#define _OgreVolumeExport
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45