Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// leaf-node-arrow.cpp |
3 |
|
|
// gepetto-viewer |
4 |
|
|
// |
5 |
|
|
// Created by Pierre Fernbach in june 2015. |
6 |
|
|
// Copyright (c) 2015 LAAS-CNRS. All rights reserved. |
7 |
|
|
// |
8 |
|
|
|
9 |
|
|
#include <gepetto/viewer/leaf-node-arrow.h> |
10 |
|
|
|
11 |
|
|
#include <osg/Version> |
12 |
|
|
|
13 |
|
|
namespace gepetto { |
14 |
|
|
namespace viewer { |
15 |
|
|
|
16 |
|
|
/* Declaration of private function members */ |
17 |
|
|
|
18 |
|
✗ |
void LeafNodeArrow::init() { |
19 |
|
|
/* Create Geode for adding ShapeDrawable */ |
20 |
|
✗ |
geode_ptr_ = new osg::Geode(); |
21 |
|
|
|
22 |
|
✗ |
resetGeodeContent(); |
23 |
|
|
|
24 |
|
|
/* Create PositionAttitudeTransform */ |
25 |
|
✗ |
this->asQueue()->addChild(geode_ptr_); |
26 |
|
|
|
27 |
|
|
/* Allow transparency */ |
28 |
|
✗ |
geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, |
29 |
|
|
::osg::StateAttribute::ON); |
30 |
|
|
; |
31 |
|
|
|
32 |
|
✗ |
addProperty(FloatProperty::create( |
33 |
|
|
"Radius", |
34 |
|
✗ |
FloatProperty::getterFromMemberFunction(this, &LeafNodeArrow::getRadius), |
35 |
|
✗ |
FloatProperty::setterFromMemberFunction(this, |
36 |
|
|
&LeafNodeArrow::setRadius))); |
37 |
|
✗ |
addProperty(FloatProperty::create( |
38 |
|
|
"Size", |
39 |
|
✗ |
FloatProperty::getterFromMemberFunction(this, &LeafNodeArrow::getSize), |
40 |
|
✗ |
FloatProperty::setterFromMemberFunction(this, &LeafNodeArrow::setSize))); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
✗ |
void LeafNodeArrow::resetGeodeContent() { |
44 |
|
✗ |
if (cylinder_drawable_) geode_ptr_->removeDrawable(cylinder_drawable_); |
45 |
|
✗ |
if (cone_drawable_) geode_ptr_->removeDrawable(cone_drawable_); |
46 |
|
|
|
47 |
|
|
/* create the axis : */ |
48 |
|
✗ |
float R = getRadius(); |
49 |
|
✗ |
float L = getSize(); |
50 |
|
✗ |
float Lcone = std::min(L, 4.f * R); |
51 |
|
|
|
52 |
|
|
/* Create cylinder */ |
53 |
|
✗ |
::osg::CylinderRefPtr cylinder_shape_x_ptr = new ::osg::Cylinder(); |
54 |
|
✗ |
cylinder_shape_x_ptr->set(osgVector3((L - Lcone) / 2.f, 0.f, 0.f), R, |
55 |
|
|
L - Lcone); |
56 |
|
✗ |
cylinder_shape_x_ptr->setRotation( |
57 |
|
✗ |
osgQuat(0.f, ::osg::X_AXIS, M_PI_2, ::osg::Y_AXIS, 0.f, ::osg::Z_AXIS)); |
58 |
|
|
/* Create cone */ |
59 |
|
✗ |
::osg::ConeRefPtr cone_shape_x_ptr = new ::osg::Cone(); |
60 |
|
✗ |
cone_shape_x_ptr->set(osgVector3(L - 3 * Lcone / 4, 0.f, 0.f), 2.f * R, |
61 |
|
|
Lcone); |
62 |
|
✗ |
cone_shape_x_ptr->setRotation( |
63 |
|
✗ |
osgQuat(0.f, ::osg::X_AXIS, M_PI_2, ::osg::Y_AXIS, 0.f, ::osg::Z_AXIS)); |
64 |
|
|
|
65 |
|
|
/* create drawable and add them to geode */ |
66 |
|
✗ |
cylinder_drawable_ = new ::osg::ShapeDrawable(cylinder_shape_x_ptr); |
67 |
|
✗ |
cone_drawable_ = new ::osg::ShapeDrawable(cone_shape_x_ptr); |
68 |
|
✗ |
setColor(color_); |
69 |
|
|
|
70 |
|
✗ |
geode_ptr_->addDrawable(cylinder_drawable_); |
71 |
|
✗ |
geode_ptr_->addDrawable(cone_drawable_); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
✗ |
LeafNodeArrow::LeafNodeArrow(const std::string& name, const osgVector4& color, |
75 |
|
✗ |
float radius, float size) |
76 |
|
✗ |
: NodeDrawable(name), color_(color) { |
77 |
|
✗ |
radius_ = radius; |
78 |
|
✗ |
size_ = size; |
79 |
|
|
|
80 |
|
✗ |
init(); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
✗ |
LeafNodeArrow::LeafNodeArrow(const LeafNodeArrow& other) |
84 |
|
✗ |
: NodeDrawable(other.getID()) { |
85 |
|
✗ |
init(); |
86 |
|
|
// TODO |
87 |
|
|
} |
88 |
|
|
|
89 |
|
✗ |
void LeafNodeArrow::initWeakPtr(LeafNodeArrowWeakPtr other_weak_ptr) { |
90 |
|
✗ |
weak_ptr_ = other_weak_ptr; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* End of declaration of private function members */ |
94 |
|
|
|
95 |
|
|
/* Declaration of protected function members */ |
96 |
|
|
|
97 |
|
✗ |
LeafNodeArrowPtr_t LeafNodeArrow::create(const std::string& name, |
98 |
|
|
const osgVector4& color, |
99 |
|
|
float radiusCenter, float size) { |
100 |
|
|
LeafNodeArrowPtr_t shared_ptr( |
101 |
|
✗ |
new LeafNodeArrow(name, color, radiusCenter, size)); |
102 |
|
|
|
103 |
|
|
// Add reference to itself |
104 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
105 |
|
|
|
106 |
|
✗ |
return shared_ptr; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
✗ |
LeafNodeArrowPtr_t LeafNodeArrow::create(const std::string& name, |
110 |
|
|
const osgVector4& color, |
111 |
|
|
float radiusCenter) { |
112 |
|
|
LeafNodeArrowPtr_t shared_ptr( |
113 |
|
✗ |
new LeafNodeArrow(name, color, radiusCenter, 4 * radiusCenter)); |
114 |
|
|
|
115 |
|
|
// Add reference to itself |
116 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
117 |
|
|
|
118 |
|
✗ |
return shared_ptr; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
✗ |
LeafNodeArrowPtr_t LeafNodeArrow::createCopy(LeafNodeArrowPtr_t other) { |
122 |
|
✗ |
LeafNodeArrowPtr_t shared_ptr(new LeafNodeArrow(*other)); |
123 |
|
|
|
124 |
|
|
// Add reference to itself |
125 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
126 |
|
|
|
127 |
|
✗ |
return shared_ptr; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/* End of declaration of protected function members */ |
131 |
|
|
|
132 |
|
|
/* Declaration of public function members */ |
133 |
|
|
|
134 |
|
✗ |
LeafNodeArrowPtr_t LeafNodeArrow::clone(void) const { |
135 |
|
✗ |
return LeafNodeArrow::createCopy(weak_ptr_.lock()); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
✗ |
LeafNodeArrowPtr_t LeafNodeArrow::self(void) const { return weak_ptr_.lock(); } |
139 |
|
|
|
140 |
|
✗ |
void LeafNodeArrow::setRadius(const float& radius) { |
141 |
|
✗ |
if (radius != getRadius()) { // avoid useless resize |
142 |
|
✗ |
radius_ = radius; |
143 |
|
✗ |
resetGeodeContent(); |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
|
✗ |
float LeafNodeArrow::getRadius() const { return radius_; } |
148 |
|
|
|
149 |
|
✗ |
void LeafNodeArrow::setSize(const float& size) { |
150 |
|
✗ |
if (size != getSize()) { // avoid useless resize |
151 |
|
✗ |
size_ = size; |
152 |
|
✗ |
resetGeodeContent(); |
153 |
|
|
} |
154 |
|
|
} |
155 |
|
|
|
156 |
|
✗ |
float LeafNodeArrow::getSize() const { return size_; } |
157 |
|
|
|
158 |
|
✗ |
void LeafNodeArrow::setColor(const osgVector4& color) { |
159 |
|
✗ |
cylinder_drawable_->setColor(color); |
160 |
|
✗ |
cone_drawable_->setColor(color); |
161 |
|
|
#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 6) |
162 |
|
✗ |
cylinder_drawable_->build(); |
163 |
|
✗ |
cone_drawable_->build(); |
164 |
|
|
#else |
165 |
|
|
cylinder_drawable_->dirtyDisplayList(); |
166 |
|
|
cone_drawable_->dirtyDisplayList(); |
167 |
|
|
cylinder_drawable_->dirtyBound(); |
168 |
|
|
cone_drawable_->dirtyBound(); |
169 |
|
|
#endif |
170 |
|
✗ |
color_ = color; |
171 |
|
✗ |
setTransparentRenderingBin(color[3] < |
172 |
|
✗ |
Node::TransparencyRenderingBinThreshold); |
173 |
|
✗ |
setDirty(); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
✗ |
void LeafNodeArrow::resize(float radius, float length) { |
177 |
|
✗ |
if (length != getSize() || radius != getRadius()) { // avoid useless resize |
178 |
|
✗ |
size_ = length; |
179 |
|
✗ |
radius_ = radius; |
180 |
|
|
|
181 |
|
✗ |
resetGeodeContent(); |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
|
185 |
|
✗ |
LeafNodeArrow::~LeafNodeArrow() { |
186 |
|
|
/* Proper deletion of all tree scene */ |
187 |
|
|
|
188 |
|
✗ |
geode_ptr_->removeDrawable(cylinder_drawable_); |
189 |
|
✗ |
geode_ptr_->removeDrawable(cone_drawable_); |
190 |
|
|
|
191 |
|
✗ |
geode_ptr_ = NULL; |
192 |
|
✗ |
cylinder_drawable_ = NULL; |
193 |
|
✗ |
cone_drawable_ = NULL; |
194 |
|
|
|
195 |
|
✗ |
weak_ptr_.reset(); |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
/* End of declaration of public function members */ |
199 |
|
|
|
200 |
|
|
} /* namespace viewer */ |
201 |
|
|
} /* namespace gepetto */ |
202 |
|
|
|