Esempio n. 1
0
IEKG3DAnimationTag* KG3DAnimationTagContainer::GetTag(enuTagType Type)
{
    IEKG3DAnimationTag *pTag = NULL;
    for (size_t i = 0; i < m_vecTags.size(); i++)
    {
        if (m_vecTags[i].Type == Type)
        {
            pTag = dynamic_cast<IEKG3DAnimationTag*>(m_vecTags[i].pTag);
            break;
        }
    }
    if (!pTag)
    {
        Item NewItem;
        NewItem.Type = Type;
        NewItem.pTag = GetNewInstance(Type);
        KGLOG_PROCESS_ERROR(NewItem.pTag);
        
        m_vecTags.push_back(NewItem);
        pTag = dynamic_cast<IEKG3DAnimationTag*>(NewItem.pTag);
        NewItem.pTag->SetParentModel(m_pModel);
        
    }
Exit0:
    return pTag;
}
Esempio n. 2
0
	int GradientBoostingForest::GetNewInstancePool(InstancePool &instancepool,InstancePool &newInstancePool)
	{
		for(int i=0;i<instancepool.Size();i++)
		{
			int ret;
			Instance newInstance;
			ret = GetNewInstance(instancepool.GetInstance(i),newInstance);
			if(ret != 0)
			{
				return -1;
			}
			newInstancePool.AddInstance(newInstance);
		}
		return 0;
	}
