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/mol/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 ColorBy(const mol::EntityView& ev,
92  const String& prop,
93  const Gradient& g, float minv, float maxv);
94 #if OST_IMG_ENABLED
95  virtual void ColorBy(const img::MapHandle& mh,
96  const String& prop,
97  const Gradient& g,float minv, float maxv);
98 #endif
99 
100  // end of gfx obj base interface
101 
102  // new gfx obj virtual interface starts here
103 
110  virtual geom::AlignedCuboid GetBoundingBox() const;
111 
113  virtual void ProcessLimits(geom::Vec3& minc, geom::Vec3& maxc,
114  const mol::Transform& tf) const;
115 
116  // implemented in derived classes for the actual GL rendering
117  /*
118  note: only STANDARD_RENDER_PASS and GLOW_RENDER_PASS need to
119  be implemented, the rest is taken care of by GfxObj::RenderGL
120  */
121  virtual void CustomRenderGL(RenderPass pass);
122 
123  // implemented in derived classes to deal with initialization etc
124  // called just before CustomRenderGL is called
125  // the boolean flag indicated that a re-build was requested
126  virtual void CustomPreRenderGL(bool rebuild);
127 
128  // implemented in derived classes for first GL initialization
129  // which should be done here, not in the ctor
130  virtual void InitGL();
131 
132  // implemented in derived classes for the actual POVray export
133  virtual void CustomRenderPov(PovState& pov);
134 
135  // handle pick (select) event
136  /*
137  should return the position of the picked object in order for the caller
138  to determine the closest one, and indicate with the boolean return wether
139  the selection was successful
140  the boolean flag indicates whether a true pick or just a feedback is requested
141  the given zlim is the projected z of the best selection so far, and should be
142  used for both picking as well as feedback if the selection is in front of the
143  currently best one
144  */
145  virtual bool OnSelect(const geom::Line3& l, geom::Vec3& result, float zlim, bool pick_flag);
146 
147  // input event entry point
148  virtual void OnInput(const InputEvent& e);
149 
150  // informs derived class that render mode has changes
151  virtual void OnRenderModeChange();
152  virtual void OnGLCleanup();
153  //
154 
156  void Clear();
157 
159  const mol::Transform& GetTF() const;
161  void SetTF(const mol::Transform& tf);
162 
163  // add a label at the given position
164  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col, float psize);
165  // convenience method
166  void AddLabel(const String& s, const geom::Vec3& pos, const Color& col);
167  // convenience method
168  void AddLabel(const String& s, const geom::Vec3& pos, float psize);
169  // convenience method
170  void AddLabel(const String& s, const geom::Vec3& pos);
171  // remove all labels
172  void ClearLabels();
173 
174  void FlagRebuild();
175  void FlagRefresh();
176 
177  bool GetAALines() const {return aalines_flag_;}
178  float GetLineWidth() const {return line_width_;}
179  float GetLineHalo() const {return line_halo_;}
180 
181  void SetNormalSmoothFactor(float smoothf);
182  float GetNormalSmoothFactor() const;
183 
184  Material GetMaterial() const;
185  void SetMaterial(const Material& m);
186 
187  // experimental, don't use
188  void SmoothVertices(float smoothf);
189 
190  void GLCleanup();
191 
192  // this really should not be here
193  static Color Ele2Color(const String& ele);
194 
195  void Debug(unsigned int flags);
196 
197  protected:
198 
199  void PreRenderGL(bool flag);
200 
201  private:
202  GfxObj(const GfxObj& o);
203  GfxObj& operator=(const GfxObj&);
204 
205  protected:
206  void AppendColorOp(gfx::ColorOp* op);
207  void CleanColorOps();
208  void ReapplyColorOps();
209  void render_labels() const;
210  void render_depth_only();
211 
214  unsigned int debug_flags_;
215 
217  bool rebuild_;
218  bool refresh_;
219  float line_width_;
220  unsigned int poly_mode_;
222  float line_halo_;
223 
225  unsigned int mat_dlist_;
227 
228  float opacity_;
229  float smoothf_;
232 
233  boost::ptr_vector<gfx::ColorOp> c_ops_;
234 
236 
238 };
239 
240 }} //ns
241 
242 #endif