Beispiel #1
0
void AnimSkeleton::dump() const {
    qCDebug(animation) << "[";
    for (int i = 0; i < getNumJoints(); i++) {
        qCDebug(animation) << "    {";
        qCDebug(animation) << "        index =" << i;
        qCDebug(animation) << "        name =" << getJointName(i);
        qCDebug(animation) << "        absBindPose =" << getAbsoluteBindPose(i);
        qCDebug(animation) << "        relBindPose =" << getRelativeBindPose(i);
        qCDebug(animation) << "        absDefaultPose =" << getAbsoluteDefaultPose(i);
        qCDebug(animation) << "        relDefaultPose =" << getRelativeDefaultPose(i);
#ifdef DUMP_FBX_JOINTS
        qCDebug(animation) << "        fbxJoint =";
        qCDebug(animation) << "            isFree =" << _joints[i].isFree;
        qCDebug(animation) << "            freeLineage =" << _joints[i].freeLineage;
        qCDebug(animation) << "            parentIndex =" << _joints[i].parentIndex;
        qCDebug(animation) << "            translation =" << _joints[i].translation;
        qCDebug(animation) << "            preTransform =" << _joints[i].preTransform;
        qCDebug(animation) << "            preRotation =" << _joints[i].preRotation;
        qCDebug(animation) << "            rotation =" << _joints[i].rotation;
        qCDebug(animation) << "            postRotation =" << _joints[i].postRotation;
        qCDebug(animation) << "            postTransform =" << _joints[i].postTransform;
        qCDebug(animation) << "            transform =" << _joints[i].transform;
        qCDebug(animation) << "            rotationMin =" << _joints[i].rotationMin << ", rotationMax =" << _joints[i].rotationMax;
        qCDebug(animation) << "            inverseDefaultRotation" << _joints[i].inverseDefaultRotation;
        qCDebug(animation) << "            inverseBindRotation" << _joints[i].inverseBindRotation;
        qCDebug(animation) << "            bindTransform" << _joints[i].bindTransform;
        qCDebug(animation) << "            isSkeletonJoint" << _joints[i].isSkeletonJoint;
#endif
        if (getParentIndex(i) >= 0) {
            qCDebug(animation) << "        parent =" << getJointName(getParentIndex(i));
        }
        qCDebug(animation) << "    },";
    }
    qCDebug(animation) << "]";
}
Beispiel #2
0
void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints, const AnimPose& geometryOffset) {
    _joints = joints;

    // build a cache of bind poses
    _absoluteBindPoses.reserve(joints.size());
    _relativeBindPoses.reserve(joints.size());

    // iterate over FBXJoints and extract the bind pose information.
    for (size_t i = 0; i < joints.size(); i++) {
        if (_joints[i].bindTransformFoundInCluster) {
            // Use the FBXJoint::bindTransform, which is absolute model coordinates
            // i.e. not relative to it's parent.
            AnimPose absoluteBindPose(_joints[i].bindTransform);
            _absoluteBindPoses.push_back(absoluteBindPose);
            int parentIndex = getParentIndex(i);
            if (parentIndex >= 0) {
                AnimPose inverseParentAbsoluteBindPose = _absoluteBindPoses[parentIndex].inverse();
                _relativeBindPoses.push_back(inverseParentAbsoluteBindPose * absoluteBindPose);
            } else {
                _relativeBindPoses.push_back(absoluteBindPose);
            }
        } else {
            // use FBXJoint's local transform, instead
            glm::mat4 rotTransform = glm::mat4_cast(_joints[i].preRotation * _joints[i].rotation * _joints[i].postRotation);
            glm::mat4 relBindMat = glm::translate(_joints[i].translation) * _joints[i].preTransform * rotTransform * _joints[i].postTransform;
            AnimPose relBindPose(relBindMat);
            _relativeBindPoses.push_back(relBindPose);

            int parentIndex = getParentIndex(i);
            if (parentIndex >= 0) {
                _absoluteBindPoses.push_back(_absoluteBindPoses[parentIndex] * relBindPose);
            } else {
                _absoluteBindPoses.push_back(relBindPose);
            }
        }
    }

    // now we want to normalize scale from geometryOffset to all poses.
    // This will ensure our bone translations will be in meters, even if the model was authored with some other unit of mesure.
    for (auto& absPose : _absoluteBindPoses) {
        absPose.trans = (geometryOffset * absPose).trans;
        absPose.scale = vec3(1, 1, 1);
    }

    // re-compute relative poses based on the modified absolute poses.
    for (size_t i = 0; i < _relativeBindPoses.size(); i++) {
        int parentIndex = getParentIndex(i);
        if (parentIndex >= 0) {
            _relativeBindPoses[i] = _absoluteBindPoses[parentIndex].inverse() * _absoluteBindPoses[i];
        } else {
            _relativeBindPoses[i] = _absoluteBindPoses[i];
        }
    }
}
Beispiel #3
0
void Heap::bubbleUp(int pos) {
	if (pos < 1)
		return;
	if (arr[pos]->priority < arr[getParentIndex(pos)]->priority) {
		Node *temp;
		temp = arr[getParentIndex(pos)];
		arr[getParentIndex(pos)] = arr[pos];
		arr[pos] = temp;
		pos = getParentIndex(pos);
		bubbleUp(pos);
	}
	return;
}
Beispiel #4
0
void D_HEAP<KeyType>::siftUp(int idx) {
    if ((idx >= sizeTree_) || (idx < 0))
        throw myExcp("Out of range.");
    if (idx == 0) return;

    int parent = getParentIndex(idx);

    while ((parent != -1) && (tree_[parent] > tree_[idx])) {
        swap(parent, idx);
        idx = parent;
        parent = getParentIndex(idx);
    }
}
Beispiel #5
0
void BinaryHeap<T>::heapifyUp(int nodeIndex) {
	int parentIndex = getParentIndex(nodeIndex);
	while(parentIndex != -1) {
		T parent = heap[parentIndex]->payload;
		T current = heap[nodeIndex]->payload;
		if(compare(current, parent)) {
			swap(parentIndex, nodeIndex);
			nodeIndex = parentIndex;
			parentIndex = getParentIndex(nodeIndex);	
		}
		else {
			break;
		}
	}
}
Beispiel #6
0
void heap_Insert(Heap *heap, int val)
{
    int index = heap->sz;

    heap->hPtr[index] = val;
    (heap->sz)++;

    int temp = getParentIndex(index);
    while ((heap->hPtr[temp] > heap->hPtr[index]) && (index > 0))
    {
        swapInt(heap->hPtr+temp, heap->hPtr+index);
        index = temp;
        temp = getParentIndex(index);
    }
};
Beispiel #7
0
void AnimSkeleton::dump() const {
    qCDebug(animation) << "[";
    for (int i = 0; i < getNumJoints(); i++) {
        qCDebug(animation) << "    {";
        qCDebug(animation) << "        index =" << i;
        qCDebug(animation) << "        name =" << getJointName(i);
        qCDebug(animation) << "        absBindPose =" << getAbsoluteBindPose(i);
        qCDebug(animation) << "        relBindPose =" << getRelativeBindPose(i);
        if (getParentIndex(i) >= 0) {
            qCDebug(animation) << "        parent =" << getJointName(getParentIndex(i));
        }
        qCDebug(animation) << "    },";
    }
    qCDebug(animation) << "]";
}
Beispiel #8
0
AnimPose AnimSkeleton::getRootAbsoluteBindPoseByChildName(const QString& childName) const {
    AnimPose pose = AnimPose::identity;
    int jointIndex = nameToJointIndex(childName);
    if (jointIndex >= 0) {
        int numJoints = (int)(_absoluteBindPoses.size());
        if (jointIndex < numJoints) {
            int parentIndex = getParentIndex(jointIndex);
            while (parentIndex != -1 && parentIndex < numJoints) {
                jointIndex = parentIndex;
                parentIndex = getParentIndex(jointIndex);
            }
            pose = _absoluteBindPoses[jointIndex];
        }
    }
    return pose;
}
Beispiel #9
0
void AnimSkeleton::dump(const AnimPoseVec& poses) const {
    qCDebug(animation) << "[";
    for (int i = 0; i < getNumJoints(); i++) {
        qCDebug(animation) << "    {";
        qCDebug(animation) << "        index =" << i;
        qCDebug(animation) << "        name =" << getJointName(i);
        qCDebug(animation) << "        absDefaultPose =" << getAbsoluteDefaultPose(i);
        qCDebug(animation) << "        relDefaultPose =" << getRelativeDefaultPose(i);
        qCDebug(animation) << "        pose =" << poses[i];
        if (getParentIndex(i) >= 0) {
            qCDebug(animation) << "        parent =" << getJointName(getParentIndex(i));
        }
        qCDebug(animation) << "    },";
    }
    qCDebug(animation) << "]";
}
Beispiel #10
0
ATOM_OctreeNode *ATOM_OctreeNodeChunk::getOrCreateNodeChain (ATOM_OctreeNode::NodeIndex index) 
{
  ATOM_OctreeNode *node = getOrCreateNode (index);
  if (getPrev ())
  {
    getPrev()->getOrCreateNodeChain (getParentIndex (index));
  }
  return node;
}
Beispiel #11
0
void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints) {
    _joints = joints;

    // build a cache of bind poses
    _absoluteBindPoses.reserve(joints.size());
    _relativeBindPoses.reserve(joints.size());

    // build a chache of default poses
    _absoluteDefaultPoses.reserve(joints.size());
    _relativeDefaultPoses.reserve(joints.size());
    _relativePreRotationPoses.reserve(joints.size());
    _relativePostRotationPoses.reserve(joints.size());

    // iterate over FBXJoints and extract the bind pose information.
    for (int i = 0; i < (int)joints.size(); i++) {

        // build pre and post transforms
        glm::mat4 preRotationTransform = _joints[i].preTransform * glm::mat4_cast(_joints[i].preRotation);
        glm::mat4 postRotationTransform = glm::mat4_cast(_joints[i].postRotation) * _joints[i].postTransform;
        _relativePreRotationPoses.push_back(AnimPose(preRotationTransform));
        _relativePostRotationPoses.push_back(AnimPose(postRotationTransform));

        // build relative and absolute default poses
        glm::mat4 relDefaultMat = glm::translate(_joints[i].translation) * preRotationTransform * glm::mat4_cast(_joints[i].rotation) * postRotationTransform;
        AnimPose relDefaultPose(relDefaultMat);
        _relativeDefaultPoses.push_back(relDefaultPose);
        int parentIndex = getParentIndex(i);
        if (parentIndex >= 0) {
            _absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose);
        } else {
            _absoluteDefaultPoses.push_back(relDefaultPose);
        }

        // build relative and absolute bind poses
        if (_joints[i].bindTransformFoundInCluster) {
            // Use the FBXJoint::bindTransform, which is absolute model coordinates
            // i.e. not relative to it's parent.
            AnimPose absoluteBindPose(_joints[i].bindTransform);
            _absoluteBindPoses.push_back(absoluteBindPose);
            if (parentIndex >= 0) {
                AnimPose inverseParentAbsoluteBindPose = _absoluteBindPoses[parentIndex].inverse();
                _relativeBindPoses.push_back(inverseParentAbsoluteBindPose * absoluteBindPose);
            } else {
                _relativeBindPoses.push_back(absoluteBindPose);
            }
        } else {
            // use default transform instead
            _relativeBindPoses.push_back(relDefaultPose);
            if (parentIndex >= 0) {
                _absoluteBindPoses.push_back(_absoluteBindPoses[parentIndex] * relDefaultPose);
            } else {
                _absoluteBindPoses.push_back(relDefaultPose);
            }
        }
    }
}
Beispiel #12
0
void 
balance_heap(binary_heap_t* bheap)
{
	size_t i = bheap->filled_elements - 1;
	int index = 0;

	while (getParentIndex(i) >= 0 
		   && 
		   bheap->value_comparer(bheap->buffer[i], bheap->buffer[getParentIndex(i)]) < 0)
	{
		void* value = bheap->buffer[i];

		index = getParentIndex(i);
		bheap->buffer[i] = bheap->buffer[index];
		bheap->buffer[index] = value;

		i = index;
	}
}
size_t StatusStructure::getLeftNeighbourIndex(size_t index) const {
    size_t currentIndex = index;

    if (leftChild(currentIndex) != nullptr) {
        // if there is a left sub tree find the most right leaf in that tree
        currentIndex = getLeftChildIndex(currentIndex);

        while (rightChild(currentIndex) != nullptr) {
            currentIndex = getRightChildIndex(currentIndex);
        }

        return currentIndex;
    }

    // the root element can't be the right child of another element
    if (currentIndex == 0) {
        return index;
    }

    if (!isLeftChild(currentIndex)) {
        // current element is the right child of its parent... hence the parent is the left neighbour
        return getParentIndex(currentIndex);
    }

    // current element is the left child of its parent... traverse upwards to the first node that is not a left child or the root node
    while (currentIndex > 0 && isLeftChild(currentIndex)) {
        currentIndex = getParentIndex(currentIndex);
    }

    if (currentIndex == 0) {
        return index;
    }

    // the fragment at currentIndex is right of its parent and the fragment that
    // we started with is the most left child of this fragment... hence the parent is
    // the direct left neighbour
    currentIndex = getParentIndex(currentIndex);

    return currentIndex;
}
size_t StatusStructure::getRightNeighbourIndex(size_t index) const {
    size_t currentIndex = index;

    if (rightChild(currentIndex) != nullptr) {
        // if there is a right sub tree find the most left leaf in that tree
        currentIndex = getRightChildIndex(currentIndex);

        while (leftChild(currentIndex) != nullptr) {
            currentIndex = getLeftChildIndex(currentIndex);
        }

        return currentIndex;
    }

    // the root element can't be the left child of another element
    if (currentIndex == 0) {
        return index;
    }

    if (isLeftChild(currentIndex)) {
        // current element is the left child of its parent... hence the parent is the right neighbour
        return getParentIndex(currentIndex);
    }

    // current element is the right child of its parent... traverse upwards to the first node that is not a right child or the root node
    while (currentIndex > 0 && !isLeftChild(currentIndex)) {
        currentIndex = getParentIndex(currentIndex);
    }

    if (currentIndex == 0) {
        return index;
    }

    currentIndex = getParentIndex(currentIndex);

    return currentIndex;
}
Beispiel #15
0
void
V3BvBlastBv::getNetName(V3NetId& id, string& name) const {
   if (V3NetUD == id) return;
   // Current Network
   if (!id.cp) {
      V3NetStrHash::const_iterator it = _netHash.find(id.id);
      if (it != _netHash.end()) { name = it->second; return; }
   }
   // Parent Networks
   if (_handler) {
      const V3NetId netId = id; id = getParentNetId(id); _handler->getNetName(id, name);
      if (_handler->getNtk()->getNetSize() <= netId.id && name.size()) 
         name += (V3AuxNameBitPrefix + v3Int2Str(getParentIndex(netId)) + V3AuxNameBitSuffix);
   }
}
Beispiel #16
0
	void heapify(int nodeIndex)
	{
		int parentIndex, temp;
		if (nodeIndex != 0)
		{
			parentIndex = getParentIndex(nodeIndex);
			// If parent node's value is bigger than current node's value, switch their places
			if (data[parentIndex] > data[nodeIndex])
			{
				temp = data[parentIndex];
				data[parentIndex] = data[nodeIndex];
				data[nodeIndex] = temp;
				// after switching, try to heapify the current node's parent
				heapify(parentIndex);
			}
		}
	}
