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 00043 //----------------------------------------------------------------------------// 00044 00045 #include "Hdf5Util.h" 00046 00047 #include "FieldMappingIO.h" 00048 00049 //----------------------------------------------------------------------------// 00050 00051 FIELD3D_NAMESPACE_OPEN 00052 00053 //----------------------------------------------------------------------------// 00054 // Field3D namespaces 00055 //----------------------------------------------------------------------------// 00056 00057 using namespace std; 00058 using namespace Exc; 00059 using namespace Hdf5Util; 00060 00061 //----------------------------------------------------------------------------// 00062 00063 namespace { 00065 const string k_nullMappingName("NullFieldMapping"); 00067 const string k_matrixMappingName("MatrixFieldMapping"); 00068 00069 const string k_nullMappingDataName("NullFieldMapping data"); 00070 const string k_matrixMappingDataName("MatrixFieldMapping data"); 00071 } 00072 00073 //----------------------------------------------------------------------------// 00074 00075 FieldMapping::Ptr 00076 NullFieldMappingIO::read(hid_t mappingGroup) 00077 { 00078 string nfmData; 00079 if (!readAttribute(mappingGroup, k_nullMappingDataName, nfmData)) { 00080 Msg::print(Msg::SevWarning, "Couldn't read attribute " + k_nullMappingDataName); 00081 return NullFieldMapping::Ptr(); 00082 } 00083 return NullFieldMapping::Ptr(new NullFieldMapping); 00084 } 00085 00086 //----------------------------------------------------------------------------// 00087 00088 bool 00089 NullFieldMappingIO::write(hid_t mappingGroup, FieldMapping::Ptr /* nm */) 00090 { 00091 string nfmAttrData("NullFieldMapping has no data"); 00092 if (!writeAttribute(mappingGroup, k_nullMappingDataName, nfmAttrData)) { 00093 Msg::print(Msg::SevWarning, "Couldn't add attribute " + k_nullMappingDataName); 00094 return false; 00095 } 00096 return true; 00097 } 00098 00099 //----------------------------------------------------------------------------// 00100 00102 std::string NullFieldMappingIO::className() const 00103 { return k_nullMappingName; } 00104 00105 //----------------------------------------------------------------------------// 00106 00107 FieldMapping::Ptr 00108 MatrixFieldMappingIO::read(hid_t mappingGroup) 00109 { 00110 M44d mtx; 00111 00112 if (!readAttribute(mappingGroup, k_matrixMappingDataName, 16, 00113 mtx.x[0][0])) { 00114 Msg::print(Msg::SevWarning, "Couldn't read attribute " + k_matrixMappingDataName); 00115 return MatrixFieldMapping::Ptr(); 00116 } 00117 00118 MatrixFieldMapping::Ptr mm(new MatrixFieldMapping); 00119 00120 mm->setLocalToWorld(mtx); 00121 00122 return mm; 00123 } 00124 00125 //----------------------------------------------------------------------------// 00126 00127 bool 00128 MatrixFieldMappingIO::write(hid_t mappingGroup, FieldMapping::Ptr mapping) 00129 { 00130 MatrixFieldMapping::Ptr mm = 00131 boost::dynamic_pointer_cast<MatrixFieldMapping>(mapping); 00132 if (!mm) { 00133 Msg::print(Msg::SevWarning, "Couldn't get MatrixFieldMapping from pointer"); 00134 return false; 00135 } 00136 if (!writeAttribute(mappingGroup, k_matrixMappingDataName, 16, 00137 mm->localToWorld().x[0][0])) { 00138 Msg::print(Msg::SevWarning, "Couldn't add attribute " + k_matrixMappingDataName); 00139 return false; 00140 } 00141 00142 return true; 00143 } 00144 00145 //----------------------------------------------------------------------------// 00146 00148 std::string MatrixFieldMappingIO::className() const 00149 { return k_matrixMappingName; } 00150 00151 //----------------------------------------------------------------------------// 00152 00153 FIELD3D_NAMESPACE_SOURCE_CLOSE 00154 00155 //----------------------------------------------------------------------------//