Go to the documentation of this file.00001
00002 #ifndef vimt3d_reconstruct_from_grid_h_
00003 #define vimt3d_reconstruct_from_grid_h_
00004
00005
00006
00007
00008
00009 #include <vimt3d/vimt3d_image_3d_of.h>
00010 #include <vnl/vnl_fwd.h>
00011 #include <vgl/vgl_fwd.h>
00012 #include <vnl/vnl_math.h>
00013 #include <vcl_cassert.h>
00014
00015
00016
00017
00018
00019
00020 template<class T>
00021 inline void vimt3d_reconstruct_ic_safe(double val, double x, double y, double z,
00022 T* data, int ni, int nj, int nk,
00023 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep, vcl_ptrdiff_t zstep, bool add_data)
00024 {
00025 int ix=vnl_math_rnd(x);
00026 int iy=vnl_math_rnd(y);
00027 int iz=vnl_math_rnd(z);
00028 vcl_ptrdiff_t index = (ix *xstep) + (iy *ystep) + (iz *zstep);
00029
00030
00031 if (add_data)
00032 {
00033 if (ix>=0 && iy>=0 && iz>=0
00034 && ix<=(ni-1) && iy<=(nj-1) && iz<(nk-1) )
00035 {
00036 data[index] += T(val);
00037 }
00038 }
00039 else
00040 {
00041 if (ix>=0 && iy>=0 && iz>=0
00042 && ix<=(ni-1) && iy<=(nj-1) && iz<(nk-1) )
00043 {
00044 data[index] = T(val);
00045 }
00046 }
00047
00048 return;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057 template<class T>
00058 inline void vimt3d_reconstruct_ic_no_checks(double val, double x, double y, double z,
00059 T* data, int ni, int nj, int nk,
00060 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep, vcl_ptrdiff_t zstep, bool add_data)
00061 {
00062 int ix=vnl_math_rnd(x);
00063 int iy=vnl_math_rnd(y);
00064 int iz=vnl_math_rnd(z);
00065 assert (ix >= 0 && ix < ni);
00066 assert (iy >= 0 && iy < nj);
00067 assert (iz >= 0 && iz < nk);
00068 vcl_ptrdiff_t index = (ix *xstep) + (iy *ystep) + (iz *zstep);
00069
00070
00071 double new_val = add_data ? data[index]+val : val;
00072 data[index] = T(new_val);
00073 #if 0 // doesn't seem to help ...
00074
00075 if (T(new_val + 1e-2) == T(new_val + 1e-1))
00076 data[index] = T(new_val+1e-2);
00077 #endif
00078
00079 return;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089 template <class imType, class vecType>
00090 void vimt3d_reconstruct_from_grid(vimt3d_image_3d_of<imType>& image,
00091 const vnl_vector<vecType>& vec,
00092 const vgl_point_3d<double>& p,
00093 const vgl_vector_3d<double>& u,
00094 const vgl_vector_3d<double>& v,
00095 const vgl_vector_3d<double>& w,
00096 int nu, int nv, int nw, bool add_data);
00097
00098
00099
00100
00101
00102
00103
00104
00105 template <class imType, class vecType>
00106 void vimt3d_reconstruct_from_grid_ic(vil3d_image_view<imType>& image,
00107 const vnl_vector<vecType>& vec,
00108 const vgl_point_3d<double>& im_p,
00109 const vgl_vector_3d<double>& im_u,
00110 const vgl_vector_3d<double>& im_v,
00111 const vgl_vector_3d<double>& im_w,
00112 int nu, int nv, int nw, bool add_data);
00113
00114 #endif // vimt3d_reconstruct_from_grid_h_