Field3D
|
00001 //----------------------------------------------------------------------------// 00002 00003 /* 00004 * Copyright (c) 2009 Sony Pictures Imageworks Inc 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. Neither the name of Sony Pictures Imageworks nor the 00018 * names of its contributors may be used to endorse or promote 00019 * products derived from this software without specific prior written 00020 * permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00028 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00031 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00032 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00033 * OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 //----------------------------------------------------------------------------// 00037 00042 //----------------------------------------------------------------------------// 00043 00044 #ifndef _INCLUDED_Field3D_EmptyField_H_ 00045 #define _INCLUDED_Field3D_EmptyField_H_ 00046 00047 #include <vector> 00048 00049 #include <boost/lexical_cast.hpp> 00050 00051 #include "Field.h" 00052 00053 //----------------------------------------------------------------------------// 00054 00055 #include "ns.h" 00056 00057 FIELD3D_NAMESPACE_OPEN 00058 00059 //----------------------------------------------------------------------------// 00060 00061 // gets rid of warnings 00062 #define UNUSED(p) ((p)=(p)) 00063 00064 //----------------------------------------------------------------------------// 00065 00078 //----------------------------------------------------------------------------// 00079 00080 template <class Data_T> 00081 class EmptyField 00082 : public ResizableField<Data_T> 00083 { 00084 public: 00085 00086 // Typedefs ------------------------------------------------------------------ 00087 00088 typedef boost::intrusive_ptr<EmptyField> Ptr; 00089 typedef std::vector<Ptr> Vec; 00090 00091 // Constructors -------------------------------------------------------------- 00092 00095 00097 EmptyField(); 00098 00099 // \} 00100 00101 // Main methods -------------------------------------------------------------- 00102 00104 virtual void clear(const Data_T &value); 00105 00107 const Data_T& constantvalue() const; 00109 void setConstantvalue(const Data_T &val); 00110 00111 // From Field base class ------------------------------------------------- 00112 00115 virtual Data_T value(int i, int j, int k) const; 00116 virtual long long int memSize() const; 00118 00119 // RTTI replacement ---------------------------------------------------------- 00120 00121 typedef EmptyField<Data_T> class_type; 00122 DEFINE_FIELD_RTTI_CONCRETE_CLASS 00123 00125 static const char *classType() 00126 { 00127 return "EmptyField"; 00128 } 00129 00130 // From WritableField base class ----------------------------------------- 00131 00134 virtual Data_T& lvalue(int i, int j, int k); 00136 00137 // From FieldBase ------------------------------------------------------------ 00138 00141 00142 virtual std::string className() const 00143 { return std::string(classType()); } 00144 00145 virtual FieldBase::Ptr clone() const 00146 { return Ptr(new EmptyField(*this)); } 00147 00149 00150 protected: 00151 00152 // Data members -------------------------------------------------------------- 00153 00155 Data_T m_default; 00157 Data_T m_ignoredData; 00159 Data_T m_constantData; 00160 00161 private: 00162 00163 // Typedefs ------------------------------------------------------------------ 00164 00165 typedef ResizableField<Data_T> base; 00166 00167 }; 00168 00169 //----------------------------------------------------------------------------// 00170 // EmptyField implementations 00171 //----------------------------------------------------------------------------// 00172 00173 template <class Data_T> 00174 EmptyField<Data_T>::EmptyField() 00175 : base() 00176 { 00177 // Empty 00178 } 00179 00180 //----------------------------------------------------------------------------// 00181 00182 template <class Data_T> 00183 void EmptyField<Data_T>::clear(const Data_T &value) 00184 { 00185 m_constantData = m_default = value; 00186 } 00187 00188 //----------------------------------------------------------------------------// 00189 00190 template <class Data_T> 00191 Data_T EmptyField<Data_T>::value(int i, int j, int k) const 00192 { 00193 assert (i >= base::m_dataWindow.min.x); 00194 assert (i <= base::m_dataWindow.max.x); 00195 assert (j >= base::m_dataWindow.min.y); 00196 assert (j <= base::m_dataWindow.max.y); 00197 assert (k >= base::m_dataWindow.min.z); 00198 assert (k <= base::m_dataWindow.max.z); 00199 00200 UNUSED(i); 00201 UNUSED(j); 00202 UNUSED(k); 00203 00204 // Access data 00205 return m_default; 00206 } 00207 00208 //----------------------------------------------------------------------------// 00209 00210 template <class Data_T> 00211 long long int EmptyField<Data_T>::memSize() const 00212 { 00213 long long int superClassMemSize = base::memSize(); 00214 return sizeof(*this) + superClassMemSize; 00215 } 00216 00217 //----------------------------------------------------------------------------// 00218 00219 template <class Data_T> 00220 Data_T& EmptyField<Data_T>::lvalue(int i, int j, int k) 00221 { 00222 assert (i >= base::m_dataWindow.min.x); 00223 assert (i <= base::m_dataWindow.max.x); 00224 assert (j >= base::m_dataWindow.min.y); 00225 assert (j <= base::m_dataWindow.max.y); 00226 assert (k >= base::m_dataWindow.min.z); 00227 assert (k <= base::m_dataWindow.max.z); 00228 00229 UNUSED(i); 00230 UNUSED(j); 00231 UNUSED(k); 00232 00233 // Access data 00234 return m_ignoredData; 00235 } 00236 00237 //----------------------------------------------------------------------------// 00238 00239 template <class Data_T> 00240 inline void EmptyField<Data_T>::setConstantvalue(const Data_T &val) 00241 { 00242 m_constantData = val; 00243 } 00244 00245 //----------------------------------------------------------------------------// 00246 00247 template <class Data_T> 00248 inline const Data_T& EmptyField<Data_T>::constantvalue() const 00249 { 00250 return m_constantData; 00251 } 00252 00253 //----------------------------------------------------------------------------// 00254 // Typedefs 00255 //----------------------------------------------------------------------------// 00256 00257 typedef EmptyField<float> Proxy; 00258 typedef EmptyField<float>::Ptr ProxyPtr; 00259 typedef std::vector<ProxyPtr> Proxies; 00260 00261 //----------------------------------------------------------------------------// 00262 00263 FIELD3D_NAMESPACE_HEADER_CLOSE 00264 00265 //----------------------------------------------------------------------------// 00266 00267 #undef UNUSED 00268 00269 //----------------------------------------------------------------------------// 00270 00271 #endif // Include guard