#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/IO/OffsetScale.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2002, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_OFFSETSCALE_HEADER #define RAVL_OFFSETSCALE_HEADER 1 ///////////////////////////////////////////////////////// //! rcsid="$Id: OffsetScale.hh,v 1.2 2002/08/08 16:03:11 craftit Exp $" //! example=exDataProc.cc //! docentry="Ravl.Core.Data Processing.Processes" //! lib=RavlIO //! author="Charles Galambos" //! date="04/07/1998" //! file="Ravl/Core/IO/OffsetScale.hh" #include "Ravl/DP/Process.hh" #include "Ravl/Types.hh" namespace RavlN { //////////////////////////// //! userlevel=Develop //: OffsetScale and offset by value body template class DPOffsetScaleBodyC : public DPProcessBodyC { public: DPOffsetScaleBodyC(NumTypeT off,ScaleT fact) : factor(fact), offset(off) {} //: Constructor. DPOffsetScaleBodyC(istream &strm) : DPProcessBodyC(in) { in >> fact >> offset; } //: Stream constructor. virtual NumTypeT Apply(const NumTypeT &) { return (arg + offset) * factor; } //: Apply operation. virtual IntT ApplyArray(const SArray1dC &in,SArray1dC &out) { RavlAssert(in.Size() <= out.Size()); for(SArray1dIter2C it(in,out);it;it++) it.Data2() = (it.Data1() + offset) * factor; return in.Size(); } //: Apply operation to an array of elements. // returns the number of elements processed. virtual bool Save(ostream &out) const { DPProcessBodyC::Save(out); out << factor << " " << offset; return true; } //: Save to ostream. virtual RCBodyVC &Copy() const { return *new DPOffsetScaleBodyC(offset,factor); } //: Deep copy of object. virtual bool IsStateless() const { return true; } //: Is operation stateless ? private: ScaleT factor; NumTypeT offset; }; ////////////////////////// //! userlevel=Normal //: OffsetScale a stream of data. template class DPOffsetScaleC : public DPProcessC { public: DPOffsetScaleC(NumTypeT off,ScaleT fact) : DPProcessC(*new DPOffsetScaleBodyC(off,fact)) {} //: Constructor. }; ///////////////////////////////////////// template DPProcessC DPOffsetScale(const NumTypeT &off,const ScaleT &fact) { return DPOffsetScaleC(off,fact); } } #endif