HexahedronSetTopologyContainer.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 
00026 #include <sofa/component/topology/HexahedronSetTopologyContainer.h>
00027 #include <sofa/core/ObjectFactory.h>
00028 
00029 #include <sofa/component/MeshLoader.h>
00030 
00031 namespace sofa
00032 {
00033 namespace component
00034 {
00035 namespace topology
00036 {
00037     using namespace std;
00038     using namespace sofa::defaulttype;
00039 
00040   SOFA_DECL_CLASS(HexahedronSetTopologyContainer)
00041   int HexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container")
00042     .add< HexahedronSetTopologyContainer >()
00043     ;
00044 
00045     const unsigned int hexahedronEdgeArray[12][2]={{0,1},{0,3},{0,4},{1,2},{1,5},{2,3},{2,6},{3,7},{4,5},{4,7},{5,6},{6,7}};
00046 
00047     HexahedronSetTopologyContainer::HexahedronSetTopologyContainer()
00048     : QuadSetTopologyContainer()
00049     { }
00050 
00051 HexahedronSetTopologyContainer::HexahedronSetTopologyContainer(const sofa::helper::vector< Hexahedron > &hexahedra )
00052 : QuadSetTopologyContainer()
00053 , m_hexahedron( hexahedra )
00054 {
00055     for (unsigned int i=0; i<m_hexahedron.size(); ++i)
00056     {
00057         for(unsigned int j=0; j<8; ++j)
00058         {
00059             int a = m_hexahedron[i][j];
00060             if (a >= (int)nbPoints) nbPoints = a+1;
00061         }
00062     }
00063 }
00064 
00065 void HexahedronSetTopologyContainer::addHexa( int a, int b, int c, int d, int e, int f, int g, int h )
00066 {
00067   m_hexahedron.push_back(Hexahedron(a,b,c,d,e,f,g,h));
00068     if (a >= (int)nbPoints) nbPoints = a+1;
00069     if (b >= (int)nbPoints) nbPoints = b+1;
00070     if (c >= (int)nbPoints) nbPoints = c+1;
00071     if (d >= (int)nbPoints) nbPoints = d+1;
00072     if (e >= (int)nbPoints) nbPoints = e+1;
00073     if (f >= (int)nbPoints) nbPoints = f+1;
00074     if (g >= (int)nbPoints) nbPoints = g+1;
00075     if (h >= (int)nbPoints) nbPoints = h+1;
00076 }
00077 
00078     void HexahedronSetTopologyContainer::init()
00079     {
00080         QuadSetTopologyContainer::init();
00081     }
00082 
00083     void HexahedronSetTopologyContainer::loadFromMeshLoader(sofa::component::MeshLoader* loader)
00084     {
00085         // load points
00086         PointSetTopologyContainer::loadFromMeshLoader(loader);
00087         m_hexahedron = loader->getHexas();
00088     }
00089 
00090     void HexahedronSetTopologyContainer::createHexahedronSetArray()
00091     {
00092     #ifndef NDEBUG
00093         cout << "Error. [HexahedronSetTopologyContainer::createHexahedronSetArray] This method must be implemented by a child topology." << endl;
00094     #endif
00095     }
00096 
00097     void HexahedronSetTopologyContainer::createEdgeSetArray()
00098     {
00099         if(hasEdges())
00100         {
00101             EdgeSetTopologyContainer::clear();
00102 
00103             clearQuadEdges();
00104             clearQuadEdgeShell();
00105 
00106             clearHexahedronEdges();
00107             clearHexahedronEdgeShell();
00108         }
00109 
00110         // create a temporary map to find redundant edges
00111         std::map<Edge,unsigned int> edgeMap;
00112 
00114         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00115         {
00116             Hexahedron &t = m_hexahedron[i];
00117             for(unsigned int j=0; j<12; ++j) 
00118             { 
00119                 unsigned int v1 = t[hexahedronEdgeArray[j][0]];
00120                 unsigned int v2 = t[hexahedronEdgeArray[j][1]];
00121                 const Edge e((v1<v2) ? Edge(v1,v2) : Edge(v2,v1));
00122 
00123                 if(edgeMap.find(e)==edgeMap.end()) 
00124                 {
00125                     // edge not in edgeMap so create a new one
00126                     const int edgeIndex = edgeMap.size();
00127                     edgeMap[e] = edgeIndex;
00128                     m_edge.push_back(e);
00129                 } 
00130             }
00131         }
00132     }
00133 
00134     void HexahedronSetTopologyContainer::createHexahedronEdgeArray()
00135     {
00136         if(!hasEdges())
00137             createEdgeSetArray();
00138 
00139         if(hasHexahedronEdges())
00140             clearHexahedronEdges();
00141 
00142         m_hexahedronEdge.resize( getNumberOfHexahedra());
00143 
00144         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00145         {
00146             Hexahedron &t = m_hexahedron[i];
00147 
00148             // adding edge i in the edge shell of both points
00149             for(unsigned int j=0; j<12; ++j) 
00150             { 
00151                 const int edgeIndex = getEdgeIndex(t[hexahedronEdgeArray[j][0]],
00152                                                     t[hexahedronEdgeArray[j][1]]);
00153                 m_hexahedronEdge[i][j] = edgeIndex; 
00154             }
00155         }
00156     }
00157 
00158     void HexahedronSetTopologyContainer::createQuadSetArray()
00159     {
00160         if(hasQuads())
00161         {
00162             QuadSetTopologyContainer::clear();
00163             clearQuads();
00164             clearHexahedronQuads();
00165             clearHexahedronQuadShell();
00166         }
00167 
00168         // create a temporary map to find redundant quads
00169         std::map<Quad,unsigned int> quadMap;
00170 
00171         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00172         {
00173             Hexahedron &h = m_hexahedron[i];
00174 
00175             unsigned int v[4], val;
00176 
00177             // Quad 0 :
00178             v[0]=h[0]; 
00179             v[1]=h[3]; 
00180             v[2]=h[2]; 
00181             v[3]=h[1];
00182 
00183             // sort v such that v[0] is the smallest one 
00184             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00185             {
00186                 val = v[0]; 
00187                 v[0]=v[1];
00188                 v[1]=v[2];
00189                 v[2]=v[3];
00190                 v[3]=val;
00191             }
00192 
00193             // sort vertices in lexicographics order
00194             int quadIndex;
00195             Quad qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00196             std::map<Quad,unsigned int>::iterator itt = quadMap.find(qu);
00197             if(itt==quadMap.end()) 
00198             {
00199                 // quad not in edgeMap so create a new one
00200                 quadIndex=m_quad.size();
00201                 quadMap[qu]=quadIndex;
00202                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00203                 quadMap[qu]=quadIndex;
00204                 m_quad.push_back(qu);
00205             } 
00206 
00207             // Quad 1 :
00208             v[0]=h[4]; 
00209             v[1]=h[5]; 
00210             v[2]=h[6]; 
00211             v[3]=h[7];
00212             // sort v such that v[0] is the smallest one 
00213             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00214             {
00215                 val=v[0]; 
00216                 v[0]=v[1];
00217                 v[1]=v[2];
00218                 v[2]=v[3];
00219                 v[3]=val;
00220             }
00221             // sort vertices in lexicographics order
00222             qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00223             itt=quadMap.find(qu);
00224             if(itt==quadMap.end()) 
00225             {
00226                 // quad not in edgeMap so create a new one
00227                 quadIndex=m_quad.size();
00228                 quadMap[qu]=quadIndex;
00229                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00230                 quadMap[qu]=quadIndex;
00231                 m_quad.push_back(qu);
00232             } 
00233 
00234             // Quad 2 :
00235             v[0]=h[0]; v[1]=h[1]; v[2]=h[5]; v[3]=h[4];
00236             // sort v such that v[0] is the smallest one 
00237             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00238             {
00239                 val=v[0]; 
00240                 v[0]=v[1];
00241                 v[1]=v[2];
00242                 v[2]=v[3];
00243                 v[3]=val;
00244             }
00245             // sort vertices in lexicographics order
00246             qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00247             itt=quadMap.find(qu);
00248             if(itt==quadMap.end()) 
00249             {
00250                 // quad not in edgeMap so create a new one
00251                 quadIndex=m_quad.size();
00252                 quadMap[qu]=quadIndex;
00253                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00254                 quadMap[qu]=quadIndex;
00255                 m_quad.push_back(qu);
00256             } 
00257 
00258             // Quad 3 :
00259             v[0]=h[1]; v[1]=h[2]; v[2]=h[6]; v[3]=h[5];
00260             // sort v such that v[0] is the smallest one 
00261             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00262             {
00263                 val=v[0]; 
00264                 v[0]=v[1];
00265                 v[1]=v[2];
00266                 v[2]=v[3];
00267                 v[3]=val;
00268             }
00269             // sort vertices in lexicographics order
00270             qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00271             itt=quadMap.find(qu);
00272             if(itt==quadMap.end()) 
00273             {
00274                 // quad not in edgeMap so create a new one
00275                 quadIndex=m_quad.size();
00276                 quadMap[qu]=quadIndex;
00277                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00278                 quadMap[qu]=quadIndex;
00279                 m_quad.push_back(qu);
00280             } 
00281 
00282             // Quad 4 :
00283             v[0]=h[2]; 
00284             v[1]=h[3]; 
00285             v[2]=h[7]; 
00286             v[3]=h[6];
00287             // sort v such that v[0] is the smallest one 
00288             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00289             {
00290                 val=v[0]; 
00291                 v[0]=v[1];
00292                 v[1]=v[2];
00293                 v[2]=v[3];
00294                 v[3]=val;
00295             }
00296             // sort vertices in lexicographics order
00297             qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00298             itt=quadMap.find(qu);
00299             if(itt==quadMap.end()) 
00300             {
00301                 // quad not in edgeMap so create a new one
00302                 quadIndex=m_quad.size();
00303                 quadMap[qu]=quadIndex;
00304                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00305                 quadMap[qu]=quadIndex;
00306                 m_quad.push_back(qu);
00307             } 
00308 
00309             // Quad 5 :
00310             v[0]=h[3]; 
00311             v[1]=h[0]; 
00312             v[2]=h[4]; 
00313             v[3]=h[7];
00314             // sort v such that v[0] is the smallest one 
00315             while ((v[0]>v[1]) || (v[0]>v[2]) || (v[0]>v[3])) 
00316             {
00317                 val=v[0]; 
00318                 v[0]=v[1];
00319                 v[1]=v[2];
00320                 v[2]=v[3];
00321                 v[3]=val;
00322             }
00323             // sort vertices in lexicographics order
00324             qu=helper::make_array<unsigned int>(v[0],v[3],v[2],v[1]);
00325             itt=quadMap.find(qu);
00326             if(itt==quadMap.end()) 
00327             {
00328                 // quad not in edgeMap so create a new one
00329                 quadIndex=m_quad.size();
00330                 quadMap[qu]=quadIndex;
00331                 qu=helper::make_array<unsigned int>(v[0],v[1],v[2],v[3]);
00332                 quadMap[qu]=quadIndex;
00333                 m_quad.push_back(qu);
00334             } 
00335         }
00336     }
00337 
00338     void HexahedronSetTopologyContainer::createHexahedronQuadArray()
00339     {
00340         if(!hasQuads()) 
00341             createQuadSetArray();
00342 
00343         if(hasHexahedronQuads())
00344             clearHexahedronQuads();
00345 
00346         m_hexahedronQuad.resize( getNumberOfHexahedra());
00347 
00348         for(unsigned int i = 0; i < m_hexahedron.size(); ++i)
00349         {
00350             Hexahedron &h=m_hexahedron[i];
00351             int quadIndex;
00352 
00353             // adding the 6 quads in the quad list of the ith hexahedron  i
00354             // Quad 0 :
00355             quadIndex=getQuadIndex(h[0],h[3],h[2],h[1]);
00356             assert(quadIndex!= -1);
00357             m_hexahedronQuad[i][0]=quadIndex; 
00358             // Quad 1 :
00359             quadIndex=getQuadIndex(h[4],h[5],h[6],h[7]);
00360             assert(quadIndex!= -1);
00361             m_hexahedronQuad[i][1]=quadIndex; 
00362             // Quad 2 :
00363             quadIndex=getQuadIndex(h[0],h[1],h[5],h[4]);
00364             assert(quadIndex!= -1);
00365             m_hexahedronQuad[i][2]=quadIndex; 
00366             // Quad 3 :
00367             quadIndex=getQuadIndex(h[1],h[2],h[6],h[5]);
00368             assert(quadIndex!= -1);
00369             m_hexahedronQuad[i][3]=quadIndex; 
00370             // Quad 4 :
00371             quadIndex=getQuadIndex(h[2],h[3],h[7],h[6]);
00372             assert(quadIndex!= -1);
00373             m_hexahedronQuad[i][4]=quadIndex; 
00374             // Quad 5 :
00375             quadIndex=getQuadIndex(h[3],h[0],h[4],h[7]);
00376             assert(quadIndex!= -1);
00377             m_hexahedronQuad[i][5]=quadIndex; 
00378         }
00379     }
00380 
00381     void HexahedronSetTopologyContainer::createHexahedronVertexShellArray()
00382     {
00383         if(hasHexahedronVertexShell())
00384             clearHexahedronVertexShell();
00385 
00386         m_hexahedronVertexShell.resize( getNbPoints() );
00387 
00388         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00389         {
00390             // adding vertex i in the vertex shell
00391             for(unsigned int j=0; j<8; ++j) 
00392                 m_hexahedronVertexShell[ m_hexahedron[i][j]  ].push_back( i );
00393         }
00394     }
00395 
00396     void HexahedronSetTopologyContainer::createHexahedronEdgeShellArray ()
00397     {
00398         if(!hasHexahedronEdges())
00399             createHexahedronEdgeArray();
00400 
00401         if(hasHexahedronEdgeShell())
00402             clearHexahedronEdgeShell();
00403 
00404         m_hexahedronEdgeShell.resize(getNumberOfEdges());
00405 
00406         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00407         {
00408             // adding edge i in the edge shell
00409             for(unsigned int j=0; j<12; ++j) 
00410             { 
00411                 m_hexahedronEdgeShell[ m_hexahedronEdge[i][j] ].push_back( i );
00412             }
00413         }
00414     }
00415 
00416     void HexahedronSetTopologyContainer::createHexahedronQuadShellArray()
00417     {
00418         if(!hasHexahedronQuads())
00419             createHexahedronQuadArray();
00420 
00421         if(hasHexahedronQuadShell())
00422             clearHexahedronQuadShell();
00423 
00424         m_hexahedronQuadShell.resize( getNumberOfQuads());
00425 
00426         for(unsigned int i=0; i<m_hexahedron.size(); ++i)
00427         {
00428             // adding quad i in the edge shell of both points
00429             for(unsigned int j=0; j<6; ++j) 
00430             { 
00431                 m_hexahedronQuadShell[ m_hexahedronQuad[i][j] ].push_back( i );
00432             }
00433         }
00434     }
00435 
00436     const sofa::helper::vector<Hexahedron> &HexahedronSetTopologyContainer::getHexahedronArray()
00437     {
00438         if(!hasHexahedra() && getNbPoints()>0)
00439         {
00440     #ifndef NDEBUG
00441             cout << "Warning. [HexahedronSetTopologyContainer::getHexahedronArray] creating hexahedron array." << endl;
00442     #endif
00443             createHexahedronSetArray();
00444         }
00445 
00446         return m_hexahedron;
00447     }
00448 
00449     int HexahedronSetTopologyContainer::getHexahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4, 
00450                                                             PointID v5, PointID v6, PointID v7, PointID v8)
00451     {
00452         if(!hasHexahedronVertexShell())
00453             createHexahedronVertexShellArray();
00454 
00455         sofa::helper::vector<unsigned int> set1 = getHexahedronVertexShell(v1);
00456         sofa::helper::vector<unsigned int> set2 = getHexahedronVertexShell(v2);
00457         sofa::helper::vector<unsigned int> set3 = getHexahedronVertexShell(v3);
00458         sofa::helper::vector<unsigned int> set4 = getHexahedronVertexShell(v4);
00459         sofa::helper::vector<unsigned int> set5 = getHexahedronVertexShell(v5);
00460         sofa::helper::vector<unsigned int> set6 = getHexahedronVertexShell(v6);
00461         sofa::helper::vector<unsigned int> set7 = getHexahedronVertexShell(v7);
00462         sofa::helper::vector<unsigned int> set8 = getHexahedronVertexShell(v8);
00463 
00464         sort(set1.begin(), set1.end());
00465         sort(set2.begin(), set2.end());
00466         sort(set3.begin(), set3.end());
00467         sort(set4.begin(), set4.end());
00468         sort(set5.begin(), set5.end());
00469         sort(set6.begin(), set6.end());
00470         sort(set7.begin(), set7.end());
00471         sort(set8.begin(), set8.end());
00472 
00473         // The destination vector must be large enough to contain the result.
00474         sofa::helper::vector<unsigned int> out1(set1.size()+set2.size());
00475         sofa::helper::vector<unsigned int>::iterator result1;
00476         result1 = std::set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),out1.begin());
00477         out1.erase(result1,out1.end());
00478 
00479         sofa::helper::vector<unsigned int> out2(set3.size()+out1.size());
00480         sofa::helper::vector<unsigned int>::iterator result2;
00481         result2 = std::set_intersection(set3.begin(),set3.end(),out1.begin(),out1.end(),out2.begin());
00482         out2.erase(result2,out2.end());
00483 
00484         sofa::helper::vector<unsigned int> out3(set4.size()+out2.size());
00485         sofa::helper::vector<unsigned int>::iterator result3;
00486         result3 = std::set_intersection(set4.begin(),set4.end(),out2.begin(),out2.end(),out3.begin());
00487         out3.erase(result3,out3.end());
00488 
00489         sofa::helper::vector<unsigned int> out4(set5.size()+out3.size());
00490         sofa::helper::vector<unsigned int>::iterator result4;
00491         result4 = std::set_intersection(set5.begin(),set5.end(),out3.begin(),out3.end(),out4.begin());
00492         out4.erase(result4,out4.end());
00493 
00494         sofa::helper::vector<unsigned int> out5(set6.size()+out4.size());
00495         sofa::helper::vector<unsigned int>::iterator result5;
00496         result5 = std::set_intersection(set6.begin(),set6.end(),out4.begin(),out4.end(),out5.begin());
00497         out5.erase(result5,out5.end());
00498 
00499         sofa::helper::vector<unsigned int> out6(set7.size()+out5.size());
00500         sofa::helper::vector<unsigned int>::iterator result6;
00501         result6 = std::set_intersection(set7.begin(),set7.end(),out5.begin(),out5.end(),out6.begin());
00502         out6.erase(result6,out6.end());
00503 
00504         sofa::helper::vector<unsigned int> out7(set8.size()+out6.size());
00505         sofa::helper::vector<unsigned int>::iterator result7;
00506         result7 = std::set_intersection(set8.begin(),set8.end(),out6.begin(),out6.end(),out7.begin());
00507         out7.erase(result7,out7.end());
00508 
00509         assert(out7.size()==0 || out7.size()==1);
00510         if(out7.size()==1)
00511             return (int) (out7[0]);
00512         else
00513             return -1;
00514     }
00515 
00516     const Hexahedron &HexahedronSetTopologyContainer::getHexahedron(const unsigned int i)
00517     {
00518         if(!hasHexahedra())
00519             createHexahedronSetArray();
00520 
00521         return m_hexahedron[i];
00522     }
00523 
00524     unsigned int HexahedronSetTopologyContainer::getNumberOfHexahedra() const
00525     {
00526         return m_hexahedron.size();
00527     }
00528 
00529     const sofa::helper::vector< sofa::helper::vector<unsigned int> > &HexahedronSetTopologyContainer::getHexahedronVertexShellArray() 
00530     {
00531         if(!hasHexahedronVertexShell())
00532             createHexahedronVertexShellArray();
00533 
00534         return m_hexahedronVertexShell;
00535     }
00536 
00537     const sofa::helper::vector< sofa::helper::vector<unsigned int> > &HexahedronSetTopologyContainer::getHexahedronEdgeShellArray() 
00538     {
00539         if(!hasHexahedronEdgeShell())
00540             createHexahedronEdgeShellArray();
00541 
00542         return m_hexahedronEdgeShell;
00543     }
00544 
00545     const sofa::helper::vector< sofa::helper::vector<unsigned int> > &HexahedronSetTopologyContainer::getHexahedronQuadShellArray() 
00546     {
00547         if(!hasHexahedronQuadShell())
00548             createHexahedronQuadShellArray();
00549 
00550         return m_hexahedronQuadShell;
00551     }
00552 
00553     const sofa::helper::vector< HexahedronEdges> &HexahedronSetTopologyContainer::getHexahedronEdgeArray() 
00554     {
00555         if(!hasHexahedronEdges())
00556             createHexahedronEdgeArray();
00557 
00558         return m_hexahedronEdge;
00559     }
00560 
00561     Edge HexahedronSetTopologyContainer::getLocalHexahedronEdges (const unsigned int i) const 
00562     {
00563         assert(i<12);
00564         return Edge (hexahedronEdgeArray[i][0], hexahedronEdgeArray[i][1]);
00565     }
00566 
00567     const sofa::helper::vector< HexahedronQuads> &HexahedronSetTopologyContainer::getHexahedronQuadArray() 
00568     {
00569         if(!hasHexahedronQuads())
00570             createHexahedronQuadArray();
00571 
00572         return m_hexahedronQuad;
00573     }
00574 
00575     const sofa::helper::vector< unsigned int > &HexahedronSetTopologyContainer::getHexahedronVertexShell(const unsigned int i) 
00576     {
00577         if(!hasHexahedronVertexShell())
00578             createHexahedronVertexShellArray();
00579 
00580         assert(i < m_hexahedronVertexShell.size());
00581 
00582         return m_hexahedronVertexShell[i];
00583     }
00584 
00585     const sofa::helper::vector< unsigned int > &HexahedronSetTopologyContainer::getHexahedronEdgeShell(const unsigned int i) 
00586     {
00587         if(!hasHexahedronEdgeShell())
00588             createHexahedronEdgeShellArray();
00589 
00590         assert(i < m_hexahedronEdgeShell.size());
00591 
00592         return m_hexahedronEdgeShell[i];
00593     }
00594 
00595     const sofa::helper::vector< unsigned int > &HexahedronSetTopologyContainer::getHexahedronQuadShell(const unsigned int i) 
00596     {
00597         if(!hasHexahedronQuadShell())
00598             createHexahedronQuadShellArray();
00599 
00600         assert(i < m_hexahedronQuadShell.size());
00601 
00602         return m_hexahedronQuadShell[i];
00603     }
00604 
00605     const HexahedronEdges &HexahedronSetTopologyContainer::getHexahedronEdges(const unsigned int i) 
00606     {
00607         if(!hasHexahedronEdges())
00608             createHexahedronEdgeArray();
00609 
00610         assert(i < m_hexahedronEdge.size());
00611 
00612         return m_hexahedronEdge[i];
00613     }
00614 
00615     const HexahedronQuads &HexahedronSetTopologyContainer::getHexahedronQuads(const unsigned int i) 
00616     {
00617         if(!hasHexahedronQuads())
00618             createHexahedronQuadArray();
00619 
00620         assert(i < m_hexahedronQuad.size());
00621 
00622         return m_hexahedronQuad[i];
00623     }
00624 
00625     int HexahedronSetTopologyContainer::getVertexIndexInHexahedron(Hexahedron &t,unsigned int vertexIndex) const
00626     {
00627         if(t[0]==vertexIndex)
00628             return 0;
00629         else if(t[1]==vertexIndex)
00630             return 1;
00631         else if(t[2]==vertexIndex)
00632             return 2;
00633         else if(t[3]==vertexIndex)
00634             return 3;
00635         else if(t[4]==vertexIndex)
00636             return 4;
00637         else if(t[5]==vertexIndex)
00638             return 5;
00639         else if(t[6]==vertexIndex)
00640             return 6;
00641         else if(t[7]==vertexIndex)
00642             return 7;
00643         else 
00644             return -1;
00645     }
00646 
00647     int HexahedronSetTopologyContainer::getEdgeIndexInHexahedron(const HexahedronEdges &t,
00648                                                                  const unsigned int edgeIndex) const
00649     {
00650         if(t[0]==edgeIndex)
00651             return 0;
00652         else if(t[1]==edgeIndex)
00653             return 1;
00654         else if(t[2]==edgeIndex)
00655             return 2;
00656         else if(t[3]==edgeIndex)
00657             return 3;
00658         else if(t[4]==edgeIndex)
00659             return 4;
00660         else if(t[5]==edgeIndex)
00661             return 5;
00662         else if(t[6]==edgeIndex)
00663             return 6;
00664         else if(t[7]==edgeIndex)
00665             return 7;
00666         else if(t[8]==edgeIndex)
00667             return 8;
00668         else if(t[9]==edgeIndex)
00669             return 9;
00670         else if(t[10]==edgeIndex)
00671             return 10;
00672         else if(t[11]==edgeIndex)
00673             return 11;
00674         else 
00675             return -1;
00676     }
00677 
00678     int HexahedronSetTopologyContainer::getQuadIndexInHexahedron(const HexahedronQuads &t,
00679                                                                  const unsigned int quadIndex) const
00680     {
00681         if(t[0]==quadIndex)
00682             return 0;
00683         else if(t[1]==quadIndex)
00684             return 1;
00685         else if(t[2]==quadIndex)
00686             return 2;
00687         else if(t[3]==quadIndex)
00688             return 3;
00689         else if(t[4]==quadIndex)
00690             return 4;
00691         else if(t[5]==quadIndex)
00692             return 5;
00693         else 
00694             return -1;
00695     }
00696 
00697     sofa::helper::vector< unsigned int > &HexahedronSetTopologyContainer::getHexahedronEdgeShellForModification(const unsigned int i) 
00698     {
00699         if(!hasHexahedronEdgeShell())
00700             createHexahedronEdgeShellArray();
00701 
00702         assert( i < m_hexahedronEdgeShell.size());
00703 
00704         return m_hexahedronEdgeShell[i];
00705     }
00706 
00707     sofa::helper::vector< unsigned int > &HexahedronSetTopologyContainer::getHexahedronVertexShellForModification(const unsigned int i) 
00708     {
00709         if(!hasHexahedronVertexShell())
00710             createHexahedronVertexShellArray();
00711 
00712         assert( i < m_hexahedronVertexShell.size());
00713 
00714         return m_hexahedronVertexShell[i];
00715     }
00716 
00717     bool HexahedronSetTopologyContainer::checkTopology() const
00718     {
00719     #ifndef NDEBUG
00720         bool ret = true;
00721 
00722         if(hasHexahedronVertexShell()) 
00723         {
00724             for(unsigned int i=0; i<m_hexahedronVertexShell.size(); ++i) 
00725             {
00726                 const sofa::helper::vector<unsigned int> &tvs = m_hexahedronVertexShell[i];
00727                 for(unsigned int j=0; j<tvs.size(); ++j)
00728                 {
00729                     bool check_hexa_vertex_shell = (m_hexahedron[tvs[j]][0]==i) 
00730                                                 || (m_hexahedron[tvs[j]][1]==i) 
00731                                                 || (m_hexahedron[tvs[j]][2]==i) 
00732                                                 || (m_hexahedron[tvs[j]][3]==i) 
00733                                                 || (m_hexahedron[tvs[j]][4]==i) 
00734                                                 ||  (m_hexahedron[tvs[j]][5]==i) 
00735                                                 || (m_hexahedron[tvs[j]][6]==i) 
00736                                                 || (m_hexahedron[tvs[j]][7]==i);
00737 
00738                     if(!check_hexa_vertex_shell)
00739                     {
00740                         std::cout << "*** CHECK FAILED : check_hexa_vertex_shell, i = " << i << " , j = " << j << std::endl;
00741                         ret = false;
00742                     }
00743                 }
00744             }
00745         }
00746 
00747         if(hasHexahedronEdgeShell()) 
00748         {
00749             for(unsigned int i=0;i<m_hexahedronEdgeShell.size();++i) 
00750             {
00751                 const sofa::helper::vector<unsigned int> &tes=m_hexahedronEdgeShell[i];
00752                 for(unsigned int j=0; j<tes.size(); ++j)
00753                 {
00754                     bool check_hexa_edge_shell =   (m_hexahedronEdge[tes[j]][0]==i) 
00755                                                 || (m_hexahedronEdge[tes[j]][1]==i) 
00756                                                 || (m_hexahedronEdge[tes[j]][2]==i) 
00757                                                 || (m_hexahedronEdge[tes[j]][3]==i) 
00758                                                 || (m_hexahedronEdge[tes[j]][4]==i) 
00759                                                 || (m_hexahedronEdge[tes[j]][5]==i) 
00760                                                 || (m_hexahedronEdge[tes[j]][6]==i) 
00761                                                 || (m_hexahedronEdge[tes[j]][7]==i) 
00762                                                 || (m_hexahedronEdge[tes[j]][8]==i) 
00763                                                 || (m_hexahedronEdge[tes[j]][9]==i) 
00764                                                 || (m_hexahedronEdge[tes[j]][10]==i) 
00765                                                 || (m_hexahedronEdge[tes[j]][11]==i);
00766                     if(!check_hexa_edge_shell)
00767                     {
00768                         std::cout << "*** CHECK FAILED : check_hexa_edge_shell, i = " << i << " , j = " << j << std::endl;
00769                         ret = false;
00770                     }
00771                 }
00772             }
00773         }
00774 
00775         if(hasHexahedronQuadShell()) 
00776         {
00777             for(unsigned int i=0;i<m_hexahedronQuadShell.size();++i)
00778             {
00779                 const sofa::helper::vector<unsigned int> &tes=m_hexahedronQuadShell[i];
00780                 for(unsigned int j=0; j<tes.size(); ++j)
00781                 {
00782                     bool check_hexa_quad_shell =   (m_hexahedronQuad[tes[j]][0]==i) 
00783                                                 || (m_hexahedronQuad[tes[j]][1]==i) 
00784                                                 || (m_hexahedronQuad[tes[j]][2]==i) 
00785                                                 || (m_hexahedronQuad[tes[j]][3]==i) 
00786                                                 || (m_hexahedronQuad[tes[j]][4]==i) 
00787                                                 || (m_hexahedronQuad[tes[j]][5]==i);
00788                     if(!check_hexa_quad_shell)
00789                     {
00790                         std::cout << "*** CHECK FAILED : check_hexa_quad_shell, i = " << i << " , j = " << j << std::endl;
00791                         ret = false;
00792                     }
00793                 }
00794             }
00795         }
00796 
00797         return ret && QuadSetTopologyContainer::checkTopology();
00798     #else
00799         return true;
00800     #endif
00801     }
00802 
00803     bool HexahedronSetTopologyContainer::hasHexahedra() const
00804     {
00805         return !m_hexahedron.empty();
00806     }
00807 
00808     bool HexahedronSetTopologyContainer::hasHexahedronEdges() const
00809     {
00810         return !m_hexahedronEdge.empty();
00811     }
00812 
00813     bool HexahedronSetTopologyContainer::hasHexahedronQuads() const
00814     {
00815         return !m_hexahedronQuad.empty();
00816     }
00817 
00818     bool HexahedronSetTopologyContainer::hasHexahedronVertexShell() const
00819     {
00820         return !m_hexahedronVertexShell.empty();
00821     }
00822 
00823     bool HexahedronSetTopologyContainer::hasHexahedronEdgeShell() const
00824     {
00825         return !m_hexahedronEdgeShell.empty();
00826     }
00827 
00828     bool HexahedronSetTopologyContainer::hasHexahedronQuadShell() const
00829     {
00830         return !m_hexahedronQuadShell.empty();
00831     }
00832 
00833     void HexahedronSetTopologyContainer::clearHexahedra()
00834     {
00835         m_hexahedron.clear();
00836     }
00837 
00838     void HexahedronSetTopologyContainer::clearHexahedronEdges()
00839     {
00840         m_hexahedronEdge.clear();
00841     }
00842 
00843     void HexahedronSetTopologyContainer::clearHexahedronQuads()
00844     {
00845         m_hexahedronQuad.clear();
00846     }
00847 
00848     void HexahedronSetTopologyContainer::clearHexahedronVertexShell()
00849     {
00850         m_hexahedronVertexShell.clear();
00851     }
00852 
00853     void HexahedronSetTopologyContainer::clearHexahedronEdgeShell()
00854     {
00855         m_hexahedronEdgeShell.clear();
00856     }
00857 
00858     void HexahedronSetTopologyContainer::clearHexahedronQuadShell()
00859     {
00860         m_hexahedronQuadShell.clear();
00861     }
00862 
00863     void HexahedronSetTopologyContainer::clear()
00864     {
00865         clearHexahedronVertexShell();
00866         clearHexahedronEdgeShell();
00867         clearHexahedronQuadShell();
00868         clearHexahedronQuads();
00869         clearHexahedronEdges();
00870         clearHexahedra();
00871 
00872         QuadSetTopologyContainer::clear();
00873     }
00874 
00875 } // namespace topology
00876 
00877 } // namespace component
00878 
00879 } // namespace sofa
00880 

Generated on Sun Nov 23 03:44:15 2008 for Sofa by  doxygen 1.5.7.1