BackFaceCullingOptimizer.cpp
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 #include <vector>
00046 #include "VRender.h"
00047 #include "Optimizer.h"
00048 #include "Primitive.h"
00049 
00050 using namespace std ;
00051 using namespace vrender ;
00052 
00053 // Over-simplified algorithm to check wether a polygon is front-facing or not.
00054 // Only works for convex polygons.
00055 
00056 void BackFaceCullingOptimizer::optimize(std::vector<PtrPrimitive>& primitives_tab,VRenderParams&)
00057 {
00058         Polygone *P ;
00059         int nb_culled = 0 ;
00060 
00061         for(unsigned int i=0;i<primitives_tab.size();++i)
00062                 if((P = dynamic_cast<Polygone *>(primitives_tab[i])) != NULL)
00063                 {
00064                         for(unsigned int j=0;j<P->nbVertices();++j)
00065                                 if(( (P->vertex(j+2) - P->vertex(j+1))^(P->vertex(j+1) - P->vertex(j))).z() > 0.0 )
00066                                 {
00067                                         delete primitives_tab[i] ;
00068                                         primitives_tab[i] = NULL ;
00069                                         ++nb_culled ;
00070                                         break ;
00071                                 }
00072                 }
00073 
00074         // Rule out gaps. This avoids testing for null primitives later.
00075 
00076         int j=0 ;
00077         for(unsigned int k=0;k<primitives_tab.size();++k)
00078                 if(primitives_tab[k] != NULL)
00079                         primitives_tab[j++] = primitives_tab[k] ;
00080 
00081         primitives_tab.resize(j) ;
00082 #ifdef DEBUG_BFC
00083         cout << "Backface culling: " << nb_culled << " polygons culled." << endl ;
00084 #endif
00085 }


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:19