| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// leaf-node-sphere.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-sphere.h> |
| 10 |
|
|
|
| 11 |
|
|
namespace gepetto { |
| 12 |
|
|
namespace viewer { |
| 13 |
|
|
|
| 14 |
|
|
/* Declaration of private function members */ |
| 15 |
|
|
|
| 16 |
|
✗ |
void LeafNodeSphere::init() { |
| 17 |
|
|
/* Create sphere object */ |
| 18 |
|
✗ |
sphere_ptr_ = new ::osg::Sphere(); |
| 19 |
|
|
|
| 20 |
|
|
/* Set ShapeDrawable */ |
| 21 |
|
✗ |
shape_drawable_ptr_ = new ::osg::ShapeDrawable(sphere_ptr_); |
| 22 |
|
|
|
| 23 |
|
|
/* Create Geode for adding ShapeDrawable */ |
| 24 |
|
✗ |
geode_ptr_ = new osg::Geode(); |
| 25 |
|
✗ |
geode_ptr_->addDrawable(shape_drawable_ptr_); |
| 26 |
|
|
|
| 27 |
|
|
/* Create PositionAttitudeTransform */ |
| 28 |
|
✗ |
this->asQueue()->addChild(geode_ptr_); |
| 29 |
|
|
|
| 30 |
|
|
/* Allow transparency */ |
| 31 |
|
✗ |
geode_ptr_->getOrCreateStateSet()->setMode(GL_BLEND, |
| 32 |
|
|
::osg::StateAttribute::ON); |
| 33 |
|
|
|
| 34 |
|
|
RangedFloatProperty::Ptr_t radiusProp = RangedFloatProperty::create( |
| 35 |
|
✗ |
"Radius", this, &LeafNodeSphere::getRadius, &LeafNodeSphere::setRadius); |
| 36 |
|
✗ |
radiusProp->min = 0.f; |
| 37 |
|
✗ |
radiusProp->step = 0.1f; |
| 38 |
|
✗ |
radiusProp->adaptiveDecimal = true; |
| 39 |
|
✗ |
addProperty(radiusProp); |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
✗ |
LeafNodeSphere::LeafNodeSphere(const std::string& name, const float& radius) |
| 43 |
|
✗ |
: NodeDrawable(name) { |
| 44 |
|
✗ |
init(); |
| 45 |
|
✗ |
setRadius(radius); |
| 46 |
|
✗ |
setColor(osgVector4(1., 1., 1., 1.)); |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
✗ |
LeafNodeSphere::LeafNodeSphere(const std::string& name, const float& radius, |
| 50 |
|
✗ |
const osgVector4& color) |
| 51 |
|
✗ |
: NodeDrawable(name) { |
| 52 |
|
✗ |
init(); |
| 53 |
|
✗ |
setRadius(radius); |
| 54 |
|
✗ |
setColor(color); |
| 55 |
|
|
} |
| 56 |
|
|
|
| 57 |
|
✗ |
LeafNodeSphere::LeafNodeSphere(const std::string& name, |
| 58 |
|
✗ |
const LeafNodeSphere& other) |
| 59 |
|
✗ |
: NodeDrawable(other) { |
| 60 |
|
✗ |
setID(name); |
| 61 |
|
✗ |
init(); |
| 62 |
|
✗ |
setRadius(other.getRadius()); |
| 63 |
|
✗ |
setColor(other.getColor()); |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
✗ |
void LeafNodeSphere::initWeakPtr(LeafNodeSphereWeakPtr other_weak_ptr) { |
| 67 |
|
✗ |
weak_ptr_ = other_weak_ptr; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
/* End of declaration of private function members */ |
| 71 |
|
|
|
| 72 |
|
|
/* Declaration of protected function members */ |
| 73 |
|
|
|
| 74 |
|
✗ |
LeafNodeSpherePtr_t LeafNodeSphere::create(const std::string& name, |
| 75 |
|
|
const float& radius) { |
| 76 |
|
✗ |
LeafNodeSpherePtr_t shared_ptr(new LeafNodeSphere(name, radius)); |
| 77 |
|
|
|
| 78 |
|
|
// Add reference to itself |
| 79 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 80 |
|
|
|
| 81 |
|
✗ |
return shared_ptr; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
✗ |
LeafNodeSpherePtr_t LeafNodeSphere::create(const std::string& name, |
| 85 |
|
|
const float& radius, |
| 86 |
|
|
const osgVector4& color) { |
| 87 |
|
✗ |
LeafNodeSpherePtr_t shared_ptr(new LeafNodeSphere(name, radius, color)); |
| 88 |
|
|
|
| 89 |
|
|
// Add reference to itself |
| 90 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 91 |
|
|
|
| 92 |
|
✗ |
return shared_ptr; |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
✗ |
LeafNodeSpherePtr_t LeafNodeSphere::createCopy(LeafNodeSpherePtr_t other) { |
| 96 |
|
✗ |
LeafNodeSpherePtr_t shared_ptr(new LeafNodeSphere(*other)); |
| 97 |
|
|
|
| 98 |
|
|
// Add reference to itself |
| 99 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 100 |
|
|
|
| 101 |
|
✗ |
return shared_ptr; |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
/* End of declaration of protected function members */ |
| 105 |
|
|
|
| 106 |
|
|
/* Declaration of public function members */ |
| 107 |
|
|
|
| 108 |
|
✗ |
LeafNodeSpherePtr_t LeafNodeSphere::clone(void) const { |
| 109 |
|
✗ |
return LeafNodeSphere::createCopy(weak_ptr_.lock()); |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
✗ |
LeafNodeSpherePtr_t LeafNodeSphere::self(void) const { |
| 113 |
|
✗ |
return weak_ptr_.lock(); |
| 114 |
|
|
} |
| 115 |
|
|
|
| 116 |
|
✗ |
void LeafNodeSphere::setRadius(const float& radius) { |
| 117 |
|
✗ |
sphere_ptr_->setRadius(radius); |
| 118 |
|
✗ |
redrawShape(); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
✗ |
LeafNodeSphere::~LeafNodeSphere() { |
| 122 |
|
|
/* Proper deletion of all tree scene */ |
| 123 |
|
✗ |
geode_ptr_->removeDrawable(shape_drawable_ptr_); |
| 124 |
|
✗ |
shape_drawable_ptr_ = NULL; |
| 125 |
|
|
|
| 126 |
|
✗ |
this->asQueue()->removeChild(geode_ptr_); |
| 127 |
|
✗ |
geode_ptr_ = NULL; |
| 128 |
|
|
|
| 129 |
|
✗ |
weak_ptr_.reset(); |
| 130 |
|
|
} |
| 131 |
|
|
|
| 132 |
|
|
/* End of declaration of public function members */ |
| 133 |
|
|
|
| 134 |
|
|
} /* namespace viewer */ |
| 135 |
|
|
|
| 136 |
|
|
} /* namespace gepetto */ |
| 137 |
|
|
|