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
00076 Entity(const String& name,
00077 RenderMode::Type m,
00078 const mol::EntityHandle& eh,
00079 const mol::Query& q=mol::Query());
00080
00083 Entity(const String& name,
00084 const mol::EntityView& ev);
00085
00087 Entity(const String& name,
00088 RenderMode::Type m,
00089 const mol::EntityView& ev);
00090
00091 virtual geom::AlignedCuboid GetBoundingBox() const;
00092
00093 virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
00094 const mol::Transform& tf) const;
00095
00097 virtual void CustomRenderGL(RenderPass pass);
00098
00099 virtual void RefreshVA();
00100
00101 virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim,
00102 bool pick_flag);
00103
00110 mol::AtomHandle PickAtom(const geom::Line3& line, Real line_width=0.5);
00111
00112
00119 mol::BondHandle PickBond(const geom::Line3& line, Real line_width=0.5);
00120
00121
00122 virtual void OnRenderModeChange();
00123
00124 const String GetRenderModeName(RenderMode::Type mode);
00125
00126 void SetEnableRenderMode(RenderMode::Type mode, bool enable);
00127
00128 bool IsRenderModeEnabled(RenderMode::Type mode);
00129
00130 RenderModeTypes GetNotEmptyRenderModes();
00131
00132 void SetRenderMode(RenderMode::Type mode, const mol::EntityView& view,
00133 bool keep=false);
00134
00135 virtual void SetRenderMode(RenderMode::Type mode);
00136
00137 mol::EntityView GetRenderView(RenderMode::Type mode);
00138
00139 virtual void SetVisible(const mol::EntityView& view, bool visible);
00140
00141 virtual void OptionsChanged(RenderMode::Type mode);
00142
00144 void Rebuild();
00145
00147 void UpdatePositions();
00148
00150 void SetColor(const Color& col, const String& selection=String(""));
00151
00152
00153 void SetDetailColor(const Color& col, const String& selection=String(""));
00154
00156 void SetColorForAtom(const Color& col,
00157 const mol::AtomHandle& atom);
00158
00160 void ColorByElement();
00161
00163 void ColorByChain();
00164
00166 mol::EntityView GetView() const;
00167
00168
00169
00170 void SetBlur(bool f);
00171
00172 void BlurSnapshot();
00173
00174 void SetBlurFactors(float bf1,float bf2);
00175
00178 void SetSelection(const mol::EntityView& view);
00179
00182 mol::EntityView GetSelection() const;
00183
00184
00185 virtual void ColorBy(const mol::EntityView& ev,
00186 const String& prop,
00187 const Gradient& g, float minv, float maxv);
00188
00189 #if OST_IMG_ENABLED
00190
00191 virtual void ColorBy(const img::MapHandle& mh,
00192 const String& prop,
00193 const Gradient& g,float minv, float maxv);
00194 #endif
00195
00196
00197 void ColorBy(const String& prop,
00198 const Gradient& gradient,
00199 float minv,float maxv,
00200 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00201
00202
00203 void ColorBy(const String& prop,
00204 const Gradient& gradient,
00205 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00206
00207
00208 void ColorBy(const String& prop,
00209 const Color& c1, const Color& c2,
00210 float min, float max,
00211 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00212
00213
00214 void ColorBy(const String& prop,
00215 const Color& c1, const Color& c2,
00216 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00217
00218
00219 void RadiusBy(const String& prop,
00220 float rmin, float rmax,
00221 float vmin, float vmax,
00222 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00223
00224 void RadiusBy(const String& prop,
00225 float rmin, float rmax,
00226 mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
00227
00228 void ResetRadiusBy();
00229
00230 void Apply(const gfx::ByElementColorOp& op, bool store=true);
00231 void Apply(const gfx::ByChainColorOp& op, bool store=true);
00232 void Apply(const gfx::UniformColorOp& op, bool store=true);
00233
00234 void Apply(const gfx::GradientLevelColorOp& op, bool store=true);
00235 void Apply(const gfx::EntityViewColorOp& op, bool store=true);
00236
00237 #if OST_IMG_ENABLED
00238 void Apply(const gfx::MapHandleColorOp& op, bool store=true);
00239 #endif
00240
00241 void CleanColorOps();
00242 void ReapplyColorOps();
00243
00254 RenderOptionsPtr GetOptions(RenderMode::Type render_mode);
00255 void SetOptions(RenderMode::Type render_mode,
00256 RenderOptionsPtr& render_options);
00257 void ApplyOptions(RenderMode::Type render_mode,
00258 RenderOptionsPtr& render_options);
00259 bool HasSelection() const;
00260 protected:
00261
00262 virtual void CustomPreRenderGL(bool flag);
00263 virtual void CustomRenderPov(PovState& pov);
00264 void UpdateSelection();
00265 bool UpdateIfNeeded() const;
00266 void CacheBoundingBox() const;
00267 impl::EntityRenderer* GetOrCreateRenderer(RenderMode::Type);
00268 private:
00269 mol::QueryViewWrapper qv_;
00270
00271 mutable mol::EntityView cached_view_;
00272 mutable bool update_view_;
00273
00274 mutable geom::AlignedCuboid bbox_;
00275 mol::EntityView sel_;
00276 bool sel_update_;
00277 impl::BackboneTrace trace_;
00278
00279 void init(RenderMode::Type);
00280
00281 void set_static_max_rad();
00282
00283 typedef boost::ptr_map<RenderMode::Type, impl::EntityRenderer> RendererMap;
00284 mutable RendererMap renderer_;
00285 };
00286
00287
00293
00299
00309
00310
00315 }}
00316
00317 #endif