itom  3.0.0
paletteOrganizer.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PALETTEORGANIZER_H
24 #define PALETTEORGANIZER_H
25 
26 #include "../../common/sharedStructures.h"
27 #include "../../common/sharedStructuresQt.h"
28 #include "../../common/sharedStructuresGraphics.h"
29 
30 #include <qhash.h>
31 #include <qsharedpointer.h>
32 namespace ito
33 {
34 
36 {
37  public:
38 
39  ItomPaletteBase():m_name(""), m_type(0), m_inverseColorOne(), m_inverseColorTwo(), m_invalidColor() {m_colorStops.clear();};
40  ItomPaletteBase(const QString name, const char type): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo(), m_invalidColor() {m_colorStops.clear();};
41  ItomPaletteBase(const QString name, const char type, QColor start, QColor stop): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo() , m_invalidColor()
42  {
43  m_colorStops.clear();
44  m_colorStops.append(QPair<double, QColor>(0.0, start));
45  m_colorStops.append(QPair<double, QColor>(1.0, stop));
46  };
47 
48  ItomPaletteBase(const ItomPaletteBase & scr)
49  {
50  m_invalidColor = scr.m_invalidColor;
51  m_inverseColorOne = scr.m_inverseColorOne;
52  m_inverseColorTwo = scr.m_inverseColorTwo;
53  m_name = scr.m_name;
54  m_type = scr.m_type;
55  m_colorStops.clear();
56  m_colorStops = scr.m_colorStops;
57  m_paletteData = scr.m_paletteData;
58  }
59 
60  ~ItomPaletteBase() {m_colorStops.clear(); m_paletteData.colorStops.clear(); m_paletteData.colorVector256.clear();};
61 /*
62  enum tPalette{
63  NoType = 0x00,
64  GrayPalette = 0x01,
65  RGBPalette = 0x02,
66  FCPalette = 0x04,
67  indexPalette = 0x08,
68  LinearPalette = 0x10,
69  ReadOnlyPalette = 0x20,
70  };
71 */
72  QString getName() const {return m_name;};
73  inline int getSize() const {return m_colorStops.size();};
74  inline int getType() const {return m_type;};
75 
76  double getPosFirst() const {return m_colorStops[0].first;};
77  double getPosLast() const {return m_colorStops[m_colorStops.size()-1].first;};
78  double getPos(unsigned int color) const;
79 
80  bool setInverseColorOne(const QColor color);
81  QColor getInverseColorOne() const {return m_inverseColorOne;};
82  bool setInversColorTwo(const QColor color);
83  QColor getInverseColorTwo() const {return m_inverseColorTwo;};
84 
85  bool setInvalidColor(const QColor color);
86  QColor getInvalidColor() const;
87 
88  QColor getColorFirst() const {return m_colorStops[0].second;};
89  QColor getColorLast() const {return m_colorStops[m_colorStops.size()-1].second;};
90  QColor getColor(unsigned int color) const;
91 
92  void update(const bool updateInverseColors);
94 
95  inline void setWriteProtection() { m_type = m_type | ito::tPaletteReadOnly; return;};
96  bool insertColorStop( double pos, const QColor color );
97  void calculateInverseColors(QColor &inv1, QColor &inv2);
98  //QColor getColor(double pos) const;
99 
100  QVector<ito::uint32> get256Colors(bool includeAlpha = false) const;
101 
102  protected:
103  inline void removeWriteProtection() { m_type = m_type & !ito::tPaletteReadOnly; return;};
104 
105  private:
106  QString m_name;
107  char m_type;
108 
109  ItomPalette m_paletteData;
110 
111  QColor m_inverseColorTwo;
112  QColor m_inverseColorOne;
113  QColor m_invalidColor;
114  QVector<QPair<double, QColor> > m_colorStops;
115 
116  int findUpper( double pos ) const;
117 
118  public slots:
119 
120  private slots:
121 
122  signals:
123 
124 };
125 
126 class PaletteOrganizer : public QObject
127 {
128  Q_OBJECT
129 
130  public:
131 
133  ~PaletteOrganizer(){};
134 
135  protected:
136 
137 
138  private:
139 
140  QList<QString> restrictedKeyWords;
141  QList<ItomPaletteBase> m_colorBars;
142  QHash<QString,int> m_colorBarLookUp;
143 
144  ItomPaletteBase noPalette;
145 
146  public slots:
147  ItomPaletteBase getColorBar(const int index) const;
148  ItomPaletteBase getNextColorBar(const int curindex, const int type = ito::tPaletteNoType) const;
149  int getColorBarIndex(const QString name, bool *found = NULL) const;
150  ItomPaletteBase getColorBar(const QString name, bool *found = NULL) const;
151  QList<QString> getColorBarList(const int type = ito::tPaletteNoType) const;
152  int numberOfColorBars() const {return m_colorBars.length();};
153 
154  ito::RetVal setColorBarThreaded(QString name, ito::ItomPaletteBase newPalette, ItomSharedSemaphore *waitCond = NULL);
155  ito::RetVal getColorBarThreaded(QString name, QSharedPointer<ito::ItomPaletteBase> palette, ItomSharedSemaphore *waitCond = NULL);
156  ito::RetVal getColorBarListThreaded(int types, QSharedPointer<QStringList> palettes, ItomSharedSemaphore *waitCond = NULL);
157  private slots:
158 
159  signals:
160 
161 };
162 } //namespace íto
163 #endif
Definition: paletteOrganizer.h:35
int findUpper(double pos) const
Find the next color stop and its values within this palette.
Definition: paletteOrganizer.cpp:46
QColor getColor(unsigned int color) const
Get the RGBA-Color of the n-th color-stop in the palette.
Definition: paletteOrganizer.cpp:219
bool insertColorStop(double pos, const QColor color)
Insert a new color stop into the palette defined by color and position.
Definition: paletteOrganizer.cpp:155
Definition: paletteOrganizer.h:126
Class for managing status values (like errors or warning)
Definition: retVal.h:54
double getPos(unsigned int color) const
Get the position of the n-th color-stop in the palette.
Definition: paletteOrganizer.cpp:206
bool setInversColorTwo(const QColor color)
Set the second inverse color for this color bar.
Definition: paletteOrganizer.cpp:102
QVector< ito::uint32 > get256Colors(bool includeAlpha=false) const
Transform the color stops to a 256 color vector.
Definition: paletteOrganizer.cpp:290
Definition: apiFunctionsGraph.cpp:39
void update(const bool updateInverseColors)
This function updates the internal structur of the palette after modifications.
Definition: paletteOrganizer.cpp:245
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
void calculateInverseColors(QColor &inv1, QColor &inv2)
Function which shall calculate the ideal inverse colors.
Definition: paletteOrganizer.cpp:232
ItomPalette getPalette()
This function returns the internal structur of the palett.
Definition: paletteOrganizer.cpp:275
bool setInverseColorOne(const QColor color)
Set the first inverse color for this color bar.
Definition: paletteOrganizer.cpp:81
Definition: sharedStructuresGraphics.h:117
bool setInvalidColor(const QColor color)
Set the invalid color for this color bar.
Definition: paletteOrganizer.cpp:122
QColor getInvalidColor() const
Get the invalid color for this color bar.
Definition: paletteOrganizer.cpp:141