Primitive.h
Go to the documentation of this file.
00001 /*
00002  This file is part of the VRender library.
00003  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
00004  Version 1.0.0, released on June 27, 2005.
00005 
00006  http://artis.imag.fr/Members/Cyril.Soler/VRender
00007 
00008  VRender is free software; you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation; either version 2 of the License, or
00011  (at your option) any later version.
00012 
00013  VRender is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with VRender; if not, write to the Free Software Foundation, Inc.,
00020  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00021 */
00022 
00023 /****************************************************************************
00024 
00025  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00026 
00027  This file is part of the QGLViewer library version 2.4.0.
00028 
00029  http://www.libqglviewer.com - contact@libqglviewer.com
00030 
00031  This file may be used under the terms of the GNU General Public License 
00032  versions 2.0 or 3.0 as published by the Free Software Foundation and
00033  appearing in the LICENSE file included in the packaging of this file.
00034  In addition, as a special exception, Gilles Debunne gives you certain 
00035  additional rights, described in the file GPL_EXCEPTION in this package.
00036 
00037  libQGLViewer uses dual licensing. Commercial/proprietary software must
00038  purchase a libQGLViewer Commercial License.
00039 
00040  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00041  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00042 
00043 *****************************************************************************/
00044 
00045 #ifndef _PRIMITIVE_H_
00046 #define _PRIMITIVE_H_
00047 
00048 #include <vector>
00049 #include "AxisAlignedBox.h"
00050 #include "Vector3.h"
00051 #include "NVector3.h"
00052 #include "Types.h"
00053 
00054 #ifdef WIN32
00055 # include <windows.h>
00056 #endif
00057 
00058 #ifdef __APPLE__
00059 # include <OpenGL/gl.h>
00060 #else
00061 # include <GL/gl.h>
00062 #endif
00063 
00064 namespace vrender
00065 {
00066     class Feedback3DColor ;
00067     class Primitive ;
00068 
00069 
00070 #define EPS_SMOOTH_LINE_FACTOR 0.06  /* Lower for better smooth lines. */
00071 
00072     //  A Feedback3DColor is a structure containing informations about a vertex projected into
00073     // the frame buffer.
00074 
00075     class Feedback3DColor
00076     {
00077     public:
00078         Feedback3DColor(GLfloat *loc)
00079             :   _pos(loc[0],loc[1],loc[2]),
00080             _red(loc[3]),_green(loc[4]),_blue(loc[5]),_alpha(loc[6]) {}
00081 
00082         inline FLOAT x() const { return _pos[0] ; }
00083         inline FLOAT y() const { return _pos[1] ; }
00084         inline FLOAT z() const { return _pos[2] ; }
00085         inline GLfloat red() const { return _red ; }
00086         inline GLfloat green() const { return _green ; }
00087         inline GLfloat blue() const { return _blue ; }
00088         inline GLfloat alpha() const { return _alpha ; }
00089         inline const Vector3& pos() const { return _pos ; }
00090 
00091         inline Feedback3DColor operator+(const Feedback3DColor & v) const
00092         {
00093             return Feedback3DColor(x()+v.x(),y()+v.y(),z()+v.z(),red()+v.red(),green()+v.green(),blue()+v.blue(),alpha()+v.alpha()) ;
00094         }
00095         inline Feedback3DColor operator*(const GLFLOAT & f) const
00096         {
00097             return Feedback3DColor(x()*f,y()*f,z()*f,red()*GLfloat(f),green()*GLfloat(f),blue()*GLfloat(f),alpha()*GLfloat(f)) ;
00098         }
00099         friend inline Feedback3DColor operator*(const GLFLOAT & f,const Feedback3DColor& F)
00100         {
00101             return F*f ;
00102         }
00103 
00104         static int sizeInBuffer() { return 7 ; }
00105 
00106         friend std::ostream& operator<<(std::ostream&,const Feedback3DColor&) ;
00107 
00108                 protected:
00109         Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
00110             :_pos(x,y,z), _red(r), _green(g), _blue(b), _alpha(a) {}
00111 
00112         Vector3 _pos ;
00113         GLfloat _red;
00114         GLfloat _green;
00115         GLfloat _blue;
00116         GLfloat _alpha;
00117     } ;
00118 
00119     // A primitive is an entity
00120     //
00121     class Primitive
00122     {
00123     public:
00124         virtual ~Primitive() {}
00125 
00126 
00127         virtual const Feedback3DColor& sommet3DColor(int) const =0 ;
00128 
00129         // Renvoie le ieme vertex modulo le nombre de vertex.
00130         virtual const Vector3& vertex(int) const = 0 ;
00131 #ifdef A_FAIRE
00132         virtual FLOAT Get_I_EPS(Primitive *) const ;
00133         Vect3 VerticalProjectPointOnSupportPlane(const Vector3 &) const ;
00134         void IntersectPrimitiveWithSupportPlane(Primitive *,int[],FLOAT[],Vect3 *&,Vect3 *&) ;
00135         inline FLOAT Equation(const Vect3& p) { return p*_normal-_C ; }
00136         virtual void Split(Vect3,FLOAT,Primitive * &,Primitive * &) = 0 ;
00137         void GetSigns(Primitive *,int * &,FLOAT * &,int &,int &,FLOAT) ;
00138         FLOAT Const() const { return _C ; }
00139 
00140         int depth() const { return _depth ; }
00141         void setDepth(int d) const { _depth = d ; }
00142 #endif
00143         virtual AxisAlignedBox_xyz bbox() const = 0 ;
00144         virtual unsigned int nbVertices() const = 0 ;
00145 
00146                 protected:
00147 
00148         int _vibility ;
00149     } ;
00150 
00151     class Point: public Primitive
00152     {
00153     public:
00154         Point(const Feedback3DColor& f);
00155         virtual ~Point() {}
00156 
00157         virtual const Vector3& vertex(int) const ;
00158         virtual unsigned int nbVertices() const { return 1 ; }
00159         virtual const Feedback3DColor& sommet3DColor(int) const ;
00160         virtual AxisAlignedBox_xyz bbox() const ;
00161 
00162                 private:
00163         Feedback3DColor _position_and_color ;
00164     };
00165 
00166     class Segment: public Primitive
00167     {
00168     public:
00169         Segment(const Feedback3DColor & p1, const Feedback3DColor & p2): P1(p1), P2(p2) {}
00170         virtual ~Segment() {}
00171         virtual unsigned int nbVertices() const { return 2 ; }
00172         virtual const Vector3& vertex(int) const ;
00173         virtual const Feedback3DColor& sommet3DColor(int i) const ;
00174         virtual AxisAlignedBox_xyz bbox() const ;
00175 #ifdef A_FAIRE
00176         virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
00177 #endif
00178 
00179                 protected:
00180         Feedback3DColor P1 ;
00181         Feedback3DColor P2 ;
00182     } ;
00183 
00184 
00185     class Polygone: public Primitive
00186     {
00187     public:
00188         Polygone(const std::vector<Feedback3DColor>&) ;
00189         virtual ~Polygone() {}
00190 #ifdef A_FAIRE
00191         virtual int IsAPolygon() { return 1 ; }
00192         virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
00193         void InitEquation(double &,double &,double &,double &) ;
00194 #endif
00195         virtual const Feedback3DColor& sommet3DColor(int) const ;
00196         virtual const Vector3& vertex(int) const ;
00197         virtual unsigned int nbVertices() const { return _vertices.size() ; }
00198         virtual AxisAlignedBox_xyz bbox() const ;
00199         double equation(const Vector3& p) const ;
00200         const NVector3& normal() const { return _normal ; }
00201         double c() const { return _c ; }
00202 
00203         FLOAT FlatFactor() const { return anglefactor ; }
00204 
00205                 protected:
00206         virtual void initNormal() ;
00207         void CheckInfoForPositionOperators() ;
00208 
00209         AxisAlignedBox_xyz _bbox ;
00210         std::vector<Feedback3DColor> _vertices ;
00211         // std::vector<FLOAT> _sommetsProjetes ;
00212         // Vector3 N,M,L ;
00213         double anglefactor ;            //  Determine a quel point un polygone est plat.
00214         // Comparer a FLAT_POLYGON_EPS
00215         double _c ;
00216         NVector3 _normal ;
00217     } ;
00218 }
00219 #endif
00220 


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Jun 6 2019 17:31:58