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_DATATYPE_LIST_H
00023 # include <BALL/DATATYPE/list.h>
00024 #endif
00025 
00026 #ifndef BALL_VIEW_KERNEL_COMMON_H
00027 # include <BALL/VIEW/KERNEL/common.h>
00028 #endif
00029 
00030 namespace BALL
00031 {
00032   class Atom;
00033 
00034   namespace VIEW
00035   {
00036     class Mesh;
00037         
00054 class BALL_VIEW_EXPORT ColorProcessor
00055   : public UnaryProcessor<GeometricObject*>
00056 {
00057   public:
00058 
00059   BALL_CREATE(ColorProcessor)
00060   
00061   
00062   typedef HashSet<const Composite*>  CompositeSet;
00063 
00065   typedef HashGrid3<const Atom*>  AtomGrid;
00066 
00068   typedef HashGridBox3<const Atom*> AtomBox;
00069 
00071   ColorProcessor();
00072 
00074   ColorProcessor(const ColorProcessor& color_calculator);
00075 
00077   virtual ~ColorProcessor();
00078 
00084   virtual void clear();
00085 
00087   void set(const ColorProcessor& color_calculator);
00088 
00090   virtual bool start();
00091 
00095   const ColorProcessor&  operator = (const ColorProcessor& color_calculator);
00096 
00105   bool updateAlwaysNeeded() { return update_always_needed_;};
00106 
00109   void setDefaultColor(const ColorRGBA& color);
00110 
00113   const ColorRGBA& getDefaultColor() const
00114     {return default_color_;}
00115 
00118   virtual Processor::Result operator() (GeometricObject*& object);
00119 
00126   virtual void getColor(const Composite& composite, ColorRGBA& color_to_be_set);
00127 
00129   Size getTransparency() const
00130     { return transparency_;}
00131 
00135   virtual void setTransparency(Size value);
00136 
00140   void setComposites(const List<const Composite*>* composites);
00141 
00143   const List<const Composite*>* getComposites()
00144     { return composites_;}
00145 
00147   void clearAtomGrid();
00148 
00150   void setAdditionalGridDistance(float distance)
00151     { additional_grid_distance_ = distance;}
00152 
00154   float getAdditionalGridDistance() const
00155     { return additional_grid_distance_;}
00156 
00158   void setMinGridSpacing(float spacing) {min_spacing_ = spacing;}
00159 
00161   AtomGrid& getAtomGrid() 
00162     { return atom_grid_;}
00163 
00170   virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00171 
00173   void setModelType(ModelType type) {model_type_ = type;}
00174 
00175   //_ Create the threedimensional grid from the CompositeSet, or a given Composite 
00176   virtual void createAtomGrid(const Composite* from_mesh = 0);
00177 
00179   const Atom* getClosestItem(const Vector3& v) const;
00180 
00181   protected:
00182 
00183   //_ Colorize the mesh with the computed grid.
00184   virtual void colorMeshFromGrid_(Mesh& mesh);
00185 
00186   //_
00187   virtual bool canUseMeshShortcut_(const Composite&) { return false;}
00188 
00189   bool        update_always_needed_;
00190   //_ a color that will be used if no other color can be calculated.
00191   ColorRGBA   default_color_;
00192   //_ for speedup, we dont have to set transparency each time we color a geometric object
00193   ColorRGBA   selection_color_;
00194   Size        transparency_;
00195 
00196   const       List<const Composite*>* composites_;
00197 
00198   AtomGrid    atom_grid_;
00199   ModelType   model_type_;
00200   const Composite*  last_composite_of_grid_;
00201   float       additional_grid_distance_;
00202   float       min_spacing_;
00204 };
00205 
00206 
00210 class BALL_VIEW_EXPORT InterpolateColorProcessor
00211   : public ColorProcessor
00212 {
00213   public: 
00214 
00216   enum Mode
00217   {
00219     USE_OUTSIDE_COLOR = 0,
00220 
00222     DEFAULT_COLOR_FOR_OUTSIDE_COLORS,
00223 
00225     NO_OUTSIDE_COLORS
00226   };
00227     
00228 
00229   BALL_CREATE(InterpolateColorProcessor)
00230 
00231   
00232   InterpolateColorProcessor();
00233   
00235   InterpolateColorProcessor(const InterpolateColorProcessor& pro);
00236 
00238   virtual bool start();
00239 
00241   void setMode(Mode mode) { mode_ = mode;}
00242 
00244   Mode getMode() const { return mode_;}
00245 
00247   vector<ColorRGBA>& getColors() { return colors_;}
00248   
00250   const vector<ColorRGBA>& getColors() const { return colors_;}
00251 
00253   void setColors(const vector<ColorRGBA>& colors) { colors_ = colors;}
00254 
00256   void setMinColor(const ColorRGBA& color);
00257 
00259   void setMaxColor(const ColorRGBA& color);
00260 
00262   const ColorRGBA& getMinColor() const;
00263   
00265   const ColorRGBA& getMaxColor() const;
00266 
00268   void setMaxValue(float value) {max_value_ = value;}
00269 
00271   float getMaxValue() const { return max_value_;}
00272 
00274   void setMinValue(float value) { min_value_ = value;}
00275 
00277   float getMinValue() const { return min_value_;}
00278 
00282   virtual void interpolateColor(float value, ColorRGBA& color_to_be_set);
00283 
00284   protected:
00285 
00286   // out of range colors
00287   ColorRGBA min_color_,
00288             max_color_;
00289 
00290   // standard colors
00291   vector<ColorRGBA> colors_;
00292 
00293   Mode      mode_;
00294 
00295   float     max_value_;
00296   float     min_value_;
00297   
00298   // value distance between two colors
00299   float     x_;
00300 };
00301 
00302 } } // namespaces
00303 
00304 #endif // BALL_VIEW_MODELS_COLORPROCESSOR_H