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 
93  virtual geom::AlignedCuboid GetBoundingBox() const;
94 
95  virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
96  const mol::Transform& tf) const;
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 
155  void Reset(const mol::EntityHandle& eh);
158  void Reset(const mol::EntityHandle& eh, const mol::Query& q);
161  void Reset(const mol::EntityHandle& eh, const mol::Query& q, mol::QueryFlags flags);
164  void Reset(const mol::EntityView& ev);
166  /*
167  the naming here is misleading - this method WON'T be called upon FlagRebuild
168  */
169  void Rebuild();
170 
173  void UpdatePositions();
174 
176  void UpdateView();
177 
179  void SetColor(const Color& col, const String& selection=String(""));
180 
181  // \brief detail coloring
182  void SetDetailColor(const Color& col, const String& selection=String(""));
183 
185  void SetColorForAtom(const Color& col,
186  const mol::AtomHandle& atom);
187 
189  void ColorByElement();
190 
192  void ColorByElement(const String& selection);
193 
195  void ColorByChain();
196 
198  void ColorByChain(const String& selection);
199 
201  mol::EntityView GetView() const;
202 
205  void SetQuery(const mol::Query& q);
206 
208  mol::QueryViewWrapper GetQueryView() const;
210  void SetQueryView(const mol::QueryViewWrapper& qv);
211 
213  mol::EntityHandle GetEntity() const;
214 
215  // turn blur on or off (experimental feature)
216  void SetBlur(bool f);
217  // set atom positions as n-1 for blur (experimental feature)
218  void BlurSnapshot();
219  // blur transparency falloffs (experimental feature)
220  void SetBlurFactors(float bf1,float bf2);
221 
224  void SetSelection(const mol::EntityView& view);
225 
228  mol::EntityView GetSelection() const;
229 
230  // GfxObj property interface
231  virtual void ColorBy(const mol::EntityView& ev,
232  const String& prop,
233  const Gradient& g, float minv, float maxv);
234 
235 #if OST_IMG_ENABLED
236  // GfxObj property interface
237  virtual void ColorBy(const img::MapHandle& mh,
238  const String& prop,
239  const Gradient& g,float minv, float maxv);
240 #endif
241 
242  // map property to color gradient from minv to maxv
243  void ColorBy(const String& prop,
244  const Gradient& gradient,
245  float minv,float maxv,
247 
248  // temporarily here, will be moved to py interface
249  void ColorBy(const String& prop,
250  const Gradient& gradient,
251  float minv,float maxv,
252  bool clamp);
253 
254  // temporary, should be incorporated with ColorBy
255  void DetailColorBy(const String& prop,
256  const Gradient& gradient,
257  float minv,float maxv,
259 
260  // convenience
261  void ColorBy(const String& prop,
262  const Gradient& gradient,
264 
265  // convenience
266  void ColorBy(const String& prop,
267  const Gradient& gradient,
268  const String& selection);
269 
270  // convenience
271  void ColorBy(const String& prop,
272  const Color& c1, const Color& c2,
273  float min, float max,
275 
276  // convenience
277  void ColorBy(const String& prop,
278  const Color& c1, const Color& c2,
280 
281 
282  void RadiusBy(const String& prop,
283  float rmin, float rmax,
284  float vmin, float vmax,
286 
287  void RadiusBy(const String& prop,
288  float rmin, float rmax,
290 
291  void ResetRadiusBy();
292 
293  void Apply(const gfx::ByElementColorOp& op, bool store=true);
294  void Apply(const gfx::ByChainColorOp& op, bool store=true);
295  void Apply(const gfx::UniformColorOp& op, bool store=true);
296 
297  void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
298  void Apply(const gfx::EntityViewColorOp& op, bool store=true);
299 
300 #if OST_IMG_ENABLED
301  void Apply(const gfx::MapHandleColorOp& op, bool store=true);
302 #endif
303 
304  void CleanColorOps();
305  void ReapplyColorOps();
306 
317  RenderOptionsPtr GetOptions(RenderMode::Type render_mode);
318  void SetOptions(RenderMode::Type render_mode,
319  RenderOptionsPtr& render_options);
320  void ApplyOptions(RenderMode::Type render_mode,
321  RenderOptionsPtr& render_options);
322  bool HasSelection() const;
323 
324  void SetSeqHack(bool b);
325  bool GetSeqHack() const;
326 
327  virtual void Export(Exporter* ex);
328 
329 protected:
330 
331  virtual void CustomPreRenderGL(bool flag);
332  virtual void CustomRenderPov(PovState& pov);
333  void UpdateSelection();
334  bool UpdateIfNeeded() const;
335  void CacheBoundingBox() const;
336  impl::EntityRenderer* GetOrCreateRenderer(RenderMode::Type);
337 private:
339 
340  mutable mol::EntityView cached_view_;
341  mutable bool update_view_;
342 
343  mutable geom::AlignedCuboid bbox_;
344  mol::EntityView sel_;
345  bool sel_update_;
346  mutable impl::BackboneTrace trace_;
347 
348  void init(RenderMode::Type);
349 
350  void set_static_max_rad();
351  void do_update_view() const;
352 
353  typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap;
354  mutable RendererMap renderer_;
355 
356  float opacity_;
357  bool blur_;
358  float blurf1_;
359  float blurf2_;
360  mutable bool needs_update_;
361 };
362 
363 
369 
375 
385 
386 
391 }} // ns
392 
393 #endif