//**************************************************************************** //! \file ocoutput.cpp //! \date 12-07-2003 //***************************************************************************** // This file is part of the WOCK. // // The WOCK is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // The WOCK is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with DataView; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "ocoutput.hpp" //*************************************************************************** // ocOutput methods //*************************************************************************** // public methods //*************************************************************************** //*************************************************************************** ocOutput::ocOutput() //*************************************************************************** { using std::make_pair; bound.insert( make_pair( "x", 5.0)); bound.insert( make_pair( "y", 5.0)); bound.insert( make_pair( "theta", 30.0)); bound.insert( make_pair( "phi", 30.0)); bound.insert( make_pair( "focus", 10.0)); // const_cast > bound; apos.insert( make_pair( "x", 0.)); apos.insert( make_pair( "y", 0.)); apos.insert( make_pair( "theta", 0.)); apos.insert( make_pair( "phi", 0.)); apos.insert( make_pair( "focus", 0.)); } //*************************************************************************** void ocOutput::rotate( const double theta, const double phi) //*************************************************************************** { double h = apos["theta"] + theta; if( h > bound["theta"])throw oc_eor( "theta", h - bound["theta"]); else if( h < -bound["theta"])throw oc_eor( "theta", h + bound["theta"]); else apos["theta"] = h; h = apos["phi"] + phi; if( h > bound["phi"])throw oc_eor( "phi", h - bound["phi"]); else if( h < -bound["phi"])throw oc_eor( "phi", h + bound["phi"]); else apos["phi"] = h; Execute(); } //*************************************************************************** void ocOutput::translate( const double x, const double y) //*************************************************************************** { double h = apos["x"] + x; if( h > bound["x"])throw oc_eor( "x", h - bound["x"]); else if( h < -bound["x"])throw oc_eor( "x", h + bound["x"]); else apos["x"] = h; h = apos["y"] + y; if( h > bound["y"])throw oc_eor( "y", h - bound["y"]); else if( h < -bound["y"])throw oc_eor( "y", h + bound["y"]); else apos["y"] = h; Execute(); } //*************************************************************************** void ocOutput::focus( const double foc) //*************************************************************************** { double h = apos["focus"] + foc; if( h > bound["focus"])throw oc_eor( "x", h - bound["focus"]); else if( h < -bound["focus"])throw oc_eor( "x", h + bound["focus"]); else apos["focus"] = h; Execute(); } //*************************************************************************** // ocTestOutput methods //*************************************************************************** // public methods //*************************************************************************** //*************************************************************************** ocTestOutput::ocTestOutput() : ocOutput() //*************************************************************************** { std::srand(static_cast( time( 0))); using std::make_pair; using std::rand; mpos.insert( make_pair( "x", 2*bound["x"]*( rand()/RAND_MAX) - bound["x"])); mpos.insert( make_pair( "y", 2*bound["y"]*( rand()/RAND_MAX) - bound["y"])); mpos.insert( make_pair( "theta", 2*bound["theta"]*( rand()/RAND_MAX) - bound["theta"])); mpos.insert( make_pair( "phi", 2*bound["phi"]*( rand()/RAND_MAX) - bound["phi"])); mpos.insert( make_pair( "focus", 2*bound["focus"]*( rand()/RAND_MAX) - bound["focus"])); rad= M_PI/360.; Execute(); } //*************************************************************************** void ocTestOutput::Execute() //*************************************************************************** { double erg = 200.*rand()/RAND_MAX + 450.; // background noise double mult; double h2; std::string h; for( posit = apos.begin(); posit!=apos.end(); ++posit) { h = posit->first; h2 = ( posit->second - mpos[posit->first])*rad; if( std::fabs( h2) > ( M_PI/2.)) mult = 0.; else if( ( h=="x")||( h=="y")) mult = 10.; else if( ( h=="theta")||( h=="phi")) mult = 20.; else if( h=="focus") mult = 2.; erg += mult * std::cos( h2); } rate = static_cast(std::ceil( erg)); }