Beispiel #17
0
void D_HEAP<KeyType>::deleteElem(int idx) {
    if ((idx >= sizeTree_) || (idx < 0))
        throw myExcp("Out of range.");

    swap(idx, sizeTree_ - 1);

    sizeTree_--;

    if (tree_[idx] < tree_[getParentIndex(idx)]) {
        cout << 2 << endl;

        siftUp(idx);
    }
    else {

        siftDown(idx);
    }
}
Beispiel #18
0
void AnimSkeleton::buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets) {

    _joints = joints;
    _jointsSize = (int)joints.size();
    // build a cache of bind poses

    // build a chache of default poses
    _absoluteDefaultPoses.reserve(_jointsSize);
    _relativeDefaultPoses.reserve(_jointsSize);
    _relativePreRotationPoses.reserve(_jointsSize);
    _relativePostRotationPoses.reserve(_jointsSize);

    // iterate over HFMJoints and extract the bind pose information.
    for (int i = 0; i < _jointsSize; i++) {

        // build pre and post transforms
        glm::mat4 preRotationTransform = _joints[i].preTransform * glm::mat4_cast(_joints[i].preRotation);
        glm::mat4 postRotationTransform = glm::mat4_cast(_joints[i].postRotation) * _joints[i].postTransform;
        _relativePreRotationPoses.push_back(AnimPose(preRotationTransform));
        _relativePostRotationPoses.push_back(AnimPose(postRotationTransform));

        // build relative and absolute default poses
        glm::mat4 relDefaultMat = glm::translate(_joints[i].translation) * preRotationTransform * glm::mat4_cast(_joints[i].rotation) * postRotationTransform;
        AnimPose relDefaultPose(relDefaultMat);

        int parentIndex = getParentIndex(i);
        if (parentIndex >= 0) {
            _absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose);
        } else {
            _absoluteDefaultPoses.push_back(relDefaultPose);
        }
    }

    for (int k = 0; k < _jointsSize; k++) {
        if (jointOffsets.contains(k)) {
            AnimPose localOffset(jointOffsets[k], glm::vec3());
            _absoluteDefaultPoses[k] = _absoluteDefaultPoses[k] * localOffset;
        }
    }
    // re-compute relative poses
    _relativeDefaultPoses = _absoluteDefaultPoses;
    convertAbsolutePosesToRelative(_relativeDefaultPoses);

    for (int i = 0; i < _jointsSize; i++) {
        _jointIndicesByName[_joints[i].name] = i;
    }

    // build mirror map.
    _nonMirroredIndices.clear();
    _mirrorMap.reserve(_jointsSize);
    for (int i = 0; i < _jointsSize; i++) {
        if (_joints[i].name != "Hips" && _joints[i].name != "Spine" &&
            _joints[i].name != "Spine1" && _joints[i].name != "Spine2" &&
            _joints[i].name != "Neck" && _joints[i].name != "Head" &&
            !((_joints[i].name.startsWith("Left") || _joints[i].name.startsWith("Right")) &&
              _joints[i].name != "LeftEye" && _joints[i].name != "RightEye")) {
            // HACK: we don't want to mirror some joints so we remember their indices
            // so we can restore them after a future mirror operation
            _nonMirroredIndices.push_back(i);
        }
        int mirrorJointIndex = -1;
        if (_joints[i].name.startsWith("Left")) {
            QString mirrorJointName = QString(_joints[i].name).replace(0, 4, "Right");
            mirrorJointIndex = nameToJointIndex(mirrorJointName);
        } else if (_joints[i].name.startsWith("Right")) {
            QString mirrorJointName = QString(_joints[i].name).replace(0, 5, "Left");
            mirrorJointIndex = nameToJointIndex(mirrorJointName);
        }
        if (mirrorJointIndex >= 0) {
            _mirrorMap.push_back(mirrorJointIndex);
        } else {
            _mirrorMap.push_back(i);
        }
    }
}
/*---------------------------------------------------------------------*//**
	親オブジェクトを設定する ⇒ STOBJ_SET_PARENT, STOBJ_CLEAR_PARENT
**//*---------------------------------------------------------------------*/
void EsObjectSlots::setParentObject(EsObject* obj)
{
	EsValue* v = value(getParentIndex());
	if(v == 0L)	{	return;	}
	v->setValue(obj);
}
/*---------------------------------------------------------------------*//**
	親オブジェクトを得る ⇒ STOBJ_GET_PARENT, OBJ_GET_PARENT
**//*---------------------------------------------------------------------*/
EsObject* EsObjectSlots::parentObject()
{
	EsValue* v = value(getParentIndex());
	if(v == 0L)	{	return 0L;	}
	return v->isVoid() ? 0L : v->getObject();
}
Beispiel #21
0
int D_HEAP<KeyType>::getReallocSize(void) const {
    int maxChild = getMaxChildIndex(getParentIndex(sizeTree_ - 1));
    return (d_ - maxChild % d_);
}
/*---------------------------------------------------------------------*//**
	親オブジェクトを得る ⇒ STOBJ_GET_PARENT, OBJ_GET_PARENT
**//*---------------------------------------------------------------------*/
const EsObject* EsObjectSlots::getParentObject() const
{
	const EsValue* v = getValue(getParentIndex());
	if(v == 0L)	{	return 0L;	}
	return v->isVoid() ? 0L : v->getObject();
}
Beispiel #23
0
void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints) {
    _joints = joints;

    // build a cache of bind poses
    _absoluteBindPoses.reserve(joints.size());
    _relativeBindPoses.reserve(joints.size());

    // build a chache of default poses
    _absoluteDefaultPoses.reserve(joints.size());
    _relativeDefaultPoses.reserve(joints.size());
    _relativePreRotationPoses.reserve(joints.size());
    _relativePostRotationPoses.reserve(joints.size());

    // iterate over FBXJoints and extract the bind pose information.
    for (int i = 0; i < (int)joints.size(); i++) {

        // build pre and post transforms
        glm::mat4 preRotationTransform = _joints[i].preTransform * glm::mat4_cast(_joints[i].preRotation);
        glm::mat4 postRotationTransform = glm::mat4_cast(_joints[i].postRotation) * _joints[i].postTransform;
        _relativePreRotationPoses.push_back(AnimPose(preRotationTransform));
        _relativePostRotationPoses.push_back(AnimPose(postRotationTransform));

        // build relative and absolute default poses
        glm::mat4 relDefaultMat = glm::translate(_joints[i].translation) * preRotationTransform * glm::mat4_cast(_joints[i].rotation) * postRotationTransform;
        AnimPose relDefaultPose(relDefaultMat);
        _relativeDefaultPoses.push_back(relDefaultPose);
        int parentIndex = getParentIndex(i);
        if (parentIndex >= 0) {
            _absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose);
        } else {
            _absoluteDefaultPoses.push_back(relDefaultPose);
        }

        // build relative and absolute bind poses
        if (_joints[i].bindTransformFoundInCluster) {
            // Use the FBXJoint::bindTransform, which is absolute model coordinates
            // i.e. not relative to it's parent.
            AnimPose absoluteBindPose(_joints[i].bindTransform);
            _absoluteBindPoses.push_back(absoluteBindPose);
            if (parentIndex >= 0) {
                AnimPose inverseParentAbsoluteBindPose = _absoluteBindPoses[parentIndex].inverse();
                _relativeBindPoses.push_back(inverseParentAbsoluteBindPose * absoluteBindPose);
            } else {
                _relativeBindPoses.push_back(absoluteBindPose);
            }
        } else {
            // use default transform instead
            _relativeBindPoses.push_back(relDefaultPose);
            if (parentIndex >= 0) {
                _absoluteBindPoses.push_back(_absoluteBindPoses[parentIndex] * relDefaultPose);
            } else {
                _absoluteBindPoses.push_back(relDefaultPose);
            }
        }
    }

    // build mirror map.
    _nonMirroredIndices.clear();
    _mirrorMap.reserve(_joints.size());
    for (int i = 0; i < (int)joints.size(); i++) {
        if (_joints[i].name.endsWith("tEye")) {
            // HACK: we don't want to mirror some joints so we remember their indices
            // so we can restore them after a future mirror operation
            _nonMirroredIndices.push_back(i);
        }
        int mirrorJointIndex = -1;
        if (_joints[i].name.startsWith("Left")) {
            QString mirrorJointName = QString(_joints[i].name).replace(0, 4, "Right");
            mirrorJointIndex = nameToJointIndex(mirrorJointName);
        } else if (_joints[i].name.startsWith("Right")) {
            QString mirrorJointName = QString(_joints[i].name).replace(0, 5, "Left");
            mirrorJointIndex = nameToJointIndex(mirrorJointName);
        }
        if (mirrorJointIndex >= 0) {
            _mirrorMap.push_back(mirrorJointIndex);
        } else {
            _mirrorMap.push_back(i);
        }
    }
}