Primitive.h
Go to the documentation of this file.
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.4.0.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #ifndef _PRIMITIVE_H_
46 #define _PRIMITIVE_H_
47 
48 #include <vector>
49 #include "AxisAlignedBox.h"
50 #include "Vector3.h"
51 #include "NVector3.h"
52 #include "Types.h"
53 
54 #ifdef WIN32
55 # include <windows.h>
56 #endif
57 
58 #ifdef __APPLE__
59 # include <OpenGL/gl.h>
60 #else
61 # include <GL/gl.h>
62 #endif
63 
64 namespace vrender
65 {
66  class Feedback3DColor ;
67  class Primitive ;
68 
69 
70 #define EPS_SMOOTH_LINE_FACTOR 0.06 /* Lower for better smooth lines. */
71 
72  // A Feedback3DColor is a structure containing informations about a vertex projected into
73  // the frame buffer.
74 
76  {
77  public:
78  Feedback3DColor(GLfloat *loc)
79  : _pos(loc[0],loc[1],loc[2]),
80  _red(loc[3]),_green(loc[4]),_blue(loc[5]),_alpha(loc[6]) {}
81 
82  inline FLOAT x() const { return _pos[0] ; }
83  inline FLOAT y() const { return _pos[1] ; }
84  inline FLOAT z() const { return _pos[2] ; }
85  inline GLfloat red() const { return _red ; }
86  inline GLfloat green() const { return _green ; }
87  inline GLfloat blue() const { return _blue ; }
88  inline GLfloat alpha() const { return _alpha ; }
89  inline const Vector3& pos() const { return _pos ; }
90 
91  inline Feedback3DColor operator+(const Feedback3DColor & v) const
92  {
93  return Feedback3DColor(x()+v.x(),y()+v.y(),z()+v.z(),red()+v.red(),green()+v.green(),blue()+v.blue(),alpha()+v.alpha()) ;
94  }
95  inline Feedback3DColor operator*(const GLFLOAT & f) const
96  {
97  return Feedback3DColor(x()*f,y()*f,z()*f,red()*GLfloat(f),green()*GLfloat(f),blue()*GLfloat(f),alpha()*GLfloat(f)) ;
98  }
99  friend inline Feedback3DColor operator*(const GLFLOAT & f,const Feedback3DColor& F)
100  {
101  return F*f ;
102  }
103 
104  static int sizeInBuffer() { return 7 ; }
105 
106  friend std::ostream& operator<<(std::ostream&,const Feedback3DColor&) ;
107 
108  protected:
109  Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
110  :_pos(x,y,z), _red(r), _green(g), _blue(b), _alpha(a) {}
111 
113  GLfloat _red;
114  GLfloat _green;
115  GLfloat _blue;
116  GLfloat _alpha;
117  } ;
118 
119  // A primitive is an entity
120  //
121  class Primitive
122  {
123  public:
124  virtual ~Primitive() {}
125 
126 
127  virtual const Feedback3DColor& sommet3DColor(int) const =0 ;
128 
129  // Renvoie le ieme vertex modulo le nombre de vertex.
130  virtual const Vector3& vertex(int) const = 0 ;
131 #ifdef A_FAIRE
132  virtual FLOAT Get_I_EPS(Primitive *) const ;
133  Vect3 VerticalProjectPointOnSupportPlane(const Vector3 &) const ;
134  void IntersectPrimitiveWithSupportPlane(Primitive *,int[],FLOAT[],Vect3 *&,Vect3 *&) ;
135  inline FLOAT Equation(const Vect3& p) { return p*_normal-_C ; }
136  virtual void Split(Vect3,FLOAT,Primitive * &,Primitive * &) = 0 ;
137  void GetSigns(Primitive *,int * &,FLOAT * &,int &,int &,FLOAT) ;
138  FLOAT Const() const { return _C ; }
139 
140  int depth() const { return _depth ; }
141  void setDepth(int d) const { _depth = d ; }
142 #endif
143  virtual AxisAlignedBox_xyz bbox() const = 0 ;
144  virtual unsigned int nbVertices() const = 0 ;
145 
146  protected:
147 
148  int _vibility ;
149  } ;
150 
151  class Point: public Primitive
152  {
153  public:
154  Point(const Feedback3DColor& f);
155  virtual ~Point() {}
156 
157  virtual const Vector3& vertex(int) const ;
158  virtual unsigned int nbVertices() const { return 1 ; }
159  virtual const Feedback3DColor& sommet3DColor(int) const ;
160  virtual AxisAlignedBox_xyz bbox() const ;
161 
162  private:
164  };
165 
166  class Segment: public Primitive
167  {
168  public:
169  Segment(const Feedback3DColor & p1, const Feedback3DColor & p2): P1(p1), P2(p2) {}
170  virtual ~Segment() {}
171  virtual unsigned int nbVertices() const { return 2 ; }
172  virtual const Vector3& vertex(int) const ;
173  virtual const Feedback3DColor& sommet3DColor(int i) const ;
174  virtual AxisAlignedBox_xyz bbox() const ;
175 #ifdef A_FAIRE
176  virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
177 #endif
178 
179  protected:
182  } ;
183 
184 
185  class Polygone: public Primitive
186  {
187  public:
188  Polygone(const std::vector<Feedback3DColor>&) ;
189  virtual ~Polygone() {}
190 #ifdef A_FAIRE
191  virtual int IsAPolygon() { return 1 ; }
192  virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
193  void InitEquation(double &,double &,double &,double &) ;
194 #endif
195  virtual const Feedback3DColor& sommet3DColor(int) const ;
196  virtual const Vector3& vertex(int) const ;
197  virtual unsigned int nbVertices() const { return _vertices.size() ; }
198  virtual AxisAlignedBox_xyz bbox() const ;
199  double equation(const Vector3& p) const ;
200  const NVector3& normal() const { return _normal ; }
201  double c() const { return _c ; }
202 
203  FLOAT FlatFactor() const { return anglefactor ; }
204 
205  protected:
206  virtual void initNormal() ;
207  void CheckInfoForPositionOperators() ;
208 
210  std::vector<Feedback3DColor> _vertices ;
211  // std::vector<FLOAT> _sommetsProjetes ;
212  // Vector3 N,M,L ;
213  double anglefactor ; // Determine a quel point un polygone est plat.
214  // Comparer a FLAT_POLYGON_EPS
215  double _c ;
217  } ;
218 }
219 #endif
220 
GLdouble GLFLOAT
Definition: Types.h:61
virtual unsigned int nbVertices() const
Definition: Primitive.h:197
virtual ~Point()
Definition: Primitive.h:155
FLOAT x() const
Definition: Primitive.h:82
friend Feedback3DColor operator*(const GLFLOAT &f, const Feedback3DColor &F)
Definition: Primitive.h:99
Feedback3DColor operator*(const GLFLOAT &f) const
Definition: Primitive.h:95
GLfloat alpha() const
Definition: Primitive.h:88
virtual ~Primitive()
Definition: Primitive.h:124
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:209
NVector3 _normal
Definition: Primitive.h:216
double c() const
Definition: Primitive.h:201
GLfloat green() const
Definition: Primitive.h:86
struct bbox_shape bbox
Feedback3DColor _position_and_color
Definition: Primitive.h:163
virtual unsigned int nbVertices() const
Definition: Primitive.h:158
const Vector3 & pos() const
Definition: Primitive.h:89
Segment(const Feedback3DColor &p1, const Feedback3DColor &p2)
Definition: Primitive.h:169
friend std::ostream & operator<<(std::ostream &, const Feedback3DColor &)
const NVector3 & normal() const
Definition: Primitive.h:200
Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: Primitive.h:109
FLOAT z() const
Definition: Primitive.h:84
virtual ~Segment()
Definition: Primitive.h:170
Feedback3DColor P1
Definition: Primitive.h:180
virtual ~Polygone()
Definition: Primitive.h:189
FLOAT y() const
Definition: Primitive.h:83
double FLOAT
Definition: Types.h:60
GLfloat blue() const
Definition: Primitive.h:87
FLOAT FlatFactor() const
Definition: Primitive.h:203
double anglefactor
Definition: Primitive.h:213
Feedback3DColor(GLfloat *loc)
Definition: Primitive.h:78
Feedback3DColor operator+(const Feedback3DColor &v) const
Definition: Primitive.h:91
static int sizeInBuffer()
Definition: Primitive.h:104
std::vector< Feedback3DColor > _vertices
Definition: Primitive.h:210
virtual unsigned int nbVertices() const
Definition: Primitive.h:171
GLfloat red() const
Definition: Primitive.h:85
Feedback3DColor P2
Definition: Primitive.h:181


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:25