Wed, 05 Aug 2009 15:00:54 +0100
small changes to hexdump code to stop a gcc warning on platforms where sizeof(int) != sizeof(int*) e.g. x86_64
philpem@5 | 1 | /* |
philpem@5 | 2 | # |
philpem@5 | 3 | # File : pde_heatflow2D.cpp |
philpem@5 | 4 | # ( C++ source file ) |
philpem@5 | 5 | # |
philpem@5 | 6 | # Description : A simple Heat flow on 2D images. |
philpem@5 | 7 | # This file is a part of the CImg Library project. |
philpem@5 | 8 | # ( http://cimg.sourceforge.net ) |
philpem@5 | 9 | # |
philpem@5 | 10 | # Copyright : David Tschumperle |
philpem@5 | 11 | # ( http://www.greyc.ensicaen.fr/~dtschump/ ) |
philpem@5 | 12 | # |
philpem@5 | 13 | # License : CeCILL v2.0 |
philpem@5 | 14 | # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) |
philpem@5 | 15 | # |
philpem@5 | 16 | # This software is governed by the CeCILL license under French law and |
philpem@5 | 17 | # abiding by the rules of distribution of free software. You can use, |
philpem@5 | 18 | # modify and/ or redistribute the software under the terms of the CeCILL |
philpem@5 | 19 | # license as circulated by CEA, CNRS and INRIA at the following URL |
philpem@5 | 20 | # "http://www.cecill.info". |
philpem@5 | 21 | # |
philpem@5 | 22 | # As a counterpart to the access to the source code and rights to copy, |
philpem@5 | 23 | # modify and redistribute granted by the license, users are provided only |
philpem@5 | 24 | # with a limited warranty and the software's author, the holder of the |
philpem@5 | 25 | # economic rights, and the successive licensors have only limited |
philpem@5 | 26 | # liability. |
philpem@5 | 27 | # |
philpem@5 | 28 | # In this respect, the user's attention is drawn to the risks associated |
philpem@5 | 29 | # with loading, using, modifying and/or developing or reproducing the |
philpem@5 | 30 | # software by the user in light of its specific status of free software, |
philpem@5 | 31 | # that may mean that it is complicated to manipulate, and that also |
philpem@5 | 32 | # therefore means that it is reserved for developers and experienced |
philpem@5 | 33 | # professionals having in-depth computer knowledge. Users are therefore |
philpem@5 | 34 | # encouraged to load and test the software's suitability as regards their |
philpem@5 | 35 | # requirements in conditions enabling the security of their systems and/or |
philpem@5 | 36 | # data to be ensured and, more generally, to use and operate it in the |
philpem@5 | 37 | # same conditions as regards security. |
philpem@5 | 38 | # |
philpem@5 | 39 | # The fact that you are presently reading this means that you have had |
philpem@5 | 40 | # knowledge of the CeCILL license and that you accept its terms. |
philpem@5 | 41 | # |
philpem@5 | 42 | */ |
philpem@5 | 43 | |
philpem@5 | 44 | // Include library header file |
philpem@5 | 45 | #include "CImg.h" |
philpem@5 | 46 | |
philpem@5 | 47 | // Make a simpler namespace alias if one wants to avoid 'using namespace cimg_library' |
philpem@5 | 48 | namespace cil = cimg_library; |
philpem@5 | 49 | |
philpem@5 | 50 | #ifndef cimg_imagepath |
philpem@5 | 51 | #define cimg_imagepath "img/" |
philpem@5 | 52 | #endif |
philpem@5 | 53 | |
philpem@5 | 54 | //--------------------- |
philpem@5 | 55 | // Begin main procedure |
philpem@5 | 56 | //--------------------- |
philpem@5 | 57 | int main(int argc,char **argv) { |
philpem@5 | 58 | |
philpem@5 | 59 | // Read command line arguments, and init images and displays |
philpem@5 | 60 | //----------------------------------------------------------- |
philpem@5 | 61 | cimg_usage("Perform a simple Heat Flow on 2D images"); |
philpem@5 | 62 | cil::CImg<> img(cimg_option("-i",cimg_imagepath "milla.bmp","Input image")), veloc(img); |
philpem@5 | 63 | const double dt = cimg_option("-dt",3.0,"Adapting time step"); |
philpem@5 | 64 | img. |
philpem@5 | 65 | noise(cimg_option("-ng",0.0,"Add gaussian noise"),0). |
philpem@5 | 66 | noise(cimg_option("-nu",0.0,"Add uniform noise"),1). |
philpem@5 | 67 | noise(cimg_option("-ns",0.0,"Add Salt&Pepper noise"),2); |
philpem@5 | 68 | cil::CImgDisplay profile(400,300,"Intensity Profile",0,false,true), disp(img,"Heat flow 2D",0,false,true); |
philpem@5 | 69 | disp.move((cil::CImgDisplay::screen_dimx()-disp.dimx()-profile.dimx())/2, |
philpem@5 | 70 | (cil::CImgDisplay::screen_dimy()-disp.dimy())/2); |
philpem@5 | 71 | |
philpem@5 | 72 | profile.move(disp.window_x + 8 + disp.window_width, disp.window_y); |
philpem@5 | 73 | CImg_3x3(I,float); |
philpem@5 | 74 | float white[] = { 255,255,255 }; |
philpem@5 | 75 | bool run_PDE = true; |
philpem@5 | 76 | |
philpem@5 | 77 | // Begin PDE iteration loop |
philpem@5 | 78 | //------------------------- |
philpem@5 | 79 | for (int iter=0; !disp.is_closed && !profile.is_closed && !disp.is_keyQ && !disp.is_keyESC && !profile.is_keyQ && !profile.is_keyESC;) { |
philpem@5 | 80 | |
philpem@5 | 81 | // Compute one iteration of PDE explicit scheme |
philpem@5 | 82 | if (run_PDE) { |
philpem@5 | 83 | cimg_forV(img,k) cimg_for3x3(img,x,y,0,k,I) veloc(x,y,k) = Inc + Ipc + Icn + Icp - 4*Icc; |
philpem@5 | 84 | float m, M = veloc.maxmin(m); |
philpem@5 | 85 | const double xdt = dt/(M-m); |
philpem@5 | 86 | img += veloc*xdt; |
philpem@5 | 87 | cil::CImg<>(img).draw_text(2,2,"iter = %d",white,0,1,13,iter).display(disp.wait(25)); |
philpem@5 | 88 | } |
philpem@5 | 89 | |
philpem@5 | 90 | // Plot (R,G,B) intensity profiles and display it |
philpem@5 | 91 | if (disp.mouse_x>=0) { |
philpem@5 | 92 | const int |
philpem@5 | 93 | mx = disp.mouse_x, my = disp.mouse_y, |
philpem@5 | 94 | mnx = mx*profile.dimx()/disp.dimx(); |
philpem@5 | 95 | const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 }, white[] = { 255,255,255 }; |
philpem@5 | 96 | cil::CImg<unsigned char>(profile.dimx(),profile.dimy(),1,3,0). |
philpem@5 | 97 | draw_graph(img.get_shared_line(my,0,0),red,1,1,0,255,0). |
philpem@5 | 98 | draw_graph(img.get_shared_line(my,0,1),green,1,1,0,255,0). |
philpem@5 | 99 | draw_graph(img.get_shared_line(my,0,2),blue,1,1,0,255,0). |
philpem@5 | 100 | draw_line(mnx,0,mnx,profile.dimy()-1,white,0.5f,cil::cimg::rol(0xFF00FF00,iter%32)). |
philpem@5 | 101 | draw_text(2,2,"(x,y)=(%d,%d)",white,0,1,13,mx,my). |
philpem@5 | 102 | display(profile); |
philpem@5 | 103 | } |
philpem@5 | 104 | |
philpem@5 | 105 | // Mouse button stops/starts PDE evolution. |
philpem@5 | 106 | if (disp.button || profile.button) { disp.button = profile.button = 0; run_PDE = !run_PDE; } |
philpem@5 | 107 | profile.resize(); |
philpem@5 | 108 | disp.resize(disp); |
philpem@5 | 109 | if (run_PDE) ++iter; |
philpem@5 | 110 | } |
philpem@5 | 111 | |
philpem@5 | 112 | return 0; |
philpem@5 | 113 | } |