GCC Code Coverage Report


Directory: ./
File: src/leaf-node-cylinder.cpp
Date: 2024-12-20 15:53:58
Exec Total Coverage
Lines: 0 63 0.0%
Branches: 0 76 0.0%

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