| Directory: | ./ |
|---|---|
| File: | src/leaf-node-box.cpp |
| Date: | 2025-04-14 11:18:00 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 36 | 57 | 63.2% |
| Branches: | 14 | 60 | 23.3% |
| 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 | /* Create sphere object */ | ||
| 18 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | box_ptr_ = new ::osg::Box(); |
| 19 | |||
| 20 | /* Set ShapeDrawable */ | ||
| 21 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | shape_drawable_ptr_ = new ::osg::ShapeDrawable(box_ptr_); |
| 22 | |||
| 23 | /* Create Geode for adding ShapeDrawable */ | ||
| 24 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | geode_ptr_ = new ::osg::Geode(); |
| 25 | 1 | geode_ptr_->addDrawable(shape_drawable_ptr_); | |
| 26 | |||
| 27 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | addProperty( |
| 28 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | Vector3Property::create("HalfLength", |
| 29 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | Vector3Property::getterFromMemberFunction( |
| 30 | box_ptr_.get(), &osg::Box::getHalfLengths), | ||
| 31 | 2 | Vector3Property::setterFromMemberFunction( | |
| 32 | this, &LeafNodeBox::setHalfAxis))); | ||
| 33 | |||
| 34 | /* Create PositionAttitudeTransform */ | ||
| 35 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | this->asQueue()->addChild(geode_ptr_); |
| 36 | |||
| 37 | /* Allow transparency */ | ||
| 38 | 1 | geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, | |
| 39 | ::osg::StateAttribute::ON); | ||
| 40 | 1 | } | |
| 41 | |||
| 42 | 1 | LeafNodeBox::LeafNodeBox(const std::string &name, const osgVector3 &half_axis) | |
| 43 | 1 | : NodeDrawable(name) { | |
| 44 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | init(); |
| 45 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | setHalfAxis(half_axis); |
| 46 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | setColor(osgVector4(1., 1., 1., 1.)); |
| 47 | 1 | } | |
| 48 | |||
| 49 | ✗ | LeafNodeBox::LeafNodeBox(const std::string &name, const osgVector3 &half_axis, | |
| 50 | ✗ | const osgVector4 &color) | |
| 51 | ✗ | : NodeDrawable(name) { | |
| 52 | ✗ | init(); | |
| 53 | ✗ | setHalfAxis(half_axis); | |
| 54 | ✗ | setColor(color); | |
| 55 | } | ||
| 56 | |||
| 57 | ✗ | LeafNodeBox::LeafNodeBox(const LeafNodeBox &other) : NodeDrawable(other) { | |
| 58 | ✗ | init(); | |
| 59 | ✗ | setHalfAxis(other.getHalfAxis()); | |
| 60 | ✗ | setColor(other.getColor()); | |
| 61 | } | ||
| 62 | |||
| 63 | 1 | void LeafNodeBox::initWeakPtr(LeafNodeBoxWeakPtr other_weak_ptr) { | |
| 64 | 1 | weak_ptr_ = other_weak_ptr; | |
| 65 | 1 | } | |
| 66 | |||
| 67 | /* End of declaration of private function members */ | ||
| 68 | |||
| 69 | /* Declaration of protected function members */ | ||
| 70 | |||
| 71 | 1 | LeafNodeBoxPtr_t LeafNodeBox::create(const std::string &name, | |
| 72 | const osgVector3 &half_axis) { | ||
| 73 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(name, half_axis)); |
| 74 | |||
| 75 | // Add reference to itself | ||
| 76 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | shared_ptr->initWeakPtr(shared_ptr); |
| 77 | |||
| 78 | 1 | return shared_ptr; | |
| 79 | } | ||
| 80 | |||
| 81 | ✗ | LeafNodeBoxPtr_t LeafNodeBox::create(const std::string &name, | |
| 82 | const osgVector3 &half_axis, | ||
| 83 | const osgVector4 &color) { | ||
| 84 | ✗ | LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(name, half_axis, color)); | |
| 85 | |||
| 86 | // Add reference to itself | ||
| 87 | ✗ | shared_ptr->initWeakPtr(shared_ptr); | |
| 88 | |||
| 89 | ✗ | return shared_ptr; | |
| 90 | } | ||
| 91 | |||
| 92 | ✗ | LeafNodeBoxPtr_t LeafNodeBox::createCopy(LeafNodeBoxPtr_t other) { | |
| 93 | ✗ | LeafNodeBoxPtr_t shared_ptr(new LeafNodeBox(*other)); | |
| 94 | |||
| 95 | // Add reference to itself | ||
| 96 | ✗ | shared_ptr->initWeakPtr(shared_ptr); | |
| 97 | |||
| 98 | ✗ | return shared_ptr; | |
| 99 | } | ||
| 100 | |||
| 101 | /* End of declaration of protected function members */ | ||
| 102 | |||
| 103 | /* Declaration of public function members */ | ||
| 104 | |||
| 105 | ✗ | LeafNodeBoxPtr_t LeafNodeBox::clone(void) const { | |
| 106 | ✗ | return LeafNodeBox::createCopy(weak_ptr_.lock()); | |
| 107 | } | ||
| 108 | |||
| 109 | ✗ | LeafNodeBoxPtr_t LeafNodeBox::self(void) const { return weak_ptr_.lock(); } | |
| 110 | |||
| 111 | 1 | void LeafNodeBox::setHalfAxis(const osgVector3 &half_axis) { | |
| 112 | 1 | box_ptr_->setHalfLengths(half_axis); | |
| 113 | 1 | redrawShape(); | |
| 114 | 1 | } | |
| 115 | |||
| 116 | 4 | LeafNodeBox::~LeafNodeBox() { | |
| 117 | /* Proper deletion of all tree scene */ | ||
| 118 | 2 | geode_ptr_->removeDrawable(shape_drawable_ptr_); | |
| 119 | 2 | shape_drawable_ptr_ = NULL; | |
| 120 | |||
| 121 | 2 | this->asQueue()->removeChild(geode_ptr_); | |
| 122 | 2 | geode_ptr_ = NULL; | |
| 123 | |||
| 124 | 2 | weak_ptr_.reset(); | |
| 125 | 4 | } | |
| 126 | |||
| 127 | /* End of declaration of public function members */ | ||
| 128 | |||
| 129 | } /* namespace viewer */ | ||
| 130 | } /* namespace gepetto */ | ||
| 131 |