space.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 Revision 1.10  2007/07/31 12:21:50  ganovelli
00028 added gltetra, added normal gltriangle
00029 
00030 Revision 1.9  2007/05/08 18:55:38  ganovelli
00031 glTriangle added
00032 
00033 Revision 1.8  2007/01/18 01:26:23  cignoni
00034 Added cast for mac compiling
00035 
00036 Revision 1.7  2005/10/13 08:32:26  cignoni
00037 Added glscale(scalar) and corrected bug in glscale(point2)
00038 
00039 Revision 1.6  2005/06/30 10:17:04  ganovelli
00040 added draw plane
00041 
00042 Revision 1.5  2005/05/05 12:28:13  cignoni
00043 added glboxwire
00044 
00045 Revision 1.4  2004/07/07 23:30:28  cignoni
00046 Added box3 drawing functions
00047 
00048 Revision 1.3  2004/05/26 15:13:01  cignoni
00049 Removed inclusion of gl extension stuff and added glcolor stuff
00050 
00051 Revision 1.2  2004/05/13 23:44:47  ponchio
00052 <GL/GL.h>  -->   <GL/gl.h>
00053 
00054 Revision 1.1  2004/04/05 11:56:14  cignoni
00055 First working version!
00056 
00057 
00058 ****************************************************************************/
00059 
00060 #ifndef VCG_USE_EIGEN
00061 #include "deprecated_space.h"
00062 #else
00063 
00064 #ifndef VCG_GL_SPACE_H
00065 #define VCG_GL_SPACE_H
00066 
00067 // Please note that this file assume that you have already included your
00068 // gl-extension wrapping utility, and that therefore all the extension symbol are already defined.
00069 
00070 #include <vcg/space/triangle3.h>
00071 #include <vcg/space/plane3.h>
00072 #include <vcg/space/point2.h>
00073 #include <vcg/space/point3.h>
00074 #include <vcg/space/color4.h>
00075 #include <vcg/space/box2.h>
00076 #include <vcg/space/box3.h>
00077 
00078 namespace vcg {
00079 
00080 template<typename Derived, int Rows=Derived::RowsAtCompileTime, int Cols=Derived::ColsAtCompileTime>
00081 struct EvalToKnownPointType;
00082 
00083 template<typename Derived> struct EvalToKnownPointType<Derived,2,1>
00084 { typedef Point2<typename Derived::Scalar> Type; };
00085 
00086 template<typename Derived> struct EvalToKnownPointType<Derived,3,1>
00087 { typedef Point3<typename Derived::Scalar> Type; };
00088 
00089 template<typename Derived> struct EvalToKnownPointType<Derived,4,1>
00090 { typedef Point4<typename Derived::Scalar> Type; };
00091 
00092 #define _WRAP_EIGEN_XPR(FUNC) template<typename Derived>  \
00093         inline void FUNC(const Eigen::MatrixBase<Derived>& p) { \
00094                 FUNC(typename EvalToKnownPointType<Derived>::Type(p)); }
00095 
00096 _WRAP_EIGEN_XPR(glVertex)
00097 _WRAP_EIGEN_XPR(glNormal)
00098 _WRAP_EIGEN_XPR(glTexCoord)
00099 _WRAP_EIGEN_XPR(glTranslate)
00100 _WRAP_EIGEN_XPR(glScale)
00101 
00102         inline void glScale(float const & p){ glScalef(p,p,p);}
00103         inline void glScale(double const & p){ glScaled(p,p,p);}
00104 
00105         template<typename T> inline void glVertex(const Eigen::Matrix<T,2,1> & p) { assert(0); }
00106         template<> inline void glVertex(const Eigen::Matrix<int,2,1> & p)   { glVertex2iv((const GLint*)p.data());}
00107         template<> inline void glVertex(const Eigen::Matrix<short,2,1> & p) { glVertex2sv(p.data());}
00108         template<> inline void glVertex(const Eigen::Matrix<float,2,1> & p) { glVertex2fv(p.data());}
00109         template<> inline void glVertex(const Eigen::Matrix<double,2,1> & p){ glVertex2dv(p.data());}
00110 
00111         template<typename T> inline void glTexCoord(const Eigen::Matrix<T,2,1> & p) { assert(0); }
00112         template<> inline void glTexCoord(const Eigen::Matrix<int,2,1> & p)   { glTexCoord2iv((const GLint*)p.data());}
00113         template<> inline void glTexCoord(const Eigen::Matrix<short,2,1> & p) { glTexCoord2sv(p.data());}
00114         template<> inline void glTexCoord(const Eigen::Matrix<float,2,1> & p) { glTexCoord2fv(p.data());}
00115         template<> inline void glTexCoord(const Eigen::Matrix<double,2,1> & p){ glTexCoord2dv(p.data());}
00116 
00117         template<typename T> inline void glTranslate(const Eigen::Matrix<T,2,1> & p) { assert(0); }
00118         template<> inline void glTranslate(const Eigen::Matrix<float,2,1> & p) { glTranslatef(p[0],p[1],0);}
00119         template<> inline void glTranslate(const Eigen::Matrix<double,2,1> & p){ glTranslated(p[0],p[1],0);}
00120 
00121         template<typename T> inline void glScale(const Eigen::Matrix<T,2,1> & p) { assert(0); }
00122         template<> inline void glScale(const Eigen::Matrix<float,2,1> & p) { glScalef(p[0],p[1],1.f);}
00123         template<> inline void glScale(const Eigen::Matrix<double,2,1> & p){ glScaled(p[0],p[1],1.0);}
00124 
00125         template<typename T> inline void glVertex(const Eigen::Matrix<T,3,1> & p) { assert(0); }
00126         template<> inline void glVertex(const Eigen::Matrix<int,3,1> & p)   { glVertex3iv((const GLint*)p.data());}
00127         template<> inline void glVertex(const Eigen::Matrix<short,3,1> & p) { glVertex3sv(p.data());}
00128         template<> inline void glVertex(const Eigen::Matrix<float,3,1> & p) { glVertex3fv(p.data());}
00129         template<> inline void glVertex(const Eigen::Matrix<double,3,1> & p){ glVertex3dv(p.data());}
00130 
00131         template<typename T> inline void glNormal(const Eigen::Matrix<T,3,1> & p) { assert(0); }
00132         template<> inline void glNormal(const Eigen::Matrix<int,3,1> & p)   { glNormal3iv((const GLint*)p.data());}
00133         template<> inline void glNormal(const Eigen::Matrix<short,3,1> & p) { glNormal3sv(p.data());}
00134         template<> inline void glNormal(const Eigen::Matrix<float,3,1> & p) { glNormal3fv(p.data());}
00135         template<> inline void glNormal(const Eigen::Matrix<double,3,1> & p){ glNormal3dv(p.data());}
00136 
00137         template<typename T> inline void glTexCoord(const Eigen::Matrix<T,3,1> & p) { assert(0); }
00138         template<> inline void glTexCoord(const Eigen::Matrix<int,3,1> & p)   { glTexCoord3iv((const GLint*)p.data());}
00139         template<> inline void glTexCoord(const Eigen::Matrix<short,3,1> & p) { glTexCoord3sv(p.data());}
00140         template<> inline void glTexCoord(const Eigen::Matrix<float,3,1> & p) { glTexCoord3fv(p.data());}
00141         template<> inline void glTexCoord(const Eigen::Matrix<double,3,1> & p){ glTexCoord3dv(p.data());}
00142 
00143         template<typename T> inline void glTranslate(const Eigen::Matrix<T,3,1> & p) { assert(0); }
00144         template<> inline void glTranslate(const Eigen::Matrix<float,3,1> & p) { glTranslatef(p[0],p[1],p[2]);}
00145         template<> inline void glTranslate(const Eigen::Matrix<double,3,1> & p){ glTranslated(p[0],p[1],p[2]);}
00146 
00147         template<typename T> inline void glScale(const Eigen::Matrix<T,3,1> & p) { assert(0); }
00148         template<> inline void glScale(const Eigen::Matrix<float,3,1> & p) { glScalef(p[0],p[1],p[2]);}
00149         template<> inline void glScale(const Eigen::Matrix<double,3,1> & p){ glScaled(p[0],p[1],p[2]);}
00150 
00151   inline void glColor(Color4b const & c)   { glColor4ubv(c.data());}
00152   inline void glClearColor(Color4b const &c) {  ::glClearColor(float(c[0])/255.0f,float(c[1])/255.0f,float(c[2])/255.0f,1.0f);}
00153   inline void glLight(GLenum light, GLenum pname,  Color4b const & c)   {
00154     static float cf[4];
00155     cf[0]=float(cf[0]/255.0); cf[1]=float(c[1]/255.0); cf[2]=float(c[2]/255.0); cf[3]=float(c[3]/255.0);
00156     glLightfv(light,pname,cf);
00157   }
00158 
00159 
00160  template <class T>
00161    inline void glBoxWire(Box3<T> const & b)
00162 {
00163         glPushAttrib(GL_ENABLE_BIT);
00164         glDisable(GL_LIGHTING);
00165         glBegin(GL_LINE_STRIP);
00166         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00167         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00168         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00169         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00170         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00171         glEnd();
00172         glBegin(GL_LINE_STRIP);
00173         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00174         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00175         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00176         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00177         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00178         glEnd();
00179         glBegin(GL_LINES);
00180         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00181         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00182 
00183         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00184         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00185 
00186         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00187         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00188 
00189         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00190         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00191         glEnd();
00192         glPopAttrib();
00193 };
00194 template <class T>
00196 inline void glBoxFlat(Box3<T> const & b)
00197 {
00198         glPushAttrib(GL_SHADE_MODEL);
00199         glShadeModel(GL_FLAT);
00200         glBegin(GL_QUAD_STRIP);
00201         glNormal3f(.0f,.0f,1.0f);
00202         glVertex3f(b.min[0], b.max[1], b.max[2]);
00203   glVertex3f(b.min[0], b.min[1], b.max[2]);
00204         glVertex3f(b.max[0], b.max[1], b.max[2]);
00205   glVertex3f(b.max[0], b.min[1], b.max[2]);
00206         glNormal3f(1.0f,.0f,.0f);
00207         glVertex3f(b.max[0], b.max[1], b.min[2]);
00208         glVertex3f(b.max[0], b.min[1], b.min[2]);
00209   glNormal3f(.0f,.0f,-1.0f);
00210         glVertex3f(b.min[0], b.max[1], b.min[2]);
00211         glVertex3f(b.min[0], b.min[1], b.min[2]);
00212         glNormal3f(-1.0f,.0f,.0f);
00213         glVertex3f(b.min[0], b.max[1], b.max[2]);
00214         glVertex3f(b.min[0], b.min[1], b.max[2]);
00215         glEnd();
00216 
00217   glBegin(GL_QUADS);
00218         glNormal3f(.0f,1.0f,.0f);
00219         glVertex3f(b.min[0], b.max[1], b.max[2]);
00220         glVertex3f(b.max[0], b.max[1], b.max[2]);
00221         glVertex3f(b.max[0], b.max[1], b.min[2]);
00222   glVertex3f(b.min[0], b.max[1], b.min[2]);
00223 
00224         glNormal3f(.0f,-1.0f,.0f);
00225         glVertex3f(b.min[0], b.min[1], b.min[2]);
00226   glVertex3f(b.max[0], b.min[1], b.min[2]);
00227         glVertex3f(b.max[0], b.min[1], b.max[2]);
00228   glVertex3f(b.min[0], b.min[1], b.max[2]);
00229   glEnd();
00230         glPopAttrib();
00231 };
00232 
00233 
00234 template <class T>
00236 inline void glBoxClip(const Box3<T>  & b)
00237 {
00238         double eq[4];
00239         eq[0]= 1; eq[1]= 0; eq[2]= 0; eq[3]=(double)-b.min[0];
00240         glClipPlane(GL_CLIP_PLANE0,eq);
00241         eq[0]=-1; eq[1]= 0; eq[2]= 0; eq[3]=(double) b.max[0];
00242         glClipPlane(GL_CLIP_PLANE1,eq);
00243 
00244         eq[0]= 0; eq[1]= 1; eq[2]= 0; eq[3]=(double)-b.min[1];
00245         glClipPlane(GL_CLIP_PLANE2,eq);
00246         eq[0]= 0; eq[1]=-1; eq[2]= 0; eq[3]=(double) b.max[1];
00247         glClipPlane(GL_CLIP_PLANE3,eq);
00248 
00249 
00250         eq[0]= 0; eq[1]= 0; eq[2]= 1; eq[3]=(double)-b.min[2];
00251         glClipPlane(GL_CLIP_PLANE4,eq);
00252         eq[0]= 0; eq[1]= 0; eq[2]=-1; eq[3]=(double) b.max[2];
00253         glClipPlane(GL_CLIP_PLANE5,eq);
00254 }
00255  template <class T>
00256    inline void glBoxWire(const Box2<T>  & b)
00257 {
00258         glPushAttrib(GL_ENABLE_BIT);
00259         glDisable(GL_LIGHTING);
00260         glBegin(GL_LINE_LOOP);
00261 
00262   glVertex2f((float)b.min[0],(float)b.min[1]);
00263           glVertex2f((float)b.max[0],(float)b.min[1]);
00264           glVertex2f((float)b.max[0],(float)b.max[1]);
00265           glVertex2f((float)b.min[0],(float)b.max[1]);
00266   glEnd();
00267 
00268         glPopAttrib();
00269 };
00270  template <class T>
00271         inline void glPlane3( Plane3<T>   p, Point3<T>  c, T size )  {
00272                 Point3<T> w = p.Direction();
00273                 Point3<T> u,v,c1;
00274                 GetUV<T>(w,u,v);
00275 
00276                 c1 = p.Projection(c);
00277 
00278                 u.Normalize();
00279                 w.Normalize();
00280                 v.Normalize();
00281 
00282                 Matrix44<T> m;
00283           *(Point3<T>*)&m[0][0] = *(Point3<T>*)&u[0];m[0][3]=0;
00284                 *(Point3<T>*)&m[1][0] = *(Point3<T>*)&w[0];m[1][3]=0;
00285                 *(Point3<T>*)&m[2][0] = *(Point3<T>*)&v[0];m[2][3]=0;
00286                 *(Point3<T>*)&m[3][0] = *(Point3<T>*)&c1[0];m[3][3]=1;
00287 
00288                 glPushMatrix();
00289                 glMultMatrix(m.transpose());
00290 
00291                 glBegin(GL_QUADS);
00292                 glNormal(Point3<T>(0,1,0));
00293                 glVertex(Point3<T>(-size,0,-size));
00294                 glVertex(Point3<T>(size ,0,-size));
00295                 glVertex(Point3<T>(size ,0, size));
00296                 glVertex(Point3<T>(-size,0, size));
00297                 glEnd();
00298 
00299 
00300                 glPopMatrix();
00301         }
00302 
00303 
00304 template <class TriangleType>
00305         inline void glTriangle3(  TriangleType & c )  {
00306                 vcg::Point3<typename TriangleType::ScalarType> n =  vcg::Normal(c);
00307                 glBegin(GL_TRIANGLES);
00308                 glNormal(n);
00309                 glVertex(c.P(0));
00310                 glVertex(c.P(1));
00311                 glVertex(c.P(2));
00312                 glEnd();
00313         }
00314 
00315 template <class TetraType>
00316         inline void glTetra3(  TetraType & c )  {
00317                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(0),c.P(1),c.P(2)));
00318                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(1),c.P(3),c.P(2)));
00319                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(0),c.P(2),c.P(3)));
00320                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(1),c.P(0),c.P(3)));
00321         }
00322 
00323 }//namespace
00324 #endif
00325 
00326 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:36:01