GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/group-node.cpp Lines: 1 73 1.4 %
Date: 2020-05-14 11:23:33 Branches: 2 82 2.4 %

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
    }
20
21
    GroupNode::GroupNode (const GroupNode& other):
22
        Node (other), list_of_objects_()
23
    {
24
        size_t i;
25
        for (i=0;
26
             i < other.getNumOfChildren();
27
             i++)
28
        {
29
            addChild(other.getChild(i));
30
        }
31
    }
32
33
    void GroupNode::initWeakPtr(GroupNodeWeakPtr other_weak_ptr)
34
    {
35
        weak_ptr_ = other_weak_ptr;
36
    }
37
38
    /* End of declaration of private function members */
39
40
    /* Declaration of protected function members */
41
    GroupNodePtr_t GroupNode::create(const std::string& name)
42
    {
43
        GroupNodePtr_t shared_ptr(new GroupNode(name));
44
45
        // Add reference to itself
46
        shared_ptr->initWeakPtr(shared_ptr);
47
48
        return shared_ptr;
49
    }
50
51
    GroupNodePtr_t GroupNode::createCopy(GroupNodePtr_t other)
52
    {
53
        GroupNodePtr_t shared_ptr(new GroupNode(*other));
54
55
        // Add reference to itself
56
        shared_ptr->initWeakPtr(shared_ptr);
57
58
        return shared_ptr;
59
    }
60
61
    /* End of declaration of protected function members */
62
63
    /* Declaration of public function members */
64
65
    GroupNodePtr_t GroupNode::clone(void) const
66
    {
67
        return GroupNode::createCopy(weak_ptr_.lock());
68
    }
69
70
    GroupNodePtr_t GroupNode::self(void) const
71
    {
72
        return weak_ptr_.lock();
73
    }
74
75
    bool GroupNode::addChild (NodePtr_t child_ptr)
76
    {
77
        list_of_objects_.push_back(child_ptr);
78
        this->asQueue()->addChild(child_ptr->asGroup());
79
        setDirty();
80
        return true;
81
    }
82
83
    bool GroupNode::removeChild (NodePtr_t child_ptr)
84
    {
85
        Nodes_t::iterator it =
86
            std::find (list_of_objects_.begin(), list_of_objects_.end(), child_ptr);
87
        if (it != list_of_objects_.end())
88
          list_of_objects_.erase(it);
89
        bool removed = this->asQueue()->removeChild(this->asQueue()->getChildIndex(child_ptr->asGroup()));
90
        if (removed) setDirty();
91
        return removed;
92
    }
93
94
    bool GroupNode::hasChild (NodePtr_t child_ptr) const
95
    {
96
        Nodes_t::const_iterator it =
97
            std::find (list_of_objects_.begin(), list_of_objects_.end(), child_ptr);
98
        return it != list_of_objects_.end();
99
    }
100
101
    void GroupNode::removeAllChildren()
102
    {
103
        list_of_objects_.clear();
104
        this->asQueue()->removeChild(0, this->asQueue()->getNumChildren());
105
        setDirty();
106
    }
107
108
    void GroupNode::setLightingMode (const LightingMode& lighting_state)
109
    {
110
        Node::setLightingMode ( lighting_state );
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();
114
             iter_list_of_objects++)
115
        {
116
            (*iter_list_of_objects)->setLightingMode ( lighting_state );
117
        }
118
    }
119
120
    void GroupNode::setWireFrameMode (const WireFrameMode& wireframe_state)
121
    {
122
        Node::setWireFrameMode ( wireframe_state );
123
124
        Nodes_t::iterator iter_list_of_objects;
125
        for (iter_list_of_objects = list_of_objects_.begin();
126
             iter_list_of_objects != list_of_objects_.end();
127
             iter_list_of_objects++)
128
        {
129
            (*iter_list_of_objects)->setWireFrameMode ( wireframe_state );
130
        }
131
    }
132
133
    void GroupNode::setAlpha (const float& alpha)
134
    {
135
      alpha_ = alpha;
136
      Nodes_t::iterator iter_list_of_objects;
137
      for (iter_list_of_objects = list_of_objects_.begin();
138
	   iter_list_of_objects != list_of_objects_.end();
139
	   iter_list_of_objects++)
140
        {
141
	  (*iter_list_of_objects)->setAlpha ( alpha );
142
	}
143
    }
144
145
    void GroupNode::setColor (const osgVector4& color)
146
    {
147
        Nodes_t::iterator iter_list_of_objects;
148
        for (iter_list_of_objects = list_of_objects_.begin();
149
             iter_list_of_objects != list_of_objects_.end();
150
             iter_list_of_objects++)
151
        {
152
            (*iter_list_of_objects)->setColor ( color );
153
        }
154
    }
155
156
    void GroupNode::traverse (NodeVisitor& visitor)
157
    {
158
        Nodes_t::iterator iter_list_of_objects;
159
        for (iter_list_of_objects = list_of_objects_.begin();
160
             iter_list_of_objects != list_of_objects_.end();
161
             iter_list_of_objects++)
162
        {
163
            (*iter_list_of_objects)->accept ( visitor );
164
        }
165
    }
166
167
  osg::ref_ptr<osg::Node> GroupNode::getOsgNode() const
168
    {
169
      return this->asQueue();
170
    }
171
172
    GroupNode::~GroupNode()
173
    {
174
        removeAllChildren();
175
    }
176
177
    /* End of declaration of public function members */
178
179
} /* namespace viewer */
180

3
} /* namespace gepetto */