diff --git a/MeshLib/Elements/Tri.cpp b/MeshLib/Elements/Tri.cpp index 3778b7c0e160609ddc2577364d04f7c443b731b0..653343ca2a3c43d63876252fa971f87d7262516a 100644 --- a/MeshLib/Elements/Tri.cpp +++ b/MeshLib/Elements/Tri.cpp @@ -11,6 +11,7 @@ */ #include "Tri.h" +#include "Edge.h" #include "Node.h" #include "MathTools.h" @@ -76,5 +77,19 @@ double Tri::computeArea() return MathLib::calcTriangleArea(_nodes[0]->getCoords(), _nodes[1]->getCoords(), _nodes[2]->getCoords()); } +Element* Tri::reviseElement() const +{ + // try to create an edge + if (_nodes[0] == _nodes[1] || _nodes[1] == _nodes[2]) { + return new Edge(_nodes[0], _nodes[2], _value); + } + + if (_nodes[0] == _nodes[2]) { + return new Edge(_nodes[0], _nodes[1], _value); + } + + return NULL; +} + } diff --git a/MeshLib/Elements/Tri.h b/MeshLib/Elements/Tri.h index 3440323edb945e5c9068379babfc1a6fda810f18..096c1ada7984d930ce969c20e5c28a302098d0c8 100644 --- a/MeshLib/Elements/Tri.h +++ b/MeshLib/Elements/Tri.h @@ -18,18 +18,19 @@ namespace MeshLib { /** - * A 2d Triangle Element. + * This class represents a 2d triangle element. The following sketch shows the node and edge numbering. + * @anchor TriNodeAndEdgeNumbering * @code * - * Tri: 2 + * 2 * o * / \ * / \ - * / \ + * 2/ \1 * / \ * / \ - * o-----------o - * 0 1 + * 0-----------1 + * 0 * * @endcode */ @@ -69,6 +70,16 @@ public: */ virtual Element* clone() const; + /** + * This method should be called after at least two nodes of the triangle + * element are collapsed. As a consequence of the node collapsing an edge + * of the triangle will be collapsed. If one of the edges is collapsed we + * obtain an edge. In this case the method will create the appropriate + * object of class Edge. + * @return an Edge object or NULL + */ + virtual Element* reviseElement() const; + protected: /// Calculates the area of the triangle by returning half of the area of the corresponding parallelogram. double computeArea();