OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
entity.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_HH
20 #define OST_GFX_ENTITY_HH
21 
22 /*
23  Author: Ansgar Philippsen, Marco Biasini
24 */
25 #include <vector>
26 
27 #include <boost/ptr_container/ptr_map.hpp>
28 
29 #include <ost/geom/geom.hh>
30 
39 
40 #if OST_IMG_ENABLED
42 #endif //OST_IMG_ENABLED
43 
45 
46 #include "gradient.hh"
47 #include "entity_fw.hh"
48 #include "impl/backbone_trace.hh"
49 #include "impl/entity_detail.hh"
50 
51 namespace ost { namespace gfx {
52 
53 typedef std::vector<RenderMode::Type> RenderModeTypes;
54 
64 
65 public:
71  Entity(const String& name,
72  const mol::EntityHandle& eh,
73  const mol::Query& q=mol::Query(),
74  mol::QueryFlags f=0);
75 
77  Entity(const String& name,
79  const mol::EntityHandle& eh,
80  const mol::Query& q=mol::Query(),
81  mol::QueryFlags f=0);
82 
85  Entity(const String& name,
86  const mol::EntityView& ev);
87 
89  Entity(const String& name,
91  const mol::EntityView& ev);
92  virtual ~Entity();
93 
94  virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
95 
96  // ProcessLimits uses the default implementation of bounding box
97 
99  virtual void CustomRenderGL(RenderPass pass);
100 
101  virtual void RefreshVA();
102 
103  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim,
104  bool pick_flag);
105 
112  mol::AtomHandle PickAtom(const geom::Line3& line, Real line_width=0.5);
113 
114 
121  mol::BondHandle PickBond(const geom::Line3& line, Real line_width=0.5);
122 
123 
124  virtual void OnRenderModeChange();
125 
126  const String GetRenderModeName(RenderMode::Type mode);
127 
128  void SetEnableRenderMode(RenderMode::Type mode, bool enable);
129 
130  bool IsRenderModeEnabled(RenderMode::Type mode);
131 
132  RenderModeTypes GetNotEmptyRenderModes();
133 
134  void SetRenderMode(RenderMode::Type mode, const mol::EntityView& view,
135  bool keep=false);
136  void SetRenderMode(RenderMode::Type mode, const String& selection,
137  bool keep=false);
138  virtual void SetRenderMode(RenderMode::Type mode);
139 
140  mol::EntityView GetRenderView(RenderMode::Type mode);
141 
142  virtual void SetVisible(const mol::EntityView& view, bool visible);
143 
144  virtual void SetVisible(const String& sel, bool visible);
145  virtual void OptionsChanged(RenderMode::Type mode);
146 
147  virtual void SetOpacity(float f);
148  virtual float GetOpacity() const {return opacity_;}
149  virtual void SetOutlineWidth(float f);
150  virtual void SetOutlineExpandFactor(float f);
151  virtual void SetOutlineExpandColor(const Color& c);
152  virtual void SetClipOffset(float f);
153 
156  void Reset(const mol::EntityHandle& eh);
159  void Reset(const mol::EntityHandle& eh, const mol::Query& q);
162  void Reset(const mol::EntityHandle& eh, const mol::Query& q, mol::QueryFlags flags);
165  void Reset(const mol::EntityView& ev);
167  /*
168  the naming here is misleading - this method WON'T be called upon FlagRebuild
169  */
170  void Rebuild();
171 
174  void UpdatePositions();
175 
177  void UpdateView();
178 
180  void SetColor(const Color& col, const String& selection=String(""));
181 
182  // \brief detail coloring
183  void SetDetailColor(const Color& col, const String& selection=String(""));
184 
186  void SetColorForAtom(const Color& col,
187  const mol::AtomHandle& atom);
188 
190  void ColorByElement();
191 
193  void ColorByElement(const String& selection);
194 
196  void ColorByChain();
197 
199  void ColorByChain(const String& selection);
200 
202  mol::EntityView GetView() const;
203 
206  void SetQuery(const mol::Query& q);
207 
209  mol::QueryViewWrapper GetQueryView() const;
211  void SetQueryView(const mol::QueryViewWrapper& qv);
212 
214  mol::EntityHandle GetEntity() const;
215 
216  // turn blur on or off (experimental feature)
217  void SetBlur(bool f);
218  // set atom positions as n-1 for blur (experimental feature)
219  void BlurSnapshot();
220  // blur transparency falloffs (experimental feature)
221  void SetBlurFactors(float bf1,float bf2);
222 
225  void SetSelection(const mol::EntityView& view);
226 
229  mol::EntityView GetSelection() const;
230 
231  // GfxObj property interface
232  virtual void ColorBy(const mol::EntityView& ev,
233  const String& prop,
234  const Gradient& g, float minv, float maxv);
235 
236 #if OST_IMG_ENABLED
237  // GfxObj property interface
238  virtual void ColorBy(const img::MapHandle& mh,
239  const String& prop,
240  const Gradient& g,float minv, float maxv);
241 #endif
242 
243  // map property to color gradient from minv to maxv
244  void ColorBy(const String& prop,
245  const Gradient& gradient,
246  float minv,float maxv,
248 
249  // temporarily here, will be moved to py interface
250  void ColorBy(const String& prop,
251  const Gradient& gradient,
252  float minv,float maxv,
253  bool clamp);
254 
255  // temporary, should be incorporated with ColorBy
256  void DetailColorBy(const String& prop,
257  const Gradient& gradient,
258  float minv,float maxv,
260 
261  // convenience
262  void ColorBy(const String& prop,
263  const Gradient& gradient,
265 
266  // convenience
267  void ColorBy(const String& prop,
268  const Gradient& gradient,
269  const String& selection);
270 
271  // convenience
272  void ColorBy(const String& prop,
273  const Color& c1, const Color& c2,
274  float min, float max,
276 
277  // convenience
278  void ColorBy(const String& prop,
279  const Color& c1, const Color& c2,
281 
282 
283  void RadiusBy(const String& prop,
284  float rmin, float rmax,
285  float vmin, float vmax,
287 
288  void RadiusBy(const String& prop,
289  float rmin, float rmax,
291 
292  void ResetRadiusBy();
293 
294  void Apply(const gfx::ByElementColorOp& op, bool store=true);
295  void Apply(const gfx::ByChainColorOp& op, bool store=true);
296  void Apply(const gfx::UniformColorOp& op, bool store=true);
297 
298  void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
299  void Apply(const gfx::EntityViewColorOp& op, bool store=true);
300 
301 #if OST_IMG_ENABLED
302  void Apply(const gfx::MapHandleColorOp& op, bool store=true);
303 #endif
304 
305  void CleanColorOps();
306  void ReapplyColorOps();
307 
318  RenderOptionsPtr GetOptions(RenderMode::Type render_mode);
319  void SetOptions(RenderMode::Type render_mode,
320  RenderOptionsPtr& render_options);
321  void ApplyOptions(RenderMode::Type render_mode,
322  RenderOptionsPtr& render_options);
323  bool HasSelection() const;
324 
325  void SetSeqHack(bool b);
326  bool GetSeqHack() const;
327 
328  virtual void Export(Exporter* ex);
329 
330 protected:
331 
332  virtual void CustomPreRenderGL(bool flag);
333  virtual void CustomRenderPov(PovState& pov);
334  void UpdateSelection();
335  bool UpdateIfNeeded() const;
336  void CacheBoundingBox() const;
337  impl::EntityRenderer* GetOrCreateRenderer(RenderMode::Type);
338 private:
340 
341  mutable mol::EntityView cached_view_;
342  mutable bool update_view_;
343 
344  mutable geom::AlignedCuboid bbox_;
345  mol::EntityView sel_;
346  bool sel_update_;
347  mutable impl::BackboneTrace trace_;
348 
349  void init(RenderMode::Type);
350 
351  void set_static_max_rad();
352  void do_update_view() const;
353 
354  typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap;
355  mutable RendererMap renderer_;
356 
357  float opacity_;
358  bool blur_;
359  float blurf1_;
360  float blurf2_;
361  mutable bool needs_update_;
362 };
363 
364 
370 
376 
386 
387 
392 }} // ns
393 
394 #endif
std::string String
Definition: base.hh:54
Handle to atom datatype.
Definition: atom_handle.hh:37
float Real
Definition: base.hh:44
axis-aligned cuboid
std::vector< RenderMode::Type > RenderModeTypes
Definition: entity.hh:53
Protein or molecule.
main class for all graphic objects
Definition: gfx_object.hh:51
Line3.
Definition: composite3.hh:39
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63
#define DLLEXPORT_OST_GFX
Selection Query.
Definition: query.hh:74
uint QueryFlags
Definition: query.hh:69
Three dimensional vector class, using Real precision.
Definition: vec3.hh:42
boost::shared_ptr< RenderOptions > RenderOptionsPtr
chemical bond
Definition: bond_handle.hh:34
virtual float GetOpacity() const
returns a value smaller than 1.0 if transparency is used in this object
Definition: entity.hh:148
Manage shared instances of images.
definition of EntityView
Definition: entity_view.hh:86
color gradient
Definition: gradient.hh:59