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
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
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
00062 Subscript offr = (stepheight-image.nrows())/2; assert(offr>=0);
00063 Subscript offc = (stepwidth -image.ncols())/2; assert(offc>=0);
00064
00065
00066
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 }
00079 #endif