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