// SurfTest.h #ifndef SurfTest_H #define SurfTest_H // SurfTest is a dummy concrete subclass for testing the abstract // class Surface. // // It serves as a template for constructing pure and bound surface // implementations. Note however that the methods are chosen to // simplify testing not to provide behavior characteristic of a real // surface. See trfcyl/SurfCylinder for abetter example of a Surface // subclass. // // SurfTest has two constructors: one from the x-coordinate and one // the full SpacePath. // // We arbitrarily define the direction to be forward if x > 0. #include "Surface.h" #include #include "spacegeom/SpacePath.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "CrossStat.h" #include "TrackVector.h" using trf::Surface; using trf::TrackVector; using trf::CrossStat; using trf::VTrack; using trf::ETrack; class SurfTest; ObjPtr create_SurfTest(const ObjData& data); ObjPtr create_BSurfTest(const ObjData& data); //********************************************************************** // Pure surface class SurfTest : public Surface { protected: // attributes // Here the surface position and orientation are assumed to be // characterized by a single number. A more complicated surface // might use more parameters or might define a space vector. double _x; // SpacePath for testing SurfDCA. SpacePath _spth; private: // methods // output stream void ostr( ostream& stream ) const { stream << begin_object; stream << "Test surface with parameter " << _x << "."; stream << end_object; } // equality comparing two pure surfaces bool safe_pure_equal(const Surface& srf) const { return _x == ((SurfTest&) srf)._x; } // ordering surfaces bool safe_pure_less_than(const Surface& srf) const { return _x < ((SurfTest&) srf)._x; } public: // static methods // Return the type name. static TypeName get_type_name() { return "SurfTest"; } // Return the creator. static ObjCreator get_creator() { return create_SurfTest; } // Return the type. static Type get_static_type() { return get_creator(); } public: // methods // constructor SurfTest(double x) : _x(x), _spth() { _spth = CartesianPath(_x,0,0,0,0,0); } // constructor from a space path SurfTest(const SpacePath& spth) : _x(spth.x()), _spth(spth) { } // Return the type. Type get_type() const { return get_static_type(); } // Write the data. ObjData write_data() const { ObjData data("SurfTest"); data.add_double("x",_x); return data; } // Return the direction. // The direction is defined if x > 0 and set forward. // For x < 0 it is left undefined so the direction can // be specified in VTrack. TrackSurfaceDirection get_direction(const TrackVector& vec) const { if ( _x > 0.0 ) return TSD_FORWARD; else return TSD_UNDEFINED; } // return the pure type Type get_pure_type() const { return get_static_type(); }; // clone the pure surface virtual Surface* new_pure_surface( ) const { return new SurfTest(_spth); }; // Return the parameter. double get_parameter(int ipar) const { assert( ipar == 0 ); return _x; } // Return the space vector specifying the position and orientation // of the surface. SpacePath get_space_vector() const { return CartesianPath(_x, 0.0, 0.0, 1.0, 0.0, 0.0); } // Return the crossing status for a track without error. CrossStat pure_status( const VTrack& trv ) const { return CrossStat(CrossStat::AT); } // Return the difference between two track vectors. TrackVector vec_diff( const TrackVector& vec1, const TrackVector& vec2 ) const { return vec1 - vec2; } // Return the space point for a track vector. SpacePoint space_point( const TrackVector& vec ) const { return SpacePoint(); } // Return the space vector for a track vector. SpacePath space_vector(const TrackVector& vec, TrackSurfaceDirection dir) const { return _spth; } }; //********************************************************************** // Bounded surface class BSurfTest : public SurfTest { private: // attributes // parameters specifying the bounds double _bparam; public: // static methods // Return the type name. static TypeName get_type_name() { return "BSurfTest"; } // Return the creator. static ObjCreator get_creator() { return create_BSurfTest; } // Return the type. static Type get_static_type() { return get_creator(); } private: // methods // output stream void ostr( ostream& stream ) const { stream << "Test bounded surface with parameters " << _x << " and " << _bparam << "."; }; // Equality comparing two bound surfaces of this type bool safe_bound_equal(const Surface& srf) const { if ( ! pure_equal(srf) ) return false; return _bparam == ((BSurfTest&) srf)._bparam; }; public: // methods // constructor BSurfTest(double x, double bparam) : SurfTest(x), _bparam(bparam) { }; // Return the type. Type get_type() const { return get_static_type(); } // Write the data. ObjData write_data() const { ObjData data("BSurfTest"); data.add_double("x",_x); data.add_double("b",_bparam); return data; } // return the full crossing status CrossStat status(const VTrack& trv) const { return CrossStat(CrossStat::IN_BOUNDS); }; CrossStat status(const ETrack& tre) const { return CrossStat(CrossStat::BOTH_BOUNDS); }; // clone Surface* new_surface() const { return new BSurfTest(get_parameter(0),_bparam); } }; //********************************************************************** // Free functions. //********************************************************************** // Creators. ObjPtr create_SurfTest(const ObjData& data) { assert( data.get_object_type() == "SurfTest" ); if ( data.get_object_type() != "SurfTest" ) return ObjPtr(0); double x = data.get_double("x"); return ObjPtr( new SurfTest(x) ); } ObjPtr create_BSurfTest(const ObjData& data) { assert( data.get_object_type() == "BSurfTest" ); if ( data.get_object_type() != "BSurfTest" ) return ObjPtr(0); double x = data.get_double("x"); double b = data.get_double("b"); return ObjPtr( new BSurfTest(x,b) ); } //********************************************************************** #endif