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=typename MatrixType<PixelType>::rectangular >
00018 class ImageGrid : public AARImage<PixelType,PixelMatrix> {
00019
00021 typedef typename 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:
00047 template <class MatrixOfImages>
00048 ImageGrid(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0,
00049 const PixelType bg=default_bg)
00050 : AARImage<PixelType>(totalheight(ms,borderwidth,internalborderwidth),
00051 totalwidth (ms,borderwidth,internalborderwidth),bg) {
00052 draw_border(borderwidth, bg);
00053 typedef typename MatrixOfImages::size_type Subscript;
00054 Subscript cursorr=borderwidth;
00055
00056 for (Subscript r=0; r<ms.nrows(); r++) {
00057
00058 typename MatrixOfImages::size_type stepheight = mat::max_nrows(mat::submatrix(ms,r,r+1,0,ms.ncols()));
00059 Subscript cursorc=borderwidth;
00060
00061 for (Subscript c=0; c<ms.ncols(); c++) {
00062
00063 typename MatrixOfImages::size_type stepwidth = mat::max_ncols(mat::submatrix(ms,0,ms.nrows(),c,c+1));
00064 typename MatrixOfImages::value_type image = ms[r][c];
00065
00066 Subscript offr = (stepheight-image.nrows())/2; assert(int(offr)>=0);
00067 Subscript offc = (stepwidth -image.ncols())/2; assert(int(offc)>=0);
00068
00069
00070
00071 for (Subscript sr=0; sr<image.nrows(); sr++)
00072 for (Subscript sc=0; sc<image.ncols(); sc++)
00073 draw_pixel(cursorr+offr+sr, cursorc+offc+sc, image.get_pixel(sr,sc));
00074 cursorc += stepwidth+internalborderwidth;
00075 }
00076 cursorr += stepheight+internalborderwidth;
00077 }
00078 }
00079 };
00080
00081
00082
00085 template<class PixelType=RGBPixel<>, class PixelMatrix=typename MatrixType<PixelType>::rectangular >
00086 class ImagePointerGrid : public AARImage<PixelType,PixelMatrix> {
00087
00089 typedef typename AARImage<PixelType,PixelMatrix>::PixelSubscript PixelSubscript;
00090
00092 template <class MatrixOfImages>
00093 PixelSubscript totalheight(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0 ) {
00094 PixelSubscript t=borderwidth;
00095 for (typename MatrixOfImages::size_type r=0; r<ms.nrows(); r++)
00096 t += mat::max_pnrows(mat::submatrix(ms,r,r+1,0,ms.ncols()))+internalborderwidth;
00097 return t - (ms.nrows()>0?internalborderwidth : 0) + borderwidth;
00098 }
00099
00101 template <class MatrixOfImages>
00102 PixelSubscript totalwidth(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0 ) {
00103 PixelSubscript t=borderwidth;
00104 for (typename MatrixOfImages::size_type c=0; c<ms.ncols(); c++)
00105 t += mat::max_pncols(mat::submatrix(ms,0,ms.nrows(),c,c+1))+internalborderwidth;
00106 return t - (ms.ncols()>0?internalborderwidth : 0) + borderwidth;
00107 }
00108
00109
00110 public:
00115 template <class MatrixOfImages>
00116 ImagePointerGrid(const MatrixOfImages& ms, int borderwidth=0, int internalborderwidth=0,
00117 const PixelType bg=default_bg)
00118 : AARImage<PixelType>(totalheight(ms,borderwidth,internalborderwidth),
00119 totalwidth (ms,borderwidth,internalborderwidth),bg) {
00120 draw_border(borderwidth, bg);
00121 typedef typename MatrixOfImages::size_type Subscript;
00122 Subscript cursorr=borderwidth;
00123
00124 for (Subscript r=0; r<ms.nrows(); r++) {
00125
00126 typename MatrixOfImages::size_type stepheight = mat::max_pnrows(mat::submatrix(ms,r,r+1,0,ms.ncols()));
00127 Subscript cursorc=borderwidth;
00128
00129 for (Subscript c=0; c<ms.ncols(); c++) {
00130
00131 typename MatrixOfImages::size_type stepwidth = mat::max_pncols(mat::submatrix(ms,0,ms.nrows(),c,c+1));
00132 typename MatrixOfImages::value_type p = ms[r][c];
00133
00134 if (p) {
00135
00136 Subscript offr = (stepheight-p->nrows())/2; assert(int(offr)>=0);
00137 Subscript offc = (stepwidth -p->ncols())/2; assert(int(offc)>=0);
00138
00139
00140
00141 for (Subscript sr=0; sr<p->nrows(); sr++)
00142 for (Subscript sc=0; sc<p->ncols(); sc++)
00143 draw_pixel(cursorr+offr+sr, cursorc+offc+sc, p->get_pixel(sr,sc));
00144 }
00145 cursorc += stepwidth+internalborderwidth;
00146 }
00147 cursorr += stepheight+internalborderwidth;
00148 }
00149 }
00150 };
00151
00152
00153 }
00154 #endif