imagemap.h

Go to the documentation of this file.
00001 /* file name  : imagemap.h
00002  * authors    : Michael Brailsford
00003  * created    : Thu Oct 25 01:07:13 -0500 2007
00004  * copyright  : (c) 2007 Michael Brailsford
00005  */
00006 
00007 #ifndef IMAGEMAP_H
00008 #define IMAGEMAP_H
00009 
00010 #include <Magick++.h>
00011 
00012 #include "solidmaterial.h"
00013 #include "pluginfactory.h"
00014 
00015 inline Material * new_immagemap_material(std::map<std::string, std::string> props);
00016 
00018 class ImageMap : public Material {
00020     class StaticInit
00021     {
00022         public:
00024             StaticInit()
00025             {
00026                 log_info("Registering as \"image\" ");
00027                 MaterialFactory::get_instance()->registerPlugin("image", sigc::ptr_fun(new_immagemap_material));
00028             }
00029     };
00030 
00031     private:
00033         static StaticInit m_init;
00034 
00035     protected:
00037         Magick::Image m_image;
00038 
00042         double m_reflection_coefficient;
00043 
00047         double m_diffusion_factor;
00048 
00051         double m_reflectivity;
00052 
00054         bool m_is_light_source;
00055 
00058         double m_opacity;
00059 
00061         double m_refraction_index; 
00062 
00064         virtual void normalize_opacity() {
00065             m_opacity = m_opacity > TRANSPARENT ? TRANSPARENT
00066                       : m_opacity < OPAQUE      ? OPAQUE
00067                       :                           m_opacity;
00068         }
00069 
00070 
00071     public:
00072         ImageMap(std::string &image_name, bool is_light , double reflection, 
00073                 double diffuse , double reflectivity, double refraction, double opacity) 
00074             : m_is_light_source(is_light),    m_reflection_coefficient(reflection),
00075               m_diffusion_factor(diffuse),    m_reflectivity(reflectivity),
00076               m_refraction_index(refraction), m_opacity(opacity)
00077         {
00078             m_image.read(image_name);
00079         }
00080 
00081         ImageMap(ImageMap &);
00082         ~ImageMap() {}
00083 
00084         virtual Magick::Color get_color(const Point3D& intersection_point) const {
00085             Vector v(0,0,0);
00086             return get_color(intersection_point, NULL);
00087         }
00088 
00089         virtual Magick::Color get_color(const Point3D& intersection_point, const Renderable * const obj) const;
00090 
00096         virtual bool is_light(const Point3D& intersection_point) const;
00097 
00102         virtual void set_is_light(bool v);
00103 
00107         virtual double get_diffuse(const Point3D& intersection_point) const;
00108 
00111         virtual void set_diffuse(double diffuse);
00112 
00116         virtual double get_reflection(const Point3D& intersection_point) const;
00117 
00121         virtual double get_reflectivity(const Point3D& intersection_point) const;
00122 
00128         virtual double get_refraction_index(const Point3D& intersection_point) const;
00129 
00133         virtual double get_opacity(const Point3D& intersection_point) const;
00134 
00139         virtual void set_opacity(double opacity);
00140 };
00141 
00142 Material * new_immagemap_material(std::map<std::string, std::string> props) {
00143     bool isLight = props.count("light") > 0;
00144 
00145     std::string image_name("");
00146     if(props.find("image") != props.end()) {
00147         image_name = props["image"];
00148     }
00149 
00150     double reflection = props.count("reflection") > 0 ?
00151         (double)strtod(props["reflection"    ].c_str(), NULL)   : 1.0;
00152 
00153     double diffusion = props.count("diffusion") > 0 ?
00154         (double)strtod(props["diffusion"].c_str(), NULL)        :  1.0;
00155 
00156     double reflectivity = props.count("reflectivity") > 0 ?
00157         (double)strtod(props["reflectivity"].c_str(), NULL)     :  35.0;
00158 
00159     double refraction = props.count("refraction") > 0 ?
00160         (double)strtod(props["refraction"].c_str(), NULL)       :  1.0;
00161 
00162     double opacity = props.count("opacity") > 0 ?
00163         (double)strtod(props["opacity"].c_str(), NULL)          :  OPAQUE;
00164 
00165     log_debug("Creating material '%s' with:", props["name"].c_str());
00166     log_debug("  reflection:   %2.2f", reflection  );
00167     log_debug("  diffusion:    %2.2f", diffusion   );
00168     log_debug("  reflectivity: %2.2f", reflectivity);
00169     log_debug("  refraction:   %2.2f", refraction  );
00170     log_debug("  opacity:      %2.2f", opacity     );
00171     log_debug("  image:        %s",    image_name.c_str()  );
00172 
00173     return new ImageMap( image_name, isLight,
00174             reflection, diffusion, reflectivity, refraction, opacity);
00175 }
00176 #endif
00177 

Generated on Tue Oct 30 22:12:15 2007 for mbrt by  doxygen 1.5.2