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_CSGSource_H__ 00029 #define __Ogre_Volume_CSGSource_H__ 00030 00031 #include "OgreVolumeSource.h" 00032 #include "OgreVector3.h" 00033 #include "OgreAxisAlignedBox.h" 00034 #include "OgreVolumePrerequisites.h" 00035 #include "OgreVolumeSimplexNoise.h" 00036 00037 namespace Ogre { 00038 namespace Volume { 00039 00042 class _OgreVolumeExport CSGSphereSource : public Source 00043 { 00044 protected: 00047 const Real mR; 00048 00051 const Vector3 mCenter; 00052 public: 00053 00060 CSGSphereSource(const Real r, const Vector3 ¢er); 00061 00064 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00065 00068 virtual Real getValue(const Vector3 &position) const; 00069 }; 00070 00073 class _OgreVolumeExport CSGPlaneSource : public Source 00074 { 00075 protected: 00076 00078 const Real mD; 00079 00081 Vector3 mNormal; 00082 00083 public: 00084 00091 CSGPlaneSource(const Real d, const Vector3 &normal); 00092 00095 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00096 00099 virtual Real getValue(const Vector3 &position) const; 00100 }; 00101 00104 class _OgreVolumeExport CSGCubeSource : public Source 00105 { 00106 protected: 00107 00109 static Vector3 mBoxNormals[6]; 00110 00112 AxisAlignedBox mBox; 00113 00120 inline Real distanceTo(const Vector3 &position) const 00121 { 00122 Real distance; 00123 const Vector3 dMin = position - mBox.getMinimum(); 00124 const Vector3 dMax = mBox.getMaximum() - position; 00125 00126 // Check if inside of the box 00127 if (dMin.x >= (Real)0.0 && dMin.y >= (Real)0.0 && dMin.z >= (Real)0.0 && 00128 dMax.x >= (Real)0.0 && dMax.y >= (Real)0.0 && dMax.z >= (Real)0.0) 00129 { 00130 const Real d[6] = {dMin.x, dMin.y, dMin.z, dMax.x, dMax.y, dMax.z}; 00131 distance = Math::POS_INFINITY; 00132 for (size_t i = 0; i < 6; ++i) 00133 { 00134 if (d[i] < distance) 00135 { 00136 distance = d[i]; 00137 } 00138 } 00139 } 00140 else 00141 { 00142 distance = -mBox.distance(position); 00143 } 00144 return distance; 00145 } 00146 00147 public: 00148 00155 CSGCubeSource(const Vector3 &min, const Vector3 &max); 00156 00159 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00160 00163 virtual Real getValue(const Vector3 &position) const; 00164 }; 00165 00168 class _OgreVolumeExport CSGOperationSource : public Source 00169 { 00170 protected: 00171 00173 const Source *mA; 00174 00176 const Source *mB; 00177 00184 CSGOperationSource(const Source *a, const Source *b); 00185 00189 CSGOperationSource(void); 00190 public: 00191 00196 virtual const Source* getSourceA() const; 00197 00202 virtual void setSourceA(Source *a); 00203 00208 virtual const Source* getSourceB(void) const; 00209 00214 virtual void setSourceB(Source *b); 00215 }; 00216 00219 class _OgreVolumeExport CSGIntersectionSource : public CSGOperationSource 00220 { 00221 public: 00222 00229 CSGIntersectionSource(const Source *a, const Source *b); 00230 00233 CSGIntersectionSource(void); 00234 00237 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00238 00241 virtual Real getValue(const Vector3 &position) const; 00242 }; 00243 00246 class _OgreVolumeExport CSGUnionSource : public CSGOperationSource 00247 { 00248 public: 00249 00256 CSGUnionSource(const Source *a, const Source *b); 00257 00260 CSGUnionSource(void); 00261 00264 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00265 00268 virtual Real getValue(const Vector3 &position) const; 00269 }; 00270 00273 class _OgreVolumeExport CSGDifferenceSource : public CSGOperationSource 00274 { 00275 public: 00276 00277 00284 CSGDifferenceSource(const Source *a, const Source *b); 00285 00288 CSGDifferenceSource(void); 00289 00292 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00293 00296 virtual Real getValue(const Vector3 &position) const; 00297 }; 00298 00301 class _OgreVolumeExport CSGUnarySource : public Source 00302 { 00303 protected: 00304 00306 const Source *mSrc; 00307 00312 CSGUnarySource(const Source *src); 00313 00317 CSGUnarySource(void); 00318 00319 public: 00320 00325 virtual const Source* getSource(void) const; 00326 00331 virtual void setSource(Source *a); 00332 }; 00333 00336 class _OgreVolumeExport CSGNegateSource : public CSGUnarySource 00337 { 00338 public: 00339 00344 explicit CSGNegateSource(const Source *src); 00345 00348 CSGNegateSource(void); 00349 00352 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00353 00356 virtual Real getValue(const Vector3 &position) const; 00357 }; 00358 00361 class _OgreVolumeExport CSGScaleSource : public CSGUnarySource 00362 { 00363 protected: 00364 00366 Real mScale; 00367 public: 00368 00375 CSGScaleSource(const Source *src, const Real scale); 00376 00379 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00380 00383 virtual Real getValue(const Vector3 &position) const; 00384 }; 00385 00386 class _OgreVolumeExport CSGNoiseSource: public CSGUnarySource 00387 { 00388 protected: 00389 00391 Real *mFrequencies; 00392 00394 Real *mAmplitudes; 00395 00397 size_t mNumOctaves; 00398 00400 SimplexNoise mNoise; 00401 00403 Real mGradientOff; 00404 00406 long mSeed; 00407 00409 void setData(void); 00410 00411 /* Gets the density value. 00412 @param position 00413 The position of the value. 00414 @return 00415 The value. 00416 */ 00417 inline Real getInternalValue(const Vector3 &position) const 00418 { 00419 Real toAdd = (Real)0.0; 00420 for (size_t i = 0; i < mNumOctaves; ++i) 00421 { 00422 toAdd += mNoise.noise(position.x * mFrequencies[i], position.y * mFrequencies[i], position.z * mFrequencies[i]) * mAmplitudes[i]; 00423 } 00424 return mSrc->getValue(position) + toAdd; 00425 } 00426 00427 public: 00428 00441 CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves, long seed); 00442 00453 CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves); 00454 00457 virtual Vector4 getValueAndGradient(const Vector3 &position) const; 00458 00461 virtual Real getValue(const Vector3 &position) const; 00462 00467 long getSeed(void) const; 00468 }; 00469 00470 } 00471 } 00472 00473 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48