OpenStructure
Loading...
Searching...
No Matches
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-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_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
36
37#include <ost/gfx/color.hh>
38#include <ost/gfx/gfx_object.hh>
43
45
53
54#include "mapped_property.hh"
55#include "entity_renderer_fw.hh"
56
57namespace ost { namespace gfx { namespace impl {
58
59typedef enum {
61 DIRTY_VA = 0x2
63
64typedef unsigned int DirtyFlags;
65
68public:
70 virtual ~EntityRenderer(){}
71
73 void AddView(const mol::EntityView& view);
74
75 void SubstractView(const mol::EntityView& view);
77 void ClearViews();
78
79 virtual bool HasDataToRender() const;
80
81 virtual const String& GetName() const;
82
83 void SetEnabled(bool enabled=true);
84
85 bool IsEnabled() const;
86
88 bool HasSelection() const;
89
91 void SetSelection(const mol::EntityView& sel);
92
94 void SetVisible(const mol::EntityView& view, bool visible);
95
96 const Color& GetSelectionColor() const;
97
99
106
108
110 virtual void UpdateViews()=0;
111
113 virtual void PrepareRendering()=0;
114
122 virtual void Render(RenderPass pass);
123
125 virtual void RenderPov(PovState& pov, const std::string& name);
126
128 virtual void Export(Exporter* ex);
129
130 virtual bool CanSetOptions(RenderOptionsPtr& render_options)=0;
131 virtual void SetOptions(RenderOptionsPtr& render_options)=0;
132
134
136
141 virtual void PickAtom(const geom::Line3& line, Real line_width,
142 mol::AtomHandle& picked_atom)=0;
143
148 virtual void PickBond(const geom::Line3& line, Real line_width,
149 mol::BondHandle& picked_bond)=0;
150
151 virtual void RenderOptionsChanged();
152
153 virtual void Apply(const gfx::ByElementColorOp& op)=0;
154 virtual void Apply(const gfx::ByChainColorOp& op)=0;
155 virtual void Apply(const gfx::UniformColorOp& op)=0;
156 virtual void Apply(const gfx::GradientLevelColorOp& op)=0;
157 virtual void Apply(const gfx::EntityViewColorOp& op)=0;
158 virtual void Apply(const gfx::MapHandleColorOp& op)=0;
159
160 bool IsDirty() const;
161
163
164 void Debug(unsigned int flags);
165
166 IndexedVertexArray& VA() {return va_;}
167protected:
168 virtual void SetName(const String& name);
169
172
177
181
184 unsigned int debug_flags_;
185 float opacity_;
186};
187
188//Simplify color ops
190 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
191 return std::make_pair(true,GfxObj::Ele2Color(atom.GetElement()));
192 }
193};
194
197 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
198 return std::make_pair(true,op_.GetColor(atom.GetResidue().GetChain().GetName()));
199 }
201};
202
204 UniformGetCol(const Color& col):col_(col){ }
205 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
206 return std::make_pair(true,col_);
207 }
208 const Color& col_;
209};
210
213 property_(op.GetProperty()),
214 epm_(property_, op.GetLevel()),
215 gradient_(op.GetGradient()),
216 minv_(op.GetMinV()),
217 maxv_(op.GetMaxV()),
218 clamp_(op.GetClamp())
219 {}
220 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
221 try{
222 float r = epm_.Get(atom, minv_);
223 if(clamp_) {
224 float n=Normalize(r, minv_, maxv_);
225 return std::make_pair(true,gradient_.GetColorAt(n));
226 } else {
227 if(r>=minv_ && r<=maxv_) {
228 float n=Normalize(r, minv_, maxv_);
229 return std::make_pair(true,gradient_.GetColorAt(n));
230 } else {
231 return std::make_pair(false,Color());
232 }
233 }
234 }catch(std::exception&){
235 LOG_DEBUG("property " << property_ << " not found");
236 return std::make_pair(false,Color());
237 }
238 return std::make_pair(false,Color());
239 }
243 float minv_, maxv_;
244 bool clamp_;
245};
246
248 EntityViewGetCol(const EntityViewColorOp& op):property_(op.GetProperty()),
249 ev_(op.GetEntityView()),
250 gradient_(op.GetGradient()),
251 minv_(op.GetMinV()),
252 maxv_(op.GetMaxV()){}
253 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
254 return std::make_pair(true,MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos()));
255 }
259 float minv_, maxv_;
260};
261
263 MapHandleGetCol(const MapHandleColorOp& op):property_(op.GetProperty()),
264 mh_(op.GetMapHandle()),
265 gradient_(op.GetGradient()),
266 minv_(op.GetMinV()),
267 maxv_(op.GetMaxV()){}
268 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
269 return std::make_pair(true,MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos()));
270 }
274 float minv_, maxv_;
275};
276
277}}} //ns
278
279#endif /* ENTITYRENDERER_HH_ */
axis-aligned cuboid
Color GetColor(const String &ident) const
static Color Ele2Color(const String &ele)
color gradient
Definition gradient.hh:59
Color GetColorAt(float t) const
get color
void ClearViews()
reset rendering views to zero
virtual void UpdateViews()=0
update views
virtual void PickBond(const geom::Line3 &line, Real line_width, mol::BondHandle &picked_bond)=0
pick bond
void AddView(const mol::EntityView &view)
add view
mol::EntityView GetFullView()
get view to be rendered by this renderer.
virtual void RenderPov(PovState &pov, const std::string &name)
povray rendering call
virtual void SetName(const String &name)
bool HasSelection() const
whether the renderer has a non-empty selection
void SetEnabled(bool enabled=true)
virtual const String & GetName() const
virtual void Apply(const gfx::UniformColorOp &op)=0
void SubstractView(const mol::EntityView &view)
virtual bool HasDataToRender() const
virtual void Apply(const gfx::ByElementColorOp &op)=0
virtual void RenderOptionsChanged()
virtual RenderOptionsPtr GetOptions()=0
virtual void Apply(const gfx::ByChainColorOp &op)=0
virtual void Apply(const gfx::EntityViewColorOp &op)=0
virtual void SetOptions(RenderOptionsPtr &render_options)=0
void Debug(unsigned int flags)
virtual void Render(RenderPass pass)
render the entity
const Color & GetSelectionColor() const
void SetVisible(const mol::EntityView &view, bool visible)
hide / show part of the rendered data
virtual void Apply(const gfx::GradientLevelColorOp &op)=0
mol::EntityView GetEffectiveView()
virtual void Apply(const gfx::MapHandleColorOp &op)=0
virtual geom::AlignedCuboid GetBoundingBox() const =0
virtual void Export(Exporter *ex)
scene exporter interface
virtual void PrepareRendering()=0
virtual void PickAtom(const geom::Line3 &line, Real line_width, mol::AtomHandle &picked_atom)=0
pick atom
const Color & GetSelectionColorOutline() const
void SetSelection(const mol::EntityView &sel)
virtual bool CanSetOptions(RenderOptionsPtr &render_options)=0
Manage shared instances of images.
const String & GetElement() const
returns the element name of the atom
const geom::Vec3 & GetPos() const
Get global position in cartesian coordinates with entity transformations applied.
Handle to atom datatype.
ResidueHandle GetResidue() const
String GetName() const
Real Get(const AtomHandle &atom) const
get float property throwing an exception when the value does not exist
definition of EntityView
ChainHandle GetChain() const
The chain this residue is attached to.
#define DLLEXPORT_OST_GFX
#define LOG_DEBUG(m)
Definition log.hh:93
float Real
Definition base.hh:44
std::string String
Definition base.hh:54
float DLLEXPORT_OST_GFX MappedProperty(const mol::EntityView &ev, const String &prop, const geom::Vec3 &pos)
unsigned int DirtyFlags
float Normalize(float v, float min_v, float max_v)
boost::shared_ptr< RenderOptions > RenderOptionsPtr
Definition base.dox:1
ByChainGetCol(const ByChainColorOp &op)
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
EntityViewGetCol(const EntityViewColorOp &op)
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
GradientLevelGetCol(const GradientLevelColorOp &op)
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
MapHandleGetCol(const MapHandleColorOp &op)
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const
std::pair< bool, Color > ColorOfAtom(mol::AtomHandle &atom) const