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

matriximagefactory.h

Go to the documentation of this file.
00001 
00011 #ifndef __MATRIX_IMAGE_FACTORY_H__
00012 #define __MATRIX_IMAGE_FACTORY_H__
00013 
00014 #include <utility>
00015 #include <string>
00016 using std::string;
00017 
00018 // Uses roundabout paths to the current directory to avoid Cray C bug
00019 #include "../src/matriximage.h"
00020 #include "../src/matrixadapter.h"
00021 #include "../src/scale.h"
00022 #include "../src/aarectangle.h"
00023 
00024 namespace  Plot {
00025 
00026 
00027 
00051 template<class BaseMatrixType=mat::MatrixInterface<double>,
00052          class T=typename BaseMatrixType::value_type,
00053          class ScaleT=Scale::Linear<T>,
00054          class Rectangle=Boundary::AAArbitraryRectangle<double,int>,
00055          class PixelType=RGBPixel<>,
00056          class PixelMatrix=typename MatrixType<PixelType>::rectangular >
00057 class MatrixImageFactory {
00058   typedef mat::MatrixAdapter<BaseMatrixType> MatrixWindow;
00059 
00060   bool paper_colors;
00061   double size_scale;
00062   int border;
00063   Rectangle box;
00064   const ColorLookup<PixelType>* strength_clu;
00065   PixelType bordercolor;
00066   
00067 public:
00072   MatrixImageFactory(bool paper_based_colors=false, double size_scale_i=1.0, int border_i=1,
00073                      Rectangle plot_subregion=Rectangle(),
00074                      const ColorLookup<PixelType>* strength_colorlookup=0,
00075                      PixelType bordercolor_=PixelType()) 
00076     : paper_colors(paper_based_colors), size_scale(size_scale_i), border(border_i),
00077       box(plot_subregion), strength_clu(strength_colorlookup),
00078       bordercolor(!bordercolor_.istransparent()? bordercolor_ :
00079                   MatrixImage<PixelType,PixelMatrix>::default_border) { }
00080 
00086   MatrixImage<PixelType,PixelMatrix>* operator()
00087     (const BaseMatrixType* const strength=0,   ScaleT strengthscale=ScaleT(),
00088      const BaseMatrixType* const color=0,      ScaleT colorscale=ScaleT(),
00089      const BaseMatrixType* const confidence=0, ScaleT confidencescale=ScaleT()) const {
00090 
00091     /* If no strength or color, there is no plot */
00092     if (!(strength||color))
00093       return 0;
00094       
00095     const typename BaseMatrixType::size_type nrows = (strength? strength->nrows() : color->nrows());
00096     const typename BaseMatrixType::size_type ncols = (strength? strength->ncols() : color->ncols());
00097 
00098     /* Strength-only plots use the ColorLookup constructor for maximum versatility */
00099     if (strength && !color) {
00100       const RYWColorLookup<PixelType> default_clu = RYWColorLookup<PixelType>();
00101       return new MatrixImage<PixelType,PixelMatrix>
00102         (MatrixWindow(*strength,strengthscale,box),
00103          size_scale,border,(strength_clu? *strength_clu : default_clu),bordercolor);
00104     }
00105 
00106 
00107     /* Plots with a specified color dimension use the HSV constructor */
00108     
00109     /* Types to be used */
00110     typedef mat::MatrixInterfaceConstant<T>                              ConstantMatrix;
00111     typedef Generic::max_fnobj<T>                                        MaxFunType;
00112     typedef mat::MatrixInterfaceBinaryAdapter<BaseMatrixType,MaxFunType> MaxFunAdapter;
00113     typedef mat::MatrixInterfaceAdapter<BaseMatrixType>                  MatAdapter;
00114     
00115     /* Dummy matrix to stand in for a missing arument */
00116     const ConstantMatrix   one(1.0,nrows,ncols);
00117     
00118     /* Combined matrix needed for paper-based plot with confidence; allows
00119          color plot to show only where confidence is high. */
00120     const Scale::Linear<T> negate(-1.0,1.0);
00121     const MatAdapter       negstrength(*(strength? strength : (confidence? confidence : &one)),negate); // Minor hack
00122     const MaxFunAdapter    mnp(negstrength,*(confidence? confidence : &one),MaxFunType());
00123     const BaseMatrixType*  confidencedef = (paper_colors ? &mnp : confidence);
00124     
00125     /* Determine appropriate defaults for each matrix */
00126     const BaseMatrixType& strengthmat   = (strength?   *strength      : one);
00127     const BaseMatrixType& confidencemat = (confidence? *confidencedef : one);
00128     
00129     /* Determine appropriate defaults for each matrix */
00130     const BaseMatrixType& sat=(paper_colors ? strengthmat   : confidencemat);
00131     const BaseMatrixType& val=(paper_colors ? confidencemat : strengthmat  );
00132     
00133     const ScaleT& satscale=(paper_colors ? strengthscale : confidencescale);
00134     const ScaleT& valscale=(paper_colors ? confidencescale : strengthscale);
00135     
00136     /* Treat as if confidence was 1.0 if there is none */
00137     return new MatrixImage<PixelType,PixelMatrix>
00138     (MatrixWindow(*color,colorscale,box),
00139      MatrixWindow(sat,satscale,box),
00140      MatrixWindow(val,valscale,box),
00141      size_scale,border,bordercolor);
00142   }
00143 };
00144 
00145 
00146  
00147 } /* namespace Plot */
00148 #endif /* __MATRIX_IMAGE_FACTORY_H__ */

Generated on Mon Jan 20 02:35:44 2003 for RF-LISSOM by doxygen1.3-rc2