EdgeSetGeometryAlgorithms.inl

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 #ifndef SOFA_COMPONENT_TOPOLOGY_EDGESETGEOMETRYALGORITHMS_INL
00026 #define SOFA_COMPONENT_TOPOLOGY_EDGESETGEOMETRYALGORITHMS_INL
00027 
00028 #include <sofa/component/topology/EdgeSetGeometryAlgorithms.h>
00029 
00030 #include <sofa/component/topology/PointSetGeometryAlgorithms.inl>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace topology
00039 {
00040     using namespace sofa::defaulttype;
00041     
00042     template< class DataTypes>
00043     typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeEdgeLength( const unsigned int i) const 
00044     {
00045         const Edge &e = this->m_topology->getEdge(i);
00046         const VecCoord& p = *(this->object->getX());
00047         const Real length = (p[e[0]]-p[e[1]]).norm();
00048         return length;
00049     }
00050 
00051     template< class DataTypes>
00052     typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeRestEdgeLength( const unsigned int i) const 
00053     {
00054         const Edge &e = this->m_topology->getEdge(i);
00055         const VecCoord& p = *(this->object->getX0());
00056         const Real length = (p[e[0]]-p[e[1]]).norm();
00057         return length;
00058     }
00059 
00060     template< class DataTypes>
00061     typename DataTypes::Real EdgeSetGeometryAlgorithms< DataTypes >::computeRestSquareEdgeLength( const unsigned int i) const 
00062     {       
00063         const Edge &e = this->m_topology->getEdge(i);
00064         const VecCoord& p = *(this->object->getX0());
00065         const Real length = (p[e[0]]-p[e[1]]).norm2();
00066         return length;
00067     }
00068 
00070     template<class DataTypes>
00071     void EdgeSetGeometryAlgorithms<DataTypes>::computeEdgeLength( BasicArrayInterface<Real> &ai) const
00072     {
00073         const sofa::helper::vector<Edge> &ea = this->m_topology->getEdges();
00074         const typename DataTypes::VecCoord& p = *(this->object->getX());
00075 
00076         for (unsigned int i=0; i<ea.size(); ++i) 
00077         {
00078             const Edge &e = ea[i];
00079             ai[i] = (p[e[0]]-p[e[1]]).norm();
00080         }
00081     }
00082 
00084         template <typename DataTypes>
00085             void EdgeSetGeometryAlgorithms<DataTypes>::writeMSHfile(const char *filename)                   
00086         {
00087           std::ofstream myfile;                    
00088           myfile.open (filename); 
00089                  
00090           const typename DataTypes::VecCoord& vect_c = *(this->object->getX());                    
00091 
00092           const unsigned int numVertices = vect_c.size(); 
00093 
00094           myfile << "$NOD\n";      
00095           myfile << numVertices <<"\n";    
00096 
00097           for (unsigned int i=0; i<numVertices; ++i)       
00098           {        
00099             double x = (double) vect_c[i][0];       
00100             double y = (double) vect_c[i][1];       
00101             double z = (double) vect_c[i][2];       
00102 
00103             myfile << i+1 << " " << x << " " << y << " " << z <<"\n";       
00104           }        
00105 
00106           myfile << "$ENDNOD\n";   
00107           myfile << "$ELM\n";      
00108 
00109           const sofa::helper::vector<Edge> &edge = this->m_topology->getEdges();       
00110 
00111           myfile << edge.size() <<"\n";     
00112 
00113           for (unsigned int i=0; i<edge.size(); ++i)        
00114           {        
00115             myfile << i+1 << " 1 1 1 2 " << edge[i][0]+1 << " " << edge[i][1]+1 <<"\n";   
00116           }        
00117 
00118           myfile << "$ENDELM\n";   
00119 
00120           myfile.close();          
00121         }
00122 } // namespace topology
00123 
00124 } // namespace component
00125 
00126 } // namespace sofa
00127 
00128 #endif // SOFA_COMPONENTS_EDGESETGEOMETRYALGORITHMS_INL

Generated on Sun Nov 23 03:43:31 2008 for Sofa by  doxygen 1.5.7.1