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-2014 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.6.3.
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 #define EPS_SMOOTH_LINE_FACTOR 0.06 /* Lower for better smooth lines. */
70 
71  // A Feedback3DColor is a structure containing informations about a vertex projected into
72  // the frame buffer.
73 
75  {
76  public:
77  Feedback3DColor(GLfloat *loc)
78  : _pos(loc[0],loc[1],loc[2]),
79  _red(loc[3]),_green(loc[4]),_blue(loc[5]),_alpha(loc[6]) {}
80 
81  inline FLOAT x() const { return _pos[0] ; }
82  inline FLOAT y() const { return _pos[1] ; }
83  inline FLOAT z() const { return _pos[2] ; }
84  inline GLfloat red() const { return _red ; }
85  inline GLfloat green() const { return _green ; }
86  inline GLfloat blue() const { return _blue ; }
87  inline GLfloat alpha() const { return _alpha ; }
88  inline const Vector3& pos() const { return _pos ; }
89 
90  inline Feedback3DColor operator+(const Feedback3DColor & v) const
91  {
92  return Feedback3DColor(x()+v.x(),y()+v.y(),z()+v.z(),red()+v.red(),green()+v.green(),blue()+v.blue(),alpha()+v.alpha()) ;
93  }
94  inline Feedback3DColor operator*(const GLFLOAT & f) const
95  {
96  return Feedback3DColor(x()*f,y()*f,z()*f,red()*GLfloat(f),green()*GLfloat(f),blue()*GLfloat(f),alpha()*GLfloat(f)) ;
97  }
98  friend inline Feedback3DColor operator*(const GLFLOAT & f,const Feedback3DColor& F)
99  {
100  return F*f ;
101  }
102 
103  static size_t sizeInBuffer() { return 7 ; }
104 
105  friend std::ostream& operator<<(std::ostream&,const Feedback3DColor&) ;
106 
107  protected:
108  Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
109  :_pos(x,y,z), _red(r), _green(g), _blue(b), _alpha(a) {}
110 
112  GLfloat _red;
113  GLfloat _green;
114  GLfloat _blue;
115  GLfloat _alpha;
116  } ;
117 
118  // A primitive is an entity
119  //
120  class Primitive
121  {
122  public:
123  virtual ~Primitive() {}
124 
125 
126  virtual const Feedback3DColor& sommet3DColor(size_t) const =0 ;
127 
128  // Renvoie le ieme vertex modulo le nombre de vertex.
129  virtual const Vector3& vertex(size_t) const = 0 ;
130 #ifdef A_FAIRE
131  virtual FLOAT Get_I_EPS(Primitive *) const ;
132  Vect3 VerticalProjectPointOnSupportPlane(const Vector3 &) const ;
133  void IntersectPrimitiveWithSupportPlane(Primitive *,int[],FLOAT[],Vect3 *&,Vect3 *&) ;
134  inline FLOAT Equation(const Vect3& p) { return p*_normal-_C ; }
135  virtual void Split(Vect3,FLOAT,Primitive * &,Primitive * &) = 0 ;
136  void GetSigns(Primitive *,int * &,FLOAT * &,int &,int &,FLOAT) ;
137  FLOAT Const() const { return _C ; }
138 
139  int depth() const { return _depth ; }
140  void setDepth(int d) const { _depth = d ; }
141 #endif
142  virtual AxisAlignedBox_xyz bbox() const = 0 ;
143  virtual size_t nbVertices() const = 0 ;
144 
145  protected:
146 
147  int _vibility ;
148  } ;
149 
150  class Point: public Primitive
151  {
152  public:
153  Point(const Feedback3DColor& f);
154  virtual ~Point() {}
155 
156  virtual const Vector3& vertex(size_t) const ;
157  virtual size_t nbVertices() const { return 1 ; }
158  virtual const Feedback3DColor& sommet3DColor(size_t) const ;
159  virtual AxisAlignedBox_xyz bbox() const ;
160 
161  private:
163  };
164 
165  class Segment: public Primitive
166  {
167  public:
168  Segment(const Feedback3DColor & p1, const Feedback3DColor & p2): P1(p1), P2(p2) {}
169  virtual ~Segment() {}
170  virtual size_t nbVertices() const { return 2 ; }
171  virtual const Vector3& vertex(size_t) const ;
172  virtual const Feedback3DColor& sommet3DColor(size_t i) const ;
173  virtual AxisAlignedBox_xyz bbox() const ;
174 #ifdef A_FAIRE
175  virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
176 #endif
177 
178  protected:
181  } ;
182 
183 
184  class Polygone: public Primitive
185  {
186  public:
187  Polygone(const std::vector<Feedback3DColor>&) ;
188  virtual ~Polygone() {}
189 #ifdef A_FAIRE
190  virtual int IsAPolygon() { return 1 ; }
191  virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
192  void InitEquation(double &,double &,double &,double &) ;
193 #endif
194  virtual const Feedback3DColor& sommet3DColor(size_t) const ;
195  virtual const Vector3& vertex(size_t) const ;
196  virtual size_t nbVertices() const { return _vertices.size() ; }
197  virtual AxisAlignedBox_xyz bbox() const ;
198  double equation(const Vector3& p) const ;
199  const NVector3& normal() const { return _normal ; }
200  double c() const { return _c ; }
201 
202  FLOAT FlatFactor() const { return anglefactor ; }
203 
204  protected:
205  virtual void initNormal() ;
206  void CheckInfoForPositionOperators() ;
207 
209  std::vector<Feedback3DColor> _vertices ;
210  // std::vector<FLOAT> _sommetsProjetes ;
211  // Vector3 N,M,L ;
212  double anglefactor ; // Determine a quel point un polygone est plat.
213  // Comparer a FLAT_POLYGON_EPS
214  double _c ;
216  } ;
217 }
218 #endif
219 
GLdouble GLFLOAT
Definition: Types.h:61
virtual ~Point()
Definition: Primitive.h:154
FLOAT x() const
Definition: Primitive.h:81
friend Feedback3DColor operator*(const GLFLOAT &f, const Feedback3DColor &F)
Definition: Primitive.h:98
Feedback3DColor operator*(const GLFLOAT &f) const
Definition: Primitive.h:94
GLfloat alpha() const
Definition: Primitive.h:87
static size_t sizeInBuffer()
Definition: Primitive.h:103
virtual ~Primitive()
Definition: Primitive.h:123
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:208
NVector3 _normal
Definition: Primitive.h:215
double c() const
Definition: Primitive.h:200
GLfloat green() const
Definition: Primitive.h:85
struct bbox_shape bbox
Feedback3DColor _position_and_color
Definition: Primitive.h:162
const Vector3 & pos() const
Definition: Primitive.h:88
Segment(const Feedback3DColor &p1, const Feedback3DColor &p2)
Definition: Primitive.h:168
virtual size_t nbVertices() const
Definition: Primitive.h:170
friend std::ostream & operator<<(std::ostream &, const Feedback3DColor &)
virtual size_t nbVertices() const
Definition: Primitive.h:196
const NVector3 & normal() const
Definition: Primitive.h:199
Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
Definition: Primitive.h:108
FLOAT z() const
Definition: Primitive.h:83
virtual ~Segment()
Definition: Primitive.h:169
Feedback3DColor P1
Definition: Primitive.h:179
virtual ~Polygone()
Definition: Primitive.h:188
FLOAT y() const
Definition: Primitive.h:82
double FLOAT
Definition: Types.h:60
GLfloat blue() const
Definition: Primitive.h:86
FLOAT FlatFactor() const
Definition: Primitive.h:202
double anglefactor
Definition: Primitive.h:212
Feedback3DColor(GLfloat *loc)
Definition: Primitive.h:77
virtual size_t nbVertices() const
Definition: Primitive.h:157
Feedback3DColor operator+(const Feedback3DColor &v) const
Definition: Primitive.h:90
std::vector< Feedback3DColor > _vertices
Definition: Primitive.h:209
GLfloat red() const
Definition: Primitive.h:84
Feedback3DColor P2
Definition: Primitive.h:180


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39