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 "RefCount.h"
50 #include "Types.h"
51 
52 //----------------------------------------------------------------------------//
53 
54 #include "ns.h"
55 
57 
58 //----------------------------------------------------------------------------//
59 // LazyLoadAction
60 //----------------------------------------------------------------------------//
61 
67 //----------------------------------------------------------------------------//
68 
69 template <class Field_T>
71 {
72 public:
73 
74  // Typedefs ------------------------------------------------------------------
75 
76  typedef boost::shared_ptr<LazyLoadAction<Field_T> > Ptr;
77  typedef std::vector<Ptr> Vec;
78 
79  virtual ~LazyLoadAction()
80  { }
81 
82  // To be implemented by subclasses -------------------------------------------
83 
86  virtual typename Field_T::Ptr load() const = 0;
87 
88 };
89 
90 //----------------------------------------------------------------------------//
91 // MIPBase
92 //----------------------------------------------------------------------------//
93 
112 //----------------------------------------------------------------------------//
113 
114 template <class Data_T>
115 class MIPBase : public Field<Data_T>
116 {
117 
118 public:
119 
120  // Typedefs ------------------------------------------------------------------
121 
122  typedef boost::intrusive_ptr<MIPBase> Ptr;
123 
124  // RTTI replacement ----------------------------------------------------------
125 
128 
129  static const char *staticClassName()
130  {
131  return "MIPBase";
132  }
133 
134  static const char* staticClassType()
135  {
137  }
138 
139  // Constructors --------------------------------------------------------------
140 
141  MIPBase();
142 
143  // To be implemented by subclasses -------------------------------------------
144 
147  virtual Data_T mipValue(size_t level, int i, int j, int k) const = 0;
148 
150  virtual V3i mipResolution(size_t level) const = 0;
151 
153  virtual bool levelLoaded(const size_t level) const = 0;
154 
157  virtual void getVsMIPCoord(const V3f &vsP, const size_t level,
158  V3f &outVsP) const = 0;
159 
161  virtual typename Field<Data_T>::Ptr mipLevel(const size_t level) const = 0;
162 
163 
164  // Main methods --------------------------------------------------------------
165 
168  void setLowestLevel(size_t level);
170  size_t lowestLevel() const
171  { return m_lowestLevel; }
173  size_t numLevels() const
174  { return m_numLevels; }
175 
176 protected:
177 
178  // Static data members -------------------------------------------------------
179 
181 
182  // Typedefs ------------------------------------------------------------------
183 
185 
186  // Data members --------------------------------------------------------------
187 
189  size_t m_numLevels;
193 
194 };
195 
196 //----------------------------------------------------------------------------//
197 // MIPBase implementations
198 //----------------------------------------------------------------------------//
199 
200 template <typename Data_T>
202  : m_numLevels(1), m_lowestLevel(0)
203 {
204 
205 }
206 
207 //----------------------------------------------------------------------------//
208 
209 template <typename Data_T>
211 {
212  m_lowestLevel = level;
213 }
214 
215 //----------------------------------------------------------------------------//
216 // Static member initialization
217 //----------------------------------------------------------------------------//
218 
220 
221 //----------------------------------------------------------------------------//
222 
224 
225 //----------------------------------------------------------------------------//
226 
227 #endif // Include guard
228 
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
Contains typedefs for the commonly used types in Field3D.
Contains base class for reference counting with Mutex.
Definition: Field.h:394
size_t numLevels() const
Number of MIP levels.
Definition: MIPBase.h:173
size_t lowestLevel() const
Lowest MIP level to use.
Definition: MIPBase.h:170
Imath::V3i V3i
Definition: SpiMathLib.h:71
Field< Data_T > base
Definition: MIPBase.h:184
boost::intrusive_ptr< MIPBase > Ptr
Definition: MIPBase.h:122
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:192
static TemplatedFieldType< MIPBase< Data_T > > ms_classType
Definition: MIPBase.h:180
Imath::V3f V3f
Definition: SpiMathLib.h:73
FIELD3D_CLASSTYPE_TEMPL_INSTANTIATION(MIPBase)
Used to return a string for the name of a templated field.
Definition: Traits.h:116
static const char * staticClassName()
Definition: MIPBase.h:129
boost::shared_ptr< LazyLoadAction< Field_T > > Ptr
Definition: MIPBase.h:76
size_t m_numLevels
Number of MIP levels. The default is 1.
Definition: MIPBase.h:189
MIPBase()
Definition: MIPBase.h:201
Contains Field, WritableField and ResizableField classes.
std::vector< Ptr > Vec
Definition: MIPBase.h:77
DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Definition: MIPBase.h:127
FIELD3D_API V3i mipResolution(const V3i &baseRes, const size_t level)
Definition: MIPUtil.cpp:66
MIPBase< Data_T > class_type
Definition: MIPBase.h:126
virtual ~LazyLoadAction()
Definition: MIPBase.h:79
static const char * staticClassType()
Definition: MIPBase.h:134
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:210
virtual Field_T::Ptr load() const =0
Performs the loading of the pre-determined field and returns a pointer to it.
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:400
std::string name
Optional name of the field.
Definition: Field.h:176