Field3D
MIPBase.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
43 //----------------------------------------------------------------------------//
44 
45 #ifndef _INCLUDED_Field3D_MIPBase_H_
46 #define _INCLUDED_Field3D_MIPBase_H_
47 
48 #include "Field.h"
49 #include "MIPUtil.h"
50 #include "RefCount.h"
51 #include "Types.h"
52 
53 //----------------------------------------------------------------------------//
54 
55 #include "ns.h"
56 
58 
59 //----------------------------------------------------------------------------//
60 // LazyLoadAction
61 //----------------------------------------------------------------------------//
62 
68 //----------------------------------------------------------------------------//
69 
70 template <class Field_T>
72 {
73 public:
74 
75  // Typedefs ------------------------------------------------------------------
76 
77  typedef boost::shared_ptr<LazyLoadAction<Field_T> > Ptr;
78  typedef std::vector<Ptr> Vec;
79 
80  virtual ~LazyLoadAction()
81  { }
82 
83  // To be implemented by subclasses -------------------------------------------
84 
87  virtual typename Field_T::Ptr load() const = 0;
88 
89 };
90 
91 //----------------------------------------------------------------------------//
92 // MIPBase
93 //----------------------------------------------------------------------------//
94 
113 //----------------------------------------------------------------------------//
114 
115 template <class Data_T>
116 class MIPBase : public Field<Data_T>
117 {
118 
119 public:
120 
121  // Typedefs ------------------------------------------------------------------
122 
123  typedef boost::intrusive_ptr<MIPBase> Ptr;
124 
125  // RTTI replacement ----------------------------------------------------------
126 
129 
130  static const char *staticClassName()
131  {
132  return "MIPBase";
133  }
134 
135  static const char* staticClassType()
136  {
138  }
139 
140  // Constructors --------------------------------------------------------------
141 
143 
144  // To be implemented by subclasses -------------------------------------------
145 
148  virtual Data_T mipValue(size_t level, int i, int j, int k) const = 0;
149 
151  virtual V3i mipResolution(size_t level) const = 0;
152 
154  virtual bool levelLoaded(const size_t level) const = 0;
155 
158  virtual void getVsMIPCoord(const V3f &vsP, const size_t level,
159  V3f &outVsP) const = 0;
160 
162  virtual typename Field<Data_T>::Ptr mipLevel(const size_t level) const = 0;
163 
164 
165  // Main methods --------------------------------------------------------------
166 
169  void setLowestLevel(size_t level);
171  size_t lowestLevel() const
172  { return m_lowestLevel; }
174  size_t numLevels() const
175  { return m_numLevels; }
178  void setMIPOffset(const V3i &offset);
180  const V3i& mipOffset() const
181  { return m_mipOffset; }
182 
183 protected:
184 
185  // Static data members -------------------------------------------------------
186 
188 
189  // Typedefs ------------------------------------------------------------------
190 
192 
193  // Data members --------------------------------------------------------------
194 
196  size_t m_numLevels;
205 
206 };
207 
208 //----------------------------------------------------------------------------//
209 // MIPBase implementations
210 //----------------------------------------------------------------------------//
211 
212 template <typename Data_T>
214  : m_numLevels(1), m_lowestLevel(0), m_mipOffset(0)
215 {
216 
217 }
218 
219 //----------------------------------------------------------------------------//
220 
221 template <typename Data_T>
223 {
224  m_lowestLevel = level;
225 }
226 
227 //----------------------------------------------------------------------------//
228 
229 template <typename Data_T>
231 {
232  this->metadata().setVecIntMetadata(detail::k_mipOffsetStr, offset);
233  m_mipOffset = offset;
234 }
235 
236 //----------------------------------------------------------------------------//
237 // Static member initialization
238 //----------------------------------------------------------------------------//
239 
241 
242 //----------------------------------------------------------------------------//
243 
245 
246 //----------------------------------------------------------------------------//
247 
248 #endif // Include guard
249 
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
LazyLoadAction::~LazyLoadAction
virtual ~LazyLoadAction()
Definition: MIPBase.h:80
V3i
Imath::V3i V3i
Definition: SpiMathLib.h:71
MIPBase::numLevels
size_t numLevels() const
Number of MIP levels.
Definition: MIPBase.h:174
Types.h
Contains typedefs for the commonly used types in Field3D.
MIPBase::class_type
MIPBase< Data_T > class_type
Definition: MIPBase.h:127
Field::Ptr
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:395
LazyLoadAction::Vec
std::vector< Ptr > Vec
Definition: MIPBase.h:78
MIPBase::setMIPOffset
void setMIPOffset(const V3i &offset)
Sets the base MIP offset. This is used to indicate where voxel space coordinate (0,...
Definition: MIPBase.h:230
MIPBase::lowestLevel
size_t lowestLevel() const
Lowest MIP level to use.
Definition: MIPBase.h:171
MIPBase::m_lowestLevel
size_t m_lowestLevel
The lowest MIP level to use. Defaults to 0, but can be set higher to prevent high resolution levels f...
Definition: MIPBase.h:199
V3f
Imath::V3f V3f
Definition: SpiMathLib.h:73
FieldBase::name
std::string name
Optional name of the field.
Definition: Field.h:171
RefCount.h
Contains base class for reference counting with Mutex.
MIPBase::mipValue
virtual Data_T mipValue(size_t level, int i, int j, int k) const =0
Read access to a voxel in a given MIP level.
ns.h
MIPBase::MIPBase
MIPBase()
Definition: MIPBase.h:213
LazyLoadAction::load
virtual Field_T::Ptr load() const =0
Performs the loading of the pre-determined field and returns a pointer to it.
MIPBase::mipOffset
const V3i & mipOffset() const
Returns the base MIP offset.
Definition: MIPBase.h:180
LazyLoadAction
Definition: MIPBase.h:72
detail::k_mipOffsetStr
FIELD3D_API const std::string k_mipOffsetStr
Definition: MIPUtil.cpp:66
MIPBase::Ptr
boost::intrusive_ptr< MIPBase > Ptr
Definition: MIPBase.h:123
MIPBase::base
Field< Data_T > base
Definition: MIPBase.h:191
MIPBase::ms_classType
static TemplatedFieldType< MIPBase< Data_T > > ms_classType
Definition: MIPBase.h:187
MIPBase::m_mipOffset
V3i m_mipOffset
Base coordinate offset. This is used to indicate where voxel space coordinate (0, 0,...
Definition: MIPBase.h:204
MIPBase::getVsMIPCoord
virtual void getVsMIPCoord(const V3f &vsP, const size_t level, V3f &outVsP) const =0
Given a voxel space coordinate in the 0-level field, computes the coordinate in another level.
MIPBase::staticClassName
static const char * staticClassName()
Definition: MIPBase.h:130
Field.h
Contains Field, WritableField and ResizableField classes.
MIPBase::m_numLevels
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:196
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(MIPBase)
MIPBase::mipLevel
virtual Field< Data_T >::Ptr mipLevel(const size_t level) const =0
Returns a MIP level field.
MIPBase
Definition: MIPBase.h:117
MIPBase::levelLoaded
virtual bool levelLoaded(const size_t level) const =0
Whether a given MIP level is loaded.
MIPBase::setLowestLevel
void setLowestLevel(size_t level)
Sets the lowest MIP level to use. Defaults to zero, but can be set higher to prevent high resolution ...
Definition: MIPBase.h:222
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
LazyLoadAction::Ptr
boost::shared_ptr< LazyLoadAction< Field_T > > Ptr
Definition: MIPBase.h:77
Field
Definition: Field.h:390
MIPBase::DEFINE_FIELD_RTTI_ABSTRACT_CLASS
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition: MIPBase.h:128
TemplatedFieldType
Used to return a string for the name of a templated field.
Definition: Traits.h:283
MIPUtil.h
Contains MIP-related utility functions.
MIPBase::mipResolution
virtual V3i mipResolution(size_t level) const =0
Returns the resolution of a given MIP level.
MIPBase::staticClassType
static const char * staticClassType()
Definition: MIPBase.h:135