Developer Documentation
JointT_impl.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44#define JOINTT_C
45
46#include "JointT.hh"
47#include <cassert>
48#include <algorithm>
49
50//-----------------------------------------------------------------------------------------------------
51
55template <class PointT>
56JointT<PointT>::JointT(Joint *_parent, std::string _name) :
57 id_(0),
58 selected_(false),
59 parent_(_parent),
60 name_(_name)
61{
62}
63
64//-----------------------------------------------------------------------------------------------------
65
72template<typename PointT>
74 id_(_other.id_),
75 selected_(_other.selected_),
76 parent_(0),
77 name_(_other.name_)
78{
79}
80
81//-----------------------------------------------------------------------------------------------------
82
83template <class PointT>
85{
86}
87
88//-----------------------------------------------------------------------------------------------------
89
96template <class PointT>
97inline size_t JointT<PointT>::id() const
98{
99 return id_;
100}
101
102//-----------------------------------------------------------------------------------------------------
103
104template <class PointT>
105inline void JointT<PointT>::setId(const size_t _id)
106{
107 id_ = _id;
108}
109
110//-----------------------------------------------------------------------------------------------------
111
121template <class PointT>
122inline void JointT<PointT>::setParent(Joint *_newParent, SkeletonT<PointT> &_skeleton)
123{
124 // Check for cycles and do not continue operation if cycles would be created! (if this joint is a parent of newParent this will be the case)
125 Joint *parent = _newParent;
126
127 while (parent != 0){
128 if (parent == this) {
129 std::cerr << "Illegal setParent operation (joint " << _newParent->id() << " cannot be parent of " << this->id() << " because this would lead to a cycle. Cancelling." << std::endl;
130 return;
131 }
132 parent = parent->parent();
133 }
134
135 if(parent_ != 0)
136 if(std::remove(parent_->children_.begin(), parent_->children_.end(), this) != parent_->children_.end()) // remove from the last parent
137 parent_->children_.resize(parent_->children_.size() - 1);
138
139 parent_ = _newParent;
140
141 if ( _newParent != 0)
142 _newParent->children_.push_back(this);
143
144 _skeleton.updateFromGlobal(id_);
145}
146
147//-----------------------------------------------------------------------------------------------------
148
155template <class PointT>
157{
158 return parent_;
159}
160
161//-----------------------------------------------------------------------------------------------------
162
163template <class PointT>
164inline bool JointT<PointT>::isRoot() const
165{
166 return (parent_ == NULL);
167}
168
169//-----------------------------------------------------------------------------------------------------
170
174template <class PointT>
175inline typename JointT<PointT>::ChildIter JointT<PointT>::begin()
176{
177 return children_.begin();
178}
179
180//-----------------------------------------------------------------------------------------------------
181
185template <class PointT>
186inline typename JointT<PointT>::ChildIter JointT<PointT>::end()
187{
188 return children_.end();
189}
190
191//-----------------------------------------------------------------------------------------------------
192
196template<typename PointT>
197inline size_t JointT<PointT>::size() const
198{
199 return children_.size();
200}
201
202//-----------------------------------------------------------------------------------------------------
203
210template<typename PointT>
212{
213 assert( _index < children_.size() );
214
215 if(_index >= children_.size())
216 return 0;
217 return children_[_index];
218}
219
220//-----------------------------------------------------------------------------------------------------
221
226template <class PointT>
227inline bool JointT<PointT>::selected() const
228{
229 return selected_;
230}
231
232//-----------------------------------------------------------------------------------------------------
233
238template <class PointT>
239inline void JointT<PointT>::setSelected(bool _selected)
240{
241 selected_ = _selected;
242}
243
244//-----------------------------------------------------------------------------------------------------
245
246template<typename PointT>
247inline std::string JointT<PointT>::name() const {
248 return name_;
249}
250
251//-----------------------------------------------------------------------------------------------------
252
253template<typename PointT>
254inline void JointT<PointT>::setName(const std::string& _name) {
255 name_ = _name;
256}
257
258//-----------------------------------------------------------------------------------------------------
259
Represents a single joint in the skeleton.
Definition: JointT.hh:61
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
Definition: JointT_impl.hh:122
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT_impl.hh:186
size_t size() const
Returns the number of children.
Definition: JointT_impl.hh:197
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97
Joint * child(size_t _index)
Returns the child joint with the given index.
Definition: JointT_impl.hh:211
void setId(const size_t _id)
An unique identifier, guaranteed to be part of a continuous sequence starting from 0.
Definition: JointT_impl.hh:105
JointT(const Joint &_other)
Constructor.
Definition: JointT_impl.hh:73
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT_impl.hh:175
void setName(const std::string &_name)
An unique identifier, guaranteed to be part of a continuous sequence starting from 0.
Definition: JointT_impl.hh:254
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Definition: JointT.hh:123
bool selected() const
Returns the joint's selection state.
Definition: JointT_impl.hh:227
std::string name() const
Access the name of the joint.
Definition: JointT_impl.hh:247
~JointT()
Destructor.
Definition: JointT_impl.hh:84
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
void setSelected(bool _selected)
Set the joint's selction state.
Definition: JointT_impl.hh:239
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint