OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
node.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_NODE_HPP__
10 #define CMZN_NODE_HPP__
11 
12 #include "zinc/node.h"
13 #include "zinc/field.hpp"
14 #include "zinc/timesequence.hpp"
15 
16 namespace OpenCMISS
17 {
18 namespace Zinc
19 {
20 
21 class Fieldmodule;
22 class Nodeset;
23 class NodesetGroup;
24 class Nodetemplate;
25 
38 class Node
39 {
40 private:
41 
42  cmzn_node_id id;
43 
44 public:
45 
46  Node() : id(0)
47  { }
48 
49  // takes ownership of C handle, responsibility for destroying it
50  explicit Node(cmzn_node_id node_id) : id(node_id)
51  { }
52 
53  Node(const Node& node) :
54  id(cmzn_node_access(node.id))
55  { }
56 
61  {
62  CHANGE_FLAG_NONE = CMZN_NODE_CHANGE_FLAG_NONE,
64  CHANGE_FLAG_ADD = CMZN_NODE_CHANGE_FLAG_ADD,
66  CHANGE_FLAG_REMOVE = CMZN_NODE_CHANGE_FLAG_REMOVE,
68  CHANGE_FLAG_IDENTIFIER = CMZN_NODE_CHANGE_FLAG_IDENTIFIER,
70  CHANGE_FLAG_DEFINITION = CMZN_NODE_CHANGE_FLAG_DEFINITION,
72  CHANGE_FLAG_FIELD = CMZN_NODE_CHANGE_FLAG_FIELD
74  };
75 
79  typedef int ChangeFlags;
80 
85  {
86  VALUE_LABEL_INVALID = CMZN_NODE_VALUE_LABEL_INVALID,
88  VALUE_LABEL_VALUE = CMZN_NODE_VALUE_LABEL_VALUE,
90  VALUE_LABEL_D_DS1 = CMZN_NODE_VALUE_LABEL_D_DS1,
92  VALUE_LABEL_D_DS2 = CMZN_NODE_VALUE_LABEL_D_DS2,
94  VALUE_LABEL_D2_DS1DS2 = CMZN_NODE_VALUE_LABEL_D2_DS1DS2,
96  VALUE_LABEL_D_DS3 = CMZN_NODE_VALUE_LABEL_D_DS3,
98  VALUE_LABEL_D2_DS1DS3 = CMZN_NODE_VALUE_LABEL_D2_DS1DS3,
100  VALUE_LABEL_D2_DS2DS3 = CMZN_NODE_VALUE_LABEL_D2_DS2DS3,
102  VALUE_LABEL_D3_DS1DS2DS3 = CMZN_NODE_VALUE_LABEL_D3_DS1DS2DS3,
104  };
105 
106  Node& operator=(const Node& node)
107  {
108  cmzn_node_id temp_id = cmzn_node_access(node.id);
109  if (0 != id)
110  {
111  cmzn_node_destroy(&id);
112  }
113  id = temp_id;
114  return *this;
115  }
116 
117  ~Node()
118  {
119  if (0 != id)
120  {
121  cmzn_node_destroy(&id);
122  }
123  }
124 
130  bool isValid() const
131  {
132  return (0 != id);
133  }
134 
140  cmzn_node_id getId() const
141  {
142  return id;
143  }
144 
153  {
154  return cmzn_node_get_identifier(id);
155  }
156 
165  int setIdentifier(int identifier)
166  {
167  return cmzn_node_set_identifier(id, identifier);
168  }
169 
175  inline Nodeset getNodeset() const;
176 
177  int merge(const Nodetemplate& nodeTemplate);
178 
179 };
180 
181 inline bool operator==(const Node& a, const Node& b)
182 {
183  return a.getId() == b.getId();
184 }
185 
194 {
195 private:
196 
197  cmzn_nodetemplate_id id;
198 
199 public:
200 
201  Nodetemplate() : id(0)
202  { }
203 
204  // takes ownership of C handle, responsibility for destroying it
205  explicit Nodetemplate(cmzn_nodetemplate_id node_template_id) :
206  id(node_template_id)
207  { }
208 
209  Nodetemplate(const Nodetemplate& nodeTemplate) :
210  id(cmzn_nodetemplate_access(nodeTemplate.id))
211  { }
212 
213  Nodetemplate& operator=(const Nodetemplate& nodeTemplate)
214  {
215  cmzn_nodetemplate_id temp_id = cmzn_nodetemplate_access(nodeTemplate.id);
216  if (0 != id)
217  {
218  cmzn_nodetemplate_destroy(&id);
219  }
220  id = temp_id;
221  return *this;
222  }
223 
224  ~Nodetemplate()
225  {
226  if (0 != id)
227  {
228  cmzn_nodetemplate_destroy(&id);
229  }
230  }
231 
237  bool isValid() const
238  {
239  return (0 != id);
240  }
241 
247  cmzn_nodetemplate_id getId() const
248  {
249  return id;
250  }
251 
262  int defineField(const Field& field)
263  {
264  return cmzn_nodetemplate_define_field(id, field.getId());
265  }
266 
279  int defineFieldFromNode(const Field& field, const Node& node)
280  {
281  return cmzn_nodetemplate_define_field_from_node(id, field.getId(), node.getId());
282  }
283 
292  {
293  return Timesequence(cmzn_nodetemplate_get_timesequence(id, field.getId()));
294  }
295 
310  int setTimesequence(const Field& field, const Timesequence& timesequence)
311  {
312  return cmzn_nodetemplate_set_timesequence(id, field.getId(), timesequence.getId());
313  }
314 
328  int getValueNumberOfVersions(const Field& field, int componentNumber,
329  Node::ValueLabel valueLabel)
330  {
331  return cmzn_nodetemplate_get_value_number_of_versions(id, field.getId(),
332  componentNumber, static_cast<cmzn_node_value_label>(valueLabel));
333  }
334 
358  int setValueNumberOfVersions(const Field& field, int componentNumber,
359  Node::ValueLabel valueLabel, int numberOfVersions)
360  {
361  return cmzn_nodetemplate_set_value_number_of_versions(id, field.getId(),
362  componentNumber, static_cast<cmzn_node_value_label>(valueLabel), numberOfVersions);
363  }
364 
372  int removeField(const Field& field)
373  {
374  return cmzn_nodetemplate_remove_field(id, field.getId());
375  }
384  int undefineField(const Field& field)
385  {
386  return cmzn_nodetemplate_undefine_field(id, field.getId());
387  }
388 };
389 
396 {
397 private:
398 
399  cmzn_nodeiterator_id id;
400 
401 public:
402 
403  Nodeiterator() : id(0)
404  { }
405 
406  // takes ownership of C handle, responsibility for destroying it
407  explicit Nodeiterator(cmzn_nodeiterator_id node_iterator_id) :
408  id(node_iterator_id)
409  { }
410 
411  Nodeiterator(const Nodeiterator& nodeIterator) :
412  id(cmzn_nodeiterator_access(nodeIterator.id))
413  { }
414 
415  Nodeiterator& operator=(const Nodeiterator& nodeIterator)
416  {
417  cmzn_nodeiterator_id temp_id = cmzn_nodeiterator_access(nodeIterator.id);
418  if (0 != id)
419  {
420  cmzn_nodeiterator_destroy(&id);
421  }
422  id = temp_id;
423  return *this;
424  }
425 
426  ~Nodeiterator()
427  {
428  if (0 != id)
429  {
430  cmzn_nodeiterator_destroy(&id);
431  }
432  }
433 
439  bool isValid() const
440  {
441  return (0 != id);
442  }
443 
452  {
453  return Node(cmzn_nodeiterator_next(id));
454  }
455 };
456 
462 class Nodeset
463 {
464 protected:
465 
466  cmzn_nodeset_id id;
467 
468 public:
469 
470  Nodeset() : id(0)
471  { }
472 
473  // takes ownership of C handle, responsibility for destroying it
474  explicit Nodeset(cmzn_nodeset_id nodeset_id) : id(nodeset_id)
475  { }
476 
477  Nodeset(const Nodeset& nodeset) :
478  id(cmzn_nodeset_access(nodeset.id))
479  { }
480 
481  Nodeset& operator=(const Nodeset& nodeset)
482  {
483  cmzn_nodeset_id temp_id = cmzn_nodeset_access(nodeset.id);
484  if (0 != id)
485  {
486  cmzn_nodeset_destroy(&id);
487  }
488  id = temp_id;
489  return *this;
490  }
491 
492  ~Nodeset()
493  {
494  if (0 != id)
495  {
496  cmzn_nodeset_destroy(&id);
497  }
498  }
499 
505  bool isValid() const
506  {
507  return (0 != id);
508  }
509 
515  cmzn_nodeset_id getId() const
516  {
517  return id;
518  }
519 
527  inline NodesetGroup castGroup();
528 
535  bool containsNode(const Node& node)
536  {
537  return cmzn_nodeset_contains_node(id, node.getId());
538  }
539 
548  {
549  return Nodetemplate(cmzn_nodeset_create_nodetemplate(id));
550  }
551 
562  Node createNode(int identifier, const Nodetemplate& nodeTemplate)
563  {
564  return Node(cmzn_nodeset_create_node(id, identifier, nodeTemplate.getId()));
565  }
566 
578  {
579  return Nodeiterator(cmzn_nodeset_create_nodeiterator(id));
580  }
581 
589  {
590  return cmzn_nodeset_destroy_all_nodes(id);
591  }
592 
600  int destroyNode(const Node& node)
601  {
602  return cmzn_nodeset_destroy_node(id, node.getId());
603  }
604 
616  int destroyNodesConditional(const Field& conditionalField)
617  {
618  return cmzn_nodeset_destroy_nodes_conditional(id, conditionalField.getId());
619  }
620 
627  Node findNodeByIdentifier(int identifier)
628  {
629  return Node(cmzn_nodeset_find_node_by_identifier(id, identifier));
630  }
631 
637  inline Fieldmodule getFieldmodule() const;
638 
646  {
647  return Nodeset(cmzn_nodeset_get_master_nodeset(id));
648  }
649 
657  char *getName()
658  {
659  return cmzn_nodeset_get_name(id);
660  }
661 
667  int getSize()
668  {
669  return cmzn_nodeset_get_size(id);
670  }
671 
672 };
673 
674 inline bool operator==(const Nodeset& a, const Nodeset& b)
675 {
676  return cmzn_nodeset_match(a.getId(), b.getId());
677 }
678 
679 inline Nodeset Node::getNodeset() const
680 {
681  return Nodeset(cmzn_node_get_nodeset(id));
682 }
683 
689 class NodesetGroup : public Nodeset
690 {
691 
692 public:
693 
694  // takes ownership of C handle, responsibility for destroying it
695  explicit NodesetGroup(cmzn_nodeset_group_id nodeset_id) : Nodeset(reinterpret_cast<cmzn_nodeset_id>(nodeset_id))
696  { }
697 
698  NodesetGroup()
699  { }
700 
706  cmzn_nodeset_group_id getId() const
707  {
708  return (cmzn_nodeset_group_id)(id);
709  }
710 
719  int addNode(const Node& node)
720  {
721  return cmzn_nodeset_group_add_node(
722  reinterpret_cast<cmzn_nodeset_group_id>(id), node.getId());
723  }
724 
733  int addNodesConditional(const Field& conditionalField)
734  {
735  return cmzn_nodeset_group_add_nodes_conditional(
736  reinterpret_cast<cmzn_nodeset_group_id>(id), conditionalField.getId());
737  }
738 
745  {
746  return cmzn_nodeset_group_remove_all_nodes(
747  reinterpret_cast<cmzn_nodeset_group_id>(id));
748  }
749 
758  int removeNode(const Node& node)
759  {
760  return cmzn_nodeset_group_remove_node(reinterpret_cast<cmzn_nodeset_group_id>(id),
761  node.getId());
762  }
763 
773  int removeNodesConditional(const Field& conditionalField)
774  {
775  return cmzn_nodeset_group_remove_nodes_conditional(
776  reinterpret_cast<cmzn_nodeset_group_id>(id), conditionalField.getId());
777  }
778 
779 };
780 
782 {
783  return NodesetGroup(cmzn_nodeset_cast_group(id));
784 }
785 
792 {
793 private:
794 
795  cmzn_nodesetchanges_id id;
796 
797 public:
798 
799  Nodesetchanges() : id(0)
800  { }
801 
802  // takes ownership of C handle, responsibility for destroying it
803  explicit Nodesetchanges(cmzn_nodesetchanges_id nodesetchanges_id) :
804  id(nodesetchanges_id)
805  { }
806 
807  Nodesetchanges(const Nodesetchanges& nodesetchanges) :
808  id(cmzn_nodesetchanges_access(nodesetchanges.id))
809  { }
810 
811  Nodesetchanges& operator=(const Nodesetchanges& nodesetchanges)
812  {
813  cmzn_nodesetchanges_id temp_id = cmzn_nodesetchanges_access(nodesetchanges.id);
814  if (0 != id)
815  cmzn_nodesetchanges_destroy(&id);
816  id = temp_id;
817  return *this;
818  }
819 
820  ~Nodesetchanges()
821  {
822  if (0 != id)
823  cmzn_nodesetchanges_destroy(&id);
824  }
825 
831  bool isValid() const
832  {
833  return (0 != id);
834  }
835 
843  {
844  return cmzn_nodesetchanges_get_node_change_flags(id, node.getId());
845  }
846 
854  {
855  return cmzn_nodesetchanges_get_number_of_changes(id);
856  }
857 
864  {
865  return cmzn_nodesetchanges_get_summary_node_change_flags(id);
866  }
867 };
868 
869 inline int Node::merge(const Nodetemplate& nodeTemplate)
870 {
871  return cmzn_node_merge(id, nodeTemplate.getId());
872 }
873 
874 } // namespace Zinc
875 }
876 
877 #endif
An iterator for looping through all the nodes in a nodeset.
Definition: node.hpp:395
bool isValid() const
Definition: node.hpp:831
Object describing changes to a nodeset in a fieldmoduleevent.
Definition: node.hpp:791
bool isValid() const
Definition: node.hpp:505
int setTimesequence(const Field &field, const Timesequence &timesequence)
Definition: node.hpp:310
int addNode(const Node &node)
Definition: node.hpp:719
cmzn_nodetemplate_id getId() const
Definition: node.hpp:247
int setValueNumberOfVersions(const Field &field, int componentNumber, Node::ValueLabel valueLabel, int numberOfVersions)
Definition: node.hpp:358
A description of field parameters to define at a node.
Definition: node.hpp:193
int removeNode(const Node &node)
Definition: node.hpp:758
ValueLabel
Definition: node.hpp:84
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:49
int removeNodesConditional(const Field &conditionalField)
Definition: node.hpp:773
Node::ChangeFlags getNodeChangeFlags(const Node &node)
Definition: node.hpp:842
int getIdentifier()
Definition: node.hpp:152
A subset of a master nodeset.
Definition: node.hpp:689
cmzn_nodeset_id getId() const
Definition: node.hpp:515
int destroyAllNodes()
Definition: node.hpp:588
Node next()
Definition: node.hpp:451
int removeField(const Field &field)
Definition: node.hpp:372
bool isValid() const
Definition: node.hpp:237
cmzn_nodeset_group_id getId() const
Definition: node.hpp:706
NodesetGroup castGroup()
Definition: node.hpp:781
Node::ChangeFlags getSummaryNodeChangeFlags()
Definition: node.hpp:863
ChangeFlag
Definition: node.hpp:60
Node findNodeByIdentifier(int identifier)
Definition: node.hpp:627
int undefineField(const Field &field)
Definition: node.hpp:384
Nodetemplate createNodetemplate()
Definition: node.hpp:547
int getValueNumberOfVersions(const Field &field, int componentNumber, Node::ValueLabel valueLabel)
Definition: node.hpp:328
cmzn_field_id getId() const
Definition: field.hpp:101
Nodeiterator createNodeiterator()
Definition: node.hpp:577
int destroyNode(const Node &node)
Definition: node.hpp:600
int setIdentifier(int identifier)
Definition: node.hpp:165
Timesequence getTimesequence(const Field &field)
Definition: node.hpp:291
bool isValid() const
Definition: node.hpp:439
Nodeset getMasterNodeset()
Definition: node.hpp:645
Nodeset getNodeset() const
Definition: node.hpp:679
int getSize()
Definition: node.hpp:667
char * getName()
Definition: node.hpp:657
cmzn_node_id getId() const
Definition: node.hpp:140
int getNumberOfChanges()
Definition: node.hpp:853
int defineField(const Field &field)
Definition: node.hpp:262
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:133
bool isValid() const
Definition: node.hpp:130
A non-decreasing list of times at which nodal parameters can be stored.
Definition: timesequence.hpp:35
Node createNode(int identifier, const Nodetemplate &nodeTemplate)
Definition: node.hpp:562
cmzn_timesequence_id getId() const
Definition: timesequence.hpp:88
int ChangeFlags
Definition: node.hpp:79
bool containsNode(const Node &node)
Definition: node.hpp:535
Point object used to represent finite element nodes.
Definition: node.hpp:38
int removeAllNodes()
Definition: node.hpp:744
int destroyNodesConditional(const Field &conditionalField)
Definition: node.hpp:616
int addNodesConditional(const Field &conditionalField)
Definition: node.hpp:733
int defineFieldFromNode(const Field &field, const Node &node)
Definition: node.hpp:279
A set of nodes or points.
Definition: node.hpp:462
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1734