SMIL  0.9.1
DLineHistogram.hpp
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_LINE_HISTOGRAM_HPP
31 #define _D_LINE_HISTOGRAM_HPP
32 
33 
34 #include "DBaseLineOperations.hpp"
35 
36 namespace smil
37 {
38 
41 
42 
43  template <class T, class T_out=T>
44  struct threshLine : public unaryLineFunctionBase<T, T_out>
45  {
46  T minVal, maxVal;
47  T_out trueVal, falseVal;
48 
49  typedef typename unaryLineFunctionBase<T,T_out>::lineInType lineInType;
50  typedef typename unaryLineFunctionBase<T,T_out>::lineOutType lineOutType;
51 
52  virtual void _exec(const lineInType lIn, const size_t size, lineOutType lOut)
53  {
54  for(size_t i=0;i<size;i++)
55  lOut[i] = lIn[i] >= minVal && lIn[i] <= maxVal ? trueVal : falseVal;
56  }
57  };
58 
59  template <class Tin, class Tout>
60  struct stretchHistLine : public unaryLineFunctionBase<Tin, Tout>
61  {
62  Tin inOrig;
63  Tout outOrig;
64  double coeff;
65  typedef typename unaryLineFunctionBase<Tin>::lineType lineInType;
66  typedef typename unaryLineFunctionBase<Tout>::lineType lineOutType;
67 
68  virtual void _exec(const lineInType lIn, const size_t size, lineOutType lOut)
69  {
70  double newVal;
71 
72  for(size_t i=0;i<size;i++)
73  {
74  newVal = double(outOrig) + (double(lIn[i])-double(inOrig))*coeff;
75  if (newVal > double(numeric_limits<Tout>::max()))
76  newVal = numeric_limits<Tout>::max();
77  else if (newVal < double(numeric_limits<Tout>::min()))
78  newVal = numeric_limits<Tout>::min();
79  lOut[i] = Tout(round(newVal));
80 
81  }
82  }
83  };
84 
86 
87 } // namespace smil
88 
89 
90 #endif // _D_LINE_HISTOGRAM_HPP
Definition: DColorConvert.h:38
Definition: DLineHistogram.hpp:44
Definition: DBaseLineOperations.hpp:45
Definition: DLineHistogram.hpp:60