OGRE  1.9
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 #include "OgreVolumeCSGSource.h"
36 
37 namespace Ogre {
38 namespace 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 
68  const bool mTrilinearGradient;
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 
141  GridSource(bool trilinearValue, bool trilinearGradient, bool sobelGradient);
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 
192  Real getVolumeSpaceToWorldSpaceFactor(void) const;
193 
194  };
195 
196 }
197 }
198 
199 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
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:51
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