Esempio n. 3
0
HRESULT KG3DAnimationTagContainer::Clone(KG3DAnimationTagContainer* pSrc)
{
	HRESULT hr = E_FAIL;

	ASSERT(m_pClip==NULL);

    memcpy(m_szAnimationName, pSrc->m_szAnimationName, _countof(m_szAnimationName) - 1);
    m_szAnimationName[_countof(m_szAnimationName) - 1] = '\0';

	m_pClip            = pSrc->m_pClip;
	m_pModel           = pSrc->m_pModel;
	m_uMotionTagIndex  = pSrc->m_uMotionTagIndex;
	m_bModifyFlag      = pSrc->m_bModifyFlag;
	//m_IsLoaded         = pSrc->m_IsLoaded;

	if(m_pClip)
		m_pClip->AddRef();

	ASSERT(m_vecTags.size()==0);

	for (size_t i=0;i<pSrc->m_vecTags.size();i++)
	{
		Item& SrcItem = pSrc->m_vecTags[i];
		IKG3DAnimationTag* pNewTag = NULL;
		Item NewItem;

		pNewTag = GetNewInstance(SrcItem.Type);
		KG_PROCESS_ERROR(pNewTag);

		hr = pNewTag->Clone(SrcItem.pTag);
		KG_COM_PROCESS_ERROR(hr);

		pNewTag->SetParentModel(m_pModel);
		NewItem.pTag = pNewTag;
		NewItem.Type = SrcItem.Type;
		m_vecTags.push_back(NewItem);
	}

	m_IsLoaded = TRUE;
Exit0:
	return S_OK;
}
Esempio n. 4
0
HRESULT KG3DAnimationTagContainer::_Load(LPCSTR strFileName)
{
    HRESULT hrResult = E_FAIL;
    HRESULT hrRetCode = E_FAIL;
    IFile* pFile = NULL;
    FileHeader Header;
    AnimationTagBlockHeader BlockHeader;
    unsigned long uRetCode = 0;
    IKG3DAnimationTag* pNewTag = NULL;
	Clear();

	KG_PROCESS_ERROR(strFileName);

    pFile = g_OpenFile(strFileName);
    KGLOG_PROCESS_ERROR(pFile);
    
    uRetCode = pFile->Read(&Header, sizeof(FileHeader));
    KGLOG_PROCESS_ERROR(uRetCode == sizeof(FileHeader));

    KG_PROCESS_ERROR(Header.dwMask == FileHeader::s_dwMask);

    strncpy(m_szAnimationName, Header.strAnimationFileName, _countof(m_szAnimationName) - 1);
    m_szAnimationName[_countof(m_szAnimationName) - 1] = '\0';

    hrRetCode = g_cClipTable.LoadResourceFromFile(m_szAnimationName, 0, 0, &m_pClip);
    KGLOG_COM_PROCESS_ERROR(hrRetCode);

    switch(Header.dwVersion)
    {
    case FileHeader::s_dwCurrentVersion:
        {
            for (DWORD i = 0; i < Header.dwNumBlock; i++)
            {
                Item NewItem;

                uRetCode = pFile->Read(&BlockHeader, sizeof(AnimationTagBlockHeader));
                KGLOG_PROCESS_ERROR(uRetCode == sizeof(AnimationTagBlockHeader));

                if (BlockHeader.dwNumKeyFrames == 0)
                {
                    hrRetCode = SkipBlock(&BlockHeader, pFile);
                    KGLOG_COM_PROCESS_ERROR(hrRetCode);

                    continue;
                }

                pNewTag = GetNewInstance(static_cast<enuTagType>(BlockHeader.dwType));
                KG_PROCESS_ERROR(pNewTag);

                hrRetCode = pNewTag->LoadFromFile(pFile, BlockHeader.dwVersion, BlockHeader.dwNumKeyFrames);
                KG_COM_PROCESS_ERROR(hrRetCode);

                pNewTag->SetParentModel(m_pModel);
                NewItem.pTag = pNewTag;
                NewItem.Type = static_cast<enuTagType>(BlockHeader.dwType);

                m_vecTags.push_back(NewItem);
                pNewTag = NULL;
            }
        }
        break;
    default:
        _ASSERTE(0);
    }

    m_IsLoaded = TRUE;

    hrResult = S_OK;
Exit0:
    SAFE_DELETE(pNewTag);
    KG_COM_RELEASE(pFile);

    return hrResult;
}
Esempio n. 5
0
	int GradientBoostingForest::LearnNewInstance()
	{
		if(!m_pconfig->IsLearnNewInstances)	
		{
			Comm::LogErr("GradientBoostingForest::LearnNewInstance IsLearnNewInstances is 0");
			return -1;
		}
		//	std::vector< std::vector<int> > vecTmpInstances(m_pInstancePool->Size());
		int LeafCnt = 0;
		for(int i=0;i<m_Forest.size();i++)
		{
			DecisionTree * pTree = m_Forest[i];
			for(int j=0;j<pTree->Size();j++)
			{
			//	printf("SizeSize %d\n",pTree->Size());
				DecisionTreeNode & node = pTree->GetNode(j);
				if(LEAF == node.m_status)
				{
					/*
					if(node.m_InstancesHashCode == 1150390567)
					{
						printf("f**k debug");
						node.print();
					}
					*/
					if(NULL == node.m_ppInstances)
					{
						Comm::LogErr("GradientBoostingForest::LearnNewInstance fail m_ppInstances is NULL DebugStr = %s",node.DebugStr().c_str());
						return -1;
					}
					node.m_LeafIndex = LeafCnt;
					LeafCnt++;
					node.m_ppInstances = Comm::Free(node.m_ppInstances);
				}
			}
		}
		
		m_TotLeafCnt = LeafCnt;
			
		if(m_pconfig->OutputNewInstancesFilePath == "null")
		{
			Comm::LogInfo("GradientBoostingForest::LearnNewInstance OutputNewInstancesFilePath is null");
			return 0;
		}
		std::ostringstream oss;
		oss.clear();
		oss.str("");
		FILE * fp = fopen(m_pconfig->OutputNewInstancesFilePath.c_str(),"w");
		if(NULL == fp)
		{
			Comm::LogErr("GradientBoostingForest::LearnNewInstance fail! open %s fail!",m_pconfig->OutputNewInstancesFilePath.c_str());
			return -1;
		}

		//IsPushBackOgX
		if(m_pconfig->IsPushBackOgX)
			oss<<"n_feature,"<<LeafCnt + m_pconfig->FeatureNum<<"\n";
		else 
			oss<<"n_feature,"<<LeafCnt<<"\n";
		
		int ret = fputs(oss.str().c_str(),fp);
		if(ret < 0)
		{
			Comm::LogErr("GradientBoostingForest::LearnNewInstance fail!fputs %s fail!",oss.str().c_str());
			fclose(fp);
			return -1;
		}

		for(int i=0;i<m_pInstancePool->Size();i++)
		{
			Instance newInstance;
			ret = GetNewInstance(m_pInstancePool->GetInstance(i), newInstance);
			if(ret != 0)
			{
				Comm::LogErr("GradientBoostingForest::LearnNewInstance GetNewInstance i = %d fail!",i);
				fclose(fp);
				return -1;
			}
			std::string str = newInstance.ToString() + "\n";
			ret = fputs(str.c_str(),fp);
			if(ret < 0)
			{
				Comm::LogErr("GradientBoostingForest::LearnNewInstance fputs %s fail!",str.c_str());
				fclose(fp);
				return -1;
			}
		}

		fclose(fp);
		return 0;
	}