KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
c_palette.h
Go to the documentation of this file.
1 
13 /*
14  * $Id: c_palette.h 18148 2014-11-09 21:36:11Z predoehl $
15  */
16 
17 #ifndef PALETTE_H_PREDOEHL_UOFARIZONAVISION
18 #define PALETTE_H_PREDOEHL_UOFARIZONAVISION
19 
20 #include <l_cpp/l_exception.h>
21 #include <i_cpp/i_pixel.h>
22 #include <m_cpp/m_vector.h>
23 
24 #include <vector>
25 
26 
27 namespace kjb
28 {
29 
39 class Palette
40 {
41  std::vector< kjb::PixelRGBA > my_pal;
42 
43 public:
52  Palette( size_t );
53 
55  Palette( const std::vector< kjb::PixelRGBA >& some_pal )
56  : my_pal( some_pal )
57  {}
58 
60  const kjb::PixelRGBA& operator[]( size_t index ) const
61  {
62  return my_pal.at( index );
63  }
64 
66  size_t size() const
67  {
68  return my_pal.size();
69  }
70 
72  void swap( size_t iii, size_t jjj )
73  {
74  std::swap( my_pal.at( iii ), my_pal.at( jjj ) );
75  }
76 
85  typedef kjb::PixelRGBA ( Palette::* PIXOP )( const kjb::Vector& ) const;
86 
87 
88  kjb::PixelRGBA weighted_sum( const kjb::Vector& ) const;
89 
90 
105  kjb::PixelRGBA pick_max( const kjb::Vector& weights ) const
106  {
107  int max_index;
108  if (weights.get_length() != (int)size() ) KJB_THROW(Illegal_argument);
109  weights.max( &max_index );
110  return my_pal[ max_index ];
111  }
112 };
113 
114 } // namespace kjb
115 
116 #endif
int get_length() const
Return the length of the vector.
Definition: m_vector.h:501
size_t size() const
Return the size of the palette (the number of entries)
Definition: c_palette.h:66
#define KJB_THROW(ex)
Definition: l_exception.h:46
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
kjb::PixelRGBA pick_max(const kjb::Vector &weights) const
An unforgiving function that chooses the most popular color.
Definition: c_palette.h:105
kjb::PixelRGBA weighted_sum(const kjb::Vector &) const
compute a new color mixed from old.
Definition: c_palette.cpp:352
Palette(size_t)
Build a palette of the indicated size.
Definition: c_palette.cpp:319
Code for a wrapper class around the C struct Pixel.
Wrapped version of the C struct Pixel, with Alpha (opacity).
Definition: i_pixel.h:57
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
Value_type max(int *max_index) const
Find maximum element in the vector, both its value and index.
Definition: m_vector.h:1425
Construct some colors, for visualizing grids of numbers.
Definition: c_palette.h:39
void swap(size_t iii, size_t jjj)
Swap two palette entries, indicated by index.
Definition: c_palette.h:72
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
kjb::PixelRGBA(Palette::* PIXOP)(const kjb::Vector &) const
convenience typedef for generating/mixing a color.
Definition: c_palette.h:85
Palette(const std::vector< kjb::PixelRGBA > &some_pal)
Build a palette from a vector of colored Pixels.
Definition: c_palette.h:55
Support for error handling exception classes in libKJB.
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
const kjb::PixelRGBA & operator[](size_t index) const
Return a palette entry, a color, in the form of a Pixel.
Definition: c_palette.h:60