Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageValueBar.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include "ImageValueBar.hh"
26 #include <Base/Math/Vector3.hh>
27 #include <Base/Image/ImageConvert.hh>
28 #include <Base/ImageUtils/ImageDraw.hh>
29 
30 
31 using namespace BIAS;
32 using namespace std;
33 
34 template <class StorageType>
36 ImageValueBar() : Image<StorageType>()
37 {
39  minDisplay_= minValue_ = 0.0;
40  maxDisplay_= maxValue_ = 255.0;
41  ticks_=10;
42  unit_="mm";
43 }
44 
45 
46 template<class StorageType>
49 }
50 
51 
52 template<class StorageType>
55  unsigned width = this->GetWidth();
56  unsigned height = this->GetHeight();
57  if(width < 100){
58  this->ReInit(100,height);
59  }
60 
61  unsigned barArea = width-80;
62  unsigned channels = this->GetChannelCount();
63  this->FillImageWithConstValue(this->MaxSTValue());
64 
65  //std::cout<<"Update: dimension "<<width<<","<<height<<","<<channels<<std::endl;
66  double step = (maxValue_-minValue_)/(double)height;
67  //std::cout<<"Min, max, step "<<minValue_<<","<<maxValue_<<","<<step<<std::endl;
68 
69 
70  StorageType **ida = this->GetImageDataArray();
71  // check which desired output model is requested and
72  // fill values
73  switch(model_){
74  case ImageBase::CM_Grey:
75  {
76  //go from top to bottom
77  for(unsigned y =0;y<height;y++){
78  for(unsigned x = 0;x<barArea;x++){
79  for(unsigned c=0;c<channels;c++){
80  ida[y][x*channels+c] = (StorageType)(maxValue_- step*(double)y);
81  }
82  }
83  }
84  }
85  break;
86  case ImageBase::CM_RGB:
87  //go from top to bottom
88  for(unsigned y =0;y<height;y++){
89  for(unsigned x = 0;x<barArea;x++){
90  for(unsigned c=0;c<channels;c++){
91  ida[y][x*channels+c] = (StorageType)(maxValue_- step*(double)y);
92  }
93  }
94  }
95  break;
96  case ImageBase::CM_HSV:
97  {
98  BIASWARN("This doesn't make sense right now, but maybe in the future?");
99  BIAS::Vector3<float> rgbF(0,0,0);
100  BIAS::Vector3<float> hsv(0,1,1);
101  //go from top to bottom
102  for(unsigned y =0;y<height;y++){
103  for(unsigned x = 0;x<barArea;x++){
104  hsv[0] = (float)((height-y))/2;
105  ImageConvert::HSVToRGB(hsv[0],hsv[1],hsv[2],rgbF[0],rgbF[1],rgbF[2]);
106  for(unsigned c=0;c<channels;c++){
107  ida[y][x*channels+c] = StorageType(rgbF[c]);
108  }
109  }
110  }
111  }
112  break;
113  default:
114  BIASERR("Unimplemented!");
115  }
116 
117  ////////////////////Draw ticks //////////////////
118  int spacing = ((int)height)/ticks_;
119  double stepDisplay = (maxDisplay_-minDisplay_)/(double)height;
120  //std::cout<<"Min, max, step DISPLAY"<<minDisplay_<<","<<maxDisplay_<<","<<stepDisplay<<std::endl;
121  for(int i=0;i<ticks_;i++){
122  int startX = barArea;
123  int startY = height-1-spacing*i;
124  int stopX = barArea+5;
125  int stopY = height-1-spacing*i;
126  ImageDraw<StorageType>::Line(*this,startX,startY, //startx, starty
127  stopX,stopY );//stopx, stopy
128  int value = (int)rint(minDisplay_+stepDisplay*spacing*i);
129  stringstream tx;
130  tx<< value;
131  tx<<unit_;
132  //black
133  const ColourRGB< StorageType > colorRGB(0, 0, 0);
134  if(this->GetStorageType() == ImageBase::ST_float ||
135  this->GetChannelCount() == 1)
136  {
137  ImageDraw<StorageType>::Text(*this,tx.str(),barArea+5,
138  (int)(height)-3-spacing*i,
139  colorRGB);//,CV_FONT_HERSHEY_COMPLEX_SMALL,0.7,0.7);
140  }
141  else{
142  ImageDraw<StorageType>::TextIM(*this,tx.str(),barArea+5,
143  (int)(height)-2-spacing*i,
144  colorRGB);
145  }
146  }
147 }
148 
149 
150 #define INSTANCE_Image(type)\
151 template class BIASUtils_EXPORT ImageValueBar<type>;
152 
153 // create instances
154 namespace BIAS{
155 INSTANCE_Image(unsigned char)
156 INSTANCE_Image(float)
157 #ifdef BUILD_IMAGE_INT
158 INSTANCE_Image(int)
159 #endif
160 #ifdef BUILD_IMAGE_CHAR
161 INSTANCE_Image(char)
162 #endif
163 #ifdef BUILD_IMAGE_SHORT
164 INSTANCE_Image(short)
165 #endif
166 #if defined(BUILD_IMAGE_USHORT)
167 INSTANCE_Image(unsigned short)
168 #endif
169 #ifdef BUILD_IMAGE_DOUBLE
170 INSTANCE_Image(double)
171 #endif
172 #ifdef BUILD_IMAGE_UINT
173 INSTANCE_Image(unsigned int)
174 #endif
175 }
gray values, 1 channel
Definition: ImageBase.hh:130
ImageBase::EColorModel model_
float image storage type
Definition: ImageBase.hh:118
interface class used to ease handover in function calls
Definition: ColourRGB.hh:34
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
Definition: ImageDraw.cpp:404
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
static BIASImageBase_EXPORT int HSVToRGB(const StorageType h, const StorageType s, const StorageType v, StorageType &r, StorageType &g, StorageType &b)
conversion of one pixel in HSV to RGB colorspace
Definition: ToHSV.cpp:434
The image template class for specific storage types.
Definition: Image.hh:78
HSV, 3 channels, order: hue, sat , value.
Definition: ImageBase.hh:138
static void TextIM(BIAS::Image< StorageType > &dstImg, const std::string &message, const int &posX=0, const int &posY=20, const ColourRGB< StorageType > &colorRGB=ColourRGB< StorageType >(255, 255, 255), const double hscale=1.0, const double vscale=1.0, const double shear=0, const int thickness=1, const int linetype=8)
ImageMagick: Draw Text into image.
Definition: ImageDraw.cpp:1426
static void Text(BIAS::Image< StorageType > &dstImg, const std::string &message, const int &posX=0, const int &posY=20, const ColourRGB< StorageType > &colorRGB=ColourRGB< StorageType >(255, 255, 255), const int fontface=1, const double hscale=1.0, const double vscale=1.0, const double shear=0, const int thickness=1, const int linetype=8)
OpenCV: Draw Text into image.
Definition: ImageDraw.cpp:1384