SMIL  0.9.1
DLineArith_RGB.h
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
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 #ifndef _D_LINE_ARITH_RGB_H
33 #define _D_LINE_ARITH_RGB_H
34 
35 
36 #include "Base/include/private/DLineArith.hpp"
37 #include "Core/include/DColor.h"
38 
45 namespace smil
46 {
47  template <>
48  inline void copyLine<RGB>(const unaryLineFunctionBase<RGB>::lineInType lIn, const size_t size, unaryLineFunctionBase<RGB>::lineInType lOut)
49  {
50  for (UINT n=0;n<3;n++)
51  memcpy(lOut.arrays[n], lIn.arrays[n], size*sizeof(UINT8));
52  }
53 
54  template <class T1>
55  RES_T copy(const Image<T1> &/*imIn*/, size_t /*startX*/, size_t /*startY*/, size_t /*startZ*/, size_t /*sizeX*/, size_t /*sizeY*/, size_t /*sizeZ*/, Image<RGB> &/*imOut*/, size_t /*outStartX*/=0, size_t /*outStartY*/=0, size_t /*outStartZ*/=0)
56  {
57  return RES_ERR;
58  }
59 
60  template <>
61  inline void shiftLine(const unaryLineFunctionBase<RGB>::lineInType lIn, int dx, size_t lineLen, unaryLineFunctionBase<RGB>::lineInType lOut, RGB borderValue)
62  {
63  for (UINT n=0;n<3;n++)
64  shiftLine<UINT8>(lIn.arrays[n], dx, lineLen, lOut.arrays[n], borderValue[n]);
65  }
66 
67  template <>
68  struct fillLine<RGB> : public unaryLineFunctionBase<RGB>
69  {
70  typedef Image<RGB>::lineType lineType;
71  fillLine() {}
72  fillLine(const lineType lIn, const size_t size, const RGB value) { this->_exec(lIn, size, value); }
73 
74  virtual void _exec(const lineType lIn, const size_t size, lineType lOut)
75  {
76  copyLine<RGB>(lIn, size, lOut);
77  }
78  virtual void _exec(lineType lInOut, const size_t size, const RGB value)
79  {
80  for (UINT n=0;n<3;n++)
81  {
82  UINT8 *cArr = lInOut.arrays[n];
83  UINT8 val = value[n];
84  for (size_t i=0;i<size;i++)
85  cArr[i] = val;
86  }
87 
88  }
89  };
90 
91 
92  template <>
93  double vol(const Image<RGB> &imIn);
94 
95 // template <>
96 // std::map<RGB, UINT> histogram(const Image<RGB> &imIn);
97 
98 
99  template <>
100  struct supLine<RGB> : public binaryLineFunctionBase<RGB>
101  {
102  typedef Image<RGB>::lineType lineType;
103  inline void _exec(const lineType lIn1, const lineType lIn2, const size_t size, lineType lOut)
104  {
105  for (UINT n=0;n<3;n++)
106  {
107  UINT8 *cArrIn1 = lIn1.arrays[n];
108  UINT8 *cArrIn2 = lIn2.arrays[n];
109  UINT8 *cArrOut = lOut.arrays[n];
110 
111  for (size_t i=0;i<size;i++)
112  cArrOut[i] = cArrIn1[i] > cArrIn2[i] ? cArrIn1[i] : cArrIn2[i];
113  }
114  }
115  };
116 
117  template <>
118  struct infLine<RGB> : public binaryLineFunctionBase<RGB>
119  {
120  typedef Image<RGB>::lineType lineType;
121  virtual void _exec(const lineType lIn1, const lineType lIn2, const size_t size, lineType lOut)
122  {
123  for (UINT n=0;n<3;n++)
124  {
125  UINT8 *cArrIn1 = lIn1.arrays[n];
126  UINT8 *cArrIn2 = lIn2.arrays[n];
127  UINT8 *cArrOut = lOut.arrays[n];
128 
129  for (size_t i=0;i<size;i++)
130  cArrOut[i] = cArrIn1[i] < cArrIn2[i] ? cArrIn1[i] : cArrIn2[i];
131  }
132  }
133  };
134 
135  template <>
136  struct equLine<RGB> : public binaryLineFunctionBase<RGB>
137  {
138  equLine()
139  : trueVal(numeric_limits<UINT8>::max()), falseVal(0) {}
140 
141  UINT8 trueVal, falseVal;
142 
143  typedef Image<RGB>::lineType lineType;
144  virtual void _exec(const lineType lIn1, const lineType lIn2, const size_t size, lineType lOut)
145  {
146  for (UINT n=0;n<3;n++)
147  {
148  UINT8 *cArrIn1 = lIn1.arrays[n];
149  UINT8 *cArrIn2 = lIn2.arrays[n];
150  UINT8 *cArrOut = lOut.arrays[n];
151 
152  for (size_t i=0;i<size;i++)
153  cArrOut[i] = cArrIn1[i] == cArrIn2[i] ? trueVal : falseVal;
154  }
155  }
156  };
157 
158 } // namespace smil
159 
162 #endif // _D_LINE_ARITH_RGB_H
Definition: DColorConvert.h:38
RES_T copy(const Image< T1 > &imIn, size_t startX, size_t startY, size_t startZ, size_t sizeX, size_t sizeY, size_t sizeZ, Image< T2 > &imOut, size_t outStartX=0, size_t outStartY=0, size_t outStartZ=0)
Copy image.
Definition: DImageArith.hpp:114
double vol(const Image< T > &imIn)
Volume of an image.
Definition: DMeasures.hpp:96
Definition: DLineArith.hpp:166
Definition: DBaseLineOperations.hpp:45
Definition: DBaseImageOperations.hxx:39
Main Image class.
Definition: DQVtkViewer.hpp:44
Definition: DLineArith.hpp:337
Definition: DLineArith.hpp:177
Definition: DBaseLineOperations.hpp:109
Definition: DColor.h:84