COPASI API  4.16.103
qwt3dColor.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/barChart/qwt3dColor.cpp,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: akoenig $
6 // $Date: 2007/11/20 08:32:24 $
7 // End CVS Header
8 
9 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 #include "qwt3dColor.h"
14 #include <iostream>
15 
16 BarColor::BarColor(Qwt3D::Plot3D* data, unsigned size, double min, double max)
17  : data_(data)
18 {
19  Q_ASSERT(data_);
20  reset(size);
21 
22  minZ = min;
23  maxZ = max;
24 }
25 
26 void BarColor::reset(unsigned size)
27 {
28  unsigned int i;
29  colors_ = Qwt3D::ColorVector(size);
30  Qwt3D::RGBA elem;
31 
32  double dsize = size;
33 
34  for (i = 0; i != size; ++i)
35  {
36  elem.r = i / dsize;
37  elem.g = i / dsize / 4;
38  elem.b = 1 - i / dsize;
39  elem.a = 1.0;
40  colors_[i] = elem;
41  }
42 }
43 
44 /**
45  * Assigns a new ColorVector (Also overwrites the constructors size argument)
46  */
47 void BarColor::setColorVector(Qwt3D::ColorVector const& cv)
48 {
49  colors_ = cv;
50 }
51 
52 void BarColor::setAlpha(double a)
53 {
54  unsigned int i;
55 
56  if (a < 0 || a > 1)
57  return;
58 
59  Qwt3D::RGBA elem;
60 
61  for (i = 0; i != colors_.size(); ++i)
62  {
63  elem = colors_[i];
64  elem.a = a;
65  colors_[i] = elem;
66  }
67 }
68 
69 Qwt3D::RGBA BarColor::operator()(double, double, double z) const
70  {
71  Q_ASSERT(data_);
72 
73  int index = (int)((colors_.size() - 1) * (z - minZ) / (maxZ - minZ));
74  if (index < 0)
75  index = 0;
76  if ((unsigned int)index > colors_.size() - 1)
77  index = (int)(colors_.size() - 1);
78  return colors_[index];
79  }
Qwt3D::Plot3D * data_
Definition: qwt3dColor.h:39
void setAlpha(double a)
Sets unitary alpha value for all colors.
Definition: qwt3dColor.cpp:52
void setColorVector(Qwt3D::ColorVector const &cv)
Definition: qwt3dColor.cpp:47
double maxZ
Definition: qwt3dColor.h:35
Qwt3D::ColorVector colors_
Definition: qwt3dColor.h:38
double minZ
Definition: qwt3dColor.h:36
BarColor(Qwt3D::Plot3D *data, unsigned size=100, double min=0, double max=0)
Initializes with data and set up a ColorVector with a size of 100 z values (default);.
Definition: qwt3dColor.cpp:16
void reset(unsigned size=100)
Resets the standard colors;.
Definition: qwt3dColor.cpp:26
#define min(a, b)
Definition: f2c.h:175
Qwt3D::RGBA operator()(double x, double y, double z) const
Receives z-dependend color from ColorVector.
Definition: qwt3dColor.cpp:69
#define max(a, b)
Definition: f2c.h:176