MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlStylePalette.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_STYLE_PALETTE_H
14#define ML_STYLE_PALETTE_H
15
16
19
20// ML-includes
21
22#include "mlModuleIncludes.h"
23#include "mlTreeNode.h"
24
25
26#include "mlBaseInit.h"
27
28
30
31
33
34#define MKT_DASH (static_cast<int>(StylePalette::mktDash))
35
36
37//----------------------------------------------------------------------------------
38// Base object class StylePalette
39
42//----------------------------------------------------------------------------------
44{
45public:
51
53 ~StylePalette() override = default;
54
57
58
59 // --- Type definitions ---
60
62 typedef enum {
63 lstNone = 0,
67 lstNumLineStyles
68 } LineStyle;
69
71 typedef enum {
72 mktNone = 0,
81 mktDash = -1
82 } MarkerType;
83
84
85 // --- Constants ---
86
88 static const char* const lineStyleNames[lstNumLineStyles];
89
91 static const char* const markerTypeNames[mktNumMarkerTypes];
92
94 static const int defaultNumStyles;
95
96
97 // --- Access methods ---
98
101 {
102 return static_cast<MLssize_t>(_palette.size());
103 }
106
109 void getColor(MLssize_t index, float& r, float& g, float& b) const;
110 void setColor(MLssize_t index, const Vector3& color);
111 void setColor(MLssize_t index, float r, float g, float b)
112 {
113 setColor(index, Vector3(r, g, b));
114 }
116
120 int getLineWidth(MLssize_t index) const;
121 void setLineWidth(MLssize_t index, int lw);
123
127 int getMarkerSize(MLssize_t index) const;
128 void setMarkerSize(MLssize_t index, int ms);
130
132 bool getAntiAlias(MLssize_t index) const;
133 void setAntiAlias(MLssize_t index, bool aa);
135
137 std::string getName(MLssize_t index) const;
138 void setName(MLssize_t index, const std::string& n);
140
143 {
144 return static_cast<MLssize_t>(_reservedEntries);
145 }
148
152
155
158
160 const char* getLineStyleName(LineStyle lst) const
161 {
162 return lineStyleNames[static_cast<int>(lst)];
163 }
164
167 {
168 return markerTypeNames[static_cast<int>(mkt)];
169 }
170
173
175 bool getStyleIndexForName(const std::string curveTitle, std::vector<MLssize_t>& indices);
176
177 // --- Persistence ---
178
180 void addStateToTree(TreeNode* parent) const override;
181
183 void readStateFromTree(TreeNode* parent) override;
184
187
189 virtual StylePalette* clone() const
190 {
191 return new StylePalette(*this);
192 };
193 StylePalette* deepCopy() const override
194 {
195 return new StylePalette(*this);
196 };
197
198protected:
199 // --- Methods ---
200
202 void clear();
203
206
207
208private:
209 static const int kDefLineWidth = 1;
210
211 static const int kDefMarkerSize = 4;
212
213 static const bool kDefAntiAlias = false;
214
215 // --- Data ---
216 struct StyleEntry
217 {
218 std::string name;
219 Vector3 color{Vector3(1)};
220 int lineWidth{kDefLineWidth};
221 int markerSize{kDefMarkerSize};
222 LineStyle lineStyle{lstSolid};
223 MarkerType markerType{mktNone};
224 bool antiAlias{kDefAntiAlias};
225 };
226
227 std::vector<StyleEntry> _palette;
228
230 std::size_t _reservedEntries{};
231
232
233 // Runtime type system initialization
234 ML_CLASS_HEADER(StylePalette)
235};
236
237
239
240
241#endif
242// __mlStylePalette_H
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
Base object class StylePalette for providing a collection of colors, line styles and marker types.
static const int defaultNumStyles
Default number of styles (=12)
Vector3 getColor(MLssize_t index) const
void copyStylesFrom(const StylePalette &palette)
Copy style palette from palette.
virtual StylePalette * clone() const
Create a clone of the StylePalette.
const char * getLineStyleName(LineStyle lst) const
Get name of line style lst.
StylePalette(const StylePalette &palette)=default
std::string getName(MLssize_t index) const
void setColorDefaults()
Set color default values.
StylePalette * deepCopy() const override
Creates a deep copy of the given object.
int getMarkerSize(MLssize_t index) const
void setAntiAlias(MLssize_t index, bool aa)
void setLineWidth(MLssize_t index, int lw)
MarkerType
Marker type constants.
void setLineStyle(MLssize_t index, LineStyle lst)
void addStateToTree(TreeNode *parent) const override
Attach the object state as children of the given parent node.
LineStyle
Line style constants.
StylePalette & operator=(const StylePalette &palette)=default
Assignment operator.
int getLineWidth(MLssize_t index) const
ML_SET_ADDSTATE_VERSION(0)
Sets addState version number.
bool getStyleIndexForName(const std::string curveTitle, std::vector< MLssize_t > &indices)
Get style indices using name, writes all matching indices into vector, returns true if at least one w...
MLssize_t getNumStyles() const
void dumpStyles()
Dump current style definitions to cout.
void setName(MLssize_t index, const std::string &n)
void setColor(MLssize_t index, const Vector3 &color)
StylePalette(MLssize_t numStyles)
void readStateFromTree(TreeNode *parent) override
Read the object state from the children of the given parent node.
const char * getMarkerTypeName(MarkerType mkt) const
Get name of marker type mkt.
void setColor(MLssize_t index, float r, float g, float b)
void clear()
Deallocate style definition arrays.
MarkerType getMarkerType(MLssize_t index) const
LineStyle getLineStyle(MLssize_t index) const
~StylePalette() override=default
Destructor.
bool getAntiAlias(MLssize_t index) const
void setMarkerType(MLssize_t index, MarkerType mkt)
MLssize_t getAutoStyleIndex(MLssize_t n)
Get index for automatic style n (>= 1).
MLssize_t getReservedEntries() const
void setReservedEntries(MLssize_t reserved)
void getColor(MLssize_t index, float &r, float &g, float &b) const
void setMarkerSize(MLssize_t index, int ms)
void setNumStyles(MLssize_t newNumStyles)
void init(MLssize_t numStyles)
Allocate style definition arrays.
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:160
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition mlBaseInit.h:22
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non-existing export symbol.
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition mlTypeDefs.h:563
Tvec3< MLdouble > Vector3
A vector with three components of type double.
Definition mlVector3.h:274