libidxgui
|
00001 /*************************************************************************** 00002 * Copyright (C) 2009 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef IDXGUI_HPP_ 00034 #define IDXGUI_HPP_ 00035 00036 using namespace std; 00037 00038 namespace ebl { 00039 00040 template<class T> 00041 void idxgui::draw_matrix(idx<T> &im, unsigned int h0, unsigned int w0, 00042 double zoomh, double zoomw, T minv, T maxv) { 00043 idx<ubyte> *uim = new idx<ubyte>(image_to_ubyte<T>(im, zoomh, zoomw, 00044 minv, maxv)); 00045 // send image to main gui thread 00046 emit gui_drawImage(uim, h0, w0); 00047 } 00048 00049 template<class T> 00050 void idxgui::draw_matrix(idx<T> &im, unsigned int h0, unsigned int w0) { 00051 idx<ubyte> *uim = new idx<ubyte>(im.get_idxdim()); 00052 // cast data 00053 idx_copy(im, *uim); 00054 // send image to main gui thread 00055 emit gui_drawImage(uim, h0, w0); 00056 } 00057 00058 template<class T> 00059 void idxgui::draw_matrix(idx<T> &im, const char *str, 00060 unsigned int h0, unsigned int w0, 00061 double zoomh, double zoomw, T minv, T maxv) { 00062 draw_matrix(im, h0, w0, zoomh, zoomw, minv, maxv); 00063 if (str) 00064 (*this) << white_on_transparent() << gui_only() << at(h0, w0) << str; 00065 } 00066 00067 template<class T> 00068 void idxgui::draw_matrix_frame(idx<T> &im, ubyte r, ubyte g, ubyte b, 00069 unsigned int h0, unsigned int w0, 00070 double zoomh, double zoomw, 00071 T minv, T maxv) { 00072 idx<ubyte> uim = image_to_ubyte<T>(im, zoomh, zoomw, minv, maxv); 00073 idx<ubyte> tmp(uim.dim(0) + 2, uim.dim(1) + 2); 00074 idx<ubyte> *fim = new idx<ubyte>(tmp); 00075 idx<ubyte> tmp2 = tmp.narrow(0, uim.dim(0), 1); 00076 tmp2 = tmp2.narrow(1, uim.dim(1), 1); 00077 idx_copy(uim, tmp2); 00078 tmp2 = tmp.narrow(0, 1, 0); idx_fill(tmp2, r); 00079 tmp2 = tmp.narrow(0, 1, tmp.dim(0) - 1); idx_fill(tmp2, r); 00080 tmp2 = tmp.narrow(1, 1, 0); idx_fill(tmp2, r); 00081 tmp2 = tmp.narrow(1, 1, tmp.dim(1) - 1); idx_fill(tmp2, r); 00082 // send image to main gui thread 00083 emit gui_drawImage(fim, h0, w0); 00084 } 00085 00086 template<class T> 00087 void idxgui::draw_mask(idx<T> &im, uint h0, uint w0, 00088 double zoomh, double zoomw, 00089 ubyte r, ubyte g, ubyte b, ubyte a, T threshold) { 00090 idx<float> binary(im.get_idxdim()); 00091 idx_threshold(im, (T) threshold, (float) 1.0, (float) 0.0, binary); 00092 idx<ubyte> *uim = new idx<ubyte> 00093 (image_to_ubyte<float>(binary, zoomh, zoomw, (float) 0.5, (float) .6)); 00094 // QT mask works with rgb input, TODO: find how to use 2D also 00095 if (uim->order() == 2) { // replicate 2D into 3D rgb 00096 idx<ubyte> *rgb = new idx<ubyte>(uim->dim(0), uim->dim(1), 3); 00097 idx<ubyte> tmp = rgb->select(2, 0); 00098 idx_copy(*uim, tmp); 00099 tmp = rgb->select(2, 1); 00100 idx_copy(*uim, tmp); 00101 tmp = rgb->select(2, 2); 00102 idx_copy(*uim, tmp); 00103 delete uim; 00104 uim = rgb; 00105 } 00106 // send image to main gui thread 00107 emit gui_draw_mask(uim, h0, w0, r, g, b, a); 00108 } 00109 00110 template<class T1, class T2> 00111 idxgui& operator<<(idxgui& r, const ManipInfra<T1, T2> &manip) { 00112 manip(r); 00113 return r; 00114 } 00115 00116 template<class T> 00117 idxgui& operator<<(idxgui& r, const T val) { 00118 ostringstream o; 00119 o << val; 00120 r.draw_text(new std::string(o.str())); 00121 if (r.cout_output) 00122 cout << o.str() << flush; 00123 return r; 00124 } 00125 00126 } // end namespace ebl 00127 00128 #endif /* IDXGUI_HPP_ */