/usr/include/psurface/SurfaceParts.h is in libpsurface-dev 2.0.0-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | #ifndef PSURFACE_SURFACE_PARTS
#define PSURFACE_SURFACE_PARTS
#include <vector>
#include <algorithm>
#include "StaticVector.h"
namespace psurface {
/** This is the base class for vertices in a SurfaceBase.
\tparam ctype The type used for coordinates
@see SurfaceBase, Edge, Triangle
*/
template <class ctype>
class Vertex: public StaticVector<ctype,3>
{
public:
/** \brief Export coordinate type */
typedef ctype coordtype;
/** \brief Default constructor */
Vertex() {}
/** \brief Constructor for a given position */
Vertex(const StaticVector<ctype,3> &a)
: StaticVector<ctype,3>(a)
{}
std::vector<int> edges;
/// the number of edges connected to this vertex
int degree() const {return edges.size();}
///
void removeReferenceTo(int edge){
typename std::vector<int>::iterator it = std::find(edges.begin(), edges.end(), edge);
if (it != edges.end())
edges.erase(it);
}
///
void replaceReferenceTo(int a, int b){
typename std::vector<int>::iterator it = std::find(edges.begin(), edges.end(), a);
if (it != edges.end())
*it = b;
}
};
///////////////////////////////////////////////////////////////
/** The base class for an edge in a SurfaceBase
@see SurfaceBase, Vertex, Triangle
*/
///////////////////////////////////////////////////////////////
class Edge
{
public:
///
Edge(){}
///
Edge(int a, int b)
: from(b), to(a)
{}
///
int numTriangles() const {return triangles.size();}
///
int theOtherVertex(int point) const {
return (point == to) ? from : to;
}
///
bool isConnectedTo(int vertex) const {
return to==vertex || from==vertex;
}
///
bool isConnectedToTriangle(int tri) const {
return std::find(triangles.begin(), triangles.end(), tri) != triangles.end();
}
///
bool removeReferenceTo(int tri){
std::vector<int>::iterator it = std::find(triangles.begin(), triangles.end(), tri);
if (it != triangles.end()) {
triangles.erase(it);
return true;
}
return false;
}
///
bool replaceReferenceTo(int a, int b){
std::vector<int>::iterator it = std::find(triangles.begin(), triangles.end(), a);
if (it != triangles.end()) {
*it = b;
return true;
}
return false;
}
/// The connection to a is replaced by the connection to b.
bool replaceReferenceToVertex(int a, int b){
if (from==a){
from = b;
return true;
} else if (to==a){
to = b;
return true;
} else
return false;
}
///////////////////////////////////////////
///
int from, to;
///
std::vector<int> triangles;
};
///////////////////////////////////////////////////////////////
/** The base class for triangles in a SurfaceBase
@see SurfaceBase, Vertex, Edge
*/
///////////////////////////////////////////////////////////////
class Triangle
{
public:
/// default constructor
Triangle() {
vertices[0] = vertices[1] = vertices[2] = -1;
edges[0] = edges[1] = edges[2] = -1;
}
/// creates a triangle using three given vertices
Triangle(int vertexIdx[3]) {
vertices[0] = vertexIdx[0];
vertices[1] = vertexIdx[1];
vertices[2] = vertexIdx[2];
edges[0] = edges[1] = edges[2] = -1;
}
///
Triangle(int a, int b, int c) {
vertices[0] = a;
vertices[1] = b;
vertices[2] = c;
edges[0] = edges[1] = edges[2] = -1;
}
///
bool isConnectedTo(int vertex) const {
return vertices[0]==vertex || vertices[1]==vertex || vertices[2]==vertex;
}
///
bool isCorrectlyOriented(const Triangle& other) const {
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
if (vertices[i]==other.vertices[j] && vertices[(i+1)%3]==other.vertices[(j+1)%3])
return false;
else if (vertices[i]==other.vertices[(j+1)%3] && vertices[(i+1)%3]==other.vertices[j])
return true;
assert(false);
return false;
}
///
int getThirdVertex(int a, int b) const {
for (int i=0; i<3; i++)
if (vertices[i]!=a && vertices[i]!=b)
return vertices[i];
return -1;
}
///
int getThirdVertex(int e) const {
for (int i=0; i<3; i++)
if (edges[i]==e)
return vertices[(i+2)%3];
return -1;
}
/** \brief Determines which of the three corners of the triangle
* is a given vertex v.
*
* \return 0, 1, or 2 if everything is okay. -1 if the triangle
* doesn't touch v.
*/
int getCorner(int v) const {
for (int i=0; i<3; i++)
if (vertices[i]==v)
return i;
return -1;
}
/** \brief Determines which of the three edges of the triangle
* is a given edge v.
*
* \return 0, 1, or 2 if everything is okay. -1 if the triangle
* doesn't touch v.
*/
int getEdge(int v) const {
for (int i=0; i<3; i++)
if (edges[i]==v)
return i;
return -1;
}
///
int getOppositeEdge(int a) const {
assert(vertices[0]==a || vertices[1]==a || vertices[2]==a);
for (int i=0; i<3; i++)
if (vertices[i]==a)
return edges[(i+1)%3];
return -1;
}
int getCommonEdgeWith(const Triangle& other) const {
int i, j;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
if (edges[i]==other.edges[j])
return edges[i];
return -1;
}
///
bool replaceReferenceToEdge(int a, int b) {
for (int i=0; i<3; i++)
if (edges[i]==a){
edges[i] = b;
return true;
}
return false;
}
///
bool replaceReferenceToVertex(int a, int b) {
for (int i=0; i<3; i++)
if (vertices[i]==a){
vertices[i] = b;
return true;
}
return false;
}
//////////////////////////////////////////////////////////////
public:
std::tr1::array<int, 3> vertices;
std::tr1::array<int, 3> edges;
};
} // namespace psurface
#endif
|