SciFigs/Scale.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of SciFigs.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2006-07-25
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef SCALE_H
00029 #define SCALE_H
00030 
00031 #include <QGpCoreTools.h>
00032 
00033 #include "SciFigsDLLExport.h"
00034 
00035 namespace SciFigs {
00036 
00037 class SCIFIGS_EXPORT Scale
00038 {
00039 public:
00040   Scale();
00041 
00042   enum Type {Linear, Inversed, Log};
00043 
00044   void operator=(const Scale& o);
00045 
00046   Type type() const {return _type;}
00047   void setType(Type t) {_type=t;}
00048 
00049   SamplingOption sampling() const;
00050 
00051   void setGlobalMinimum(double m) {_globalMinimum=m;}
00052   double globalMinimum() const {return _globalMinimum;}
00053 
00054   void setGlobalMaximum(double m) {_globalMaximum=m;}
00055   double globalMaximum() const {return _globalMaximum;}
00056 
00057   void autoTicks(Number::Type numberType);
00058 
00059   double majorTicks() const {return _majorTicks;}
00060   void setMajorTicks(double m) {_majorTicks=m;}
00061 
00062   double minorTicks() const {return _minorTicks;}
00063   void setMinorTicks(double m) {_minorTicks=m;}
00064 
00065   double minimum() const {return _minimum;}
00066   void setMinimum(double min) {_minimum=min;}
00067 
00068   double maximum() const {return _maximum;}
00069   void setMaximum(double max) {_maximum=max;}
00070 
00071   double a() const {return _a;}
00072   double b() const {return _b;}
00073 
00074   bool isReversed() const {return _reversed;}
00075   void setReversed(bool r) {_reversed=r;}
00076   inline bool isEffectivelyReversed() const;
00077 
00078   double s2r(int val) const {return s2rF(val);}
00079   int r2s(double val) const {return round(r2sF(val));}
00080 
00081   inline double s2rF(double val) const;
00082   inline double r2sF(double val) const;
00083 
00084   void setHorizontalTransformation(int length);
00085   void setVerticalTransformation(int length);
00086 
00087   inline int lineCount() const;
00088   void setVerticalCurrentLine(int line);
00089   int verticalCurrentLine() const;
00090   void setHorizontalCurrentLine(int line);
00091   int horizontalCurrentLine() const;
00092 
00093   void checkLimits();
00094 private:
00095   inline void setTicks(double delta, double expo);
00096   inline double a2r(double val) const;
00097   inline double r2a(double val) const;
00098 
00099   double _a, _b;  // Current parameters for tranformation between screen and real coordinates
00100   Type _type;
00101   double _globalMinimum, _globalMaximum;
00102   double _minimum, _maximum;  // Current visible minimum and maximum
00103   bool _reversed;
00104   // increment for labels and primary ticks
00105   double _majorTicks;
00106   // increment for secondary ticks
00107   double _minorTicks;
00108 };
00109 
00110 inline double Scale::r2sF(double val) const
00111 {
00112   TRACE;
00113   switch (_type) {
00114   case Inversed:
00115     return _a/val+_b;
00116   case Log:
00117     return _a*log10(val)+_b;
00118   default:
00119     return _a*val+_b;
00120   }
00121 }
00122 
00123 inline double Scale::s2rF(double val) const
00124 {
00125   TRACE;
00126   switch (_type) {
00127   case Inversed:
00128     return _a/(val-_b);
00129   case Log:
00130     return pow(10.0, (val-_b)/_a);
00131   default:
00132     return (val-_b)/_a;
00133   }
00134 }
00135 
00136 inline double Scale::r2a(double val) const
00137 {
00138   TRACE;
00139   switch (_type) {
00140   case Inversed:
00141     return 1.0/val;
00142   case Log:
00143     return log10(val);
00144   default:
00145     return val;
00146   }
00147 }
00148 
00149 inline double Scale::a2r(double val) const
00150 {
00151   TRACE;
00152   switch (_type) {
00153   case Inversed:
00154     return 1.0/val;
00155   case Log:
00156     return pow(10.0, val);
00157   default:
00158     return val;
00159   }
00160 }
00161 
00162 inline bool Scale::isEffectivelyReversed() const
00163 {
00164   TRACE;
00165   return _reversed ? _type!=Inversed : _type==Inversed;
00166 }
00167 
00168 inline int Scale::lineCount() const
00169 {
00170   TRACE;
00171   // Line is one tenth of physical size of axis in pixel (aSize()*0.1). Hence 9 steps are removed
00172   // because the screen is always full of content.
00173   return (int) ceil((r2a(_globalMaximum) - r2a(_globalMinimum))/((r2a(_maximum) - r2a(_minimum))*0.1))-9;
00174 }
00175 
00176 } // namespace SciFigs
00177 
00178 #endif // SCALE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines