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

Line Branch Exec Source
1
//
2
//  leaf-node-cone.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-cone.h>
10
11
namespace gepetto {
12
namespace viewer {
13
14
    /* Declaration of private function members */
15
16
    void LeafNodeCone::init ()
17
    {
18
        /* Create cone object */
19
        cone_ptr_ = new osg::Cone ();
20
21
        /* Set ShapeDrawable */
22
        shape_drawable_ptr_ = new osg::ShapeDrawable(cone_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
35
    LeafNodeCone::LeafNodeCone (const std::string& name, const float& radius, const float &height) :
36
        NodeDrawable (name)
37
    {
38
        init();
39
        setRadius(radius);
40
        setHeight(height);
41
        setColor(osgVector4(1.,1.,1.,1.));
42
    }
43
44
    LeafNodeCone::LeafNodeCone (const std::string& name, const float& radius, const float &height, const osgVector4& color) :
45
        NodeDrawable (name)
46
    {
47
        init();
48
        setRadius(radius);
49
        setHeight(height);
50
        setColor(color);
51
    }
52
    LeafNodeCone::LeafNodeCone (const LeafNodeCone& other) :
53
        NodeDrawable(other)
54
    {
55
        init();
56
        setRadius(other.getRadius());
57
        setHeight(other.getHeight());
58
        setColor(other.getColor());
59
    }
60
61
    void LeafNodeCone::initWeakPtr (LeafNodeConeWeakPtr other_weak_ptr)
62
    {
63
        weak_ptr_ = other_weak_ptr;
64
    }
65
66
    /* End of declaration of private function members */
67
68
    /* Declaration of protected function members */
69
70
    LeafNodeConePtr_t LeafNodeCone::create (const std::string& name, const float &radius, const float &height)
71
    {
72
        LeafNodeConePtr_t shared_ptr (new LeafNodeCone(name, radius, height));
73
74
        // Add reference to itself
75
        shared_ptr->initWeakPtr (shared_ptr);
76
77
        return shared_ptr;
78
    }
79
80
    LeafNodeConePtr_t LeafNodeCone::create (const std::string& name, const float &radius, const float &height, const osgVector4& color)
81
    {
82
        LeafNodeConePtr_t shared_ptr (new LeafNodeCone(name, radius, height, color));
83
84
        // Add reference to itself
85
        shared_ptr->initWeakPtr (shared_ptr);
86
87
        return shared_ptr;
88
    }
89
90
    LeafNodeConePtr_t LeafNodeCone::createCopy (LeafNodeConePtr_t other)
91
    {
92
        LeafNodeConePtr_t shared_ptr (new LeafNodeCone(*other));
93
94
        // Add reference to itself
95
        shared_ptr->initWeakPtr (shared_ptr);
96
97
        return shared_ptr;
98
    }
99
100
    /* End of declaration of protected function members */
101
102
    /* Declaration of public function members */
103
104
    LeafNodeConePtr_t LeafNodeCone::clone (void) const
105
    {
106
        return LeafNodeCone::createCopy(weak_ptr_.lock());
107
    }
108
109
    LeafNodeConePtr_t LeafNodeCone::self (void) const
110
    {
111
        return weak_ptr_.lock ();
112
    }
113
114
    void LeafNodeCone::setRadius (const float& radius)
115
    {
116
        cone_ptr_->setRadius(radius);
117
        redrawShape ();
118
    }
119
120
    void LeafNodeCone::setHeight (const float& height)
121
    {
122
        cone_ptr_->setHeight(height);
123
        redrawShape ();
124
    }
125
126
    LeafNodeCone::~LeafNodeCone ()
127
    {
128
        /* Proper deletion of all tree scene */
129
        geode_ptr_->removeDrawable(shape_drawable_ptr_);
130
        shape_drawable_ptr_ = NULL;
131
132
        this->asQueue()->removeChild(geode_ptr_);
133
        geode_ptr_ = NULL;
134
135
        weak_ptr_.reset();
136
    }
137
138
    /* End of declaration of public function members */
139
140
} /* namespace viewer */
141
142

3
} /* namespace gepetto */