OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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);
62  virtual void Apply(GfxNodeVisitor& v, GfxNodeVisitor::Stack st);
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();
73  virtual void SetRenderMode(RenderMode::Type m);
74  virtual RenderMode::Type GetRenderMode() const;
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 
207  Material GetMaterial() const;
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:
232  void AppendColorOp(gfx::ColorOp* op);
233  void CleanColorOps();
234  void ReapplyColorOps();
235  void render_labels() const;
236  void render_depth_only();
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
bool GetAALines() const
Definition: gfx_object.hh:200
virtual bool GetSolid() const
Definition: gfx_object.hh:93
virtual bool GetOutline() const
get state of outline rendering
Definition: gfx_object.hh:81
unsigned int poly_mode_
Definition: gfx_object.hh:246
TextPrimList labels_
Definition: gfx_object.hh:268
unsigned int debug_flags_
Definition: gfx_object.hh:240
float GetLineWidth() const
Definition: gfx_object.hh:201
geom::Transform transform_
Definition: gfx_object.hh:242
virtual bool GetClip() const
Definition: gfx_object.hh:98
virtual geom::Vec4 GetClipPlane() const
Definition: gfx_object.hh:100
std::string String
Definition: base.hh:54
axis-aligned cuboid
float GetLineHalo() const
Definition: gfx_object.hh:202
boost::ptr_vector< gfx::ColorOp > c_ops_
Definition: gfx_object.hh:266
virtual Color GetSolidColor() const
Definition: gfx_object.hh:95
main class for all graphic objects
Definition: gfx_object.hh:51
Line3.
Definition: composite3.hh:39
const IndexedVertexArray & GetVA() const
Definition: gfx_object.hh:221
#define DLLEXPORT_OST_GFX
std::stack< GfxNode * > Stack
main interface for all graphic objects, both in C++ and Python
IndexedVertexArray va_
Definition: gfx_object.hh:238
basic and essential transformation class, including translation, rotation and center of rotation ...
Definition: transform.hh:39
RenderMode::Type render_mode_
Definition: gfx_object.hh:239
Three dimensional vector class, using Real precision.
Definition: vec3.hh:43
virtual float GetClipOffset() const
Definition: gfx_object.hh:102
ImageStateConstModIPAlgorithm< ClearFnc > Clear
Definition: clear.hh:47
virtual int GetOutlineMode() const
get current outline mode
Definition: gfx_object.hh:83
std::vector< TextPrim > TextPrimList
Definition: gfx_prim.hh:117
geom::Vec4 clip_plane_
Definition: gfx_object.hh:263
Manage shared instances of images.
definition of EntityView
Definition: entity_view.hh:86
virtual float GetOpacity() const
returns a value smaller than 1.0 if transparency is used in this object
Definition: gfx_object.hh:91
boost::shared_ptr< GfxNode > GfxNodeP
Definition: gfx_node_fw.hh:31
IndexedVertexArray & GetVA()
Definition: gfx_object.hh:220
color gradient
Definition: gradient.hh:59
unsigned int mat_dlist_
Definition: gfx_object.hh:251