Go to the documentation of this file.00001
00002 #ifndef imesh_render_h_
00003 #define imesh_render_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <imesh/imesh_mesh.h>
00016 #include <vil/vil_image_view.h>
00017 #include <vgl/vgl_point_3d.h>
00018 #include <vgl/vgl_vector_3d.h>
00019 #include <vgl/vgl_triangle_scan_iterator.h>
00020 #include <vpgl/vpgl_proj_camera.h>
00021 #include <vcl_cassert.h>
00022
00023
00024
00025
00026
00027
00028 template <class T>
00029 void imesh_render_triangle_label(const vgl_point_3d<double>& v1,
00030 const vgl_point_3d<double>& v2,
00031 const vgl_point_3d<double>& v3,
00032 const T& label,
00033 vil_image_view<T>& image,
00034 vil_image_view<double>& depth_img)
00035 {
00036 assert(depth_img.ni() == image.ni());
00037 assert(depth_img.nj() == image.nj());
00038
00039 vgl_triangle_scan_iterator<double> tsi;
00040 tsi.a.x = v1.x(); tsi.a.y = v1.y();
00041 tsi.b.x = v2.x(); tsi.b.y = v2.y();
00042 tsi.c.x = v3.x(); tsi.c.y = v3.y();
00043 vgl_vector_3d<double> b1(v2.x()-v1.x(), v2.y()-v1.y(), v2.z()-v1.z());
00044 vgl_vector_3d<double> b2(v3.x()-v1.x(), v3.y()-v1.y(), v3.z()-v1.z());
00045 vgl_vector_3d<double> n = cross_product(b1,b2);
00046 double A = -n.x()/n.z();
00047 double B = -n.y()/n.z();
00048 double C = (v1.x()*n.x() + v1.y()*n.y() + v1.z()*n.z())/n.z();
00049 for (tsi.reset(); tsi.next(); ) {
00050 int y = tsi.scany();
00051 if (y<0 || y>=int(image.nj())) continue;
00052 int min_x = tsi.startx();
00053 int max_x = tsi.endx();
00054 if (min_x >= (int)image.ni() || max_x < 0)
00055 continue;
00056 if (min_x < 0) min_x = 0;
00057 if (max_x >= (int)image.ni()) max_x = image.ni()-1;
00058 double new_i = B*y+C;
00059 for (int x = min_x; x <= max_x; ++x) {
00060 double depth = new_i + A*x;
00061 if (depth < depth_img(x,y)) {
00062 depth_img(x,y) = depth;
00063 image(x,y) = label;
00064 }
00065 }
00066 }
00067 }
00068
00069
00070
00071
00072
00073 void imesh_render_triangle_texture(const vgl_point_3d<double>& v1,
00074 const vgl_point_3d<double>& v2,
00075 const vgl_point_3d<double>& v3,
00076 const vgl_point_2d<double>& t1,
00077 const vgl_point_2d<double>& t2,
00078 const vgl_point_2d<double>& t3,
00079 const vil_image_view<vxl_byte>& texture,
00080 vil_image_view<vxl_byte>& image,
00081 vil_image_view<double>& depth_img);
00082
00083
00084
00085
00086
00087
00088 void imesh_render_textured(const imesh_mesh& mesh,
00089 const vpgl_proj_camera<double>& camera,
00090 const vil_image_view<vxl_byte>& texture,
00091 vil_image_view<vxl_byte>& image,
00092 vil_image_view<double>& depth_img);
00093
00094 #endif // imesh_render_h_