OpenStructure
gfx_object.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_OBJ_HH
20 #define OST_GFX_OBJ_HH
21 
22 /*
23  Author: Ansgar Philippsen
24 */
25 // I have really no clue who defines this macro, but apparently its there.
26 #ifdef check
27 #undef check
28 #endif
29 #ifndef Q_MOC_RUN
30 #include <boost/ptr_container/ptr_vector.hpp>
31 
32 #include <vector>
33 
34 #include <ost/config.hh>
35 #include <ost/gfx/module_config.hh>
36 
37 #include <ost/geom/transform.hh>
38 
39 #include "gfx_object_fw.hh"
40 #include "gfx_object_base.hh"
41 #include "gfx_prim.hh"
42 #include "vertex_array.hh"
43 #include "input.hh"
44 #include "exporter_fw.hh"
45 #endif
46 namespace ost { namespace gfx {
47 
48 class Scene; // fw decl
49 
52 {
53 public:
54  GfxObj(const String& name);
55 
56  // gfx node interface
57  virtual GfxNodeP Copy() const;
58  virtual void DeepSwap(GfxObj& go);
59  virtual void RenderGL(RenderPass pass);
60  virtual void RenderPov(PovState& pov);
61  virtual void Export(Exporter* ex);
63  virtual int GetType() const;
64  //
65 
66  // gfx obj base interface
67  virtual void SetMatAmb(const Color& c);
68  virtual void SetMatDiff(const Color& c);
69  virtual void SetMatSpec(const Color& c);
70  virtual void SetMatShin(float s);
71  virtual void SetMatEmm(const Color& c);
72  virtual void ContextSwitch();
75  virtual geom::Vec3 GetCenter() const;
76  virtual void SetLineWidth(float w);
77  virtual void SetPolyMode(unsigned int m);
78  virtual void SetAALines(bool f);
79  virtual void SetLineHalo(float f);
80  virtual void SetOutline(bool f);
81  virtual bool GetOutline() const {return outline_flag_;};
82  virtual void SetOutlineMode(int m);
83  virtual int GetOutlineMode() const {return outline_mode_;}
84  virtual void SetOutlineWidth(float f);
85  virtual float GetOutlineWidth() const;
86  virtual void SetOutlineExpandFactor(float f);
87  virtual float GetOutlineExpandFactor() const;
88  virtual void SetOutlineExpandColor(const Color& c);
89  virtual Color GetOutlineExpandColor() const;
90  virtual void SetOpacity(float f);
91  virtual float GetOpacity() const {return opacity_;}
92  virtual void SetSolid(bool f);
93  virtual bool GetSolid() const {return solid_;}
94  virtual void SetSolidColor(const Color& c);
95  virtual Color GetSolidColor() const {return solid_color_;}
96 
97  virtual void SetClip(bool f);
98  virtual bool GetClip() const {return clip_flag_;}
99  virtual void SetClipPlane(const geom::Vec4&);
100  virtual geom::Vec4 GetClipPlane() const {return clip_plane_;}
101  virtual void SetClipOffset(float f);
102  virtual float GetClipOffset() const {return clip_offset_;}
103 
104  virtual void ColorBy(const mol::EntityView& ev,
105  const String& prop,
106  const Gradient& g, float minv, float maxv);
107  virtual void ColorBy(const img::MapHandle& mh,
108  const String& prop,
109  const Gradient& g,float minv, float maxv);
110 
111  // end of gfx obj base interface
112 
113  // new gfx obj virtual interface starts here
114 
124  virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
125 
136  virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
137  const geom::Transform& tf) const;
138 
139  // implemented in derived classes for the actual GL rendering
140  /*
141  note: only STANDARD_RENDER_PASS and GLOW_RENDER_PASS need to
142  be implemented, the rest is taken care of by GfxObj::RenderGL
143  */
144  virtual void CustomRenderGL(RenderPass pass);
145 
146  // implemented in derived classes to deal with initialization etc
147  // called just before CustomRenderGL is called
148  // the boolean flag indicated that a re-build was requested
149  virtual void CustomPreRenderGL(bool rebuild);
150 
151  // implemented in derived classes for first GL initialization
152  // which should be done here, not in the ctor
153  virtual void InitGL();
154 
155  // implemented in derived classes for the actual POVray export
156  virtual void CustomRenderPov(PovState& pov);
157 
158  // handle pick (select) event
159  /*
160  should return the position of the picked object in order for the caller
161  to determine the closest one, and indicate with the boolean return wether
162  the selection was successful
163  the boolean flag indicates whether a true pick or just a feedback is requested
164  the given zlim is the projected z of the best selection so far, and should be
165  used for both picking as well as feedback if the selection is in front of the
166  currently best one
167  */
168  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim, bool pick_flag);
169 
170  // input event entry point
171  virtual void OnInput(const InputEvent& e);
172 
173  // informs derived class that render mode has changes
174  virtual void OnRenderModeChange();
175  virtual void OnGLCleanup();
176  //
177 
179  void Clear();
180 
182  const geom::Transform& GetTF() const;
184  void SetTF(const geom::Transform& tf);
185 
186  // add a label at the given position
187  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col, float psize);
188  // convenience method
189  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col);
190  // convenience method
191  void AddLabel(const String& s, const geom::Vec3& pos, float psize);
192  // convenience method
193  void AddLabel(const String& s, const geom::Vec3& pos);
194  // remove all labels
195  void ClearLabels();
196 
197  void FlagRebuild();
198  void FlagRefresh();
199 
200  bool GetAALines() const {return aalines_flag_;}
201  float GetLineWidth() const {return line_width_;}
202  float GetLineHalo() const {return line_halo_;}
203 
204  void SetNormalSmoothFactor(float smoothf);
205  float GetNormalSmoothFactor() const;
206 
208  void SetMaterial(const Material& m);
209 
210  // experimental, don't use
211  void SmoothVertices(float smoothf);
212 
213  void GLCleanup();
214 
215  // this really should not be here
216  static Color Ele2Color(const String& ele);
217 
218  void Debug(unsigned int flags);
219 
220  IndexedVertexArray& GetVA() {return va_;}
221  const IndexedVertexArray& GetVA() const {return va_;}
222 
223  protected:
224 
225  void PreRenderGL(bool flag);
226 
227  private:
228  GfxObj(const GfxObj& o);
229  GfxObj& operator=(const GfxObj&);
230 
231  protected:
235  void render_labels() const;
237 
240  unsigned int debug_flags_;
241 
243  bool rebuild_;
244  bool refresh_;
245  float line_width_;
246  unsigned int poly_mode_;
248  float line_halo_;
249 
251  unsigned int mat_dlist_;
253 
254  float opacity_;
255  float smoothf_;
258 
259  bool solid_;
261 
265 
266  boost::ptr_vector<gfx::ColorOp> c_ops_;
267 
269 
271 };
272 
273 }} //ns
274 
275 #endif
axis-aligned cuboid
Line3.
Definition: composite3.hh:39
basic and essential transformation class, including translation, rotation and center of rotation
Definition: transform.hh:39
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
std::stack< GfxNode * > Stack
main interface for all graphic objects, both in C++ and Python
main class for all graphic objects
Definition: gfx_object.hh:52
virtual void SetClip(bool f)
virtual void SetClipOffset(float f)
unsigned int poly_mode_
Definition: gfx_object.hh:246
virtual void SetOutline(bool f)
turn outline rendering on or off
virtual void CustomRenderPov(PovState &pov)
virtual void OnGLCleanup()
static Color Ele2Color(const String &ele)
virtual geom::Vec4 GetClipPlane() const
Definition: gfx_object.hh:100
virtual void ContextSwitch()
rendering context switch, some things need to be regenerated
RenderMode::Type render_mode_
Definition: gfx_object.hh:239
void ReapplyColorOps()
virtual void OnRenderModeChange()
void AddLabel(const String &s, const geom::Vec3 &pos, const Color &col, float psize)
virtual int GetType() const
virtual void SetMatSpec(const Color &c)
material specular color
virtual Color GetSolidColor() const
Definition: gfx_object.hh:95
virtual void ColorBy(const mol::EntityView &ev, const String &prop, const Gradient &g, float minv, float maxv)
color each component based on the gradient-mapped property of the given entity
virtual bool GetOutline() const
get state of outline rendering
Definition: gfx_object.hh:81
virtual void ProcessLimits(geom::Vec3 &minc, geom::Vec3 &maxc, const geom::Transform &tf) const
adjust minimum and maximum extent based on graphical object
virtual void SetMatAmb(const Color &c)
material ambient color
virtual void SetRenderMode(RenderMode::Type m)
change render mode
virtual void SetSolid(bool f)
void AppendColorOp(gfx::ColorOp *op)
virtual void SetMatEmm(const Color &c)
material emmissive color
virtual void SetOutlineExpandFactor(float f)
set outline expansion factor (mode 3) this scales with resolution
TextPrimList labels_
Definition: gfx_object.hh:268
void PreRenderGL(bool flag)
void render_labels() const
virtual Color GetOutlineExpandColor() const
get current outline color (mode 3)
virtual float GetClipOffset() const
Definition: gfx_object.hh:102
virtual float GetOpacity() const
returns a value smaller than 1.0 if transparency is used in this object
Definition: gfx_object.hh:91
float GetLineWidth() const
Definition: gfx_object.hh:201
virtual void OnInput(const InputEvent &e)
boost::ptr_vector< gfx::ColorOp > c_ops_
Definition: gfx_object.hh:266
virtual int GetOutlineMode() const
get current outline mode
Definition: gfx_object.hh:83
unsigned int debug_flags_
Definition: gfx_object.hh:240
void SetNormalSmoothFactor(float smoothf)
virtual void SetOpacity(float f)
set opacity (1 = no transparency)
float GetLineHalo() const
Definition: gfx_object.hh:202
virtual float GetOutlineWidth() const
get current outline width
Material GetMaterial() const
virtual bool GetSolid() const
Definition: gfx_object.hh:93
virtual float GetOutlineExpandFactor() const
get current outline expand factor (mode 3)
void AddLabel(const String &s, const geom::Vec3 &pos, const Color &col)
virtual void SetPolyMode(unsigned int m)
set polygon mode
void SmoothVertices(float smoothf)
bool GetAALines() const
Definition: gfx_object.hh:200
virtual void ColorBy(const img::MapHandle &mh, const String &prop, const Gradient &g, float minv, float maxv)
color based on image
void render_depth_only()
virtual void SetMatDiff(const Color &c)
material diffuse color
virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const
returns the bounding box of this object
IndexedVertexArray va_
Definition: gfx_object.hh:238
geom::Vec4 clip_plane_
Definition: gfx_object.hh:263
void SetMaterial(const Material &m)
unsigned int mat_dlist_
Definition: gfx_object.hh:251
virtual void CustomPreRenderGL(bool rebuild)
virtual void SetAALines(bool f)
turn on sophisticated line anti-aliasing, requires shader
void Clear()
removes all graphical elements
virtual void SetClipPlane(const geom::Vec4 &)
virtual void SetLineHalo(float f)
turn on line halo of given strength
virtual geom::Vec3 GetCenter() const
get geometric center
virtual void CustomRenderGL(RenderPass pass)
void AddLabel(const String &s, const geom::Vec3 &pos, float psize)
GfxObj(const String &name)
float GetNormalSmoothFactor() const
virtual void SetSolidColor(const Color &c)
void AddLabel(const String &s, const geom::Vec3 &pos)
void Debug(unsigned int flags)
virtual bool OnSelect(const geom::Line3 &l, geom::Vec3 &result, float zlim, bool pick_flag)
virtual void RenderGL(RenderPass pass)
void SetTF(const geom::Transform &tf)
set transform
const geom::Transform & GetTF() const
get transform
virtual void RenderPov(PovState &pov)
const IndexedVertexArray & GetVA() const
Definition: gfx_object.hh:221
virtual void SetOutlineExpandColor(const Color &c)
set outline color (mode 3)
virtual bool GetClip() const
Definition: gfx_object.hh:98
virtual void SetMatShin(float s)
material shininess
virtual void SetOutlineMode(int m)
set outline mode, 1, 2 or 3
virtual RenderMode::Type GetRenderMode() const
current render mode
virtual void Export(Exporter *ex)
virtual void Apply(GfxNodeVisitor &v, GfxNodeVisitor::Stack st)
geom::Transform transform_
Definition: gfx_object.hh:242
virtual void SetOutlineWidth(float f)
set outline width in pixels (modes 1 + 2) this does not scale with resolution
virtual void DeepSwap(GfxObj &go)
virtual GfxNodeP Copy() const
virtual void InitGL()
virtual void SetLineWidth(float w)
set line width
IndexedVertexArray & GetVA()
Definition: gfx_object.hh:220
color gradient
Definition: gradient.hh:59
Manage shared instances of images.
definition of EntityView
Definition: entity_view.hh:86
#define DLLEXPORT_OST_GFX
std::string String
Definition: base.hh:54
std::vector< TextPrim > TextPrimList
Definition: gfx_prim.hh:117
boost::shared_ptr< GfxNode > GfxNodeP
Definition: gfx_node_fw.hh:31
Definition: base.dox:1