GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/node-drawable.cpp Lines: 15 28 53.6 %
Date: 2024-04-14 11:13:22 Branches: 4 32 12.5 %

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/Texture2D>
7
#include <osg/Version>
8
#include <osgDB/ReadFile>
9
10
namespace gepetto {
11
namespace viewer {
12
1
void NodeDrawable::init() {
13

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