GCC Code Coverage Report


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

Line Branch Exec Source
1 //
2 // leaf-node-capsule.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/leaf-node-capsule.h>
10
11 namespace gepetto {
12 namespace viewer {
13
14 /* Declaration of private function members */
15
16 void LeafNodeCapsule::init() {
17 /* Create capsule object */
18
19 capsule_ptr_ = new ::osg::Capsule();
20
21 /* Set ShapeDrawable */
22 shape_drawable_ptr_ = new ::osg::ShapeDrawable(capsule_ptr_);
23
24 /* Create Geode for adding ShapeDrawable */
25 geode_ptr_ = new osg::Geode();
26 geode_ptr_->addDrawable(shape_drawable_ptr_);
27
28 RangedFloatProperty::Ptr_t radiusProp = RangedFloatProperty::create(
29 "Radius", this, &LeafNodeCapsule::getRadius, &LeafNodeCapsule::setRadius);
30 radiusProp->min = 0.f;
31 radiusProp->step = 0.1f;
32 radiusProp->adaptiveDecimal = true;
33 addProperty(radiusProp);
34
35 RangedFloatProperty::Ptr_t heightProp = RangedFloatProperty::create(
36 "Height", this, &LeafNodeCapsule::getHeight, &LeafNodeCapsule::setHeight);
37 heightProp->min = 0.f;
38 heightProp->step = 0.1f;
39 heightProp->adaptiveDecimal = true;
40 addProperty(heightProp);
41
42 /* Create PositionAttitudeTransform */
43 this->asQueue()->addChild(geode_ptr_);
44
45 /* Allow transparency */
46 geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND,
47 ::osg::StateAttribute::ON);
48 }
49
50 LeafNodeCapsule::LeafNodeCapsule(const std::string& name, const float& radius,
51 const float& height)
52 : NodeDrawable(name) {
53 init();
54 setRadius(radius);
55 setHeight(height);
56 setColor(osgVector4(1., 1., 1., 1.));
57 }
58
59 LeafNodeCapsule::LeafNodeCapsule(const std::string& name, const float& radius,
60 const float& height, const osgVector4& color)
61 : NodeDrawable(name) {
62 init();
63 setRadius(radius);
64 setHeight(height);
65 setColor(color);
66 }
67
68 LeafNodeCapsule::LeafNodeCapsule(const LeafNodeCapsule& other)
69 : NodeDrawable(other) {
70 init();
71 setRadius(other.getRadius());
72 setHeight(other.getHeight());
73 setColor(other.getColor());
74 }
75
76 void LeafNodeCapsule::initWeakPtr(LeafNodeCapsuleWeakPtr other_weak_ptr) {
77 weak_ptr_ = other_weak_ptr;
78 }
79
80 /* End of declaration of private function members */
81
82 /* Declaration of protected function members */
83
84 LeafNodeCapsulePtr_t LeafNodeCapsule::create(const std::string& name,
85 const float& radius,
86 const float& height) {
87 LeafNodeCapsulePtr_t shared_ptr(new LeafNodeCapsule(name, radius, height));
88
89 // Add reference to itself
90 shared_ptr->initWeakPtr(shared_ptr);
91
92 return shared_ptr;
93 }
94
95 LeafNodeCapsulePtr_t LeafNodeCapsule::create(const std::string& name,
96 const float& radius,
97 const float& height,
98 const osgVector4& color) {
99 LeafNodeCapsulePtr_t shared_ptr(
100 new LeafNodeCapsule(name, radius, height, color));
101
102 // Add reference to itself
103 shared_ptr->initWeakPtr(shared_ptr);
104
105 return shared_ptr;
106 }
107
108 LeafNodeCapsulePtr_t LeafNodeCapsule::createCopy(
109 const LeafNodeCapsulePtr_t& other) {
110 LeafNodeCapsulePtr_t shared_ptr(new LeafNodeCapsule(*other));
111
112 // Add reference to itself
113 shared_ptr->initWeakPtr(shared_ptr);
114
115 return shared_ptr;
116 }
117
118 /* End of declaration of protected function members */
119
120 /* Declaration of public function members */
121
122 LeafNodeCapsulePtr_t LeafNodeCapsule::clone(void) const {
123 return LeafNodeCapsule::createCopy(weak_ptr_.lock());
124 }
125
126 LeafNodeCapsulePtr_t LeafNodeCapsule::self(void) const {
127 return weak_ptr_.lock();
128 }
129
130 void LeafNodeCapsule::setRadius(const float& radius) {
131 capsule_ptr_->setRadius(radius);
132 redrawShape();
133 setDirty();
134 }
135
136 void LeafNodeCapsule::setHeight(const float& height) {
137 capsule_ptr_->setHeight(height);
138 redrawShape();
139 }
140
141 LeafNodeCapsule::~LeafNodeCapsule() {
142 /* Proper deletion of all tree scene */
143 geode_ptr_->removeDrawable(shape_drawable_ptr_);
144 shape_drawable_ptr_ = NULL;
145
146 this->asQueue()->removeChild(geode_ptr_);
147 geode_ptr_ = NULL;
148
149 weak_ptr_.reset();
150 }
151
152 /* End of declaration of public function members */
153
154 } /* namespace viewer */
155
156 } /* namespace gepetto */
157