Go to the documentation of this file.00001 #ifndef bvgl_triangle_interpolation_iterator_txx_
00002 #define bvgl_triangle_interpolation_iterator_txx_
00003
00004
00005
00006 #include "bvgl_triangle_interpolation_iterator.h"
00007
00008 #include <vnl/algo/vnl_determinant.h>
00009 #include <vcl_vector.h>
00010 #include <vcl_cmath.h>
00011 #include <vcl_algorithm.h>
00012 #include <vcl_iostream.h>
00013
00014
00015
00016 template<class T>
00017 bvgl_triangle_interpolation_iterator<T>::bvgl_triangle_interpolation_iterator(double *verts_x, double *verts_y, T *vals, unsigned int v0, unsigned int v1, unsigned int v2)
00018 : tri_it_()
00019 {
00020 tri_it_.a.x = verts_x[v0] - 0.5;
00021 tri_it_.a.y = verts_y[v0] - 0.5;
00022 tri_it_.b.x = verts_x[v1] - 0.5;
00023 tri_it_.b.y = verts_y[v1] - 0.5;
00024 tri_it_.c.x = verts_x[v2] - 0.5;
00025 tri_it_.c.y = verts_y[v2] - 0.5;
00026
00027
00028
00029 double Acol0[] = {tri_it_.a.x + 0.5, tri_it_.b.x + 0.5, tri_it_.c.x + 0.5};
00030 double Acol1[] = {tri_it_.a.y + 0.5, tri_it_.b.y + 0.5, tri_it_.c.y + 0.5};
00031 double Acol2[] = {1.0, 1.0, 1.0};
00032
00033 double Z[] = {vals[v0], vals[v1], vals[v2]};
00034
00035 double detA = vnl_determinant(Acol0, Acol1, Acol2);
00036 s0_ = vnl_determinant(Z, Acol1, Acol2) / detA;
00037 s1_ = vnl_determinant(Acol0, Z, Acol2) / detA;
00038 s2_ = vnl_determinant(Acol0, Acol1, Z) / detA;
00039
00040
00041 }
00042
00043
00044
00045
00046
00047 template<class T>
00048 void bvgl_triangle_interpolation_iterator<T>::reset()
00049 {
00050 tri_it_.reset();
00051 }
00052
00053
00054
00055 template<class T>
00056 bool bvgl_triangle_interpolation_iterator<T>::next()
00057 {
00058 return tri_it_.next();
00059 }
00060
00061
00062 template<class T>
00063 int bvgl_triangle_interpolation_iterator<T>::scany() const
00064 {
00065 return tri_it_.scany();
00066 }
00067
00068
00069
00070 template<class T>
00071 int bvgl_triangle_interpolation_iterator<T>::startx() const
00072 {
00073 return tri_it_.startx();
00074 }
00075
00076
00077
00078 template<class T>
00079 int bvgl_triangle_interpolation_iterator<T>::endx() const
00080 {
00081 return tri_it_.endx() + 1;
00082 }
00083
00084
00085
00086 template<class T>
00087 T bvgl_triangle_interpolation_iterator<T>::value_at(int x)
00088 {
00089 return (T)((s0_*(x+0.5) + s1_*(tri_it_.scany()+0.5) + s2_));
00090 }
00091
00092
00093 #define BVGL_TRIANGLE_INTERPOLATION_ITERATOR_INSTANTIATE(T) \
00094 template class bvgl_triangle_interpolation_iterator<T >
00095
00096
00097 #endif