MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
29
30class CSO;
31class CSOGroup;
32
34
35template <typename T> bool CSOWriteValueToStream(std::ostream& out, const T& value, bool asBinary)
36{
37 Variant v(value);
38 v.write(out, asBinary);
39 if (!asBinary) {
40 out << std::endl;
41 }
42 return !out.bad();
43}
44
45template <> inline bool CSOWriteValueToStream<Variant>(std::ostream& out, const Variant& value, bool asBinary)
46{
47 value.write(out, asBinary);
48 if (!asBinary) {
49 out << std::endl;
50 }
51 return !out.bad();
52}
53
54template <>
55inline bool CSOWriteValueToStream<CSOPathPoints>(std::ostream& out, const CSOPathPoints& value, bool asBinary)
56{
57 Variant numPathPoints(value.numPathPoints());
58 numPathPoints.write(out, asBinary);
59 if (!asBinary) {
60 Variant::writeValue(out, " ", asBinary);
61 }
62
63 for (unsigned int k = 0; k < static_cast<unsigned int>(numPathPoints.toInt()); ++k) {
64 Vector3 pos = value.getPosAt(k);
65 for (unsigned int i = 0; i < 3; ++i) {
66 Variant::writeValue(out, pos[i], asBinary);
67 if (!asBinary) {
68 Variant::writeValue(out, " ", asBinary);
69 }
70 }
71 }
72 if (!asBinary) {
73 out << std::endl;
74 }
75 return !out.bad();
76}
77
79
80template <typename T> bool CSOReadValueFromStream(std::istream& in, T& value, bool asBinary)
81{
82 Variant v;
83 v.read(in, asBinary);
84 if (!asBinary) {
85 in.ignore();
86 }
87 if (v.isValid()) {
88 value = v.asType<T>();
89 return !in.bad();
90 }
91 else {
92 return false;
93 }
94}
95
96template <> inline bool CSOReadValueFromStream<Variant>(std::istream& in, Variant& value, bool asBinary)
97{
98 value.read(in, asBinary);
99 if (!asBinary) {
100 in.ignore();
101 }
102 return !in.bad();
103}
104
105template <> inline bool CSOReadValueFromStream<CSOPathPoints>(std::istream& in, CSOPathPoints& value, bool asBinary)
106{
107 Variant numPathPoints;
108 numPathPoints.read(in, asBinary);
109 if (!numPathPoints.isValid()) {
110 return false;
111 }
112
113 for (unsigned int k = 0; k < static_cast<unsigned int>(numPathPoints.toInt()); ++k) {
114 Vector3 pos;
115 for (unsigned int i = 0; i < 3; ++i) {
116 Variant::readValue(in, pos[i], asBinary);
117 }
118 value.appendPosition(pos);
119 }
120 if (!asBinary) {
121 in.ignore();
122 }
123 return !in.bad();
124}
125
127
131{
132
133public:
138
140 void reset();
141
143 bool writeToStream(std::ostream& outStream, bool asBinary) const;
145 bool readFromStream(std::istream& inStream, bool asBinary, short version);
146
148 bool saveTo(std::ostream& outStream) const;
150 bool saveToASCII(std::ostream& outStream) const;
151
153 void loadFrom(std::istream& inStream, short version, bool swapBytes);
155 void loadFromASCII(std::istream& inStream, short version);
156
158 void setCSO(CSO* cso);
160 void setCSOGroup(CSOGroup* group);
161
163 std::string label;
165 std::string description;
166
175
184
193
198
204 void setUserData(const std::string& name, Variant value);
206 Variant getUserData(const std::string& name) const;
208 void getUserDataNames(std::vector<std::string>& names) const;
210 void removeUserData(const std::string& name);
212
213
214private:
216 void sendAttributesChangedPreEvent();
218 void sendAttributesChangedPostEvent();
219
221 CSO* _associatedCSO;
223 CSOGroup* _associatedCSOGroup;
224
226 std::map<std::string, Variant> _variantMap;
227};
228
230
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition MLCSOSystem.h:23
@ T
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 specified file stream.
bool readFromStream(std::istream &inStream, bool asBinary, short version)
Reads the attribute values from the specified stream.
void getUserDataNames(std::vector< std::string > &names) const
Fills the specified 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 or CSOGroup.
bool saveToASCII(std::ostream &outStream) const
Saves attributes to specified 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 or CSOGroup 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 or CSOGroup.
bool saveTo(std::ostream &outStream) const
Saves attributes to specified stream and returns whether the saving was successful.
bool editableState
Should this CSO or CSOGroup be editable?
bool voxelizeState
Should this CSO or CSOGroup be voxelized?
Variant getUserData(const std::string &name) const
Returns the user data under the specified 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 or CSOGroup.
int voxelWriteMode
The write mode for voxel values.
Vector3 pathPointColor
The color of this CSO or CSOGroup.
void setCSO(CSO *cso)
Sets a pointer to the associated CSO.
void loadFromASCII(std::istream &inStream, short version)
Loads attributes from specified file stream in ASCII format.
bool writeToStream(std::ostream &outStream, bool asBinary) const
Writes the attribute values to the specified 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 that are interpolated by a certain interpolation sch...
unsigned int numPathPoints() const
Returns the number of stored points.
void appendPosition(const Vector3 &pos)
Adds a new position to the internal vector.
Vector3 getPosAt(unsigned int index) const
Returns a position at a specified index index.
The CSO represents a contour segmentation object.
Definition CSO.h:44
The Variant class stores different data types.
Definition mlVariant.h:36
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
MLint32 toInt(bool *ok=nullptr) const
std::istream & read(std::istream &in, bool asBinary)
bool isValid() const
check if the Variants type is not Invalid
Definition mlVariant.h:89
const T & asType() const
access content of variant directly, NOTE: use with care
Definition mlVariant.h:98
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
bool CSOWriteValueToStream(std::ostream &out, const T &value, bool asBinary)
bool CSOReadValueFromStream(std::istream &in, T &value, bool asBinary)