COPASI API  4.16.103
CColorScale.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/UI/CColorScale.cpp,v $
3 // $Revision: 1.3 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 21:12:27 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #include <cmath>
20 
21 #include "CColorScale.h"
22 
24  : m1(1e-4)
25 {}
26 
27 //virtual
28 QColor CColorScale1::getColor(const C_FLOAT64 & number)
29 {
30  QColor color;
31 
32  if (fabs(number) < m1)
33  color = QColor(250, 250, 250);
34  else if (number > 0)
35  color = QColor(200, 255, 200);
36  else
37  color = QColor(255, 200, 200);
38 
39  return color;
40 }
41 
42 //**************************
43 
45  : mMin(0.0),
46  mMax(1.0),
47  mLog(false),
48  mSym(false)
49 {}
50 
51 //virtual
52 QColor CColorScaleSimple::getColor(const C_FLOAT64 & number)
53 {
54  C_FLOAT64 tmp = (number - mMin) / (mMax - mMin); //scale to 0..1
55 
56  if (tmp > 1) tmp = 1;
57 
58  if (tmp < 0) tmp = 0;
59 
60  int r = 0;
61  int g = 0;
62  int b = 0;
63 
64  if (tmp != tmp)
65  {
66  r = 85;
67  g = 85;
68  b = 135;
69  }
70  else if (tmp < 0.5)
71  {
72  r = 255;
73  g = (int)(255 + (tmp - 0.5) * 260);
74  b = (int)(255 + (tmp - 0.5) * 260);
75  }
76  else
77  {
78  r = (int)(255 - (tmp - 0.5) * 260);
79  g = 255;
80  b = (int)(255 - (tmp - 0.5) * 260);
81  }
82 
83  QColor color(r, g, b);
84  return color;
85 }
86 
87 //virtual
89 {
92 }
93 
94 //virtual
96 {
97  if (number > mMax) mMax = number;
98 
99  if (number < mMin) mMin = number;
100 }
101 
102 //virtual
104 {
105  if (mSym)
106  {
107  C_FLOAT64 tmp;
108 
109  if (fabs(mMax) > fabs(mMin))
110  tmp = fabs(mMax);
111  else
112  tmp = fabs(mMin);
113 
114  mMin = - tmp;
115  mMax = tmp;
116  }
117 
118  if (mMin == mMax)
119  {
120  mMin -= 1e-5;
121  mMax += 1e-5;
122  }
123 }
124 
125 //**************************
126 
129 {
130  mColorMax = QColor(0, 255, 0);
131  mColorMin = QColor(240, 240, 240);
132 }
133 
135 {
136  mColorMin = col;
137 }
138 
140 {
141  mColorMax = col;
142 }
143 
145 {
146  C_FLOAT64 tmp = (number - mMin) / (mMax - mMin); //scale to 0..1
147 
148  if (tmp > 1) tmp = 1;
149 
150  if (tmp < 0) tmp = 0;
151 
152  int r = (int)(mColorMin.red() * (1 - tmp) + mColorMax.red() * tmp);
153  int g = (int)(mColorMin.green() * (1 - tmp) + mColorMax.green() * tmp);
154  int b = (int)(mColorMin.blue() * (1 - tmp) + mColorMax.blue() * tmp);
155 
156  QColor color(r, g, b);
157  return color;
158 }
159 
160 //**************************
161 
163  : CColorScaleSimple(),
164  mFactor(3.0),
165  mFloat(0.0),
166  mInt(0)
167 {}
168 
169 //virtual
171 {
172  mInt = 0;
173  mFloat = 0;
174 }
175 
176 //virtual
178 {
179  if (number != number) return; //NaN
180 
181  if (fabs(number) >= std::numeric_limits< C_FLOAT64 >::max()) return; //Inf
182 
183  ++mInt;
184  mFloat += fabs(number);
185 }
186 
187 //virtual
189 {
190  if (mInt)
191  mMax = mFactor * mFloat / mInt;
192  else
193  mMax = mFactor;
194 
195  mMin = -mMax;
196 
197  if (mMin == mMax)
198  {
199  mMin -= 1e-5;
200  mMax += 1e-5;
201  }
202 }
203 
204 //**************************
205 
207  : m1(-6.0),
208  m2(2.0),
209  mFloat(0.0),
210  mInt(0)
211 {}
212 
213 //virtual
214 QColor CColorScaleBiLog::getColor(const C_FLOAT64 & number)
215 {
216  C_FLOAT64 logtmp = log(fabs(number));
217 
218  C_FLOAT64 tmp = (logtmp - m1) / (m2 - m1); //scale to 0..1
219 
220  if (tmp > 1) tmp = 1;
221 
222  if (tmp < 0) tmp = 0;
223 
224  if (number > 0)
225  tmp = 0.5 + tmp * 0.5;
226  else
227  tmp = 0.5 - tmp * 0.5;
228 
229  int r = 0;
230  int g = 0;
231  int b = 0;
232 
233  if (tmp != tmp)
234  {
235  r = 85;
236  g = 85;
237  b = 135;
238  }
239  else if (tmp < 0.5)
240  {
241  r = 255;
242  g = (int)(255 + (tmp - 0.5) * 260);
243  b = (int)(255 + (tmp - 0.5) * 260);
244  }
245  else
246  {
247  r = (int)(255 - (tmp - 0.5) * 260);
248  g = 255;
249  b = (int)(255 - (tmp - 0.5) * 260);
250  }
251 
252  QColor color(r, g, b);
253  return color;
254 }
255 
256 //virtual
258 {
261  mFloat = 0.0;
262  mInt = 0;
263 }
264 
265 //virtual
267 {
268  if (number != number) return; //NaN
269 
270  if (fabs(number) >= std::numeric_limits< C_FLOAT64 >::max()) return; //Inf
271 
272  if (number == 0.0) return;
273 
274  C_FLOAT64 tmp = log(fabs(number));
275 
276  //minmax
277  if (tmp > m2) m2 = tmp;
278 
279  if (tmp < m1) m1 = tmp;
280 
281  //average
282  ++mInt;
283  mFloat += tmp;
284 }
285 
286 //virtual
288 {
289  if (mInt != 0)
290  m1 = (mFloat / mInt) - 4;
291  else
292  m1 = -4.0;
293 
294  m2 -= 1.0;
295 }
296 
297 void CColorScaleBiLog::setWhitepoint(const C_FLOAT64 & n) {m1 = log(n);}
298 
void setWhitepoint(const C_FLOAT64 &n)
C_FLOAT64 m1
Definition: CColorScale.h:92
virtual void startAutomaticParameterCalculation()
virtual void finishAutomaticParameterCalculation()
void setColorMax(QColor col)
virtual void passValue(const C_FLOAT64 &number)
Definition: CColorScale.cpp:95
virtual void passValue(const C_FLOAT64 &number)
virtual void passValue(const C_FLOAT64 &number)
virtual QColor getColor(const C_FLOAT64 &number)
Definition: CColorScale.cpp:52
void setColorMin(QColor col)
virtual void finishAutomaticParameterCalculation()
virtual QColor getColor(const C_FLOAT64 &number)
virtual QColor getColor(const C_FLOAT64 &number)
Definition: CColorScale.cpp:28
#define C_FLOAT64
Definition: copasi.h:92
void setMaxIntensityPoint(const C_FLOAT64 &n)
virtual void startAutomaticParameterCalculation()
virtual void finishAutomaticParameterCalculation()
virtual void startAutomaticParameterCalculation()
Definition: CColorScale.cpp:88
C_FLOAT64 mFloat
Definition: CColorScale.h:208
virtual QColor getColor(const C_FLOAT64 &number)
#define max(a, b)
Definition: f2c.h:176