Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

imagegrid.h

Go to the documentation of this file.
00001 
00007 #ifndef __IMAGEGRID_H__
00008 #define __IMAGEGRID_H__
00009 
00010 #include "matrix.h"
00011 #include "image.h"
00012 
00013 namespace  Plot {
00014 
00015 
00017 template<class PixelType=RGBPixel<>, class PixelMatrix=MatrixType<PixelType>::rectangular >
00018 class ImageGrid : public AARImage<PixelType,PixelMatrix> {
00019 
00021   typedef AARImage<PixelType,PixelMatrix>::PixelSubscript PixelSubscript;
00022 
00024   template <class MatrixOfImages>
00025   PixelSubscript totalheight(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0 ) {
00026     PixelSubscript t=borderwidth;
00027     for (typename MatrixOfImages::size_type r=0; r<ms.nrows(); r++)
00028       t += mat::max_nrows(mat::submatrix(ms,r,r+1,0,ms.ncols()))+internalborderwidth;
00029     return t - (ms.nrows()>0?internalborderwidth : 0) + borderwidth;
00030   }
00031 
00033   template <class MatrixOfImages>
00034   PixelSubscript totalwidth(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0 ) {
00035     PixelSubscript t=borderwidth;
00036     for (typename MatrixOfImages::size_type c=0; c<ms.ncols(); c++)
00037       t += mat::max_ncols(mat::submatrix(ms,0,ms.nrows(),c,c+1))+internalborderwidth;
00038     return t - (ms.ncols()>0?internalborderwidth : 0) + borderwidth;
00039   }
00040 
00041   
00042 public:
00044   template <class MatrixOfImages>
00045   ImageGrid(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0 )
00046     : AARImage<PixelType>(totalheight(ms,borderwidth,internalborderwidth),
00047                           totalwidth (ms,borderwidth,internalborderwidth)) {
00048         draw_border(borderwidth);
00049         typedef typename MatrixOfImages::size_type Subscript;
00050         Subscript cursorr=borderwidth;
00051         
00052         for   (Subscript r=0; r<ms.nrows(); r++) {
00053           /* Accommodate the maximum image size in this row */
00054           typename MatrixOfImages::size_type stepheight = mat::max_nrows(mat::submatrix(ms,r,r+1,0,ms.ncols()));
00055           Subscript cursorc=borderwidth;
00056           
00057           for (Subscript c=0; c<ms.ncols(); c++) {
00058             /* Accommodate the maximum image size in this column */
00059             typename MatrixOfImages::size_type stepwidth = mat::max_ncols(mat::submatrix(ms,0,ms.nrows(),c,c+1));
00060             typename MatrixOfImages::value_type image = ms[r][c];
00061             /* The image is centered in the cell available for it */
00062             Subscript offr = (stepheight-image.nrows())/2; assert(offr>=0);
00063             Subscript offc = (stepwidth -image.ncols())/2; assert(offc>=0);
00064 
00065             /* Copy the pixels from the subimage into the larger image */
00066             /* (There's probably a matrix routine to do this already.) */
00067             for   (Subscript sr=0; sr<image.nrows(); sr++)
00068               for (Subscript sc=0; sc<image.ncols(); sc++)
00069                 draw_pixel(cursorr+offr+sr, cursorc+offc+sc, image.get_pixel(sr,sc));
00070             cursorc += stepwidth+internalborderwidth;
00071           }
00072           cursorr += stepheight+internalborderwidth;
00073         }
00074    }
00075 };
00076 
00077  
00078 } /* namespace Plot */
00079 #endif /* __IMAGEGRID_H__ */

Generated at Mon Aug 21 00:30:54 2000 for RF-LISSOM by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000