Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

qwt_scale_map.cpp

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #include "qwt_scale_map.h"
00011 
00012 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;
00013 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;
00014 
00015 QwtScaleTransformation::QwtScaleTransformation():
00016     xForm(linearXForm),
00017     invXForm(linearXForm)
00018 {
00019 }
00020 
00021 QwtScaleTransformation::QwtScaleTransformation(
00022         double (*xf)(double x, double s1, double s2, 
00023             double p1, double p2, void *),
00024         double (*invxf)(double y, double p1, double p2, 
00025             double s1, double s2, void *) ):
00026     xForm(xf),
00027     invXForm(invxf)
00028 {
00029 }
00030 
00045 double QwtScaleTransformation::linearXForm(    
00046     double x, double x1, double x2, double y1, double y2, void *)
00047 {
00048     const double ratio = (y2 - y1) / (x2 - x1);
00049     return y1 + (x - x1) * ratio;
00050 }
00051 
00067 double QwtScaleTransformation::log10XForm(double x, double s1, double s2, 
00068     double p1, double p2, void *)
00069 {
00070     return p1 + (p2 - p1) / log(s2 / s1) * log(x / s1);
00071 }
00072 
00087 double QwtScaleTransformation::log10InvXForm(double x, double p1, double p2, 
00088     double s1, double s2, void *)
00089 {
00090     return exp((x - p1) / (p2 - p1) * log(s2 / s1)) * s1;
00091 }
00092 
00098 QwtScaleMap::QwtScaleMap():
00099     d_s1(0.0),
00100     d_s2(1.0),
00101     d_p1(0.0),
00102     d_p2(1.0),
00103     d_cnv(1.0),
00104     d_transformationData(NULL)
00105 {
00106 }
00107 
00108 
00120 QwtScaleMap::QwtScaleMap(int p1, int p2, double s1, double s2):
00121     d_p1(p1),
00122     d_p2(p2),
00123     d_transformationData(NULL)
00124 {
00125     setScaleInterval(s1, s2);
00126 }
00127 
00131 QwtScaleMap::~QwtScaleMap()
00132 {
00133 }
00134 
00138 void QwtScaleMap::setTransformation(bool logarithmic)
00139 {
00140     QwtScaleTransformation transformation;
00141     if ( logarithmic )
00142     {
00143         transformation.xForm = QwtScaleTransformation::log10XForm;
00144         transformation.invXForm = QwtScaleTransformation::log10InvXForm;
00145     }
00146     else
00147     {
00148         transformation.xForm = QwtScaleTransformation::linearXForm;
00149         transformation.invXForm = QwtScaleTransformation::linearXForm;
00150     }
00151     setTransformation(transformation);
00152 }
00153 
00157 void QwtScaleMap::setTransformation(
00158     const QwtScaleTransformation &transformation)
00159 {
00160     d_transformation = transformation;
00161 }
00162 
00164 const QwtScaleTransformation &QwtScaleMap::transformation() const
00165 {
00166     return d_transformation;
00167 }
00168 
00174 void QwtScaleMap::setTransformationData(void *transformationData)
00175 {
00176     d_transformationData = transformationData;
00177 }
00178 
00180 void *QwtScaleMap::transformationData() const
00181 {
00182     return d_transformationData;
00183 }
00184 
00191 void QwtScaleMap::setScaleInterval(double s1, double s2)
00192 {
00193     if (d_transformation.xForm == QwtScaleTransformation::log10XForm)
00194     {
00195         if (s1 < LogMin) 
00196            s1 = LogMin;
00197         else if (s1 > LogMax) 
00198            s1 = LogMax;
00199         
00200         if (s2 < LogMin) 
00201            s2 = LogMin;
00202         else if (s2 > LogMax) 
00203            s2 = LogMax;
00204     }
00205 
00206     d_s1 = s1;
00207     d_s2 = s2;
00208 
00209     newFactor();
00210 }
00211 
00217 void QwtScaleMap::setPaintInterval(int p1, int p2)
00218 {
00219     d_p1 = p1;
00220     d_p2 = p2;
00221     newFactor();
00222 }
00223 
00229 void QwtScaleMap::setPaintXInterval(double p1, double p2)
00230 {
00231     d_p1 = p1;
00232     d_p2 = p2;
00233     newFactor();
00234 }
00235 
00239 void QwtScaleMap::newFactor()
00240 {
00241     d_cnv = 0.0;
00242 #if 1
00243     if (d_s2 == d_s1)
00244         return;
00245 #endif
00246 
00247     if (d_transformation.xForm == QwtScaleTransformation::linearXForm)
00248         d_cnv = (d_p2 - d_p1) / (d_s2 - d_s1); 
00249     else if (d_transformation.xForm == QwtScaleTransformation::log10XForm)
00250         d_cnv = (d_p2 - d_p1) / log(d_s2 / d_s1);
00251 }

Generated on Mon Jan 30 22:16:26 2006 for Qwt User's Guide by  doxygen 1.4.4