Skip to content
Snippets Groups Projects
Commit abbbccd4 authored by Frank Gaede's avatar Frank Gaede
Browse files

- fixed issue with SurfaceType and setting properties

parent e1f3b7a7
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "DDSurfaces/Vector3D.h" #include "DDSurfaces/Vector3D.h"
#include <bitset> #include <bitset>
#include <math.h>
namespace DDSurfaces { namespace DDSurfaces {
...@@ -25,7 +26,7 @@ namespace DDSurfaces { ...@@ -25,7 +26,7 @@ namespace DDSurfaces {
virtual ~ISurface() {} virtual ~ISurface() {}
/// properties of the surface encoded in Type. /// properties of the surface encoded in Type.
virtual SurfaceType type() const =0 ; virtual const SurfaceType& type() const =0 ;
/// Checks if the given point lies within the surface /// Checks if the given point lies within the surface
virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const =0 ; virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const =0 ;
...@@ -67,8 +68,9 @@ namespace DDSurfaces { ...@@ -67,8 +68,9 @@ namespace DDSurfaces {
* @version $Id: $ * @version $Id: $
* @date Apr 6 2014 * @date Apr 6 2014
*/ */
struct SurfaceType{ class SurfaceType{
public:
/// enum for defining the bits used to decode the properties /// enum for defining the bits used to decode the properties
enum{ enum{
Cylinder = 1, Cylinder = 1,
...@@ -109,7 +111,7 @@ namespace DDSurfaces { ...@@ -109,7 +111,7 @@ namespace DDSurfaces {
} }
/// set the given peorperty /// set the given peorperty
void setProperty( unsigned prop ) { _bits.set( prop ) ; } void setProperty( unsigned prop , bool val = true ) { _bits.set( prop , val ) ; }
/// true if surface is sensitive /// true if surface is sensitive
bool isSensitive() const { return _bits[ SurfaceType::Sensitive ] ; } bool isSensitive() const { return _bits[ SurfaceType::Sensitive ] ; }
...@@ -133,7 +135,8 @@ namespace DDSurfaces { ...@@ -133,7 +135,8 @@ namespace DDSurfaces {
bool isZCylinder() const { return ( _bits[ SurfaceType::Cylinder ] && _bits[ SurfaceType::ParallelToZ ] ) ; } bool isZCylinder() const { return ( _bits[ SurfaceType::Cylinder ] && _bits[ SurfaceType::ParallelToZ ] ) ; }
/// true if this is a plane parallel to Z /// true if this is a plane parallel to Z
bool isZPlane() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::ParallelToZ ] ) ; } bool isZPlane() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::ParallelToZ ] ) ;
}
/// true if this is a plane orthogonal to Z /// true if this is a plane orthogonal to Z
bool isZDisk() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::OrthogonalToZ ] ) ; } bool isZDisk() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::OrthogonalToZ ] ) ; }
...@@ -142,23 +145,35 @@ namespace DDSurfaces { ...@@ -142,23 +145,35 @@ namespace DDSurfaces {
/** True if surface is parallel to Z with accuracy epsilon - result is cached in bit SurfaceType::ParallelToZ */ /** True if surface is parallel to Z with accuracy epsilon - result is cached in bit SurfaceType::ParallelToZ */
bool checkParallelToZ( const ISurface& surf , double epsilon=1.e-6 ) const { bool checkParallelToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
double proj = std::abs( surf.normal() * Vector3D(0.,0.,1.) ) ; double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
_bits.set( SurfaceType::ParallelToZ , ( std::abs( proj - 1. ) < epsilon ) ) ; _bits.set( SurfaceType::ParallelToZ , ( proj < epsilon ) ) ;
// std::cout << " ** checkParallelToZ() - normal : " << surf.normal() << " pojection : " << proj
// << " _bits[ SurfaceType::ParallelToZ ] = " << bool( _bits[ SurfaceType::ParallelToZ ] )
// << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( proj < epsilon ) << std::endl ;
return _bits[ SurfaceType::ParallelToZ ] ; return _bits[ SurfaceType::ParallelToZ ] ;
} }
/** True if surface is orthogonal to Z with accuracy epsilon - result is cached in bit SurfaceType::OrthogonalToZ */ /** True if surface is orthogonal to Z with accuracy epsilon - result is cached in bit SurfaceType::OrthogonalToZ */
bool checkOrthogonalToZ( const ISurface& surf , double epsilon=1.e-6 ) const { bool checkOrthogonalToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
double proj = std::abs( surf.normal() * Vector3D(0.,0.,1.) ) ; double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
_bits.set( SurfaceType::OrthogonalToZ , ( proj < epsilon ) ) ; _bits.set( SurfaceType::OrthogonalToZ , ( std::fabs( proj - 1. ) < epsilon ) ) ;
// std::cout << " ** checkOrthogonalToZ() - normal : " << surf.normal() << " pojection : " << proj
// << " _bits[ SurfaceType::OrthogonalToZ ] = " << bool( _bits[ SurfaceType::OrthogonalToZ ] )
// << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( std::fabs( proj - 1. ) < epsilon ) << std::endl ;
return _bits[ SurfaceType::OrthogonalToZ ] ; return _bits[ SurfaceType::OrthogonalToZ ] ;
} }
protected:
mutable std::bitset<32> _bits ; mutable std::bitset<32> _bits ;
} ; } ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment