<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>HippoDraw Class Library</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="hippoApp.ico"> </head><body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_eff62de51072964fc77c85daa9c2b3ad.html">transforms</a> </div> </div> <div class="contents"> <h1>LinearTransform.cxx</h1><a href="LinearTransform_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="LinearTransform_8h.html" title="LinearTransform class interface.">LinearTransform.h</a>"</span> <a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="preprocessor">#include "<a class="code" href="AxisModelBase_8h.html" title="hippodraw::AxisModelBase class interface">axes/AxisModelBase.h</a>"</span> <a name="l00015"></a>00015 <span class="preprocessor">#include "<a class="code" href="AxisTick_8h.html" title="AxisTick class interface.">axes/AxisTick.h</a>"</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include <cmath></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <cstdio></span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="keyword">using</span> std::abs; <a name="l00021"></a>00021 <span class="keyword">using</span> std::max; <a name="l00022"></a>00022 <span class="keyword">using</span> std::vector; <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="keyword">namespace </span>hippodraw { <a name="l00025"></a>00025 <a name="l00030"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a92877f79b1fc9528522550c804f79cd0">00030</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#a92877f79b1fc9528522550c804f79cd0" title="The default constructor.">LinearTransform::LinearTransform</a> () <a name="l00031"></a>00031 : <a class="code" href="classhippodraw_1_1UnaryTransform.html" title="A transform that transforms coordinates in one dimension from one coordinate system...">UnaryTransform</a> ( -DBL_MAX, DBL_MAX ) <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classhippodraw_1_1TransformBase.html#adb41893ba19e889e56c559f25fc1a68a" title="Name of the Transform.">m_name</a> = <span class="stringliteral">"Linear"</span>; <a name="l00034"></a>00034 } <a name="l00035"></a>00035 <a name="l00036"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#ad1cb32c4974ca631308b7da9f16f6a1d">00036</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#ad1cb32c4974ca631308b7da9f16f6a1d" title="The virtual destructor.">LinearTransform::~LinearTransform</a> () <a name="l00037"></a>00037 { <a name="l00038"></a>00038 } <a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a7ff7399ae93fa7e03a3df57d34d96f12">00040</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#a92877f79b1fc9528522550c804f79cd0" title="The default constructor.">LinearTransform::LinearTransform</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1LinearTransform.html" title="A transform on one axis whose output is equal to the input.">LinearTransform</a> & lt ) <a name="l00041"></a>00041 : <a class="code" href="classhippodraw_1_1UnaryTransform.html" title="A transform that transforms coordinates in one dimension from one coordinate system...">UnaryTransform</a> ( lt ) <a name="l00042"></a>00042 { <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="preprocessor">#ifdef CLONE_DEFECT</span> <a name="l00046"></a>00046 <span class="preprocessor"></span><a class="code" href="classhippodraw_1_1TransformBase.html" title="A transform that transforms coordinates from one coordinate system to another.">TransformBase</a> * <a class="code" href="classhippodraw_1_1LinearTransform.html#a5f0413be2b085270f6fbbb263416f7cd" title="Creates a new Transform object by copying an existing one.">LinearTransform::clone</a> () const <a name="l00047"></a>00047 <span class="preprocessor">#else</span> <a name="l00048"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a5f0413be2b085270f6fbbb263416f7cd">00048</a> <span class="preprocessor"></span><a class="code" href="classhippodraw_1_1LinearTransform.html" title="A transform on one axis whose output is equal to the input.">LinearTransform</a> * <a class="code" href="classhippodraw_1_1LinearTransform.html#a5f0413be2b085270f6fbbb263416f7cd" title="Creates a new Transform object by copying an existing one.">LinearTransform::clone</a> () const <a name="l00049"></a>00049 <span class="preprocessor">#endif </span> <a name="l00050"></a>00050 <span class="preprocessor"></span>{ <a name="l00051"></a>00051 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1LinearTransform.html" title="A transform on one axis whose output is equal to the input.">LinearTransform</a> ( *<span class="keyword">this</span> ); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="keywordtype">bool</span> <a name="l00055"></a>00055 <a class="code" href="classhippodraw_1_1LinearTransform.html#a792fef1281c0bcc191b5bf4330f5eeb3">LinearTransform::</a> <a name="l00056"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a792fef1281c0bcc191b5bf4330f5eeb3">00056</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#a792fef1281c0bcc191b5bf4330f5eeb3">isLinear</a> ()<span class="keyword"> const</span> <a name="l00057"></a>00057 <span class="keyword"></span>{ <a name="l00058"></a>00058 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00059"></a>00059 } <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="keywordtype">void</span> <a name="l00062"></a>00062 <a class="code" href="classhippodraw_1_1LinearTransform.html#aee3a2817949711b6b0a3465c032126a8" title="Transforms the coordinate @ x.">LinearTransform::</a> <a name="l00063"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#aee3a2817949711b6b0a3465c032126a8">00063</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#aee3a2817949711b6b0a3465c032126a8" title="Transforms the coordinate @ x.">transform</a> ( <span class="keywordtype">double</span> & )<span class="keyword"> const</span> <a name="l00064"></a>00064 <span class="keyword"></span>{ <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordtype">void</span> <a name="l00068"></a>00068 <a class="code" href="classhippodraw_1_1LinearTransform.html#ae08ffa4131d0bb8a4072fb2c90ee28e9" title="Inverse transforms the coordinate x.">LinearTransform::</a> <a name="l00069"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#ae08ffa4131d0bb8a4072fb2c90ee28e9">00069</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#ae08ffa4131d0bb8a4072fb2c90ee28e9" title="Inverse transforms the coordinate x.">inverseTransform</a> ( <span class="keywordtype">double</span> & )<span class="keyword"> const</span> <a name="l00070"></a>00070 <span class="keyword"></span>{ <a name="l00071"></a>00071 } <a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="keywordtype">void</span> <a name="l00074"></a>00074 <a class="code" href="classhippodraw_1_1LinearTransform.html#aee3a2817949711b6b0a3465c032126a8" title="Transforms the coordinate @ x.">LinearTransform::</a> <a name="l00075"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a1005e56655132bca417febd05bb02a74">00075</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#aee3a2817949711b6b0a3465c032126a8" title="Transforms the coordinate @ x.">transform</a> ( std::vector < double > & )<span class="keyword"> const</span> <a name="l00076"></a>00076 <span class="keyword"></span>{ <a name="l00077"></a>00077 } <a name="l00078"></a>00078 <a name="l00079"></a>00079 <span class="comment">/* virtual */</span> <a name="l00080"></a>00080 <span class="keywordtype">void</span> <a name="l00081"></a>00081 <a class="code" href="classhippodraw_1_1LinearTransform.html#ab36d3909864539674c1cfb50d1ffa66f" title="The following function validates the range.">LinearTransform::</a> <a name="l00082"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#ab36d3909864539674c1cfb50d1ffa66f">00082</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#ab36d3909864539674c1cfb50d1ffa66f" title="The following function validates the range.">validate</a> ( <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & )<span class="keyword"> const</span> <a name="l00083"></a>00083 <span class="keyword"></span>{ <a name="l00084"></a>00084 <span class="comment">// Nothing to be done.</span> <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keyword">const</span> vector < AxisTick > & <a name="l00088"></a>00088 <a class="code" href="classhippodraw_1_1LinearTransform.html#a63520cdf916ece9fb7de60f014dff1b7" title="Sets the vector of ticks along the axis to which this Linear transform is applied...">LinearTransform::</a> <a name="l00089"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a63520cdf916ece9fb7de60f014dff1b7">00089</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#a63520cdf916ece9fb7de60f014dff1b7" title="Sets the vector of ticks along the axis to which this Linear transform is applied...">setTicks</a> ( <a class="code" href="classhippodraw_1_1AxisModelBase.html" title="The AxisModelBase class maintains the Range and scaling of an axis.">AxisModelBase</a> & axis ) <a name="l00090"></a>00090 { <a name="l00091"></a>00091 <a class="code" href="classhippodraw_1_1LinearTransform.html#ada2f4d52253c008767b6ac38f94e985b">setTickStep</a>( axis ); <a name="l00092"></a>00092 <a class="code" href="classhippodraw_1_1LinearTransform.html#a14bf1587975bfb3064dd9cc74c8ac66a">setFirstTick</a>( axis ); <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1LinearTransform.html#af8a49cf2363c45baf09c0c2b8e1849fb">genTicks</a>( axis ); <a name="l00095"></a>00095 } <a name="l00096"></a>00096 <a name="l00097"></a><a class="code" href="namespacehippodraw.html#a677bae1007193bb8a36edc63239a541a">00097</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="namespacehippodraw.html#a677bae1007193bb8a36edc63239a541a">FLT_EQUAL</a>( <span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y ) <a name="l00098"></a>00098 { <a name="l00099"></a>00099 <span class="keywordflow">return</span> ( (<span class="keywordtype">double</span>)abs( x - y ) <= 2.0 * ( y * FLT_EPSILON + FLT_MIN ) ); <a name="l00100"></a>00100 } <a name="l00101"></a>00101 <a name="l00102"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#ada2f4d52253c008767b6ac38f94e985b">00102</a> <span class="keywordtype">void</span> <a class="code" href="classhippodraw_1_1LinearTransform.html#ada2f4d52253c008767b6ac38f94e985b">LinearTransform::setTickStep</a>( <a class="code" href="classhippodraw_1_1AxisModelBase.html" title="The AxisModelBase class maintains the Range and scaling of an axis.">AxisModelBase</a> & axis ) <a name="l00103"></a>00103 { <a name="l00104"></a>00104 <span class="keyword">static</span> <span class="keywordtype">float</span> goodTicks[] = { 5.0, 4.0, 2.0, 1.0 }; <a name="l00105"></a>00105 <span class="keywordtype">int</span> tickIndex; <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & range = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>(<span class="keyword">false</span>); <a name="l00108"></a>00108 <span class="keywordtype">double</span> rangeLength = range.<a class="code" href="classhippodraw_1_1Range.html#ad207cb443e371f73f07e874c504f60c1" title="Returns the length of the range object.">length</a>(); <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="keywordtype">double</span> scale_factor = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#afbde1a57da2ad6bd8e170d77e36e64bb" title="Returns the scale factor.">getScaleFactor</a>(); <a name="l00111"></a>00111 rangeLength *= scale_factor; <a name="l00112"></a>00112 <span class="keyword">const</span> <span class="keywordtype">int</span> MIN_TICKS = 3; <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="comment">// The following algorithm determines the magnitude of the range...</span> <a name="l00115"></a>00115 <span class="keywordtype">double</span> rmag = floor( log10( rangeLength ) ); <a name="l00116"></a>00116 <a name="l00117"></a>00117 <span class="comment">// ...and then decreases by one magnitude if it would allow less than</span> <a name="l00118"></a>00118 <span class="comment">// 3 ticks (e.g., the range is 25000 and the magnitude is 10000. This</span> <a name="l00119"></a>00119 <span class="comment">// would allow for 2.5 ticks while we in fact would rather have a</span> <a name="l00120"></a>00120 <span class="comment">// magnitude of 1000, multiplied by a constant, as below).</span> <a name="l00121"></a>00121 <a name="l00122"></a>00122 <span class="keywordflow">if</span>( rangeLength / pow( 10.0, rmag ) < MIN_TICKS ) { <a name="l00123"></a>00123 rmag--; <a name="l00124"></a>00124 } <a name="l00125"></a>00125 <a name="l00126"></a>00126 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#af933579f4160e62b19ce2fba5f530c91" title="Sets the magnitude of the range.">setRMag</a>( rmag ); <a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="keywordtype">double</span> scalelow = range.<a class="code" href="classhippodraw_1_1Range.html#a3865c37c86de4e4eafc43b6b40ef05b9" title="Returns the minimum of the range object.">low</a>() * scale_factor; <a name="l00129"></a>00129 <span class="keywordtype">double</span> scalehigh = range.<a class="code" href="classhippodraw_1_1Range.html#a10f7231db7f0fe0855fc344e98575714" title="Returns the maximum of the range object.">high</a>() * scale_factor; <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="comment">// We will also need the largest magnitude for labels.</span> <a name="l00132"></a>00132 <span class="keywordtype">double</span> pmag = max( floor( log10( abs ( scalehigh ) ) ), <a name="l00133"></a>00133 floor( log10( abs ( scalelow ) ) ) ); <a name="l00134"></a>00134 <a name="l00135"></a>00135 <span class="comment">// This if statement changes the magnitude so that if the high or</span> <a name="l00136"></a>00136 <span class="comment">// low is exactly a power of 10, we will give labels from</span> <a name="l00137"></a>00137 <span class="comment">// [1,10] * 10^mag and not [0,1] * 10^mag.</span> <a name="l00138"></a>00138 <span class="keywordflow">if</span>( pow( 10.0, pmag ) == scalehigh || <a name="l00139"></a>00139 pow( 10.0, pmag ) == scalelow ) pmag--; <a name="l00140"></a>00140 <a name="l00141"></a>00141 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a447254d994d524156b490c0f78dc5c5a" title="Sets the magnitude of the power of ten for the tick labels.">setPMag</a>( pmag ); <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="comment">// Now we determine the above stated constant. The magnitude is already</span> <a name="l00144"></a>00144 <span class="comment">// known, so we see what's the closest we can get to exactly 3 ticks</span> <a name="l00145"></a>00145 <span class="comment">// under this magnitude. In the above example, a range of 25000 was</span> <a name="l00146"></a>00146 <span class="comment">// given with a magnitude of 1000. This algorithm will recognize that</span> <a name="l00147"></a>00147 <span class="comment">// 5.0 * 1000 will give 5 ticks, which is a good number to have. If</span> <a name="l00148"></a>00148 <span class="comment">// the range was 12000 and magnitude 1000 then 5.0 * 1000 would give</span> <a name="l00149"></a>00149 <span class="comment">// only 2 ticks, not enough. The loop would then proceed to 4.0 * 1000</span> <a name="l00150"></a>00150 <span class="comment">// which will give exactly 3 ticks.</span> <a name="l00151"></a>00151 <span class="keywordtype">double</span> tick_step = 0; <a name="l00152"></a>00152 <span class="keywordflow">for</span>( tickIndex = 0; <a name="l00153"></a>00153 rangeLength / <a name="l00154"></a>00154 ( tick_step = goodTicks[tickIndex] * pow( 10.0, rmag ) ) <a name="l00155"></a>00155 < MIN_TICKS; <a name="l00156"></a>00156 tickIndex++ ){}; <a name="l00157"></a>00157 <a name="l00158"></a>00158 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#ae8434910717057b1d2e5a92bba63a756" title="Sets the tick step.">setTickStep</a>( tick_step ); <a name="l00159"></a>00159 } <a name="l00160"></a>00160 <a name="l00161"></a>00161 <a name="l00162"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#a14bf1587975bfb3064dd9cc74c8ac66a">00162</a> <span class="keywordtype">void</span> <a class="code" href="classhippodraw_1_1LinearTransform.html#a14bf1587975bfb3064dd9cc74c8ac66a">LinearTransform::setFirstTick</a>( <a class="code" href="classhippodraw_1_1AxisModelBase.html" title="The AxisModelBase class maintains the Range and scaling of an axis.">AxisModelBase</a> & axis ) <a name="l00163"></a>00163 { <a name="l00164"></a>00164 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & range = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>(<span class="keyword">true</span>); <a name="l00165"></a>00165 <span class="keywordtype">double</span> low = range.<a class="code" href="classhippodraw_1_1Range.html#a3865c37c86de4e4eafc43b6b40ef05b9" title="Returns the minimum of the range object.">low</a>(); <a name="l00166"></a>00166 <span class="keywordtype">double</span> tick_step = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a4421f43d8e6dbd79ef9e5f863b2da21c" title="Returns the tick step in the true coordinate system.">getTickStep</a>(); <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="comment">// This sets the first tick as the low value rounded up to the</span> <a name="l00169"></a>00169 <span class="comment">// nearest tick step. If the low value fell on a tick, then that is</span> <a name="l00170"></a>00170 <span class="comment">// the first tick. Otherwise, it is the next tick inside the range</span> <a name="l00171"></a>00171 <span class="comment">// of the data.</span> <a name="l00172"></a>00172 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a74b0210580d8668f96dabcc2d2260928" title="Sets the value for first tick step.">setFirstTick</a>( ceil( low / tick_step ) * tick_step ); <a name="l00173"></a>00173 } <a name="l00174"></a>00174 <a name="l00175"></a>00175 <a name="l00178"></a>00178 <span class="keyword">const</span> vector < AxisTick > & <a name="l00179"></a>00179 <a class="code" href="classhippodraw_1_1LinearTransform.html#af8a49cf2363c45baf09c0c2b8e1849fb">LinearTransform::</a> <a name="l00180"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#af8a49cf2363c45baf09c0c2b8e1849fb">00180</a> <a class="code" href="classhippodraw_1_1LinearTransform.html#af8a49cf2363c45baf09c0c2b8e1849fb">genTicks</a>( <a class="code" href="classhippodraw_1_1AxisModelBase.html" title="The AxisModelBase class maintains the Range and scaling of an axis.">AxisModelBase</a> & axis ) <a name="l00181"></a>00181 { <a name="l00182"></a>00182 <span class="keywordtype">double</span> y = 0.0, ylabel; <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="keywordtype">int</span> num_ticks = 0; <a name="l00185"></a>00185 <a class="code" href="classhippodraw_1_1LinearTransform.html#afb83347aa94ee29360b10d085dba3e02" title="The ticks generated by this transform.">m_ticks</a>.clear(); <a name="l00186"></a>00186 <span class="keywordtype">double</span> pmag = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#aa5f0390d0531f504b59bbb13de685328" title="Returns the magnitude of the power of ten for the tick labels.">getPMag</a>(); <a name="l00187"></a>00187 <span class="keywordtype">double</span> rmag = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a91b53d98dc36d6f69d1670d4a2c9c6ab" title="Sets the magnitude of the range.">getRMag</a>(); <a name="l00188"></a>00188 <span class="keywordtype">double</span> first_tick = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#ad75d6349899399e6ca07cb1103d86480" title="Returns the value for the first tick step.">getFirstTick</a>(); <a name="l00189"></a>00189 <span class="keywordtype">double</span> tick_step = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a4421f43d8e6dbd79ef9e5f863b2da21c" title="Returns the tick step in the true coordinate system.">getTickStep</a>(); <a name="l00190"></a>00190 <span class="keywordtype">double</span> scale_factor = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#afbde1a57da2ad6bd8e170d77e36e64bb" title="Returns the scale factor.">getScaleFactor</a>(); <a name="l00191"></a>00191 <span class="keywordtype">double</span> max_ticks = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#aa9c4760aa8c522cbb7b7ae6dc826d27d" title="Returns the value for maximum number of ticks.">getMaxTicks</a>(); <a name="l00192"></a>00192 <a name="l00193"></a>00193 <span class="comment">// pmag will get set to 0 if it is less than or equal to 3. This</span> <a name="l00194"></a>00194 <span class="comment">// is used later to determine scientific notation. However, m_rmag</span> <a name="l00195"></a>00195 <span class="comment">// is still needed as the original magnitude for calculations such</span> <a name="l00196"></a>00196 <span class="comment">// as decimal place notation, and rounding to nice numbers.</span> <a name="l00197"></a>00197 <a name="l00198"></a>00198 <span class="comment">// if( fabs( m_pmag ) <= 3.0 ) m_pmag = 0.0;</span> <a name="l00199"></a>00199 <span class="keywordtype">bool</span> use_pmag = abs ( pmag ) > 3.0; <a name="l00200"></a>00200 <a name="l00201"></a>00201 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#ad4bbfdc145a8049e4e52db34d968fd78" title="Use to set the value of the member variable m_use_pmag.">setUsePMag</a> ( use_pmag ); <a name="l00202"></a>00202 <a name="l00203"></a>00203 <span class="keywordtype">char</span> pstr[10]; <a name="l00204"></a>00204 <span class="keywordtype">char</span> labl[10]; <a name="l00205"></a>00205 <a name="l00206"></a>00206 <span class="keywordtype">int</span> decimals = 0; <a name="l00207"></a>00207 <a name="l00208"></a>00208 <span class="comment">// The following if-else block decides the pstr string, which holds</span> <a name="l00209"></a>00209 <span class="comment">// the number of decimal places in the label.</span> <a name="l00210"></a>00210 <a name="l00211"></a>00211 <span class="comment">// if( fabs( m_pmag ) > 3.0 ) {</span> <a name="l00212"></a>00212 <span class="keywordflow">if</span> ( use_pmag ) { <a name="l00213"></a>00213 <span class="comment">// If we are greater than mag 3, we are showing scientific</span> <a name="l00214"></a>00214 <span class="comment">// notation. How many decimals we show is determined by the</span> <a name="l00215"></a>00215 <span class="comment">// difference between the range magnitude and the power magnitude.</span> <a name="l00216"></a>00216 <a name="l00217"></a>00217 decimals = <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>( pmag - rmag ); <a name="l00218"></a>00218 <span class="comment">// minumum 1 decimal in scientific notation</span> <a name="l00219"></a>00219 <a name="l00220"></a>00220 <span class="keywordflow">if</span>( !decimals ) decimals++; <a name="l00221"></a>00221 <a name="l00222"></a>00222 } <span class="keywordflow">else</span> { <a name="l00223"></a>00223 <a name="l00224"></a>00224 <span class="keywordflow">if</span>( rmag > 0.0 ){ <a name="l00225"></a>00225 <a name="l00226"></a>00226 <span class="comment">// If we are less than mag 3 and positive, then no decimal</span> <a name="l00227"></a>00227 <span class="comment">// accuracy is needed.</span> <a name="l00228"></a>00228 <a name="l00229"></a>00229 decimals = 0; <a name="l00230"></a>00230 <a name="l00231"></a>00231 } <span class="keywordflow">else</span> { <a name="l00232"></a>00232 <a name="l00233"></a>00233 <span class="comment">// If we are less than mag 3 and negative, then we are suddenly</span> <a name="l00234"></a>00234 <span class="comment">// looking at decimal numbers not in scientific notation.</span> <a name="l00235"></a>00235 <span class="comment">// Therefore we hold as many decimal places as the magnitude.</span> <a name="l00236"></a>00236 <a name="l00237"></a>00237 decimals = <span class="keyword">static_cast<</span><span class="keywordtype">int</span><span class="keyword">></span>( abs( rmag ) ); <a name="l00238"></a>00238 <a name="l00239"></a>00239 } <a name="l00240"></a>00240 <a name="l00241"></a>00241 } <a name="l00242"></a>00242 <span class="comment">// @todo decimals should never be negative here, but it does end up</span> <a name="l00243"></a>00243 <span class="comment">// negative in some cases. See the "dirty fix" in Range.cxx, that</span> <a name="l00244"></a>00244 <span class="comment">// dirty-fixed this problem too. But a better fix is needed. </span> <a name="l00245"></a>00245 <span class="keywordflow">if</span> (decimals < 0) { <a name="l00246"></a>00246 decimals = 0; <a name="l00247"></a>00247 } <a name="l00248"></a>00248 <a name="l00249"></a>00249 sprintf( pstr, <span class="stringliteral">"%%1.%df"</span>, decimals ); <a name="l00250"></a>00250 <a name="l00251"></a>00251 y = first_tick; <a name="l00252"></a>00252 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & range = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>(<span class="keyword">false</span>); <a name="l00253"></a>00253 <span class="keywordtype">double</span> range_high = range.<a class="code" href="classhippodraw_1_1Range.html#a10f7231db7f0fe0855fc344e98575714" title="Returns the maximum of the range object.">high</a>(); <a name="l00254"></a>00254 range_high *= scale_factor; <a name="l00255"></a>00255 range_high += 100. * DBL_EPSILON; <a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="comment">// while( y <= range_high || FLT_EQUAL( range_high, y ) ) {</span> <a name="l00258"></a>00258 <span class="keywordflow">while</span>( y <= range_high ) { <a name="l00259"></a>00259 <a name="l00260"></a>00260 <span class="keywordflow">if</span>( num_ticks >= max_ticks ) { <a name="l00261"></a>00261 <a name="l00262"></a>00262 <span class="comment">// HERE So far, this has only occurred for empty histograms. The</span> <a name="l00263"></a>00263 <span class="comment">//easy fix was to do nothing, but there ought to be a better</span> <a name="l00264"></a>00264 <span class="comment">// way to handle this.</span> <a name="l00265"></a>00265 <a name="l00266"></a>00266 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1LinearTransform.html#afb83347aa94ee29360b10d085dba3e02" title="The ticks generated by this transform.">m_ticks</a>; <a name="l00267"></a>00267 <a name="l00268"></a>00268 } <a name="l00269"></a>00269 <a name="l00270"></a>00270 <span class="comment">// The following expression is used to round to the nearest nice</span> <a name="l00271"></a>00271 <span class="comment">// number, and then return to the original magnitude.</span> <a name="l00272"></a>00272 <a name="l00273"></a>00273 <span class="keywordtype">double</span> value = floor( y / pow( 10.0, rmag ) + 0.5 ) * <a name="l00274"></a>00274 pow( 10.0, rmag ); <a name="l00275"></a>00275 <a name="l00276"></a>00276 <span class="comment">// Now that the number is nice, we either keep the original magnitude</span> <a name="l00277"></a>00277 <span class="comment">// or reduce it in order to express it in scientific notation.</span> <a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="keywordflow">if</span> ( use_pmag ) ylabel = value / pow( 10.0, pmag ); <a name="l00280"></a>00280 <span class="keywordflow">else</span> ylabel = value; <a name="l00281"></a>00281 <a name="l00282"></a>00282 value /= scale_factor; <a name="l00283"></a>00283 sprintf( labl, pstr, ylabel ); <a name="l00284"></a>00284 <a class="code" href="classhippodraw_1_1LinearTransform.html#afb83347aa94ee29360b10d085dba3e02" title="The ticks generated by this transform.">m_ticks</a>.push_back( <a class="code" href="classhippodraw_1_1AxisTick.html" title="A class to maintain tick coordinates and string values.">AxisTick</a> ( value, labl ) ); <a name="l00285"></a>00285 <a name="l00286"></a>00286 num_ticks++; <a name="l00287"></a>00287 y += tick_step; <a name="l00288"></a>00288 <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1LinearTransform.html#afb83347aa94ee29360b10d085dba3e02" title="The ticks generated by this transform.">m_ticks</a>; <a name="l00292"></a>00292 } <a name="l00293"></a>00293 <a name="l00294"></a><a class="code" href="classhippodraw_1_1LinearTransform.html#ae2ab75931c7af475c0d558f24a9236db">00294</a> <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & <a class="code" href="classhippodraw_1_1LinearTransform.html#ae2ab75931c7af475c0d558f24a9236db" title="Sets the range of given axis to be a new &quot;nice&quot; within the limits given...">LinearTransform::adjustValues</a> ( <a class="code" href="classhippodraw_1_1AxisModelBase.html" title="The AxisModelBase class maintains the Range and scaling of an axis.">AxisModelBase</a> & axis, <a name="l00295"></a>00295 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & limit ) <a name="l00296"></a>00296 { <a name="l00297"></a>00297 <span class="comment">//Because the low value, the high value, and the length value of the</span> <a name="l00298"></a>00298 <span class="comment">//range were so frequently used, I added those three fields. There </span> <a name="l00299"></a>00299 <span class="comment">//should be an improvement in performance.</span> <a name="l00300"></a>00300 <span class="keywordtype">double</span> mylow, myhigh; <a name="l00301"></a>00301 <a name="l00302"></a>00302 <span class="comment">//The use of a step field and of a mag field will be explained when</span> <a name="l00303"></a>00303 <span class="comment">//they are first initialized.</span> <a name="l00304"></a>00304 <span class="keywordtype">double</span> step, magnitude; <a name="l00305"></a>00305 <a name="l00306"></a>00306 <span class="keyword">const</span> <span class="keywordtype">int</span> N_NICE = 6; <a name="l00307"></a>00307 <span class="preprocessor">#ifndef __STDC__</span> <a name="l00308"></a>00308 <span class="preprocessor"></span> <span class="keyword">static</span> <a name="l00309"></a>00309 <span class="preprocessor">#endif</span> <a name="l00310"></a>00310 <span class="preprocessor"></span> <span class="keywordtype">float</span> nice[N_NICE] = { 1.0, 2.0, 2.5, <a name="l00311"></a>00311 4.0, 5.0, 7.5 }; <a name="l00312"></a>00312 <a name="l00313"></a>00313 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> & init_range = axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a> ( <span class="keyword">false</span> ); <a name="l00314"></a>00314 <span class="keywordtype">double</span> low = init_range.<a class="code" href="classhippodraw_1_1Range.html#a3865c37c86de4e4eafc43b6b40ef05b9" title="Returns the minimum of the range object.">low</a> (); <a name="l00315"></a>00315 <span class="keywordtype">double</span> high = init_range.<a class="code" href="classhippodraw_1_1Range.html#a10f7231db7f0fe0855fc344e98575714" title="Returns the maximum of the range object.">high</a> (); <a name="l00316"></a>00316 <a name="l00317"></a>00317 <span class="keywordflow">if</span> ( ( high - low ) < 10.* DBL_MIN ) { <span class="comment">// all values in same bin</span> <a name="l00318"></a>00318 <span class="keywordflow">if</span> ( low > 0.0 ) low *= 0.95; <a name="l00319"></a>00319 <span class="keywordflow">else</span> low *= 1.05; <a name="l00320"></a>00320 <a name="l00321"></a>00321 <span class="keywordflow">if</span> ( low == 0. ) { <span class="comment">// special case</span> <a name="l00322"></a>00322 high = low + 1000. * FLT_EPSILON; <span class="comment">// large enough so tick algo works</span> <a name="l00323"></a>00323 } <a name="l00324"></a>00324 <span class="keywordflow">else</span> { <a name="l00325"></a>00325 <span class="keywordflow">if</span> ( high > 0.) high *= 1.05; <a name="l00326"></a>00326 <span class="keywordflow">else</span> high *= 0.95; <a name="l00327"></a>00327 } <a name="l00328"></a>00328 <a name="l00329"></a>00329 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#addffd7d4904f8f6261dae4e2cb51b734" title="Sets the Range to the low and high values.">setRange</a> ( low, high, low ); <a name="l00330"></a>00330 } <a name="l00331"></a>00331 <span class="keywordtype">double</span> range_length; <a name="l00332"></a>00332 <a name="l00333"></a>00333 <span class="keywordtype">int</span> i; <a name="l00334"></a>00334 <a name="l00335"></a>00335 <span class="comment">// This increases myhigh so that "myrange" covers the whole range</span> <a name="l00336"></a>00336 <span class="comment">// and then some.</span> <a name="l00337"></a>00337 <a name="l00338"></a>00338 mylow = low - 0.05*(high-low); <a name="l00339"></a>00339 myhigh = high + 0.05*(high-low); <a name="l00340"></a>00340 <a name="l00341"></a>00341 range_length = myhigh - mylow; <a name="l00342"></a>00342 <a name="l00343"></a>00343 <span class="comment">// We have now decided on a range. This tries to move low/high a</span> <a name="l00344"></a>00344 <span class="comment">// little to end up on a nice number.</span> <a name="l00345"></a>00345 <a name="l00346"></a>00346 <span class="comment">// First checks if either end is near 0.0</span> <a name="l00347"></a>00347 <span class="keywordflow">if</span>( low >= 0.0 && range_length > ( 1.05 * high ) ) { <a name="l00348"></a>00348 <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> range ( 0.0, range_length ); <a name="l00349"></a>00349 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a175253bfecf26b89ced34342b0f2a4b2" title="Sets the Range to overlap of the two ranges.">setIntersectRange</a> ( range, limit ); <a name="l00350"></a>00350 <span class="keywordflow">return</span> axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>( <span class="keyword">false</span> ); <a name="l00351"></a>00351 } <a name="l00352"></a>00352 <span class="keywordflow">if</span>( high <= 0.0 && -range_length < ( 1.05 * low ) ) { <a name="l00353"></a>00353 <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> range ( -range_length, 0.0 ); <a name="l00354"></a>00354 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a175253bfecf26b89ced34342b0f2a4b2" title="Sets the Range to overlap of the two ranges.">setIntersectRange</a> ( range, limit ); <a name="l00355"></a>00355 <span class="keywordflow">return</span> axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>( <span class="keyword">false</span> ); <a name="l00356"></a>00356 } <a name="l00357"></a>00357 <a name="l00358"></a>00358 <span class="comment">// magnitude is used to hold the magnitude of the high or low values.</span> <a name="l00359"></a>00359 <a name="l00360"></a>00360 i = N_NICE - 1; <a name="l00361"></a>00361 <span class="keywordflow">if</span>( myhigh != 0.0 ) <a name="l00362"></a>00362 magnitude = ceil( log10( fabs( myhigh ) ) ); <a name="l00363"></a>00363 <span class="keywordflow">else</span> <a name="l00364"></a>00364 magnitude = ceil( log10( fabs( mylow ) ) ); <a name="l00365"></a>00365 <a name="l00366"></a>00366 <span class="comment">// What this part does is go through the low, giving it round</span> <a name="l00367"></a>00367 <span class="comment">// numbers first, but more coarse over time.</span> <a name="l00368"></a>00368 <a name="l00369"></a>00369 <span class="keywordflow">do</span> { <a name="l00370"></a>00370 step = nice[i] * pow( 10.0, magnitude ); <a name="l00371"></a>00371 mylow = floor( low / step ) * step; <a name="l00372"></a>00372 myhigh = mylow + 1.05 * range_length; <a name="l00373"></a>00373 i--; <a name="l00374"></a>00374 <span class="keywordflow">if</span>( i < 0 ) { <a name="l00375"></a>00375 i = N_NICE - 1; <a name="l00376"></a>00376 magnitude--; <a name="l00377"></a>00377 } <a name="l00378"></a>00378 } <span class="keywordflow">while</span>( myhigh < high ); <a name="l00379"></a>00379 <a name="l00380"></a>00380 <a class="code" href="classhippodraw_1_1Range.html" title="Expresses a range of values.">Range</a> range ( mylow, myhigh, init_range.<a class="code" href="classhippodraw_1_1Range.html#a4b02f1648e2efd2c179f8398b350285b" title="Returns the first positive element in range.">pos</a>() ); <a name="l00381"></a>00381 <a name="l00382"></a>00382 axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a175253bfecf26b89ced34342b0f2a4b2" title="Sets the Range to overlap of the two ranges.">setIntersectRange</a> ( range, limit ); <a name="l00383"></a>00383 <a name="l00384"></a>00384 <span class="keywordflow">return</span> axis.<a class="code" href="classhippodraw_1_1AxisModelBase.html#a47adba99d1bb0dd9eb9800f931feb672" title="Returns the range represented by this AxisModel.">getRange</a>( <span class="keyword">false</span> ); <a name="l00385"></a>00385 } <a name="l00386"></a>00386 <a name="l00387"></a>00387 } <span class="comment">// namespace hippodraw</span> <a name="l00388"></a>00388 </pre></div></div> <hr size="1"><address style="align: right;"><small> Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0> </a> </small></address> </body> </html>