00001
00002 #ifndef imesh_imls_surface_txx_
00003 #define imesh_imls_surface_txx_
00004 #include "imesh_imls_surface.h"
00005
00006
00007
00008 #include <imesh/imesh_operations.h>
00009 #include <imesh/algo/imesh_intersect.h>
00010 #include <imesh/algo/imesh_kd_tree.txx>
00011 #include <vcl_cassert.h>
00012
00013
00014
00015
00016 template <class T, class F>
00017 T
00018 imesh_imls_surface::triangle_quadrature(F quad_func,
00019 const vgl_point_3d<double>& x,
00020 const vgl_point_3d<double>& p0,
00021 const vgl_point_3d<double>& p1,
00022 const vgl_point_3d<double>& p2,
00023 const vgl_vector_3d<double>& n,
00024 double v0, double v1, double v2,
00025 double eps)
00026 {
00027 double dist,u,v;
00028 unsigned char flag = imesh_triangle_closest_point(x,p0,p1,p2,n,dist,u,v);
00029 switch (flag)
00030 {
00031 case 1:
00032 return quad_func(x,p0,p1,p2,v0,v1,v2,eps);
00033 case 2:
00034 return quad_func(x,p1,p2,p0,v1,v2,v0,eps);
00035 case 4:
00036 return quad_func(x,p2,p0,p1,v2,v0,v1,eps);
00037
00038 case 3:
00039 {
00040 double t = 1.0-u;
00041 vgl_point_3d<double> pi(t*p0.x()+u*p1.x(), t*p0.y()+u*p1.y(), t*p0.z()+u*p1.z());
00042 double vi = t*v0 + u*v1;
00043 return quad_func(x,pi,p2,p0,vi,v2,v0,eps)
00044 + quad_func(x,pi,p1,p2,vi,v1,v2,eps);
00045 }
00046
00047 case 6:
00048 {
00049 vgl_point_3d<double> pi(u*p1.x()+v*p2.x(), u*p1.y()+v*p2.y(), u*p1.z()+v*p2.z());
00050 double vi = u*v1 + v*v2;
00051 return quad_func(x,pi,p0,p1,vi,v0,v1,eps)
00052 + quad_func(x,pi,p2,p0,vi,v2,v0,eps);
00053 }
00054
00055 case 5:
00056 {
00057 double t = 1.0-v;
00058 vgl_point_3d<double> pi(t*p0.x()+v*p2.x(), t*p0.y()+v*p2.y(), t*p0.z()+v*p2.z());
00059 double vi = t*v0 + v*v2;
00060 return quad_func(x,pi,p0,p1,vi,v0,v1,eps)
00061 + quad_func(x,pi,p1,p2,vi,v1,v2,eps);
00062 }
00063
00064 case 7:
00065 {
00066 double t = 1.0-u-v;
00067 vgl_point_3d<double> pi(t*p0.x()+u*p1.x()+v*p2.x(),
00068 t*p0.y()+u*p1.y()+v*p2.y(),
00069 t*p0.z()+u*p1.z()+v*p2.z());
00070 double vi = t*v0 + u*v1 + v*v2;
00071 return quad_func(x,pi,p0,p1,vi,v0,v1,eps)
00072 + quad_func(x,pi,p1,p2,vi,v1,v2,eps)
00073 + quad_func(x,pi,p2,p0,vi,v2,v0,eps);
00074 }
00075 default:
00076 assert(!"invalid flag");
00077 }
00078 return T();
00079 }
00080
00081 #define IMESH_IMLS_SURFACE_INSTANTATE(T1,T2) \
00082 template T1 imesh_imls_surface::triangle_quadrature(T1(*)(T2 const&, T2 const&, T2 const&, T2 const&, double, double, double, double), \
00083 const vgl_point_3d<double>& x, \
00084 const vgl_point_3d<double>& p0, \
00085 const vgl_point_3d<double>& p1, \
00086 const vgl_point_3d<double>& p2, \
00087 const vgl_vector_3d<double>& n, \
00088 double v0, double v1, double v2, \
00089 double eps)
00090
00091 #endif // imesh_imls_surface_txx_