MeVisLab Toolbox Reference
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 
29 
30 ML_START_NAMESPACE
31 
32 
34 
35 #define MKT_DASH (static_cast<int>(StylePalette::mktDash))
36 
37 
38 //----------------------------------------------------------------------------------
39 // Base object class StylePalette
40 
43 //----------------------------------------------------------------------------------
45 {
46 public:
47 
50  StylePalette (MLssize_t numStyles);
51  StylePalette (const StylePalette &palette);
53 
55  ~StylePalette () override;
56 
58  StylePalette &operator = (const StylePalette &palette);
59 
60 
61  // --- Type definitions ---
62 
64  typedef enum {
65  lstNone = 0,
69  lstNumLineStyles
70  } LineStyle;
71 
73  typedef enum {
74  mktNone = 0,
83  mktDash = -1
84  } MarkerType;
85 
86 
87  // --- Constants ---
88 
90  static const char *const lineStyleNames[lstNumLineStyles];
91 
93  static const char *const markerTypeNames[mktNumMarkerTypes];
94 
96  static const int defaultNumStyles;
97 
98 
99  // --- Access methods ---
100 
102  MLssize_t getNumStyles () const { return _numStyles; }
103  void setNumStyles (MLssize_t newNumStyles);
105 
107  Vector3 getColor (MLssize_t index) const;
108  void getColor (MLssize_t index, float &r, float &g, float &b) const;
109  void setColor (MLssize_t index, const Vector3 &color);
110  void setColor (MLssize_t index, float r, float g, float b) { setColor(index, Vector3(r, g, b)); }
112 
115  void setLineStyle (MLssize_t index, LineStyle lst);
116  int getLineWidth (MLssize_t index) const;
117  void setLineWidth (MLssize_t index, int lw);
119 
122  void setMarkerType (MLssize_t index, MarkerType mkt);
123  int getMarkerSize (MLssize_t index) const;
124  void setMarkerSize (MLssize_t index, int ms);
126 
128  bool getAntiAlias (MLssize_t index) const;
129  void setAntiAlias (MLssize_t index, bool aa);
131 
133  std::string getName (MLssize_t index) const;
134  void setName (MLssize_t index, const std::string &n);
136 
138  MLssize_t getReservedEntries () const { return _reservedEntries; }
139  void setReservedEntries (MLssize_t reserved);
141 
145 
147  void copyStylesFrom (const StylePalette &palette);
148 
151 
154 
156  const char *getLineStyleName (LineStyle lst) const {
157  return lineStyleNames[static_cast<int>(lst)];
158  }
159 
161  const char *getMarkerTypeName (MarkerType mkt) const {
162  return markerTypeNames[static_cast<int>(mkt)];
163  }
164 
166  void dumpStyles ();
167 
169  bool getStyleIndexForName(const std::string curveTitle, std::vector<MLssize_t> &indices);
170 
171  // --- Persistence ---
172 
174  void addStateToTree (TreeNode *parent) const override;
175 
177  void readStateFromTree (TreeNode *parent) override;
178 
181 
183  virtual StylePalette* clone() const { return new StylePalette(*this); };
184  StylePalette* deepCopy() const override { return new StylePalette(*this); };
185 protected:
186 
187  // --- Methods ---
188 
190  void clear ();
191 
193  void init (MLssize_t numStyles);
194 
195 
196 private:
197 
198  // --- Data ---
199 
201  Vector3 *_colors;
203  LineStyle *_lineStyles;
205  int *_lineWidths;
207  MarkerType *_markerTypes;
209  int *_markerSizes;
211  bool *_antiAlias;
213  std::string *_names;
214 
216  MLssize_t _numStyles;
217 
219  MLssize_t _reservedEntries;
220 
221 
222  // Runtime type system initialization
224 
225 };
226 
227 
228 ML_END_NAMESPACE
229 
230 
231 #endif
232 // __mlStylePalette_H
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition: mlBase.h:62
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
~StylePalette() override
Destructor.
void copyStylesFrom(const StylePalette &palette)
Copy style palette from palette.
const char * getLineStyleName(LineStyle lst) const
Get name of line style lst.
std::string getName(MLssize_t index) const
void setColorDefaults()
Set color default values.
StylePalette * deepCopy() const override
Set addStateToTree version number that can be accessed via getAddStateVersion()
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.
virtual StylePalette * clone() const
Create a clone of the StylePalette.
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)
const char * getMarkerTypeName(MarkerType mkt) const
Get name of marker type mkt.
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.
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
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 setMonoDefaults()
Set monochrome default values.
void setNumStyles(MLssize_t newNumStyles)
StylePalette(const StylePalette &palette)
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:170
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition: mlBaseInit.h:22
#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 which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
Definition: mlTypeDefs.h:654
Tvec3< MLdouble > Vector3
A vector with 3 components of type double.
Definition: mlVector3.h:300