OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
field.hpp
Go to the documentation of this file.
1 
5 /* OpenCMISS-Zinc Library
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #ifndef CMZN_FIELD_HPP__
11 #define CMZN_FIELD_HPP__
12 
13 #include "zinc/field.h"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
20 class Differentialoperator;
21 class Element;
22 class Fieldcache;
23 class FieldComponent;
24 class FieldElementGroup;
25 class FieldFindMeshLocation;
26 class FieldFiniteElement;
27 class FieldGroup;
28 class FieldImage;
29 class FieldImagefilterBinaryThreshold;
30 class FieldImagefilterDiscreteGaussian;
31 class FieldImagefilterHistogram;
32 class FieldImagefilterThreshold;
33 class FieldNodeGroup;
34 class FieldStoredMeshLocation;
35 class FieldStoredString;
36 class Fieldmodule;
37 
46 class Field
47 {
48 protected:
49 
50  cmzn_field_id id;
51 
52 public:
53 
54  Field() : id(0)
55  { }
56 
57  // takes ownership of C handle, responsibility for destroying it
58  explicit Field(cmzn_field_id field_id) : id(field_id)
59  { }
60 
61  Field(const Field& field) : id(cmzn_field_access(field.id))
62  { }
63 
64  Field& operator=(const Field& field)
65  {
66  cmzn_field_id temp_id = cmzn_field_access(field.id);
67  if (0 != id)
68  {
69  cmzn_field_destroy(&id);
70  }
71  id = temp_id;
72  return *this;
73  }
74 
75  ~Field()
76  {
77  if (0 != id)
78  {
79  cmzn_field_destroy(&id);
80  }
81  }
82 
88  bool isValid() const
89  {
90  return (0 != id);
91  }
92 
98  cmzn_field_id getId() const
99  {
100  return id;
101  }
102 
107  {
108  CHANGE_FLAG_NONE = CMZN_FIELD_CHANGE_FLAG_NONE,
110  CHANGE_FLAG_ADD = CMZN_FIELD_CHANGE_FLAG_ADD,
112  CHANGE_FLAG_REMOVE = CMZN_FIELD_CHANGE_FLAG_REMOVE,
114  CHANGE_FLAG_IDENTIFIER = CMZN_FIELD_CHANGE_FLAG_IDENTIFIER,
116  CHANGE_FLAG_DEFINITION = CMZN_FIELD_CHANGE_FLAG_DEFINITION,
120  CHANGE_FLAG_FULL_RESULT = CMZN_FIELD_CHANGE_FLAG_FULL_RESULT,
123  CHANGE_FLAG_PARTIAL_RESULT = CMZN_FIELD_CHANGE_FLAG_PARTIAL_RESULT,
127  CHANGE_FLAG_RESULT = CMZN_FIELD_CHANGE_FLAG_RESULT,
129  CHANGE_FLAG_FINAL = CMZN_FIELD_CHANGE_FLAG_FINAL
131  };
132 
137  typedef int ChangeFlags;
138 
147  {
148  COORDINATE_SYSTEM_TYPE_INVALID = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_INVALID,
150  COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN ,
152  COORDINATE_SYSTEM_TYPE_CYLINDRICAL_POLAR = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_CYLINDRICAL_POLAR,
158  COORDINATE_SYSTEM_TYPE_SPHERICAL_POLAR = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_SPHERICAL_POLAR,
164  COORDINATE_SYSTEM_TYPE_PROLATE_SPHEROIDAL = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_PROLATE_SPHEROIDAL,
172  COORDINATE_SYSTEM_TYPE_OBLATE_SPHEROIDAL = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_OBLATE_SPHEROIDAL,
180  COORDINATE_SYSTEM_TYPE_FIBRE = CMZN_FIELD_COORDINATE_SYSTEM_TYPE_FIBRE
184  };
185 
191  {
192  DOMAIN_TYPE_INVALID = CMZN_FIELD_DOMAIN_TYPE_INVALID,
194  DOMAIN_TYPE_POINT = CMZN_FIELD_DOMAIN_TYPE_POINT,
196  DOMAIN_TYPE_NODES = CMZN_FIELD_DOMAIN_TYPE_NODES,
198  DOMAIN_TYPE_DATAPOINTS = CMZN_FIELD_DOMAIN_TYPE_DATAPOINTS,
200  DOMAIN_TYPE_MESH1D = CMZN_FIELD_DOMAIN_TYPE_MESH1D,
202  DOMAIN_TYPE_MESH2D = CMZN_FIELD_DOMAIN_TYPE_MESH2D,
204  DOMAIN_TYPE_MESH3D = CMZN_FIELD_DOMAIN_TYPE_MESH3D,
206  DOMAIN_TYPE_MESH_HIGHEST_DIMENSION = CMZN_FIELD_DOMAIN_TYPE_MESH_HIGHEST_DIMENSION
208  };
209 
213  typedef int DomainTypes;
214 
220  {
221  VALUE_TYPE_INVALID = CMZN_FIELD_VALUE_TYPE_INVALID,
223  VALUE_TYPE_REAL = CMZN_FIELD_VALUE_TYPE_REAL,
225  VALUE_TYPE_STRING = CMZN_FIELD_VALUE_TYPE_STRING,
227  VALUE_TYPE_MESH_LOCATION = CMZN_FIELD_VALUE_TYPE_MESH_LOCATION
229  };
230 
237  bool isManaged()
238  {
239  return cmzn_field_is_managed(id);
240  }
241 
254  int setManaged(bool value)
255  {
256  return cmzn_field_set_managed(id, value);
257  }
258 
270  char *getComponentName(int componentNumber)
271  {
272  return cmzn_field_get_component_name(id, componentNumber);
273  }
274 
283  int setComponentName(int componentNumber, const char *name)
284  {
285  return cmzn_field_set_component_name(id, componentNumber, name);
286  }
287 
295  {
296  return cmzn_field_get_coordinate_system_focus(id);
297  }
298 
307  int setCoordinateSystemFocus(double focus)
308  {
309  return cmzn_field_set_coordinate_system_focus(id, focus);
310  }
311 
318  {
319  return static_cast<CoordinateSystemType>(
320  cmzn_field_get_coordinate_system_type(id));
321  }
322 
333  {
334  return cmzn_field_set_coordinate_system_type(id,
335  static_cast<cmzn_field_coordinate_system_type>(coordinateSystemType));
336  }
337 
344  {
345  return cmzn_field_get_number_of_components(id);
346  }
347 
354  char *getName()
355  {
356  return cmzn_field_get_name(id);
357  }
358 
366  int setName(const char *name)
367  {
368  return cmzn_field_set_name(id, name);
369  }
370 
377  {
378  return cmzn_field_get_number_of_source_fields(id);
379  }
380 
390  {
391  return Field(cmzn_field_get_source_field(id, index));
392  }
393 
401  {
402  return cmzn_field_is_type_coordinate(id);
403  }
404 
414  int setTypeCoordinate(bool value)
415  {
416  return cmzn_field_set_type_coordinate(id, value);
417  }
418 
425  {
426  return static_cast<ValueType>(cmzn_field_get_value_type(id));
427  }
428 
434  inline Fieldmodule getFieldmodule() const;
435 
447  inline int assignMeshLocation(const Fieldcache& cache, const Element& element,
448  int coordinatesCount, const double *coordinatesIn);
449 
465  inline int assignReal(const Fieldcache& cache, int valuesCount, const double *valuesIn);
466 
476  inline int assignString(const Fieldcache& cache, const char *stringValue);
477 
488  inline Element evaluateMeshLocation(const Fieldcache& cache, int coordinatesCount,
489  double *coordinatesOut);
490 
501  inline int evaluateReal(const Fieldcache& cache, int valuesCount, double *valuesOut);
502 
512  inline char *evaluateString(const Fieldcache& cache);
513 
535  inline int evaluateDerivative(const Differentialoperator& differentialOperator,
536  const Fieldcache& cache, int valuesCount, double *valuesOut);
537 
545  inline bool isDefinedAtLocation(const Fieldcache& cache);
546 
547  // casting functions: must check isValid()
554  inline FieldComponent castComponent();
583  inline FieldGroup castGroup();
590  inline FieldImage castImage();
630  inline FieldNodeGroup castNodeGroup();
643 };
644 
645 inline bool operator==(const Field& a, const Field& b)
646 {
647  return a.getId() == b.getId();
648 }
649 
656 {
657 private:
658 
659  cmzn_fielditerator_id id;
660 
661 public:
662 
663  Fielditerator() : id(0)
664  { }
665 
666  // takes ownership of C handle, responsibility for destroying it
667  explicit Fielditerator(cmzn_fielditerator_id iterator_id) :
668  id(iterator_id)
669  { }
670 
671  Fielditerator(const Fielditerator& fielditerator) :
672  id(cmzn_fielditerator_access(fielditerator.id))
673  { }
674 
675  Fielditerator& operator=(const Fielditerator& fielditerator)
676  {
677  cmzn_fielditerator_id temp_id = cmzn_fielditerator_access(fielditerator.id);
678  if (0 != id)
679  {
680  cmzn_fielditerator_destroy(&id);
681  }
682  id = temp_id;
683  return *this;
684  }
685 
686  ~Fielditerator()
687  {
688  if (0 != id)
689  {
690  cmzn_fielditerator_destroy(&id);
691  }
692  }
693 
699  bool isValid() const
700  {
701  return (0 != id);
702  }
703 
712  {
713  return Field(cmzn_fielditerator_next(id));
714  }
715 };
716 
717 } // namespace Zinc
718 }
719 #endif /* CMZN_FIELD_HPP__ */
int evaluateDerivative(const Differentialoperator&differentialOperator, const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:225
A single finite element from a mesh.
Definition: element.hpp:205
FieldNodeGroup castNodeGroup()
Definition: fieldsubobjectgroup.hpp:106
bool isValid() const
Definition: field.hpp:88
A real-valued field defined by element basis.
Definition: fieldfiniteelement.hpp:29
FieldImagefilterDiscreteGaussian castImagefilterDiscreteGaussian()
Definition: fieldimageprocessing.hpp:768
ChangeFlag
Definition: field.hpp:106
Element evaluateMeshLocation(const Fieldcache &cache, int coordinatesCount, double *coordinatesOut)
Definition: fieldcache.hpp:208
A field which defines a subset of elements from a master mesh.
Definition: fieldsubobjectgroup.hpp:31
char * getName()
Definition: field.hpp:354
FieldElementGroup castElementGroup()
Definition: fieldsubobjectgroup.hpp:95
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
int assignReal(const Fieldcache &cache, int valuesCount, const double *valuesIn)
Definition: fieldcache.hpp:198
FieldStoredString castStoredString()
Definition: fieldfiniteelement.hpp:252
FieldFindMeshLocation castFindMeshLocation()
Definition: fieldfiniteelement.hpp:222
CoordinateSystemType getCoordinateSystemType()
Definition: field.hpp:317
FieldComponent castComponent()
Definition: fieldcomposite.hpp:131
bool isTypeCoordinate()
Definition: field.hpp:400
int setCoordinateSystemFocus(double focus)
Definition: field.hpp:307
int setName(const char *name)
Definition: field.hpp:366
Field getSourceField(int index)
Definition: field.hpp:389
FieldImage castImage()
Definition: fieldimage.hpp:563
int getNumberOfComponents()
Definition: field.hpp:343
Describes the derivative of a field to evaluate.
Definition: differentialoperator.hpp:26
FieldFiniteElement castFiniteElement()
Definition: fieldfiniteelement.hpp:204
int assignString(const Fieldcache &cache, const char *stringValue)
Definition: fieldcache.hpp:203
A field which defines a subset of nodes from a master nodeset.
Definition: fieldsubobjectgroup.hpp:64
A field which stores and returns string values at nodes.
Definition: fieldfiniteelement.hpp:185
char * getComponentName(int componentNumber)
Definition: field.hpp:270
A field returning a single component of a source field as a scalar.
Definition: fieldcomposite.hpp:52
Image processing derived field type performing the ITK discrete gaussian filter.
Definition: fieldimageprocessing.hpp:226
char * evaluateString(const Fieldcache &cache)
Definition: fieldcache.hpp:220
cmzn_field_id getId() const
Definition: field.hpp:98
An image-based field giving the pixel colour/intensity values.
Definition: fieldimage.hpp:31
bool isDefinedAtLocation(const Fieldcache &cache)
Definition: fieldcache.hpp:232
A field storing locations within a mesh.
Definition: fieldfiniteelement.hpp:167
int setManaged(bool value)
Definition: field.hpp:254
int DomainTypes
Definition: field.hpp:213
DomainType
Definition: field.hpp:190
int ChangeFlags
Definition: field.hpp:137
CoordinateSystemType
Definition: field.hpp:146
Field next()
Definition: field.hpp:711
FieldGroup castGroup()
Definition: fieldgroup.hpp:315
bool isValid() const
Definition: field.hpp:699
FieldImagefilterHistogram castImagefilterHistogram()
Definition: fieldimageprocessing.hpp:789
int assignMeshLocation(const Fieldcache &cache, const Element &element, int coordinatesCount, const double *coordinatesIn)
Definition: fieldcache.hpp:191
Image processing derived field type performing the ITK threshold filter.
Definition: fieldimageprocessing.hpp:571
FieldStoredMeshLocation castStoredMeshLocation()
Definition: fieldfiniteelement.hpp:241
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:126
Cache for setting domain locations at which fields are evaluated or assigned.
Definition: fieldcache.hpp:33
int setTypeCoordinate(bool value)
Definition: field.hpp:414
int setComponentName(int componentNumber, const char *name)
Definition: field.hpp:283
ValueType
Definition: field.hpp:219
bool isManaged()
Definition: field.hpp:237
Image processing derived field type performing the ITK histogram field.
Definition: fieldimageprocessing.hpp:302
ValueType getValueType()
Definition: field.hpp:424
A generic group field used for grouping local subobjects.
Definition: fieldgroup.hpp:35
Image processing derived field type performing the ITK binary threshold filter.
Definition: fieldimageprocessing.hpp:80
double getCoordinateSystemFocus()
Definition: field.hpp:294
int getNumberOfSourceFields()
Definition: field.hpp:376
FieldImagefilterBinaryThreshold castImagefilterBinaryThreshold()
Definition: fieldimageprocessing.hpp:727
int evaluateReal(const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:215
int setCoordinateSystemType(CoordinateSystemType coordinateSystemType)
Definition: field.hpp:332
An iterator for looping through all the fields in a fieldmodule.
Definition: field.hpp:655
FieldImagefilterThreshold castImagefilterThreshold()
Definition: fieldimageprocessing.hpp:827
A field that computes the location in a mesh.
Definition: fieldfiniteelement.hpp:71
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1572