iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PixelBaseImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author
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 // ######################################################################
37 template <class T, size_t numChans, template<typename> class PixType>
38 std::string PixelBase<T, numChans, PixType>::toString()
39 {
40  std::ostringstream stream;
41  stream << "(";
42  for (size_t i=0; i<numChans; ++i)
43  {
44  // Note, this is a terrible hack - the ostream operators for some reason are
45  // just not coming into scope here...
46  if (typeid(T) == typeid(int8) || typeid(T) == typeid(uint8))
47  stream << (int)channels[i];
48  else
49  stream << channels[i];
50 
51  if (i < channels.size() - 1) stream << ",";
52  }
53  stream << ")";
54 
55  return stream.str();
56 }
57 
58 // ######################################################################
59 template <class T, size_t numChans, template<typename> class PixType>
60 inline PixelBase<T, numChans, PixType>::PixelBase() : channels()
61 { }
62 
63 // ######################################################################
64 template <class T, size_t numChans, template<typename> class PixType>
65  template <typename T1, typename>
66 inline PixelBase<T, numChans, PixType>::PixelBase(T1 const & val)
67 {
68  for(T & c : channels) c = clamped_convert<T>(val);
69 }
70 
71 // ######################################################################
72 template <class T, size_t numChans, template<typename> class PixType>
73 template <class T2>
74 inline PixelBase<T, numChans, PixType>::PixelBase(PixelBase<T2, numChans, PixType> const & other)
75 {
76  for (size_t i=0; i<numChans; ++i)
77  channels[i] = clamped_convert<T>(other.channels[i]);
78 }
79 
80 // ######################################################################
81 template <class T, size_t numChans, template<typename> class PixType>
82 template<class T1, template<typename> class PixType2>
83 inline PixelBase<T, numChans, PixType>::PixelBase(PixelBase<T1,1,PixType2> const & other)
84 {
85  for(T & c : channels) c = clamped_convert<T>(other.channels[0]);
86 }
87 
88 // ######################################################################
89 template <class T, size_t numChans, template<typename> class PixType>
90  template<template<typename ...> class PixType2, typename ...PixType2Args, typename>
91 inline PixelBase<T, numChans, PixType>::PixelBase(PixType2<PixType2Args...> const & other)
92 {
93  auto rgb = other.toRGB();
94  auto native = PixType<typename PixType2<PixType2Args...>::PODType>::fromRGB(rgb);
95 
96  for (size_t i=0; i<native.channels.size(); ++i)
97  channels[i] = clamped_convert<T>(native.channels[i]);
98 }
99 
100 // ######################################################################
101 template <class T, size_t numChans, template<typename> class PixType>
102 T* PixelBase<T, numChans, PixType>::begin()
103 { return channels.begin(); }
104 
105 // ######################################################################
106 template <class T, size_t numChans, template<typename> class PixType>
107 T* PixelBase<T, numChans, PixType>::end()
108 { return channels.end(); }
109 
110 // ######################################################################
111 template <class T, size_t numChans, template<typename> class PixType>
112 T const * PixelBase<T, numChans, PixType>::begin() const
113 { return channels.begin(); }
114 
115 // ######################################################################
116 template <class T, size_t numChans, template<typename> class PixType>
117 T const * PixelBase<T, numChans, PixType>::end() const
118 { return channels.end(); }