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-2013 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
Ogre::Volume::GridSource::mSobelGradient
const bool mSobelGradient
Whether to blur the gradient a bit Sobel like.
Definition: OgreVolumeGridSource.h:71
OgreVector4.h
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Volume::GridSource::mPosZScale
Real mPosZScale
The scale of the position based on the world depth.
Definition: OgreVolumeGridSource.h:62
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::mPosXScale
Real mPosXScale
The scale of the position based on the world width.
Definition: OgreVolumeGridSource.h:56
OgreVolumeSource.h
Ogre::Volume::GridSource::mPosYScale
Real mPosYScale
The scale of the position based on the world height.
Definition: OgreVolumeGridSource.h:59
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::GridSource::mTrilinearGradient
const bool mTrilinearGradient
Whether to use trilinear filtering or not for the gradient.
Definition: OgreVolumeGridSource.h:68
Ogre::Volume::CSGOperationSource
Abstract operation volume source holding two sources as operants.
Definition: OgreVolumeCSGSource.h:168
Ogre::Volume::GridSource::mHeight
size_t mHeight
The texture height.
Definition: OgreVolumeGridSource.h:50
_OgreVolumeExport
#define _OgreVolumeExport
Definition: OgreVolumePrerequisites.h:43
Ogre::Volume::GridSource::mTrilinearValue
bool mTrilinearValue
Whether to use trilinear filtering or not for the value.
Definition: OgreVolumeGridSource.h:65
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
OgreVolumePrerequisites.h
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Volume::Source
Abstract class defining the density function.
Definition: OgreVolumeSource.h:41
Ogre::Volume::GridSource
A volume source from a discrete 3d grid.
Definition: OgreVolumeGridSource.h:42
OgreVolumeCSGSource.h

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