MeVisLab Toolbox Reference
CSOAttributes.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 
16 
17 #pragma once
18 
19 
20 #include "MLCSOIncludes.h"
21 #include "CSODefines.h"
22 #include "CSOPathPoints.h"
23 
24 
25 #include <mlVariant.h>
26 
27 
28 ML_START_NAMESPACE
29 
30 class CSO;
31 class CSOGroup;
32 
34 
35 template < typename T >
36 bool CSOWriteValueToStream(std::ostream& out, const T& value, bool asBinary)
37 {
38  Variant v(value);
39  v.write(out, asBinary);
40  if (!asBinary) { out << std::endl; }
41  return !out.bad();
42 }
43 
44 template <>
45 inline bool CSOWriteValueToStream<Variant>(std::ostream& out, const Variant& value, bool asBinary)
46 {
47  value.write(out, asBinary);
48  if (!asBinary) { out << std::endl; }
49  return !out.bad();
50 }
51 
52 template <>
53 inline bool CSOWriteValueToStream<CSOPathPoints>(std::ostream& out, const CSOPathPoints& value, bool asBinary)
54 {
55  Variant numPathPoints(value.numPathPoints());
56  numPathPoints.write(out, asBinary);
57  if (!asBinary) { Variant::writeValue(out, " ", asBinary); }
58 
59  for (unsigned int k = 0; k < static_cast<unsigned int>(numPathPoints.toInt()); ++k)
60  {
61  Vector3 pos = value.getPosAt(k);
62  for (unsigned int i = 0; i < 3; ++i)
63  {
64  Variant::writeValue(out, pos[i], asBinary);
65  if (!asBinary) { Variant::writeValue(out, " ", asBinary); }
66  }
67  }
68  if (!asBinary) { out << std::endl; }
69  return !out.bad();
70 }
71 
73 
74 template < typename T >
75 bool CSOReadValueFromStream(std::istream& in, T& value, bool asBinary)
76 {
77  Variant v;
78  v.read(in, asBinary);
79  if (!asBinary) { in.ignore(); }
80  if (v.isValid())
81  {
82  value = v.asType<T>();
83  return !in.bad();
84  }
85  else
86  {
87  return false;
88  }
89 }
90 
91 template <>
92 inline bool CSOReadValueFromStream<Variant>(std::istream& in, Variant& value, bool asBinary)
93 {
94  value.read(in, asBinary);
95  if (!asBinary) { in.ignore(); }
96  return !in.bad();
97 }
98 
99 template <>
100 inline bool CSOReadValueFromStream<CSOPathPoints>(std::istream& in, CSOPathPoints& value, bool asBinary)
101 {
102  Variant numPathPoints;
103  numPathPoints.read(in, asBinary);
104  if (!numPathPoints.isValid())
105  {
106  return false;
107  }
108 
109  for (unsigned int k = 0; k < static_cast<unsigned int>(numPathPoints.toInt()); ++k)
110  {
111  Vector3 pos;
112  for (unsigned int i = 0; i < 3; ++i)
113  {
114  Variant::readValue(in, pos[i], asBinary);
115  }
116  value.appendPosition(pos);
117  }
118  if (!asBinary) { in.ignore(); }
119  return !in.bad();
120 }
121 
123 
127 {
128 
129 public:
130 
135 
137  void reset();
138 
140  bool writeToStream(std::ostream& outStream, bool asBinary) const;
142  bool readFromStream(std::istream& inStream, bool asBinary, short version);
143 
145  bool saveTo(std::ostream& outStream) const;
147  bool saveToASCII(std::ostream& outStream) const;
148 
150  void loadFrom(std::istream& inStream, short version, bool swapBytes);
152  void loadFromASCII(std::istream& inStream, short version);
153 
155  void setCSO(CSO* cso);
157  void setCSOGroup(CSOGroup* group);
158 
160  std::string label;
162  std::string description;
163 
167  bool showState;
172 
181 
190 
195 
201  void setUserData(const std::string& name, Variant value);
203  Variant getUserData(const std::string& name) const;
205  void getUserDataNames(std::vector< std::string >& names) const;
207  void removeUserData(const std::string& name);
209 
210 
211 private:
212 
214  void sendAttributesChangedPreEvent();
216  void sendAttributesChangedPostEvent();
217 
219  CSO* _associatedCSO;
221  CSOGroup* _associatedCSOGroup;
222 
224  std::map < std::string, Variant > _variantMap;
225 };
226 
228 
229 ML_END_NAMESPACE
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition: MLCSOSystem.h:23
@ T
Definition: SoKeyGrabber.h:71
This class comprises some attributes that are common for a CSO and a CSOGroup.
~CSOAttributes()
Destructor.
float seedPointSize
The marker's size.
void loadFrom(std::istream &inStream, short version, bool swapBytes)
Loads attributes from given file stream.
bool readFromStream(std::istream &inStream, bool asBinary, short version)
Reads the attribute values from the given stream.
void getUserDataNames(std::vector< std::string > &names) const
Fills the given vector with the keys/name under which user data are stored for this CSO.
void setUserData(const std::string &name, Variant value)
int pathPointStyle
The line style of this CSO/Group.
bool saveToASCII(std::ostream &outStream) const
Saves attributes to given stream in ASCII format. Returns whether saving was successful.
void setCSOGroup(CSOGroup *group)
Sets a pointer to the associated CSOGroup.
void reset()
Sets default values to all members.
Vector3 seedPointColor
The marker's color.
std::string label
Label string for this contour.
float voxelWriteValue
The target voxel value.
bool showState
Should this CSO / Group be shown?
int seedPointStyle
The marker mode.
void removeUserData(const std::string &name)
Removes a user data entry.
std::string description
Description string for this contour.
float pathPointWidth
The line width of this CSO/Group.
bool saveTo(std::ostream &outStream) const
Saves attributes to given stream and returns whether the saving was successful.
bool editableState
Should this CSO / Group be editable?
bool voxelizeState
Should this CSO / Group be voxelized?
Variant getUserData(const std::string &name) const
Returns the user data under the given name or an invalid value if the entry does not exist.
float seedPointAlpha
The marker's alpha value.
int timePointIndex
The time point index of this contour.
float pathPointAlpha
The alpha value of this CSO/Group.
int voxelWriteMode
The write mode for voxel values.
Vector3 pathPointColor
The color of this CSO/Group.
void setCSO(CSO *cso)
Sets a pointer to the associated CSO.
void loadFromASCII(std::istream &inStream, short version)
Loads attributes from given file stream in ASCII format.
bool writeToStream(std::ostream &outStream, bool asBinary) const
Writes the attribute values to the given stream.
A CSOGroup comprises a number of CSOs, which themselves can be in a number of different CSOGroups.
Definition: CSOGroup.h:38
The CSOPathPoints is a list of world coordinates which are interpolated by a certain interpolation sc...
Definition: CSOPathPoints.h:37
unsigned int numPathPoints() const
Returns the number of stored points.
Definition: CSOPathPoints.h:52
void appendPosition(const Vector3 &pos)
Adds a new position to the internal vector.
Definition: CSOPathPoints.h:49
Vector3 getPosAt(unsigned int index) const
Returns a position at a given index index.
Definition: CSOPathPoints.h:61
The CSO represents a contour segmentation object.
Definition: CSO.h:44
The Variant class stores different data types.
Definition: mlVariant.h:36
const T & asType() const
access content of variant directly, NOTE: use with care
Definition: mlVariant.h:78
MLint32 toInt(bool *ok=nullptr) const
std::ostream & write(std::ostream &out, bool asBinary, bool writeType=true) const
write variant to/read variant from stream, either as text or in binary form
bool isValid() const
check if the Variants type is not Invalid
Definition: mlVariant.h:71
std::istream & read(std::istream &in, bool asBinary)
bool CSOReadValueFromStream< Variant >(std::istream &in, Variant &value, bool asBinary)
Definition: CSOAttributes.h:92
bool CSOReadValueFromStream< CSOPathPoints >(std::istream &in, CSOPathPoints &value, bool asBinary)
bool CSOWriteValueToStream(std::ostream &out, const T &value, bool asBinary)
Definition: CSOAttributes.h:36
bool CSOWriteValueToStream< CSOPathPoints >(std::ostream &out, const CSOPathPoints &value, bool asBinary)
Definition: CSOAttributes.h:53
bool CSOWriteValueToStream< Variant >(std::ostream &out, const Variant &value, bool asBinary)
Definition: CSOAttributes.h:45
bool CSOReadValueFromStream(std::istream &in, T &value, bool asBinary)
Definition: CSOAttributes.h:75