OpenStructure
Loading...
Searching...
No Matches
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"
46#include "impl/entity_detail.hh"
47
48namespace ost { namespace gfx {
49
50typedef std::vector<RenderMode::Type> RenderModeTypes;
51
61
62public:
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
124
125 void SetEnableRenderMode(RenderMode::Type mode, bool enable);
126
128
130
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
138
139 virtual void SetVisible(const mol::EntityView& view, bool visible);
140
141 virtual void SetVisible(const String& sel, bool visible);
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
172
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
188
190 void ColorByElement(const String& selection);
191
194
196 void ColorByChain(const String& selection);
197
200
203 void SetQuery(const mol::Query& q);
204
209
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)
217 // blur transparency falloffs (experimental feature)
218 void SetBlurFactors(float bf1,float bf2);
219
222 void SetSelection(const mol::EntityView& view);
223
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,
242 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
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,
254 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
255
256 // convenience
257 void ColorBy(const String& prop,
258 const Gradient& gradient,
259 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
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,
270 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
271
272 // convenience
273 void ColorBy(const String& prop,
274 const Color& c1, const Color& c2,
275 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
276
277
278 void RadiusBy(const String& prop,
279 float rmin, float rmax,
280 float vmin, float vmax,
281 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
282
283 void RadiusBy(const String& prop,
284 float rmin, float rmax,
285 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
286
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
298
310 void SetOptions(RenderMode::Type render_mode,
311 RenderOptionsPtr& render_options);
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
321protected:
322
323 virtual void CustomPreRenderGL(bool flag);
324 virtual void CustomRenderPov(PovState& pov);
326 bool UpdateIfNeeded() const;
327 void CacheBoundingBox() const;
329private:
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
axis-aligned cuboid
Three dimensional vector class, using Real precision.
Definition vec3.hh:48
graphical rendering of mol::EntityHandle entites
Definition entity.hh:60
void SetColor(const Color &col, const String &selection=String(""))
set color for selection
void ApplyOptions(RenderMode::Type render_mode, RenderOptionsPtr &render_options)
virtual void SetClipOffset(float f)
virtual void SetVisible(const mol::EntityView &view, bool visible)
virtual void CustomRenderPov(PovState &pov)
virtual void OptionsChanged(RenderMode::Type mode)
void SetQuery(const mol::Query &q)
set a new query to use (deprecated) this will re-create the object based on the given selection
Entity(const String &name, const mol::EntityView &ev)
Initialize with an object name and an explicit mol::Entity view; later calls to Rebuild always use th...
void UpdateSelection()
void SetSeqHack(bool b)
void ColorByElement(const String &selection)
color by element for a specific selection
mol::EntityView GetSelection() const
get selection
void SetOptions(RenderMode::Type render_mode, RenderOptionsPtr &render_options)
void UpdateView()
forces all views to be regenerated from stored queries
void ReapplyColorOps()
bool IsRenderModeEnabled(RenderMode::Type mode)
virtual void RefreshVA()
void Apply(const gfx::GradientLevelColorOp &op, bool store=true)
virtual void OnRenderModeChange()
void SetSelection(const mol::EntityView &view)
set selection
virtual void ColorBy(const mol::EntityView &ev, const String &prop, const Gradient &g, float minv, float maxv)
color each component based on the gradient-mapped property of the given entity
void Apply(const gfx::ByElementColorOp &op, bool store=true)
RenderModeTypes GetNotEmptyRenderModes()
Entity(const String &name, RenderMode::Type m, const mol::EntityView &ev)
ctor variant with explicit graphics mode instead of the default
void RadiusBy(const String &prop, float rmin, float rmax, float vmin, float vmax, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
void Apply(const gfx::MapHandleColorOp &op, bool store=true)
impl::EntityRenderer * GetOrCreateRenderer(RenderMode::Type)
void Reset(const mol::EntityView &ev)
resets entity view this as the same effect as the ctor call with the same parameters
virtual void SetOutlineExpandFactor(float f)
set outline expansion factor (mode 3) this scales with resolution
mol::EntityHandle GetEntity() const
return underlying entity
void Apply(const gfx::EntityViewColorOp &op, bool store=true)
void SetEnableRenderMode(RenderMode::Type mode, bool enable)
void UpdatePositions()
only grab updated positions, dont rebuild the whole thing views won't be regenerated from stored quer...
const String GetRenderModeName(RenderMode::Type mode)
mol::EntityView GetView() const
get view
virtual float GetOpacity() const
returns a value smaller than 1.0 if transparency is used in this object
Definition entity.hh:145
void Reset(const mol::EntityHandle &eh, const mol::Query &q)
resets used entity handle and query replaces underlying entity and query, keeps flags intact
void ColorBy(const String &prop, const Gradient &gradient, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
bool HasSelection() const
void CacheBoundingBox() const
void SetBlurFactors(float bf1, float bf2)
virtual void SetOpacity(float f)
set opacity (1 = no transparency)
void SetDetailColor(const Color &col, const String &selection=String(""))
void SetRenderMode(RenderMode::Type mode, const mol::EntityView &view, bool keep=false)
void SetRenderMode(RenderMode::Type mode, const String &selection, bool keep=false)
virtual void ColorBy(const img::MapHandle &mh, const String &prop, const Gradient &g, float minv, float maxv)
color based on image
virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const
returns the bounding box of this object
void ColorBy(const String &prop, const Color &c1, const Color &c2, float min, float max, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
void Apply(const gfx::UniformColorOp &op, bool store=true)
Entity(const String &name, RenderMode::Type m, const mol::EntityHandle &eh, const mol::Query &q=mol::Query(), mol::QueryFlags f=0)
variant with explicit graphics mode instead of the default
void SetColorForAtom(const Color &col, const mol::AtomHandle &atom)
set color for specific atom
virtual void CustomRenderGL(RenderPass pass)
internal routine
mol::QueryViewWrapper GetQueryView() const
return internally used query view
void ColorBy(const String &prop, const Gradient &gradient, const String &selection)
void SetBlur(bool f)
mol::EntityView GetRenderView(RenderMode::Type mode)
void Reset(const mol::EntityHandle &eh, const mol::Query &q, mol::QueryFlags flags)
resets used entity handle, query and flags this has the same effect as the ctor call with the same pa...
void SetQueryView(const mol::QueryViewWrapper &qv)
set new query view, rebuilding object
mol::AtomHandle PickAtom(const geom::Line3 &line, Real line_width=0.5)
pick atom
virtual bool OnSelect(const geom::Line3 &l, geom::Vec3 &result, float zlim, bool pick_flag)
Entity(const String &name, const mol::EntityHandle &eh, const mol::Query &q=mol::Query(), mol::QueryFlags f=0)
Initialize with an object name, an mol::Entity handle, and optionally with a mol::Query.
void DetailColorBy(const String &prop, const Gradient &gradient, float minv, float maxv, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
void ColorBy(const String &prop, const Gradient &gradient, float minv, float maxv, bool clamp)
void ColorBy(const String &prop, const Gradient &gradient, float minv, float maxv, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
RenderOptionsPtr GetOptions(RenderMode::Type render_mode)
Get render options for given render mode.
virtual ~Entity()
void RadiusBy(const String &prop, float rmin, float rmax, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
virtual void SetOutlineExpandColor(const Color &c)
set outline color (mode 3)
void ColorBy(const String &prop, const Color &c1, const Color &c2, mol::Prop::Level hint=mol::Prop::UNSPECIFIED)
void Reset(const mol::EntityHandle &eh)
resets used entity handle replaces underlying entity, keeps query and flags intact
void Apply(const gfx::ByChainColorOp &op, bool store=true)
virtual void SetVisible(const String &sel, bool visible)
bool UpdateIfNeeded() const
virtual void Export(Exporter *ex)
void ColorByChain(const String &selection)
color by chain for a specific selection
void ColorByElement()
color by element
virtual void SetOutlineWidth(float f)
set outline width in pixels (modes 1 + 2) this does not scale with resolution
bool GetSeqHack() const
virtual void CustomPreRenderGL(bool flag)
void ColorByChain()
color by chain
mol::BondHandle PickBond(const geom::Line3 &line, Real line_width=0.5)
pick bond
void Rebuild()
rebuild graphical object (see ctor comments)
virtual void SetRenderMode(RenderMode::Type mode)
change render mode
main class for all graphic objects
Definition gfx_object.hh:52
color gradient
Definition gradient.hh:59
Manage shared instances of images.
Handle to atom datatype.
Protein or molecule.
definition of EntityView
Selection Query.
Definition query.hh:74
#define DLLEXPORT_OST_GFX
float Real
Definition base.hh:44
std::string String
Definition base.hh:54
std::vector< RenderMode::Type > RenderModeTypes
Definition entity.hh:50
boost::shared_ptr< RenderOptions > RenderOptionsPtr
uint QueryFlags
Definition query.hh:69
Definition base.dox:1