BALL  1.4.1
colorProcessor.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: colorProcessor.h,v 1.32.18.1 2007/03/25 21:26:06 oliver Exp $
00005 //
00006 
00007 #ifndef BALL_VIEW_MODELS_COLORPROCESSOR_H
00008 #define BALL_VIEW_MODELS_COLORPROCESSOR_H
00009 
00010 #ifndef BALL_CONCEPT_PROCESSOR_H
00011 # include <BALL/CONCEPT/processor.h>
00012 #endif
00013 
00014 #ifndef BALL_VIEW_KERNEL_GEOMETRICOBJECT_H
00015 # include <BALL/VIEW/KERNEL/geometricObject.h>
00016 #endif
00017 
00018 #ifndef BALL_DATATYPE_HASHGRID_H
00019 # include <BALL/DATATYPE/hashGrid.h>
00020 #endif
00021 
00022 #ifndef BALL_VIEW_KERNEL_COMMON_H
00023 # include <BALL/VIEW/KERNEL/common.h>
00024 #endif
00025 
00026 namespace BALL
00027 {
00028   class Atom;
00029 
00030   namespace VIEW
00031   {
00032     class Mesh;
00033         
00050 class BALL_VIEW_EXPORT ColorProcessor
00051   : public UnaryProcessor<GeometricObject*>
00052 {
00053   public:
00054 
00055   BALL_CREATE(ColorProcessor)
00056   
00057   
00058   typedef HashSet<const Composite*>  CompositeSet;
00059 
00061   typedef HashGrid3<const Atom*>  AtomGrid;
00062 
00064   typedef HashGridBox3<const Atom*> AtomBox;
00065 
00067   ColorProcessor();
00068 
00070   ColorProcessor(const ColorProcessor& color_calculator);
00071 
00073   virtual ~ColorProcessor();
00074 
00080   virtual void clear();
00081 
00083   void set(const ColorProcessor& color_calculator);
00084 
00086   virtual bool start();
00087 
00091   const ColorProcessor&  operator = (const ColorProcessor& color_calculator);
00092 
00101   bool updateAlwaysNeeded() { return update_always_needed_;};
00102 
00105   void setDefaultColor(const ColorRGBA& color);
00106 
00109   const ColorRGBA& getDefaultColor() const
00110     {return default_color_;}
00111 
00114   virtual Processor::Result operator() (GeometricObject*& object);
00115 
00122   virtual void getColor(const Composite& composite, ColorRGBA& color_to_be_set);
00123 
00125   Size getTransparency() const
00126     { return transparency_;}
00127 
00131   virtual void setTransparency(Size value);
00132 
00136   void setComposites(const std::list<const Composite*>* composites);
00137 
00139   const std::list<const Composite*>* getComposites()
00140     { return composites_;}
00141 
00143   void clearAtomGrid();
00144 
00146   void setAdditionalGridDistance(float distance)
00147     { additional_grid_distance_ = distance;}
00148 
00150   float getAdditionalGridDistance() const
00151     { return additional_grid_distance_;}
00152 
00154   void setMinGridSpacing(float spacing) {min_spacing_ = spacing;}
00155 
00157   AtomGrid& getAtomGrid() 
00158     { return atom_grid_;}
00159 
00166   virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00167 
00169   void setModelType(ModelType type) {model_type_ = type;}
00170 
00171   //_ Create the threedimensional grid from the CompositeSet, or a given Composite 
00172   virtual void createAtomGrid(const Composite* from_mesh = 0);
00173 
00175   const Atom* getClosestItem(const Vector3& v) const;
00176 
00177   protected:
00178 
00179   //_ Colorize the mesh with the computed grid.
00180   virtual void colorMeshFromGrid_(Mesh& mesh);
00181 
00182   //_
00183   virtual bool canUseMeshShortcut_(const Composite&) { return false;}
00184 
00185   bool        update_always_needed_;
00186   //_ a color that will be used if no other color can be calculated.
00187   ColorRGBA   default_color_;
00188   //_ for speedup, we dont have to set transparency each time we color a geometric object
00189   ColorRGBA   selection_color_;
00190   Size        transparency_;
00191 
00192   const       std::list<const Composite*>* composites_;
00193 
00194   AtomGrid    atom_grid_;
00195   ModelType   model_type_;
00196   const Composite*  last_composite_of_grid_;
00197   float       additional_grid_distance_;
00198   float       min_spacing_;
00200 };
00201 
00202 
00206 class BALL_VIEW_EXPORT InterpolateColorProcessor
00207   : public ColorProcessor
00208 {
00209   public: 
00210 
00212   enum Mode
00213   {
00215     USE_OUTSIDE_COLOR = 0,
00216 
00218     DEFAULT_COLOR_FOR_OUTSIDE_COLORS,
00219 
00221     NO_OUTSIDE_COLORS
00222   };
00223     
00224 
00225   BALL_CREATE(InterpolateColorProcessor)
00226 
00227   
00228   InterpolateColorProcessor();
00229   
00231   InterpolateColorProcessor(const InterpolateColorProcessor& pro);
00232 
00234   virtual bool start();
00235 
00237   void setMode(Mode mode) { mode_ = mode;}
00238 
00240   Mode getMode() const { return mode_;}
00241 
00243   vector<ColorRGBA>& getColors() { return colors_;}
00244   
00246   const vector<ColorRGBA>& getColors() const { return colors_;}
00247 
00249   void setColors(const vector<ColorRGBA>& colors) { colors_ = colors;}
00250 
00252   void setMinColor(const ColorRGBA& color);
00253 
00255   void setMaxColor(const ColorRGBA& color);
00256 
00258   const ColorRGBA& getMinColor() const;
00259   
00261   const ColorRGBA& getMaxColor() const;
00262 
00264   void setMaxValue(float value) {max_value_ = value;}
00265 
00267   float getMaxValue() const { return max_value_;}
00268 
00270   void setMinValue(float value) { min_value_ = value;}
00271 
00273   float getMinValue() const { return min_value_;}
00274 
00278   virtual void interpolateColor(float value, ColorRGBA& color_to_be_set);
00279 
00280   protected:
00281 
00282   // out of range colors
00283   ColorRGBA min_color_,
00284             max_color_;
00285 
00286   // standard colors
00287   vector<ColorRGBA> colors_;
00288 
00289   Mode      mode_;
00290 
00291   float     max_value_;
00292   float     min_value_;
00293   
00294   // value distance between two colors
00295   float     x_;
00296 };
00297 
00298 } } // namespaces
00299 
00300 #endif // BALL_VIEW_MODELS_COLORPROCESSOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines