1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawPlot_axes.c,v $
37 * Date : $Date: 2003/10/01 16:02:47 $
38 * Version : $Revision: 1.2 $
39 * CVS Id : $Id: drawPlot_axes.c,v 1.2 2003/10/01 16:02:47 tony Exp $
40 *
41 * Author : Legacy TINA
42 *
43 * Notes :
44 *
45 *********
46 */
47
48 #include "drawPlot_axes.h"
49
50 #if HAVE_CONFIG_H
51 #include <config.h>
52 #endif
53
54 #include <math.h>
55 #include <tina/sys/sysDef.h>
56 #include <tina/sys/sysPro.h>
57 #include <tina/math/mathDef.h>
58 #include <tina/geometry/geomDef.h>
59 #include <tinatool/draw/draw_TvDef.h>
60 #include <tinatool/draw/draw_PlotDef.h>
61 #include <tinatool/draw/draw_PlotPro.h>
62
63 double fvector_min();
64 double fvector_max();
65
66 double pl_get_pos(double amin, double amax)
67 {
68 double apos;
69
70 if (amin == 0.0 || amax == 0.0)
71 apos = 0.0;
72 else if (amin < 0.0 && amax > 0.0)
73 apos = 0.0;
74 else if (amin > 0.0)
75 apos = amin;
76 else if (amax < 0.0)
77 apos = amax;
78
79 return (apos);
80 }
81
82 void pl_scale(double *amin, double *amax, double *ainc, double *apos)
83 {
84 double bmin, bmax, binc, binc_exp, binc_mag;
85
86 bmin = *amin;
87 bmax = *amax;
88
89 if (bmin > 0.0 && bmin <= 0.25 * bmax)
90 bmin = 0.0;
91 else if (bmax < 0.0 && bmax >= 0.25 * bmin)
92 bmax = 0.0;
93
94 binc = (bmax - bmin) / 5.0;
95 if (binc == 0.0)
96 binc = 1.0;
97 binc_exp = pow(10.0, floor(log10(binc)));
98 binc_mag = binc / binc_exp;
99
100 if (binc_mag < 2.0)
101 binc_mag = 1.0;
102 else if (binc_mag < 5.0)
103 binc_mag = 2.0;
104 else
105 binc_mag = 5.0;
106
107 binc = binc_mag * binc_exp;
108 if ((bmax-bmin)/binc > 8.0) binc *= 2.0;
109
110 bmin = binc * ceil(bmin / binc); /* avoid too small first */
111 if (bmin > *amin)
112 bmin -= binc;
113 bmax = binc * ceil(bmax / binc);
114
115 *amin = bmin;
116 *amax = bmax;
117 *ainc = binc;
118 *apos = pl_get_pos(bmin, bmax);
119 }
120
121
122 void pl_scale_xdata(List * list, double *xmin, double *xmax, double *xinc, double *xpos)
123 {
124 List *ptr;
125
126 *xmin = 1e10;
127 *xmax = -1e10;
128 for (ptr = list; ptr != NULL; ptr = ptr->next)
129 {
130 switch (ptr->type)
131 {
132 case PL_GRAPH_TYPE:
133 {
134 Pl_graph *graph = (Pl_graph *) ptr->to;
135
136 *xmin = MIN(*xmin, fvector_min(graph->x, 0, graph->n));
137 *xmax = MAX(*xmax, fvector_max(graph->x, 0, graph->n));
138 break;
139 }
140 case PL_SCATTER_TYPE:
141 {
142 Pl_graph *graph = (Pl_graph *) ptr->to;
143
144 *xmin = MIN(*xmin, fvector_min(graph->x, 0, graph->n));
145 *xmax = MAX(*xmax, fvector_max(graph->x, 0, graph->n));
146 break;
147 }
148 case PL_CTR_TYPE:
149 {
150 Pl_ctr *ctr = (Pl_ctr *) ptr->to;
151
152 *xmin = MIN(*xmin, fvector_min(ctr->x, 0, ctr->nx));
153 *xmax = MAX(*xmax, fvector_max(ctr->x, 0, ctr->nx));
154 break;
155 }
156 }
157 }
158 if(*xmax == *xmin)
159 {
160 *xmin -= 1;
161 *xmax += 1;
162 }
163
164 pl_scale(xmin, xmax, xinc, xpos);
165 }
166
167 void pl_scale_ydata(List * list, double *ymin, double *ymax, double *yinc, double *ypos)
168 {
169 List *ptr;
170
171 *ymin = 1e10;
172 *ymax = -1e10;
173 for (ptr = list; ptr != NULL; ptr = ptr->next)
174 {
175 switch (ptr->type)
176 {
177 case PL_GRAPH_TYPE:
178 {
179 Pl_graph *graph = (Pl_graph *) ptr->to;
180
181 *ymin = MIN(*ymin, fvector_min(graph->y, 0, graph->n));
182 *ymax = MAX(*ymax, fvector_max(graph->y, 0, graph->n));
183 break;
184 }
185 case PL_SCATTER_TYPE:
186 {
187 Pl_graph *graph = (Pl_graph *) ptr->to;
188
189 *ymin = MIN(*ymin, fvector_min(graph->y, 0, graph->n));
190 *ymax = MAX(*ymax, fvector_max(graph->y, 0, graph->n));
191 break;
192 }
193 case PL_CTR_TYPE:
194 {
195 Pl_ctr *ctr = (Pl_ctr *) ptr->to;
196
197 *ymin = MIN(*ymin, fvector_min(ctr->y, 0, ctr->ny));
198 *ymax = MAX(*ymax, fvector_max(ctr->y, 0, ctr->ny));
199 break;
200 }
201 }
202 }
203 if(*ymax == *ymin)
204 {
205 *ymin -= 1;
206 *ymax += 1;
207 }
208 pl_scale(ymin, ymax, yinc, ypos);
209 }
210
211 void pl_scale_axes(List * list, Pl_axes * axes)
212 {
213 if (axes->xscale)
214 pl_scale_xdata(list, &axes->xmin, &axes->xmax, &axes->xinc, &axes->xpos);
215 if (axes->yscale)
216 pl_scale_ydata(list, &axes->ymin, &axes->ymax, &axes->yinc, &axes->ypos);
217 }
218
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.