OgreVolumeCSGSource.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_CSGSource_H__
29 #define __Ogre_Volume_CSGSource_H__
30 
31 #include "OgreVolumeSource.h"
32 #include "OgreVector3.h"
33 #include "OgreAxisAlignedBox.h"
35 #include "OgreVolumeSimplexNoise.h"
36 
37 namespace Ogre {
38 namespace Volume {
39 
43  {
44  protected:
47  const Real mR;
48 
52  public:
53 
60  CSGSphereSource(const Real r, const Vector3 &center);
61 
64  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
65 
68  virtual Real getValue(const Vector3 &position) const;
69  };
70 
74  {
75  protected:
76 
78  const Real mD;
79 
82 
83  public:
84 
91  CSGPlaneSource(const Real d, const Vector3 &normal);
92 
95  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
96 
99  virtual Real getValue(const Vector3 &position) const;
100  };
101 
105  {
106  protected:
107 
109  static Vector3 mBoxNormals[6];
110 
113 
120  inline Real distanceTo(const Vector3 &position) const
121  {
122  Real distance;
123  const Vector3 dMin = position - mBox.getMinimum();
124  const Vector3 dMax = mBox.getMaximum() - position;
125 
126  // Check if inside of the box
127  if (dMin.x >= (Real)0.0 && dMin.y >= (Real)0.0 && dMin.z >= (Real)0.0 &&
128  dMax.x >= (Real)0.0 && dMax.y >= (Real)0.0 && dMax.z >= (Real)0.0)
129  {
130  const Real d[6] = {dMin.x, dMin.y, dMin.z, dMax.x, dMax.y, dMax.z};
131  distance = Math::POS_INFINITY;
132  for (size_t i = 0; i < 6; ++i)
133  {
134  if (d[i] < distance)
135  {
136  distance = d[i];
137  }
138  }
139  }
140  else
141  {
142  distance = -mBox.distance(position);
143  }
144  return distance;
145  }
146 
147  public:
148 
155  CSGCubeSource(const Vector3 &min, const Vector3 &max);
156 
159  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
160 
163  virtual Real getValue(const Vector3 &position) const;
164  };
165 
169  {
170  protected:
171 
173  const Source *mA;
174 
176  const Source *mB;
177 
184  CSGOperationSource(const Source *a, const Source *b);
185 
189  CSGOperationSource(void);
190  public:
191 
196  virtual const Source* getSourceA() const;
197 
202  virtual void setSourceA(Source *a);
203 
208  virtual const Source* getSourceB(void) const;
209 
214  virtual void setSourceB(Source *b);
215  };
216 
220  {
221  public:
222 
229  CSGIntersectionSource(const Source *a, const Source *b);
230 
233  CSGIntersectionSource(void);
234 
237  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
238 
241  virtual Real getValue(const Vector3 &position) const;
242  };
243 
247  {
248  public:
249 
256  CSGUnionSource(const Source *a, const Source *b);
257 
260  CSGUnionSource(void);
261 
264  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
265 
268  virtual Real getValue(const Vector3 &position) const;
269  };
270 
274  {
275  public:
276 
277 
284  CSGDifferenceSource(const Source *a, const Source *b);
285 
288  CSGDifferenceSource(void);
289 
292  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
293 
296  virtual Real getValue(const Vector3 &position) const;
297  };
298 
302  {
303  protected:
304 
306  const Source *mSrc;
307 
312  CSGUnarySource(const Source *src);
313 
317  CSGUnarySource(void);
318 
319  public:
320 
325  virtual const Source* getSource(void) const;
326 
331  virtual void setSource(Source *a);
332  };
333 
337  {
338  public:
339 
344  explicit CSGNegateSource(const Source *src);
345 
348  CSGNegateSource(void);
349 
352  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
353 
356  virtual Real getValue(const Vector3 &position) const;
357  };
358 
362  {
363  protected:
364 
367  public:
368 
375  CSGScaleSource(const Source *src, const Real scale);
376 
379  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
380 
383  virtual Real getValue(const Vector3 &position) const;
384  };
385 
387  {
388  protected:
389 
392 
395 
397  size_t mNumOctaves;
398 
401 
404 
406  long mSeed;
407 
409  void setData(void);
410 
411  /* Gets the density value.
412  @param position
413  The position of the value.
414  @return
415  The value.
416  */
417  inline Real getInternalValue(const Vector3 &position) const
418  {
419  Real toAdd = (Real)0.0;
420  for (size_t i = 0; i < mNumOctaves; ++i)
421  {
422  toAdd += mNoise.noise(position.x * mFrequencies[i], position.y * mFrequencies[i], position.z * mFrequencies[i]) * mAmplitudes[i];
423  }
424  return mSrc->getValue(position) + toAdd;
425  }
426 
427  public:
428 
441  CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves, long seed);
442 
453  CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves);
454 
457  virtual Vector4 getValueAndGradient(const Vector3 &position) const;
458 
461  virtual Real getValue(const Vector3 &position) const;
462 
467  long getSeed(void) const;
468  };
469 
470 }
471 }
472 
473 #endif
Vector3 mNormal
The normal of the plane.
Real noise(Real xIn, Real yIn, Real zIn) const
3D noise function.
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
float Real
Software floating point type.
Real mGradientOff
To calculate the gradient.
Builds the difference between two sources.
const Source * mSrc
The first operant.
size_t mNumOctaves
The amount of octaves.
SimplexNoise mNoise
To make some noise.
Real * mFrequencies
The frequencies of the octaves.
const Vector3 mCenter
The center.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Real distanceTo(const Vector3 &position) const
Gets the distance of a point to the nearest cube element.
Real mScale
Holds the dimensions of the volume.
const Source * mA
The first operant.
static const Real POS_INFINITY
Definition: OgreMath.h:704
Scales the given volume source.
long mSeed
The initial seed.
Real distance(const Vector3 &v) const
Returns the minimum distance between a given point and any part of the box.
const Source * mB
The second operant.
Real getInternalValue(const Vector3 &position) const
AxisAlignedBox mBox
The box.
Source which does a unary operation to another one.
Simplex Noise ported from public domain Java Implementation http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java Thanks Stefan Gustavson!
Builds the union between two sources.
Negates the given volume.
Abstract class defining the density function.
A 3D box aligned with the x/y/z axes.
const Real mD
The distance to zero of the plane.
Real * mAmplitudes
The amplitudes of the octaves.
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
#define _OgreVolumeExport
Builds the intersection between two sources.
Abstract operation volume source holding two sources as operants.

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 Jan 2 2017 11:59:31