ICETools.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * @file ICETools.cpp
  3. * @brief simple ICE GUI tools
  4. * @author Erik Rodner
  5. * @date 03/13/2008
  6. */
  7. #include "core/image/ImageT.h"
  8. #include "core/vector/VectorT.h"
  9. #include "core/vector/MatrixT.h"
  10. #include <core/imagedisplay/ImageDisplay.h>
  11. #include <core/image/Filter.h>
  12. #include <core/image/Convert.h>
  13. #include <iostream>
  14. #include <core/image/RectT.h>
  15. #include "vislearning/baselib/ICETools.h"
  16. #include "core/basics/Exception.h"
  17. using namespace OBJREC;
  18. using namespace std;
  19. using namespace NICE;
  20. ICETools::ICETools()
  21. {
  22. }
  23. ICETools::~ICETools()
  24. {
  25. }
  26. void ICETools::selectRectangles ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
  27. {
  28. fthrow ( Exception, "ICETools::selectRectangles -- not yet implemented due to old ICE version." );
  29. // #ifndef NOVISUAL
  30. // // new NICE code
  31. // vector<RectT<double> > rectangles;
  32. // //TODO check this!
  33. // // NICE::selectRectangles ( panel, rectangles, "select rectangles" );
  34. // // selectRectangles ( panel, rectangles, "select rectangles" );
  35. //
  36. // for ( vector<RectT<double> >::const_iterator i = rectangles.begin();
  37. // i != rectangles.end(); i++ )
  38. // {
  39. // Vector vec (4);
  40. // vec[0] = i->left;
  41. // vec[1] = i->top;
  42. // vec[2] = i->right();
  43. // vec[3] = i->bottom();
  44. //
  45. // x.push_back ( vec );
  46. // }
  47. // #else
  48. // fprintf (stderr, "ICETools::selectRectangles: visualization disabled !\n");
  49. // #endif
  50. }
  51. void ICETools::selectPoints ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
  52. {
  53. fthrow ( Exception, "ICETools::selectPoints -- not yet implemented due to old ICE version." );
  54. // #ifndef NOVISUAL
  55. // vector<CoordT<double> > points;
  56. // //TODO check this!
  57. // // NICE::selectPoints ( panel, points, "select points" );
  58. // // selectPoints ( panel, points, "select points" );
  59. //
  60. // for ( vector<CoordT<double> >::const_iterator i = points.begin();
  61. // i != points.end(); i++ )
  62. // {
  63. // Vector vec (2);
  64. // vec[0] = i->x;
  65. // vec[1] = i->y;
  66. //
  67. // x.push_back ( vec );
  68. // }
  69. //
  70. // /** OLD ICE Code
  71. // int p[2];
  72. // int rc = -1;
  73. //
  74. // while ( (rc = SelPoint ( DEFAULT, panel, p )) != -1 )
  75. // {
  76. // int x1, y1;
  77. // x1 = p[0]; y1 = p[1];
  78. // // refactor-nice.pl: check this substitution
  79. // // old: Marker ( DEFAULT, p[0], p[1], color, 5, overlay );
  80. // // REFACTOR-FIXME Unable to map this statement
  81. // // refactor-nice.pl: check this substitution
  82. // // old: x.push_back ( Vector(x1, y1) );
  83. // // REFACTOR-FIXME Unable to std::map this statement
  84. // }
  85. // */
  86. // #else
  87. // fprintf (stderr, "ICETools::selectPoints: visualization disabled !\n");
  88. // #endif
  89. }
  90. void ICETools::convertToRGB ( const NICE::Matrix & m, NICE::ColorImage & img )
  91. {
  92. matrixToPseudoColor(m, img);
  93. }
  94. void ICETools::convertToRGB ( const NICE::FloatImage & m, NICE::ColorImage & img )
  95. {
  96. imageToPseudoColor(m, img);
  97. }
  98. void ICETools::calcGrayImage ( const NICE::ColorImage & img, NICE::Image & imgg )
  99. {
  100. imgg.resize ( img.width(), img.height() );
  101. for ( int y = 0 ; y < img.height(); y++ )
  102. for ( int x = 0 ; x < img.width() ; x++ )
  103. {
  104. unsigned char g = ( unsigned char ) ( 0.299 * img.getPixel ( x, y, 0 ) +
  105. 0.587 * img.getPixel ( x, y, 1 ) + 0.114 * img.getPixel ( x, y, 2 ) );
  106. imgg.setPixel ( x, y, g );
  107. }
  108. }
  109. double *ICETools::convertICE2M ( const NICE::Matrix & M )
  110. {
  111. double *raw = new double [ M.rows() * M.cols() ];
  112. long index = 0;
  113. for ( uint i = 0 ; i < M.rows() ; i++ )
  114. for ( uint j = 0 ; j < M.cols() ; j++, index++ )
  115. raw[index] = M ( i, j );
  116. return raw;
  117. }
  118. void ICETools::convertM2ICE ( NICE::Matrix & M, double *raw )
  119. {
  120. long index = 0;
  121. for ( int i = 0 ; i < ( int ) M.rows() ; i++ )
  122. for ( int j = 0 ; j < ( int ) M.cols() ; j++, index++ )
  123. M ( i, j ) = raw[index];
  124. }
  125. #ifndef NOVISUAL
  126. int ICETools::markImage ( const NICE::Image & img, NICE::Image & mark, int marksize, int color )
  127. {
  128. fprintf ( stderr, "ICETools::markImage: reimplement this function for NICE\n" );
  129. exit ( -1 );
  130. /*
  131. int flags;
  132. int p[2];
  133. int xo = -1;
  134. int yo = -1;
  135. while(1) {
  136. // refactor-nice.pl: check this substitution
  137. // old: flags = Mouse(img,p[0],p[1]);
  138. // REFACTOR-FIXME Unable to map this statement
  139. if ( (flags & M_LEFT_DOWN) > 0 ) {
  140. if ( (p[0] != xo) || (p[1] != yo) ) {
  141. if ( marksize == 1 ) {
  142. // refactor-nice.pl: check this substitution
  143. // old: PutVal( mark, p[0], p[1], color );
  144. mark.setPixel(p[0],p[1],color);
  145. } else {
  146. // refactor-nice.pl: check this substitution
  147. // old: Marker(3, p[0], p[1], color, marksize, mark);
  148. // REFACTOR-FIXME Unable to map this statement
  149. }
  150. xo = p[0];
  151. yo = p[1];
  152. }
  153. }
  154. if ( (flags & M_RIGHT_DOWN) > 0 ) {
  155. while ( (flags & M_RIGHT_DOWN) > 0 ) {
  156. // refactor-nice.pl: check this substitution
  157. // old: flags = Mouse(img,p[0],p[1]);
  158. // REFACTOR-FIXME Unable to map this statement
  159. };
  160. return -1;
  161. }
  162. }
  163. */
  164. return 0;
  165. }
  166. // refactor-nice.pl: check this substitution
  167. // old: int ICETools::showImages ( vector<Image> & imagelist )
  168. int ICETools::showImages ( vector<NICE::Image> & imagelist )
  169. {
  170. #ifndef NOVISUAL
  171. for ( size_t j = 0 ; j < imagelist.size() ; j++ )
  172. {
  173. // refactor-nice.pl: check this substitution
  174. // old: Show(ON, imagelist[j]);
  175. showImage ( imagelist[j] );
  176. }
  177. #endif
  178. // assumption: same size
  179. // refactor-nice.pl: check this substitution
  180. // old: int xsize = imagelist[0]->xsize;
  181. int xsize = imagelist[0].width();
  182. // refactor-nice.pl: check this substitution
  183. // old: int ysize = imagelist[0]->ysize;
  184. int ysize = imagelist[0].height();
  185. int n = imagelist.size();
  186. int n1 = ( int ) sqrt ( (double)n );
  187. int n2 = n / n1 + 1;
  188. NICE::Image img ( n1*xsize, n2*ysize );
  189. img.set ( 0 );
  190. int k = 0;
  191. for ( int j = 0 ; j < n2 ; j++ )
  192. for ( int i = 0 ; i < n1 ; i++, k++ )
  193. if ( k >= n ) break;
  194. else {
  195. for ( int y = 0 ; y < imagelist[k].height(); y++ )
  196. for ( int x = 0 ; x < imagelist[k].width(); x++ )
  197. {
  198. img.setPixel ( i*xsize + x, j*ysize + y,
  199. imagelist[k].getPixel ( x, y ) );
  200. }
  201. }
  202. img.write ( "display.bmp" );
  203. getchar();
  204. return 0;
  205. }
  206. #endif