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

ltiScene3D.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiScene3D.h
00027  * authors ....: Jens Paustenbach
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 14.1.2003
00030  * revisions ..: $Id: ltiScene3D.h,v 1.3 2006/02/08 11:48:21 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_SCENE3_D_H_
00034 #define _LTI_SCENE3_D_H_
00035 
00036 #include "ltiDraw3D.h"
00037 
00038 namespace lti {
00039   /**
00040    *  Tool for creating three dimensional scenes.
00041    *  A scene can be created in the same way as a scene in drawn with draw3D.
00042    *  To view a scene, you have first to set up the camera parameters with
00043    *  the setCamera and setZoom methods. Then the scene can be drawn into an
00044    *  image with the flush() methods.
00045    */
00046   template<class T>
00047   class scene3D : public draw3D<T> {
00048   public:
00049 
00050     /**
00051      * default constructor
00052      */
00053     scene3D();
00054 
00055     /**
00056      * copy constructor
00057      * @param other the object to be copied
00058      */
00059     scene3D(const scene3D& other);
00060 
00061     /**
00062      * destructor
00063      */
00064     virtual ~scene3D();
00065 
00066     /**
00067      * returns the name of this type ("scene3D")
00068      */
00069     virtual const char* getTypeName() const;
00070 
00071     /**
00072      * copy data of "other" functor.
00073      * @param other the functor to be copied
00074      * @return a reference to this functor object
00075      */
00076     scene3D& copy(const scene3D& other);
00077 
00078     /**
00079      * alias for copy member
00080      * @param other the functor to be copied
00081      * @return a reference to this functor object
00082      */
00083     scene3D& operator=(const scene3D& other);
00084 
00085     /**
00086      * Specifies color to be used. If the template type is rgbPixel this means
00087      * an actual color. For other template types, this sets a grey-level.
00088      */
00089     void setColor(const T& px);
00090 
00091     /**
00092      * Specifies color to be used. If the template type is rgbPixel this means
00093      * an actual color. For other template types, this sets a grey-level.
00094      */
00095     void setStyle(const char* style); 
00096 
00097     void text(const std::string& str,const dpoint3D& p);
00098 
00099       void number(const int& i, const dpoint3D& p);
00100 
00101 
00102     /**
00103      * sets point with selected color
00104      */
00105     void set3D(const dpoint3D& p);
00106 
00107     /**
00108      * sets 2D point with the selected color if it is in front of
00109      * all other points with the same projection coordinates, considering
00110      * the z-buffering (if enabled) and the given z coordinate.
00111      *
00112      * If the z-buffering is disabled, the pixel at (x,y) will be set.
00113      * @param x position x
00114      * @param y position y
00115      * @param z deep information
00116      */
00117     void set2D(const int& x,const int& y,const double& z);
00118 
00119     /**
00120      * sets marker with selected color and the given marker type
00121      */
00122     void marker3D(const double& x,const double& y,const double& z,
00123                   char* marker);
00124 
00125     /**
00126      * sets point with selected color and marker type
00127      */
00128     void marker3D(const double& x,const double& y,const double& z);
00129 
00130     /**
00131      * sets point with selected color
00132      */
00133     void set3D(const double& x,const double& y,const double& z);
00134 
00135     /**
00136      * sets point with selected color
00137      */
00138     template<class U>
00139     void set3D(const hPoint3D<U>& p) {
00140       set3D(p.x/p.h,p.y/p.h,p.z/p.h);
00141     };
00142 
00143     /**
00144      * draw a line between the last used point and (x,y,z)
00145      */
00146     void line3DTo(const double& x,const double& y,const double& z);
00147 
00148     /**
00149      * draw a line between the last used point and (x,y,z)
00150      */
00151     void line3DTo(const dpoint3D& p);
00152 
00153     /**
00154      * draw a line between a and b
00155      */
00156     void line3D(const dpoint3D& a,const dpoint3D& b);
00157 
00158     /**
00159      * draw a line between (x,y,z) and (x2,y2,z2)
00160      */
00161     void line3D(const double& x, const double& y, const double& z,
00162                 const double& x2,const double& y2,const double& z2);
00163 
00164     /**
00165      * draw a box with the opposite corners a and b
00166      */
00167     void box(const dpoint3D& a,
00168              const dpoint3D& b, const bool filled=true);
00169 
00170     /**
00171      * draw a filled box of the actual color with the opposite corners a and b,
00172      * and with the line color given
00173      */
00174     void box(const dpoint3D& a,
00175              const dpoint3D& b,
00176              const T lineColor);
00177 
00178 
00179     /**
00180      * Draw an ellipsoid surface defined through a constant mahalanobis
00181      * distance between the mean vector and the points of the surface, i.e.
00182      * the surface contains all points that satisfy the equation
00183      * (x-mean)^T sigma^(-1)  (x-mean) = cst
00184      *
00185      * The color of the ellipsoid is given with the setColor() method, and
00186      * the lighting conditions with the parameter "lighting".
00187      *
00188      * @param mean point at the center of the ellipsoid.
00189      * @param sigma covariance matrix
00190      * @param cst mahalanobis distace from the points at the surface and the
00191      *            mean value
00192      */
00193     void ellipsoid(const vector<double> &mean,
00194                    const matrix<double> &sigma,
00195                    const double &cst);
00196 
00197     /**
00198      * Draw the given channel as a 3D structure, where the height of the
00199      * pixel is given by its intensity.  The actual color will be shaded
00200      * to produce the 3D effect.  The y-axis will be inverted, to convert the
00201      * image left coordinate system to the 3D right system.
00202      *
00203      * @param chnl the channel with the 3D information
00204      * @param height the height of the value 1.0 in the channel
00205      * @param gridSize the number of pixels used for a "cell" in the grid.
00206      *                 Use for example point(5,5)
00207      * @param sampleRate determines which pixels in the image are going
00208      *                   to be used in the grid points.  point(1,1) uses
00209      *                   all pixels, point(2,2) each second point and so on.
00210      * @param onlyPoints if true, only the points will be drawn, if false,
00211      *                   boxes or grids will be drawn.
00212      * @param useBoxes if true, boxes will be used to display each pixel,
00213      *                 otherwise a triangular mesh will be used.
00214      * @param heightColor if true, the channel intensity will define the grey
00215      *                    tone for the pixel, otherwise the actual color will
00216      *                    be used.
00217      * @param drawLines if true, the vertical lines at each grid point will
00218      *                  be drawn.
00219      * @param lineColor color for the vertical lines
00220      * @param drawContour if true, the contour of each triangle in the mesh
00221      *                    will be redrawn using the countour color given.
00222      * @param contourColor color used to draw the contour of the triangles.
00223      *                     Only used if drawContour is true
00224      */
00225     void set3D(const channel& chnl,
00226                const float& height,
00227                const point& gridSize = point(5,5),
00228                const point& sampleRate = point(1,1),
00229                const bool onlyPoints = false,
00230                const bool useBoxes = false,
00231                const bool heightColor = false,
00232                const bool drawLines = false,
00233                const T& lineColor = T(),
00234                const bool drawContour = false,
00235                const T& contourColor = T());
00236 
00237 
00238     /**
00239      * draw axis with dimension "size"
00240      */
00241     void axis(const double size);
00242 
00243     /**
00244      * draw axis with dimension "size" and using the given color for each
00245      * axis
00246      */
00247     void axis(const double size,
00248               const T& colorX,
00249               const T& colorY,
00250               const T& colorZ);
00251 
00252     /**
00253      * draw a grid in all three dimensions from -size/2 to size/2, 
00254      * with nbSteps lines between
00255      */
00256     void grid(const double size,const int nbSteps);
00257 
00258     /** 
00259      * set new image and draw scene to this image with the actual camera 
00260      * parameters.
00261      */
00262     bool flush(matrix<T>& image);
00263 
00264     /**
00265      * set new camera parameters and draw all saved commands into the actual
00266      * image specified by the use() method
00267      */
00268     bool flush(const typename draw3D<T>::parameters& camera);
00269 
00270     /**
00271      * set new camera parameters and draw all saved commands
00272      * into the given image.
00273      */
00274     bool flush(const typename draw3D<T>::parameters& camera, matrix<T>& image);
00275 
00276     /**
00277      * draw all saved commands into the image specified by the use method
00278      * with the actual camera position and direction
00279      */
00280     bool flush();
00281 
00282     /**
00283      * Clears the scene.
00284      */
00285     void reset();
00286 
00287     /** 
00288      * sets the ranges of the axes shown in the configuration dialog
00289      */
00290     void setRange(const dmatrix& ranges);
00291 
00292     /** 
00293      * Returns the ranges of the axes shown in the configuration dialog
00294      */
00295     dmatrix getRange() const;
00296 
00297   protected:
00298 
00299     /**
00300      * these are the code that are used for the instructions that are saved,
00301      * to generate an image of the scene.
00302      * The letters after the function name symbolize the argument type:
00303      * i=int, d=double, dp=dpoint3D, T=T, dv=dvector, dm=dmatrix, ch=channel
00304      * This is necessary, because some functions exist more than once with
00305      * different arguments but the names in the enumeration had to be unique.
00306      */
00307     enum Instructions {
00308       setCol,
00309       setSty,
00310       text_s_p,
00311       number_i_dp,
00312       set2D_i_i_d,
00313       marker3D_d_d_d_c,
00314       marker3D_d_d_d,
00315       set3D_d,
00316       set3D_ch,
00317       line3DTo_d,
00318       line3D_d,
00319       line_i_i,
00320       box_dp_dp,
00321       box_dp_dp_T,
00322       ellips,
00323       axis_d,
00324       axis_d_T_T_T,
00325       grid_d
00326     };
00327 
00328     /**
00329      * List with the codes of the saved instructions.
00330      * All instructions are coded with an integer value and there parameters
00331      * are stored in the lists. When a picture is drawn the instructions
00332      * are extracted from the list in the same order as they were saved.
00333      * So the parameters can also be extracted from the lists in the same
00334      * order.
00335      */
00336     std::list<Instructions> instructionList;
00337 
00338     /** 
00339      * parameters for the Instructions
00340      */
00341     std::list<double> doubles;
00342 
00343     /** 
00344      * parameters for the Instructions
00345      */
00346     std::list<int> ints;
00347 
00348     /** 
00349      * parameters for the Instructions
00350      */
00351     std::list<T> colors;
00352 
00353     /** 
00354      * parameters for the Instructions
00355      */
00356     std::list<bool> bools;
00357 
00358     /** 
00359      * parameters for the Instructions
00360      */
00361     std::list<dvector> dvectors;
00362 
00363     /** 
00364      * parameters for the Instructions
00365      */
00366     std::list<dmatrix> dmatrices;
00367 
00368     /** 
00369      * parameters for the Instructions
00370      */
00371     std::list<channel> channels;
00372 
00373     /** 
00374      * parameters for the Instructions
00375      */
00376     std::list<std::string> styles;
00377 
00378   private: 
00379     /** 
00380      * Set by draw3DDistribution with the ranges of the axes for each dimension
00381      */
00382     dmatrix *ranges;
00383 
00384   };
00385 }
00386 
00387 #endif

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