CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/GeometrySurface/interface/Plane.h

Go to the documentation of this file.
00001 #ifndef Geom_Plane_H
00002 #define Geom_Plane_H
00003 
00014 #include "DataFormats/GeometrySurface/interface/Surface.h"
00015 #include "boost/intrusive_ptr.hpp" 
00016 
00017 class Plane : public Surface {
00018 public:
00019 #ifndef CMS_NOCXX11
00020  template<typename... Args>
00021   Plane(Args&& ... args) :
00022     Surface(std::forward<Args>(args)...){setPosPrec();computeSpan();}
00023 #endif  
00024 
00025   typedef ReferenceCountingPointer<Plane> PlanePointer;
00026   typedef ConstReferenceCountingPointer<Plane> ConstPlanePointer;
00027   typedef ReferenceCountingPointer<Plane> BoundPlanePointer;
00028   typedef ConstReferenceCountingPointer<Plane> ConstBoundPlanePointer;
00029 
00030 
00031 #ifndef CMS_NOCXX11
00032 
00033 
00034 
00035  template<typename... Args>
00036   static PlanePointer build(Args&& ... args) {
00037     return PlanePointer(new Plane(std::forward<Args>(args)...));
00038   }
00039 #endif
00040  
00041   ~Plane(){}
00042 
00043 // extension of Surface interface for planes
00044 
00045   GlobalVector normalVector() const { return GlobalVector(rotation().z()); }
00046 
00049   float localZ (const GlobalPoint& gp) const {
00050     return normalVector().dot(gp-position());
00051   }
00052 
00053 #ifndef CMS_NOCXX11
00054   float localZclamped (const GlobalPoint& gp) const {
00055     auto d = localZ(gp);
00056     return std::abs(d) > posPrec() ? d : 0; 
00057   }
00058 #endif
00059 
00061   float localZ (const GlobalVector& gv) const {
00062     return normalVector().dot(gv);
00063   }
00064 
00065   // precision on position
00066   float posPrec() const { return m_posPrec;}
00067 
00068   void computeSpan() { if(theBounds) theBounds->computeSpan(*this);}
00069 
00070 
00071 // implementation of Surface interface    
00072 
00073   virtual SurfaceOrientation::Side side( const LocalPoint& p, Scalar toler) const GCC11_FINAL {
00074     return (std::abs(p.z())<toler) ? SurfaceOrientation::onSurface : 
00075         (p.z()>0 ? SurfaceOrientation::positiveSide : SurfaceOrientation::negativeSide);
00076   }
00077 
00078   virtual SurfaceOrientation::Side side( const GlobalPoint& p, Scalar toler) const GCC11_FINAL {
00079     Scalar lz = localZ(p);
00080     return (std::abs(lz)<toler ? SurfaceOrientation::onSurface : 
00081             (lz>0 ? SurfaceOrientation::positiveSide : SurfaceOrientation::negativeSide));
00082   }
00083 
00085   virtual ReferenceCountingPointer<TangentPlane> tangentPlane (const GlobalPoint&) const GCC11_FINAL;
00086 
00088   virtual ReferenceCountingPointer<TangentPlane> tangentPlane (const LocalPoint&) const GCC11_FINAL;
00089 
00090 private:
00091   void setPosPrec() {
00092 #ifndef CMS_NOCXX11
00093     constexpr auto maxf = std::numeric_limits<float>::max();
00094     auto p = position();
00095     float l = std::max(std::max(std::abs(p.x()),std::abs(p.y())),std::abs(p.z()));
00096     m_posPrec = std::abs(l-::nextafterf(l,maxf));  //  LSB  (can be multiplied by 4 or divided by 4 for safety depending on usage)
00097 #endif
00098   }
00099 
00100   Scalar m_posPrec; // the precision on the actual global position
00101 
00102 };
00103 #ifndef CMS_NOCXX11
00104 using BoundPlane = Plane;
00105 #endif
00106 
00107 #endif