Argus API
Argus Camera API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _ARGUS_TYPES_H
30 #define _ARGUS_TYPES_H
31 
32 /**
33  * @file Types.h
34  * Defines the basic types that are used by the API.
35  */
36 
37 #include <stdint.h>
38 #include <vector>
39 #include <string>
40 #include <assert.h>
41 
42 #include <EGL/egl.h>
43 #include <EGL/eglext.h>
44 
45 // Some versions of the Xlib.h header file define 'Status' to 'int'. This collides with the Argus
46 // 'Status' type.
47 // If 'Status' is defined then undefine it and use a typedef instead.
48 #ifdef Status
49 #undef Status
50 typedef int Status;
51 #endif // Status
52 
53 namespace Argus
54 {
55 
56 /*
57  * Forward declaration of standard objects
58  */
59 class CameraDevice;
60 class CameraProvider;
61 class CaptureSession;
62 class CaptureMetadata;
63 class CaptureMetadataContainer;
64 class Event;
65 class EventQueue;
66 class InputStream;
67 class OutputStream;
68 class OutputStreamSettings;
69 class Request;
70 class SensorMode;
71 
72 /*
73  * Forward declaration of standard interfaces
74  */
75 class ICameraProperties;
76 class ICameraProvider;
77 class ICaptureSession;
78 class IAutoControlSettings;
79 class IRequest;
80 class IStream;
81 class IStreamSettings;
82 
83 /**
84  * Constant used for infinite timeouts.
85  */
86 const uint64_t TIMEOUT_INFINITE = 0xFFFFFFFFFFFFFFFF;
87 
88 /**
89  * Extension name UUID. Values are defined in extension headers.
90  */
91 class ExtensionName : public NamedUUID
92 {
93 public:
94  ExtensionName(uint32_t time_low_
95  , uint16_t time_mid_
96  , uint16_t time_hi_and_version_
97  , uint16_t clock_seq_
98  , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
99  , const char* name)
100  : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
101  c0, c1, c2, c3, c4, c5, name)
102  {}
103 
105  : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "EXT_UNSPECIFIED")
106  {}
107 };
108 
109 /*
110  * Named UUID classes.
111  */
112 
113 DEFINE_NAMED_UUID_CLASS(AwbMode);
114 DEFINE_NAMED_UUID_CLASS(CaptureIntent);
115 DEFINE_NAMED_UUID_CLASS(DenoiseMode);
116 DEFINE_NAMED_UUID_CLASS(EdgeEnhanceMode);
117 DEFINE_NAMED_UUID_CLASS(SensorModeType);
118 DEFINE_NAMED_UUID_CLASS(VideoStabilizationMode);
119 
120 /*
121  * Named UUIDs sorted alphabetically.
122  */
123 
124 DEFINE_UUID(AwbMode, AWB_MODE_OFF, FB3F365A,CC62,11E5,9956,62,56,62,87,07,61);
125 DEFINE_UUID(AwbMode, AWB_MODE_AUTO, FB3F365B,CC62,11E5,9956,62,56,62,87,07,61);
126 DEFINE_UUID(AwbMode, AWB_MODE_INCANDESCENT, FB3F365C,CC62,11E5,9956,62,56,62,87,07,61);
127 DEFINE_UUID(AwbMode, AWB_MODE_FLUORESCENT, FB3F365D,CC62,11E5,9956,62,56,62,87,07,61);
128 DEFINE_UUID(AwbMode, AWB_MODE_WARM_FLUORESCENT, FB3F365E,CC62,11E5,9956,62,56,62,87,07,61);
129 DEFINE_UUID(AwbMode, AWB_MODE_DAYLIGHT, FB3F365F,CC62,11E5,9956,62,56,62,87,07,61);
130 DEFINE_UUID(AwbMode, AWB_MODE_CLOUDY_DAYLIGHT, FB3F3660,CC62,11E5,9956,62,56,62,87,07,61);
131 DEFINE_UUID(AwbMode, AWB_MODE_TWILIGHT, FB3F3661,CC62,11E5,9956,62,56,62,87,07,61);
132 DEFINE_UUID(AwbMode, AWB_MODE_SHADE, FB3F3662,CC62,11E5,9956,62,56,62,87,07,61);
133 DEFINE_UUID(AwbMode, AWB_MODE_MANUAL, 20FB45DA,C49F,4293,AB02,13,3F,8C,CA,DD,69);
134 
135 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_MANUAL,
136  FB3F3663,CC62,11E5,9956,62,56,62,87,07,61);
137 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_PREVIEW,
138  FB3F3664,CC62,11E5,9956,62,56,62,87,07,61);
139 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_STILL_CAPTURE,
140  FB3F3665,CC62,11E5,9956,62,56,62,87,07,61);
141 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_RECORD,
142  FB3F3666,CC62,11E5,9956,62,56,62,87,07,61);
143 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_SNAPSHOT,
144  FB3F3667,CC62,11E5,9956,62,56,62,87,07,61);
145 
146 DEFINE_UUID(DenoiseMode, DENOISE_MODE_OFF, FB3F3668,CC62,11E5,9956,62,56,62,87,07,61);
147 DEFINE_UUID(DenoiseMode, DENOISE_MODE_FAST, FB3F3669,CC62,11E5,9956,62,56,62,87,07,61);
148 DEFINE_UUID(DenoiseMode, DENOISE_MODE_HIGH_QUALITY, FB3F366A,CC62,11E5,9956,62,56,62,87,07,61);
149 
150 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_OFF, F7100B40,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
151 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_FAST, F7100B41,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
152 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_HIGH_QUALITY, F7100B42,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
153 
154 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_DEPTH,
155  64483464,4b91,11e6,bbbd,40,16,7e,ab,86,92);
156 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_YUV,
157  6453e00c,4b91,11e6,871d,40,16,7e,ab,86,92);
158 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_RGB,
159  6463d4c6,4b91,11e6,88a3,40,16,7e,ab,86,92);
160 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_BAYER,
161  646f04ea,4b91,11e6,9c06,40,16,7e,ab,86,92);
162 
163 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_OFF,
164  FB3F366E,CC62,11E5,9956,62,56,62,87,07,61);
165 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_ON,
166  FB3F366F,CC62,11E5,9956,62,56,62,87,07,61);
167 
168 /*
169  * Camera settings constants - sorted alphabetically.
170  */
171 
173 {
178 
180 };
181 
183 {
189 
191 };
192 
194 {
199 
201 };
202 
204 {
209 
211 };
212 
213 /**
214  * Status values returned by API function calls.
215  */
216 enum Status
217 {
218  /// Function succeeded.
220 
221  /// The set of parameters passed was invalid.
223 
224  /// The requested settings are invalid.
226 
227  /// The requested device is unavailable.
229 
230  /// An operation failed because of insufficient mavailable memory.
232 
233  /// This method has not been implemented.
235 
236  /// An operation timed out.
238 
239  /// The capture was aborted. @see ICaptureSession::cancelRequests()
241 
242  /// The stream or other resource has been disconnected.
244 
245  // Number of elements in this enum.
247 };
248 
250 {
254 
256 };
257 
259 {
263 
266 };
267 
268 
269 /**
270  * Pixel formats.
271  */
272 class PixelFormat : public NamedUUID
273 {
274 public:
275  PixelFormat(uint32_t time_low_
276  , uint16_t time_mid_
277  , uint16_t time_hi_and_version_
278  , uint16_t clock_seq_
279  , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
280  , const char* name)
281  : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
282  c0, c1, c2, c3, c4, c5, name)
283  {}
284 
285 private:
286  PixelFormat(); // No default c'tor please use PIXEL_FMT_UNKNOWN
287 };
288 
289 DEFINE_UUID(PixelFormat, PIXEL_FMT_UNKNOWN, 00000000,93d5,11e5,0000,1c,b7,2c,ef,d4,1e);
290 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y8, 569be14a,93d5,11e5,91bc,1c,b7,2c,ef,d4,1e);
291 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y16, 56ddb19c,93d5,11e5,8e2c,1c,b7,2c,ef,d4,1e);
292 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_420_888, 570c10e6,93d5,11e5,8ff3,1c,b7,2c,ef,d4,1e);
293 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_422_888, 573a7940,93d5,11e5,99c2,1c,b7,2c,ef,d4,1e);
294 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_444_888, 576043dc,93d5,11e5,8983,1c,b7,2c,ef,d4,1e);
295 DEFINE_UUID(PixelFormat, PIXEL_FMT_JPEG_BLOB, 578b08c4,93d5,11e5,9686,1c,b7,2c,ef,d4,1e);
296 DEFINE_UUID(PixelFormat, PIXEL_FMT_RAW16, 57b484d8,93d5,11e5,aeb6,1c,b7,2c,ef,d4,1e);
297 
298 /**
299  * Utility class for Argus interfaces.
300  */
302 {
303 protected:
305 
306 private:
307  NonCopyable(NonCopyable& other);
309 };
310 
311 /**
312  * The top-level interface class.
313  *
314  * By convention, every Interface subclass exposes a public static method called @c id(),
315  * which returns the unique InterfaceID for that interface.
316  * This is required for the @c interface_cast<> template to work with that interface.
317  */
319 {
320 protected:
323 };
324 
325 /**
326  * A unique identifier for an Argus Interface.
327  */
328 class InterfaceID : public NamedUUID
329 {
330 public:
331  InterfaceID(uint32_t time_low_
332  , uint16_t time_mid_
333  , uint16_t time_hi_and_version_
334  , uint16_t clock_seq_
335  , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
336  , const char* name)
337  : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
338  c0, c1, c2, c3, c4, c5, name)
339  {}
340 
342  : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "IID_UNSPECIFIED")
343  {}
344 };
345 
346 /**
347  * The base interface for a class that provides Argus Interfaces.
348  */
350 {
351 public:
352 
353  /**
354  * Acquire the interface specified by @c interfaceId.
355  * @returns An instance of the requested interface,
356  * or NULL if that interface is not available.
357  */
358  virtual Interface* getInterface(const InterfaceID& interfaceId) = 0;
359 
360 protected:
362 };
363 
364 /**
365  * Interface-casting helper similar to dynamic_cast.
366  */
367 
368 template <typename TheInterface>
369 inline TheInterface* interface_cast(InterfaceProvider* obj)
370 {
371  return static_cast<TheInterface*>(obj ? obj->getInterface(TheInterface::id()): 0);
372 }
373 
374 template <typename TheInterface>
375 inline TheInterface* interface_cast(const InterfaceProvider* obj)
376 {
377  return static_cast<TheInterface*>(
378  obj ? const_cast<const Interface*>(
379  const_cast<InterfaceProvider*>(obj)->getInterface(TheInterface::id())): 0);
380 }
381 
382 /**
383  * A top level object class for Argus objects that are created and owned by
384  * the client. All Destructable objects created by the client must be explicitly destroyed.
385  */
387 {
388 public:
389 
390  /**
391  * Destroy this object.
392  * After making this call, the client cannot make any more calls on this object.
393  */
394  virtual void destroy() = 0;
395 
396 protected:
398 };
399 
400 /**
401  * Template helper emulating C++11 rvalue semantics.
402  */
403 template<typename T>
404 class rv : public T
405 {
406  rv();
407  ~rv();
408  rv(const rv&);
409  void operator=(const rv&);
410 };
411 
412 template<typename T>
413  rv<T>& move(T& self)
414 {
415  return *static_cast<rv<T>*>(&self);
416 }
417 
418 /**
419  * Movable smart pointer mimicking std::unique_ptr.
420  */
421 template <typename T> struct remove_const;
422 template <typename T> struct remove_const<const T&>{ typedef T& type; };
423 template <typename T> struct remove_const<const T*>{ typedef T* type; };
424 template <typename T> struct remove_const<const T >{ typedef T type; };
425 template <typename T> struct remove_const { typedef T type; };
426 
427 template <typename T>
429 {
430 public:
431  explicit UniqueObj(T* obj=NULL): m_obj(obj) {}
432 
433  void reset(T* obj=NULL)
434  { if (m_obj) const_cast<typename remove_const<T*>::type>(m_obj)->destroy(); m_obj = obj; }
435  T* release()
436  { T* obj = m_obj; m_obj = NULL; return obj; }
437 
438  UniqueObj( rv<UniqueObj>& moved ): m_obj(moved.release()) {}
439  UniqueObj& operator=( rv<UniqueObj>& moved ){ reset( moved.release()); return *this; }
440 
441  ~UniqueObj() { reset(); }
442 
443  T& operator*() const { return *m_obj; }
444  T* get() const { return m_obj; }
445 
446  operator bool() const { return !!m_obj; }
447 
448  operator rv<UniqueObj>&() { return *static_cast< rv<UniqueObj>*>(this); }
449  operator const rv<UniqueObj>&() const { return *static_cast<const rv<UniqueObj>*>(this); }
450 
451 private:
452  T* m_obj;
453 
454  T* operator->() const; // Prevent calling destroy() directly.
455  // Note: For getInterface functionality use interface_cast.
456 };
457 
458 template <typename TheInterface, typename TObject>
459 inline TheInterface* interface_cast(const UniqueObj<TObject>& obj)
460 {
461  return interface_cast<TheInterface>( obj.get());
462 }
463 
464 /**
465  * Tuple template class. This provides a finite ordered list of N elements having type T.
466  */
467 template <unsigned int N, typename T>
468 class Tuple
469 {
470 public:
471  Tuple() {}
472 
473  /// Initialize every element of the tuple to a single value.
474  Tuple(T init)
475  {
476  for (unsigned int i = 0; i < N; i++)
477  m_data[i] = init;
478  }
479 
480  /// Returns true when every element in the two tuples are identical.
481  bool operator==(const Tuple<N,T>& rhs) const
482  {
483  return !memcmp(m_data, rhs.m_data, sizeof(m_data));
484  }
485 
486  /// Returns true if there are any differences between the two tuples.
487  bool operator!=(const Tuple<N,T>& rhs) const
488  {
489  return !(*this == rhs);
490  }
491 
492  /// Adds every element of another tuple to the elements of this tuple.
494  {
495  for (unsigned int i = 0; i < N; i++)
496  m_data[i] += rhs.m_data[i];
497  return *this;
498  }
499 
500  /// Subtracts every element of another tuple from the elements of this tuple.
502  {
503  for (unsigned int i = 0; i < N; i++)
504  m_data[i] -= rhs.m_data[i];
505  return *this;
506  }
507 
508  /// Multiplies every element in the tuple by a single value.
509  Tuple<N, T>& operator*=(const T& rhs)
510  {
511  for (unsigned int i = 0; i < N; i++)
512  m_data[i] *= rhs;
513  return *this;
514  }
515 
516  /// Divides every element in the tuple by a single value.
517  Tuple<N, T>& operator/=(const T& rhs)
518  {
519  for (unsigned int i = 0; i < N; i++)
520  m_data[i] /= rhs;
521  return *this;
522  }
523 
524  /// Returns the result of adding another tuple to this tuple.
525  const Tuple<N, T> operator+(const Tuple<N, T>& rhs) const
526  {
527  return Tuple<N, T>(*this) += rhs;
528  }
529 
530  /// Returns the result of subtracting another tuple from this tuple.
531  const Tuple<N, T> operator-(const Tuple<N, T>& rhs) const
532  {
533  return Tuple<N, T>(*this) -= rhs;
534  }
535 
536  /// Returns the result of multiplying this tuple by a single value.
537  const Tuple<N, T> operator*(const T& rhs) const
538  {
539  return Tuple<N, T>(*this) *= rhs;
540  }
541 
542  /// Returns the result of dividing this tuple by a single value.
543  const Tuple<N, T> operator/(const T& rhs) const
544  {
545  return Tuple<N, T>(*this) /= rhs;
546  }
547 
548  T& operator[](unsigned int i) { assert(i < N); return m_data[i]; }
549  const T& operator[](unsigned int i) const { assert(i < N); return m_data[i]; }
550 
551  /// Returns the number of elements in the tuple.
552  static unsigned int tupleSize() { return N; }
553 
554 protected:
555  T m_data[N];
556 };
557 
558 /**
559  * BayerTuple template class. This is a Tuple specialization containing 4 elements corresponding
560  * to the Bayer color channels: R, G_EVEN, G_ODD, and B. Values can be accessed using the named
561  * methods or subscript indexing using the Argus::BayerChannel enum.
562  */
563 template <typename T>
564 class BayerTuple : public Tuple<BAYER_CHANNEL_COUNT, T>
565 {
566 public:
569 
570  BayerTuple(T init)
571  {
572  r() = gEven() = gOdd() = b() = init;
573  }
574 
575  BayerTuple(T _r, T _gEven, T _gOdd, T _b)
576  {
577  r() = _r;
578  gEven() = _gEven;
579  gOdd() = _gOdd;
580  b() = _b;
581  }
582 
591 };
592 
593 /**
594  * RGBTuple template class. This is a Tuple specialization containing 3 elements corresponding
595  * to the RGB color channels: R, G, and B. Values can be accessed using the named methods or
596  * subscript indexing using the Argus::RGBChannel enum.
597  */
598 template <typename T>
599 class RGBTuple : public Tuple<RGB_CHANNEL_COUNT, T>
600 {
601 public:
602  RGBTuple() {}
604 
605  RGBTuple(T init)
606  {
607  r() = g() = b() = init;
608  }
609 
610  RGBTuple(T _r, T _g, T _b)
611  {
612  r() = _r;
613  g() = _g;
614  b() = _b;
615  }
616 
623 };
624 
625 /**
626  * Point2D template class. This is a Tuple specialization containing 2 elements corresponding
627  * to the x and y coordinates a 2D point. Values can be accessed using the named methods or
628  * subscript indexing using the Argus::Coordinate enum.
629  */
630 template <typename T>
631 class Point2D : public Tuple<COORDINATE_2D_COUNT, T>
632 {
633 public:
634  Point2D() {}
636 
637  Point2D(T init)
638  {
639  x() = y() = init;
640  }
641 
642  Point2D(T _x, T _y)
643  {
644  x() = _x;
645  y() = _y;
646  }
647 
652 };
653 
654 /**
655  * Size2D template class. This is a Tuple specialization containing 2 elements corresponding to the
656  * width and height of a 2D size, in that order. Values can be accessed using the named methods.
657  */
658 template <typename T>
659 class Size2D : public Tuple<2, T>
660 {
661 public:
662  Size2D() {}
663  Size2D(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
664 
665  Size2D(T init)
666  {
667  width() = height() = init;
668  }
669 
670  Size2D(T _width, T _height)
671  {
672  width() = _width;
673  height() = _height;
674  }
675 
676  T& width() { return Tuple<2, T>::m_data[0]; }
677  const T& width() const { return Tuple<2, T>::m_data[0]; }
678  T& height() { return Tuple<2, T>::m_data[1]; }
679  const T& height() const { return Tuple<2, T>::m_data[1]; }
680 
681  /// Returns the area of the size (width * height).
682  T area() const { return width() * height(); }
683 };
684 
685 /**
686  * Rectangle template class. This is a Tuple specialization containing 4 elements corresponding
687  * to the positions of the left, top, right, and bottom edges of a rectangle, in that order.
688  * Values can be accessed using the named methods.
689  */
690 template <typename T>
691 class Rectangle : public Tuple<4, T>
692 {
693 public:
695  Rectangle(const Tuple<4, T>& other) : Tuple<4, T>(other) {}
696 
697  Rectangle(T init)
698  {
699  left() = top() = right() = bottom() = init;
700  }
701 
702  Rectangle(T _left, T _top, T _right, T _bottom)
703  {
704  left() = _left;
705  top() = _top;
706  right() = _right;
707  bottom() = _bottom;
708  }
709 
710  T& left() { return Tuple<4, T>::m_data[0]; }
711  const T& left() const { return Tuple<4, T>::m_data[0]; }
712  T& top() { return Tuple<4, T>::m_data[1]; }
713  const T& top() const { return Tuple<4, T>::m_data[1]; }
714  T& right() { return Tuple<4, T>::m_data[2]; }
715  const T& right() const { return Tuple<4, T>::m_data[2]; }
716  T& bottom() { return Tuple<4, T>::m_data[3]; }
717  const T& bottom() const { return Tuple<4, T>::m_data[3]; }
718 
719  /// Returns the width of the rectangle.
720  T width() const { return right() - left(); }
721 
722  /// Returns the height of the rectangle.
723  T height() const { return bottom() - top(); }
724 
725  /// Returns the area of the rectangle (width * height).
726  T area() const { return width() * height(); }
727 };
728 
729 /**
730  * Range template class. This is a Tuple specialization containing 2 elements corresponding to the
731  * min and max values of the range, in that order. Values can be accessed using the named methods.
732  */
733 template <typename T>
734 class Range : public Tuple<2, T>
735 {
736 public:
737  Range() {}
738  Range(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
739 
740  Range(T init)
741  {
742  min() = max() = init;
743  }
744 
745  Range(T _min, T _max)
746  {
747  min() = _min;
748  max() = _max;
749  }
750 
751  T& min() { return Tuple<2, T>::m_data[0]; }
752  const T& min() const { return Tuple<2, T>::m_data[0]; }
753  T& max() { return Tuple<2, T>::m_data[1]; }
754  const T& max() const { return Tuple<2, T>::m_data[1]; }
755 
756  bool empty() const { return max() < min(); }
757 };
758 
759 /**
760  * Defines an autocontrol region of interest (in pixel space). This region consists of a rectangle
761  * (inherited from the Rectangle<uint32_t> Tuple) and a floating point weight value.
762  */
763 class AcRegion : public Rectangle<uint32_t>
764 {
765 public:
767  : Rectangle<uint32_t>(0, 0, 0, 0)
768  , m_weight(1.0f)
769  {}
770 
771  AcRegion(uint32_t _left, uint32_t _top, uint32_t _right, uint32_t _bottom, float _weight)
772  : Rectangle<uint32_t>(_left, _top, _right, _bottom)
773  , m_weight(_weight)
774  {}
775 
776  float& weight() { return m_weight; }
777  const float& weight() const { return m_weight; }
778 
779 protected:
780  float m_weight;
781 };
782 
783 /**
784  * A template class to hold a 2-dimensional array of data.
785  * Data in this array is tightly packed in a 1-dimensional vector in row-major order;
786  * that is, the vector index for any value given its 2-dimensional location (Point2D) is
787  * index = location.x() + (location.y() * size.x());
788  * Indexing operators using iterators, 1-dimensional, or 2-dimensional coordinates are provided.
789  */
790 template <typename T>
791 class Array2D
792 {
793 public:
794  // Iterator types.
795  typedef T* iterator;
796  typedef const T* const_iterator;
797 
798  /// Default Constructor.
799  Array2D() : m_size(0, 0) {}
800 
801  /// Constructor given initial array size.
803  {
804  m_data.resize(size.width() * size.height());
805  }
806 
807  /// Constructor given initial array size and initial fill value.
808  Array2D(const Size2D<uint32_t>& size, const T& value) : m_size(size)
809  {
810  m_data.resize(size.width() * size.height(), value);
811  }
812 
813  /// Copy constructor.
814  Array2D(const Array2D<T>& other)
815  {
816  m_data = other.m_data;
817  m_size = other.m_size;
818  }
819 
820  /// Assignment operator.
822  {
823  m_data = other.m_data;
824  m_size = other.m_size;
825  return *this;
826  }
827 
828  /// Equality operator.
829  bool operator== (const Array2D<T>& other) const
830  {
831  return (m_size == other.m_size && m_data == other.m_data);
832  }
833 
834  /// Returns the size (dimensions) of the array.
835  Size2D<uint32_t> size() const { return m_size; }
836 
837  /// Resize the array. Array contents after resize are undefined.
838  /// Boolean return value enables error checking when exceptions are not available.
840  {
841  uint32_t s = size.width() * size.height();
842  m_data.resize(s);
843  if (m_data.size() != s)
844  return false;
845  m_size = size;
846  return true;
847  }
848 
849  /// STL style iterators.
850  inline const_iterator begin() const { return m_data.data(); }
851  inline const_iterator end() const { return m_data.data() + m_data.size(); }
852  inline iterator begin() { return m_data.data(); }
853  inline iterator end() { return m_data.data() + m_data.size(); }
854 
855  /// Array indexing using [] operator.
856  T& operator[](unsigned int i) { return m_data[checkIndex(i)]; }
857  const T& operator[](unsigned int i) const { return m_data[checkIndex(i)]; }
858 
859  /// Array indexing using () operator.
860  inline const T& operator() (uint32_t i) const { return m_data[checkIndex(i)]; }
861  inline const T& operator() (uint32_t x, uint32_t y) const { return m_data[checkIndex(x, y)]; }
862  inline const T& operator() (const Point2D<uint32_t>& p) const
863  { return m_data[checkIndex(p.x(), p.y())]; }
864  inline T& operator() (uint32_t i) { return m_data[checkIndex(i)]; }
865  inline T& operator() (uint32_t x, uint32_t y) { return m_data[checkIndex(x, y)]; }
866  inline T& operator() (const Point2D<uint32_t>& p)
867  { return m_data[checkIndex(p.x(), p.y())]; }
868 
869  // Get pointers to data.
870  inline const T* data() const { return m_data.data(); }
871  inline T* data() { return m_data.data(); }
872 
873 private:
874  inline uint32_t checkIndex(uint32_t i) const
875  {
876  assert(i < m_data.size());
877  return i;
878  }
879 
880  inline uint32_t checkIndex(uint32_t x, uint32_t y) const
881  {
882  assert(x < m_size.width());
883  assert(y < m_size.height());
884  return x + (y * m_size.width());
885  }
886 
887  std::vector<T> m_data;
889 };
890 
891 typedef uint32_t AutoControlId;
892 
893 } // namespace Argus
894 
895 #endif // _ARGUS_TYPES_H