GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/leaf-node-capsule.cpp Lines: 1 67 1.5 %
Date: 2020-05-14 11:23:33 Branches: 2 96 2.1 %

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

3
} /* namespace gepetto */