OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
entity_renderer.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_ENTITY_RENDERER_HH
20 #define OST_GFX_ENTITY_RENDERER_HH
21 
22 /*
23  Author: Stefan Scheuber, Marco Biasini
24 */
25 
26 
27 #if defined(GetAtomProps)
28 #undef GetAtomProps
29 #endif
30 #include <vector>
31 
33 #include <ost/mol/entity_view.hh>
34 #include <ost/mol/atom_handle.hh>
36 
37 #include <ost/gfx/color.hh>
38 #include <ost/gfx/gfx_object.hh>
39 #include <ost/gfx/module_config.hh>
40 #include <ost/gfx/render_pass.hh>
41 #include <ost/gfx/vertex_array.hh>
42 #include <ost/gfx/exporter_fw.hh>
43 
45 
52 #if OST_IMG_ENABLED
54 #endif //OST_IMG_ENABLED
55 
56 #include "mapped_property.hh"
57 #include "entity_renderer_fw.hh"
58 
59 namespace ost { namespace gfx { namespace impl {
60 
61 typedef enum {
62  DIRTY_VIEW = 0x1,
63  DIRTY_VA = 0x2
64 } DirtyFlag;
65 
66 typedef unsigned int DirtyFlags;
67 
70 public:
72  virtual ~EntityRenderer(){}
73 
75  void AddView(const mol::EntityView& view);
76 
77  void SubstractView(const mol::EntityView& view);
79  void ClearViews();
80 
81  virtual bool HasDataToRender() const;
82 
83  virtual const String& GetName() const;
84 
85  void SetEnabled(bool enabled=true);
86 
87  bool IsEnabled() const;
88 
90  bool HasSelection() const;
91 
93  void SetSelection(const mol::EntityView& sel);
94 
96  void SetVisible(const mol::EntityView& view, bool visible);
97 
98  const Color& GetSelectionColor() const;
99 
100  const Color& GetSelectionColorOutline() const;
101 
107  mol::EntityView GetFullView();
108 
109  mol::EntityView GetEffectiveView();
110 
112  virtual void UpdateViews()=0;
113 
115  virtual void PrepareRendering()=0;
116 
124  virtual void Render(RenderPass pass);
125 
127  virtual void RenderPov(PovState& pov, const std::string& name);
128 
130  virtual void Export(Exporter* ex);
131 
132  virtual bool CanSetOptions(RenderOptionsPtr& render_options)=0;
133  virtual void SetOptions(RenderOptionsPtr& render_options)=0;
134 
135  virtual RenderOptionsPtr GetOptions()=0;
136 
137  virtual geom::AlignedCuboid GetBoundingBox() const=0;
138 
143  virtual void PickAtom(const geom::Line3& line, Real line_width,
144  mol::AtomHandle& picked_atom)=0;
145 
150  virtual void PickBond(const geom::Line3& line, Real line_width,
151  mol::BondHandle& picked_bond)=0;
152 
153  virtual void RenderOptionsChanged();
154 
155  virtual void Apply(const gfx::ByElementColorOp& op)=0;
156  virtual void Apply(const gfx::ByChainColorOp& op)=0;
157  virtual void Apply(const gfx::UniformColorOp& op)=0;
158  virtual void Apply(const gfx::GradientLevelColorOp& op)=0;
159  virtual void Apply(const gfx::EntityViewColorOp& op)=0;
160 #if OST_IMG_ENABLED
161  virtual void Apply(const gfx::MapHandleColorOp& op)=0;
162 #endif
163 
164  bool IsDirty() const;
165 
166  void FlagPositionsDirty();
167 
168  void Debug(unsigned int flags);
169 
170  IndexedVertexArray& VA() {return va_;}
171 protected:
172  virtual void SetName(const String& name);
173 
175  bool enabled_;
176 
181 
185 
188  unsigned int debug_flags_;
189  float opacity_;
190 };
191 
192 //Simplify color ops
194  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
195  return std::make_pair(true,GfxObj::Ele2Color(atom.GetElement()));
196  }
197 };
198 
201  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
202  return std::make_pair(true,op_.GetColor(atom.GetResidue().GetChain().GetName()));
203  }
205 };
206 
208  UniformGetCol(const Color& col):col_(col){ }
209  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
210  return std::make_pair(true,col_);
211  }
212  const Color& col_;
213 };
214 
217  property_(op.GetProperty()),
218  epm_(property_, op.GetLevel()),
219  gradient_(op.GetGradient()),
220  minv_(op.GetMinV()),
221  maxv_(op.GetMaxV()),
222  clamp_(op.GetClamp())
223  {}
224  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
225  try{
226  float r = epm_.Get(atom, minv_);
227  if(clamp_) {
228  float n=Normalize(r, minv_, maxv_);
229  return std::make_pair(true,gradient_.GetColorAt(n));
230  } else {
231  if(r>=minv_ && r<=maxv_) {
232  float n=Normalize(r, minv_, maxv_);
233  return std::make_pair(true,gradient_.GetColorAt(n));
234  } else {
235  return std::make_pair(false,Color());
236  }
237  }
238  }catch(std::exception&){
239  LOG_DEBUG("property " << property_ << " not found");
240  return std::make_pair(false,Color());
241  }
242  return std::make_pair(false,Color());
243  }
247  float minv_, maxv_;
248  bool clamp_;
249 };
250 
252  EntityViewGetCol(const EntityViewColorOp& op):property_(op.GetProperty()),
253  ev_(op.GetEntityView()),
254  gradient_(op.GetGradient()),
255  minv_(op.GetMinV()),
256  maxv_(op.GetMaxV()){}
257  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
258  return std::make_pair(true,MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos()));
259  }
263  float minv_, maxv_;
264 };
265 
266 #if OST_IMG_ENABLED
267 struct MapHandleGetCol {
268  MapHandleGetCol(const MapHandleColorOp& op):property_(op.GetProperty()),
269  mh_(op.GetMapHandle()),
270  gradient_(op.GetGradient()),
271  minv_(op.GetMinV()),
272  maxv_(op.GetMaxV()){}
273  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
274  return std::make_pair(true,MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos()));
275  }
276  String property_;
277  img::MapHandle mh_;
278  Gradient gradient_;
279  float minv_, maxv_;
280 };
281 #endif
282 
283 }}} //ns
284 
285 #endif /* ENTITYRENDERER_HH_ */
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
std::string String
Definition: base.hh:54
Handle to atom datatype.
Definition: atom_handle.hh:37
float Real
Definition: base.hh:44
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
axis-aligned cuboid
GradientLevelGetCol(const GradientLevelColorOp &op)
virtual const img::MapHandle & GetMapHandle() const
Real Get(const AtomHandle &atom) const
get float property throwing an exception when the value does not exist
Line3.
Definition: composite3.hh:39
#define DLLEXPORT_OST_GFX
ChainHandle GetChain() const
The chain this residue is attached to.
unsigned int DirtyFlags
const String & GetElement() const
returns the element name of the atom
ResidueHandle GetResidue() const
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
Color GetColor(const String &ident) const
const geom::Vec3 & GetPos() const
Get global position in cartesian coordinates with entity transformations applied. ...
float Normalize(float v, float min_v, float max_v)
virtual gfx::Gradient GetGradient() const
Color GetColorAt(float t) const
get color
static Color Ele2Color(const String &ele)
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
boost::shared_ptr< RenderOptions > RenderOptionsPtr
const ByChainColorOp & op_
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
chemical bond
Definition: bond_handle.hh:34
String GetName() const
float DLLEXPORT_OST_GFX MappedProperty(const mol::EntityView &ev, const String &prop, const geom::Vec3 &pos)
virtual float GetMaxV() const
Manage shared instances of images.
definition of EntityView
Definition: entity_view.hh:86
EntityViewGetCol(const EntityViewColorOp &op)
virtual float GetMinV() const
#define LOG_DEBUG(m)
Definition: log.hh:93
ByChainGetCol(const ByChainColorOp &op)
virtual String GetProperty() const
color gradient
Definition: gradient.hh:59
mol::EntityPropertyMapper epm_