OGRE  1.9.0
OgreVolumeCacheSource.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_CacheSource_H__
29#define __Ogre_Volume_CacheSource_H__
30
31#include "OgreVector3.h"
32#include "OgreVector4.h"
33
34#include "OgreVolumeSource.h"
36
37namespace Ogre {
38namespace Volume {
39
48 bool _OgreVolumeExport operator<(const Vector3& a, const Vector3& b);
49
53 {
54 protected:
55
59
61 const Source *mSrc;
62
69 inline Vector4 getFromCache(const Vector3 &position) const
70 {
71 Vector4 result;
72 map<Vector3, Vector4>::iterator it = mCache.find(position);
73 if (it == mCache.end())
74 {
75 result = mSrc->getValueAndGradient(position);
76 mCache[position] = result;
77 }
78 else
79 {
80 result = it->second;
81 }
82 return result;
83 }
84
85 public:
86
91 CacheSource(const Source *src);
92
95 virtual Vector4 getValueAndGradient(const Vector3 &position) const;
96
99 virtual Real getValue(const Vector3 &position) const;
100
101 };
102
103}
104}
105
106#endif
#define _OgreVolumeExport
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
Vector4 getFromCache(const Vector3 &position) const
Gets a density value and gradient from the cache.
virtual Real getValue(const Vector3 &position) const
Overridden from Source.
const Source * mSrc
The source to cache.
virtual Vector4 getValueAndGradient(const Vector3 &position) const
Overridden from Source.
map< Vector3, Vector4 >::type UMapPositionValue
Map for the cache.
CacheSource(const Source *src)
Constructor.
Abstract class defining the density function.
virtual Vector4 getValueAndGradient(const Vector3 &position) const =0
Gets the density value and gradient at a specific position.
bool _OgreVolumeExport operator<(const Vector3 &a, const Vector3 &b)
A less operator.
float Real
Software floating point type.
std::map< K, V, P, A > type
std::map< K, V, P, A >::iterator iterator