latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiViewer.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 21.4.2000 00030 * revisions ..: $Id: ltiFastViewer.h,v 1.9 2006/02/08 12:56:09 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_FAST_VIEWER_H_ 00034 #define _LTI_FAST_VIEWER_H_ 00035 00036 #ifdef _LTI_WIN32 00037 #include "ltiViewer.h" 00038 #else 00039 #include "ltiViewerBase.h" 00040 #include "ltiImage.h" 00041 #include "ltiException.h" 00042 #include <X11/Intrinsic.h> 00043 #include <X11/StringDefs.h> 00044 #include <X11/extensions/XShm.h> 00045 #include <sys/shm.h> 00046 #include <X11/keysym.h> 00047 #include <sys/types.h> 00048 #include <sys/mman.h> 00049 #include <sys/fcntl.h> 00050 #include <sys/signal.h> 00051 #endif 00052 00053 #ifdef _LTI_MACOSX 00054 // this doesn't get defined on OS X with _XOPEN_SOURCE/_POSIX_C_SOURCE set 00055 extern int getdomainname (char*, int); 00056 #endif 00057 00058 namespace lti { 00059 00060 #ifdef _LTI_WIN32 00061 typedef viewer fastViewer; 00062 #else 00063 /** 00064 * Use objects of this class to display your data in a window. 00065 * 00066 * At this moment this works on Linux only!! For windows the GTK viewer 00067 * will be used instead... 00068 * 00069 * This viewer works only on true-color modes of the X-Server. So please 00070 * set your configuration to 24 or 32 bit-depth. If your program crashes, 00071 * remember to catch all std::exception and lti::exception, and ask for 00072 * a reason with their what() method. 00073 * 00074 * The use of the lti::fastViewer is very simple. Each viewer administrates 00075 * one window, and this window will exist as long as the viewer object 00076 * exists. This means, if you destroy the viewer-object, the window will 00077 * be automatically destroyed. 00078 * 00079 * If used in the localhost, a shared memory block will be used to transfer 00080 * the data between the application and the window. If used through the 00081 * X-Protocoll then this mechanism cannot be used and "normal" memory blocks 00082 * will serve for the data transfer. 00083 * 00084 * To use the viewer see following example: 00085 * 00086 * \code 00087 * 00088 * #include "ltiImage.h" 00089 * #include "ltiSplitImage.h" 00090 * #include "ltiFastViewer.h" 00091 * #include "ltiBMPFunctor.h" 00092 * 00093 * ... 00094 * 00095 * lti::image img; // an image 00096 * lti::channel chnl; // a channel 00097 * lti::splitImageTorgI splitter; // a functor to get the intensity channel 00098 * 00099 * lti::loadBMP loader; 00100 * 00101 * loader.load("yourImage.bmp",img); // load the image in the given file 00102 * splitter.getIntensity(img,chnl); // get the intensity channel of the img 00103 * 00104 * lti::fastViewer view1,view2; 00105 * 00106 * view1.show(img); // open a window and show the image 00107 * view2.show(chnl); // open a new window and show the 00108 * // intensity channel. 00109 * 00110 * ... 00111 * 00112 * // until the end of the execution block the images will be displayed. 00113 * // When view1 and view2 are destroyed, their windows will disappear! 00114 * 00115 * \endcode 00116 * 00117 */ 00118 class fastViewer : public viewerBase { 00119 public: 00120 /** 00121 * the parameters for the class viewer 00122 */ 00123 class parameters : public viewerBase::parameters { 00124 public: 00125 /** 00126 * default constructor 00127 */ 00128 parameters(); 00129 00130 /** 00131 * copy constructor 00132 */ 00133 parameters(const parameters& other); 00134 00135 /** 00136 * destructor 00137 */ 00138 virtual ~parameters(); 00139 00140 /** 00141 * copy member 00142 */ 00143 parameters& copy(const parameters& other); 00144 00145 /** 00146 * copy data of "other" parameters 00147 */ 00148 parameters& operator=(const parameters& other); 00149 00150 /** 00151 * returns a pointer to a clone of the parameters 00152 */ 00153 virtual functor::parameters* clone() const; 00154 00155 /** 00156 * returns name of this type 00157 */ 00158 const char* getTypeName() const; 00159 00160 /** 00161 * write the parameters in the given ioHandler 00162 * @param handler the ioHandler to be used 00163 * @param complete if true (the default) the enclosing begin/end will 00164 * be also written, otherwise only the data block will be written. 00165 * @return true if write was successful 00166 */ 00167 virtual bool write(ioHandler& handler, 00168 const bool complete=true) const; 00169 00170 /** 00171 * read the parameters from the given ioHandler 00172 * @param handler the ioHandler to be used 00173 * @param complete if true (the default) the enclosing begin/end will 00174 * be also written, otherwise only the data block will be written. 00175 * @return true if write was successful 00176 */ 00177 virtual bool read(ioHandler& handler,const bool complete=true); 00178 00179 # ifdef _LTI_MSC_6 00180 /** 00181 * this function is required by MSVC only, as a workaround for a 00182 * very awful bug, which exists since MSVC V.4.0, and still by 00183 * V.6.0 with all bugfixes (so called "service packs") remains 00184 * there... This method is public due to another bug!, so please 00185 * NEVER EVER call this method directly 00186 */ 00187 bool readMS(ioHandler& handler,const bool complete=true); 00188 00189 /** 00190 * this function is required by MSVC only, as a workaround for a 00191 * very awful bug, which exists since MSVC V.4.0, and still by 00192 * V.6.0 with all bugfixes (so called "service packs") remains 00193 * there... This method is public due to another bug!, so please 00194 * NEVER EVER call this method directly 00195 */ 00196 bool writeMS(ioHandler& handler,const bool complete=true) const; 00197 # endif 00198 00199 // ------------------------ 00200 // the parameters 00201 // ------------------------ 00202 00203 /** 00204 * top left corner of the viewer window. Default is (0,0) 00205 */ 00206 point topleft; 00207 00208 /** 00209 * If true, a borderless window is created. 00210 */ 00211 bool noBorder; 00212 }; 00213 00214 /** 00215 * default constructor 00216 * @param winName title of the viewer window 00217 */ 00218 fastViewer(const char* winName = "lti::fastViewer"); 00219 00220 /** 00221 * copy constructor 00222 * @param other the object to be copied 00223 */ 00224 fastViewer(const fastViewer& other); 00225 00226 /** 00227 * destructor 00228 */ 00229 virtual ~fastViewer(); 00230 00231 /** 00232 * returns the name of this type ("fastViewer") 00233 */ 00234 virtual const char* getTypeName() const; 00235 00236 /** 00237 * Sets the position of the window. This method will have an 00238 * effect only if the window has not yet been opened. 00239 */ 00240 void setPosition(const point& pos); 00241 00242 /** 00243 * shows an lti::image 00244 * @param data the object to be shown. 00245 */ 00246 bool show(const image& data); 00247 00248 /** 00249 * shows a 8-bit channel 00250 * @param data the object to be shown. 00251 * @return true if successful, false otherwise. 00252 */ 00253 virtual bool show(const channel8& data); 00254 00255 /** 00256 * shows a channel 00257 * @param data the object to be shown. 00258 * @return true if successful, false otherwise. 00259 */ 00260 virtual bool show(const channel& data); 00261 00262 /** 00263 * shows a channel or matrix of float 00264 * @param data the object to be shown. 00265 * @return true if successful, false otherwise. 00266 */ 00267 virtual bool show(const matrix<float>& data); 00268 00269 /** 00270 * shows a vector of double 00271 * @param data the object to be shown. 00272 * @return true if successful, false otherwise. 00273 */ 00274 virtual bool show(const vector<double>& data); 00275 00276 /** 00277 * shows a vector of double 00278 * @param data the object to be shown. 00279 * @return true if successful, false otherwise. 00280 */ 00281 virtual bool show(const vector<float>& data); 00282 00283 /** 00284 * shows a vector of double 00285 * @param data the object to be shown. 00286 * @return true if successful, false otherwise. 00287 */ 00288 virtual bool show(const vector<int>& data); 00289 00290 /** 00291 * shows a matrix of doubles as a channel 00292 * @param data the object to be shown. 00293 * @return true if successful, false otherwise. 00294 */ 00295 virtual bool show(const matrix<double>& data); 00296 00297 /** 00298 * shows a matrix of integers as a channel 00299 * @param data the object to be shown. 00300 * @return true if successful, false otherwise. 00301 */ 00302 virtual bool show(const matrix<int>& data); 00303 00304 /** 00305 * hides the display window 00306 */ 00307 bool hide(); 00308 00309 /** 00310 * copy data of "other" functor. 00311 */ 00312 fastViewer& copy(const fastViewer& other); 00313 00314 /** 00315 * copy data of "other" functor. 00316 */ 00317 fastViewer& operator=(const fastViewer& other); 00318 00319 /** 00320 * returns a pointer to a clone of the functor. 00321 */ 00322 virtual viewerBase* clone() const; 00323 00324 /** 00325 * returns used parameters 00326 */ 00327 const parameters& getParameters() const; 00328 00329 /** 00330 * set the parameters to be used 00331 */ 00332 virtual bool setParameters(const viewerBase::parameters& param); 00333 00334 00335 protected: 00336 /** 00337 * x-stuff structure 00338 */ 00339 struct display_info_s { 00340 display_info_s(); 00341 Display* display; 00342 GC gc; 00343 Window win; 00344 int width; 00345 int height; 00346 int depth; 00347 XImage *shmimage; 00348 }; 00349 00350 /** 00351 * window manager stuff 00352 */ 00353 struct winman_info_s { 00354 winman_info_s(); 00355 Atom motif_wm_hints; 00356 }; 00357 00358 winman_info_s wm_info; 00359 00360 /** 00361 * The useShareMemory variable indicates if the faster data transfer 00362 * through the MIT XShm extention should take place or not. 00363 * This member is automatically initialized in the contructor, depending 00364 * on where the X-Server is located. 00365 */ 00366 bool useShareMemory; 00367 00368 /** 00369 * shared memory info block 00370 */ 00371 XShmSegmentInfo shminfo; 00372 00373 /** 00374 * XWindows data 00375 */ 00376 display_info_s display_info; 00377 00378 /** 00379 * window title 00380 */ 00381 std::string title; 00382 00383 /** 00384 * the actual image being displayed 00385 */ 00386 image data; 00387 00388 /** 00389 * the data being displayed if a remote server is in use 00390 */ 00391 char* remoteData; 00392 00393 /** 00394 * initialize window 00395 */ 00396 void createWindow(); 00397 00398 /** 00399 * destroy window 00400 */ 00401 void destroyWindow(); 00402 00403 /** 00404 * create XImage 00405 */ 00406 void createImage(const image& img); 00407 00408 /** 00409 * destroy XImage 00410 */ 00411 void destroyImage(); 00412 }; 00413 #endif 00414 00415 00416 00417 } 00418 00419 #endif