Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JointT.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 14957 $ *
38 * $LastChangedBy: moeller $ *
39 * $Date: 2012-07-11 16:13:57 +0200 (Mi, 11 Jul 2012) $ *
40 * *
41 \*===========================================================================*/
42 
43 #define JOINTT_C
44 
45 #include "JointT.hh"
46 #include <cassert>
47 #include <algorithm>
48 
49 //-----------------------------------------------------------------------------------------------------
50 
54 template <class PointT>
55 JointT<PointT>::JointT(Joint *_parent, std::string _name) :
56  id_(0),
57  selected_(false),
58  parent_(_parent),
59  name_(_name)
60 {
61 }
62 
63 //-----------------------------------------------------------------------------------------------------
64 
71 template<typename PointT>
72 JointT<PointT>::JointT(const Joint &_other) :
73  id_(_other.id_),
74  selected_(_other.selected_),
75  parent_(0),
76  name_(_other.name_)
77 {
78 }
79 
80 //-----------------------------------------------------------------------------------------------------
81 
82 template <class PointT>
84 {
85 }
86 
87 //-----------------------------------------------------------------------------------------------------
88 
95 template <class PointT>
96 inline unsigned int JointT<PointT>::id()
97 {
98  return id_;
99 }
100 
101 //-----------------------------------------------------------------------------------------------------
102 
103 template <class PointT>
104 inline void JointT<PointT>::setId(unsigned int _id)
105 {
106  id_ = _id;
107 }
108 
109 //-----------------------------------------------------------------------------------------------------
110 
120 template <class PointT>
121 inline void JointT<PointT>::setParent(Joint *_newParent, SkeletonT<PointT> &_skeleton)
122 {
123  // 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)
124  Joint *parent = _newParent;
125 
126  while (parent != 0){
127  if (parent == this) {
128  std::cerr << "Illegal setParent operation (joint " << _newParent->id() << " cannot be parent of " << this->id() << " because this would lead to a cycle. Cancelling." << std::endl;
129  return;
130  }
131  parent = parent->parent();
132  }
133 
134  if(parent_ != 0)
135  if(std::remove(parent_->children_.begin(), parent_->children_.end(), this) != parent_->children_.end()) // remove from the last parent
136  parent_->children_.resize(parent_->children_.size() - 1);
137 
138  parent_ = _newParent;
139 
140  if ( _newParent != 0)
141  _newParent->children_.push_back(this);
142 
143  _skeleton.updateFromGlobal(id_);
144 }
145 
146 //-----------------------------------------------------------------------------------------------------
147 
154 template <class PointT>
156 {
157  return parent_;
158 }
159 
160 //-----------------------------------------------------------------------------------------------------
161 
162 template <class PointT>
163 inline bool JointT<PointT>::isRoot()
164 {
165  return parent_ == NULL;
166 }
167 
168 //-----------------------------------------------------------------------------------------------------
169 
173 template <class PointT>
174 inline typename JointT<PointT>::ChildIter JointT<PointT>::begin()
175 {
176  return children_.begin();
177 }
178 
179 //-----------------------------------------------------------------------------------------------------
180 
184 template <class PointT>
185 inline typename JointT<PointT>::ChildIter JointT<PointT>::end()
186 {
187  return children_.end();
188 }
189 
190 //-----------------------------------------------------------------------------------------------------
191 
195 template<typename PointT>
196 inline size_t JointT<PointT>::size()
197 {
198  return children_.size();
199 }
200 
201 //-----------------------------------------------------------------------------------------------------
202 
209 template<typename PointT>
210 inline JointT<PointT> *JointT<PointT>::child(size_t _index)
211 {
212  assert( _index < children_.size() );
213 
214  if(_index >= children_.size())
215  return 0;
216  return children_[_index];
217 }
218 
219 //-----------------------------------------------------------------------------------------------------
220 
225 template <class PointT>
227 {
228  return selected_;
229 }
230 
231 //-----------------------------------------------------------------------------------------------------
232 
237 template <class PointT>
238 inline void JointT<PointT>::setSelected(bool _selected)
239 {
240  selected_ = _selected;
241 }
242 
243 //-----------------------------------------------------------------------------------------------------
244 
245 template<typename PointT>
246 inline std::string JointT<PointT>::name() {
247  return name_;
248 }
249 
250 //-----------------------------------------------------------------------------------------------------
251 
252 template<typename PointT>
253 inline void JointT<PointT>::setName(std::string _name) {
254  name_ = _name;
255 }
256 
257 //-----------------------------------------------------------------------------------------------------
258