OgreVolumeGridSource.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Ogre_Volume_GridSource_H__
00029 #define __Ogre_Volume_GridSource_H__
00030 
00031 #include "OgreVector4.h"
00032 
00033 #include "OgreVolumePrerequisites.h"
00034 #include "OgreVolumeSource.h"
00035 #include "OgreVolumeCSGSource.h"
00036 
00037 namespace Ogre {
00038 namespace Volume {
00039 
00042     class _OgreVolumeExport GridSource : public Source
00043     {
00044     protected:
00045 
00047         size_t mWidth;
00048 
00050         size_t mHeight;
00051         
00053         size_t mDepth;
00054         
00056         Real mPosXScale;
00057         
00059         Real mPosYScale;
00060         
00062         Real mPosZScale;
00063 
00065         bool mTrilinearValue;
00066         
00068         const bool mTrilinearGradient;
00069 
00071         const bool mSobelGradient;
00072 
00074         Real mVolumeSpaceToWorldSpaceFactor;
00075         
00078         virtual Vector3 getIntersectionStart(const Ray &ray, Real maxDistance) const;
00079         
00082         virtual Vector3 getIntersectionEnd(const Ray &ray, Real maxDistance) const;
00083 
00094         virtual float getVolumeGridValue(size_t x, size_t y, size_t z) const = 0;
00095         
00106         virtual void setVolumeGridValue(int x, int y, int z, float value) = 0;
00107 
00116         inline const Vector3 getGradient(size_t x, size_t y, size_t z) const
00117         {
00118             if (mSobelGradient)
00119             {
00120                 // Calculate gradient like in the original MC paper but mix a bit of Sobel in
00121                 return Vector3(
00122                 (getVolumeGridValue(x + 1, y - 1, z) - getVolumeGridValue(x - 1, y - 1, z))
00123                         + (Real)2.0 * (getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z))
00124                         + (getVolumeGridValue(x + 1, y + 1, z) - getVolumeGridValue(x - 1, y + 1, z)),
00125                 (getVolumeGridValue(x, y + 1, z - 1) - getVolumeGridValue(x, y - 1, z - 1))
00126                     + (Real)2.0 * (getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z))
00127                     + (getVolumeGridValue(x, y + 1, z + 1) - getVolumeGridValue(x, y - 1, z + 1)),
00128                 (getVolumeGridValue(x - 1, y, z + 1) - getVolumeGridValue(x - 1, y, z - 1))
00129                     + (Real)2.0 * (getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1))
00130                     + (getVolumeGridValue(x + 1, y, z + 1) - getVolumeGridValue(x + 1, y, z - 1))) / (Real)4.0;
00131             }
00132             // Calculate gradient like in the original MC paper
00133             return Vector3(
00134                 getVolumeGridValue(x + 1, y, z) - getVolumeGridValue(x - 1, y, z),
00135                 getVolumeGridValue(x, y + 1, z) - getVolumeGridValue(x, y - 1, z),
00136                 getVolumeGridValue(x, y, z + 1) - getVolumeGridValue(x, y, z - 1));
00137         }
00138 
00139     public:
00140 
00141         GridSource(bool trilinearValue, bool trilinearGradient, bool sobelGradient);
00142 
00145         virtual ~GridSource(void);
00146 
00149         virtual Vector4 getValueAndGradient(const Vector3 &position) const;
00150         
00153         virtual Real getValue(const Vector3 &position) const;
00154 
00159         size_t getWidth(void) const;
00160         
00165         size_t getHeight(void) const;
00166         
00171         size_t getDepth(void) const;
00172 
00187         virtual void combineWithSource(CSGOperationSource *operation, Source *source, const Vector3 &center, Real radius);
00188     
00189         
00192         Real getVolumeSpaceToWorldSpaceFactor(void) const;
00193 
00194     };
00195 
00196 }
00197 }
00198 
00199 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48