iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PixelTraits.H
Go to the documentation of this file.
1 /*! @file
2  @author David J. Berg
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_CORE_TYPING_PIXELTRAITS_H
37 #define INCLUDE_NRT_CORE_TYPING_PIXELTRAITS_H
38 
41 #include <type_traits>
43 
44 namespace nrt
45 {
46  /*! \defgroup pixtraits Pixel type trait class
47 
48  This is a traits class to get information about a pixel type, which is useful in metaprogramming. For the case
49  when PixType is not a pixel, everything is so to false. The pod_type will be a nrt::NotATypeError. Most users will
50  use this through nrt_traits. the are_comparable field returns true if the classes are the same or one of the two
51  derives from the other or if a specialization has been made in PixelTraitsHelpers.H.
52 
53  \ingroup typing */
54 
55  /*! @{ */ // **********************************************************************
56 
57  //! This specialization of pixel_traits shows up when PixType is not a Pixel type
58  template <class PixType, bool B = pixel_helper::is_pixel<PixType>::value>
59  struct pixel_traits
60  {
62  static const bool is_pixel = false;
63  static const std::size_t num_channels = -1;
64  static const bool is_single_channel = false;
65  static const bool is_multi_channel = false;
66  static const bool has_extra_data = false;
67  static const bool has_alpha = false;
68  };
69 
70  //! This specialization of pixel_traits shows up when PixType is indeed a Pixel type
71  template <class PixType>
72  struct pixel_traits<PixType, true>
73  {
74  //! What is the POD type stored within this pixel?
75  typedef typename PixType::PODType pod_type;
76 
77  //! Does this type actually derive from PixelBase?
78  static const bool is_pixel = true;
79 
80  //! How many channels does this Pixel type have?
81  static const std::size_t num_channels = PixType::numChannels;
82 
83  //! Is this a single-channel Pixel?
84  /*! This is equivalent to pixel_traits<T>::num_channels == 1 */
85  static const bool is_single_channel = (num_channels == 1) ? true : false;
86 
87  //! Is this a multi-channel Pixel?
88  /*! This is equivalent to pixel_traits<T>::num_channels != 1 */
89  static const bool is_multi_channel = (num_channels > 1) ? true : false;
90 
91  //! Does this Pixel type have extra data associated with it?
92  /*! e.g. PixRGBD or PixRGBA */
93  static const bool has_extra_data = (sizeof(PixType) > sizeof(pod_type)*num_channels) ? true : false;
94 
95  //! Does this Pixel type have an alpha channel?
96  static const bool has_alpha = std::is_base_of<PixelWithAlpha<PixType>,PixType>::value;
97  };
98 
99  /*! @} */ // **********************************************************************
100 }
101 
102 #endif // INCLUDE_NRT_CORE_TYPING_PIXELTRAITS_H