LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiViewerBase.h

00001 /*
00002  * Copyright (C) 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 ...: 11.11.2001
00030  * revisions ..: $Id: ltiViewerBase.h,v 1.9 2006/03/11 03:43:14 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_VIEWER_BASE_H_
00034 #define _LTI_VIEWER_BASE_H_
00035 
00036 #include "ltiObject.h"
00037 #include "ltiFunctor.h"
00038 #include "ltiImage.h"
00039 #include "ltiMatrix.h"
00040 #include "ltiVector.h"
00041 #include <string>
00042 #include <cstdlib>
00043 
00044 namespace lti {
00045 
00046   /**
00047    * Abstract class parent for all viewer objects in the LTI-Lib.
00048    */
00049   class viewerBase : public object {
00050   public:
00051     /**
00052      * Base class for all lti parameter objects
00053      */
00054     class parameters : public functor::parameters {
00055     public:
00056       /**
00057        * default constructor
00058        */
00059       parameters();
00060 
00061       /**
00062        * copy constructor
00063        */
00064       parameters(const parameters& other);
00065 
00066       /**
00067        * destructor
00068        */
00069       virtual ~parameters();
00070 
00071       /**
00072        * copy data of "other" parameters
00073        */
00074       parameters& copy(const parameters& other);
00075 
00076       /**
00077        * copy data of "other" parameters
00078        */
00079       parameters& operator=(const parameters& other);
00080 
00081       /**
00082        * returns a pointer to a clone of the parameters.
00083        */
00084       virtual functor::parameters* clone() const;
00085 
00086       /**
00087        * return the name of this type
00088        */
00089       const char* getTypeName() const;
00090 
00091       /**
00092        * write the parameters in the given ioHandler
00093        * @param handler the ioHandler to be used
00094        * @param complete if true (the default) the enclosing begin/end will
00095        *        be also written, otherwise only the data block will be written.
00096        * @return true if write was successful
00097        */
00098       virtual bool write(ioHandler& handler,
00099                          const bool complete=true) const;
00100 
00101       /**
00102        * read the parameters from the given ioHandler
00103        * @param handler the ioHandler to be used
00104        * @param complete if true (the default) the enclosing begin/end will
00105        *        be also written, otherwise only the data block will be written.
00106        * @return true if write was successful
00107        */
00108       virtual bool read(ioHandler& handler,const bool complete=true);
00109 
00110 #     ifdef _LTI_MSC_6
00111       /**
00112        * this function is required by MSVC only, as a workaround for a
00113        * very awful bug, which exists since MSVC V.4.0, and still by
00114        * V.6.0 with all bugfixes (so called "service packs") remains
00115        * there...  This method is public due to another bug!, so please
00116        * NEVER EVER call this method directly
00117        */
00118       bool readMS(ioHandler& handler,const bool complete=true);
00119 
00120       /**
00121        * this function is required by MSVC only, as a workaround for a
00122        * very awful bug, which exists since MSVC V.4.0, and still by
00123        * V.6.0 with all bugfixes (so called "service packs") remains
00124        * there...  This method is public due to another bug!, so please
00125        * NEVER EVER call this method directly
00126        */
00127       bool writeMS(ioHandler& handler,const bool complete=true) const;
00128 #     endif
00129 
00130       // ------------------------
00131       // the parameters
00132       // ------------------------
00133 
00134       /**
00135        * title of the viewer window.
00136        *
00137        * Default value: value returned by getTypeName()
00138        */
00139       std::string title;
00140 
00141     };
00142 
00143     /**
00144      * Exception thrown when the parameters are not set
00145      */
00146     class invalidParametersException : public exception {
00147     public:
00148       /**
00149        * Default constructor
00150        */
00151       invalidParametersException()
00152         : exception("wrong parameter type or parameters not set yet") {};
00153 
00154       /**
00155        * Constructor with alternative message
00156        */
00157       invalidParametersException(const std::string& str)
00158         : exception(str) {};
00159 
00160       /**
00161        * returns the name of this exception
00162        */
00163       virtual const char* getTypeName() const;
00164     };
00165 
00166     //
00167 
00168     /**
00169      * default constructor
00170      */
00171     viewerBase();
00172 
00173     /**
00174      * copy constructor
00175      */
00176     viewerBase(const viewerBase& other);
00177 
00178     /**
00179      * destructor
00180      */
00181     virtual ~viewerBase();
00182 
00183     /**
00184      * returns the name of this type ("viewerBase")
00185      */
00186     virtual const char* getTypeName() const;
00187 
00188     /**
00189      * shows a color image.
00190      * @param data the object to be shown.
00191      * @return true if successful, false otherwise.
00192      */
00193     virtual bool show(const image& data) = 0;
00194 
00195     /**
00196      * shows a 8-bit channel
00197      * @param data the object to be shown.
00198      * @return true if successful, false otherwise.
00199      */
00200     virtual bool show(const channel8& data);
00201 
00202     /**
00203      * shows a channel or matrix of float
00204      * @param data the object to be shown.
00205      * @return true if successful, false otherwise.
00206      */
00207     virtual bool show(const channel& data);
00208 
00209     /**
00210      * shows a channel or matrix of float
00211      * @param data the object to be shown.
00212      * @return true if successful, false otherwise.
00213      */
00214     virtual bool show(const matrix<float>& data);
00215 
00216     /**
00217      * shows a vector of double
00218      * @param data the object to be shown.
00219      * @return true if successful, false otherwise.
00220      */
00221     virtual bool show(const vector<double>& data);
00222 
00223     /**
00224      * shows a vector of double
00225      * @param data the object to be shown.
00226      * @return true if successful, false otherwise.
00227      */
00228     virtual bool show(const vector<float>& data);
00229 
00230     /**
00231      * shows a vector of double
00232      * @param data the object to be shown.
00233      * @return true if successful, false otherwise.
00234      */
00235     virtual bool show(const vector<int>& data);
00236 
00237     /**
00238      * shows a matrix of doubles as a channel
00239      * @param data the object to be shown.
00240      * @return true if successful, false otherwise.
00241      */
00242     virtual bool show(const matrix<double>& data);
00243 
00244     /**
00245      * shows a matrix of integers as a channel
00246      * @param data the object to be shown.
00247      * @return true if successful, false otherwise.
00248      */
00249     virtual bool show(const matrix<int>& data);
00250 
00251     /**
00252      * hides the display window
00253      * @return true if successful, false otherwise.
00254      */
00255     virtual bool hide() = 0;
00256 
00257     /**
00258      * copy data of "other" functor.
00259      */
00260     viewerBase& copy(const viewerBase& other);
00261 
00262     /**
00263      * copy data of "other" functor.
00264      */
00265     viewerBase& operator=(const viewerBase& other);
00266 
00267     /**
00268      * returns a pointer to a clone of the functor.
00269      */
00270     virtual viewerBase* clone() const = 0;
00271 
00272     /**
00273      * returns used parameters
00274      */
00275     const parameters& getParameters() const;
00276 
00277     /**
00278      * returns used parameters
00279      */
00280     parameters& getParameters();
00281 
00282     /**
00283      * set the parameters to be used.  This object makes a copy of the given
00284      * object and manages the memory of the copy
00285      */
00286     virtual bool setParameters(const parameters& param);
00287 
00288     /**
00289      * set the parameters to be used.  Just a reference to the given object
00290      * is done.  The memory managment must be done outside this object.
00291      *
00292      * Usually the viewers provide GUI to specify the parameters, that is why
00293      * the given reference is not const.
00294      */
00295     virtual bool useParameters(parameters& param);
00296 
00297     /**
00298      * returns true if the parameters are valid
00299      */
00300     virtual bool validParameters() const;
00301 
00302     /**
00303      * return the last message set with setStatusString().  This will
00304      * never return 0.  If no status-string has been set yet an empty string
00305      * (pointer to a string with only the char(0)) will be returned.
00306      */
00307     virtual const char* getStatusString() const;
00308 
00309     /**
00310      * set a status string.
00311      *
00312      * @param msg the const string to be reported next time by
00313      * getStatusString(). The given string will be copied.
00314      * This message will be usually set within the apply methods to indicate
00315      * an error cause.
00316      *
00317      * Note that the change of the status string is not considered as
00318      * a change in the functor status.
00319      */
00320     virtual void setStatusString(const char* msg) const;
00321 
00322 
00323   private:
00324     /**
00325      * the actual parameters
00326      */
00327     parameters* params;
00328 
00329     /**
00330      * own parameters is true, if this instance must take care of the
00331      * memory management of params, otherwise false
00332      */
00333     bool ownParam;
00334 
00335     /**
00336      * the status string written with setStatusString
00337      */
00338     mutable char* statusString;
00339 
00340     /**
00341      * the empty string returned if the statusString is empty
00342      */
00343     static const char *const emptyString;
00344   };
00345 
00346   /**
00347    * write the viewerBase::parameters in the given ioHandler.
00348    * The complete flag indicates
00349    * if the enclosing begin and end should be also be written or not.
00350    *
00351    * @ingroup gStorable
00352    */
00353   bool write(ioHandler& handler,const viewerBase::parameters& p,
00354              const bool complete = true);
00355 
00356   /**
00357    * read the functor::parameters from the given ioHandler.
00358    * The complete flag indicates
00359    * if the enclosing begin and end should be also be written or not
00360    *
00361    * @ingroup gStorable
00362    */
00363   bool read(ioHandler& handler,viewerBase::parameters& p,
00364              const bool complete = true);
00365 }
00366 
00367 #endif

Generated on Sat Apr 10 15:26:22 2010 for LTI-Lib by Doxygen 1.6.1