HyperspaceExplorer 0.7.1
ColorManager.h
00001 /*
00002 Hyperspace Explorer - visualizing higher-dimensional geometry
00003 Copyright (C) 2010  Lene Preuss <lene.preuss@gmail.com>
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 */
00020 
00021 #ifndef COLOR_MANAGER_H
00022 #define COLOR_MANAGER_H
00023 
00024 #include <vector>
00025 #include <map>
00026 #include <string>
00027 #include <sstream>
00028 
00029 #include "SingletonHolder.h"
00030 
00031 #include "Color.h"
00032 #include "Vector.h"
00033 #include "Displayable.h"
00034 
00037 
00039 
00065 class ColorManager {
00066     public:
00068         ColorManager();
00069 
00071         ColorManager(Displayable *);
00072 
00073         virtual ~ColorManager() { }
00074 
00076         virtual void setFunction(Displayable *);
00077 
00079         Displayable *getFunction() const { return f; }
00080 
00082         virtual void calibrateColor(const VecMath::Vector<4> &x,
00083                                     const Color &col = Color()) = 0;
00084 
00086         void setRGB(const Color &);
00087 
00089         virtual void setColor(const VecMath::Vector<4> &);
00090 
00092 
00093         virtual Color getColor(const VecMath::Vector<4> &x) = 0;
00094 
00096         virtual void depthCueColor(double wmax, double wmin, double w,
00097                                    const VecMath::Vector<4> &x) = 0;
00098 
00100         virtual std::string getContents() { return ""; }
00101 
00102     protected:
00103 
00105         typedef std::vector<Color> colorvec1D;
00107         typedef std::vector<colorvec1D> colorvec2D;
00109         typedef std::vector<colorvec2D> colorvec3D;
00111         typedef std::vector<colorvec3D> colorvec4D;
00113         typedef std::map<VecMath::Vector<4>, Color> colormap;
00114 
00116         double getoffset4Ddepthcue() { return offset4Ddepthcue; }
00117 
00119         double getAlpha() { return ALPHA; }
00120 
00121     private:
00122         Displayable* f;      
00123 
00125         double ambientColorModifier;
00127         double specularColorModifier;
00129         double specularColorMinimum;
00131         double SHININESS;
00133         double ALPHA;
00135         double offset4Ddepthcue;
00136 };
00137 
00139 
00153 class ColorManagerManager {
00154     public:
00156         struct BadColorManagerException: public std::runtime_error {
00158             BadColorManagerException(const std::string &);
00159         };
00160 
00162         struct ColorManagerUnsetException: public std::logic_error {
00164             ColorManagerUnsetException(const std::string &);
00165         };
00166 
00168         typedef ColorManager *(*CreateColMgrCallback)();
00169 
00171         void setColorManager(ColorManager *cm);
00172 
00174         void setFunction(Displayable *_f);
00175 
00177         void calibrateColor(const VecMath::Vector<4> &, const Color & = Color());
00178 
00180         void setColor(const VecMath::Vector<4> &x);
00181 
00183         Color getColor(const VecMath::Vector<4> &x);
00184 
00186         void depthCueColor(double wmax, double wmin, double w,
00187                            const VecMath::Vector<4> &x);
00188 
00190         void setRGB(const Color &_col);
00191 
00193         std::string getContents();
00194 
00196         bool registerColorManager(const std::string &, CreateColMgrCallback);
00197 
00199         bool unregisterColorManager(const std::string &);
00200 
00202         std::vector<std::string> getRegisteredColorManagers();
00203 
00205         void setColorManager(const std::string &);
00206 
00208         bool isColorManagerSet() const;
00209 
00210     private:
00212         typedef std::map<std::string, CreateColMgrCallback> CallbackMap;
00213 
00215         ColorManagerManager(): callbacks() { }
00217         ColorManagerManager(const ColorManagerManager &);
00219         ColorManagerManager &operator=(const ColorManagerManager &);
00221         ~ColorManagerManager() { }
00222 
00223         std::auto_ptr<ColorManager> colorManager;   
00224 
00225         CallbackMap callbacks;              
00226 
00228         friend class Loki::CreateUsingNew<ColorManagerManager>;
00229 
00230 };
00231 
00232 typedef Loki::SingletonHolder<ColorManagerManager> ColMgrMgr;
00233 
00234 
00236 
00248 class xyz2RGBColorManager: public ColorManager {
00249     public:
00250         xyz2RGBColorManager(): ColorManager(), col(colormap()) { }
00251 
00253 
00254         xyz2RGBColorManager(Displayable *_f): ColorManager(_f), col(colormap()) { }
00255 
00256         virtual ~xyz2RGBColorManager() { }
00257 
00259         virtual void setFunction(Displayable *);
00260 
00261         virtual void calibrateColor(const VecMath::Vector<4> &x,
00262                                     const Color &_col = Color());
00263 
00264         virtual Color getColor(const VecMath::Vector<4> &x);
00265 
00266         virtual void depthCueColor(double wmax, double wmin, double w,
00267                                    const VecMath::Vector<4> &);
00268 
00270         virtual std::string getContents();
00271 
00272     private:
00273         Color computeColorFromNeighbors(const VecMath::Vector<4> &x);
00274         std::pair<std::vector<VecMath::Vector<4> >, std::vector<double> >
00275                 findClosestPoints(const VecMath::Vector<4> &, unsigned = 5);
00276         Color averageColors(const std::vector<Color> &);
00277 
00278         colormap col; 
00279 };
00280 
00281 namespace {
00282     ColorManager *createXYZ2RGB() { return new xyz2RGBColorManager(); }
00283     const bool registeredC0 =
00284             ColMgrMgr::Instance().registerColorManager("XYZ to RGB", createXYZ2RGB);
00285 }
00286 
00288 
00292 class Fastxyz2RGBColorManager: public ColorManager {
00293     public:
00294         Fastxyz2RGBColorManager();
00295 
00297         Fastxyz2RGBColorManager(Displayable *);
00298 
00299         virtual ~Fastxyz2RGBColorManager() { }
00300 
00302         virtual void setFunction(Displayable *);
00303 
00304         virtual void calibrateColor(const VecMath::Vector<4> &,
00305                                     const Color & = Color());
00306 
00307         virtual Color getColor(const VecMath::Vector<4> &);
00308 
00309         virtual void depthCueColor(double wmax, double wmin, double w,
00310                                    const VecMath::Vector<4> &);
00311 
00313         virtual std::string getContents();
00314 
00315     private:
00316         float _xmin;            
00317         float _xmax;            
00318         float _ymin;            
00319         float _ymax;            
00320         float _zmin;            
00321         float _zmax;            
00322         float _wmin;            
00323         float _wmax;            
00324 
00325         float _opacityRange;    
00326 };
00327 
00328 namespace {
00329     ColorManager *createFastXYZ2RGB() { return new Fastxyz2RGBColorManager(); }
00330     const bool registeredC1 =
00331             ColMgrMgr::Instance().registerColorManager("XYZ to RGB (fast)", createFastXYZ2RGB);
00332 }
00333 
00335 
00336 class depth2RGBColorManager: public ColorManager {
00337     public:
00338         depth2RGBColorManager(): ColorManager(), _wmin(1e6), _wmax(-1e6) { }
00339 
00341 
00342         depth2RGBColorManager(Displayable *_f):
00343             ColorManager(_f), _wmin(1e6), _wmax(-1e6) { }
00344 
00345         virtual ~depth2RGBColorManager() { }
00346 
00348         virtual void setFunction(Displayable *);
00349 
00350         virtual void calibrateColor(const VecMath::Vector<4> &,
00351                                     const Color & = Color());
00352 
00353         virtual Color getColor(const VecMath::Vector<4> &);
00354 
00355         virtual void depthCueColor(double, double, double,
00356                                    const VecMath::Vector<4> &);
00357 
00359         virtual std::string getContents();
00360 
00361     private:
00363         Color computeColorFromW(double);
00364 
00365         double _wmin;   
00366         double _wmax;   
00367 };
00368 
00369 namespace {
00370     ColorManager *createDepth2RGB() { return new depth2RGBColorManager(); }
00371     const bool registeredC2 =
00372             ColMgrMgr::Instance().registerColorManager("W coordinate to RGB",
00373                                                        createDepth2RGB);
00374 }
00375 
00377 
00378 class monochromeColorManager: public ColorManager {
00379     public:
00380         monochromeColorManager(): ColorManager() { }
00381 
00383 
00384         monochromeColorManager(Displayable *_f): ColorManager(_f) { }
00385 
00386         virtual ~monochromeColorManager() { }
00387 
00388         virtual void calibrateColor(const VecMath::Vector<4> &,
00389                                     const Color & = Color()) { }
00390 
00391         virtual Color getColor(const VecMath::Vector<4> &) {
00392             return Color(1., 1., 1.);
00393         }
00394 
00395         virtual void depthCueColor(double, double, double,
00396                                    const VecMath::Vector<4> &) { }
00397 };
00398 
00399 namespace {
00400     ColorManager *createMonochrome() { return new monochromeColorManager(); }
00401     const bool registeredC3 =
00402             ColMgrMgr::Instance().registerColorManager("Monochrome",
00403                                                        createMonochrome);
00404 }
00405 
00406 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:14 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo