CVR-Lib last update 20 Sep 2009

cvrViewer2DPainter.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrViewer2DPainter.h
00043  *         Contains the functor that the viewer2D uses to paint the data.
00044  * \author Pablo Alvarado
00045  * \date   05.01.2005
00046  *
00047  * revisions ..: $Id: cvrViewer2DPainter.h,v 1.12 2007/04/08 03:12:18 alvarado Exp $
00048  */
00049 
00050 #ifndef _CVR_VIEWER_2_D_PAINTER_H_
00051 #define _CVR_VIEWER_2_D_PAINTER_H_
00052 
00053 #include "cvrFunctor.h"
00054 #include "cvrImage.h"
00055 #include "cvrRGBPixel.h"
00056 #include "cvrSplitImageToHSI.h"
00057 #include "cvrMergeHSIToImage.h"
00058 #include "cvrSplitImageToRGB.h"
00059 #include "cvrMergeRGBToImage.h"
00060 
00061 
00062 namespace cvr {
00063 
00064   class histogramEqualization; // just not to include the header!
00065 
00066   /**
00067    * Class viewer2DPainter.
00068    *
00069    * Class used to paint the 2D data as required by the cvr::viewer2D.
00070    *
00071    * The apply() methods "render" an image corresponding to a window of the
00072    * data to be visualized.  They are not "const" since the viewer2DPainter
00073    * administrates a cache for the statistics of the given images and some
00074    * precomputations, in order to allow the required speed in the viewer
00075    * classes.
00076    *
00077    * Therefore, the apply methods are faster if they are always invoqued with
00078    * the same source image, as the statistics are computed only the first time
00079    * they are required.
00080    *
00081    * The "cache miss" is computed based on very simple heuristics: the
00082    * probability that two different images have exactly the same size and
00083    * located on the same memory block is relatively low, so that the signature
00084    * of the data is computed based on these "identifiers".  If you have an
00085    * application where you just fill always the same cvr::matrix (or
00086    * derived) instance, then you have to call invalidateCache() first, to
00087    * ensure that the statistics will be properly computed.
00088    *
00089    * @ingroup gVisualization
00090    */
00091   class viewer2DPainter : public functor {
00092   public:
00093 
00094     /**
00095      * Enumeration used to indicate the type of gray-scale/brightness mapping
00096      * used.
00097      */
00098     enum eMappingType {
00099       Original,    /**< Original image, without modifications */
00100       OffsetSlope, /**< Use a linear mapping with the given Offset and Slope */
00101       MinToBlack,  /**< Map always the minimum value to black */
00102       MaxToWhite,  /**< Map always the maximum value to white */
00103       Optimal,     /**< Map the minimum to black and maximum to white */
00104       HistogramEq, /**< Equalize the brightness histogram */
00105       Log,         /**< Logarithmic curve log(x+1)/log(256) where x is assumed
00106                       to be between 0 a 255.  For channels it is used x*255.*/
00107       OptimalLog,  /**< Like log, but an Optimal map is applied first */
00108       UserDefMap   /**< Use a user given LUT */
00109     };
00110 
00111     /**
00112      * Enumeration used to indicate which palette should be used when
00113      * displaying channels, or on which channel should be applied the mapping
00114      * if showing color images.
00115      */
00116     enum ePaletteType {
00117       GrayPalette,  /**< Gray palette or intensity channel */
00118       RedPalette,   /**< Red palette or red channel */
00119       GreenPalette, /**< Green palette or green channel */
00120       BluePalette,  /**< Blue palette or blue channel */
00121       HuePalette,   /**< Hue palette or hue channel*/
00122       UserDefPalette /**< A palette defined by the user or all RGB channels*/
00123     };
00124 
00125     /**
00126      * Enumeration type used to indicate the type of neighborhood used in
00127      * the adjacency analysis.
00128      */
00129     enum eNeighborhoodType {
00130       FourNeighborhood,  /**< 4-Neighborhood */
00131       EightNeighborhood  /**< 8-Neighborhood */
00132     };
00133 
00134     /**
00135      * Limit for the biggest allowable label in a channel32 for the
00136      * label adjacency analysis.
00137      */
00138     enum {
00139       BiggestLable = 307200  /**< assume that a mask of 640x480 has 1 label per
00140                               *   pixel, which would produce in the worst case
00141                               *   LUT of 1.2MB.
00142                               */
00143     };
00144 
00145     /**
00146      * Parameters of the cvr::viewer2DPainter class.
00147      */
00148     class parameters : virtual public parametersManager::parameters {
00149     public:
00150 
00151       /**
00152        * Default constructor
00153        */
00154       parameters();
00155 
00156       /**
00157        * Copy constructor
00158        */
00159       parameters(const parameters& other);
00160 
00161       /**
00162        * Destructor
00163        */
00164       virtual ~parameters();
00165 
00166       /**
00167        * Copy data of "other" parameters
00168        */
00169       parameters& copy(const parameters& other);
00170 
00171       /**
00172        * Copy data of "other" parameters
00173        */
00174       parameters& operator=(const parameters& other);
00175 
00176       /**
00177        * Returns the name of this class
00178        */
00179       virtual const std::string& name() const;
00180 
00181       /**
00182        * Returns a pointer to a clone of the parameters.
00183        */
00184       virtual parameters* clone() const;
00185 
00186       /**
00187        * Returns a pointer to a clone of the parameters.
00188        */
00189       virtual parameters* newInstance() const;
00190 
00191 
00192       /**
00193        * Write the parameters in the given ioHandler
00194        * @param handler the ioHandler to be used
00195        * @param complete if true (the default) the enclosing begin/end will
00196        *        be also written, otherwise only the data block will be written.
00197        * @return true if write was successful
00198        */
00199       virtual bool write(ioHandler& handler,
00200                          const bool complete=true) const;
00201 
00202       /**
00203        * Read the parameters from the given ioHandler
00204        * @param handler the ioHandler to be used
00205        * @param complete if true (the default) the enclosing begin/end will
00206        *        be also written, otherwise only the data block will be written.
00207        * @return true if write was successful
00208        */
00209       virtual bool read(ioHandler& handler,const bool complete=true);
00210 
00211     public:
00212       //
00213       // Attributes
00214       //
00215 
00216       /**
00217        * Zoom factor.
00218        *
00219        * The zoom functor is simply a scale factor used for each pixel.
00220        * You can interpret it as the number of pixels used per pixel.
00221        *
00222        * Values greater than one indicate a zoom-in factor, where the value
00223        * indicates the number of displayed pixels for each image pixel.
00224        *
00225        * Values smaller than one indicate a zoom-out factor, where only each
00226        * 1/zoom pixel is shown.
00227        *
00228        * This values have to be positive and different than zero.
00229        *
00230        * Default value: 1.0
00231        */
00232       float zoom;
00233 
00234       /**
00235        * Type of mapping used for the intensity of the data.
00236        *
00237        * Default value: Original
00238        */
00239       eMappingType mappingType;
00240 
00241       /**
00242        * Offset used if the linear mapping is chosen.
00243        *
00244        * This is the \a b value in a \a mx+b equation.
00245        *
00246        * The value given here is normalized, which means that a value of 1
00247        * indicates an offset of the whole value range (1.0 for cvr::channel and
00248        * 255 for channel8 or images).  In other words, you want here usually
00249        * values between -1.0 and 1.0.
00250        *
00251        * Default value: 0
00252        */
00253       float offset;
00254 
00255       /**
00256        * Slope used if the linear mapping is chosen.
00257        *
00258        * This is the \a m value in a \a mx+b equation.
00259        *
00260        * Default value: 1
00261        */
00262       float slope;
00263 
00264       /**
00265        * User defined curve, given as a LUT
00266        *
00267        * Default value: a linear mapping
00268        */
00269       vector<ubyte> userMapping;
00270 
00271       /**
00272        * Should the data in the status bar be displayed in hexadecimal or
00273        * in decimal notation.
00274        *
00275        * Default value: false
00276        */
00277       bool hexadecimal;
00278 
00279       /**
00280        * Color used for an underflow.
00281        *
00282        * The linear maps used can produce data outside the expected ranges.  If
00283        * the values are above the highest valid value, this color will be used
00284        * instead.
00285        *
00286        * Default value: Blue
00287        */
00288       rgbaPixel underflowColor;
00289 
00290       /**
00291        * Color used for an overflow
00292        *
00293        * The linear maps used can produce data outside the expected ranges.  If
00294        * the values are below the lowest valid value, this color will be used
00295        * instead.
00296        *
00297        * Default value: Red
00298        */
00299       rgbaPixel overflowColor;
00300 
00301       /**
00302        * Palette type to be used or channel to be mapped.
00303        *
00304        * If you
00305        *
00306        * Default value: GrayPalette
00307        */
00308       ePaletteType paletteType;
00309 
00310       /**
00311        * Used defined color palette.  It is used as a palette for
00312        * representation of channels (ubyte, float and int), but also as
00313        * the palette for the label adjacency representations.
00314        *
00315        * Default value: labelAdjacencyMap::defaultPalette
00316        */
00317       palette userPalette;
00318 
00319       /**
00320        * Label adjacency analysis
00321        *
00322        * If true, then the channel8 or channel32 being displayed will be
00323        * assumed to be a labeled mask, and an adjacency analysis will be done
00324        * to improve the visualization of adjacent regions.
00325        *
00326        * Default value: false
00327        */
00328       bool labelAdjacency;
00329 
00330       /**
00331        * Neighborhood type for the adjacency analysis.
00332        *
00333        * Default value: FourNeighborhood
00334        */
00335       eNeighborhoodType adjacencyNeighborhood;
00336 
00337       /**
00338        * If labelAdjacency is true, this flag indicates if the number of
00339        * used colors should be minimal (the first items in the userPalette) or
00340        * all colors in userPalette can be used.
00341        *
00342        * Default value: true;
00343        */
00344       bool minAdjacencyColors;
00345     }; // end of parameters
00346 
00347 
00348     /**
00349      * Default constructor
00350      */
00351     viewer2DPainter();
00352 
00353     /**
00354      * Construct a functor using the given parameters
00355      */
00356     viewer2DPainter(const parameters& par);
00357 
00358     /**
00359      * Copy constructor
00360      * @param other the object to be copied
00361      */
00362     viewer2DPainter(const viewer2DPainter& other);
00363 
00364     /**
00365      * Destructor
00366      */
00367     virtual ~viewer2DPainter();
00368 
00369     /**
00370      * @name Apply methods to paint the whole image
00371      */
00372     //@{
00373     /**
00374      * Generate a new image considering all viewer parameterization and store
00375      * it in dest.
00376      *
00377      * @param src image with the source data.
00378      * @param dest image where the result will be left.
00379      * @return true if apply successful or false otherwise.
00380      */
00381     bool apply(const matrix<rgbaPixel>& src, image& dest);
00382 
00383     /**
00384      * Generate a new image considering all viewer parameterization and store
00385      * it in dest.
00386      *
00387      * @param src channel with the source data.
00388      * @param dest image where the result will be left.
00389      * @return true if apply successful or false otherwise.
00390      */
00391     bool apply(const matrix<float>& src, image& dest);
00392 
00393     /**
00394      * Generate a new image considering all viewer parameterization and store
00395      * it in dest.
00396      *
00397      * @param src channel with the source data.
00398      * @param dest image where the result will be left.
00399      * @return true if apply successful or false otherwise.
00400      */
00401     bool apply(const matrix<ubyte>& src, image& dest);
00402 
00403     /**
00404      * Generate a new image considering all viewer parameterization and store
00405      * it in dest.
00406      *
00407      * @param src channel with the source data.
00408      * @param dest image where the result will be left.
00409      * @return true if apply successful or false otherwise.
00410      */
00411     bool apply(const matrix<int32>& src, image& dest);
00412     //@}
00413 
00414     /**
00415      * @name Apply methods to partially paint an image.
00416      *
00417      * The view port is considered to denote the dimensions of an area in a
00418      * canvas where the src data is to be painted on.  Please note that, due to
00419      * the chosen zoom factor, such canvas may have a different size than the
00420      * input data itself.  The apply methods have to take care of all
00421      * conversions of coordinate systems, as the viewport denote the canvas
00422      * coordinates and not the src image coordinates.
00423      *
00424      * If you are overloading these methods, you may find the method
00425      * analyzeViewport() useful.
00426      */
00427     //@{
00428 
00429     /**
00430      * Generate a new image to the given viewport.
00431      *
00432      * @param src Original image
00433      *
00434      * @param viewport section of the destination image to be rendered.  The
00435      *  meaning of this rectangle depends on the zoom factor configured by the
00436      *  user.
00437      *
00438      * @param dest Canvas where the region will be painted.
00439      *
00440      * @return true if the rendering was possible, false if not.
00441      */
00442     virtual bool apply(const matrix<rgbaPixel>& src,
00443                        const irectangle& viewport,
00444                        image& dest);
00445 
00446     /**
00447      * Generate a new image.
00448      *
00449      * @param src Original image
00450      *
00451      * @param viewport section of the destination image to be rendered.  The
00452      *  meaning of this rectangle depends on the zoom factor configured by the
00453      *  user.
00454      *
00455      * @param dest Canvas where the region will be painted.
00456      *
00457      * @return true if the rendering was possible, false if not.
00458      */
00459     virtual bool apply(const matrix<float>& src,
00460                        const irectangle& viewport,
00461                        image& dest);
00462 
00463     /**
00464      * Generate a new image.
00465      *
00466      * @param src Original image
00467      *
00468      * @param viewport section of the destination image to be rendered.  The
00469      *  meaning of this rectangle depends on the zoom factor configured by the
00470      *  user.
00471      *
00472      * @param dest Canvas where the region will be painted.
00473      *
00474      * @return true if the rendering was possible, false if not.
00475      */
00476     virtual bool apply(const matrix<ubyte>& src,
00477                        const irectangle& viewport,
00478                        image& dest);
00479 
00480     /**
00481      * Generate a new image.
00482      *
00483      * @param src Original image
00484      *
00485      * @param viewport section of the destination image to be rendered.  The
00486      *  meaning of this rectangle depends on the zoom factor configured by the
00487      *  user.
00488      *
00489      * @param dest Canvas where the region will be painted.
00490      *
00491      * @return true if the rendering was possible, false if not.
00492      */
00493     virtual bool apply(const matrix<int32>& src,
00494                        const irectangle& viewport,
00495                        image& dest);
00496 
00497     //@}
00498 
00499     /**
00500      * Ensure that the next apply called will force the computation of the
00501      * required statistics.
00502      */
00503     virtual void invalidateCache();
00504 
00505     /**
00506      * Copy data of "other" functor.
00507      * @param other the functor to be copied
00508      * @return a reference to this functor object
00509      */
00510     viewer2DPainter& copy(const viewer2DPainter& other);
00511 
00512     /**
00513      * Alias for copy member
00514      * @param other the functor to be copied
00515      * @return a reference to this functor object
00516      */
00517     viewer2DPainter& operator=(const viewer2DPainter& other);
00518 
00519     /**
00520      * Returns the complete name of the functor class
00521      */
00522     virtual const std::string& name() const;
00523 
00524     /**
00525      * Returns a pointer to a clone of this functor.
00526      */
00527     virtual viewer2DPainter* clone() const;
00528 
00529     /**
00530      * Returns a pointer to a new instance of this functor.
00531      */
00532     virtual viewer2DPainter* newInstance() const;
00533 
00534     /**
00535      * Set the zoom parameter to the value indicated.
00536      *
00537      * The painter can be used with GUI tools that take care of the zoom,
00538      * so it is handy to have a method that allows a direct change of the
00539      * parameters object to set only the zoom value.
00540      */
00541     void setZoom(const float zoomFactor);
00542 
00543     /**
00544      * Returns used parameters
00545      */
00546     const parameters& getParameters() const;
00547 
00548     /**
00549      * Compute a correct user palette from the parameters
00550      */
00551     virtual bool updateParameters();
00552 
00553 
00554   protected:
00555     /**
00556      * Returns a read-write reference to the used parameters
00557      */
00558     parameters& getParameters();
00559 
00560     /**
00561      * Histogram equalization functor.
00562      *
00563      * It is initialized only at construction time
00564      */
00565     histogramEqualization* histEq_;
00566 
00567     /**
00568      * @name Splitters and mergers
00569      */
00570     //@{
00571     const splitImageToHSI splitHSI_;
00572     const mergeHSIToImage mergeHSI_;
00573     const splitImageToRGB splitRGB_;
00574     const mergeRGBToImage mergeRGB_;
00575     //@}
00576 
00577     /**
00578      * @name Palettes
00579      *
00580      * The channel representations can be colored using one of the following
00581      * palettes
00582      */
00583     //@{
00584     /**
00585      * Initialize all palettes
00586      */
00587     void initPalettes();
00588 
00589     /**
00590      * Gray palette
00591      */
00592     static palette gray_;
00593 
00594     /**
00595      * palette
00596      */
00597     static palette red_;
00598 
00599     /**
00600      * palette
00601      */
00602     static palette green_;
00603 
00604     /**
00605      * palette
00606      */
00607     static palette blue_;
00608 
00609     /**
00610      * palette
00611      */
00612     static palette hue_;
00613 
00614     /**
00615      * user palette that depends on the parameters
00616      */
00617     palette user_;
00618     //@}
00619 
00620     /**
00621      * @name Cached data statistics
00622      */
00623     //@{
00624 
00625     // Anonymous constants
00626     enum eChannelType {
00627       IntensityCache = 0,
00628       HueCache       = 1,
00629       RedCache       = 2,
00630       GreenCache     = 3,
00631       BlueCache      = 4,
00632       NumCacheBlocks = 5
00633     };
00634 
00635     /**
00636      * Data computed for a channel and flags indicating if stats were already
00637      * computed
00638      */
00639     class cacheBlock {
00640     public:
00641       /**
00642        * Constructor
00643        */
00644       cacheBlock();
00645 
00646       /**
00647        * Invalidate cache block
00648        */
00649       void invalidate();
00650 
00651       /**
00652        * Flag to indicate that the min-max statistics are up-to-date.
00653        */
00654       bool minMaxOk_;
00655 
00656       /**
00657        * Flag to indicate that the histogram equalization LUT are up-to-date.
00658        */
00659       bool histEqOk_;
00660 
00661       /**
00662        * Min value
00663        */
00664       float min_;
00665 
00666       /**
00667        * Max value
00668        */
00669       float max_;
00670 
00671       /**
00672        * LUT for histogram equalization
00673        */
00674       vector<float> lut_;
00675     };
00676 
00677     /**
00678      * A manager for all statistic blocks, computed (only if necessary) for
00679      * the red, green, blue, hue and intensity channels of the data.
00680      */
00681     class cacheManager {
00682     public:
00683       /**
00684        * Constructor
00685        */
00686       cacheManager(histogramEqualization*& histoEq);
00687 
00688       /**
00689        * Update the internal cache blocks if necessary
00690        *
00691        * @param data pointer to the data block from which chnl was extracted.
00692        * @param chnlType type of color channel being analyzed (red, hue, etc).
00693        * @param chnl the channel for which the statistics are required.  It
00694        *             has to be exactly of the same size than the original
00695        *             data, or the statistics will be wrong!
00696        * @param mapping the transformation desired is used to detect which
00697        *        statistics have to be computed.
00698        *
00699        * @return false if nothing had to be updated, or true if changes were
00700        *         done.
00701        */
00702       bool update(const void* data,
00703                   const eChannelType chnlType,
00704                   const matrix<float>& chnl,
00705                   const eMappingType mapping);
00706 
00707       /**
00708        * Update the internal cache blocks if necessary
00709        *
00710        * @param data pointer to the data block from which chnl was extracted.
00711        * @param chnlType type of color channel being analyzed (red, hue, etc).
00712        * @param chnl the channel for which the statistics are required.  It
00713        *             has to be exactly of the same size than the original
00714        *             data, or the statistics will be wrong!
00715        * @param mapping the transformation desired is used to detect which
00716        *        statistics have to be computed.
00717        *
00718        * @return false if nothing had to be updated, or true if changes were
00719        *         done.
00720        */
00721       bool update(const ubyte* data,
00722                   const eChannelType chnlType,
00723                   const matrix<ubyte>& chnl,
00724                   const eMappingType mapping);
00725 
00726 
00727       /**
00728        * Update the internal cache blocks if necessary
00729        *
00730        * @param data pointer to the data block from which chnl32 was extracted.
00731        * @param chnlType type of color channel being analyzed (red, hue, etc).
00732        * @param chnl the channel for which the statistics are required.  It
00733        *             has to be exactly of the same size than the original
00734        *             data, or the statistics will be wrong!
00735        * @param mapping the transformation desired is used to detect which
00736        *        statistics have to be computed.
00737        *
00738        * @return false if nothing had to be updated, or true if changes were
00739        *         done.
00740        */
00741       bool update(const int32* data,
00742                   const eChannelType chnlType,
00743                   const matrix<int32>& chnl,
00744                   const eMappingType mapping);
00745 
00746       /**
00747        * Update the internal signature to the given matrix
00748        */
00749       bool updateSignature(const matrix<ubyte>& data);
00750 
00751       /**
00752        * Update the internal signature to the given matrix
00753        */
00754       bool updateSignature(const matrix<int32>& data);
00755 
00756       /**
00757        * Verify if there will be a cache miss with the given data.
00758        *
00759        * Mapping is used to determine if the statistics have to be recomputed
00760        * or are not necessary at all.
00761        */
00762       bool checkCacheMiss(const void* data,
00763                           const eChannelType chnlType,
00764                           const ipoint& size,
00765                           const eMappingType mapping) const;
00766 
00767       /**
00768        * Verify if there will be a cache miss with the given data
00769        * of a channel8 or equivalent matrix.
00770        */
00771       bool checkCacheMiss(const ubyte* data,
00772                           const ipoint& size,
00773                           const int cacheIdx) const;
00774 
00775       /**
00776        * Verify if there will be a cache miss with the given data
00777        * of a channel32 or equivalent matrix.
00778        */
00779       bool checkCacheMiss(const int* data,
00780                           const ipoint& size,
00781                           const int cacheIdx) const;
00782 
00783       /**
00784        * Invalidate the cache
00785        */
00786       void invalidate();
00787 
00788     protected:
00789       /**
00790        * @name Signature data
00791        */
00792       //@{
00793       /**
00794        * Pointer to the data block of the matrix.
00795        *
00796        * Note that this is the pointer to the data block itself, and NOT to the
00797        * container matrix, i.e. it will be a rgbaPixel*, int*, ubyte* or
00798        * float*.
00799        */
00800       const void* dataPtr_;
00801 
00802       /**
00803        * Size of the matrix.
00804        *
00805        * Even if dataPtr_ is almost perfect for the task, a second check cannot
00806        * hurt!
00807        */
00808       ipoint dataSize_;
00809       //@}
00810 
00811       /**
00812        * histogram equalizer
00813        */
00814       histogramEqualization*& histoEq_;
00815 
00816     public:
00817       /**
00818        * All cached blocks
00819        */
00820       cacheBlock blocks_[NumCacheBlocks];
00821 
00822       enum {
00823         ClutSize = UserDefMap+5
00824       };
00825 
00826       /**
00827        * Cached palettes used by channel8 and channel32
00828        * The boolean is a flag to indicate that the palette has been
00829        * computed.
00830        *
00831        * The first (UserDefMap+1) entries are for normal display and the last
00832        * 4 are used by the label adjacency LUT
00833        */
00834       std::pair<ivector,bool> clut_[ClutSize];
00835 
00836       /**
00837        * Flag that indicates if a labeled channel32 has too many labels
00838        */
00839       bool tooManyLabels_;
00840     };
00841 
00842     /**
00843      * Cache instance
00844      */
00845     cacheManager cache_;
00846 
00847     /**
00848      * Flag to indicate that the parameters may have changed
00849      * (the user called in the mean time setParameters(), useParameters(), etc.
00850      */
00851     bool haveNewParameters_;
00852 
00853     //@}
00854 
00855     /**
00856      * Get the start and end coordinates of the viewport but in
00857      * the coordinate system of the original image.
00858      *
00859      * If the viewport area corresponds to a region that exceeds the boundaries
00860      * in the original image, then the returned startPx and endPx coordinates
00861      * will be truncated to not exceed the area between (0,0) and
00862      * dataSize-(1,1).
00863      *
00864      * @param viewport section of the canvas that has to be rendered
00865      * @param dataSize size of the original data
00866      * @param zoom zoom factor
00867      * @param startPx coordinates of the upper-left point in the original
00868      *                data equivalent to the requested viewport.
00869      * @param endPx   coordinates of the bottom-write point in the
00870      *                original data (inclusive)
00871      */
00872     void analyzeViewport(const irectangle& viewport,
00873                          const ipoint& dataSize,
00874                          const float& zoom,
00875                          ipoint& startPx,
00876                          ipoint& endPx) const;
00877 
00878     /**
00879      * Changes pixelwise the appearance of src but only the pixels from
00880      * the point "from" to "to", and leaves the result in dest.
00881      *
00882      * The dest image is always connected and owns its data.
00883      */
00884     bool render(const matrix<rgbaPixel>& src,
00885                 const ipoint from,
00886                 const ipoint to,
00887                 image& dest);
00888 
00889     /**
00890      * Changes pixelwise the appearance of src but only the pixels from
00891      * the point "from" to "to", and leaves the result in dest.
00892      *
00893      * The dest image is always connected and owns its data.
00894      */
00895     bool render(const matrix<float>& src,
00896                 const ipoint from,
00897                 const ipoint to,
00898                 image& dest);
00899 
00900 
00901     /**
00902      * Changes pixelwise the appearance of src but only the pixels from
00903      * the point "from" to "to", and leaves the result in dest.
00904      *
00905      * The dest image is always connected and owns its data.
00906      */
00907     bool render(const matrix<ubyte>& src,
00908                 const ipoint from,
00909                 const ipoint to,
00910                 image& dest);
00911 
00912     /**
00913      * Changes pixelwise the appearance of src but only the pixels from
00914      * the point "from" to "to", and leaves the result in dest, assuming
00915      * that src is a labeled mask
00916      *
00917      * The dest image is always connected and owns its data.
00918      */
00919     bool renderLabels(const matrix<ubyte>& src,
00920                       const ipoint from,
00921                       const ipoint to,
00922                       image& dest);
00923 
00924 
00925     /**
00926      * Changes pixelwise the appearance of src but only the pixels from
00927      * the point "from" to "to", and leaves the result in dest, assuming
00928      * that src is a labeled mask
00929      *
00930      * The dest image is always connected and owns its data.
00931      */
00932     bool renderLabels(const matrix<int32>& src,
00933                       const ipoint from,
00934                       const ipoint to,
00935                       image& dest);
00936 
00937     /**
00938      * Changes pixelwise the appearance of src but only the pixels from
00939      * the point "from" to "to", and leaves the result in dest.
00940      *
00941      * The dest image is always connected and owns its data.
00942      */
00943     bool render(const matrix<int32>& src,
00944                 const ipoint from,
00945                 const ipoint to,
00946                 image& dest);
00947 
00948     /**
00949      * Computes on-place the intensity mapping.
00950      *
00951      * It is assumed that the normal range is always from 0.0 to 1.0
00952      */
00953     bool mapping(matrix<float>& srcDest,
00954                  const eChannelType type) const;
00955 
00956     /**
00957      * Computes on-place the intensity mapping.
00958      *
00959      * It is assumed that the normal range is always from 0 to 255
00960      * The normal output will be in that range too.
00961      */
00962     bool mapping(matrix<int32>& srcDest,
00963                  const eChannelType type) const;
00964 
00965     /**
00966      * Computes a LUT for a channel8 (or similar)
00967      */
00968     bool computeC8LUT(ivector& lut) const;
00969 
00970     /**
00971      * Zoom in or out the given image by the given factor
00972      * leaving the result in dest and considering the "from" point that
00973      * may indicate a partial part of the pixels.
00974      *
00975      * @param src a reference to the source image, which is not const since
00976      *        it can be detached to the dest if it is possible.  It has to
00977      *        be connected!
00978      * @param viewport coordinates of the viewport
00979      * @param zoom zoom factor
00980      * @param dest destination image, which must have the desired size already!
00981      *
00982      * @return true if successful or false otherwise.
00983      */
00984     virtual bool zoom(image& src,
00985                       const irectangle& viewport,
00986                       const float zoom,
00987                       image& dest) const;
00988 
00989 
00990 
00991   };
00992 
00993 }
00994 
00995 #endif
00996 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8