GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/roadmap-viewer.cpp Lines: 1 94 1.1 %
Date: 2020-05-14 11:23:33 Branches: 2 144 1.4 %

Line Branch Exec Source
1
//
2
//  roadmap-viewer.cpp
3
//  gepetto-viewer
4
//
5
//  Created by Pierre Fernbach in april 2015.
6
//  Copyright (c) 2015 LAAS-CNRS. All rights reserved.
7
//
8
9
#include <gepetto/viewer/roadmap-viewer.h>
10
#include <sstream>
11
12
#include <gepetto/viewer/leaf-node-sphere.h>
13
14
namespace gepetto {
15
namespace viewer {
16
    /* Declaration of private function members */
17
18
    RoadmapViewer::RoadmapViewer (const std::string& name,const osgVector4& colorNode,float radiusSphere,float sizeAxis,const osgVector4& colorEdge):
19
        Node (name), list_nodes_(),list_edges_()
20
    {
21
        colorNode_=osgVector4(colorNode);
22
        colorEdge_=osgVector4(colorEdge);
23
        radiusSphere_=radiusSphere;
24
        sizeAxis_ = sizeAxis;
25
26
    }
27
28
    RoadmapViewer::RoadmapViewer (const RoadmapViewer& other):
29
        Node (other), list_nodes_(),list_edges_()
30
    {
31
        size_t i;
32
        for (i=0;i < other.getNumOfNodes(); i++)
33
        {
34
            LeafNodeXYZAxisPtr_t node = LeafNodeXYZAxis::createCopy(other.getNode(i));
35
            list_nodes_.push_back(node);
36
        }
37
        for (i=0;i < other.getNumOfEdges(); i++)
38
        {
39
            LeafNodeLinePtr_t edge = LeafNodeLine::createCopy(other.getEdge(i));
40
            list_edges_.push_back(edge);
41
        }
42
        colorNode_ = other.getColorNode();
43
        colorEdge_ = other.getColorEdge();
44
        sizeAxis_ = other.getSizeAxis();
45
        radiusSphere_ = other.getRadiusSphere();
46
    }
47
48
    void RoadmapViewer::initWeakPtr(RoadmapViewerWeakPtr other_weak_ptr)
49
    {
50
        weak_ptr_ = other_weak_ptr;
51
    }
52
53
    /* End of declaration of private function members */
54
55
    /* Declaration of public function members */
56
    RoadmapViewerPtr_t RoadmapViewer::create(const std::string& name,const osgVector4& colorNode,float radiusSphere,float sizeAxis,const osgVector4& colorEdge)
57
    {
58
        RoadmapViewerPtr_t shared_ptr(new RoadmapViewer(name,colorNode,radiusSphere,sizeAxis,colorEdge));
59
60
        // Add reference to itself
61
        shared_ptr->initWeakPtr(shared_ptr);
62
63
        return shared_ptr;
64
    }
65
66
   RoadmapViewerPtr_t RoadmapViewer::createCopy(RoadmapViewerPtr_t other)
67
    {
68
        RoadmapViewerPtr_t shared_ptr(new RoadmapViewer(*other));
69
70
        // Add reference to itself
71
        shared_ptr->initWeakPtr(shared_ptr);
72
73
        return shared_ptr;
74
    }
75
76
77
   RoadmapViewerPtr_t RoadmapViewer::clone(void) const
78
   {
79
       return RoadmapViewer::createCopy(weak_ptr_.lock());
80
   }
81
82
   RoadmapViewerPtr_t RoadmapViewer::self(void) const
83
   {
84
       return weak_ptr_.lock();
85
   }
86
87
   // -------------------------------------------
88
89
   bool RoadmapViewer::addNode(osgVector3 position, osgQuat quat, OpenThreads::Mutex& mtx){
90
       std::stringstream msg;
91
       msg << getID()<<"_node"<<list_nodes_.size();
92
93
       LeafNodeXYZAxisPtr_t node = LeafNodeXYZAxis::create(msg.str(),colorNode_,radiusSphere_,sizeAxis_);
94
       list_nodes_.push_back(node);
95
96
       mtx.lock(); // need mutex (from windowsManager) : if we add graphical object during the call of osg::frame() we have a gepetto-viewer seg fault
97
       node->applyConfiguration (position,quat);
98
       this->asQueue()->addChild(node->asGroup());;
99
       mtx.unlock();
100
101
       return true;
102
   }
103
104
   bool RoadmapViewer::addEdge(osgVector3 from, osgVector3 to, OpenThreads::Mutex& mtx){
105
       std::stringstream msg;
106
       msg << getID()<<"_Edge"<<list_edges_.size();
107
       LeafNodeLinePtr_t edge = LeafNodeLine::create (msg.str(),from, to, colorEdge_);
108
       list_edges_.push_back(edge);
109
110
       mtx.lock();
111
       this->asQueue()->addChild(edge->asGroup());
112
       mtx.unlock();
113
       return true;
114
   }
115
116
   void RoadmapViewer::removeAllChildren()
117
   {
118
       list_nodes_.clear();
119
       list_edges_.clear();
120
       this->asQueue()->removeChild(0, this->asQueue()->getNumChildren());
121
   }
122
123
   void RoadmapViewer::setVisibilityMode (const VisibilityMode& visibility_state)
124
   {
125
       Node::setVisibilityMode (visibility_state);
126
       std::list<LeafNodeXYZAxisPtr_t>::iterator iter_list_of_nodes;
127
       for (iter_list_of_nodes = list_nodes_.begin();
128
            iter_list_of_nodes != list_nodes_.end();
129
            iter_list_of_nodes++)
130
       {
131
           (*iter_list_of_nodes)->setVisibilityMode ( visibility_state );
132
       }
133
       std::list<LeafNodeLinePtr_t>::iterator iter_list_of_edges;
134
       for (iter_list_of_edges = list_edges_.begin();
135
            iter_list_of_edges != list_edges_.end();
136
            iter_list_of_edges++)
137
       {
138
           (*iter_list_of_edges)->setVisibilityMode ( visibility_state );
139
       }
140
   }
141
142
   void RoadmapViewer::setLightingMode (const LightingMode& lighting_state)
143
   {
144
       Node::setLightingMode ( lighting_state );
145
       std::list<LeafNodeXYZAxisPtr_t>::iterator iter_list_of_nodes;
146
       for (iter_list_of_nodes = list_nodes_.begin();
147
            iter_list_of_nodes != list_nodes_.end();
148
            iter_list_of_nodes++)
149
       {
150
           (*iter_list_of_nodes)->setLightingMode ( lighting_state );
151
       }
152
       std::list<LeafNodeLinePtr_t>::iterator iter_list_of_edges;
153
       for (iter_list_of_edges = list_edges_.begin();
154
            iter_list_of_edges != list_edges_.end();
155
            iter_list_of_edges++)
156
       {
157
           (*iter_list_of_edges)->setLightingMode ( lighting_state );
158
       }
159
   }
160
161
   void RoadmapViewer::setWireFrameMode (const WireFrameMode& wireframe_state)
162
   {
163
       Node::setWireFrameMode ( wireframe_state );
164
165
       std::list<LeafNodeXYZAxisPtr_t>::iterator iter_list_of_nodes;
166
       for (iter_list_of_nodes = list_nodes_.begin();
167
            iter_list_of_nodes != list_nodes_.end();
168
            iter_list_of_nodes++)
169
       {
170
           (*iter_list_of_nodes)->setWireFrameMode ( wireframe_state );
171
       }
172
       std::list<LeafNodeLinePtr_t>::iterator iter_list_of_edges;
173
       for (iter_list_of_edges = list_edges_.begin();
174
            iter_list_of_edges != list_edges_.end();
175
            iter_list_of_edges++)
176
       {
177
           (*iter_list_of_edges)->setWireFrameMode ( wireframe_state );
178
       }
179
   }
180
181
   void RoadmapViewer::setColorNode(const osgVector4& color)
182
   {
183
     std::list<LeafNodeXYZAxisPtr_t>::iterator it;
184
     for (it = list_nodes_.begin(); it != list_nodes_.end(); ++it) {
185
       (*it)->setColor ( color );
186
     }
187
   }
188
189
   void RoadmapViewer::setColorEdge(const osgVector4& color)
190
   {
191
     std::list<LeafNodeLinePtr_t>::iterator it;
192
     for (it = list_edges_.begin(); it != list_edges_.end(); ++it) {
193
       (*it)->setColor ( color );
194
     }
195
   }
196
197
    /* End of declaration of public function members */
198
199
200
} /* namespace viewer */
201
202

3
} // namespace gepetto