GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/leaf-node-box.cpp Lines: 36 58 62.1 %
Date: 2020-05-14 11:23:33 Branches: 16 64 25.0 %

Line Branch Exec Source
1
//
2
//  leaf-node-box.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-box.h>
10
11
namespace gepetto {
12
namespace viewer {
13
14
    /* Declaration of private function members */
15
16
1
    void LeafNodeBox::init ()
17
    {
18
        /* Create sphere object */
19
1
        box_ptr_ = new ::osg::Box();
20
21
        /* Set ShapeDrawable */
22
1
        shape_drawable_ptr_ = new ::osg::ShapeDrawable(box_ptr_);
23
24
        /* Create Geode for adding ShapeDrawable */
25
1
        geode_ptr_ = new ::osg::Geode();
26
1
        geode_ptr_->addDrawable(shape_drawable_ptr_);
27
28

2
        addProperty(Vector3Property::create("HalfLength",
29
2
              Vector3Property::getterFromMemberFunction(box_ptr_.get(), &osg::Box::getHalfLengths),
30
2
              Vector3Property::setterFromMemberFunction(this, &LeafNodeBox::setHalfAxis)
31
              ));
32
33
        /* Create PositionAttitudeTransform */
34
1
        this->asQueue()->addChild(geode_ptr_);
35
36
        /* Allow transparency */
37
1
        geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON);
38
1
    }
39
40
1
    LeafNodeBox::LeafNodeBox (const std::string &name, const osgVector3& half_axis) :
41
1
        NodeDrawable(name)
42
    {
43
1
        init();
44
1
        setHalfAxis(half_axis);
45
1
        setColor(osgVector4(1.,1.,1.,1.));
46
1
    }
47
48
    LeafNodeBox::LeafNodeBox (const std::string &name, const osgVector3& half_axis, const osgVector4 &color) :
49
        NodeDrawable(name)
50
    {
51
        init();
52
        setHalfAxis(half_axis);
53
        setColor(color);
54
    }
55
56
    LeafNodeBox::LeafNodeBox (const LeafNodeBox& other) :
57
        NodeDrawable(other)
58
    {
59
        init();
60
        setHalfAxis(other.getHalfAxis());
61
        setColor(other.getColor());
62
    }
63
64
1
    void LeafNodeBox::initWeakPtr (LeafNodeBoxWeakPtr other_weak_ptr )
65
    {
66
1
        weak_ptr_ = other_weak_ptr;
67
1
    }
68
69
    /* End of declaration of private function members */
70
71
    /* Declaration of protected function members */
72
73
1
    LeafNodeBoxPtr_t LeafNodeBox::create (const std::string &name, const osgVector3 &half_axis)
74
    {
75

1
        LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(name, half_axis));
76
77
        // Add reference to itself
78
1
        shared_ptr->initWeakPtr( shared_ptr );
79
80
1
        return shared_ptr;
81
    }
82
83
    LeafNodeBoxPtr_t LeafNodeBox::create (const std::string &name, const osgVector3 &half_axis, const osgVector4 &color)
84
    {
85
        LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(name, half_axis, color));
86
87
        // Add reference to itself
88
        shared_ptr->initWeakPtr( shared_ptr );
89
90
        return shared_ptr;
91
    }
92
93
    LeafNodeBoxPtr_t LeafNodeBox::createCopy (LeafNodeBoxPtr_t other)
94
    {
95
        LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(*other));
96
97
        // Add reference to itself
98
        shared_ptr->initWeakPtr( shared_ptr );
99
100
        return shared_ptr;
101
    }
102
103
    /* End of declaration of protected function members */
104
105
    /* Declaration of public function members */
106
107
    LeafNodeBoxPtr_t LeafNodeBox::clone (void) const
108
    {
109
        return LeafNodeBox::createCopy(weak_ptr_.lock());
110
    }
111
112
    LeafNodeBoxPtr_t LeafNodeBox::self (void) const
113
    {
114
        return weak_ptr_.lock();
115
    }
116
117
1
    void LeafNodeBox::setHalfAxis (const osgVector3& half_axis)
118
    {
119
1
        box_ptr_->setHalfLengths(half_axis);
120
1
        redrawShape ();
121
1
    }
122
123
3
    LeafNodeBox::~LeafNodeBox()
124
    {
125
        /* Proper deletion of all tree scene */
126
1
        geode_ptr_->removeDrawable(shape_drawable_ptr_);
127
1
        shape_drawable_ptr_ = NULL;
128
129
1
        this->asQueue()->removeChild(geode_ptr_);
130
1
        geode_ptr_ = NULL;
131
132
1
        weak_ptr_.reset();
133
2
    }
134
135
    /* End of declaration of public function members */
136
137
} /* namespace viewer */
138

3
} /* namespace gepetto */