00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_GFX_ENTITY_RENDERER_HH
00020 #define OST_GFX_ENTITY_RENDERER_HH
00021
00022
00023
00024
00025
00026
00027 #if defined(GetProp)
00028 #undef GetProp
00029 #endif
00030 #include <vector>
00031
00032 #include <ost/mol/query_view_wrapper.hh>
00033 #include <ost/mol/entity_view.hh>
00034 #include <ost/mol/atom_handle.hh>
00035 #include <ost/mol/entity_property_mapper.hh>
00036
00037 #include <ost/gfx/color.hh>
00038 #include <ost/gfx/gfx_object.hh>
00039 #include <ost/gfx/module_config.hh>
00040 #include <ost/gfx/render_pass.hh>
00041 #include <ost/gfx/vertex_array.hh>
00042 #include <ost/gfx/render_options/render_options.hh>
00043 #include <ost/gfx/impl/mapped_property.hh>
00044
00045 #include <ost/gfx/color_ops/color_op.hh>
00046 #include <ost/gfx/color_ops/by_element_color_op.hh>
00047 #include <ost/gfx/color_ops/by_chain_color_op.hh>
00048 #include <ost/gfx/color_ops/uniform_color_op.hh>
00049 #include <ost/gfx/color_ops/gradient_level_color_op.hh>
00050 #include <ost/gfx/color_ops/entity_view_color_op.hh>
00051 #if OST_IMG_ENABLED
00052 #include <ost/gfx/color_ops/map_handle_color_op.hh>
00053 #endif //OST_IMG_ENABLED
00054 #include <ost/gfx/impl/entity_renderer_fw.hh>
00055
00056 namespace ost { namespace gfx { namespace impl {
00057
00058 typedef enum {
00059 DIRTY_VIEW =1,
00060 DIRTY_VA =2,
00061 } DirtyFlag;
00062
00063 typedef char DirtyFlags;
00064
00066 class DLLEXPORT_OST_GFX EntityRenderer {
00067 public:
00068 EntityRenderer();
00069 virtual ~EntityRenderer(){}
00070
00072 void AddView(const mol::EntityView& view);
00073
00074 void SubstractView(const mol::EntityView& view);
00076 void ClearViews();
00077
00078 virtual bool HasDataToRender() const;
00079
00080 virtual const String& GetName() const;
00081
00082 void SetEnabled(bool enabled=true);
00083
00084 bool IsEnabled() const;
00085
00087 bool HasSelection() const;
00088
00090 void SetSelection(const mol::EntityView& sel);
00091
00093 void SetVisible(const mol::EntityView& view, bool visible);
00094
00095 const Color& GetSelectionColor() const;
00096
00097 const Color& GetSelectionColorOutline() const;
00098
00104 mol::EntityView GetFullView();
00105
00106 mol::EntityView GetEffectiveView();
00107
00109 virtual void UpdateViews()=0;
00110
00112 virtual void PrepareRendering()=0;
00113
00121 virtual void Render(RenderPass pass=STANDARD_RENDER_PASS);
00122
00124 virtual void RenderPov(PovState& pov, const std::string& name);
00125
00126 virtual bool CanSetOptions(RenderOptionsPtr& render_options)=0;
00127 virtual void SetOptions(RenderOptionsPtr& render_options)=0;
00128
00129 virtual RenderOptionsPtr GetOptions()=0;
00130
00131 virtual geom::AlignedCuboid GetBoundingBox() const=0;
00132
00137 virtual void PickAtom(const geom::Line3& line, Real line_width,
00138 mol::AtomHandle& picked_atom)=0;
00139
00144 virtual void PickBond(const geom::Line3& line, Real line_width,
00145 mol::BondHandle& picked_bond)=0;
00146
00147 virtual void RenderOptionsChanged();
00148
00149 virtual void Apply(const gfx::ByElementColorOp& op)=0;
00150 virtual void Apply(const gfx::ByChainColorOp& op)=0;
00151 virtual void Apply(const gfx::UniformColorOp& op)=0;
00152 virtual void Apply(const gfx::GradientLevelColorOp& op)=0;
00153 virtual void Apply(const gfx::EntityViewColorOp& op)=0;
00154 #if OST_IMG_ENABLED
00155 virtual void Apply(const gfx::MapHandleColorOp& op)=0;
00156 #endif
00157
00158 bool IsDirty() const;
00159
00160 void FlagPositionsDirty();
00161
00162 void Debug(unsigned int flags);
00163 protected:
00164 virtual void SetName(const String& name);
00165
00166 String name_;
00167 bool enabled_;
00168
00169 mol::EntityView full_view_;
00170 mol::EntityView effective_view_;
00171 mol::EntityView hidden_view_;
00172 IndexedVertexArray va_;
00173
00174 mol::EntityView sel_;
00175 mol::EntityView full_sel_;
00176 IndexedVertexArray sel_va_;
00177
00178 DirtyFlags sel_state_;
00179 DirtyFlags state_;
00180 unsigned int debug_flags_;
00181 };
00182
00183
00184 struct ByElementGetCol {
00185 Color ColorOfAtom(mol::AtomHandle& atom) const{
00186 return GfxObj::Ele2Color(atom.GetAtomProps().element);
00187 }
00188 };
00189
00190 struct ByChainGetCol {
00191 ByChainGetCol(const ByChainColorOp& op):op_(op){}
00192 Color ColorOfAtom(mol::AtomHandle& atom) const{
00193 return op_.GetColor(atom.GetResidue().GetChain().GetName());
00194 }
00195 const ByChainColorOp& op_;
00196 };
00197
00198 struct UniformGetCol {
00199 UniformGetCol(const Color& col):col_(col){ }
00200 Color ColorOfAtom(mol::AtomHandle& atom) const{
00201 return col_;
00202 }
00203 const Color& col_;
00204 };
00205
00206 struct GradientLevelGetCol {
00207 GradientLevelGetCol(const GradientLevelColorOp& op):property_(op.GetProperty()),
00208 epm_(property_, op.GetLevel()),
00209 gradient_(op.GetGradient()),
00210 minv_(op.GetMinV()),
00211 maxv_(op.GetMaxV()){}
00212 Color ColorOfAtom(mol::AtomHandle& atom) const{
00213 try{
00214 float n=Normalize(epm_.Get(atom), minv_, maxv_);
00215 return gradient_.GetColorAt(n);
00216 }catch(std::exception&){
00217 LOGN_DEBUG("property " << property_ << " not found");
00218 return Color();
00219 }
00220 }
00221 String property_;
00222 mol::EntityPropertyMapper epm_;
00223 Gradient gradient_;
00224 float minv_, maxv_;
00225 };
00226
00227 struct EntityViewGetCol {
00228 EntityViewGetCol(const EntityViewColorOp& op):property_(op.GetProperty()),
00229 ev_(op.GetEntityView()),
00230 gradient_(op.GetGradient()),
00231 minv_(op.GetMinV()),
00232 maxv_(op.GetMaxV()){}
00233 Color ColorOfAtom(mol::AtomHandle& atom) const{
00234 return MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos());
00235 }
00236 String property_;
00237 mol::EntityView ev_;
00238 Gradient gradient_;
00239 float minv_, maxv_;
00240 };
00241
00242 #if OST_IMG_ENABLED
00243 struct MapHandleGetCol {
00244 MapHandleGetCol(const MapHandleColorOp& op):property_(op.GetProperty()),
00245 mh_(op.GetMapHandle()),
00246 gradient_(op.GetGradient()),
00247 minv_(op.GetMinV()),
00248 maxv_(op.GetMaxV()){}
00249 Color ColorOfAtom(mol::AtomHandle& atom) const{
00250 return MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos());
00251 }
00252 String property_;
00253 img::MapHandle mh_;
00254 Gradient gradient_;
00255 float minv_, maxv_;
00256 };
00257 #endif
00258
00259 }}}
00260
00261 #endif