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 
55 template <class PointT>
56 JointT<PointT>::JointT(Joint *_parent, std::string _name) :
57  id_(0),
58  selected_(false),
59  parent_(_parent),
60  name_(_name)
61 {
62 }
63 
64 //-----------------------------------------------------------------------------------------------------
65 
72 template<typename PointT>
73 JointT<PointT>::JointT(const Joint &_other) :
74  id_(_other.id_),
75  selected_(_other.selected_),
76  parent_(0),
77  name_(_other.name_)
78 {
79 }
80 
81 //-----------------------------------------------------------------------------------------------------
82 
83 template <class PointT>
85 {
86 }
87 
88 //-----------------------------------------------------------------------------------------------------
89 
96 template <class PointT>
97 inline size_t JointT<PointT>::id() const
98 {
99  return id_;
100 }
101 
102 //-----------------------------------------------------------------------------------------------------
103 
104 template <class PointT>
105 inline void JointT<PointT>::setId(const size_t _id)
106 {
107  id_ = _id;
108 }
109 
110 //-----------------------------------------------------------------------------------------------------
111 
121 template <class PointT>
122 inline 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 
155 template <class PointT>
157 {
158  return parent_;
159 }
160 
161 //-----------------------------------------------------------------------------------------------------
162 
163 template <class PointT>
164 inline bool JointT<PointT>::isRoot() const
165 {
166  return (parent_ == NULL);
167 }
168 
169 //-----------------------------------------------------------------------------------------------------
170 
174 template <class PointT>
175 inline typename JointT<PointT>::ChildIter JointT<PointT>::begin()
176 {
177  return children_.begin();
178 }
179 
180 //-----------------------------------------------------------------------------------------------------
181 
185 template <class PointT>
186 inline typename JointT<PointT>::ChildIter JointT<PointT>::end()
187 {
188  return children_.end();
189 }
190 
191 //-----------------------------------------------------------------------------------------------------
192 
196 template<typename PointT>
197 inline size_t JointT<PointT>::size() const
198 {
199  return children_.size();
200 }
201 
202 //-----------------------------------------------------------------------------------------------------
203 
210 template<typename PointT>
211 inline JointT<PointT> *JointT<PointT>::child(size_t _index)
212 {
213  assert( _index < children_.size() );
214 
215  if(_index >= children_.size())
216  return 0;
217  return children_[_index];
218 }
219 
220 //-----------------------------------------------------------------------------------------------------
221 
226 template <class PointT>
227 inline bool JointT<PointT>::selected() const
228 {
229  return selected_;
230 }
231 
232 //-----------------------------------------------------------------------------------------------------
233 
238 template <class PointT>
239 inline void JointT<PointT>::setSelected(bool _selected)
240 {
241  selected_ = _selected;
242 }
243 
244 //-----------------------------------------------------------------------------------------------------
245 
246 template<typename PointT>
247 inline std::string JointT<PointT>::name() const {
248  return name_;
249 }
250 
251 //-----------------------------------------------------------------------------------------------------
252 
253 template<typename PointT>
254 inline void JointT<PointT>::setName(const std::string& _name) {
255  name_ = _name;
256 }
257 
258 //-----------------------------------------------------------------------------------------------------
259 
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97
size_t size() const
Returns the number of children.
Definition: JointT_impl.hh:197
void setSelected(bool _selected)
Set the joint&#39;s selction state.
Definition: JointT_impl.hh:239
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
Definition: JointT_impl.hh:122
std::string name() const
Access the name of the joint.
Definition: JointT_impl.hh:247
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT_impl.hh:186
JointT(const Joint &_other)
Constructor.
Definition: JointT_impl.hh:73
Represents a single joint in the skeleton.
Definition: JointT.hh:60
bool selected() const
Returns the joint&#39;s selection state.
Definition: JointT_impl.hh:227
Joint * child(size_t _index)
Returns the child joint with the given index.
Definition: JointT_impl.hh:211
std::string name_
the name of the joint
Definition: JointT.hh:125
size_t id_
An unique identifier, guaranteed to be part of a continuous sequence starting from 0...
Definition: JointT.hh:114
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It&#39;s 0 for the root node...
Definition: JointT.hh:121
~JointT()
Destructor.
Definition: JointT_impl.hh:84
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Definition: JointT.hh:123
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT_impl.hh:175