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 #include <boost/ptr_container/ptr_vector.hpp>
30 
31 #include <vector>
32 
33 #include <ost/config.hh>
34 #include <ost/gfx/module_config.hh>
35 
36 #include <ost/geom/transform.hh>
37 
38 #include "gfx_object_fw.hh"
39 #include "gfx_object_base.hh"
40 #include "gfx_prim.hh"
41 #include "vertex_array.hh"
42 #include "input.hh"
43 #include "exporter_fw.hh"
44 
45 namespace ost { namespace gfx {
46 
47 class Scene; // fw decl
48 
51 {
52 public:
53  GfxObj(const String& name);
54 
55  // gfx node interface
56  virtual GfxNodeP Copy() const;
57  virtual void DeepSwap(GfxObj& go);
58  virtual void RenderGL(RenderPass pass);
59  virtual void RenderPov(PovState& pov);
60  virtual void Export(Exporter* ex);
61  virtual void Apply(GfxNodeVisitor& v, GfxNodeVisitor::Stack st);
62  virtual int GetType() const;
63  //
64 
65  // gfx obj base interface
66  virtual void SetMatAmb(const Color& c);
67  virtual void SetMatDiff(const Color& c);
68  virtual void SetMatSpec(const Color& c);
69  virtual void SetMatShin(float s);
70  virtual void SetMatEmm(const Color& c);
71  virtual void ContextSwitch();
72  virtual void SetRenderMode(RenderMode::Type m);
73  virtual RenderMode::Type GetRenderMode() const;
74  virtual geom::Vec3 GetCenter() const;
75  virtual void SetLineWidth(float w);
76  virtual void SetPolyMode(unsigned int m);
77  virtual void SetAALines(bool f);
78  virtual void SetLineHalo(float f);
79  virtual void SetOutline(bool f);
80  virtual bool GetOutline() const {return outline_flag_;};
81  virtual void SetOutlineMode(int m);
82  virtual int GetOutlineMode() const {return outline_mode_;}
83  virtual void SetOutlineWidth(float f);
84  virtual float GetOutlineWidth() const;
85  virtual void SetOutlineExpandFactor(float f);
86  virtual float GetOutlineExpandFactor() const;
87  virtual void SetOutlineExpandColor(const Color& c);
88  virtual Color GetOutlineExpandColor() const;
89  virtual void SetOpacity(float f);
90  virtual float GetOpacity() const {return opacity_;}
91  virtual void SetSolid(bool f);
92  virtual bool GetSolid() const {return solid_;}
93  virtual void SetSolidColor(const Color& c);
94  virtual Color GetSolidColor() const {return solid_color_;}
95 
96  virtual void ColorBy(const mol::EntityView& ev,
97  const String& prop,
98  const Gradient& g, float minv, float maxv);
99 #if OST_IMG_ENABLED
100  virtual void ColorBy(const img::MapHandle& mh,
101  const String& prop,
102  const Gradient& g,float minv, float maxv);
103 #endif
104 
105  // end of gfx obj base interface
106 
107  // new gfx obj virtual interface starts here
108 
118  virtual geom::AlignedCuboid GetBoundingBox(bool use_tf=false) const;
119 
130  virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
131  const geom::Transform& tf) const;
132 
133  // implemented in derived classes for the actual GL rendering
134  /*
135  note: only STANDARD_RENDER_PASS and GLOW_RENDER_PASS need to
136  be implemented, the rest is taken care of by GfxObj::RenderGL
137  */
138  virtual void CustomRenderGL(RenderPass pass);
139 
140  // implemented in derived classes to deal with initialization etc
141  // called just before CustomRenderGL is called
142  // the boolean flag indicated that a re-build was requested
143  virtual void CustomPreRenderGL(bool rebuild);
144 
145  // implemented in derived classes for first GL initialization
146  // which should be done here, not in the ctor
147  virtual void InitGL();
148 
149  // implemented in derived classes for the actual POVray export
150  virtual void CustomRenderPov(PovState& pov);
151 
152  // handle pick (select) event
153  /*
154  should return the position of the picked object in order for the caller
155  to determine the closest one, and indicate with the boolean return wether
156  the selection was successful
157  the boolean flag indicates whether a true pick or just a feedback is requested
158  the given zlim is the projected z of the best selection so far, and should be
159  used for both picking as well as feedback if the selection is in front of the
160  currently best one
161  */
162  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim, bool pick_flag);
163 
164  // input event entry point
165  virtual void OnInput(const InputEvent& e);
166 
167  // informs derived class that render mode has changes
168  virtual void OnRenderModeChange();
169  virtual void OnGLCleanup();
170  //
171 
173  void Clear();
174 
176  const geom::Transform& GetTF() const;
178  void SetTF(const geom::Transform& tf);
179 
180  // add a label at the given position
181  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col, float psize);
182  // convenience method
183  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col);
184  // convenience method
185  void AddLabel(const String& s, const geom::Vec3& pos, float psize);
186  // convenience method
187  void AddLabel(const String& s, const geom::Vec3& pos);
188  // remove all labels
189  void ClearLabels();
190 
191  void FlagRebuild();
192  void FlagRefresh();
193 
194  bool GetAALines() const {return aalines_flag_;}
195  float GetLineWidth() const {return line_width_;}
196  float GetLineHalo() const {return line_halo_;}
197 
198  void SetNormalSmoothFactor(float smoothf);
199  float GetNormalSmoothFactor() const;
200 
201  Material GetMaterial() const;
202  void SetMaterial(const Material& m);
203 
204  // experimental, don't use
205  void SmoothVertices(float smoothf);
206 
207  void GLCleanup();
208 
209  // this really should not be here
210  static Color Ele2Color(const String& ele);
211 
212  void Debug(unsigned int flags);
213 
214  protected:
215 
216  void PreRenderGL(bool flag);
217 
218  private:
219  GfxObj(const GfxObj& o);
220  GfxObj& operator=(const GfxObj&);
221 
222  protected:
223  void AppendColorOp(gfx::ColorOp* op);
224  void CleanColorOps();
225  void ReapplyColorOps();
226  void render_labels() const;
227  void render_depth_only();
228 
231  unsigned int debug_flags_;
232 
234  bool rebuild_;
235  bool refresh_;
236  float line_width_;
237  unsigned int poly_mode_;
239  float line_halo_;
240 
242  unsigned int mat_dlist_;
244 
245  float opacity_;
246  float smoothf_;
249 
250  bool solid_;
252 
253  boost::ptr_vector<gfx::ColorOp> c_ops_;
254 
256 
258 };
259 
260 }} //ns
261 
262 #endif