MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlFieldContainer.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_FIELD_CONTAINER_H
14#define ML_FIELD_CONTAINER_H
15
21
22// ML-includes
23#include "mlInitSystemML.h"
24#include "mlLinearAlgebra.h"
25#include "mlImageVector.h"
26#include "mlSubImageBox.h"
27
28#include "mlBase.h"
29#include "mlFieldSensor.h"
30#include "mlFields.h"
31#include "mlListFields.h"
32
34class SoNode;
36
38
40class InputConnector;
41class OutputConnector;
42class SubImageBoxd;
44
45//-------------------------------------------------------------------------
53//-------------------------------------------------------------------------
55{
56
58
59public:
62
64 ~FieldContainer() override;
65
70 std::string whoAmI(bool withInstanceName = true) const;
71
77 Field* addField(const char* name, const char* type, const char* value);
78
81
83 BoolField* addBool(const char* name);
85 BoolField* addBool(const char* name, bool value);
86
88 IntField* addInt(const char* name);
90 IntField* addInt(const char* name, MLint value);
91
97 EnumField* addEnum(const char* name, const char* const* enumerationItemNames, MLint numEnumerationItems);
98
103 EnumField* addEnum(const char* name, const std::vector<std::string>& enumerationItemNames);
104
108
128 template <typename EnumType>
130 {
132 addField(field);
133 return field;
134 }
135
137 FloatField* addFloat(const char* name);
139 FloatField* addFloat(const char* name, float value);
140
142 ProgressField* addProgress(const char* name);
144 ProgressField* addProgress(const char* name, float value);
145
147 DoubleField* addDouble(const char* name);
149 DoubleField* addDouble(const char* name, double value);
150
152 StringField* addString(const char* name);
154 StringField* addString(const char* name, const std::string& value);
155
157 NotifyField* addNotify(const char* name);
160 TriggerField* addTrigger(const char* name);
161
163 BaseField* addBase(const char* name);
165 BaseField* addBase(const char* name, Base* value);
167 BaseField* addBase(const char* name, const RefCountedBasePtr& value);
169 template <typename T> BaseField* addBaseWithAllowedType(const char* name, T* value = nullptr)
170 {
171 BaseField* f = addBase(name);
173 return f;
174 }
176 template <typename T> BaseField* addBaseWithAllowedType(const char* name, const ::boost::intrusive_ptr<T>& value)
177 {
178 return addBaseWithAllowedType(name, value.get());
179 }
180
182 template <typename T> TypedBaseField<T>* addTypedBase(const char* name)
183 {
184 TypedBaseField<T>* field = nullptr;
185
186 field = new TypedBaseField<T>(name);
187 addField(field);
188 return field;
189 }
191 template <typename T> TypedBaseField<T>* addTypedBase(const char* name, T* value)
192 {
194 field->setValue(value);
195 return field;
196 }
198 template <typename T> TypedBaseField<T>* addTypedBase(const char* name, const ::boost::intrusive_ptr<T>& value)
199 {
201 field->setValue(value);
202 return field;
203 }
204
206 SoNodeField* addSoNode(const char* name);
208 SoNodeField* addSoNode(const char* name, SoNode* value);
209
211 PointerField* addPointer(const char* name);
212
214 Vector2Field* addVector2(const char* name);
216 Vector2Field* addVector2(const char* name, const Vector2& value);
218 Vector2Field* addVector2(const char* name, double x, double y);
219
221 Vector3Field* addVector3(const char* name);
223 Vector3Field* addVector3(const char* name, const Vector3& value);
225 Vector3Field* addVector3(const char* name, double x, double y, double z);
226
228 Vector4Field* addVector4(const char* name);
230 Vector4Field* addVector4(const char* name, const Vector4& value);
232 Vector4Field* addVector4(const char* name, double x, double y, double z, double w);
233
235 Vector5Field* addVector5(const char* name);
237 Vector5Field* addVector5(const char* name, const Vector5& value);
238
240 Vector6Field* addVector6(const char* name);
242 Vector6Field* addVector6(const char* name, const Vector6& value);
243
245 Vector10Field* addVector10(const char* name);
247 Vector10Field* addVector10(const char* name, const Vector10& value);
248
252 ImageVectorField* addImageVector(const char* name, const ImageVector& value);
254 ImageVectorField* addImageVector(const char* name, MLint x, MLint y, MLint z, MLint c, MLint t, MLint u);
255
259 SubImageBoxField* addSubImageBox(const char* name, const SubImageBox& value);
260
264 SubImageBoxdField* addSubImageBoxd(const char* name, const SubImageBoxd& value);
265
267 ColorField* addColor(const char* name);
269 ColorField* addColor(const char* name, float r, float g, float b);
271 ColorField* addColor(const char* name, const Vector3& value);
272
274 PlaneField* addPlane(const char* name);
276 PlaneField* addPlane(const char* name, double f0, double f1, double f2, double f3);
278 PlaneField* addPlane(const char* name, const Plane& value);
279
281 RotationField* addRotation(const char* name);
283 RotationField* addRotation(const char* name, const Rotation& value);
284
286 Matrix2Field* addMatrix2(const char* name);
288 Matrix2Field* addMatrix2(const char* name, const Matrix2& value);
289
291 Matrix3Field* addMatrix3(const char* name);
293 Matrix3Field* addMatrix3(const char* name, const Matrix3& value);
294
296 Matrix4Field* addMatrix4(const char* name);
298 Matrix4Field* addMatrix4(const char* name, const Matrix4& value);
299
301 Matrix5Field* addMatrix5(const char* name);
303 Matrix5Field* addMatrix5(const char* name, const Matrix5& value);
304
306 Matrix6Field* addMatrix6(const char* name);
308 Matrix6Field* addMatrix6(const char* name, const Matrix6& value);
309
311 MatrixField* addMatrix(const char* name);
313 MatrixField* addMatrix(const char* name, const Matrix4& value);
314
316 MLDataTypeField* addMLDataType(const char* name);
318 MLDataTypeField* addMLDataType(const char* name, MLDataType value);
319
322
324 IntListField* addIntList(const char* name);
326 IntListField* addIntList(const char* name, const std::vector<MLint>& value);
327
329 DoubleListField* addDoubleList(const char* name);
331 DoubleListField* addDoubleList(const char* name, const std::vector<double>& value);
332
336 Vector2ListField* addVector2List(const char* name, const std::vector<Vector2>& value);
337
341 Vector3ListField* addVector3List(const char* name, const std::vector<Vector3>& value);
342
346 Vector4ListField* addVector4List(const char* name, const std::vector<Vector4>& value);
347
348
350 size_t getNumFields() const;
351
353 bool hasField(const std::string& name) const;
354
357 Field* getField(const std::string& name) const;
358
360 Field* getField(MLint index) const;
361
364
367 void setFieldStringValue(const std::string& name, const std::string& value);
368
372 std::string getFieldStringValue(const std::string& name) const;
373
384 virtual void activateAttachments()
385 {
386 enableNotifications(true);
387 }
388
399 {
400 enableNotifications(false);
401 }
402
403private:
408 bool removeField(Field* field);
409
413 void enableNotifications(bool flag);
414
415protected:
416 // Permit access from field to call handleNotificationInternal
417 friend class Field;
418
420 virtual void handleNotificationInternal(Field* /*field*/, FieldSensor::Strength /*strength*/) {};
421
422private:
424 std::vector<Field*> _fields;
425
427};
428
429
431
432//-----------------------------------------------------------------------------------
433// Stream output for std::ostream
434//-----------------------------------------------------------------------------------
435namespace std
436{
437
439 MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::FieldContainer& fc);
440
441} // namespace std
442
443
444#endif // of __mlFieldContainer_H
@ T
Field to encapsulate a pointer to an ML base object.
Definition mlFields.h:813
void setBaseValueAndAddAllowedType(T *value)
Convenience routine for setting the base value and its type at the same time.
Definition mlFields.h:864
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
Field to encapsulate a boolean value.
Definition mlFields.h:56
Field to encapsulate a vector of three float values representing an (RGB) color with all properties o...
Definition mlFields.h:1547
Field to encapsulate a double value.
Definition mlFields.h:567
Field to encapsulate an enumerated value.
Definition mlFields.h:185
Helper class that stores a list of typed enum values and their string names.
Definition mlFields.h:318
Defines the class FieldContainer to encapsulate a vector of fields (see class Field).
FloatField * addFloat(const char *name, float value)
Creates a FloatField with name and adds it to the container.
Matrix4Field * addMatrix4(const char *name)
Creates a Matrix4Field with name and adds it to the container.
IntListField * addIntList(const char *name)
Creates an IntListField field with name and empty list value and adds it to the container.
MLDataTypeField * addMLDataType(const char *name)
Creates a MTDataTypeField with name and adds it to the container.
size_t getNumFields() const
Returns the number of added fields.
virtual void handleNotificationInternal(Field *, FieldSensor::Strength)
Called when field has changed.
Vector2ListField * addVector2List(const char *name, const std::vector< Vector2 > &value)
Creates an Vector2ListField field with name and given list value and adds it to the container.
Field * getField(const std::string &name) const
Returns the pointer to the field with name name.
ImageVectorField * addImageVector(const char *name, MLint x, MLint y, MLint z, MLint c, MLint t, MLint u)
Creates a ImageVectorField with name and adds it to the container.
Matrix6Field * addMatrix6(const char *name)
Creates a Matrix6Field with name and adds it to the container.
virtual void deactivateAttachments()
Disables notification handling, i.e., all fields of this module will not send notifications to attach...
BoolField * addBool(const char *name, bool value)
Creates a BoolField with name and adds it to the container.
ImageVectorField * addImageVector(const char *name, const ImageVector &value)
Creates a ImageVectorField with name and adds it to the container.
IntField * addInt(const char *name)
Creates an IntField with name and adds it to the container. Default value is 0.
BaseField * addBaseWithAllowedType(const char *name, T *value=nullptr)
As above, but also sets the allowed type of the field.
SubImageBoxField * addSubImageBox(const char *name, const SubImageBox &value)
Creates a SubImageBoxField with name and adds it to the container.
EnumField * addEnum(const char *name, const char *const *enumerationItemNames, MLint numEnumerationItems)
Creates an EnumField field with name and adds it to the container.
Matrix3Field * addMatrix3(const char *name)
Creates a Matrix3Field with name and adds it to the container.
FloatField * addFloat(const char *name)
Creates a FloatField with name and adds it to the container. Default value is 0.f.
Vector3Field * addVector3(const char *name, const Vector3 &value)
Creates a Vector3Field with name and adds it to the container.
Matrix2Field * addMatrix2(const char *name)
Creates a Matrix2Field with name and adds it to the container.
Vector2Field * addVector2(const char *name)
Creates a Vector2Field with name and adds it to the container.
Vector2ListField * addVector2List(const char *name)
Creates an Vector2ListField field with name and empty list value and adds it to the container.
void setFieldStringValue(const std::string &name, const std::string &value)
Sets the value of the field with name if it exists.
BaseField * addBaseWithAllowedType(const char *name, const ::boost::intrusive_ptr< T > &value)
As above, but also sets the allowed type of the field.
IntListField * addIntList(const char *name, const std::vector< MLint > &value)
Creates an IntListField field with name and given list value and adds it to the container.
Vector4ListField * addVector4List(const char *name)
Creates an Vector4ListField field with name and empty list value and adds it to the container.
DoubleField * addDouble(const char *name)
Creates a DoubleField with name and adds it to the container. Default value is 0.
TriggerField * addTrigger(const char *name)
Creates a TriggerField field with name and adds it to the container.
bool hasField(const std::string &name) const
Returns true if the field with name name exists; otherwise, false is returned.
Vector4Field * addVector4(const char *name)
Creates a Vector4Field with name and adds it to the container.
ProgressField * addProgress(const char *name)
Creates a float ProgressField with name and adds it to the container. Default value is 0....
Vector10Field * addVector10(const char *name, const Vector10 &value)
Creates a Vector10Field with name and adds it to the container.
TypedBaseField< T > * addTypedBase(const char *name, T *value)
Creates a TypedBaseField with name and adds it to the container.
Field * addField(const char *name, const char *type, const char *value)
Adds a new field with name name, type type, and value value (encoded as string) to the container.
Matrix2Field * addMatrix2(const char *name, const Matrix2 &value)
Creates a Matrix2Field with name and adds it to the container.
Vector5Field * addVector5(const char *name, const Vector5 &value)
Creates a Vector5Field with name and adds it to the container.
TypedEnumField< EnumType > * addEnum(const char *name, const EnumValues< EnumType > &values, EnumType initialValue)
Creates a TypedEnumField field with name and adds it to the container.
Vector3Field * addVector3(const char *name)
Creates a Vector3Field with name and adds it to the container.
PlaneField * addPlane(const char *name, double f0, double f1, double f2, double f3)
Creates a PlaneField with name and adds it to the container.
ImageVectorField * addImageVector(const char *name)
Creates a ImageVectorField with name and adds it to the container.
DoubleListField * addDoubleList(const char *name, const std::vector< double > &value)
Creates an DoubleListField field with name and given list value and adds it to the container.
Matrix5Field * addMatrix5(const char *name, const Matrix5 &value)
Creates a Matrix5Field with name and adds it to the container.
SoNodeField * addSoNode(const char *name, SoNode *value)
Creates a SoNodeField with name and adds it to the container.
ColorField * addColor(const char *name, const Vector3 &value)
Creates a ColorField with name and adds it to the container.
MatrixField * addMatrix(const char *name)
Creates a MatrixField with name and adds it to the container.
TypedBaseField< T > * addTypedBase(const char *name)
Creates a TypedBaseField with name and adds it to the container. Default value is NULL.
MLint getFieldIndex(Field *field) const
Returns index of field if it exists. If not, -1 is returned.
BaseField * addBase(const char *name)
Creates a Base field with name and adds it to the container. Default value is NULL.
Field * addField(Field *field)
Adds a field, the ownership of the field is passed to the FieldContainer.
BoolField * addBool(const char *name)
Creates a BoolField with name and adds it to the container. Default value is false.
SubImageBoxdField * addSubImageBoxd(const char *name, const SubImageBoxd &value)
Creates a SubImageBoxd field with name and adds it to the container.
FieldContainer()
Constructor.
SoNodeField * addSoNode(const char *name)
Creates a SoNodeField with name and adds it to the container. Default value is NULL.
ColorField * addColor(const char *name, float r, float g, float b)
Creates a ColorField with name and adds it to the container.
Field * getField(MLint index) const
Returns pointer of field at index if it exists. If not, -1 is returned.
RotationField * addRotation(const char *name, const Rotation &value)
Creates a RotationField with name and adds it to the container.
BaseField * addBase(const char *name, const RefCountedBasePtr &value)
Creates a Base field with name and adds it to the container. Sets the value from intrusive pointer.
EnumField * addEnum(const char *name, const std::vector< std::string > &enumerationItemNames)
Creates an EnumField field with name and adds it to the container.
SubImageBoxdField * addSubImageBoxd(const char *name)
Creates a SubImageBoxd field with name and adds it to the container.
SubImageBoxField * addSubImageBox(const char *name)
Creates a SubImageBoxField with name and adds it to the container.
Matrix4Field * addMatrix4(const char *name, const Matrix4 &value)
Creates a Matrix4Field with name and adds it to the container.
UniversalTypeField * addUniversalType(const char *name)
Creates an UniversalTypeField field with name and adds it to the container.
PointerField * addPointer(const char *name)
Creates a PointerField with name and adds it to the container.
Vector3ListField * addVector3List(const char *name)
Creates an Vector3ListField field with name and empty list value and adds it to the container.
Vector6Field * addVector6(const char *name, const Vector6 &value)
Creates a Vector6Field with name and adds it to the container.
Matrix5Field * addMatrix5(const char *name)
Creates a Matrix5Field with name and adds it to the container.
virtual void activateAttachments()
Reactivates notification handling, i.e., all fields of this module will send notifications again to a...
std::string whoAmI(bool withInstanceName=true) const
Returns the type and the instance name of format 'ClassTypeName(instanceName)' if the instance name i...
PlaneField * addPlane(const char *name)
Creates a PlaneField with name and adds it to the container.
Vector2Field * addVector2(const char *name, const Vector2 &value)
Creates a Vector2Field with name and adds it to the container.
MatrixField * addMatrix(const char *name, const Matrix4 &value)
Creates a MatrixField with name and adds it to the container.
NotifyField * addNotify(const char *name)
Creates a NotifyField field with name and adds it to the container.
DoubleField * addDouble(const char *name, double value)
Creates a DoubleField with name and adds it to the container.
Vector3Field * addVector3(const char *name, double x, double y, double z)
Creates a Vector3Field with name and adds it to the container.
MLDataTypeField * addMLDataType(const char *name, MLDataType value)
Creates a MTDataTypeField with name and adds it to the container.
DoubleListField * addDoubleList(const char *name)
Creates an DoubleListField field with name and empty list value and adds it to the container.
Vector4ListField * addVector4List(const char *name, const std::vector< Vector4 > &value)
Creates an Vector4ListField field with name and given list value and adds it to the container.
TypedBaseField< T > * addTypedBase(const char *name, const ::boost::intrusive_ptr< T > &value)
Creates a TypedBaseField with name and adds it to the container. Sets the value from intrusive pointe...
Vector4Field * addVector4(const char *name, const Vector4 &value)
Creates a Vector4Field with name and adds it to the container.
Vector5Field * addVector5(const char *name)
Creates a Vector5Field with name and adds it to the container.
ColorField * addColor(const char *name)
Creates a ColorField with name and adds it to the container.
StringField * addString(const char *name, const std::string &value)
Creates a StringField with name and adds it to the container.
Vector6Field * addVector6(const char *name)
Creates a Vector6Field with name and adds it to the container.
Vector2Field * addVector2(const char *name, double x, double y)
Creates a Vector2Field with name and adds it to the container.
RotationField * addRotation(const char *name)
Creates a RotationField with name and adds it to the container.
Matrix3Field * addMatrix3(const char *name, const Matrix3 &value)
Creates a Matrix3Field with name and adds it to the container.
Matrix6Field * addMatrix6(const char *name, const Matrix6 &value)
Creates a Matrix6Field with name and adds it to the container.
StringField * addString(const char *name)
Creates a StringField with name and adds it to the container. Default value is empty string.
std::string getFieldStringValue(const std::string &name) const
Returns the string value of the field with name if it is found.
~FieldContainer() override
Destructor: Deletes all added fields.
PlaneField * addPlane(const char *name, const Plane &value)
Creates a PlaneField with name and adds it to the container.
Vector3ListField * addVector3List(const char *name, const std::vector< Vector3 > &value)
Creates an Vector3ListField field with name and given list value and adds it to the container.
Vector10Field * addVector10(const char *name)
Creates a Vector10Field with name and adds it to the container.
IntField * addInt(const char *name, MLint value)
Creates an IntField with name and adds it to the container.
BaseField * addBase(const char *name, Base *value)
Creates a Base field with name and adds it to the container.
ProgressField * addProgress(const char *name, float value)
Creates a float ProgressField with name and adds it to the container.
Vector4Field * addVector4(const char *name, double x, double y, double z, double w)
Creates a Vector4Field with name and adds it to the container.
Strength
Enumeration type describing the strength of notifications.
Base class for all fields used in the ML.
Definition mlField.h:73
Field to encapsulate a float value.
Definition mlFields.h:449
Field to encapsulate an ML vector ImageVector with six integer components.
Definition mlFields.h:2017
Field to encapsulate an integer value.
Definition mlFields.h:123
Field to encapsulate an MLDataType value.
Definition mlFields.h:1967
Field encapsulating a 2x2 matrix.
Definition mlFields.h:1595
Field encapsulating a 3x3 matrix.
Definition mlFields.h:1665
Field to encapsulate a 4x4 matrix.
Definition mlFields.h:1810
Field encapsulating a 5x5 matrix.
Definition mlFields.h:1825
Field encapsulating a 6x6 matrix.
Definition mlFields.h:1896
Field to encapsulate a 4x4 matrix, same as Matrix4Field for backward compatibility.
Definition mlFields.h:1736
Field without value for notifications.
Definition mlFields.h:687
Field to encapsulate a vector of four double values representing a plane with all properties of Vecto...
Definition mlFields.h:2338
Class defining a plane in 3D.
Definition mlPlane.h:30
Field to encapsulate a void pointer to arbitrary data.
Definition mlFields.h:1043
Field to encapsulate an increasing float value from range [0,1].
Definition mlFields.h:519
Field to encapsulate a vector of four double values representing a rotation with all properties of Ve...
Definition mlFields.h:2306
Class to handle Rotations (internally, the rotation is stored as a unit quaternion)
Definition mlRotation.h:38
Field to encapsulate a pointer to an SoNode instance of OpenInventor.
Definition mlFields.h:986
Field to encapsulate a string value.
Definition mlFields.h:634
Field to encapsulate an ML integer SubimgBox.
Definition mlFields.h:2078
Field to encapsulate an ML double SubimgBox.
Definition mlFields.h:2140
SubImageBoxd - SubImageBox with coordinates of float data type.
Templated version of BaseField that only stores the template type as pointer.
Definition mlFields.h:943
TypedEnumField is used to encapsulate a C++ enum value and work with a real enum value instead of int...
Definition mlFields.h:398
Field to encapsulate any of the registered ML types.
Definition mlFields.h:2203
Field to encapsulate a vector of ten double values.
Definition mlFields.h:1468
Field to encapsulate a vector of two double values.
Definition mlFields.h:1091
Field to encapsulate a vector of three double values.
Definition mlFields.h:1164
Field to encapsulate a vector of four double values.
Definition mlFields.h:1240
Field to encapsulate a vector of five double values.
Definition mlFields.h:1315
Field to encapsulate a vector of six double values.
Definition mlFields.h:1392
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition mlMacros.h:21
#define ML_ABSTRACT_CLASS_HEADER(className)
Similar to ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non-existing export symbol.
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:592
#define MLEXPORT
To export symbols from a DLL/shared object, we need to mark them with the MLEXPORT symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:489
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.