GCC Code Coverage Report


Directory: ./
File: src/group-node.cpp
Date: 2024-08-14 11:04:57
Exec Total Coverage
Lines: 0 68 0.0%
Branches: 0 80 0.0%

Line Branch Exec Source
1 //
2 // group-node.cpp
3 // gepetto-viewer
4 //
5 // Created by Justin Carpentier, Mathieu Geisert in November 2014.
6 // Copyright (c) 2014 LAAS-CNRS. All rights reserved.
7 //
8
9 #include <gepetto/viewer/group-node.h>
10
11 namespace gepetto {
12 namespace viewer {
13
14 /* Declaration of private function members */
15
16 GroupNode::GroupNode(const std::string& name)
17 : Node(name), list_of_objects_() {}
18
19 GroupNode::GroupNode(const GroupNode& other) : Node(other), list_of_objects_() {
20 size_t i;
21 for (i = 0; i < other.getNumOfChildren(); i++) {
22 addChild(other.getChild(i));
23 }
24 }
25
26 void GroupNode::initWeakPtr(GroupNodeWeakPtr other_weak_ptr) {
27 weak_ptr_ = other_weak_ptr;
28 }
29
30 /* End of declaration of private function members */
31
32 /* Declaration of protected function members */
33 GroupNodePtr_t GroupNode::create(const std::string& name) {
34 GroupNodePtr_t shared_ptr(new GroupNode(name));
35
36 // Add reference to itself
37 shared_ptr->initWeakPtr(shared_ptr);
38
39 return shared_ptr;
40 }
41
42 GroupNodePtr_t GroupNode::createCopy(GroupNodePtr_t other) {
43 GroupNodePtr_t shared_ptr(new GroupNode(*other));
44
45 // Add reference to itself
46 shared_ptr->initWeakPtr(shared_ptr);
47
48 return shared_ptr;
49 }
50
51 /* End of declaration of protected function members */
52
53 /* Declaration of public function members */
54
55 GroupNodePtr_t GroupNode::clone(void) const {
56 return GroupNode::createCopy(weak_ptr_.lock());
57 }
58
59 GroupNodePtr_t GroupNode::self(void) const { return weak_ptr_.lock(); }
60
61 bool GroupNode::addChild(NodePtr_t child_ptr) {
62 list_of_objects_.push_back(child_ptr);
63 this->asQueue()->addChild(child_ptr->asGroup());
64 setDirty();
65 return true;
66 }
67
68 bool GroupNode::removeChild(NodePtr_t child_ptr) {
69 Nodes_t::iterator it =
70 std::find(list_of_objects_.begin(), list_of_objects_.end(), child_ptr);
71 if (it != list_of_objects_.end()) list_of_objects_.erase(it);
72 bool removed = this->asQueue()->removeChild(
73 this->asQueue()->getChildIndex(child_ptr->asGroup()));
74 if (removed) setDirty();
75 return removed;
76 }
77
78 bool GroupNode::hasChild(NodePtr_t child_ptr) const {
79 Nodes_t::const_iterator it =
80 std::find(list_of_objects_.begin(), list_of_objects_.end(), child_ptr);
81 return it != list_of_objects_.end();
82 }
83
84 void GroupNode::removeAllChildren() {
85 list_of_objects_.clear();
86 this->asQueue()->removeChild(0, this->asQueue()->getNumChildren());
87 setDirty();
88 }
89
90 void GroupNode::setLightingMode(const LightingMode& lighting_state) {
91 Node::setLightingMode(lighting_state);
92 Nodes_t::iterator iter_list_of_objects;
93 for (iter_list_of_objects = list_of_objects_.begin();
94 iter_list_of_objects != list_of_objects_.end(); iter_list_of_objects++) {
95 (*iter_list_of_objects)->setLightingMode(lighting_state);
96 }
97 }
98
99 void GroupNode::setWireFrameMode(const WireFrameMode& wireframe_state) {
100 Node::setWireFrameMode(wireframe_state);
101
102 Nodes_t::iterator iter_list_of_objects;
103 for (iter_list_of_objects = list_of_objects_.begin();
104 iter_list_of_objects != list_of_objects_.end(); iter_list_of_objects++) {
105 (*iter_list_of_objects)->setWireFrameMode(wireframe_state);
106 }
107 }
108
109 void GroupNode::setAlpha(const float& alpha) {
110 alpha_ = alpha;
111 Nodes_t::iterator iter_list_of_objects;
112 for (iter_list_of_objects = list_of_objects_.begin();
113 iter_list_of_objects != list_of_objects_.end(); iter_list_of_objects++) {
114 (*iter_list_of_objects)->setAlpha(alpha);
115 }
116 }
117
118 void GroupNode::setColor(const osgVector4& color) {
119 Nodes_t::iterator iter_list_of_objects;
120 for (iter_list_of_objects = list_of_objects_.begin();
121 iter_list_of_objects != list_of_objects_.end(); iter_list_of_objects++) {
122 (*iter_list_of_objects)->setColor(color);
123 }
124 }
125
126 void GroupNode::traverse(NodeVisitor& visitor) {
127 Nodes_t::iterator iter_list_of_objects;
128 for (iter_list_of_objects = list_of_objects_.begin();
129 iter_list_of_objects != list_of_objects_.end(); iter_list_of_objects++) {
130 (*iter_list_of_objects)->accept(visitor);
131 }
132 }
133
134 osg::ref_ptr<osg::Node> GroupNode::getOsgNode() const {
135 return this->asQueue();
136 }
137
138 GroupNode::~GroupNode() { removeAllChildren(); }
139
140 /* End of declaration of public function members */
141
142 } /* namespace viewer */
143 } /* namespace gepetto */
144