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 "opencmiss/zinc/node.h"
13 #include "opencmiss/zinc/field.hpp"
14 #include "opencmiss/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 
592  {
593  return cmzn_nodeset_destroy_all_nodes(id);
594  }
595 
606  int destroyNode(const Node& node)
607  {
608  return cmzn_nodeset_destroy_node(id, node.getId());
609  }
610 
625  int destroyNodesConditional(const Field& conditionalField)
626  {
627  return cmzn_nodeset_destroy_nodes_conditional(id, conditionalField.getId());
628  }
629 
636  Node findNodeByIdentifier(int identifier)
637  {
638  return Node(cmzn_nodeset_find_node_by_identifier(id, identifier));
639  }
640 
646  inline Fieldmodule getFieldmodule() const;
647 
655  {
656  return Nodeset(cmzn_nodeset_get_master_nodeset(id));
657  }
658 
666  char *getName()
667  {
668  return cmzn_nodeset_get_name(id);
669  }
670 
676  int getSize()
677  {
678  return cmzn_nodeset_get_size(id);
679  }
680 
681 };
682 
683 inline bool operator==(const Nodeset& a, const Nodeset& b)
684 {
685  return cmzn_nodeset_match(a.getId(), b.getId());
686 }
687 
688 inline Nodeset Node::getNodeset() const
689 {
690  return Nodeset(cmzn_node_get_nodeset(id));
691 }
692 
698 class NodesetGroup : public Nodeset
699 {
700 
701 public:
702 
703  // takes ownership of C handle, responsibility for destroying it
704  explicit NodesetGroup(cmzn_nodeset_group_id nodeset_id) : Nodeset(reinterpret_cast<cmzn_nodeset_id>(nodeset_id))
705  { }
706 
707  NodesetGroup()
708  { }
709 
715  cmzn_nodeset_group_id getId() const
716  {
717  return (cmzn_nodeset_group_id)(id);
718  }
719 
728  int addNode(const Node& node)
729  {
730  return cmzn_nodeset_group_add_node(
731  reinterpret_cast<cmzn_nodeset_group_id>(id), node.getId());
732  }
733 
742  int addNodesConditional(const Field& conditionalField)
743  {
744  return cmzn_nodeset_group_add_nodes_conditional(
745  reinterpret_cast<cmzn_nodeset_group_id>(id), conditionalField.getId());
746  }
747 
754  {
755  return cmzn_nodeset_group_remove_all_nodes(
756  reinterpret_cast<cmzn_nodeset_group_id>(id));
757  }
758 
767  int removeNode(const Node& node)
768  {
769  return cmzn_nodeset_group_remove_node(reinterpret_cast<cmzn_nodeset_group_id>(id),
770  node.getId());
771  }
772 
782  int removeNodesConditional(const Field& conditionalField)
783  {
784  return cmzn_nodeset_group_remove_nodes_conditional(
785  reinterpret_cast<cmzn_nodeset_group_id>(id), conditionalField.getId());
786  }
787 
788 };
789 
791 {
792  return NodesetGroup(cmzn_nodeset_cast_group(id));
793 }
794 
801 {
802 private:
803 
804  cmzn_nodesetchanges_id id;
805 
806 public:
807 
808  Nodesetchanges() : id(0)
809  { }
810 
811  // takes ownership of C handle, responsibility for destroying it
812  explicit Nodesetchanges(cmzn_nodesetchanges_id nodesetchanges_id) :
813  id(nodesetchanges_id)
814  { }
815 
816  Nodesetchanges(const Nodesetchanges& nodesetchanges) :
817  id(cmzn_nodesetchanges_access(nodesetchanges.id))
818  { }
819 
820  Nodesetchanges& operator=(const Nodesetchanges& nodesetchanges)
821  {
822  cmzn_nodesetchanges_id temp_id = cmzn_nodesetchanges_access(nodesetchanges.id);
823  if (0 != id)
824  cmzn_nodesetchanges_destroy(&id);
825  id = temp_id;
826  return *this;
827  }
828 
829  ~Nodesetchanges()
830  {
831  if (0 != id)
832  cmzn_nodesetchanges_destroy(&id);
833  }
834 
840  bool isValid() const
841  {
842  return (0 != id);
843  }
844 
852  {
853  return cmzn_nodesetchanges_get_node_change_flags(id, node.getId());
854  }
855 
863  {
864  return cmzn_nodesetchanges_get_number_of_changes(id);
865  }
866 
873  {
874  return cmzn_nodesetchanges_get_summary_node_change_flags(id);
875  }
876 };
877 
878 inline int Node::merge(const Nodetemplate& nodeTemplate)
879 {
880  return cmzn_node_merge(id, nodeTemplate.getId());
881 }
882 
883 } // namespace Zinc
884 }
885 
886 #endif
An iterator for looping through all the nodes in a nodeset.
Definition: node.hpp:395
bool isValid() const
Definition: node.hpp:840
Object describing changes to a nodeset in a fieldmoduleevent.
Definition: node.hpp:800
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:728
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:767
ValueLabel
Definition: node.hpp:84
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:50
int removeNodesConditional(const Field &conditionalField)
Definition: node.hpp:782
Node::ChangeFlags getNodeChangeFlags(const Node &node)
Definition: node.hpp:851
int getIdentifier()
Definition: node.hpp:152
A subset of a master nodeset.
Definition: node.hpp:698
cmzn_nodeset_id getId() const
Definition: node.hpp:515
int destroyAllNodes()
Definition: node.hpp:591
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:715
NodesetGroup castGroup()
Definition: node.hpp:790
Node::ChangeFlags getSummaryNodeChangeFlags()
Definition: node.hpp:872
ChangeFlag
Definition: node.hpp:60
Node findNodeByIdentifier(int identifier)
Definition: node.hpp:636
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:102
Nodeiterator createNodeiterator()
Definition: node.hpp:577
int destroyNode(const Node &node)
Definition: node.hpp:606
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:654
Nodeset getNodeset() const
Definition: node.hpp:688
int getSize()
Definition: node.hpp:676
char * getName()
Definition: node.hpp:666
cmzn_node_id getId() const
Definition: node.hpp:140
int getNumberOfChanges()
Definition: node.hpp:862
int defineField(const Field &field)
Definition: node.hpp:262
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:134
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:753
int destroyNodesConditional(const Field &conditionalField)
Definition: node.hpp:625
int addNodesConditional(const Field &conditionalField)
Definition: node.hpp:742
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:1784