00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_GFX_ENTITY_HH
00020 #define OST_GFX_ENTITY_HH
00021
00022
00023
00024
00025 #include <vector>
00026
00027 #include <boost/ptr_container/ptr_map.hpp>
00028
00029 #include <ost/geom/geom.hh>
00030
00031 #include <ost/mol/query_view_wrapper.hh>
00032 #include <ost/gfx/render_options/render_options.hh>
00033 #include <ost/gfx/color_ops/color_op.hh>
00034 #include <ost/gfx/color_ops/by_element_color_op.hh>
00035 #include <ost/gfx/color_ops/by_chain_color_op.hh>
00036 #include <ost/gfx/color_ops/uniform_color_op.hh>
00037 #include <ost/gfx/color_ops/gradient_level_color_op.hh>
00038 #include <ost/gfx/color_ops/entity_view_color_op.hh>
00039
00040 #if OST_IMG_ENABLED
00041 #include <ost/gfx/color_ops/map_handle_color_op.hh>
00042 #endif //OST_IMG_ENABLED
00043
00044 #include <ost/gfx/impl/entity_renderer.hh>
00045
00046 #include "gradient.hh"
00047 #include "entity_fw.hh"
00048 #include "impl/backbone_trace.hh"
00049 #include "impl/entity_detail.hh"
00050
00051 namespace ost { namespace gfx {
00052
00053 typedef std::vector<RenderMode::Type> RenderModeTypes;
00054
00063 class DLLEXPORT_OST_GFX Entity: public GfxObj {
00064
00065 public:
00071 Entity(const String& name,
00072 const mol::EntityHandle& eh,
00073 const mol::Query& q=mol::Query(),
00074 mol::QueryFlags f=0);
00075
00077 Entity(const String& name,
00078 RenderMode::Type m,
00079 const mol::EntityHandle& eh,
00080 const mol::Query& q=mol::Query(),
00081 mol::QueryFlags f=0);
00082
00085 Entity(const String& name,
00086 const mol::EntityView& ev);
00087
00089 Entity(const String& name,
00090 RenderMode::Type m,
00091 const mol::EntityView& ev);
00092 virtual ~Entity();
00093
00094 virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
00095
00096
00097
00099 virtual void CustomRenderGL(RenderPass pass);
00100
00101 virtual void RefreshVA();
00102
00103 virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim,
00104 bool pick_flag);
00105
00112 mol::AtomHandle PickAtom(const geom::Line3& line, Real line_width=0.5);
00113
00114
00121 mol::BondHandle PickBond(const geom::Line3& line, Real line_width=0.5);
00122
00123
00124 virtual void OnRenderModeChange();
00125
00126 const String GetRenderModeName(RenderMode::Type mode);
00127
00128 void SetEnableRenderMode(RenderMode::Type mode, bool enable);
00129
00130 bool IsRenderModeEnabled(RenderMode::Type mode);
00131
00132 RenderModeTypes GetNotEmptyRenderModes();
00133
00134 void SetRenderMode(RenderMode::Type mode, const mol::EntityView& view,
00135 bool keep=false);
00136 void SetRenderMode(RenderMode::Type mode, const String& selection,
00137 bool keep=false);
00138 virtual void SetRenderMode(RenderMode::Type mode);
00139
00140 mol::EntityView GetRenderView(RenderMode::Type mode);
00141
00142 virtual void SetVisible(const mol::EntityView& view, bool visible);
00143
00144 virtual void SetVisible(const String& sel, bool visible);
00145 virtual void OptionsChanged(RenderMode::Type mode);
00146
00147 virtual void SetOpacity(float f);
00148 virtual float GetOpacity() const {return opacity_;}
00149 virtual void SetOutlineWidth(float f);
00150 virtual void SetOutlineExpandFactor(float f);
00151 virtual void SetOutlineExpandColor(const Color& c);
00152 virtual void SetClipOffset(float f);
00153
00156 void Reset(const mol::EntityHandle& eh);
00159 void Reset(const mol::EntityHandle& eh, const mol::Query& q);
00162 void Reset(const mol::EntityHandle& eh, const mol::Query& q, mol::QueryFlags flags);
00165 void Reset(const mol::EntityView& ev);
00167
00168
00169
00170 void Rebuild();
00171
00174 void UpdatePositions();
00175
00177 void UpdateView();
00178
00180 void SetColor(const Color& col, const String& selection=String(""));
00181
00182
00183 void SetDetailColor(const Color& col, const String& selection=String(""));
00184
00186 void SetColorForAtom(const Color& col,
00187 const mol::AtomHandle& atom);
00188
00190 void ColorByElement();
00191
00193 void ColorByElement(const String& selection);
00194
00196 void ColorByChain();
00197
00199 void ColorByChain(const String& selection);
00200
00202 mol::EntityView GetView() const;
00203
00206 void SetQuery(const mol::Query& q);
00207
00209 mol::QueryViewWrapper GetQueryView() const;
00211 void SetQueryView(const mol::QueryViewWrapper& qv);
00212
00214 mol::EntityHandle GetEntity() const;
00215
00216
00217 void SetBlur(bool f);
00218
00219 void BlurSnapshot();
00220
00221 void SetBlurFactors(float bf1,float bf2);
00222
00225 void SetSelection(const mol::EntityView& view);
00226
00229 mol::EntityView GetSelection() const;
00230
00231
00232 virtual void ColorBy(const mol::EntityView& ev,
00233 const String& prop,
00234 const Gradient& g, float minv, float maxv);
00235
00236 #if OST_IMG_ENABLED
00237
00238 virtual void ColorBy(const img::MapHandle& mh,
00239 const String& prop,
00240 const Gradient& g,float minv, float maxv);
00241 #endif
00242
00243
00244 void ColorBy(const String& prop,
00245 const Gradient& gradient,
00246 float minv,float maxv,
00247 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00248
00249
00250 void ColorBy(const String& prop,
00251 const Gradient& gradient,
00252 float minv,float maxv,
00253 bool clamp);
00254
00255
00256 void DetailColorBy(const String& prop,
00257 const Gradient& gradient,
00258 float minv,float maxv,
00259 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00260
00261
00262 void ColorBy(const String& prop,
00263 const Gradient& gradient,
00264 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00265
00266
00267 void ColorBy(const String& prop,
00268 const Gradient& gradient,
00269 const String& selection);
00270
00271
00272 void ColorBy(const String& prop,
00273 const Color& c1, const Color& c2,
00274 float min, float max,
00275 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00276
00277
00278 void ColorBy(const String& prop,
00279 const Color& c1, const Color& c2,
00280 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00281
00282
00283 void RadiusBy(const String& prop,
00284 float rmin, float rmax,
00285 float vmin, float vmax,
00286 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00287
00288 void RadiusBy(const String& prop,
00289 float rmin, float rmax,
00290 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00291
00292 void ResetRadiusBy();
00293
00294 void Apply(const gfx::ByElementColorOp& op, bool store=true);
00295 void Apply(const gfx::ByChainColorOp& op, bool store=true);
00296 void Apply(const gfx::UniformColorOp& op, bool store=true);
00297
00298 void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
00299 void Apply(const gfx::EntityViewColorOp& op, bool store=true);
00300
00301 #if OST_IMG_ENABLED
00302 void Apply(const gfx::MapHandleColorOp& op, bool store=true);
00303 #endif
00304
00305 void CleanColorOps();
00306 void ReapplyColorOps();
00307
00318 RenderOptionsPtr GetOptions(RenderMode::Type render_mode);
00319 void SetOptions(RenderMode::Type render_mode,
00320 RenderOptionsPtr& render_options);
00321 void ApplyOptions(RenderMode::Type render_mode,
00322 RenderOptionsPtr& render_options);
00323 bool HasSelection() const;
00324
00325 void SetSeqHack(bool b);
00326 bool GetSeqHack() const;
00327
00328 virtual void Export(Exporter* ex);
00329
00330 protected:
00331
00332 virtual void CustomPreRenderGL(bool flag);
00333 virtual void CustomRenderPov(PovState& pov);
00334 void UpdateSelection();
00335 bool UpdateIfNeeded() const;
00336 void CacheBoundingBox() const;
00337 impl::EntityRenderer* GetOrCreateRenderer(RenderMode::Type);
00338 private:
00339 mol::QueryViewWrapper qv_;
00340
00341 mutable mol::EntityView cached_view_;
00342 mutable bool update_view_;
00343
00344 mutable geom::AlignedCuboid bbox_;
00345 mol::EntityView sel_;
00346 bool sel_update_;
00347 mutable impl::BackboneTrace trace_;
00348
00349 void init(RenderMode::Type);
00350
00351 void set_static_max_rad();
00352 void do_update_view() const;
00353
00354 typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap;
00355 mutable RendererMap renderer_;
00356
00357 float opacity_;
00358 bool blur_;
00359 float blurf1_;
00360 float blurf2_;
00361 mutable bool needs_update_;
00362 };
00363
00364
00370
00376
00386
00387
00392 }}
00393
00394 #endif