$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

triangleToDef.h

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 /* Main author: Dimitrios Kontaxakis */
00026 
00027 #ifndef TRIANGLE_TO_DEF_H
00028 #define TRIANGLE_TO_DEF_H
00029 
00030 #include "core/globalDefs.h"
00031 #include "core/geometry3D.h"
00032 #include "offLattice/triangularSurfaceMesh.h"
00033 #include "offLattice/triangleSet.h"
00034 #include <vector>
00035 #include <map>
00036 #include <set>
00037 #include <queue>
00038 
00039 namespace plb {
00040 
00041 template<typename T>
00042 class TriangleToDef {
00043 public:
00044     typedef typename TriangleSet<T>::Triangle Triangle;
00045 private:  // This class should only be used by the function constructSurfaceMesh().
00046     TriangleToDef(std::vector<Triangle> const& triangles, T epsilon=std::numeric_limits<float>::epsilon());
00047     void generateOnce (
00048         std::vector<Array<T,3> >& vertexList_,
00049         std::vector<plint>& emanatingEdgeList_,
00050         std::vector<typename TriangularSurfaceMesh<T>::Edge>& edgeList_ );
00051 private:
00052     struct EdgeListNode {
00053         plint maxv;   /* Integer key value representing the maximum of the global
00054                          indices of the two vertices that constitute a mesh edge */
00055         plint t1, t2; /* Indices of the adjacent triangles to the specific
00056                          edge. The value -1 in t2 indicates that the edge has no
00057                          triangle neighbor and therefore is a boundary edge */
00058     };
00059     struct VertexSetNode {
00060         VertexSetNode(plint i_, Array<T,3> const* vertex_)
00061             : i(i_), vertex(vertex_)
00062         { }
00063         plint i;                  // Global index of the vertex
00064         Array<T,3> const* vertex; // Pointer to vertex coordinates
00065     };
00066     struct BoundaryVertexMapNode {
00067         BoundaryVertexMapNode()
00068             : v1(-1), t1(-1), v2(-1), t2(-1), counter(0)
00069         { }
00070         plint v1; /* Global index of the vertex that the boundary edge
00071                      that points to the boundary vertex of index equal to
00072                      the map key starts from */
00073         plint t1; /* Index of the adjacent triangle of the boundary edge
00074                      that points to the boundary vertex of index equal to
00075                      the map key */
00076 
00077         plint v2; /* Global index of the vertex that the boundary edge
00078                      that starts from the boundary vertex of index equal
00079                      to the map key points to */
00080         plint t2; /* Index of the adjacent triangle of the boundary edge
00081                      that starts from the boundary vertex of index equal
00082                      to the map key */
00083 
00084         plint counter; /* Counter of boundary edges attached to the boundary
00085                           vertex of index equal to the map key. If `counter'
00086                           is not equal to two then there is a problem with
00087                           the mesh */
00088     };
00089 
00090     class VsLessThan {
00091     public:
00092         VsLessThan(T epsilon_=std::numeric_limits<float>::epsilon())
00093             : epsilon(epsilon_)
00094         { }
00095         bool operator()(VertexSetNode const& node1, VertexSetNode const& node2);
00096     private:
00097         bool vertexComponentLessThan(T x, T y);
00098         bool vertexComponentEqual(T x, T y);
00099         bool vertexLessThan(Array<T,3> const& v1, Array<T,3> const& v2);
00100     private:
00101         T epsilon;
00102     };
00103     typedef std::set<VertexSetNode,VsLessThan> VertexSet;
00104     typedef typename VertexSet::iterator VsNodeIt;
00105     typedef typename VertexSet::const_iterator VsNodeConstIt;
00106 
00107     typedef std::map<plint, BoundaryVertexMapNode> BoundaryVertexMap;
00108     typedef typename BoundaryVertexMap::iterator BvmNodeIt;
00109     typedef typename BoundaryVertexMap::const_iterator BvmNodeConstIt;
00110 private:
00111     void vsAdd( Array<T,3> const& coord, plint& index, plint& count );
00112     void vsOrder();
00113     plint searchEdgeList (
00114         std::vector<EdgeListNode> const& edgeList, plint maxv ) const;
00115     BvmNodeIt bvmAdd(plint id);
00116     bool bvmCheck() const;
00117     void bvmLabel();
00118     plint& globalVertex(plint triangle, plint localVertex);
00119     plint uniqueVertices(std::vector<Triangle> const& triangles);
00120     void computePointingVertex();
00121     plint createEdgeTable();
00122     void findBoundaryVertices();
00123     void computeNeighboringEdges();
00124     void computeInternalNeighboringEdges (
00125         plint iVertex, plint jVertex, plint triangle1, plint triangle2,
00126         plint localEdge1, plint va1, plint vb1 );
00127     void computeEmanatingEdges();
00128     bool fixOrientation();
00129     void fixOrientationOfNeighbors(plint iTriangle, std::queue<plint>& trianglesToFixNeighbors,
00130                                    char* visitedTriangles, bool& flag);
00131 private:
00132     std::vector<Array<plint,3> > triangleIndices;
00133     VertexSet vertexSet;
00134     std::vector<std::vector<EdgeListNode> > edgeTable;
00135     BoundaryVertexMap boundaryVertexMap;
00136 private:
00137     std::vector<Array<T,3> > vertexList;
00138     std::vector<plint> emanatingEdgeList;
00139     std::vector<typename TriangularSurfaceMesh<T>::Edge> edgeList;
00140     plint numTriangles, numVertices;
00141 template<typename U> friend 
00142 void constructSurfaceMesh (
00143         std::vector<typename TriangleToDef<U>::Triangle> const& triangles,
00144         std::vector<Array<U,3> >& vertexList,
00145         std::vector<plint>& emanatingEdgeList,
00146         std::vector<typename TriangularSurfaceMesh<U>::Edge>& edgeList, U epsilon );
00147 };
00148 
00149 template<typename T>
00150 void constructSurfaceMesh (
00151         std::vector<typename TriangleToDef<T>::Triangle> const& triangles,
00152         std::vector<Array<T,3> >& vertexList,
00153         std::vector<plint>& emanatingEdgeList,
00154         std::vector<typename TriangularSurfaceMesh<T>::Edge>& edgeList,
00155         T epsilon=std::numeric_limits<float>::epsilon() )
00156 {
00157     TriangleToDef<T>(triangles, epsilon).generateOnce (
00158             vertexList, emanatingEdgeList, edgeList );
00159 }
00160 
00161 } // namespace plb
00162 
00163 #endif  // TRIANGLE_TO_DEF_H