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-2020 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 
40 
42 
43 #include "gradient.hh"
44 #include "entity_fw.hh"
45 #include "impl/backbone_trace.hh"
46 #include "impl/entity_detail.hh"
47 
48 namespace ost { namespace gfx {
49 
50 typedef std::vector<RenderMode::Type> RenderModeTypes;
51 
61 
62 public:
68  Entity(const String& name,
69  const mol::EntityHandle& eh,
70  const mol::Query& q=mol::Query(),
71  mol::QueryFlags f=0);
72 
74  Entity(const String& name,
76  const mol::EntityHandle& eh,
77  const mol::Query& q=mol::Query(),
78  mol::QueryFlags f=0);
79 
82  Entity(const String& name,
83  const mol::EntityView& ev);
84 
86  Entity(const String& name,
88  const mol::EntityView& ev);
89  virtual ~Entity();
90 
91  virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
92 
93  // ProcessLimits uses the default implementation of bounding box
94 
96  virtual void CustomRenderGL(RenderPass pass);
97 
98  virtual void RefreshVA();
99 
100  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim,
101  bool pick_flag);
102 
109  mol::AtomHandle PickAtom(const geom::Line3& line, Real line_width=0.5);
110 
111 
118  mol::BondHandle PickBond(const geom::Line3& line, Real line_width=0.5);
119 
120 
121  virtual void OnRenderModeChange();
122 
123  const String GetRenderModeName(RenderMode::Type mode);
124 
125  void SetEnableRenderMode(RenderMode::Type mode, bool enable);
126 
127  bool IsRenderModeEnabled(RenderMode::Type mode);
128 
129  RenderModeTypes GetNotEmptyRenderModes();
130 
131  void SetRenderMode(RenderMode::Type mode, const mol::EntityView& view,
132  bool keep=false);
133  void SetRenderMode(RenderMode::Type mode, const String& selection,
134  bool keep=false);
135  virtual void SetRenderMode(RenderMode::Type mode);
136 
137  mol::EntityView GetRenderView(RenderMode::Type mode);
138 
139  virtual void SetVisible(const mol::EntityView& view, bool visible);
140 
141  virtual void SetVisible(const String& sel, bool visible);
142  virtual void OptionsChanged(RenderMode::Type mode);
143 
144  virtual void SetOpacity(float f);
145  virtual float GetOpacity() const {return opacity_;}
146  virtual void SetOutlineWidth(float f);
147  virtual void SetOutlineExpandFactor(float f);
148  virtual void SetOutlineExpandColor(const Color& c);
149  virtual void SetClipOffset(float f);
150 
153  void Reset(const mol::EntityHandle& eh);
156  void Reset(const mol::EntityHandle& eh, const mol::Query& q);
159  void Reset(const mol::EntityHandle& eh, const mol::Query& q, mol::QueryFlags flags);
162  void Reset(const mol::EntityView& ev);
164  /*
165  the naming here is misleading - this method WON'T be called upon FlagRebuild
166  */
167  void Rebuild();
168 
171  void UpdatePositions();
172 
174  void UpdateView();
175 
177  void SetColor(const Color& col, const String& selection=String(""));
178 
179  // \brief detail coloring
180  void SetDetailColor(const Color& col, const String& selection=String(""));
181 
183  void SetColorForAtom(const Color& col,
184  const mol::AtomHandle& atom);
185 
187  void ColorByElement();
188 
190  void ColorByElement(const String& selection);
191 
193  void ColorByChain();
194 
196  void ColorByChain(const String& selection);
197 
199  mol::EntityView GetView() const;
200 
203  void SetQuery(const mol::Query& q);
204 
206  mol::QueryViewWrapper GetQueryView() const;
208  void SetQueryView(const mol::QueryViewWrapper& qv);
209 
211  mol::EntityHandle GetEntity() const;
212 
213  // turn blur on or off (experimental feature)
214  void SetBlur(bool f);
215  // set atom positions as n-1 for blur (experimental feature)
216  void BlurSnapshot();
217  // blur transparency falloffs (experimental feature)
218  void SetBlurFactors(float bf1,float bf2);
219 
222  void SetSelection(const mol::EntityView& view);
223 
226  mol::EntityView GetSelection() const;
227 
228  // GfxObj property interface
229  virtual void ColorBy(const mol::EntityView& ev,
230  const String& prop,
231  const Gradient& g, float minv, float maxv);
232 
233  // GfxObj property interface
234  virtual void ColorBy(const img::MapHandle& mh,
235  const String& prop,
236  const Gradient& g,float minv, float maxv);
237 
238  // map property to color gradient from minv to maxv
239  void ColorBy(const String& prop,
240  const Gradient& gradient,
241  float minv,float maxv,
243 
244  // temporarily here, will be moved to py interface
245  void ColorBy(const String& prop,
246  const Gradient& gradient,
247  float minv,float maxv,
248  bool clamp);
249 
250  // temporary, should be incorporated with ColorBy
251  void DetailColorBy(const String& prop,
252  const Gradient& gradient,
253  float minv,float maxv,
255 
256  // convenience
257  void ColorBy(const String& prop,
258  const Gradient& gradient,
260 
261  // convenience
262  void ColorBy(const String& prop,
263  const Gradient& gradient,
264  const String& selection);
265 
266  // convenience
267  void ColorBy(const String& prop,
268  const Color& c1, const Color& c2,
269  float min, float max,
271 
272  // convenience
273  void ColorBy(const String& prop,
274  const Color& c1, const Color& c2,
276 
277 
278  void RadiusBy(const String& prop,
279  float rmin, float rmax,
280  float vmin, float vmax,
282 
283  void RadiusBy(const String& prop,
284  float rmin, float rmax,
286 
287  void ResetRadiusBy();
288 
289  void Apply(const gfx::ByElementColorOp& op, bool store=true);
290  void Apply(const gfx::ByChainColorOp& op, bool store=true);
291  void Apply(const gfx::UniformColorOp& op, bool store=true);
292  void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
293  void Apply(const gfx::EntityViewColorOp& op, bool store=true);
294  void Apply(const gfx::MapHandleColorOp& op, bool store=true);
295 
296  void CleanColorOps();
297  void ReapplyColorOps();
298 
309  RenderOptionsPtr GetOptions(RenderMode::Type render_mode);
310  void SetOptions(RenderMode::Type render_mode,
311  RenderOptionsPtr& render_options);
312  void ApplyOptions(RenderMode::Type render_mode,
313  RenderOptionsPtr& render_options);
314  bool HasSelection() const;
315 
316  void SetSeqHack(bool b);
317  bool GetSeqHack() const;
318 
319  virtual void Export(Exporter* ex);
320 
321 protected:
322 
323  virtual void CustomPreRenderGL(bool flag);
324  virtual void CustomRenderPov(PovState& pov);
325  void UpdateSelection();
326  bool UpdateIfNeeded() const;
327  void CacheBoundingBox() const;
328  impl::EntityRenderer* GetOrCreateRenderer(RenderMode::Type);
329 private:
331 
332  mutable mol::EntityView cached_view_;
333  mutable bool update_view_;
334 
335  mutable geom::AlignedCuboid bbox_;
336  mol::EntityView sel_;
337  bool sel_update_;
338  mutable impl::BackboneTrace trace_;
339 
340  void init(RenderMode::Type);
341 
342  void set_static_max_rad();
343  void do_update_view() const;
344 
345  typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap;
346  mutable RendererMap renderer_;
347 
348  float opacity_;
349  bool blur_;
350  float blurf1_;
351  float blurf2_;
352  mutable bool needs_update_;
353 };
354 
355 
361 
367 
377 
378 
383 }} // ns
384 
385 #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:50
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:60
#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:43
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:145
Manage shared instances of images.
definition of EntityView
Definition: entity_view.hh:86
color gradient
Definition: gradient.hh:59