Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
JointT.cc
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #define JOINTT_C
51
52 #include "JointT.hh"
53 #include <cassert>
54 #include <algorithm>
55
56 //-----------------------------------------------------------------------------------------------------
57
61 template <class PointT>
62 JointT<PointT>::JointT(Joint *_parent, std::string _name) :
63 id_(0),
64 selected_(false),
65 parent_(_parent),
66 name_(_name)
67 {
68 }
69
70 //-----------------------------------------------------------------------------------------------------
71
78 template<typename PointT>
79 JointT<PointT>::JointT(const Joint &_other) :
80 id_(_other.id_),
81 selected_(_other.selected_),
82 parent_(0),
83 name_(_other.name_)
84 {
85 }
86
87 //-----------------------------------------------------------------------------------------------------
88
89 template <class PointT>
90 JointT<PointT>::~JointT()
91 {
92 }
93
94 //-----------------------------------------------------------------------------------------------------
95
102 template <class PointT>
103 inline unsigned int JointT<PointT>::id()
104 {
105 return id_;
106 }
107
108 //-----------------------------------------------------------------------------------------------------
109
110 template <class PointT>
111 inline void JointT<PointT>::setId(unsigned int _id)
112 {
113 id_ = _id;
114 }
115
116 //-----------------------------------------------------------------------------------------------------
117
127 template <class PointT>
128 inline void JointT<PointT>::setParent(Joint *_newParent, SkeletonT<PointT> &_skeleton)
129 {
130 // 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)
131 Joint *parent = _newParent;
132
133 while (parent != 0){
134 if (parent == this) {
135 std::cerr << "Illegal setParent operation (joint " << _newParent->id() << " cannot be parent of " << this->id() << " because this would lead to a cycle. Cancelling." << std::endl;
136 return;
137 }
138 parent = parent->parent();
139 }
140
141 if(parent_ != 0)
142 if(std::remove(parent_->children_.begin(), parent_->children_.end(), this) != parent_->children_.end()) // remove from the last parent
143 parent_->children_.resize(parent_->children_.size() - 1);
144
145 parent_ = _newParent;
146
147 if ( _newParent != 0)
148 _newParent->children_.push_back(this);
149
150 _skeleton.updateFromGlobal(id_);
151 }
152
153 //-----------------------------------------------------------------------------------------------------
154
161 template <class PointT>
162 inline JointT<PointT> *JointT<PointT>::parent()
163 {
164 return parent_;
165 }
166
167 //-----------------------------------------------------------------------------------------------------
168
169 template <class PointT>
170 inline bool JointT<PointT>::isRoot()
171 {
172 return parent_ == NULL;
173 }
174
175 //-----------------------------------------------------------------------------------------------------
176
180 template <class PointT>
181 inline typename JointT<PointT>::ChildIter JointT<PointT>::begin()
182 {
183 return children_.begin();
184 }
185
186 //-----------------------------------------------------------------------------------------------------
187
191 template <class PointT>
192 inline typename JointT<PointT>::ChildIter JointT<PointT>::end()
193 {
194 return children_.end();
195 }
196
197 //-----------------------------------------------------------------------------------------------------
198
202 template<typename PointT>
203 inline size_t JointT<PointT>::size()
204 {
205 return children_.size();
206 }
207
208 //-----------------------------------------------------------------------------------------------------
209
216 template<typename PointT>
217 inline JointT<PointT> *JointT<PointT>::child(size_t _index)
218 {
219 assert( _index < children_.size() );
220
221 if(_index >= children_.size())
222 return 0;
223 return children_[_index];
224 }
225
226 //-----------------------------------------------------------------------------------------------------
227
232 template <class PointT>
233 inline bool JointT<PointT>::selected()
234 {
235 return selected_;
236 }
237
238 //-----------------------------------------------------------------------------------------------------
239
244 template <class PointT>
245 inline void JointT<PointT>::setSelected(bool _selected)
246 {
247 selected_ = _selected;
248 }
249
250 //-----------------------------------------------------------------------------------------------------
251
252 template<typename PointT>
253 inline std::string JointT<PointT>::name() {
254 return name_;
255 }
256
257 //-----------------------------------------------------------------------------------------------------
258
259 template<typename PointT>
260 inline void JointT<PointT>::setName(std::string _name) {
261 name_ = _name;
262 }
263
264 //-----------------------------------------------------------------------------------------------------
265
JointT::JointT
JointT(const Joint &_other)
Constructor.
Definition: JointT.cc:79
JointT::begin
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT.cc:181
JointT::name
std::string name()
Access the name of the joint.
Definition: JointT.cc:253
JointT::child
Joint * child(size_t _index)
Returns the child joint with the given index.
Definition: JointT.cc:217
JointT::children_
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Definition: JointT.hh:129
JointT::~JointT
~JointT()
Destructor.
Definition: JointT.cc:90
JointT::end
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT.cc:192
JointT::selected
bool selected()
Returns the joint's selection state.
Definition: JointT.cc:233
JointT::parent
Joint * parent()
Returns the parent joint.
Definition: JointT.cc:162
SkeletonT
Definition: JointT.hh:56
SkeletonT::updateFromGlobal
void updateFromGlobal(unsigned int _idJoint)
update the structure when parent changes for a joint
Definition: SkeletonT.cc:1006
JointT::id
unsigned int id()
returns the joint id
Definition: JointT.cc:103
JointT::setSelected
void setSelected(bool _selected)
Set the joint's selction state.
Definition: JointT.cc:245
JointT::size
size_t size()
Returns the number of children.
Definition: JointT.cc:203
JointT
Represents a single joint in the skeleton.
Definition: JointT.hh:66
JointT::setParent
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
Definition: JointT.cc:128