shot.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 $Log: not supported by cvs2svn $
00026 Revision 1.12  2006/12/18 16:02:57  matteodelle
00027 minor eroor correction on variable names
00028 
00029 Revision 1.11  2006/12/18 15:26:24  callieri
00030 added a function to approximate a far plane value given a shot and the mesh bbox
00031 
00032 Revision 1.10  2006/12/18 14:28:07  matteodelle
00033 *** empty log message ***
00034 
00035 Revision 1.9  2006/12/18 09:46:39  callieri
00036 camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot.
00037 
00038 Revision 1.8  2006/01/11 16:06:25  matteodelle
00039 *** empty log message ***
00040 
00041 
00042 Revision 1.8  2005/01/11 17:06:30  dellepiane
00043 FromTrackball() coorected (similarity->Extrinsics
00044 
00045 Revision 1.7  2005/11/25 10:33:33  spinelli
00046 shot.camera  -> shot.Intrinsics
00047 shot.similarity.Matrix() -> shot.Extrinsics.Matrix()
00048 
00049 Revision 1.6  2005/02/22 11:15:01  ganovelli
00050 added vcg namespace
00051 
00052 Revision 1.5  2005/02/11 11:43:09  tommyfranken
00053 FromTrackball() corrected
00054 
00055 Revision 1.4  2004/12/15 18:45:06  tommyfranken
00056 *** empty log message ***
00057 
00058 Revision 1.3  2004/11/03 09:41:57  ganovelli
00059 added FromTrackball and fixed include names (Poiint to point)
00060 
00061 Revision 1.2  2004/10/05 19:04:45  ganovelli
00062 changed from classes to functions
00063 
00064 Revision 1.1  2004/09/15 22:59:13  ganovelli
00065 creation
00066 
00067 Revision 1.2  2004/09/06 21:41:30  ganovelli
00068 *** empty log message ***
00069 
00070 Revision 1.1  2004/09/03 13:01:51  ganovelli
00071 creation
00072 
00073 ****************************************************************************/
00074 
00075 
00076 #ifndef __VCGLIB_GLSHOT
00077 #define __VCGLIB_GLSHOT
00078 
00079 // include vcg stuff
00080 #include <vcg/space/point2.h>
00081 #include <vcg/space/point3.h>
00082 #include <vcg/math/similarity.h>
00083 
00084 #include <vcg/math/shot.h>
00085 
00086 // include wrap stuff
00087 #include <wrap/gui/trackball.h>
00088 #include <wrap/gl/math.h>
00089 #include <wrap/gl/camera.h>
00090 
00091 template <class ShotType>
00092 struct GlShot {
00093 
00094         typedef typename ShotType::ScalarType ScalarType;
00095         typedef GlCamera<typename ShotType::CameraType> GlCameraType;
00096 
00098 static void MatrixGL(ShotType & shot,vcg::Matrix44<ScalarType> & m) 
00099 {
00100         m = shot.GetWorldToExtrinsicsMatrix();
00101 }
00102 
00104 static void TransformGL(vcg::Shot<ScalarType> & shot)
00105 {
00106         vcg::Matrix44<ScalarType> m;
00107         MatrixGL(shot,m);
00108         glMultMatrix(m);
00109 }
00110 
00112 static void SetView(vcg::Shot<ScalarType> & shot, ScalarType nearDist, ScalarType farDist)
00113 {
00114         assert(glGetError() == 0);
00115         glMatrixMode(GL_PROJECTION);
00116         glPushMatrix();
00117         glLoadIdentity();
00118 
00119         assert(glGetError() == 0);
00120         GlCameraType::TransformGL(shot.Intrinsics, nearDist, farDist); // apply camera/projection transformation
00121         assert(glGetError() == 0);
00122 
00123         glMatrixMode(GL_MODELVIEW);
00124         glPushMatrix();
00125         glLoadIdentity();
00126 
00127         GlShot<ShotType>::TransformGL(shot);    // apply similarity/modelview transformation
00128         assert(glGetError() == 0);
00129 }
00130 
00132 static void     UnsetView()
00133 {
00134         glPushAttrib(GL_TRANSFORM_BIT);
00135         glMatrixMode(GL_MODELVIEW);
00136         glPopMatrix();
00137         glMatrixMode(GL_PROJECTION);
00138         glPopMatrix();
00139         glPopAttrib();
00140 }
00141 
00144 static ScalarType GetFarPlane(vcg::Shot<ScalarType> & shot, vcg::Box3<ScalarType> bbox)
00145 {
00146         ScalarType farDist;
00147 
00148         vcg::Point3<ScalarType> farcorner;
00149     vcg::Point3<ScalarType> campos = shot.Extrinsics.Tra();
00150          
00151          if (abs(campos.X() - bbox.max.X()) > abs(campos.X() - bbox.min.X()))
00152                  farcorner.X() = bbox.max.X();
00153          else
00154                  farcorner.X() = bbox.min.X();
00155 
00156          if (abs(campos.Y() - bbox.max.Y()) > abs(campos.Y() - bbox.min.Y()))
00157                  farcorner.Y() = bbox.max.Y();
00158          else
00159                  farcorner.Y() = bbox.min.Y();
00160 
00161          if (abs(campos.Z() - bbox.max.Z()) > abs(campos.Z() - bbox.min.Z()))
00162                  farcorner.Z() = bbox.max.Z();
00163          else
00164                  farcorner.Z() = bbox.min.Z();
00165 
00166          farDist = (campos - farcorner).Norm();
00167 
00168         return farDist;
00169 }
00170 
00171 
00173 static void GetNearFarPlanes(vcg::Shot<ScalarType> & shot, vcg::Box3<ScalarType> bbox, ScalarType &nr, ScalarType &fr)
00174 {
00175   vcg::Point3<ScalarType> zaxis = shot.Axis(2); 
00176   ScalarType offset = zaxis * shot.GetViewPoint();
00177   bool first = true;
00178   for(int i = 0; i < 8; i++) {
00179     vcg::Point3<ScalarType> c = bbox.P(i);
00180     ScalarType d = -(zaxis * c - offset);
00181     if(first || d < nr)  
00182       nr = d;
00183     if(first || d > fr)   
00184       fr = d;
00185     first = false;
00186   }
00187 }
00188 
00189 
00190 
00191 static void SetSubView(vcg::Shot<ScalarType> & shot,
00192                                            vcg::Point2<ScalarType> p1,
00193                                            vcg::Point2<ScalarType> p2)
00194 {
00195         glMatrixMode(GL_PROJECTION);
00196         glPushMatrix();
00197         glLoadIdentity();
00198         assert(glGetError() == 0);
00199         GlCameraType::SetSubView(shot.Intrinsics,p1,0,1000,p2);
00200         assert(glGetError() == 0);
00201         glMatrixMode(GL_MODELVIEW);
00202         glPushMatrix();
00203         glLoadIdentity();
00204         GlShot<ShotType>::TransformGL(shot);                                                    // apply similarity/modelview transformation
00205         assert(glGetError() == 0);
00206 }
00207 
00208 
00209         
00210 /**********************************
00211 DEFINE SHOT FROM TRACKBALL
00212 Adds to a given shot the trackball transformations.
00213 After this operation the trackball should be resetted, to avoid
00214 multiple apply of the same transformation.
00215 ***********************************/
00216 static void FromTrackball(const vcg::Trackball & tr, 
00217                                                   vcg::Shot<ScalarType> & sShot, 
00218                                                   vcg::Shot<ScalarType> & shot )
00219 {
00220         vcg::Point3<ScalarType>         cen; cen.Import(tr.center);
00221         vcg::Point3<ScalarType>         tra; tra.Import(tr.track.tra);
00222         vcg::Matrix44<ScalarType>       trM; trM.FromMatrix(tr.track.Matrix());
00223 
00224         vcg::Point3<ScalarType>         vp = Inverse(trM)*(sShot.GetViewPoint()-cen) +cen;// +tra;
00225 
00226         shot.SetViewPoint(vp);
00227         shot.Extrinsics.SetRot(sShot.Extrinsics.Rot()*trM);
00228 //      shot.Extrinsics.sca     =       sShot.Extrinsics.sca*(ScalarType)tr.track.sca;
00229 }
00230 };
00231 #endif
00232 
00233 
00234 
00235 
00236 


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