OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
surface.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GFX_SURFACE_HH
20 #define OST_GFX_SURFACE_HH
21 
22 /*
23  graphical representation of all kinds of surfaces
24 
25  Author: Ansgar Philippsen
26 */
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include <ost/config.hh>
31 #include <ost/mol/surface.hh>
32 #include "gfx_object.hh"
33 #include "vertex_array.hh"
34 
39 
40 #if OST_IMG_ENABLED
42 #endif //OST_IMG_ENABLED
43 
44 namespace ost { namespace gfx {
45 
46 class Surface;
47 typedef boost::shared_ptr<Surface> SurfaceP;
48 
50  typedef std::map<mol::SurfaceVertexID, VertexID> VMap;
51 
52 public:
53  Surface(const String& name, const mol::SurfaceHandle& sh);
54 
55  virtual void OnRenderModeChange();
56 
57  virtual void CustomRenderGL(RenderPass pass);
58  virtual void CustomRenderPov(PovState& pov);
59  virtual geom::AlignedCuboid GetBoundingBox(bool use_global=false) const;
60 
61  mol::SurfaceHandle GetHandle() const;
62 
63  void Rebuild();
64  void Replace(const mol::SurfaceHandle& sh);
65 
67  void SetColor(const Color& col, const String& selection=String(""));
68 
69  // GfxObj property interface
70  virtual void ColorBy(const mol::EntityView& ev,
71  const String& prop,
72  const Gradient& g, float minv, float maxv);
73 #if OST_IMG_ENABLED
74  // GfxObj property interface
75  virtual void ColorBy(const img::MapHandle& mh,
76  const String& prop,
77  const Gradient& g,float minv, float maxv);
78 #endif //OST_IMG_ENABLED
79 
80  // map property to color gradient from minv to maxv
81  void ColorBy(const String& prop,
82  const Gradient& gradient,
83  float minv,float maxv,
85 
86  // convenience
87  void ColorBy(const String& prop,
88  const Gradient& gradient,
90 
91  // convenience
92  void ColorBy(const String& prop,
93  const Color& c1, const Color& c2,
94  float min, float max,
96 
97  // convenience
98  void ColorBy(const String& prop,
99  const Color& c1, const Color& c2,
101 
102 
103  void Apply(const gfx::UniformColorOp& op, bool store=true);
104  void Apply(const gfx::BasicGradientColorOp& op, bool store=true);
105  void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
106  void Apply(const gfx::EntityViewColorOp& op, bool store=true);
107 #if OST_IMG_ENABLED
108  void Apply(const gfx::MapHandleColorOp& op, bool store=true);
109 #endif
110 
111  void CleanColorOps();
112  void ReapplyColorOps();
113 
114 protected:
115  virtual void CustomPreRenderGL(bool flag);
116 
117 private:
118 
119  mol::SurfaceHandle sh_;
120  VMap vmap_;
121 
122  mutable bool recalc_bb_;
123 
124  boost::ptr_vector<gfx::ColorOp> c_ops_;
125 };
126 
127 }} // ns
128 
129 #endif