EdgeSetGeometryAlgorithms.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }
00123
00124 }
00125
00126 }
00127
00128 #endif // SOFA_COMPONENTS_EDGESETGEOMETRYALGORITHMS_INL