/usr/share/netgen/libsrc/stlgeom/stltopology.hpp is in netgen-headers 4.9.13.dfsg-8build2.
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | #ifndef FILE_STLTOPOLOGY
#define FILE_STLTOPOLOGY
/**************************************************************************/
/* File: stltopology.hpp */
/* Author: Joachim Schoeberl */
/* Author2: Johannes Gerstmayr */
/* Date: 26. Jul. 99 */
/**************************************************************************/
/*
The STLTopology contains topologic information as
triangle->point, point->triangles, triangle->edge, 2-points->edge,...
*/
class STLGeometry;
#define STLBASE 1
class STLPointIndex
{
int i;
public:
STLPointIndex () { ; }
STLPointIndex (int ai) : i(ai) { ; }
STLPointIndex & operator= (const STLPointIndex & ai) { i = ai.i; return *this; }
STLPointIndex & operator= (int ai) { i = ai; return *this; }
operator int () const { return i; }
STLPointIndex operator++ (int) { return i++; }
STLPointIndex operator-- (int) { return i--; }
};
class STLTrigIndex
{
int i;
public:
STLTrigIndex () { ; }
STLTrigIndex (int ai) : i(ai) { ; }
STLTrigIndex & operator= (const STLTrigIndex & ai) { i = ai.i; return *this; }
STLTrigIndex & operator= (int ai) { i = ai; return *this; }
operator int () const { return i; }
STLTrigIndex operator++ (int) { return i++; }
STLTrigIndex operator-- (int) { return i--; }
};
// triangle structure for loading stl files
class STLReadTriangle
{
Vec<3> normal;
Point<3> pts[3];
public:
STLReadTriangle (const Point<3> * apts, const Vec<3> & anormal);
STLReadTriangle () {};
const Point<3> & operator[] (int i) const { return pts[i]; }
const Vec<3> & Normal() const { return normal; }
};
class STLTriangle
{
// topology edges of triangle, edge[i] opposite to point[i]
int topedges[3];
// neighbour triangles, trig[i] opposite to point[i]
int nbtrigs[2][3];
// normalized stored normal vector ??
Vec<3> normal;
// point numbers of triangle
int pts[3];
// front-side and back-side domains
int domains[2];
public:
Box<3> box;
Point<3> center;
double rad;
int facenum;
struct
{
unsigned int toperror : 1;
} flags;
STLTriangle (const int * apts);
STLTriangle () {pts[0]=0;pts[1]=0;pts[2]=0;}
int operator[] (int i) const { return pts[i]; }
int & operator[] (int i) { return pts[i]; }
int EdgeNum(int i) const { return topedges[(i-1)]; }
int & EdgeNum(int i) { return topedges[(i-1)]; }
int NBTrig (bool side, int i) const { return nbtrigs[side][i]; }
int & NBTrig (bool side, int i) { return nbtrigs[side][i]; }
int Domain (bool side) const { return domains[side]; }
int & Domain (bool side) { return domains[side]; }
// obsolete:
int PNum(int i) const { return pts[(i-1)]; }
int & PNum(int i) { return pts[(i-1)]; }
int PNumMod(int i) const { return pts[(i-1)%3]; }
int & PNumMod(int i) { return pts[(i-1)%3]; }
int EdgeNumMod(int i) const { return topedges[(i-1)%3]; }
int & EdgeNumMod(int i) { return topedges[(i-1)%3]; }
int NBTrigNum(int i) const { return nbtrigs[0][(i-1)]; }
int & NBTrigNum(int i) { return nbtrigs[0][(i-1)]; }
int NBTrigNumMod(int i) const { return nbtrigs[0][(i-1)%3]; }
int & NBTrigNumMod(int i) { return nbtrigs[0][(i-1)%3]; }
// consistently oriented neighbour:
int IsNeighbourFrom(const STLTriangle& t) const;
// opposite to consistently oriented neighbour:
int IsWrongNeighbourFrom(const STLTriangle& t) const;
///Get the two points of neighbour-Triangles in orientation of this-Triangle
void GetNeighbourPoints(const STLTriangle& t, int& p1, int& p2) const;
int GetNeighbourPointsAndOpposite(const STLTriangle& t, int& p1, int& p2, int& po) const;
// NON-normalized geometry - normal vector
Vec<3> GeomNormal(const Array<Point<3> >& ap) const;
// Stored normal vector, normalized
void SetNormal (const Vec<3> & n);
const Vec<3> & Normal () const { return normal; }
void ChangeOrientation();
//project with a certain normal vector in plane
void ProjectInPlain(const Array<Point<3> >& ap,
const Vec<3> & n, Point<3> & pp) const;
//project with the triangle's normal vector in plane
void ProjectInPlain(const Array<Point<3> > & ap, Point<3> & pp) const;
/*
Project the point pp along the nproj into the plane of
the triangle. The triangle normal is given by ntrig to
avoid numerical instabilities.
The local coordinates lam are defined by
pp(input) = P1 + lam1 v1 + lam2 v2 + lam3 n
the result is
pp(output) = P1 + lam1 v1 + lam2 v2
*/
int ProjectInPlain (const Array<Point<3> >& ap,
const Vec<3> & nproj,
Point<3> & pp, Vec<3> & lam) const;
int PointInside(const Array<Point<3> >& ap, const Point<3> & pp) const;
//get nearest point on triangle and distance to it
double GetNearestPoint(const Array<Point<3> >& ap,
Point<3> & p3d) const;
double Area(const Array<Point<3> >& ap) const;
double MinHeight(const Array<Point<3> >& ap) const;
double MaxLength(const Array<Point<3> >& ap) const;
//max length of a side of triangle
int GetFaceNum() {return facenum;}
void SetFaceNum(int i) {facenum = i;}
int HasEdge(int p1, int p2) const;
};
/**
Topology Edge:
Useful unside a face.
A edges sharing more than 2 faces: trigs are undefined
*/
class STLTopEdge
{
int pts[2];
int trigs[2];
double cosangle;
int status; // excluded, confirmed, candidate, undefined
public:
STLTopEdge ();
STLTopEdge (int p1, int p2, int trig1, int trig2);
int operator[] (int i) const { return pts[i]; }
int & operator[] (int i) { return pts[i]; }
int PNum(int i) const { return pts[(i-1)]; }
int & PNum(int i) { return pts[(i-1)]; }
int PNumMod(int i) const { return pts[(i-1)%2]; }
int & PNumMod(int i) { return pts[(i-1)%2]; }
int TrigNum(int i) const { return trigs[(i-1)]; }
int & TrigNum(int i) { return trigs[(i-1)]; }
int TrigNumMod(int i) const { return trigs[(i-1)%2]; }
int & TrigNumMod(int i) { return trigs[(i-1)%2]; }
void SetCosAngle (double ca) { cosangle = ca; }
double CosAngle () const { return cosangle; }
double Angle () const { return acos (cosangle); }
void SetStatus (int stat) { status = stat; }
int GetStatus () const { return status; }
};
ostream& operator<<(ostream& os, const STLTriangle& t);
class STLTopology
{
protected:
Array<STLTriangle> trias;
Array<STLTopEdge> topedges;
Array<Point<3> > points;
// mapping of sorted pair of points to topedge
INDEX_2_HASHTABLE<int> * ht_topedges;
// mapping of node to trigs
TABLE<int> trigsperpoint;
// mapping of node to edges
TABLE<int> topedgesperpoint;
// searchtree for trigs and points
Box3dTree * searchtree; // ADT
Point3dTree * pointtree;
Box<3> boundingbox;
double pointtol;
public:
enum STL_GEOM_STATUS { STL_GOOD, STL_WARNING, STL_ERROR };
protected:
STL_GEOM_STATUS status;
string statustext;
bool topology_ok;
bool orientation_ok;
public:
STLTopology();
virtual ~STLTopology();
static STLGeometry * LoadNaomi (istream & ist);
static STLGeometry * Load (istream & ist);
static STLGeometry * LoadBinary (istream & ist);
void Save (const char* filename);
void SaveBinary (const char* filename, const char* aname);
void SaveSTLE (const char * filename); // stores trigs and edges
virtual void InitSTLGeometry (const Array<STLReadTriangle> & readtrigs);
virtual void TopologyChanged() {}; //do some things, if topology changed!
/// Generate topology tables
void FindNeighbourTrigs();
void GetTrianglesInBox (const Box<3> & box,
Array<int> & trias) const;
int GetNP() const { return points.Size(); }
int AddPoint(const Point<3> & p) { return points.Append(p); }
const Point<3> & GetPoint(int nr) const { return points.Get(nr); }
int GetPointNum (const Point<3> & p);
void SetPoint(int nr, const Point<3> & p) { points.Elem(nr) = p; }
const Array<Point<3> >& GetPoints() const { return points; }
const Point<3> & operator[] (STLPointIndex i) const { return points[i]; }
Point<3> & operator[] (STLPointIndex i) { return points[i]; }
int GetNT() const { return trias.Size(); }
void AddTriangle(const STLTriangle& t);
const STLTriangle & GetTriangle (int nr) const { return trias.Get(nr); }
STLTriangle & GetTriangle (int nr) { return trias.Elem(nr); }
const STLTriangle & operator[] (STLTrigIndex i) const { return trias[i]; }
STLTriangle & operator[] (STLTrigIndex i) { return trias[i]; }
int GetNTE() const { return topedges.Size(); }
const STLTopEdge & GetTopEdge (int nr) const { return topedges.Get(nr); }
STLTopEdge & GetTopEdge (int nr) { return topedges.Elem(nr); }
int GetTopEdgeNum (int pi1, int pi2) const;
int NOTrigsPerPoint(int pn) { return trigsperpoint.EntrySize(pn); }
int TrigPerPoint(int pn, int i) { return trigsperpoint.Get(pn, i); }
int NTopEdgesPerPoint (int pn) const { return topedgesperpoint.EntrySize(pn); }
int TopEdgePerPoint (int pn, int ei) const { return topedgesperpoint.Get(pn, ei); }
bool Topology_Ok() const { return topology_ok; }
bool Orientation_Ok() const { return orientation_ok; }
STL_GEOM_STATUS GetStatus () const { return status; }
const string & GetStatusText () const { return statustext; }
void InvertTrig (int trig);
void DeleteTrig (int trig);
void OrientAfterTrig (int trig);
// Table will be constructed, if topology is not ok
/// neighbourtrigs for surfacetrigs
TABLE<int> neighbourtrigs;
/// get nr-th neighbour Triangle for triangle trig
int NONeighbourTrigs(int trig) const { return neighbourtrigs.EntrySize(trig); }
int NeighbourTrig(int trig, int nr) const { return neighbourtrigs.Get(trig,nr); }
int NeighbourTrigSorted(int trig, int nr) const;
void AddNeighbourTrig(int i, int nt) { neighbourtrigs.Add1(i, nt); }
int GetLeftTrig (int p1, int p2) const;
int GetRightTrig (int p1, int p2) const;
const Box<3> & GetBoundingBox () const { return boundingbox; }
};
#endif
|