ML Reference
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 
34 class SoNode;
36 
37 ML_START_NAMESPACE
38 
40 class InputConnector;
41 class OutputConnector;
42 class SubImageBoxd;
44 
45 //-------------------------------------------------------------------------
53 //-------------------------------------------------------------------------
54 class MLEXPORT FieldContainer : public Base {
55 
57 
58 public:
61 
63  ~FieldContainer() override;
64 
69  std::string whoAmI(bool withInstanceName = true) const;
70 
76  Field* addField(const char* name, const char* type, const char* value);
77 
79  Field* addField(Field* field);
80 
82  BoolField* addBool(const char* name);
84  BoolField* addBool(const char* name, bool value);
85 
87  IntField* addInt(const char* name);
89  IntField* addInt(const char* name, MLint value);
90 
96  EnumField* addEnum(const char* name, const char* const * enumerationItemNames, MLint numEnumerationItems);
97 
102  EnumField* addEnum(const char* name, const std::vector<std::string> &enumerationItemNames);
103 
107 
127  template<typename EnumType>
128  TypedEnumField<EnumType>* addEnum(const char* name, const EnumValues<EnumType>& values, EnumType initialValue) {
129  TypedEnumField<EnumType>* field = new TypedEnumField<EnumType>(name, values, initialValue);
130  addField(field);
131  return field;
132  }
133 
135  FloatField* addFloat(const char* name);
137  FloatField* addFloat(const char* name, float value);
138 
140  ProgressField* addProgress(const char* name);
142  ProgressField* addProgress(const char* name, float value);
143 
145  DoubleField* addDouble(const char* name);
147  DoubleField* addDouble(const char* name, double value);
148 
150  StringField* addString(const char* name);
152  StringField* addString(const char* name, const std::string& value);
153 
155  NotifyField* addNotify(const char* name);
158  TriggerField* addTrigger(const char* name);
159 
161  BaseField* addBase(const char* name);
163  BaseField* addBase(const char* name, Base* value);
165  BaseField* addBase(const char* name, const RefCountedBasePtr& value);
167  template <typename T>
168  BaseField* addBaseWithAllowedType(const char* name, T* value = nullptr)
169  {
170  BaseField* f = addBase(name);
172  return f;
173  }
175  template <typename T>
176  BaseField* addBaseWithAllowedType(const char* name, const ::boost::intrusive_ptr<T>& value)
177  {
178  return addBaseWithAllowedType(name, value.get());
179  }
180 
182  template <typename T>
183  TypedBaseField<T>* addTypedBase(const char* name)
184  {
185  TypedBaseField<T>* field = nullptr;
186 
187  field = new TypedBaseField<T>(name);
188  addField(field);
189  return field;
190  }
192  template <typename T>
193  TypedBaseField<T>* addTypedBase(const char* name, T* value)
194  {
195  TypedBaseField<T>* field = addTypedBase<T>(name);
196  field->setValue(value);
197  return field;
198  }
200  template <typename T>
201  TypedBaseField<T>* addTypedBase(const char* name, const ::boost::intrusive_ptr<T>& value)
202  {
203  TypedBaseField<T>* field = addTypedBase<T>(name);
204  field->setValue(value);
205  return field;
206  }
207 
209  SoNodeField* addSoNode(const char* name);
211  SoNodeField* addSoNode(const char* name, SoNode* value);
212 
214  PointerField* addPointer(const char* name);
215 
217  Vector2Field* addVector2(const char* name);
219  Vector2Field* addVector2(const char* name, const Vector2& value);
221  Vector2Field* addVector2(const char* name, double x, double y);
222 
224  Vector3Field* addVector3(const char* name);
226  Vector3Field* addVector3(const char* name, const Vector3& value);
228  Vector3Field* addVector3(const char* name, double x, double y, double z);
229 
231  Vector4Field* addVector4(const char* name);
233  Vector4Field* addVector4(const char* name, const Vector4& value);
235  Vector4Field* addVector4(const char* name, double x, double y, double z, double w);
236 
238  Vector5Field* addVector5(const char* name);
240  Vector5Field* addVector5(const char* name, const Vector5& value);
241 
243  Vector6Field* addVector6(const char* name);
245  Vector6Field* addVector6(const char* name, const Vector6& value);
246 
248  Vector10Field* addVector10(const char* name);
250  Vector10Field* addVector10(const char* name, const Vector10& value);
251 
253  ImageVectorField* addImageVector(const char* name);
255  ImageVectorField* addImageVector(const char* name, const ImageVector& value);
257  ImageVectorField* addImageVector(const char* name, MLint x, MLint y, MLint z, MLint c, MLint t, MLint u);
258 
260  SubImageBoxField* addSubImageBox(const char* name);
262  SubImageBoxField* addSubImageBox(const char* name, const SubImageBox& value);
263 
265  SubImageBoxdField* addSubImageBoxd(const char* name);
267  SubImageBoxdField* addSubImageBoxd(const char* name, const SubImageBoxd& value);
268 
270  ColorField* addColor(const char* name);
272  ColorField* addColor(const char* name, float r, float g, float b);
274  ColorField* addColor(const char* name, const Vector3& value);
275 
277  PlaneField* addPlane(const char* name);
279  PlaneField* addPlane(const char* name, double f0, double f1, double f2, double f3);
281  PlaneField* addPlane(const char* name, const Plane& value);
282 
284  RotationField* addRotation(const char* name);
286  RotationField* addRotation(const char* name, const Rotation& value);
287 
289  Matrix2Field* addMatrix2(const char* name);
291  Matrix2Field* addMatrix2(const char* name, const Matrix2& value);
292 
294  Matrix3Field* addMatrix3(const char* name);
296  Matrix3Field* addMatrix3(const char* name, const Matrix3& value);
297 
299  Matrix4Field* addMatrix4(const char* name);
301  Matrix4Field* addMatrix4(const char* name, const Matrix4& value);
302 
304  Matrix5Field* addMatrix5(const char* name);
306  Matrix5Field* addMatrix5(const char* name, const Matrix5& value);
307 
309  Matrix6Field* addMatrix6(const char* name);
311  Matrix6Field* addMatrix6(const char* name, const Matrix6& value);
312 
314  MatrixField* addMatrix(const char* name);
316  MatrixField* addMatrix(const char* name, const Matrix4& value);
317 
319  MLDataTypeField* addMLDataType(const char* name);
321  MLDataTypeField* addMLDataType(const char* name, MLDataType value);
322 
325 
327  IntListField* addIntList(const char* name);
329  IntListField* addIntList(const char* name, const std::vector<MLint>& value);
330 
332  DoubleListField* addDoubleList(const char* name);
334  DoubleListField* addDoubleList(const char* name, const std::vector<double>& value);
335 
337  Vector2ListField* addVector2List(const char* name);
339  Vector2ListField* addVector2List(const char* name, const std::vector<Vector2>& value);
340 
342  Vector3ListField* addVector3List(const char* name);
344  Vector3ListField* addVector3List(const char* name, const std::vector<Vector3>& value);
345 
347  Vector4ListField* addVector4List(const char* name);
349  Vector4ListField* addVector4List(const char* name, const std::vector<Vector4>& value);
350 
351 
353  size_t getNumFields() const;
354 
356  bool hasField(const std::string& name) const;
357 
360  Field* getField(const std::string& name) const ;
361 
363  Field* getField(MLint index) const ;
364 
366  MLint getFieldIndex(Field* field) const;
367 
370  void setFieldStringValue(const std::string& name, const std::string& value);
371 
375  std::string getFieldStringValue(const std::string& name) const;
376 
387  virtual void activateAttachments() { enableNotifications(true); }
388 
398  virtual void deactivateAttachments(){ enableNotifications(false); }
399 
400 private:
405  bool removeField(Field* field);
406 
410  void enableNotifications(bool flag);
411 
412 protected:
413  // Permit access from Field to call handleNotificationInternal
414  friend class Field;
415 
417  virtual void handleNotificationInternal(Field* /*field*/, FieldSensor::Strength /*strength*/) {};
418 
419 private:
421  std::vector <Field*> _fields;
422 
424 };
425 
426 
427 ML_END_NAMESPACE
428 
429 //-----------------------------------------------------------------------------------
430 // Stream output for std::ostream
431 //-----------------------------------------------------------------------------------
432 namespace std
433 {
434 
436  MLEXPORT std::ostream& operator<<(std::ostream& s, const ML_NAMESPACE::FieldContainer &fc);
437 
438 }
439 
440 
441 
442 #endif //of __mlFieldContainer_H
443 
444 
445 
Field to encapsulate a pointer to an ML base object.
Definition: mlFields.h:797
void setBaseValueAndAddAllowedType(T *value)
convenience routine for setting the base value and its type at the same time.
Definition: mlFields.h:848
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition: mlBase.h:59
Field to encapsulate a boolean value.
Definition: mlFields.h:58
Field to encapsulate a vector of 3 float values representing an (rgb) color with all properties of Ve...
Definition: mlFields.h:1441
Field to encapsulate a double value.
Definition: mlFields.h:538
Field to encapsulate an enumerated value.
Definition: mlFields.h:195
Helper class that stores a list of typed enum values and their string names.
Definition: mlFields.h:319
Defines the class FieldContainer to encapsulate a vector of fields for (see class Field).
PlaneField * addPlane(const char *name, const Plane &value)
Creates a PlaneField with name 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.
Vector2Field * addVector2(const char *name, const Vector2 &value)
Creates a Vector2Field with name and adds it to the container.
Matrix6Field * addMatrix6(const char *name)
Creates a Matrix6Field 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....
size_t getNumFields() const
Returns the number of added fields.
virtual void handleNotificationInternal(Field *, FieldSensor::Strength)
Called when field has changed.
Vector4Field * addVector4(const char *name, const Vector4 &value)
Creates a Vector4Field 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.
virtual void deactivateAttachments()
Disables notification handling, i.e., all fields of this module will not send notifications to attach...
TriggerField * addTrigger(const char *name)
Creates a TriggerField field with name and adds it to the container.
SubImageBoxField * addSubImageBox(const char *name, const SubImageBox &value)
Creates a SubImageBoxField with name and adds it to the container.
Vector4Field * addVector4(const char *name)
Creates a Vector4Field with name and adds it to the container.
MLDataTypeField * addMLDataType(const char *name)
Creates a MTDataTypeField with name and adds it to the container.
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.
RotationField * addRotation(const char *name, const Rotation &value)
Creates a RotationField with name and adds it to the container.
BaseField * addBaseWithAllowedType(const char *name, T *value=nullptr)
As above, but also sets the allowed type of the field.
Vector5Field * addVector5(const char *name, const Vector5 &value)
Creates a Vector5Field 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.
void setFieldStringValue(const std::string &name, const std::string &value)
Sets the value of the field with name if it exists.
EnumField * addEnum(const char *name, const std::vector< std::string > &enumerationItemNames)
Creates an EnumField field 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.
MatrixField * addMatrix(const char *name)
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.
BaseField * addBase(const char *name, Base *value)
Creates a Base field with name 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.
BoolField * addBool(const char *name, bool value)
Creates a BoolField 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.
FloatField * addFloat(const char *name, float value)
Creates a FloatField 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.
Matrix3Field * addMatrix3(const char *name)
Creates a Matrix3Field with name and adds it to the container.
Field * getField(const std::string &name) const
Returns the pointer to the field with name name.
DoubleField * addDouble(const char *name, double value)
Creates a DoubleField 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.
IntField * addInt(const char *name)
Creates an IntField with name and adds it to the container. Default value is 0.
Matrix6Field * addMatrix6(const char *name, const Matrix6 &value)
Creates a Matrix6Field 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 (coded as string) to the container.
SubImageBoxdField * addSubImageBoxd(const char *name)
Creates a SubImageBoxd field with name and adds it to the container.
Vector5Field * addVector5(const char *name)
Creates a Vector5Field 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.
MatrixField * addMatrix(const char *name, const Matrix4 &value)
Creates a MatrixField with name 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.
ImageVectorField * addImageVector(const char *name, const ImageVector &value)
Creates a ImageVectorField 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.
Matrix2Field * addMatrix2(const char *name)
Creates a Matrix2Field 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.
ImageVectorField * addImageVector(const char *name)
Creates a ImageVectorField with name and adds it to the container.
BaseField * addBase(const char *name)
Creates a Base field with name and adds it to the container. Default value is NULL.
Vector10Field * addVector10(const char *name, const Vector10 &value)
Creates a Vector10Field with name and adds it to the container.
Vector3Field * addVector3(const char *name, const Vector3 &value)
Creates a Vector3Field with name and adds it to the container.
ColorField * addColor(const char *name, float r, float g, float b)
Creates a ColorField with name and adds it to the container.
Matrix5Field * addMatrix5(const char *name)
Creates a Matrix5Field 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.
TypedBaseField< T > * addTypedBase(const char *name)
Creates a TypedBaseField with name and adds it to the container. Default value is NULL.
SoNodeField * addSoNode(const char *name)
Creates a SoNodeField with name and adds it to the container. Default value is NULL.
BoolField * addBool(const char *name)
Creates a BoolField with name and adds it to the container. Default value is false.
ColorField * addColor(const char *name)
Creates a ColorField 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.
ColorField * addColor(const char *name, const Vector3 &value)
Creates a ColorField 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.
SubImageBoxdField * addSubImageBoxd(const char *name, const SubImageBoxd &value)
Creates a SubImageBoxd field with name and adds it to the container.
MLint getFieldIndex(Field *field) const
Returns index of field if it exists. If not, -1 is returned.
Vector3Field * addVector3(const char *name)
Creates a Vector3Field 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.
Vector10Field * addVector10(const char *name)
Creates a Vector10Field with name and adds it to the container.
FieldContainer()
Constructor.
RotationField * addRotation(const char *name)
Creates a RotationField with name 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...
SubImageBoxField * addSubImageBox(const char *name)
Creates a SubImageBoxField 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.
DoubleListField * addDoubleList(const char *name)
Creates an DoubleListField 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.
Field * getField(MLint index) const
Returns pointer of field at index if it exists. If not, -1 is returned.
Vector2Field * addVector2(const char *name)
Creates a Vector2Field 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 type and instance name of format "ClassTypeName(instanceName)" if the instance name is not em...
SoNodeField * addSoNode(const char *name, SoNode *value)
Creates a SoNodeField with name and adds it to the container.
Vector6Field * addVector6(const char *name)
Creates a Vector6Field 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.
PlaneField * addPlane(const char *name, double f0, double f1, double f2, double f3)
Creates a PlaneField 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.
BaseField * addBaseWithAllowedType(const char *name, const ::boost::intrusive_ptr< T > &value)
As above, but also sets the allowed type of the field.
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.
Matrix2Field * addMatrix2(const char *name, const Matrix2 &value)
Creates a Matrix2Field 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.
StringField * addString(const char *name, const std::string &value)
Creates a StringField with name and adds it to the container.
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.
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.
PlaneField * addPlane(const char *name)
Creates a PlaneField with name and adds it to the container.
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.
std::string getFieldStringValue(const std::string &name) const
Returns the string value of the field with name if it is found.
Matrix4Field * addMatrix4(const char *name)
Creates a Matrix4Field with name and adds it to the container.
~FieldContainer() override
Destructor: Deletes all added fields.
Vector3ListField * addVector3List(const char *name)
Creates an Vector3ListField field with name and empty list value and adds it to the container.
Field * addField(Field *field)
Adds a field, the ownership of the field is passed to the FieldContainer.
PointerField * addPointer(const char *name)
Creates a PointerField 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.
Vector4ListField * addVector4List(const char *name)
Creates an Vector4ListField field with name and empty list value and adds it to the container.
Strength
Enumeration type describing the strength of notifications.
Definition: mlFieldSensor.h:44
Base class for all fields used in the ML.
Definition: mlField.h:73
Field to encapsulate a float value.
Definition: mlFields.h:415
Field to encapsulate an ML vector ImageVector with 6 integer components.
Definition: mlFields.h:1872
Field to encapsulate an integer value.
Definition: mlFields.h:126
Field to encapsulate an MLDataType value.
Definition: mlFields.h:1822
Field encapsulating a 2x2 matrix.
Definition: mlFields.h:1487
Field encapsulating a 3x3 matrix.
Definition: mlFields.h:1548
Field to encapsulate a 4x4 matrix.
Definition: mlFields.h:1682
Field encapsulating a 5x5 matrix.
Definition: mlFields.h:1697
Field encapsulating a 6x6 matrix.
Definition: mlFields.h:1759
Field to encapsulate a 4x4 matrix, same as Matrix4Field for backward compatibility.
Definition: mlFields.h:1610
Field without value for notifications.
Definition: mlFields.h:659
Field to encapsulate a vector of 4 double values representing a plane with all properties of Vector4F...
Definition: mlFields.h:2174
Class defining a plane in 3D.
Definition: mlPlane.h:30
Field to encapsulate a void pointer to arbitrary data.
Definition: mlFields.h:992
Field to encapsulate an increasing float value from range [0,1].
Definition: mlFields.h:491
Field to encapsulate a vector of 4 double values representing a rotation with all properties of Vecto...
Definition: mlFields.h:2145
Class to handle Rotations (internally the rotation is stored as a unit quaternion)
Definition: mlRotation.h:40
Field to encapsulate a pointer to an SoNode instance of OpenInventor.
Definition: mlFields.h:937
Field to encapsulate a string value.
Definition: mlFields.h:610
Field to encapsulate an ML integer SubimgBox.
Definition: mlFields.h:1932
Field to encapsulate an ML double SubimgBox.
Definition: mlFields.h:1991
SubImageBoxd - SubImageBox with coordinates of float data type.
Templated version of BaseField which only stores the template type as pointer.
Definition: mlFields.h:907
void setValue(T *basePointerValue)
Sets the value of the field to basePointerValue.
Definition: mlFields.h:913
TypedEnumField is used to encapsulate a C++ enum value and work with a real enum value instead of int...
Definition: mlFields.h:384
Field to encapsulate any of the registered ML types.
Definition: mlFields.h:2052
Field to encapsulate a vector of 10 double values.
Definition: mlFields.h:1373
Field to encapsulate a vector of 2 double values.
Definition: mlFields.h:1038
Field to encapsulate a vector of 3 double values.
Definition: mlFields.h:1103
Field to encapsulate a vector of 4 double values.
Definition: mlFields.h:1171
Field to encapsulate a vector of 5 double values.
Definition: mlFields.h:1239
Field to encapsulate a vector of 6 double values.
Definition: mlFields.h:1305
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
Definition: mlMacros.h:23
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:596
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:490