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 
74  class Feedback3DColor
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 
111  Vector3 _pos ;
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:
162  Feedback3DColor _position_and_color ;
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() ;
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 ;
215  NVector3 _normal ;
216  } ;
217 }
218 #endif
219 
vrender::Feedback3DColor::blue
GLfloat blue() const
Definition: Primitive.h:106
vrender::Polygone::initNormal
virtual void initNormal()
Definition: Primitive.cpp:122
vrender::Segment::~Segment
virtual ~Segment()
Definition: Primitive.h:189
vrender::Feedback3DColor::_pos
Vector3 _pos
Definition: Primitive.h:131
vrender::Polygone::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:112
vrender::Segment::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:79
vrender::Point::Point
Point(const Feedback3DColor &f)
Definition: Primitive.cpp:54
vrender::Polygone::nbVertices
virtual size_t nbVertices() const
Definition: Primitive.h:216
vrender::Point::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:64
vrender::Feedback3DColor::sizeInBuffer
static size_t sizeInBuffer()
Definition: Primitive.h:123
Types.h
vrender::Primitive::~Primitive
virtual ~Primitive()
Definition: Primitive.h:143
vrender::Polygone
Definition: Primitive.h:204
vrender::Polygone::equation
double equation(const Vector3 &p) const
Definition: Primitive.cpp:117
vrender::Point::nbVertices
virtual size_t nbVertices() const
Definition: Primitive.h:177
AxisAlignedBox.h
vrender::Feedback3DColor::pos
const Vector3 & pos() const
Definition: Primitive.h:108
vrender::Polygone::CheckInfoForPositionOperators
void CheckInfoForPositionOperators()
vrender::Polygone::_c
double _c
Definition: Primitive.h:234
vrender::Feedback3DColor::alpha
GLfloat alpha() const
Definition: Primitive.h:107
vrender::NVector3
Definition: NVector3.h:75
vrender::Primitive::_vibility
int _vibility
Definition: Primitive.h:167
vrender::Polygone::c
double c() const
Definition: Primitive.h:220
vrender::Feedback3DColor::_blue
GLfloat _blue
Definition: Primitive.h:134
vrender::Primitive::vertex
virtual const Vector3 & vertex(size_t) const =0
vrender::Segment::nbVertices
virtual size_t nbVertices() const
Definition: Primitive.h:190
vrender::Segment::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:84
vrender::Feedback3DColor::operator*
Feedback3DColor operator*(const GLFLOAT &f) const
Definition: Primitive.h:114
vrender::Feedback3DColor::_red
GLfloat _red
Definition: Primitive.h:132
vrender::Point::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:59
vrender::Feedback3DColor::x
FLOAT x() const
Definition: Primitive.h:101
vrender::FLOAT
double FLOAT
Definition: Types.h:80
vrender::Feedback3DColor::_green
GLfloat _green
Definition: Primitive.h:133
vrender::Feedback3DColor::_alpha
GLfloat _alpha
Definition: Primitive.h:135
vrender::Polygone::normal
const NVector3 & normal() const
Definition: Primitive.h:219
vrender::Point::bbox
virtual AxisAlignedBox_xyz bbox() const
Definition: Primitive.cpp:74
vrender::Point::~Point
virtual ~Point()
Definition: Primitive.h:174
vrender::Segment::Segment
Segment(const Feedback3DColor &p1, const Feedback3DColor &p2)
Definition: Primitive.h:188
vrender::Feedback3DColor::z
FLOAT z() const
Definition: Primitive.h:103
vrender::Feedback3DColor::green
GLfloat green() const
Definition: Primitive.h:105
vrender::AxisAlignedBox_xyz
AxisAlignedBox< Vector3 > AxisAlignedBox_xyz
Definition: AxisAlignedBox.h:91
vrender::Polygone::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t) const
Definition: Primitive.cpp:92
vrender::Primitive::bbox
virtual AxisAlignedBox_xyz bbox() const =0
vrender::Vector3
Definition: Vector3.h:58
vrender::Point::_position_and_color
Feedback3DColor _position_and_color
Definition: Primitive.h:182
vrender::Polygone::anglefactor
double anglefactor
Definition: Primitive.h:232
vrender::Feedback3DColor::red
GLfloat red() const
Definition: Primitive.h:104
vrender::Polygone::~Polygone
virtual ~Polygone()
Definition: Primitive.h:208
vrender::Primitive::nbVertices
virtual size_t nbVertices() const =0
vrender::Feedback3DColor
Definition: Primitive.h:94
vrender
Definition: AxisAlignedBox.h:48
vrender::Segment::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t i) const
Definition: Primitive.cpp:69
vrender::Point
Definition: Primitive.h:170
Vector3.h
vrender::Primitive
Definition: Primitive.h:140
vrender::Polygone::FlatFactor
FLOAT FlatFactor() const
Definition: Primitive.h:222
vrender::Feedback3DColor::operator+
Feedback3DColor operator+(const Feedback3DColor &v) const
Definition: Primitive.h:110
vrender::Polygone::_bbox
AxisAlignedBox_xyz _bbox
Definition: Primitive.h:228
NVector3.h
vrender::Feedback3DColor::y
FLOAT y() const
Definition: Primitive.h:102
vrender::Polygone::_normal
NVector3 _normal
Definition: Primitive.h:235
vrender::Polygone::vertex
virtual const Vector3 & vertex(size_t) const
Definition: Primitive.cpp:97
vrender::Feedback3DColor::Feedback3DColor
Feedback3DColor(GLfloat *loc)
Definition: Primitive.h:97
vrender::Primitive::sommet3DColor
virtual const Feedback3DColor & sommet3DColor(size_t) const =0
vrender::AxisAlignedBox< Vector3 >
vrender::Polygone::Polygone
Polygone(const std::vector< Feedback3DColor > &)
Definition: Primitive.cpp:103
vrender::Segment::P2
Feedback3DColor P2
Definition: Primitive.h:200
vrender::GLFLOAT
GLdouble GLFLOAT
Definition: Types.h:81
vrender::Feedback3DColor::operator<<
friend std::ostream & operator<<(std::ostream &, const Feedback3DColor &)
vrender::Segment::P1
Feedback3DColor P1
Definition: Primitive.h:199
vrender::Polygone::_vertices
std::vector< Feedback3DColor > _vertices
Definition: Primitive.h:229


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Apr 3 2025 02:40:44