UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
u3d_curvature_triangled_surface.hpp
1 // u3d_curvature_triangled_surface.hpp
2 // $Id: u3d_curvature_triangled_surface.hpp,v 1.1 2008/05/13 12:06:26 sad Exp $
3 
4 #ifndef U3D_CURVATURE_TRIANGLED_SURFACE_HPP_
5 #define U3D_CURVATURE_TRIANGLED_SURFACE_HPP_
6 
7 #include "u3d_triangled_abstract_surface.hpp"
8 #include <mth/u3d_box.hpp>
9 #include <cassert>
10 #include <map>
11 #include <set>
12 #include <vector>
13 #include <exception>
14 
15 #include <iostream>
16 #include <fstream>
17 
18 using namespace std;
19 
20 
21 class badmathsurf_exception : public exception {};
22 
23 
28 {
29 public:
33  U3dPoint zeroPoint,
34  double minTriangleSide
35  )
36  throw (badmathsurf_exception);
37 
38  // Copy constructor
40 
41 
42  virtual void addPoint(U3dPoint *p);
43  virtual bool removePoint(int i);
44  virtual void movePoint(int i, double d1, double d2, double d3);
45 
46  virtual U3dBox getBox() const { return m_box; };
47 
48 
49  virtual ~U3dCurvatureTriangledSurface() {};
50 
51 protected:
52 
53  friend class CurvaturePlate;
55  public:
57  CurvaturePlate(U3dCurvatureTriangledSurface* trSurface) : trSurf(trSurface) {};
58  void calculate();
59  bool checkCurvature(const double& dp, const double& dq, const double& up, const double& uq);
60  ~CurvaturePlate() { for (unsigned i=0; i<n; ++i) delete[] curvatures[i]; delete[] curvatures; };
61  double getMinCurv() { return minCurv; };
62  double getMaxCurv() { return maxCurv; };
63  private:
64  CurvaturePlate(const CurvaturePlate&) {};
65  void operator=(const CurvaturePlate&) {};
66  float** curvatures;
68  size_t n, m;
69  float step_p, step_q;
70  double minCurv, maxCurv;
71  };
72 
73 
74  virtual void triangulate();
75 
76  struct PQ_Point {
77  PQ_Point(double p_, double q_) : p(p_), q(q_) {};
78  double p, q;
79  };
80 
81 
82  friend class PointsKeeper;
83  class PointsKeeper {
84  typedef vector<PQ_Point> pq_points_vector;
85  public:
88  inline int add_point(const double& p, const double& q);
89  inline double p(const int& num) { return pq_points[num].p; };
90  inline double q(const int& num) { return pq_points[num].q; };
91  private:
92  PointsKeeper(const PointsKeeper&) {};
94  pq_points_vector pq_points;
95  };
96 
97 
98 
99 
100  struct QuadMapCoords {
101  QuadMapCoords() : level(0), i(0), j(0) {};
102  QuadMapCoords(int level_, int i_, int j_) : level(level_), i(i_), j(j_) {};
103  inline bool operator() (const QuadMapCoords& c1, const QuadMapCoords& c2); // For comparator function
104  int level;
105  int i, j;
106  QuadMapCoords& up() { --level; i /= 2; j /= 2; return *this; };
107  QuadMapCoords& down() { ++level; i *= 2; j *= 2; return *this; };
108  };
109 
110 
111  friend class Quad;
112  class Quad {
113  public:
114 
115  enum Placement {UP, RIGHT, DOWN, LEFT}; // order is important!
116 
117  struct Point {
118  Point(int number, Placement p) : ndx(number), placement(p) {};
119  int ndx; // number of point
120  Placement placement;
121  inline bool operator==(const Point& other) const { return ndx == other.ndx && placement == other.placement; };
122  };
123 
124 
126  inline bool operator()(const Point& p1, const Point& p2);
127  };
128 
129  typedef set<Point, PointComparator> QPoints;
130 
131  Quad(int vul, int vur, int vdr, int vdl);
132 
133  void add_points(const QPoints& ps, const Placement& p);
134 
135  QPoints get_points(const Placement& p) const;
136 
137  const QPoints& points() const { return qpoints; };
138  const vector<Point>& angles() const { return qangles; };
139  private:
140  QPoints qpoints;
141  vector<Point> qangles;
142  };
143 
144 
146  TrigPointComparator(PointsKeeper* p) : pKeeper(p) {};
147  bool operator()(const Quad::Point&, const Quad::Point&);
148  private:
149  PointsKeeper* pKeeper;
150  };
151  typedef set<Quad::Point, TrigPointComparator> QTrigPoints;
152 
153 
154  typedef map<QuadMapCoords, Quad, QuadMapCoords> QuadMap;
155  typedef vector<QuadMap> QuadMapVector;
156 
157 
158 
159  bool checkUpCoord(QuadMapCoords cmc);
160 
161 
162  QuadMapVector quadMapVector;
163 
164 
165 
166 private:
167 
168  U3dBox modelBox;
169  double minTriangleSide;
170  double curvature;
171  double sqr_minTrSide; // minTriangleSide^2
172 
173  U3dBox m_box;
174 
175  void make_quads(QuadMapCoords cmc, double dp, double dq, double up, double uq,
176  int vul, int vur, int vdr, int vdl);
177 
178 
179  Quad::QPoints get_neighbour_points(QuadMapCoords cmc, const Quad::Placement& p);
180  inline int get_neighbour_point(QuadMapCoords cmc, const Quad::Placement& p);
181 
182  vector<int> max_coords;
183 
184  PointsKeeper pKeeper;
185 
186  CurvaturePlate curvPlate;
187 
188  int rgnlevel;
189  int rmqlevel;
190 
191  double minX, minY, minZ;
192  double maxX, maxY, maxZ;
193 
194 };
195 
196 
197 
198 #endif // U3D_CURVATURE_TRIANGLED_SURFACE_HPP_
199 
Definition: u3d_math_abstract_surface.hpp:11
Definition: u3d_curvature_triangled_surface.hpp:100
Definition: u3d_triangled_abstract_surface.hpp:31
Definition: u3d_curvature_triangled_surface.hpp:145
Definition: u3d_curvature_triangled_surface.hpp:125
Definition: u3d_box.hpp:24
Definition: u3d_curvature_triangled_surface.hpp:27
Definition: u3d_curvature_triangled_surface.hpp:76
Definition: u3d_curvature_triangled_surface.hpp:117
Definition: u3d_point.hpp:16
Definition: u3d_curvature_triangled_surface.hpp:112
Definition: u3d_curvature_triangled_surface.hpp:83
Definition: u3d_curvature_triangled_surface.hpp:54
Definition: u3d_curvature_triangled_surface.hpp:21