GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/node-drawable.cpp Lines: 16 28 57.1 %
Date: 2020-05-14 11:23:33 Branches: 6 40 15.0 %

Line Branch Exec Source
1
// Copyright (c) 2018, Joseph Mirabel
2
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3
4
#include <gepetto/viewer/node-drawable.h>
5
6
#include <osg/Version>
7
#include <osg/Texture2D>
8
#include <osgDB/ReadFile>
9
10
namespace gepetto {
11
namespace viewer {
12
1
  void NodeDrawable::init ()
13
  {
14

2
    addProperty(Vector4Property::create("Color",
15
2
          Vector4Property::getterFromMemberFunction(this, &NodeDrawable::getColor),
16
2
          Vector4Property::setterFromMemberFunction(this, &NodeDrawable::setColor)));
17
1
  }
18
19
1
  void NodeDrawable::setColor(const osgVector4 &color)
20
  {
21
1
    shape_drawable_ptr_->setColor(color);
22
1
    redrawShape ();
23
1
    setTransparentRenderingBin (color[3] < Node::TransparencyRenderingBinThreshold);
24
1
  }
25
26
2
  void NodeDrawable::redrawShape ()
27
  {
28
#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 6)
29
    shape_drawable_ptr_->build();
30
#else
31
2
    shape_drawable_ptr_->dirtyDisplayList();
32
2
    shape_drawable_ptr_->dirtyBound();
33
#endif
34
2
    setDirty();
35
2
  }
36
37
  osgVector4 NodeDrawable::getColor() const
38
  {
39
    return shape_drawable_ptr_->getColor();
40
  }
41
42
  void NodeDrawable::setTexture(const std::string& image_path)
43
  {
44
    osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
45
    texture->setDataVariance(osg::Object::DYNAMIC);
46
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(image_path);
47
    if (!image)
48
    {
49
      std::cerr << " couldn't find texture " << image_path << ", quiting." << std::endl;
50
      return;
51
    }
52
    texture->setImage(image);
53
    geode_ptr_->getStateSet()->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
54
    setDirty();
55
  }
56
} /* namespace viewer */
57

3
}