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-2011 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 #if OST_IMG_ENABLED
108  virtual void ColorBy(const img::MapHandle& mh,
109  const String& prop,
110  const Gradient& g,float minv, float maxv);
111 #endif
112 
113  // end of gfx obj base interface
114 
115  // new gfx obj virtual interface starts here
116 
126  virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
127 
138  virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
139  const geom::Transform& tf) const;
140 
141  // implemented in derived classes for the actual GL rendering
142  /*
143  note: only STANDARD_RENDER_PASS and GLOW_RENDER_PASS need to
144  be implemented, the rest is taken care of by GfxObj::RenderGL
145  */
146  virtual void CustomRenderGL(RenderPass pass);
147 
148  // implemented in derived classes to deal with initialization etc
149  // called just before CustomRenderGL is called
150  // the boolean flag indicated that a re-build was requested
151  virtual void CustomPreRenderGL(bool rebuild);
152 
153  // implemented in derived classes for first GL initialization
154  // which should be done here, not in the ctor
155  virtual void InitGL();
156 
157  // implemented in derived classes for the actual POVray export
158  virtual void CustomRenderPov(PovState& pov);
159 
160  // handle pick (select) event
161  /*
162  should return the position of the picked object in order for the caller
163  to determine the closest one, and indicate with the boolean return wether
164  the selection was successful
165  the boolean flag indicates whether a true pick or just a feedback is requested
166  the given zlim is the projected z of the best selection so far, and should be
167  used for both picking as well as feedback if the selection is in front of the
168  currently best one
169  */
170  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim, bool pick_flag);
171 
172  // input event entry point
173  virtual void OnInput(const InputEvent& e);
174 
175  // informs derived class that render mode has changes
176  virtual void OnRenderModeChange();
177  virtual void OnGLCleanup();
178  //
179 
181  void Clear();
182 
184  const geom::Transform& GetTF() const;
186  void SetTF(const geom::Transform& tf);
187 
188  // add a label at the given position
189  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col, float psize);
190  // convenience method
191  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col);
192  // convenience method
193  void AddLabel(const String& s, const geom::Vec3& pos, float psize);
194  // convenience method
195  void AddLabel(const String& s, const geom::Vec3& pos);
196  // remove all labels
197  void ClearLabels();
198 
199  void FlagRebuild();
200  void FlagRefresh();
201 
202  bool GetAALines() const {return aalines_flag_;}
203  float GetLineWidth() const {return line_width_;}
204  float GetLineHalo() const {return line_halo_;}
205 
206  void SetNormalSmoothFactor(float smoothf);
207  float GetNormalSmoothFactor() const;
208 
209  Material GetMaterial() const;
210  void SetMaterial(const Material& m);
211 
212  // experimental, don't use
213  void SmoothVertices(float smoothf);
214 
215  void GLCleanup();
216 
217  // this really should not be here
218  static Color Ele2Color(const String& ele);
219 
220  void Debug(unsigned int flags);
221 
222  IndexedVertexArray& GetVA() {return va_;}
223  const IndexedVertexArray& GetVA() const {return va_;}
224 
225  protected:
226 
227  void PreRenderGL(bool flag);
228 
229  private:
230  GfxObj(const GfxObj& o);
231  GfxObj& operator=(const GfxObj&);
232 
233  protected:
234  void AppendColorOp(gfx::ColorOp* op);
235  void CleanColorOps();
236  void ReapplyColorOps();
237  void render_labels() const;
238  void render_depth_only();
239 
242  unsigned int debug_flags_;
243 
245  bool rebuild_;
246  bool refresh_;
247  float line_width_;
248  unsigned int poly_mode_;
250  float line_halo_;
251 
253  unsigned int mat_dlist_;
255 
256  float opacity_;
257  float smoothf_;
260 
261  bool solid_;
263 
267 
268  boost::ptr_vector<gfx::ColorOp> c_ops_;
269 
271 
273 };
274 
275 }} //ns
276 
277 #endif
bool GetAALines() const
Definition: gfx_object.hh:202
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:248
TextPrimList labels_
Definition: gfx_object.hh:270
unsigned int debug_flags_
Definition: gfx_object.hh:242
float GetLineWidth() const
Definition: gfx_object.hh:203
geom::Transform transform_
Definition: gfx_object.hh:244
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:204
boost::ptr_vector< gfx::ColorOp > c_ops_
Definition: gfx_object.hh:268
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:223
#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:240
basic and essential transformation class, including translation, rotation and center of rotation ...
Definition: transform.hh:39
RenderMode::Type render_mode_
Definition: gfx_object.hh:241
Three dimensional vector class, using Real precision.
Definition: vec3.hh:42
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:265
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:222
color gradient
Definition: gradient.hh:59
unsigned int mat_dlist_
Definition: gfx_object.hh:253