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(GetAtomProps)
00028 #undef GetAtomProps
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/exporter_fw.hh>
00043
00044 #include <ost/gfx/render_options/render_options.hh>
00045
00046 #include <ost/gfx/color_ops/color_op.hh>
00047 #include <ost/gfx/color_ops/by_element_color_op.hh>
00048 #include <ost/gfx/color_ops/by_chain_color_op.hh>
00049 #include <ost/gfx/color_ops/uniform_color_op.hh>
00050 #include <ost/gfx/color_ops/gradient_level_color_op.hh>
00051 #include <ost/gfx/color_ops/entity_view_color_op.hh>
00052 #if OST_IMG_ENABLED
00053 #include <ost/gfx/color_ops/map_handle_color_op.hh>
00054 #endif //OST_IMG_ENABLED
00055
00056 #include "mapped_property.hh"
00057 #include "entity_renderer_fw.hh"
00058
00059 namespace ost { namespace gfx { namespace impl {
00060
00061 typedef enum {
00062 DIRTY_VIEW = 0x1,
00063 DIRTY_VA = 0x2
00064 } DirtyFlag;
00065
00066 typedef unsigned int DirtyFlags;
00067
00069 class DLLEXPORT_OST_GFX EntityRenderer {
00070 public:
00071 EntityRenderer();
00072 virtual ~EntityRenderer(){}
00073
00075 void AddView(const mol::EntityView& view);
00076
00077 void SubstractView(const mol::EntityView& view);
00079 void ClearViews();
00080
00081 virtual bool HasDataToRender() const;
00082
00083 virtual const String& GetName() const;
00084
00085 void SetEnabled(bool enabled=true);
00086
00087 bool IsEnabled() const;
00088
00090 bool HasSelection() const;
00091
00093 void SetSelection(const mol::EntityView& sel);
00094
00096 void SetVisible(const mol::EntityView& view, bool visible);
00097
00098 const Color& GetSelectionColor() const;
00099
00100 const Color& GetSelectionColorOutline() const;
00101
00107 mol::EntityView GetFullView();
00108
00109 mol::EntityView GetEffectiveView();
00110
00112 virtual void UpdateViews()=0;
00113
00115 virtual void PrepareRendering()=0;
00116
00124 virtual void Render(RenderPass pass);
00125
00127 virtual void RenderPov(PovState& pov, const std::string& name);
00128
00130 virtual void Export(Exporter* ex);
00131
00132 virtual bool CanSetOptions(RenderOptionsPtr& render_options)=0;
00133 virtual void SetOptions(RenderOptionsPtr& render_options)=0;
00134
00135 virtual RenderOptionsPtr GetOptions()=0;
00136
00137 virtual geom::AlignedCuboid GetBoundingBox() const=0;
00138
00143 virtual void PickAtom(const geom::Line3& line, Real line_width,
00144 mol::AtomHandle& picked_atom)=0;
00145
00150 virtual void PickBond(const geom::Line3& line, Real line_width,
00151 mol::BondHandle& picked_bond)=0;
00152
00153 virtual void RenderOptionsChanged();
00154
00155 virtual void Apply(const gfx::ByElementColorOp& op)=0;
00156 virtual void Apply(const gfx::ByChainColorOp& op)=0;
00157 virtual void Apply(const gfx::UniformColorOp& op)=0;
00158 virtual void Apply(const gfx::GradientLevelColorOp& op)=0;
00159 virtual void Apply(const gfx::EntityViewColorOp& op)=0;
00160 #if OST_IMG_ENABLED
00161 virtual void Apply(const gfx::MapHandleColorOp& op)=0;
00162 #endif
00163
00164 bool IsDirty() const;
00165
00166 void FlagPositionsDirty();
00167
00168 void Debug(unsigned int flags);
00169
00170 IndexedVertexArray& VA() {return va_;}
00171 protected:
00172 virtual void SetName(const String& name);
00173
00174 String name_;
00175 bool enabled_;
00176
00177 mol::EntityView full_view_;
00178 mol::EntityView effective_view_;
00179 mol::EntityView hidden_view_;
00180 IndexedVertexArray va_;
00181
00182 mol::EntityView sel_;
00183 mol::EntityView full_sel_;
00184 IndexedVertexArray sel_va_;
00185
00186 DirtyFlags sel_state_;
00187 DirtyFlags state_;
00188 unsigned int debug_flags_;
00189 float opacity_;
00190 };
00191
00192
00193 struct ByElementGetCol {
00194 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00195 return std::make_pair(true,GfxObj::Ele2Color(atom.GetElement()));
00196 }
00197 };
00198
00199 struct ByChainGetCol {
00200 ByChainGetCol(const ByChainColorOp& op):op_(op){}
00201 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00202 return std::make_pair(true,op_.GetColor(atom.GetResidue().GetChain().GetName()));
00203 }
00204 const ByChainColorOp& op_;
00205 };
00206
00207 struct UniformGetCol {
00208 UniformGetCol(const Color& col):col_(col){ }
00209 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00210 return std::make_pair(true,col_);
00211 }
00212 const Color& col_;
00213 };
00214
00215 struct GradientLevelGetCol {
00216 GradientLevelGetCol(const GradientLevelColorOp& op):
00217 property_(op.GetProperty()),
00218 epm_(property_, op.GetLevel()),
00219 gradient_(op.GetGradient()),
00220 minv_(op.GetMinV()),
00221 maxv_(op.GetMaxV()),
00222 clamp_(op.GetClamp())
00223 {}
00224 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00225 try{
00226 float r = epm_.Get(atom, minv_);
00227 if(clamp_) {
00228 float n=Normalize(r, minv_, maxv_);
00229 return std::make_pair(true,gradient_.GetColorAt(n));
00230 } else {
00231 if(r>=minv_ && r<=maxv_) {
00232 float n=Normalize(r, minv_, maxv_);
00233 return std::make_pair(true,gradient_.GetColorAt(n));
00234 } else {
00235 return std::make_pair(false,Color());
00236 }
00237 }
00238 }catch(std::exception&){
00239 LOG_DEBUG("property " << property_ << " not found");
00240 return std::make_pair(false,Color());
00241 }
00242 return std::make_pair(false,Color());
00243 }
00244 String property_;
00245 mol::EntityPropertyMapper epm_;
00246 Gradient gradient_;
00247 float minv_, maxv_;
00248 bool clamp_;
00249 };
00250
00251 struct EntityViewGetCol {
00252 EntityViewGetCol(const EntityViewColorOp& op):property_(op.GetProperty()),
00253 ev_(op.GetEntityView()),
00254 gradient_(op.GetGradient()),
00255 minv_(op.GetMinV()),
00256 maxv_(op.GetMaxV()){}
00257 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00258 return std::make_pair(true,MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos()));
00259 }
00260 String property_;
00261 mol::EntityView ev_;
00262 Gradient gradient_;
00263 float minv_, maxv_;
00264 };
00265
00266 #if OST_IMG_ENABLED
00267 struct MapHandleGetCol {
00268 MapHandleGetCol(const MapHandleColorOp& op):property_(op.GetProperty()),
00269 mh_(op.GetMapHandle()),
00270 gradient_(op.GetGradient()),
00271 minv_(op.GetMinV()),
00272 maxv_(op.GetMaxV()){}
00273 std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
00274 return std::make_pair(true,MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos()));
00275 }
00276 String property_;
00277 img::MapHandle mh_;
00278 Gradient gradient_;
00279 float minv_, maxv_;
00280 };
00281 #endif
00282
00283 }}}
00284
00285 #endif