deprecated_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_GL_SPACE_H
00061 #define VCG_GL_SPACE_H
00062 
00063 // Please note that this file assume that you have already included your
00064 // gl-extension wrapping utility, and that therefore all the extension symbol are already defined.
00065 
00066 #include <vcg/space/triangle3.h>
00067 #include <vcg/space/plane3.h>
00068 #include <vcg/space/point2.h>
00069 #include <vcg/space/point3.h>
00070 #include <vcg/space/color4.h>
00071 #include <vcg/space/box2.h>
00072 #include <vcg/space/box3.h>
00073 
00074 namespace vcg {
00075 
00076         inline void glScale(float const & p){ glScalef(p,p,p);}
00077         inline void glScale(double const & p){ glScaled(p,p,p);}
00078 
00079         inline void glVertex(Point2<int> const & p)   { glVertex2iv((const GLint*)p.V());}
00080         inline void glVertex(Point2<short> const & p) { glVertex2sv(p.V());}
00081         inline void glVertex(Point2<float> const & p) { glVertex2fv(p.V());}
00082         inline void glVertex(Point2<double> const & p){ glVertex2dv(p.V());}
00083         inline void glTexCoord(Point2<int> const & p)   { glTexCoord2iv((const GLint*)p.V());}
00084         inline void glTexCoord(Point2<short> const & p) { glTexCoord2sv(p.V());}
00085         inline void glTexCoord(Point2<float> const & p) { glTexCoord2fv(p.V());}
00086         inline void glTexCoord(Point2<double> const & p){ glTexCoord2dv(p.V());}
00087         inline void glTranslate(Point2<float> const & p) { glTranslatef(p[0],p[1],0);}
00088         inline void glTranslate(Point2<double> const & p){ glTranslated(p[0],p[1],0);}
00089         inline void glScale(Point2<float> const & p) { glScalef(p[0],p[1],1.0);}
00090         inline void glScale(Point2<double> const & p){ glScaled(p[0],p[1],1.0);}
00091 
00092   inline void glVertex(Point3<int> const & p)   { glVertex3iv((const GLint*)p.V());}
00093         inline void glVertex(Point3<short> const & p) { glVertex3sv(p.V());}
00094         inline void glVertex(Point3<float> const & p) { glVertex3fv(p.V());}
00095         inline void glVertex(Point3<double> const & p){ glVertex3dv(p.V());}
00096         inline void glNormal(Point3<int> const & p)   { glNormal3iv((const GLint*)p.V());}
00097         inline void glNormal(Point3<short> const & p) { glNormal3sv(p.V());}
00098         inline void glNormal(Point3<float> const & p) { glNormal3fv(p.V());}
00099         inline void glNormal(Point3<double> const & p){ glNormal3dv(p.V());}
00100         inline void glTexCoord(Point3<int> const & p)   { glTexCoord3iv((const GLint*)p.V());}
00101         inline void glTexCoord(Point3<short> const & p) { glTexCoord3sv(p.V());}
00102         inline void glTexCoord(Point3<float> const & p) { glTexCoord3fv(p.V());}
00103         inline void glTexCoord(Point3<double> const & p){ glTexCoord3dv(p.V());}
00104         inline void glTranslate(Point3<float> const & p) { glTranslatef(p[0],p[1],p[2]);}
00105         inline void glTranslate(Point3<double> const & p){ glTranslated(p[0],p[1],p[2]);}
00106         inline void glScale(Point3<float> const & p) { glScalef(p[0],p[1],p[2]);}
00107         inline void glScale(Point3<double> const & p){ glScaled(p[0],p[1],p[2]);}
00108 
00109   inline void glColor(Color4b const & c)   { glColor4ubv(c.V());}
00110   inline void glColor(Color4f const & c)   { glColor4fv (c.V());}
00111   inline void glColor(Color4d const & c)   { glColor4dv (c.V());}
00112   inline void glClearColor(Color4b const &c) { ::glClearColor(float(c[0])/255.0f,float(c[1])/255.0f,float(c[2])/255.0f,1.0f);}
00113   inline void glClearColor(Color4f const &c) { ::glClearColor(c[0],c[1],c[2],c[3]); }
00114   inline void glClearColor(Color4d const &c) { ::glClearColor(float(c[0]),float(c[1]),float(c[2]),float(c[3])); }
00115   inline void glLight(GLenum light, GLenum pname,  Color4b const & c) {
00116     static float cf[4];
00117     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);
00118     glLightfv(light,pname,cf);
00119   }
00120 
00121 
00122  template <class T>
00123    inline void glBoxWire(Box3<T> const & b)
00124 {
00125         glPushAttrib(GL_ENABLE_BIT);
00126         glDisable(GL_LIGHTING);
00127         glBegin(GL_LINE_STRIP);
00128         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00129         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00130         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00131         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00132         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00133         glEnd();
00134         glBegin(GL_LINE_STRIP);
00135         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00136         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00137         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00138         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00139         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00140         glEnd();
00141         glBegin(GL_LINES);
00142         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.min[2]);
00143         glVertex3f((float)b.min[0],(float)b.min[1],(float)b.max[2]);
00144 
00145         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.min[2]);
00146         glVertex3f((float)b.max[0],(float)b.min[1],(float)b.max[2]);
00147 
00148         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.min[2]);
00149         glVertex3f((float)b.max[0],(float)b.max[1],(float)b.max[2]);
00150 
00151         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.min[2]);
00152         glVertex3f((float)b.min[0],(float)b.max[1],(float)b.max[2]);
00153         glEnd();
00154         glPopAttrib();
00155 };
00156 template <class T>
00158 inline void glBoxFlat(Box3<T> const & b)
00159 {
00160         glPushAttrib(GL_SHADE_MODEL);
00161         glShadeModel(GL_FLAT);
00162         glBegin(GL_QUAD_STRIP);
00163         glNormal3f(.0f,.0f,1.0f);
00164         glVertex3f(b.min[0], b.max[1], b.max[2]);
00165   glVertex3f(b.min[0], b.min[1], b.max[2]);
00166         glVertex3f(b.max[0], b.max[1], b.max[2]);
00167   glVertex3f(b.max[0], b.min[1], b.max[2]);
00168         glNormal3f(1.0f,.0f,.0f);
00169         glVertex3f(b.max[0], b.max[1], b.min[2]);
00170         glVertex3f(b.max[0], b.min[1], b.min[2]);
00171   glNormal3f(.0f,.0f,-1.0f);
00172         glVertex3f(b.min[0], b.max[1], b.min[2]);
00173         glVertex3f(b.min[0], b.min[1], b.min[2]);
00174         glNormal3f(-1.0f,.0f,.0f);
00175         glVertex3f(b.min[0], b.max[1], b.max[2]);
00176         glVertex3f(b.min[0], b.min[1], b.max[2]);
00177         glEnd();
00178 
00179   glBegin(GL_QUADS);
00180         glNormal3f(.0f,1.0f,.0f);
00181         glVertex3f(b.min[0], b.max[1], b.max[2]);
00182         glVertex3f(b.max[0], b.max[1], b.max[2]);
00183         glVertex3f(b.max[0], b.max[1], b.min[2]);
00184   glVertex3f(b.min[0], b.max[1], b.min[2]);
00185 
00186         glNormal3f(.0f,-1.0f,.0f);
00187         glVertex3f(b.min[0], b.min[1], b.min[2]);
00188   glVertex3f(b.max[0], b.min[1], b.min[2]);
00189         glVertex3f(b.max[0], b.min[1], b.max[2]);
00190   glVertex3f(b.min[0], b.min[1], b.max[2]);
00191   glEnd();
00192         glPopAttrib();
00193 };
00194 
00195 
00196 template <class T>
00198 inline void glBoxClip(const Box3<T>  & b)
00199 {
00200         double eq[4];
00201         eq[0]= 1; eq[1]= 0; eq[2]= 0; eq[3]=(double)-b.min[0];
00202         glClipPlane(GL_CLIP_PLANE0,eq);
00203         eq[0]=-1; eq[1]= 0; eq[2]= 0; eq[3]=(double) b.max[0];
00204         glClipPlane(GL_CLIP_PLANE1,eq);
00205 
00206         eq[0]= 0; eq[1]= 1; eq[2]= 0; eq[3]=(double)-b.min[1];
00207         glClipPlane(GL_CLIP_PLANE2,eq);
00208         eq[0]= 0; eq[1]=-1; eq[2]= 0; eq[3]=(double) b.max[1];
00209         glClipPlane(GL_CLIP_PLANE3,eq);
00210 
00211 
00212         eq[0]= 0; eq[1]= 0; eq[2]= 1; eq[3]=(double)-b.min[2];
00213         glClipPlane(GL_CLIP_PLANE4,eq);
00214         eq[0]= 0; eq[1]= 0; eq[2]=-1; eq[3]=(double) b.max[2];
00215         glClipPlane(GL_CLIP_PLANE5,eq);
00216 }
00217  template <class T>
00218    inline void glBoxWire(const Box2<T>  & b)
00219 {
00220         glPushAttrib(GL_ENABLE_BIT);
00221         glDisable(GL_LIGHTING);
00222         glBegin(GL_LINE_LOOP);
00223 
00224   glVertex2f((float)b.min[0],(float)b.min[1]);
00225           glVertex2f((float)b.max[0],(float)b.min[1]);
00226           glVertex2f((float)b.max[0],(float)b.max[1]);
00227           glVertex2f((float)b.min[0],(float)b.max[1]);
00228   glEnd();
00229 
00230         glPopAttrib();
00231 };
00232  template <class T>
00233         inline void glPlane3( Plane3<T>   p, Point3<T>  c, T size )  {
00234                 Point3<T> w = p.Direction();
00235                 Point3<T> u,v,c1;
00236                 GetUV<T>(w,u,v);
00237 
00238                 c1 = p.Projection(c);
00239 
00240                 u.Normalize();
00241                 w.Normalize();
00242                 v.Normalize();
00243 
00244                 Matrix44<T> m;
00245           *(Point3<T>*)&m[0][0] = *(Point3<T>*)&u[0];m[0][3]=0;
00246                 *(Point3<T>*)&m[1][0] = *(Point3<T>*)&w[0];m[1][3]=0;
00247                 *(Point3<T>*)&m[2][0] = *(Point3<T>*)&v[0];m[2][3]=0;
00248                 *(Point3<T>*)&m[3][0] = *(Point3<T>*)&c1[0];m[3][3]=1;
00249 
00250                 glPushMatrix();
00251                 glMultMatrix(m.transpose());
00252 
00253                 glBegin(GL_QUADS);
00254                 glNormal(Point3<T>(0,1,0));
00255                 glVertex(Point3<T>(-size,0,-size));
00256                 glVertex(Point3<T>(size ,0,-size));
00257                 glVertex(Point3<T>(size ,0, size));
00258                 glVertex(Point3<T>(-size,0, size));
00259                 glEnd();
00260 
00261 
00262                 glPopMatrix();
00263         }
00264 
00265 
00266 template <class TriangleType>
00267         inline void glTriangle3(  TriangleType & c )  {
00268                 vcg::Point3<typename TriangleType::ScalarType> n =  vcg::Normal(c);
00269                 glBegin(GL_TRIANGLES);
00270                 glNormal(n);
00271                 glVertex(c.P(0));
00272                 glVertex(c.P(1));
00273                 glVertex(c.P(2));
00274                 glEnd();
00275         }
00276 
00277 template <class TetraType>
00278         inline void glTetra3(  TetraType & c )  {
00279                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(0),c.P(1),c.P(2)));
00280                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(1),c.P(3),c.P(2)));
00281                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(0),c.P(2),c.P(3)));
00282                 glTriangle3(Triangle3<typename TetraType::ScalarType>(c.P(1),c.P(0),c.P(3)));
00283         }
00284 
00285 #ifdef VCG_USE_EIGEN
00286 
00287 template<typename Derived, int Rows=Derived::RowsAtCompileTime, int Cols=Derived::ColsAtCompileTime>
00288 struct EvalToKnownPointType;
00289 
00290 template<typename Derived> struct EvalToKnownPointType<Derived,2,1>
00291 { typedef Point2<typename Derived::Scalar> Type; };
00292 
00293 template<typename Derived> struct EvalToKnownPointType<Derived,3,1>
00294 { typedef Point3<typename Derived::Scalar> Type; };
00295 
00296 template<typename Derived> struct EvalToKnownPointType<Derived,4,1>
00297 { typedef Point4<typename Derived::Scalar> Type; };
00298 
00299 #define _WRAP_EIGEN_XPR(FUNC) template<typename Derived>  \
00300         inline void FUNC(const Eigen::MatrixBase<Derived>& p) { \
00301                 FUNC(typename EvalToKnownPointType<Derived>::Type(p)); }
00302 
00303 _WRAP_EIGEN_XPR(glVertex)
00304 _WRAP_EIGEN_XPR(glNormal)
00305 _WRAP_EIGEN_XPR(glTexCoord)
00306 _WRAP_EIGEN_XPR(glTranslate)
00307 _WRAP_EIGEN_XPR(glScale)
00308 
00309 #endif
00310 
00311 }//namespace
00312 #endif


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