CVB++ 15.0
pharma_code.hpp
1#pragma once
2
3#include "reader_config_base.hpp"
4
5namespace Cvb
6{
7 CVB_BEGIN_INLINE_NS
8
9 namespace Barcode
10 {
11 using namespace Internal;
12
13
15
18 {
19 public:
21
27 {
28 if(direction_ != direction)
29 SetDirty();
30 direction_ = direction;
31 }
32
34
40 {
41 return direction_;
42 }
43
45
50 void SetMaxDigits(int maxDigits)
51 {
52 if(maxDigits < minDigitsLimit_ || maxDigits > maxDigitsLimit_ || maxDigits < minDigits_)
53 throw std::runtime_error("MaxDigits out of range [2, 16] or less then MinDigits");
54 if(maxDigits_ != maxDigits)
55 SetDirty();
56 maxDigits_ = static_cast<short>(maxDigits);
57 }
58
60
65 int MaxDigits() const
66 {
67 return maxDigits_;
68 }
69
70
72
77 void SetMinDigits(int minDigits)
78 {
79 if(minDigits < minDigitsLimit_ || minDigits > maxDigitsLimit_ || minDigits > maxDigits_)
80 throw std::runtime_error("MinDigits out of range [2, 16] or higher then MaxDigits");
81 if(minDigits_ != minDigits)
82 SetDirty();
83 minDigits_ = static_cast<short>(minDigits);
84 }
85
87
92 int MinDigits() const
93 {
94 return minDigits_;
95 }
96
98
103 void SetPixelReference(int pixelRef)
104 {
105 if(pixelRef < minPixelReferenceLimit_ || pixelRef > maxPixelReferenceLimit_)
106 throw std::runtime_error("PixelReference out of range [0, 1000]");
107 if(pixelRef_ != pixelRef)
108 SetDirty();
109 pixelRef_ = static_cast<short>(pixelRef);
110 }
111
113
118 int PixelReference() const
119 {
120 return pixelRef_;
121 }
122
124
129 void SetQuietzoneWidth(int quietzoneWidth)
130 {
131 if(quietzoneWidth < minQuietzoneWidthLimit_ || quietzoneWidth > maxQuietzoneWidthLimit_)
132 throw std::runtime_error("Quietzone width out of range [10, 200]");
133 if(quietzoneWidth_ != quietzoneWidth)
134 SetDirty();
135 quietzoneWidth_ = static_cast<short>(quietzoneWidth);
136 }
137
139
144 int QuietzoneWidth() const
145 {
146 return quietzoneWidth_;
147 }
148
150
155 void SetScaleFactor(int scaleFactor)
156 {
157 if(scaleFactor < minScaleFactorLimit_ || scaleFactor > maxScaleFactorLimit_)
158 throw std::runtime_error("Scale factor out of range [50, 200]");
159 if(scaleFactor_ != scaleFactor)
160 SetDirty();
161 scaleFactor_ = static_cast<short>(scaleFactor);
162 }
163
165
170 int ScaleFactor() const
171 {
172 return scaleFactor_;
173 }
174
175 //void SetSkew(PharmaCodeSkew skew)
176 //{
177 // if(skew_ != skew)
178 // SetDirty();
179 // skew_ = skew;
180 //}
181 //PharmaCodeSkew Skew() const
182 //{
183 // return skew_;
184 //}
185
186
188
193 void SetThreshold(int threshold)
194 {
195 if(threshold < 0 || threshold > 100)
196 throw std::runtime_error("Threshold out of range [0, 100]");
197 if(threshold_ != threshold)
198 SetDirty();
199 threshold_ = static_cast<short>(threshold);
200 }
201
203
208 int Threshold() const
209 {
210 return threshold_;
211 }
212
213 //void SetTolerance(PharmaCodeTolerance tolerance)
214 //{
215 // if(tolerance_ != tolerance)
216 // SetDirty();
217 // tolerance_ = tolerance;
218 //}
219 //PharmaCodeTolerance Tolerance() const
220 //{
221 // return tolerance_;
222 //}
223
224 protected:
225 PharmaCodeRunDirection direction_;
226 short maxDigits_;
227 short minDigits_;
228 short pixelRef_;
229 short quietzoneWidth_;
230 short scaleFactor_;
231 PharmaCodeSkew skew_;
232 short threshold_;
233
234
235 const short minDigitsLimit_ = 2;
236 const short maxDigitsLimit_ = 16;
237
238 const short minPixelReferenceLimit_ = 0;
239 const short maxPixelReferenceLimit_ = 1000;
240
241 const short minQuietzoneWidthLimit_ = 10;
242 const short maxQuietzoneWidthLimit_ = 200;
243
244 const short minScaleFactorLimit_ = 50;
245 const short maxScaleFactorLimit_ = 200;
246
247
248
249
250
251 public:
252 virtual Symbology Type() const override { return Symbology::PharmaCode; }
253
255
261 static std::unique_ptr<PharmaCode> FromHandle(const HandleGuard<ReaderConfig>& guard, bool& isActiveOut)
262 {
263 auto pConfig = std::unique_ptr<PharmaCode>(new PharmaCode());
264 isActiveOut = pConfig->ReadFromHandle(guard);
265 return pConfig;
266 }
267
268 protected:
269 virtual bool ReadFromHandle_(const HandleGuard<ReaderConfig>& guard) override
270 {
271 CExports::cvbbool_t active;
272 short tmpDirection;
273 CVB_CALL_CAPI(CvcBcGetPharmacode( reinterpret_cast<std::intptr_t>(guard.Handle()),
274 &active,
275 &tmpDirection,
276 &minDigits_,
277 &maxDigits_,
278 &scaleFactor_,
279 &quietzoneWidth_,
280 &pixelRef_,
281 &threshold_,
282 inverse_.Ptr()
283 ));
284 direction_ = static_cast<PharmaCodeRunDirection>(tmpDirection);
285 return SmartBool(active);
286 }
287
288 virtual void WriteToHandle_(bool active, HandleGuard<ReaderConfig>& guard) override
289 {
290 Internal::DoResCall([&]()
291 {
292 return CVB_CALL_CAPI(CvcBcSetPharmacode(reinterpret_cast<std::intptr_t>(guard.Handle()),
293 SmartBool(active),
294 static_cast<short>(direction_),
295 minDigits_,
296 maxDigits_,
297 scaleFactor_,
298 quietzoneWidth_,
299 pixelRef_,
300 threshold_,
301 inverse_
302 ));
303 });
304 }
305 protected:
306 PharmaCode()
307 : ReaderConfigBase()
308 {
309 }
310
311 };
312
313 using PharmaCodePtr = std::shared_ptr<PharmaCode>;
314 }
315
316 CVB_END_INLINE_NS
317}
Configuration to access parameters of ReaderConfigBase.
Definition: reader_config_base.hpp:20
Configuration to access parameters of PharmaCode.
Definition: pharma_code.hpp:18
void SetMinDigits(int minDigits)
Sets the minimum number of Pharmacode code words.
Definition: pharma_code.hpp:77
void SetDirection(PharmaCodeRunDirection direction)
Sets the run-direction in which the Pharmacode moves in the camera picture.
Definition: pharma_code.hpp:26
void SetPixelReference(int pixelRef)
Sets the illustration measure of the camera in a 10th of a pixel per millimetre.
Definition: pharma_code.hpp:103
static std::unique_ptr< PharmaCode > FromHandle(const HandleGuard< ReaderConfig > &guard, bool &isActiveOut)
Create object from handle.
Definition: pharma_code.hpp:261
int MaxDigits() const
Returns the maximum number of Pharmacode code words.
Definition: pharma_code.hpp:65
int MinDigits() const
Returns the minimum number of Pharmacode code words.
Definition: pharma_code.hpp:92
int ScaleFactor() const
Returns the scale factor of the Pharmacode in %.
Definition: pharma_code.hpp:170
PharmaCodeRunDirection Direction() const
Returns the run-direction in which the Pharmacode moves in the camera picture.
Definition: pharma_code.hpp:39
int PixelReference() const
Returns the illustration measure of the camera in a 10th of a pixel per millimetre.
Definition: pharma_code.hpp:118
int QuietzoneWidth() const
Returns the minimal quiet zone in a 10th of a millimetre.
Definition: pharma_code.hpp:144
void SetQuietzoneWidth(int quietzoneWidth)
Sets the minimal quiet zone in a 10th of a millimetre.
Definition: pharma_code.hpp:129
void SetThreshold(int threshold)
Sets the digitalisation threshold in percent ranging from 0 to 100 (default 10).
Definition: pharma_code.hpp:193
int Threshold() const
Returns the digitalisation threshold in percent ranging from 0 to 100 (default 10).
Definition: pharma_code.hpp:208
void SetScaleFactor(int scaleFactor)
Sets the scale factor of the Pharmacode in percent.
Definition: pharma_code.hpp:155
void SetMaxDigits(int maxDigits)
Sets the maximum number of Pharmacode code words.
Definition: pharma_code.hpp:50
PharmaCodeSkew
Skew of the Pharma Code bars.
Definition: barcode.hpp:345
Symbology
The symbologies supported by Barcode.
Definition: barcode.hpp:97
@ PharmaCode
PharmaCode Barcode.
PharmaCodeRunDirection
Run direction of Pharma Codes.
Definition: barcode.hpp:272
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24