GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/leaf-node-light.cpp Lines: 1 63 1.6 %
Date: 2020-05-14 11:23:33 Branches: 2 92 2.2 %

Line Branch Exec Source
1
//
2
//  leaf-node-light.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-light.h>
10
11
#include <osgDB/ReadFile>
12
13
namespace gepetto {
14
namespace viewer {
15
16
    /* Declaration of private function members */
17
18
    int LeafNodeLight::uniqueLightNumber = 1;
19
20
    void LeafNodeLight::init()
21
    {
22
        /* Create light object */
23
        ::osg::LightRefPtr light = new ::osg::Light();
24
        light->setLightNum (uniqueLightNumber++);
25
        light->setPosition(osgVector4(0.0, 0.0, 0.0, 1.0));
26
        light->setDiffuse(osgVector4(0,0,0,1));
27
        light->setSpecular(osgVector4(1.0, 1.0, 1.0, 1.0));
28
        light->setAmbient( osgVector4(0.0, 0.0, 0.0, 1.0));
29
        light_ptr_ = new ::osg::LightSource();
30
        light_ptr_->setLight (light);
31
32
        addProperty(Vector4Property::create("ColorSpecular",
33
              Vector4Property::getterFromMemberFunction(light.get(), &osg::Light::getSpecular),
34
              Vector4Property::setterFromMemberFunction(light.get(), &osg::Light::setSpecular)));
35
        addProperty(Vector4Property::create("ColorAmbient",
36
              Vector4Property::getterFromMemberFunction(light.get(), &osg::Light::getAmbient),
37
              Vector4Property::setterFromMemberFunction(light.get(), &osg::Light::setAmbient)));
38
        addProperty(Vector4Property::create("ColorDiffuse",
39
              Vector4Property::getterFromMemberFunction(light.get(), &osg::Light::getDiffuse),
40
              Vector4Property::setterFromMemberFunction(light.get(), &osg::Light::setDiffuse)));
41
42
        /* Create PositionAttitudeTransform */
43
        this->asQueue()->addChild(light_ptr_);
44
    }
45
46
    LeafNodeLight::LeafNodeLight(const std::string& name, const float& radius) :
47
        LeafNodeSphere(name, radius)
48
    {
49
        init();
50
        setColor(osgVector4(1.,1.,1.,1.));
51
    }
52
53
    LeafNodeLight::LeafNodeLight(const std::string& name, const float& radius, const osgVector4& color) :
54
        LeafNodeSphere(name, radius, color)
55
    {
56
        init();
57
        setColor(color);
58
    }
59
60
    LeafNodeLight::LeafNodeLight(const std::string& name, const LeafNodeLight& other) :
61
        LeafNodeSphere(name, other)
62
    {
63
        init();
64
        setColor(other.getColor());
65
    }
66
67
    void LeafNodeLight::initWeakPtr(LeafNodeLightWeakPtr other_weak_ptr)
68
    {
69
        LeafNodeSphere::initWeakPtr(other_weak_ptr);
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
    LeafNodeLightPtr_t LeafNodeLight::create(const std::string& name, const float &radius)
78
    {
79
        LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(name, radius));
80
81
        // Add reference to itself
82
        shared_ptr->initWeakPtr(shared_ptr);
83
84
        return shared_ptr;
85
    }
86
87
    LeafNodeLightPtr_t LeafNodeLight::create(const std::string& name, const float &radius, const osgVector4& color)
88
    {
89
        LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(name, radius, color));
90
91
        // Add reference to itself
92
        shared_ptr->initWeakPtr(shared_ptr);
93
94
        return shared_ptr;
95
    }
96
97
    LeafNodeLightPtr_t LeafNodeLight::createCopy(LeafNodeLightPtr_t other)
98
    {
99
        LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(*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
    LeafNodeLightPtr_t LeafNodeLight::clone(void) const
112
    {
113
        return LeafNodeLight::createCopy(weak_ptr_.lock());
114
    }
115
116
    LeafNodeLightPtr_t LeafNodeLight::self(void) const
117
    {
118
        return weak_ptr_.lock();
119
    }
120
121
    void LeafNodeLight::setColor (const osgVector4& color)
122
    {
123
        light_ptr_->getLight ()->setDiffuse (color);
124
        LeafNodeSphere::setColor (color);
125
        setDirty();
126
    }
127
128
    void LeafNodeLight::setRoot (GroupNodePtr_t root)
129
    {
130
      light_ptr_->setLocalStateSetModes (::osg::StateAttribute::ON);
131
      light_ptr_->setStateSetModes (*root->getOrCreateRootStateSet (), ::osg::StateAttribute::ON);
132
      setDirty();
133
    }
134
135
    LeafNodeLight::~LeafNodeLight()
136
    {
137
        this->asQueue()->removeChild(geode_ptr_);
138
        geode_ptr_ = NULL;
139
140
        weak_ptr_.reset();
141
    }
142
143
    /* End of declaration of public function members */
144
145
} /* namespace viewer */
146
147

3
} /* namespace gepetto */