GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/leaf-node-cylinder.cpp Lines: 1 62 1.6 %
Date: 2020-05-14 11:23:33 Branches: 2 80 2.5 %

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

3
} /* namespace gepetto */