OGRE  1.9.0
OgreVolumeCSGSource.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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"
36
37namespace Ogre {
38namespace 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
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
230
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
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
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
313
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
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
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
#define _OgreVolumeExport
A 3D box aligned with the x/y/z axes.
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
Real distance(const Vector3 &v) const
Returns the minimum distance between a given point and any part of the box.
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
Real distanceTo(const Vector3 &position) const
Gets the distance of a point to the nearest cube element.
CSGCubeSource(const Vector3 &min, const Vector3 &max)
Constructor.
AxisAlignedBox mBox
The box.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
Builds the difference between two sources.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
CSGDifferenceSource(void)
Constructor, sets the sources to null.
CSGDifferenceSource(const Source *a, const Source *b)
Constructor.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
Builds the intersection between two sources.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
CSGIntersectionSource(const Source *a, const Source *b)
Constructor.
CSGIntersectionSource(void)
Constructor, sets the sources to null.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
Negates the given volume.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
CSGNegateSource(void)
Constructor.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
CSGNegateSource(const Source *src)
Constructor.
long getSeed(void) const
Gets the initial seed.
Real * mAmplitudes
The amplitudes of the octaves.
Real * mFrequencies
The frequencies of the octaves.
size_t mNumOctaves
The amount of octaves.
SimplexNoise mNoise
To make some noise.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
void setData(void)
Prepares the node members.
Real getInternalValue(const Vector3 &position) const
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves)
Constructor with current time as seed.
CSGNoiseSource(const Source *src, Real *frequencies, Real *amplitudes, size_t numOctaves, long seed)
Constructor.
Real mGradientOff
To calculate the gradient.
Abstract operation volume source holding two sources as operants.
const Source * mA
The first operant.
CSGOperationSource(const Source *a, const Source *b)
Constructor.
CSGOperationSource(void)
Constructor, sets the sources to null.
virtual const Source * getSourceA() const
Gets the first operator source.
virtual void setSourceB(Source *b)
Sets the second operator source.
virtual void setSourceA(Source *a)
Sets the first operator source.
const Source * mB
The second operant.
virtual const Source * getSourceB(void) const
Gets the second operator source.
Vector3 mNormal
The normal of the plane.
const Real mD
The distance to zero of the plane.
CSGPlaneSource(const Real d, const Vector3 &normal)
Constructor.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
Scales the given volume source.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
CSGScaleSource(const Source *src, const Real scale)
Constructor.
Real mScale
Holds the dimensions of the volume.
CSGSphereSource(const Real r, const Vector3 &center)
Constructor.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
const Vector3 mCenter
The center.
Source which does a unary operation to another one.
virtual const Source * getSource(void) const
Gets the source.
const Source * mSrc
The first operant.
CSGUnarySource(void)
Constructor.
CSGUnarySource(const Source *src)
Constructor.
virtual void setSource(Source *a)
Sets the source.
Builds the union between two sources.
CSGUnionSource(void)
Constructor, sets the sources to null.
CSGUnionSource(const Source *a, const Source *b)
Constructor.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
Simplex Noise ported from public domain Java Implementation http://webstaff.itn.liu....
Real noise(Real xIn, Real yIn, Real zIn) const
3D noise function.
Abstract class defining the density function.
float Real
Software floating point type.