NormalConeT.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS NormalConeT - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 #define ACG_NORMALCONE_C
00053 
00054 //== INCLUDES =================================================================
00055 
00056 #include <math.h>
00057 #include "NormalConeT.hh"
00058 
00059 #ifdef max
00060 #  undef max
00061 #endif
00062 
00063 #ifdef min
00064 #  undef min
00065 #endif
00066 
00067 
00068 //== NAMESPACES ===============================================================
00069 
00070 
00071 namespace ACG {
00072 namespace Geometry {
00073 
00074 
00075 //== IMPLEMENTATION ========================================================== 
00076 
00077 template <typename Scalar>
00078 NormalConeT<Scalar>::
00079 NormalConeT(const Vec3& _center_normal, Scalar _angle)
00080   : center_normal_(_center_normal), angle_(_angle)
00081 {
00082 }
00083 
00084 
00085 //----------------------------------------------------------------------------
00086 
00087 
00088 template <typename Scalar>
00089 Scalar 
00090 NormalConeT<Scalar>::
00091 max_angle(const Vec3& _norm) const
00092 {
00093   Scalar dotp = (center_normal_ | _norm);
00094   return (dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp)))
00095     + angle_;
00096 }
00097 
00098 
00099 //----------------------------------------------------------------------------
00100 
00101 
00102 template <typename Scalar>
00103 Scalar 
00104 NormalConeT<Scalar>::
00105 max_angle(const NormalConeT& _cone) const
00106 {
00107   Scalar dotp = (center_normal_ | _cone.center_normal_);
00108   Scalar centerAngle = dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp));
00109   Scalar sideAngle0 = std::max(angle_-centerAngle, _cone.angle_);
00110   Scalar sideAngle1 = std::max(_cone.angle_-centerAngle, angle_);
00111 
00112   return centerAngle + sideAngle0 + sideAngle1;
00113 }
00114 
00115 
00116 //----------------------------------------------------------------------------
00117 
00118 
00119 template <typename Scalar>
00120 void 
00121 NormalConeT<Scalar>::
00122 merge(const NormalConeT& _cone)
00123 {
00124   Scalar dotp = (center_normal_ | _cone.center_normal_);
00125 
00126   if (fabs(dotp) < 0.99999)
00127   {
00128     // new angle
00129     Scalar centerAngle = acos(dotp);
00130     Scalar minAngle    = std::min(-angle(), centerAngle - _cone.angle());
00131     Scalar maxAngle    = std::max( angle(), centerAngle + _cone.angle());
00132     angle_     = 0.5 * (maxAngle - minAngle);
00133 
00134     // axis by SLERP
00135     Scalar axisAngle = 0.5*(minAngle + maxAngle);
00136     center_normal_ = ((center_normal_ * sin(centerAngle-axisAngle)
00137                        + _cone.center_normal_ * sin(axisAngle))
00138                        / sin(centerAngle));
00139   }
00140   else
00141   {
00142     // axes point in same direction
00143     if (dotp > 0.0)
00144       angle_ = std::max(angle_, _cone.angle_);
00145 
00146     // axes point in opposite directions
00147     else
00148       angle_ = 2*M_PI;
00149   }
00150 }
00151 
00152 
00153 //=============================================================================
00154 } // namespace Geometry
00155 } // namespace ACG
00156 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .