plane3.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 #ifndef VCG_PLANE3_H
00025 #define VCG_PLANE3_H
00026 
00027 #include <vcg/space/point3.h>
00028 
00029 namespace vcg {
00030 
00047 template <class T, bool NORM=true> class Plane3 {
00048 public: 
00049   typedef T ScalarType;
00050         typedef Point3<T> PointType;
00051 
00052 private:
00054   ScalarType _offset;
00056   PointType _dir;
00057 
00058 public:
00060 
00062 
00063   Plane3() {}
00065   Plane3(const ScalarType &dist, const PointType &dir) { Set(dist, dir); }
00066 
00067         template <class Q>
00068         inline void Import( const Plane3<Q,false> & b )
00069         {
00070                 _offset = ScalarType(b.Offset());
00071                 _dir = Point3<T>::Construct(b.Direction());
00072         }
00073 
00075 
00080   const ScalarType &Offset() const { return _offset; } 
00081   ScalarType &Offset() { return _offset; } 
00083         void SetOffset( const ScalarType &o ) { _offset=o; }
00084         
00085   const PointType &Direction() const { return _dir; } 
00087         void SetDirection( const PointType & dir)       {       
00088     _dir=dir; 
00089     if (NORM) _dir.Normalize();  
00090   }
00092         void Set( const ScalarType & off, const PointType & dir ) {
00093                 if (NORM) {
00094                         const ScalarType normFactor = dir.Norm();
00095                         this->_dir = dir / normFactor;
00096                         this->_offset = off / normFactor;
00097                 }
00098                 else {
00099                         this->_offset = off;
00100                         this->_dir = dir;
00101                 }
00102   }
00103   void Set( const PointType & dir, const ScalarType & off) {Set(off,dir);}
00104         
00106         bool operator==(Plane3 const &p) const  {       
00107     return _offset == p._offset && _dir == p._dir; 
00108   }
00110         bool operator!=(Plane3 const &p) const  {       
00111     return _offset != p._offset || _dir != p._dir; 
00112   }
00113         
00115   PointType Projection(const PointType &p) const        {
00116                 ScalarType k = p.dot(_dir) - _offset;
00117                 return p - _dir * k;
00118         }
00119 
00121   PointType Mirror(const PointType &p) const    {
00122      PointType mirr=Projection(p);
00123      mirr+=mirr-p;
00124      return mirr;
00125   }
00126 
00128   void Normalize() {
00129           _dir.Normalize();
00130   }
00131 
00133   void Init(const PointType &p0, const PointType &p1, const PointType &p2) {
00134     _dir = (p2 - p0) ^ (p1 - p0);
00135     if(NORM) Normalize();
00136     _offset = p0.dot(_dir);
00137   }
00138 
00140   inline void Init(const PointType &p0, const PointType &norm) {
00141           _dir = norm;
00142           if(NORM) Normalize();
00143           _offset = p0.dot(_dir);
00144   }
00145 };      // end class Plane3
00146 
00147 typedef Plane3<float>  Plane3f;
00148 typedef Plane3<double> Plane3d;
00149 
00151 template<class T> T SignedDistancePlanePoint(const Plane3<T,true> & plane, const Point3<T> & point)
00152 {
00153         return plane.Direction().dot(point) - plane.Offset();
00154 }
00155 
00156 
00157 template<class T> T SignedDistancePointPlane(const Point3<T> & point, const Plane3<T,true> & plane)
00158 {
00159         return SignedDistancePlanePoint(plane, point);
00160 }
00161 
00162 } // end namespace
00163 
00164 
00165 #endif


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