KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_spline.h
Go to the documentation of this file.
1 /* $Id: gr_spline.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== */
19 
20 #ifndef KJB_gr_spline_H
21 #define KJB_gr_spline_H
22 
23 #include <m2_cpp/m2_spline.h>
24 #include <gr_cpp/gr_renderable.h>
26 #include <l_cpp/l_cloneable.h>
27 #include <m_cpp/m_vector.h>
28 #include <vector>
29 
30 #ifdef KJB_HAVE_OPENGL
31 
32 
33 namespace kjb {
34 namespace opengl {
35 class Opengl_nurbs_object
36 {
37 public:
38  Opengl_nurbs_object();
39  Opengl_nurbs_object(GLUnurbsObj* nobj);
40  Opengl_nurbs_object(const Opengl_nurbs_object& src);
41  virtual ~Opengl_nurbs_object();
42 
43  Opengl_nurbs_object& operator=(const Opengl_nurbs_object& nobj);
44 
45  void set(GLUnurbsObj* nobj);
46  GLUnurbsObj* get() const { return _my_nobj; }
47 protected:
48  static GLvoid _nurbs_error (GLenum errorCode);
49 private:
50  static GLUnurbsObj* _nobj;
51  static int _nobj_ref_count;
52 
53  mutable GLUnurbsObj* _my_nobj;
54 };
55 
56 class Opengl_nurbs_callable :
57  public Opengl_callable,
58  public virtual Cloneable
59 {
60 public:
61  Opengl_nurbs_callable(GLenum type = 0);
62  Opengl_nurbs_callable(const Opengl_nurbs_callable& src);
63  virtual ~Opengl_nurbs_callable();
64 
65  virtual Opengl_nurbs_callable& operator=(const Opengl_nurbs_callable& src);
66  virtual Opengl_nurbs_callable* clone() const = 0;
67 
69  void set_nurbs_object(GLUnurbsObj* nobj);
70 
71  GLUnurbsObj* get_nurbs_object() const;
72 
73  virtual void gl_call() const = 0;
74 protected:
75  mutable Opengl_nurbs_object _nobj;
76 
77  GLenum _type;
78 };
79 
80 class Nurbs_trim_curve
81 {
82 public:
83  virtual void trim() const = 0;
84 };
85 
86 class Gl_nurbs_curve : public Nurbs_curve,
87  public Opengl_nurbs_callable,
88  public Nurbs_trim_curve,
89  public Generic_renderable
90 {
91 public:
92  Gl_nurbs_curve();
93  Gl_nurbs_curve(
94  uint num_knots,
95  const float* knots,
96  uint degree,
97  std::vector<Vector> ctl_points,
98  GLenum type);
99  Gl_nurbs_curve(const Gl_nurbs_curve& src);
100  virtual ~Gl_nurbs_curve(){}
101 
102  Gl_nurbs_curve& operator=(const Gl_nurbs_curve& src);
103  Gl_nurbs_curve* clone() const;
104 
105  virtual void gl_call() const;
106 
107  virtual void solid_render() const {gl_call();}
108 
109  virtual void trim() const {gl_call();}
110 };
111 
112 
113 class Gl_nurbs_surface :
114  public Nurbs_surface,
115  public Opengl_nurbs_callable,
116  public Generic_renderable
117 {
118 public:
119  Gl_nurbs_surface();
120  Gl_nurbs_surface(
121  uint num_knots_s,
122  const float* knots_s,
123  uint num_knots_t,
124  const float* knots_t,
125  uint degree_s,
126  uint degree_t,
127  const std::vector<std::vector<Vector> >& ctl_points,
128  GLenum type = GL_MAP2_VERTEX_3);
129 
130  Gl_nurbs_surface(const Gl_nurbs_surface& src);
131  virtual ~Gl_nurbs_surface(){}
132 
133  void init(std::vector<float>& pts, const std::vector<std::vector<kjb::Vector> >& ctl_points);
134 
135  Gl_nurbs_surface& operator=(const Gl_nurbs_surface& src);
136  Gl_nurbs_surface* clone() const;
137 
138  virtual void gl_call() const;
139 
140  virtual void wire_render() const;
141  virtual void solid_render() const {gl_call();}
142 
143 protected:
144  mutable std::vector< float > _ctl_points_flat;
145 };
146 
147 class Gl_bezier_curve :
148  public Bezier_curve,
149  public Opengl_nurbs_callable,
150  public Generic_renderable
151 {
152 public:
153  Gl_bezier_curve(int degree = 3, int dimension = 3, GLenum type = GL_MAP1_VERTEX_3);
154  Gl_bezier_curve(const Gl_bezier_curve& src);
155  virtual ~Gl_bezier_curve() {}
156 
157  Gl_bezier_curve& operator=(const Gl_bezier_curve& src);
158  Gl_bezier_curve* clone() const;
159 
160  Gl_nurbs_curve to_gl_nurbs() const;
161 
162  virtual void gl_call() const;
163 
164  virtual void solid_render() const {gl_call();}
165 };
166 
170 class Gl_polybezier_curve :
171  public Polybezier_curve,
172  public Opengl_nurbs_callable,
173  public Generic_renderable
174 {
175 public:
176  Gl_polybezier_curve(int dimension = 3, GLenum type = GL_MAP1_VERTEX_3);
177  Gl_polybezier_curve(const Gl_polybezier_curve& src);
178  virtual ~Gl_polybezier_curve() {}
179 
180  Gl_polybezier_curve& operator=(const Gl_polybezier_curve& src);
181  virtual Gl_polybezier_curve* clone() const {return new Gl_polybezier_curve(*this);}
182 
183  virtual Gl_nurbs_curve to_gl_nurbs() const;
184 
185  virtual void gl_call() const;
186 
187  virtual void solid_render() const {gl_call();}
188 };
189 } // namespace opengl
190 } // namespace kjb
191 
192 #endif
193 #endif /* ----- #ifndef KJB_gr_spline_H ----- */
int GLenum
Definition: gr_opengl_headers.h:65
Definitions of spline classes.
Abstract class to render this object with GL.
Abstract class to clone this object.
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...