00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _MbHexahedronTopologyExplicitIjk_H
00024 #define _MbHexahedronTopologyExplicitIjk_H
00025
00026 #ifdef _WIN32
00027 #pragma warning(push)
00028 #pragma warning(disable:4250)
00029 #pragma warning(disable:4251)
00030 #endif
00031
00032 #include <MeshVizXLM/mesh/topology/MiHexahedronTopologyExplicitIjk.h>
00033 #include <topology/MbTopologyIjk.h>
00034 #include <MbError.h>
00035
00036 #include <Inventor/SbTime.h>
00037 #include <Inventor/STL/limits>
00038
00039
00071 template <MiMeshIjk::StorageLayout layout = MiMeshIjk::LAYOUT_KJI>
00072 class MbHexahedronTopologyExplicitIjk : public MiHexahedronTopologyExplicitIjk, public MbTopologyIjk<layout>
00073 {
00074 public:
00078 MbHexahedronTopologyExplicitIjk(size_t numCellI, size_t numCellJ, size_t numCellK);
00079 MbHexahedronTopologyExplicitIjk(const MbHexahedronTopologyExplicitIjk& topology);
00080
00081 #ifdef MBMESH_DONT_USE_STL
00082 virtual ~MbHexahedronTopologyExplicitIjk();
00083 #endif
00084
00085
00090 virtual void getCellNodeIndices(size_t i, size_t j, size_t k, size_t& n0, size_t& n1, size_t& n2, size_t& n3,
00091 size_t& n4, size_t& n5, size_t& n6, size_t& n7) const;
00092 const size_t* getCellNodeIndicesBuffer(size_t i, size_t j, size_t k) const;
00093
00094 virtual MiMeshIjk::StorageLayout getStorageLayout() const { return layout; }
00095
00096 size_t getBeginNodeId() const;
00097
00104 size_t getEndNodeId() const;
00105
00109 size_t getNumCellsI() const { return this->m_numI; }
00110
00114 size_t getNumCellsJ() const { return this->m_numJ; }
00115
00119 size_t getNumCellsK() const { return this->m_numK; }
00120
00127 bool isDead(size_t i, size_t j, size_t k) const
00128 {
00129 return MbTopologyIjk<layout>::isDead(i,j,k);
00130 }
00131
00135 virtual void setCellNodeIndices(size_t i, size_t j, size_t k,
00136 const size_t* beginId, const size_t* endId);
00137
00141 size_t getNumCells() const;
00142
00143 private:
00147 virtual std::ostream& toStream(std::ostream& s) const;
00148
00149 #ifndef MBMESH_DONT_USE_STL
00150 std::vector<size_t> m_indices;
00151 #else
00152 size_t* m_indices;
00153 #endif
00154
00155 size_t m_beginNodeId;
00156 size_t m_endNodeId;
00157
00158 #ifdef MBMESH_DATA_ACCESS_MICROSLEEP
00159 public:
00160 static size_t s_microsleep;
00161 #endif
00162 };
00163
00164
00165 template <MiMeshIjk::StorageLayout layout>
00166 inline
00167 MbHexahedronTopologyExplicitIjk<layout>::MbHexahedronTopologyExplicitIjk(size_t numCellI, size_t numCellJ, size_t numCellK)
00168 : MiHexahedronTopologyExplicitIjk()
00169 , MbTopologyIjk<layout>(numCellI,numCellJ,numCellK)
00170 , m_beginNodeId(0)
00171 , m_endNodeId(0)
00172 {
00173 m_beginNodeId = std::numeric_limits<size_t>::max();
00174 #ifndef MBMESH_DONT_USE_STL
00175 m_indices.resize(getNumCells()*8);
00176 #else
00177 m_indices = new size_t[getNumCells()*8];
00178 #endif
00179 }
00180
00181
00182 #ifdef MBMESH_DONT_USE_STL
00183 template <MiMeshIjk::StorageLayout layout>
00184 inline
00185 MbHexahedronTopologyExplicitIjk<layout>::~MbHexahedronTopologyExplicitIjk()
00186 {
00187 delete[] m_indices;
00188 }
00189 #endif
00190
00191
00192 template <MiMeshIjk::StorageLayout layout>
00193 #ifndef MBMESH_DONT_USE_STL
00194 inline
00195 MbHexahedronTopologyExplicitIjk<layout>::MbHexahedronTopologyExplicitIjk(const MbHexahedronTopologyExplicitIjk& topology)
00196 : MiTopology(), MiHexahedronTopologyExplicitIjk()
00197 , MbTopologyIjk<layout>(topology)
00198 , m_indices(topology.m_indices)
00199 , m_beginNodeId(topology.m_beginNodeId)
00200 , m_endNodeId(topology.m_endNodeId)
00201 {
00202 }
00203 #else
00204 inline
00205 MbHexahedronTopologyExplicitIjk<layout>::MbHexahedronTopologyExplicitIjk(const MbHexahedronTopologyExplicitIjk& topology)
00206 : MiTopology(), MiHexahedronTopologyExplicitIjk()
00207 , MbTopologyIjk<>(topology)
00208 , m_beginNodeId(topology.m_beginNodeId)
00209 , m_endNodeId(topology.m_endNodeId)
00210 {
00211 m_indices = new size_t[m_endNodeId];
00212 for (size_t i=m_beginNodeId; i!=m_endNodeId; ++i)
00213 m_indices[i] = topology.m_indices[i];
00214 }
00215 #endif
00216
00217
00218
00219
00220 template <MiMeshIjk::StorageLayout layout>
00221 inline size_t
00222 MbHexahedronTopologyExplicitIjk<layout>::getNumCells() const
00223 {
00224 return this->m_numK*this->m_numI*this->m_numJ;
00225 }
00226
00227
00228 template <MiMeshIjk::StorageLayout layout>
00229 inline
00230 void
00231 MbHexahedronTopologyExplicitIjk<layout>::getCellNodeIndices(size_t i, size_t j, size_t k, size_t& n0, size_t& n1, size_t& n2, size_t& n3,
00232 size_t& n4, size_t& n5, size_t& n6, size_t& n7) const
00233 {
00234 const size_t *it = this->getCellNodeIndicesBuffer(i,j,k);
00235 n0 = *it++;
00236 n1 = *it++;
00237 n2 = *it++;
00238 n3 = *it++;
00239 n4 = *it++;
00240 n5 = *it++;
00241 n6 = *it++;
00242 n7 = *it;
00243 }
00244
00245
00246 template <MiMeshIjk::StorageLayout layout>
00247 inline const size_t*
00248 MbHexahedronTopologyExplicitIjk<layout>::getCellNodeIndicesBuffer(size_t i, size_t j, size_t k) const
00249 {
00250 #ifndef MBMESH_DONT_USE_ASSERT
00251 if (hasDeadCells() && isDead(i,j,k))
00252 throw MbError("accessing dead cells");
00253 #endif
00254
00255 #ifndef MBMESH_DONT_USE_STL
00256 const size_t *it = &m_indices.front();
00257 #else
00258 const size_t *it = m_indices;
00259 #endif
00260 it += this->getI(i,j,k) * 8;
00261
00262 #ifdef MBMESH_DATA_ACCESS_MICROSLEEP
00263 if (s_microsleep>0)
00264 SbTime::usleep(s_microsleep);
00265 #endif
00266
00267 return it;
00268 }
00269
00270
00271
00272 template <MiMeshIjk::StorageLayout layout>
00273 inline size_t
00274 MbHexahedronTopologyExplicitIjk<layout>::getBeginNodeId() const
00275 {
00276 if (m_endNodeId == 0)
00277 return 0;
00278 else
00279 return m_beginNodeId;
00280 }
00281
00282
00283 template <MiMeshIjk::StorageLayout layout>
00284 inline size_t
00285 MbHexahedronTopologyExplicitIjk<layout>::getEndNodeId() const
00286 {
00287 return m_endNodeId;
00288 }
00289
00290
00291 template <MiMeshIjk::StorageLayout layout>
00292 inline void
00293 MbHexahedronTopologyExplicitIjk<layout>::setCellNodeIndices(size_t i, size_t j, size_t k, const size_t* beginId, const size_t* endId)
00294 {
00295 #ifndef MBMESH_DONT_USE_ASSERT
00296 assert( std::distance(beginId,endId) == 8 );
00297 #endif
00298
00299 #ifndef MBMESH_DONT_USE_STL
00300 std::vector<size_t>::iterator index = m_indices.begin() + (this->getI(i,j,k) * 8);
00301 #else
00302 size_t* index= m_indices + (this->getI(i,j,k) * 8);
00303 #endif
00304
00305 size_t nodeId;
00306 for (const size_t* it = beginId; it != endId; ++it,++index)
00307 {
00308 nodeId = *it;
00309 if (nodeId >= m_endNodeId)
00310 m_endNodeId = nodeId + 1;
00311 if (nodeId < m_beginNodeId)
00312 m_beginNodeId = nodeId;
00313 *index = nodeId;
00314 }
00315 this->m_timeStamp = MxTimeStamp::getTimeStamp();
00316 }
00317
00318
00319 template <MiMeshIjk::StorageLayout layout>
00320 inline std::ostream&
00321 MbHexahedronTopologyExplicitIjk<layout>::toStream(std::ostream& s) const
00322 {
00323 s << "#Hexahedron topology explicitIjk " << std::endl;
00324 s << "# num cells" << std::endl;
00325 s << getNumCells() << std::endl;
00326
00327 for(size_t i=0; i<this->m_numI; i++)
00328 for(size_t j=0; j<this->m_numJ; j++)
00329 for(size_t k=0; k<this->m_numK; k++)
00330 {
00331 s << "# cell #("<<i<<","<<j<<","<<k<<")";
00332 if (hasDeadCells() && isDead(i,j,k))
00333 s <<"(dead)";
00334 s << std::endl << "( ";
00335 size_t pos = this->getI(i,j,k) * 8;
00336 for (size_t n = 0; n < 8; ++n)
00337 s << m_indices[pos + n] << " ";
00338 s << ")" << std::endl;
00339 }
00340 return s;
00341 }
00342
00343 #ifdef _WIN32
00344 #pragma warning(pop)
00345 #endif
00346
00347 #endif
00348
00349
00350