processAttribs.c
1 #include
2 #include "global.h"
3 #include "graphicsData.h"
4 #include "trees.h"
5
6 /********************************************************************
7 * pickAttribColor:
8 * Determines what shade of the base color (startColor) should
9 * be assigned for the given value based on its position in the
10 * range (min to max). Min would have the color black, max the
11 * color white, and values in the middle would have dark to
12 * light shades for small to large values, respectively.
13 ********************************************************************/
14
15 void pickAttribColor (float value, float min, float max, eco_color startColor, eco_color *newColor)
16 {
17 float range;
18 float half;
19 float midpoint;
20 float percent;
21 float temp;
22 bool red = FALSE,
23 green = FALSE,
24 blue = FALSE;
25 int i;
26
27 /*** keep track of the startColor ***/
28 if (startColor.red == 1.0)
29 red = TRUE;
30 if (startColor.green == 1.0)
31 green = TRUE;
32 if (startColor.blue == 1.0)
33 blue = TRUE;
34
35 /*** calculate the percentage of the range the value takes up ***/
36 range = fabs (max - min);
37 half = range/2.0;
38 midpoint = min + half;
39 if ((temp = fabs(value - min)) == 0.0)
40 percent = 0.0;
41 else
42 percent = temp/max;
43
44 /*** choose a shade according to the percentage ***/
45 if (percent <= 0.5) {
46 newColor->red = newColor->green = newColor->blue = 0.0;
47 if (red)
48 newColor->red = 2.0*percent;
49 if (green)
50 newColor->green = 2.0*percent;
51 if (blue)
52 newColor->blue = 2.0*percent;
53 } else {
54 newColor->red = startColor.red;
55 newColor->green = startColor.green;
56 newColor->blue = startColor.blue;
57 if (!red)
58 newColor->red = percent;
59 if (!green)
60 newColor->green = percent;
61 if (!blue)
62 newColor->blue = percent;
63 }
64 }
65
66 /********************************************************************
67 * setLeafAttributeRange:
68 * Steps through the leaves linked list and finds the minimum
69 * and maximum values for the given leaf type (lfType).
70 ********************************************************************/
71
72 void setLeafAttributeRange (lfStructPtr L, eco_leafType lfType, float *min, float *max)
73 {
74 char ch;
75 longstring line;
76 string temp, minStr, maxStr, last;
77 float value;
78 int i;
79 lfStructPtr lf = L;
80 bool first = TRUE;
81 strcpy (minStr, "0.0");
82 strcpy (maxStr, "0.0");
83
84 while (L != NULL) {
85 switch (lfType) {
86 case PSYN :
87 value = L->psyn; break;
88 case SHADE :
89 value = L->shade; break;
90 case LPI :
91 value = L->lpi; break;
92 case PPFDSUN :
93 value = L->ppfdSUN; break;
94 case PPFDSHADE :
95 value = L->ppfdSHADE; break;
96 }
97 if (first) {
98 *min = *max = value;
99 first = FALSE;
100 } else {
101 if (value > *max) {
102 *max = value;
103 strcpy (maxStr, temp);
104 } else if (value < *min) {
105 *min = value;
106 strcpy (minStr, temp);
107 }
108 }
109 L = L->next;
110 }
111 }
112
113 /********************************************************************
114 * setRootAttributeRange:
115 * Steps through the roots linked list and finds the minimum
116 * and maximum values for the given root type (ryType).
117 ********************************************************************/
118
119 void setRootAttributeRange (rtSegPtr R, eco_rootType rtType, float *min, float *max)
120 {
121 FILE *fp;
122 char ch;
123 longstring line;
124 string temp, minStr, maxStr, last;
125 float value;
126 int i;
127 bool first = TRUE;
128 strcpy (minStr, "0.0");
129 strcpy (maxStr, "0.0");
130 while (R != NULL) {
131 switch (rtType) {
132 case DIAM :
133 value = R->diameter; break;
134 case ORDER :
135 value = R->order; break;
136 case RHO :
137 value = R->rho; break;
138 }
139 if (first) {
140 *min = *max = value;
141 first = FALSE;
142 } else {
143 if (value >= *max) {
144 *max = value;
145 strcpy (maxStr, temp);
146 } else if (value < *min) {
147 *min = value;
148 strcpy (minStr, temp);
149 }
150 }
151 R = R->next;
152 }
153 }
154
155 /******************** end of processAttribs.c **************************/
156