Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / HACD / hacdGraph.h
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)\r
2  All rights reserved.\r
3  \r
4  \r
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r
6  \r
7  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r
8  \r
9  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r
10  \r
11  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.\r
12  \r
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
14  */\r
15 #pragma once\r
16 #ifndef HACD_GRAPH_H\r
17 #define HACD_GRAPH_H\r
18 #include "hacdVersion.h"\r
19 #include "hacdVector.h"\r
20 #include "hacdICHull.h"\r
21 #include <map>\r
22 #include <vector>\r
23 #include <set>\r
24 \r
25 namespace HACD\r
26 {\r
27     class GraphVertex;\r
28     class GraphEdge;\r
29     class Graph;\r
30         class HACD;\r
31        \r
32     class GraphVertex  \r
33     {\r
34     public:\r
35         bool                                    AddEdge(long name) \r
36                                                                                                 { \r
37                                                                                                         m_edges.insert(name); \r
38                                                                                                         return true; \r
39                                                                                                 }\r
40         bool                                    DeleteEdge(long name);        \r
41                                                 GraphVertex();\r
42                                                 ~GraphVertex(){ delete m_convexHull;};      \r
43     private:\r
44         long                                    m_name;\r
45         long                                    m_cc;\r
46         std::set<long>                          m_edges;\r
47         bool                                    m_deleted;\r
48         std::vector<long>                           m_ancestors;\r
49                 std::map<long, DPoint>                                  m_distPoints;\r
50 \r
51         Real                                    m_error;\r
52         double                                  m_surf;\r
53                 double                                  m_volume;\r
54         double                                  m_perimeter;\r
55         double                                  m_concavity;\r
56         ICHull *                                m_convexHull;\r
57                 std::set<unsigned long long>                    m_boudaryEdges;\r
58         \r
59 \r
60         friend class GraphEdge;\r
61         friend class Graph;\r
62                 friend class HACD;\r
63     };\r
64     \r
65         class GraphEdge \r
66     {\r
67     public:\r
68                                                 GraphEdge();\r
69                                                 ~GraphEdge(){delete m_convexHull;};\r
70     private:\r
71         long                                    m_name;\r
72         long                                    m_v1;\r
73         long                                    m_v2;\r
74                 std::map<long, DPoint>                                  m_distPoints;\r
75         Real                                    m_error;\r
76         double                                  m_surf;\r
77                 double                                  m_volume;\r
78         double                                  m_perimeter;\r
79         double                                  m_concavity;\r
80         ICHull *                                m_convexHull;\r
81                 std::set<unsigned long long>                    m_boudaryEdges;\r
82         bool                                    m_deleted;\r
83                 \r
84 \r
85         \r
86         friend class GraphVertex;\r
87         friend class Graph;\r
88                 friend class HACD;\r
89     };\r
90     \r
91     class Graph  \r
92     {\r
93     public:\r
94                 size_t                                                                  GetNEdges() const { return m_nE;}\r
95                 size_t                                                                  GetNVertices() const { return m_nV;}\r
96         bool                                    EdgeCollapse(long v1, long v2);\r
97         long                                    AddVertex();\r
98         long                                    AddEdge(long v1, long v2);\r
99         bool                                    DeleteEdge(long name);  \r
100         bool                                    DeleteVertex(long name);\r
101         long                                    GetEdgeID(long v1, long v2) const;\r
102                 void                                                                    Clear();\r
103         void                                    Print() const;\r
104         long                                    ExtractCCs();\r
105         \r
106                                                 Graph();\r
107         virtual                                 ~Graph();      \r
108                 void                                                                    Allocate(size_t nV, size_t nE);\r
109 \r
110     private:\r
111         size_t                                  m_nCCs;\r
112         size_t                                  m_nV;\r
113         size_t                                  m_nE;\r
114         std::vector<GraphEdge>                  m_edges;\r
115         std::vector<GraphVertex>                m_vertices;\r
116 \r
117                 friend class HACD;\r
118     };\r
119 }\r
120 #endif\r