HexahedronSetTopologyModifier.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 #include <sofa/component/topology/HexahedronSetTopologyModifier.h>
00026 #include <sofa/component/topology/HexahedronSetTopologyChange.h>
00027 #include <sofa/component/topology/HexahedronSetTopologyContainer.h>
00028 #include <algorithm>
00029 #include <functional>
00030 #include <iostream>
00031 #include <sofa/core/ObjectFactory.h>
00032 
00033 namespace sofa
00034 {
00035 namespace component
00036 {
00037 namespace topology
00038 {
00039   SOFA_DECL_CLASS(HexahedronSetTopologyModifier)
00040         int HexahedronSetTopologyModifierClass = core::RegisterObject("Hexahedron set topology modifier")   
00041     .add< HexahedronSetTopologyModifier >();
00042 
00043     using namespace std;
00044     using namespace sofa::defaulttype;
00045     using namespace sofa::core::componentmodel::behavior;
00046 
00047     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}};
00048     
00049     
00050     void HexahedronSetTopologyModifier::init()
00051     {
00052         QuadSetTopologyModifier::init();
00053         this->getContext()->get(m_container);
00054     }
00055 
00056     
00057     void HexahedronSetTopologyModifier::addHexahedronProcess(Hexahedron t)
00058     {
00059 #ifndef NDEBUG
00060         // check if the 8 vertices are different
00061         assert(t[0]!=t[1]); assert(t[0]!=t[2]); assert(t[0]!=t[3]); assert(t[0]!=t[4]); assert(t[0]!=t[5]); assert(t[0]!=t[6]); assert(t[0]!=t[7]);
00062         assert(t[1]!=t[2]); assert(t[1]!=t[3]); assert(t[1]!=t[4]); assert(t[1]!=t[5]); assert(t[1]!=t[6]); assert(t[1]!=t[7]);
00063         assert(t[2]!=t[3]); assert(t[2]!=t[4]); assert(t[2]!=t[5]); assert(t[2]!=t[6]); assert(t[2]!=t[7]);
00064         assert(t[3]!=t[4]); assert(t[3]!=t[5]); assert(t[3]!=t[6]); assert(t[3]!=t[7]);
00065         assert(t[4]!=t[5]); assert(t[4]!=t[6]); assert(t[4]!=t[7]);
00066         assert(t[5]!=t[6]); assert(t[5]!=t[7]);
00067         assert(t[6]!=t[7]);
00068 
00069         // check if there already exists a hexahedron with the same indices
00070         assert(m_container->getHexahedronIndex(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7])== -1);
00071 #endif
00072         const unsigned int hexahedronIndex = m_container->getNumberOfHexahedra();
00073 
00074         if(m_container->hasHexahedronQuads()) 
00075         {
00076             int quadIndex;
00077 
00078             // Quad 0 :
00079             quadIndex=m_container->getQuadIndex(t[0],t[3],t[2],t[1]);
00080             //assert(quadIndex!= -1);
00081             if(quadIndex == -1)
00082             {
00083                 // first create the quad
00084                 sofa::helper::vector< Quad > v;
00085                 Quad e1 (t[0],t[3],t[2],t[1]);
00086                 v.push_back(e1);
00087 
00088                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00089 
00090                 quadIndex=m_container->getQuadIndex(t[0],t[3],t[2],t[1]);
00091                 sofa::helper::vector< unsigned int > quadIndexList;
00092                 quadIndexList.push_back(quadIndex);
00093                 addQuadsWarning( v.size(), v,quadIndexList);
00094             }
00095             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00096             m_container->m_hexahedronQuad[hexahedronIndex][0]=quadIndex; 
00097 
00098             // Quad 1 :
00099             quadIndex=m_container->getQuadIndex(t[4],t[5],t[6],t[7]);
00100             //assert(quadIndex!= -1);
00101             if(quadIndex == -1)
00102             {
00103                 // first create the quad
00104                 sofa::helper::vector< Quad > v;
00105                 Quad e1 (t[4],t[5],t[6],t[7]);
00106                 v.push_back(e1);
00107 
00108                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00109 
00110                 quadIndex=m_container->getQuadIndex(t[4],t[5],t[6],t[7]);
00111                 sofa::helper::vector< unsigned int > quadIndexList;
00112                 quadIndexList.push_back(quadIndex);
00113                 addQuadsWarning( v.size(), v,quadIndexList);
00114             }
00115             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00116             m_container->m_hexahedronQuad[hexahedronIndex][1]=quadIndex; 
00117 
00118             // Quad 2 :
00119             quadIndex=m_container->getQuadIndex(t[0],t[1],t[5],t[4]);
00120             //assert(quadIndex!= -1);
00121             if(quadIndex == -1)
00122             {
00123                 // first create the quad
00124                 sofa::helper::vector< Quad > v;
00125                 Quad e1 (t[0],t[1],t[5],t[4]);
00126                 v.push_back(e1);
00127 
00128                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00129 
00130                 quadIndex=m_container->getQuadIndex(t[0],t[1],t[5],t[4]);
00131                 sofa::helper::vector< unsigned int > quadIndexList;
00132                 quadIndexList.push_back(quadIndex);
00133                 addQuadsWarning( v.size(), v,quadIndexList);
00134             }
00135             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00136             m_container->m_hexahedronQuad[hexahedronIndex][2]=quadIndex; 
00137 
00138             // Quad 3 :
00139             quadIndex=m_container->getQuadIndex(t[1],t[2],t[6],t[5]);
00140             //assert(quadIndex!= -1);
00141             if(quadIndex == -1)
00142             {
00143                 // first create the quad
00144                 sofa::helper::vector< Quad > v;
00145                 Quad e1 (t[1],t[2],t[6],t[5]);
00146                 v.push_back(e1);
00147 
00148                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00149 
00150                 quadIndex=m_container->getQuadIndex(t[1],t[2],t[6],t[5]);
00151                 sofa::helper::vector< unsigned int > quadIndexList;
00152                 quadIndexList.push_back(quadIndex);
00153                 addQuadsWarning( v.size(), v,quadIndexList);
00154             }
00155             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00156             m_container->m_hexahedronQuad[hexahedronIndex][3]=quadIndex; 
00157 
00158             // Quad 4 :
00159             quadIndex=m_container->getQuadIndex(t[2],t[3],t[7],t[6]);
00160             //assert(quadIndex!= -1);
00161             if(quadIndex == -1)
00162             {
00163                 // first create the quad
00164                 sofa::helper::vector< Quad > v;
00165                 Quad e1 (t[2],t[3],t[7],t[6]);
00166                 v.push_back(e1);
00167 
00168                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00169 
00170                 quadIndex=m_container->getQuadIndex(t[2],t[3],t[7],t[6]);
00171                 sofa::helper::vector< unsigned int > quadIndexList;
00172                 quadIndexList.push_back(quadIndex);
00173                 addQuadsWarning( v.size(), v,quadIndexList);
00174             }
00175             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00176             m_container->m_hexahedronQuad[hexahedronIndex][4]=quadIndex; 
00177 
00178             // Quad 5 :
00179             quadIndex=m_container->getQuadIndex(t[3],t[0],t[4],t[7]);
00180             //assert(quadIndex!= -1);
00181             if(quadIndex == -1)
00182             {
00183                 // first create the quad
00184                 sofa::helper::vector< Quad > v;
00185                 Quad e1 (t[3],t[0],t[4],t[7]);
00186                 v.push_back(e1);
00187 
00188                 addQuadsProcess((const sofa::helper::vector< Quad > &) v);
00189 
00190                 quadIndex=m_container->getQuadIndex(t[3],t[0],t[4],t[7]);
00191                 sofa::helper::vector< unsigned int > quadIndexList;
00192                 quadIndexList.push_back(quadIndex);
00193                 addQuadsWarning( v.size(), v,quadIndexList);
00194             }
00195             m_container->m_hexahedronQuad.resize(hexahedronIndex+1);
00196             m_container->m_hexahedronQuad[hexahedronIndex][5]=quadIndex; 
00197 
00198             if(m_container->hasHexahedronQuadShell()) 
00199             {
00200                 for(unsigned int q=0; q<6; ++q) 
00201                 {
00202                     sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronQuadShell[m_container->m_hexahedronQuad[hexahedronIndex][q]];
00203                     shell.push_back( hexahedronIndex );             
00204                 }
00205             }       
00206         } // quads
00207 
00208         if(m_container->hasHexahedronEdges()) 
00209         {
00210             m_container->m_hexahedronEdge.resize(hexahedronIndex+1);
00211             for(unsigned int edgeIdx=0; edgeIdx<12; ++edgeIdx) 
00212             {
00213                 const int edgeIndex=m_container->getEdgeIndex(t[hexahedronEdgeArray[edgeIdx][0]], 
00214                     t[hexahedronEdgeArray[edgeIdx][1]]);
00215                 assert(edgeIndex!= -1);
00216                 m_container->m_hexahedronEdge[hexahedronIndex][edgeIdx]= edgeIndex; 
00217             }
00218 
00219             if(m_container->hasHexahedronEdgeShell()) 
00220             {
00221                 for(unsigned int e=0; e<12; ++e) 
00222                 {
00223                     sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronEdgeShell[m_container->m_hexahedronEdge[hexahedronIndex][e]];
00224                     shell.push_back( hexahedronIndex );                 
00225                 }
00226             }
00227         } // edges
00228 
00229         if(m_container->hasHexahedronVertexShell()) 
00230         {
00231             for(unsigned int v=0; v<8; ++v) 
00232             {
00233                 sofa::helper::vector< unsigned int > &shell = m_container->getHexahedronVertexShellForModification( t[v] );
00234                 shell.push_back( hexahedronIndex );             
00235             }                       
00236         }
00237 
00238         m_container->m_hexahedron.push_back(t);
00239     }
00240 
00241     
00242     void HexahedronSetTopologyModifier::addHexahedraProcess(const sofa::helper::vector< Hexahedron > &hexahedra) 
00243     {
00244         for(unsigned int i = 0; i < hexahedra.size(); ++i)
00245         {
00246             addHexahedronProcess(hexahedra[i]);
00247         }
00248     }
00249 
00250     
00251     void HexahedronSetTopologyModifier::addHexahedraWarning(const unsigned int nHexahedra, 
00252                                             const sofa::helper::vector< Hexahedron >& hexahedraList,
00253                                             const sofa::helper::vector< unsigned int >& hexahedraIndexList) 
00254     {
00255         // Warning that hexahedra just got created
00256         HexahedraAdded *e = new HexahedraAdded(nHexahedra, hexahedraList, hexahedraIndexList);
00257         addTopologyChange(e);
00258     }   
00259     
00260     
00261     void HexahedronSetTopologyModifier::addHexahedraWarning(const unsigned int nHexahedra, 
00262                                             const sofa::helper::vector< Hexahedron >& hexahedraList,
00263                                             const sofa::helper::vector< unsigned int >& hexahedraIndexList,
00264                                             const sofa::helper::vector< sofa::helper::vector< unsigned int > > & ancestors,
00265                                             const sofa::helper::vector< sofa::helper::vector< double > >& baryCoefs) 
00266     {
00267         // Warning that hexahedra just got created
00268         HexahedraAdded *e = new HexahedraAdded(nHexahedra, hexahedraList, hexahedraIndexList, ancestors, baryCoefs);
00269         addTopologyChange(e);
00270     }
00271 
00272     
00273     void HexahedronSetTopologyModifier::removeHexahedraWarning( sofa::helper::vector<unsigned int> &hexahedra ) 
00274     {
00276         std::sort( hexahedra.begin(), hexahedra.end(), std::greater<unsigned int>() );
00277 
00278         // Warning that these edges will be deleted
00279         HexahedraRemoved *e = new HexahedraRemoved(hexahedra);
00280         addTopologyChange(e);
00281     }
00282 
00283     
00284     void HexahedronSetTopologyModifier::removeHexahedraProcess( const sofa::helper::vector<unsigned int> &indices,
00285                                                                         const bool removeIsolatedItems)
00286     {
00287         if(!m_container->hasHexahedra())
00288             return;
00289 
00290         bool removeIsolatedVertices = removeIsolatedItems;
00291         bool removeIsolatedEdges = removeIsolatedItems && m_container->hasEdges();
00292         bool removeIsolatedQuads = removeIsolatedItems && m_container->hasQuads();
00293 
00294         if(removeIsolatedVertices)
00295         {
00296             if(!m_container->hasHexahedronVertexShell())
00297                 m_container->createHexahedronVertexShellArray();
00298         }
00299 
00300         if(removeIsolatedEdges)
00301         {
00302             if(!m_container->hasHexahedronEdgeShell())
00303                 m_container->createHexahedronEdgeShellArray();
00304         }
00305 
00306         if(removeIsolatedQuads)
00307         {
00308             if(!m_container->hasHexahedronQuadShell())
00309                 m_container->createHexahedronQuadShellArray();
00310         }
00311 
00312         sofa::helper::vector<unsigned int> quadToBeRemoved;
00313         sofa::helper::vector<unsigned int> edgeToBeRemoved;
00314         sofa::helper::vector<unsigned int> vertexToBeRemoved;
00315 
00316         unsigned int lastHexahedron = m_container->getNumberOfHexahedra() - 1;
00317         for(unsigned int i=0; i<indices.size(); ++i, --lastHexahedron)
00318         {
00319             Hexahedron &t = m_container->m_hexahedron[ indices[i] ];
00320             Hexahedron &h = m_container->m_hexahedron[ lastHexahedron ];
00321 
00322             if(m_container->hasHexahedronVertexShell()) 
00323             {
00324                 for(unsigned int v=0; v<8; ++v)
00325                 {
00326                     sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronVertexShell[ t[v] ];
00327                     shell.erase(remove(shell.begin(), shell.end(), indices[i]), shell.end());
00328                     if(removeIsolatedVertices && shell.empty())
00329                         vertexToBeRemoved.push_back(t[v]);
00330                 }
00331             }
00332 
00333             if(m_container->hasHexahedronEdgeShell()) 
00334             {
00335                 for(unsigned int e=0; e<12; ++e)
00336                 {
00337                     sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronEdgeShell[ m_container->m_hexahedronEdge[indices[i]][e]];
00338                     shell.erase(remove(shell.begin(), shell.end(), indices[i]), shell.end());
00339                     if(removeIsolatedEdges && shell.empty())
00340                         edgeToBeRemoved.push_back(m_container->m_hexahedronEdge[indices[i]][e]);
00341                 }
00342             }
00343 
00344             if(m_container->hasHexahedronQuadShell()) 
00345             {
00346                 for(unsigned int q=0; q<6; ++q)
00347                 {
00348                     sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronQuadShell[ m_container->m_hexahedronQuad[indices[i]][q]];
00349                     shell.erase(remove(shell.begin(), shell.end(), indices[i]), shell.end());
00350                     if(removeIsolatedQuads && shell.empty())
00351                         quadToBeRemoved.push_back(m_container->m_hexahedronQuad[indices[i]][q]);
00352                 }
00353             }
00354 
00355             // now updates the shell information of the edge formely at the end of the array
00356             if( indices[i] < lastHexahedron ) 
00357             {
00358                 if(m_container->hasHexahedronVertexShell()) 
00359                 {
00360                     for(unsigned int v=0; v<8; ++v)
00361                     {
00362                         sofa::helper::vector< unsigned int > &shell = m_container->m_hexahedronVertexShell[ h[v] ];
00363                         replace(shell.begin(), shell.end(), lastHexahedron, indices[i]);                        
00364                     }
00365                 }
00366 
00367                 if(m_container->hasHexahedronEdgeShell()) 
00368                 {
00369                     for(unsigned int e=0; e<12; ++e)
00370                     {
00371                         sofa::helper::vector< unsigned int > &shell =  m_container->m_hexahedronEdgeShell[ m_container->m_hexahedronEdge[lastHexahedron][e]];
00372                         replace(shell.begin(), shell.end(), lastHexahedron, indices[i]);                        
00373                     }
00374                 }
00375 
00376                 if(m_container->hasHexahedronQuadShell()) 
00377                 {
00378                     for(unsigned int q=0; q<6; ++q)
00379                     {
00380                         sofa::helper::vector< unsigned int > &shell =  m_container->m_hexahedronQuadShell[ m_container->m_hexahedronQuad[lastHexahedron][q]];
00381                         replace(shell.begin(), shell.end(), lastHexahedron, indices[i]);                        
00382                     }
00383                 }
00384             }
00385 
00386             if(m_container->hasHexahedronQuads()) 
00387             {
00388                 // removes the hexahedronQuads from the hexahedronQuadArray
00389                 m_container->m_hexahedronQuad[ indices[i] ] = m_container->m_hexahedronQuad[ lastHexahedron ]; // overwriting with last valid value.
00390                 m_container->m_hexahedronQuad.resize( lastHexahedron ); // resizing to erase multiple occurence of the hexa.
00391             }
00392 
00393             if(m_container->hasHexahedronEdges()) 
00394             {
00395                 // removes the hexahedronEdges from the hexahedronEdgeArray
00396                 m_container->m_hexahedronEdge[ indices[i] ] = m_container->m_hexahedronEdge[ lastHexahedron ]; // overwriting with last valid value.
00397                 m_container->m_hexahedronEdge.resize( lastHexahedron ); // resizing to erase multiple occurence of the hexa.
00398             }
00399 
00400             // removes the hexahedron from the hexahedronArray
00401             m_container->m_hexahedron[ indices[i] ] = m_container->m_hexahedron[ lastHexahedron ]; // overwriting with last valid value.
00402             m_container->m_hexahedron.resize( lastHexahedron ); // resizing to erase multiple occurence of the hexa.
00403         }
00404 
00405         if( (!quadToBeRemoved.empty()) || (!edgeToBeRemoved.empty())) 
00406         {  
00407             if(!quadToBeRemoved.empty())
00408             { 
00410                 removeQuadsWarning(quadToBeRemoved);
00411             }
00412 
00413             if(!edgeToBeRemoved.empty())
00414             { 
00416                 removeEdgesWarning(edgeToBeRemoved);
00417             }
00418 
00419             propagateTopologicalChanges();
00420 
00421             if(!quadToBeRemoved.empty())
00422             {
00424                 removeQuadsProcess(quadToBeRemoved, false, false);
00425             }
00426 
00427             if(!edgeToBeRemoved.empty())
00428             {
00430                 removeEdgesProcess(edgeToBeRemoved, false);
00431             }
00432         }
00433 
00434         if(!vertexToBeRemoved.empty())
00435         { 
00436             removePointsWarning(vertexToBeRemoved);
00437             propagateTopologicalChanges();  
00438             removePointsProcess(vertexToBeRemoved);
00439         }
00440     }
00441 
00442     void HexahedronSetTopologyModifier::addPointsProcess(const unsigned int nPoints) 
00443     {
00444         // start by calling the parent's method.
00445         QuadSetTopologyModifier::addPointsProcess( nPoints );
00446 
00447         if(m_container->hasHexahedronVertexShell())
00448             m_container->m_hexahedronVertexShell.resize( m_container->getNbPoints() );
00449     }   
00450 
00451     void HexahedronSetTopologyModifier::addEdgesProcess(const sofa::helper::vector< Edge > &edges) 
00452     {
00453         // start by calling the parent's method.
00454         QuadSetTopologyModifier::addEdgesProcess( edges );
00455 
00456         if(m_container->hasHexahedronEdgeShell())
00457             m_container->m_hexahedronEdgeShell.resize( m_container->getNumberOfEdges() );
00458     }
00459 
00460     void HexahedronSetTopologyModifier::addQuadsProcess(const sofa::helper::vector< Quad > &quads) 
00461     {
00462         // start by calling the parent's method.
00463         QuadSetTopologyModifier::addQuadsProcess( quads );
00464 
00465         if(m_container->hasHexahedronQuadShell())
00466             m_container->m_hexahedronQuadShell.resize( m_container->getNumberOfQuads() );
00467     }
00468 
00469     void HexahedronSetTopologyModifier::removePointsProcess( sofa::helper::vector<unsigned int> &indices, 
00470                                                                         const bool removeDOF) 
00471     {
00472         if(m_container->hasHexahedra())
00473         {
00474             if(!m_container->hasHexahedronVertexShell())
00475             {
00476                 m_container->createHexahedronVertexShellArray();
00477             }
00478 
00479             unsigned int lastPoint = m_container->getNbPoints() - 1;
00480             for(unsigned int i = 0; i < indices.size(); ++i, --lastPoint)
00481             {
00482                 // updating the edges connected to the point replacing the removed one:
00483                 // for all edges connected to the last point
00484                 for(sofa::helper::vector<unsigned int>::iterator itt=m_container->m_hexahedronVertexShell[lastPoint].begin();
00485                     itt!=m_container->m_hexahedronVertexShell[lastPoint].end(); ++itt) 
00486                 {
00487                     unsigned int vertexIndex = m_container->getVertexIndexInHexahedron(m_container->m_hexahedron[*itt], lastPoint);
00488                     m_container->m_hexahedron[*itt][ vertexIndex] = indices[i];
00489                 }
00490 
00491                 // updating the edge shell itself (change the old index for the new one)
00492                 m_container->m_hexahedronVertexShell[ indices[i] ] = m_container->m_hexahedronVertexShell[ lastPoint ];
00493             }
00494 
00495             m_container->m_hexahedronVertexShell.resize( m_container->m_hexahedronVertexShell.size() - indices.size() );
00496         }
00497 
00498         // Important : the points are actually deleted from the mechanical object's state vectors iff (removeDOF == true)
00499         // call the parent's method.
00500         QuadSetTopologyModifier::removePointsProcess(  indices, removeDOF );
00501     }
00502 
00503     void HexahedronSetTopologyModifier::removeEdgesProcess( const sofa::helper::vector<unsigned int> &indices,
00504                                                                         const bool removeIsolatedItems) 
00505     {
00506         if(!m_container->hasEdges()) // this method should only be called when edges exist
00507             return;
00508 
00509         if(m_container->hasHexahedronEdges()) 
00510         {
00511             if(!m_container->hasHexahedronEdgeShell())
00512                 m_container->createHexahedronEdgeShellArray();
00513 
00514             unsigned int lastEdge = m_container->getNumberOfEdges() - 1;
00515             for(unsigned int i=0; i<indices.size(); ++i, --lastEdge)
00516             {
00517                 for(sofa::helper::vector<unsigned int>::iterator itt=m_container->m_hexahedronEdgeShell[lastEdge].begin();
00518                     itt!=m_container->m_hexahedronEdgeShell[lastEdge].end(); ++itt) 
00519                 {
00520                     unsigned int edgeIndex = m_container->getEdgeIndexInHexahedron(m_container->m_hexahedronEdge[*itt], lastEdge);
00521                     m_container->m_hexahedronEdge[*itt][edgeIndex] = indices[i];
00522                 }
00523 
00524                 // updating the edge shell itself (change the old index for the new one)
00525                 m_container->m_hexahedronEdgeShell[ indices[i] ] = m_container->m_hexahedronEdgeShell[ lastEdge ];
00526             }
00527 
00528             m_container->m_hexahedronEdgeShell.resize( m_container->m_hexahedronEdgeShell.size() - indices.size() );
00529         }
00530 
00531         // call the parent's method.
00532         QuadSetTopologyModifier::removeEdgesProcess(  indices, removeIsolatedItems );
00533     }
00534 
00535     void HexahedronSetTopologyModifier::removeQuadsProcess( const sofa::helper::vector<unsigned int> &indices,
00536                                                                         const bool removeIsolatedEdges, 
00537                                                                         const bool removeIsolatedPoints) 
00538     {
00539         if(!m_container->hasQuads()) // this method should only be called when quads exist
00540             return;
00541 
00542         if(m_container->hasHexahedronQuads()) 
00543         {
00544             if(!m_container->hasHexahedronQuadShell())
00545                 m_container->createHexahedronQuadShellArray();
00546 
00547             unsigned int lastQuad = m_container->getNumberOfQuads() - 1;
00548             for(unsigned int i=0; i<indices.size(); ++i, --lastQuad)
00549             {
00550                 for(sofa::helper::vector<unsigned int>::iterator itt=m_container->m_hexahedronQuadShell[lastQuad].begin();
00551                     itt!=m_container->m_hexahedronQuadShell[lastQuad].end(); ++itt) 
00552                 {
00553                     unsigned int quadIndex=m_container->getQuadIndexInHexahedron(m_container->m_hexahedronQuad[*itt],lastQuad);
00554                     m_container->m_hexahedronQuad[*itt][quadIndex]=indices[i];
00555                 }
00556 
00557                 // updating the quad shell itself (change the old index for the new one)
00558                 m_container->m_hexahedronQuadShell[ indices[i] ] = m_container->m_hexahedronQuadShell[ lastQuad ];
00559             }
00560             m_container->m_hexahedronQuadShell.resize( m_container->m_hexahedronQuadShell.size() - indices.size() );
00561         }
00562 
00563         // call the parent's method.
00564         QuadSetTopologyModifier::removeQuadsProcess( indices, removeIsolatedEdges, removeIsolatedPoints );
00565     }
00566 
00567     void HexahedronSetTopologyModifier::renumberPointsProcess( const sofa::helper::vector<unsigned int> &index, const sofa::helper::vector<unsigned int> &inv_index, const bool renumberDOF) 
00568     {
00569         if(m_container->hasHexahedra())
00570         {
00571             if(m_container->hasHexahedronVertexShell())
00572             {
00573                 sofa::helper::vector< sofa::helper::vector< unsigned int > > hexahedronVertexShell_cp = m_container->m_hexahedronVertexShell;
00574                 for(unsigned int i=0; i<index.size(); ++i)
00575                 {
00576                     m_container->m_hexahedronVertexShell[i] = hexahedronVertexShell_cp[ index[i] ];
00577                 }
00578             }
00579 
00580             for(unsigned int i=0; i<m_container->m_hexahedron.size(); ++i)
00581             {
00582                 m_container->m_hexahedron[i][0]  = inv_index[ m_container->m_hexahedron[i][0]  ];
00583                 m_container->m_hexahedron[i][1]  = inv_index[ m_container->m_hexahedron[i][1]  ];
00584                 m_container->m_hexahedron[i][2]  = inv_index[ m_container->m_hexahedron[i][2]  ];
00585                 m_container->m_hexahedron[i][3]  = inv_index[ m_container->m_hexahedron[i][3]  ];
00586                 m_container->m_hexahedron[i][4]  = inv_index[ m_container->m_hexahedron[i][4]  ];
00587                 m_container->m_hexahedron[i][5]  = inv_index[ m_container->m_hexahedron[i][5]  ];
00588                 m_container->m_hexahedron[i][6]  = inv_index[ m_container->m_hexahedron[i][6]  ];
00589                 m_container->m_hexahedron[i][7]  = inv_index[ m_container->m_hexahedron[i][7]  ];
00590             }
00591         }
00592 
00593         // call the parent's method.
00594         QuadSetTopologyModifier::renumberPointsProcess( index, inv_index, renumberDOF );
00595     }
00596 
00597     void HexahedronSetTopologyModifier::removeHexahedra(sofa::helper::vector< unsigned int >& hexahedra)
00598     {
00599         // add the topological changes in the queue
00600         removeHexahedraWarning(hexahedra);
00601         // inform other objects that the hexa are going to be removed
00602         propagateTopologicalChanges();
00603         // now destroy the old hexahedra.
00604         removeHexahedraProcess(  hexahedra ,true);
00605 
00606         m_container->checkTopology();           
00607     }
00608 
00609     void HexahedronSetTopologyModifier::removeItems(sofa::helper::vector< unsigned int >& items)
00610     {
00611         removeHexahedra(items);
00612     }
00613 
00614     void HexahedronSetTopologyModifier::renumberPoints(const sofa::helper::vector<unsigned int> &index, 
00615                                                                     const sofa::helper::vector<unsigned int> &inv_index)
00616     {
00618         renumberPointsWarning(index, inv_index);
00619         // inform other objects that the triangles are going to be removed
00620         propagateTopologicalChanges();
00621         // now renumber the points      
00622         renumberPointsProcess(index, inv_index);
00623 
00624         m_container->checkTopology(); 
00625     }
00626 
00627 } // namespace topology
00628 
00629 } // namespace component
00630 
00631 } // namespace sofa
00632 

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