Ejemplo n.º 1
0
void Point2PhantomNode::CalculateWeights(FeatureGraphNode & node) const
{
    // Need to initialize weights for correct work of PhantomNode::GetForwardWeightPlusOffset
    // and PhantomNode::GetReverseWeightPlusOffset.
  CalculateWeight(node.segment, node.segmentPoint, node.node.forward_node_id,
                  false /* calcFromRight */, node.node.forward_weight, node.node.forward_offset);
  CalculateWeight(node.segment, node.segmentPoint, node.node.reverse_node_id,
                  true /* calcFromRight */, node.node.reverse_weight, node.node.reverse_offset);
}
Ejemplo n.º 2
0
int CalculateWeight(struct Node* root){
    NodeT* p = root;
    int leftWeight = 0, rightWeight = 0;
    if(root == NULL) return 0;
    else{
        leftWeight = CalculateWeight(root->left) + 1;
        rightWeight = CalculateWeight(root->right) + 1;
        p->weight = leftWeight - rightWeight;
    }
    return (leftWeight>rightWeight)? leftWeight:rightWeight;
}
Ejemplo n.º 3
0
NodeT* balanceTree(struct Node* root){
    CalculateWeight(root);
    if(root == NULL) return 0;
    if(root != NULL){
            if(root->weight > 1){
                if(root->left->weight <= -1){
                    root->left=rotateLeft(root->left);
                    root = rotateRight(root);
                    return root;
                }
                else{
                    root = rotateRight(root);
                    return root;
                }
            }
            else if(root->weight < -1){
                if(root->right->weight >= 1){
                    root->right=rotateRight(root->right);
                    root = rotateLeft(root);
                    return root;
            }
                else{
                    root = rotateLeft(root);
                    return root;
            }
        }
        else return root;
    }
    return root;
}
Ejemplo n.º 4
0
void CFingerImage::UpdateTexture(  double weight, FBVector3d inherit, int index, 
								 GLuint drop, GLuint drop25, GLuint drop50, GLuint drop75, GLuint drop100 )
{
	if (mModel)
	{
		int value = CalculateWeight( (int) weight, index, inherit );

		if (value <= 10)
		{
			textureId = drop;
		}
		else
		if (value <= 35)
		{
			textureId = drop25;
		}
		else
		if (value <= 60)
		{
			textureId = drop50;
		}
		else
		if (value <= 85)
		{
			textureId = drop75;
		}
		else
			textureId = drop100;
	} else
		textureId = drop;
}
Ejemplo n.º 5
0
void Inventory::AddSlotItemRes(const ieResRef ItemResRef, int SlotID, int Charge0, int Charge1, int Charge2)
{
	CREItem *TmpItem = new CREItem();
	strnlwrcpy(TmpItem->ItemResRef, ItemResRef, 8);
	TmpItem->Expired=0;
	TmpItem->Usages[0]=(ieWord) Charge0;
	TmpItem->Usages[1]=(ieWord) Charge1;
	TmpItem->Usages[2]=(ieWord) Charge2;
	TmpItem->Flags=0;
	if (core->ResolveRandomItem(TmpItem) && gamedata->Exists(TmpItem->ItemResRef, IE_ITM_CLASS_ID)) {
		AddSlotItem( TmpItem, SlotID );
	} else {
		delete TmpItem;
	}
	CalculateWeight();
}
Ejemplo n.º 6
0
void Inventory::dump()
{
	printf( "INVENTORY:\n" );
	for (unsigned int i = 0; i < Slots.size(); i++) {
		CREItem* itm = Slots[i];

		if (!itm) {
			continue;
		}

		printf ( "%2u: %8.8s - (%d %d %d) %x Wt: %d x %dLb\n", i, itm->ItemResRef, itm->Usages[0], itm->Usages[1], itm->Usages[2], itm->Flags, itm->StackAmount, itm->Weight );
	}

	printf( "Equipped: %d\n", Equipped );
	Changed = true;
	CalculateWeight();
	printf( "Total weight: %d\n", Weight );
}
Ejemplo n.º 7
0
void Inventory::SetSlotItemRes(const ieResRef ItemResRef, int SlotID, int Charge0, int Charge1, int Charge2)
{
	if(ItemResRef[0]) {
		CREItem *TmpItem = new CREItem();
		strnlwrcpy(TmpItem->ItemResRef, ItemResRef, 8);
		TmpItem->Expired=0;
		TmpItem->Usages[0]=(ieWord) Charge0;
		TmpItem->Usages[1]=(ieWord) Charge1;
		TmpItem->Usages[2]=(ieWord) Charge2;
		TmpItem->Flags=0;
		if (core->ResolveRandomItem(TmpItem) && gamedata->Exists(TmpItem->ItemResRef, IE_ITM_CLASS_ID)) {
			SetSlotItem( TmpItem, SlotID );
		} else {
			delete TmpItem;
		}
	} else {
		//if the item isn't creatable, we still destroy the old item
		KillSlot( SlotID );
	}
	CalculateWeight();
}
Ejemplo n.º 8
0
void CFingerImage::UpdateTexture( FBModel *pRoot, int index, GLuint drop, GLuint drop25, GLuint drop50, GLuint drop75, GLuint drop100 )
{
	if (mModel)
	{
		FBProperty		*lWeightProp = pRoot->PropertyList.Find( "weight" );
		FBProperty		*lInheritProp = pRoot->PropertyList.Find( "inherit" );
		if (lWeightProp && lInheritProp)
		{
			int value = lWeightProp->AsInt();
			FBVector3d		lInherit;
			lInheritProp->GetData( &lInherit, sizeof( FBVector3d) );

			value = CalculateWeight( (int) value, index, lInherit );

			if (value <= 10)
			{
				textureId = drop;
			}
			else
			if (value <= 35)
			{
				textureId = drop25;
			}
			else
			if (value <= 60)
			{
				textureId = drop50;
			}
			else
			if (value <= 85)
			{
				textureId = drop75;
			}
			else
				textureId = drop100;
			
		}
	} else
		textureId = drop;
}
Ejemplo n.º 9
0
NodeT* insertNode(struct Node* root, int data){
    root = insertNodeUtil(root, data);
    CalculateWeight(root);
//    root = balanceTree(root);
    return root;
}