source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/geom/3D.h @ 1526

Revision 1526, 2.3 KB checked in by gumbau, 18 years ago (diff)

Updated modules to the new interface and the new simplification algorithm improvements.

Line 
1#ifndef GFXGEOM_3D_INCLUDED // -*- C++ -*-
2#define GFXGEOM_3D_INCLUDED
3
4#include <gfx/math/Vec3.h>
5#include <gfx/math/Vec4.h>
6#include <gfx/tools/Array.h>
7
8//
9// Generally useful geometric functions
10//
11
12namespace simplif
13{
14        extern Vec3 randomPoint(const Vec3&, const Vec3&);  // on segment
15        extern Vec3 randomPoint(const Vec3&, const Vec3&, const Vec3&); // in triangle
16
17        extern real triangleArea(const Vec3&, const Vec3&, const Vec3&);
18        extern real triangleCompactness(const Vec3&, const Vec3&, const Vec3&);
19
20        class Bounds
21        {
22        public:
23
24                Vec3 min, max;
25                Vec3 center;
26                real radius;
27                unsigned int points;
28
29                Bounds() { reset(); }
30
31                void reset();
32                void addPoint(const Vec3&);
33                void complete();
34        };
35
36        class Plane
37        {
38                //
39                // A plane is defined by the equation:  n*p + d = 0
40                Vec3 n;
41                real d;
42
43        public:
44
45                Plane() : n(0,0,1) { d=0; } // -- this will define the XY plane
46                Plane(const Vec3& p, const Vec3& q, const Vec3& r) { calcFrom(p,q,r); }
47                Plane(const array<Vec3>& verts) { calcFrom(verts); }
48                Plane(const Plane& p) { n=p.n; d=p.d; }
49
50                void calcFrom(const Vec3& p, const Vec3& q, const Vec3& r);
51                void calcFrom(const array<Vec3>&);
52
53                bool isValid() const { return n[X]!=0.0 || n[Y]!=0.0 || n[Z]!= 0.0; }
54                void markInvalid() { n[X] = n[Y] = n[Z] = 0.0; }
55
56                real distTo(const Vec3& p) const { return n*p + d; }
57                const Vec3& normal() const { return n; }
58
59                void coeffs(real *a, real *b, real *c, real *dd) const {
60                        *a=n[X]; *b=n[Y]; *c=n[Z]; *dd=d;
61                }
62                Vec4 coeffs() const { return Vec4(n,d); }
63        };
64
65        //
66        // A triangular face in 3D (ie. a 2-simplex in E3)
67        //
68        class Face3
69        {
70        protected:
71                Plane P;
72
73        private:
74                void recalcPlane() { P.calcFrom(vertexPos(0),vertexPos(1),vertexPos(2)); }
75                void recalcPlane(const Vec3& a,const Vec3& b,const Vec3& c)
76                { P.calcFrom(a,b,c); }
77
78        public:
79                Face3(const Vec3& a,const Vec3& b,const Vec3& c)
80                : P(a,b,c)
81                { }
82
83                //
84                // Basic primitive operations on faces
85                virtual const Vec3& vertexPos(int i) const = 0;
86                virtual void vertexPos(int i, const Vec3&) = 0;
87                const Plane& plane() { if(!P.isValid()) recalcPlane();   return P;}
88                void invalidatePlane() { P.markInvalid(); }
89
90                real distTo(const Vec3& p) const;
91                real area();
92        };
93}
94
95// GFXGEOM_3D_INCLUDED
96#endif
Note: See TracBrowser for help on using the repository browser.