GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/Geometry/QEM.h
00001 #ifndef __GEOMETRY_QEM_H
00002 #define __GEOMETRY_QEM_H
00003 
00004 #include <cfloat>
00005 #include "CGLA/Vec3d.h"
00006 #include "CGLA/Mat3x3d.h"
00007 
00008 
00009 namespace
00010 {
00011         inline const CGLA::Mat3x3d direct_product(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1)
00012                 {
00013                         CGLA::Mat3x3d m;
00014                         for(int i=0;i<3;++i)
00015                                 for(int j=0;j<3;++j)
00016                                         m[i][j] = v0[i]*v1[j];
00017                         return m;
00018                 }
00019 }
00020 
00021 namespace Geometry
00022 {
00023         class QEM
00024                 {
00025                         CGLA::Mat3x3d A;
00026                         CGLA::Vec3d   b;
00027                         double   c;
00028                 public:
00029                         
00030                         QEM(): A(0), b(0), c(0) {}
00031                         
00032                         QEM(const CGLA::Vec3d& p0, const CGLA::Vec3d& n0, double w=1.0f):
00033                                 A(direct_product(n0,n0) * w), 
00034                                 b(-2*n0*dot(n0,p0) * w), 
00035                                 c(dot(p0,n0)*dot(p0,n0) * w) {}
00036 
00037                         
00038                         void operator+=(const QEM& q)
00039                                 {
00040                                         A += q.A;
00041                                         b += q.b;
00042                                         c += q.c;
00043                                 }
00044                         
00045                         float error(const CGLA::Vec3d& p) const
00046                                 {
00047                                         return dot(p,A*p) + dot(b,p)+ c;
00048                                 }
00049 
00050                         double determinant() const
00051                                 {
00052                                         return CGLA::determinant(A);
00053                                 }
00054                         
00055                         const CGLA::Vec3d grad(const CGLA::Vec3d& p) const
00056                                 {
00057                                         return CGLA::Vec3d(2*A*p+b);
00058                                 }
00059                         
00060                         CGLA::Vec3d opt_pos(double QEM_thresh = 0.005, const CGLA::Vec3d& p0 = CGLA::Vec3d(0.0)) const;
00061                         
00062                 };
00063 }
00064 
00065 namespace GEO = Geometry;
00066 
00067 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations