GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/leaf-node-sphere.cpp Lines: 1 56 1.8 %
Date: 2020-05-14 11:23:33 Branches: 2 84 2.4 %

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

3
} /* namespace gepetto */