common/animation/skeleton_utils.cc
// Implement joint hierarchy depth-first traversal.
// Uses a non-recursive implementation to control stack usage (ie: making
// algorithm behavior (stack consumption) independent off the data being
// processed).

Implement joint hierarchy depth-first traversal.
Uses a non-recursive implementation to control stack usage  independent off the data being
processed).
Implement joint hierarchy depth - first traversal . Uses a non - recursive implementation to control stack usage independent off the data being processed ) .
void IterateJointsDF(const Skeleton& _skeleton, int _from,
			JointsIterator* _iterator)
		{
			assert(_iterator);
			const int num_joints = _skeleton.num_joints();
			Range<const Skeleton::JointProperties> properties =
				_skeleton.joint_properties();
			_iterator->num_joints = 0;
			if (num_joints == 0)
			{
				return;
			}
			if ((_from < 0 || _from >= num_joints) && _from != Skeleton::kNoParentIndex)
			{
				return;
			}
			struct Context
			{
				uint16_t joint : 15;
				uint16_t has_brother : 1;
			};
			Context stack[Skeleton::kMaxJoints];
			int stack_size = 0;
			Context start;
			if (_from != Skeleton::kNoParentIndex)
			{
				start.joint = _from;
				start.has_brother = false;  
			}
			else
			{  
				start.joint = 0;
				start.has_brother = _HAS_SIBLING(0, num_joints, properties.begin);
			}
			stack[stack_size++] = start;
			for (; stack_size != 0;)
			{
				const Context& top = stack[stack_size - 1];
				_iterator->joints[_iterator->num_joints++] = top.joint;
				if (!properties.begin[top.joint].is_leaf)
				{  
					uint16_t next_joint = top.joint + 1;
					for (; next_joint < num_joints &&
						top.joint != properties.begin[next_joint].parent;
						++next_joint)
					{
					}
					if (next_joint < num_joints)
					{
						Context& next = stack[stack_size++];  
						next.joint = next_joint;
						next.has_brother =
							_HAS_SIBLING(next_joint, num_joints, properties.begin);
						continue;
					}
				}
				for (; stack_size != 0 && !stack[stack_size - 1].has_brother;
					--stack_size)
				{
				}
				if (stack_size != 0)
				{
					Context& next = stack[stack_size - 1];
					assert(next.has_brother && next.joint + 1 < num_joints);
					++next.joint;  
					next.has_brother = _HAS_SIBLING(next.joint, num_joints, properties.begin);
				}
			}
		}
void IterateJointsDF ( const Skeleton & _skeleton , int _from , JointsIterator * _iterator ) { assert ( _iterator ) ; const int num_joints = _skeleton . num_joints ( ) ; Range < const Skeleton :: JointProperties > properties = _skeleton . joint_properties ( ) ; _iterator -> num_joints = 0 ; if ( num_joints == 0 ) { return ; } if ( ( _from < 0 || _from >= num_joints ) && _from != Skeleton :: kNoParentIndex ) { return ; } struct Context { uint16_t joint : 15 ; uint16_t has_brother : 1 ; } ; Context stack [ Skeleton :: kMaxJoints ] ; int stack_size = 0 ; Context start ; if ( _from != Skeleton :: kNoParentIndex ) { start . joint = _from ; start . has_brother = false ; } else { start . joint = 0 ; start . has_brother = _HAS_SIBLING ( 0 , num_joints , properties . begin ) ; } stack [ stack_size ++ ] = start ; for ( ; stack_size != 0 ; ) { const Context & top = stack [ stack_size - 1 ] ; _iterator -> joints [ _iterator -> num_joints ++ ] = top . joint ; if ( ! properties . begin [ top . joint ] . is_leaf ) { uint16_t next_joint = top . joint + 1 ; for ( ; next_joint < num_joints && top . joint != properties . begin [ next_joint ] . parent ; ++ next_joint ) { } if ( next_joint < num_joints ) { Context & next = stack [ stack_size ++ ] ; next . joint = next_joint ; next . has_brother = _HAS_SIBLING ( next_joint , num_joints , properties . begin ) ; continue ; } } for ( ; stack_size != 0 && ! stack [ stack_size - 1 ] . has_brother ; -- stack_size ) { } if ( stack_size != 0 ) { Context & next = stack [ stack_size - 1 ] ; assert ( next . has_brother && next . joint + 1 < num_joints ) ; ++ next . joint ; next . has_brother = _HAS_SIBLING ( next . joint , num_joints , properties . begin ) ; } } }
Implement joint hierarchy depth-first traversal.
Implement joint hierarchy depth - first traversal .
// Initialize iterator.
 // Validates input range first.
 // Simulate a stack to unroll usual recursive implementation.
 // Initializes iteration start.
 // Disallow brother processing.
 // num_joints > 0, which was tested as pre-conditions.
 // Process next joint on the stack.
 // Push that joint to the list and then process its child.
 // Skip all the joints until the first child is found.
 // A leaf has no child anyway.
 // Push child and process it.
 // Rewind the stack while there's no brother to process.
 // Replace top joint by its brother.
 // The brother is the next joint in breadth-first order.
