Пример #1
0
void StudioModel::scaleMeshes (float scale)
{
	CStudioHdr *pStudioHdr = GetStudioHdr();
	if (!pStudioHdr)
		return;

	int i, j, k;

	// manadatory to access correct verts
	SetCurrentModel();

	// scale verts
	int tmp = m_bodynum;
	for (i = 0; i < pStudioHdr->numbodyparts(); i++)
	{
		mstudiobodyparts_t *pbodypart = pStudioHdr->pBodypart( i );
		for (j = 0; j < pbodypart->nummodels; j++)
		{
			SetBodygroup (i, j);
			SetupModel (i);

			const mstudio_modelvertexdata_t *vertData = m_pmodel->GetVertexData();

			for (k = 0; k < m_pmodel->numvertices; k++)
			{
				*vertData->Position(k) *= scale;
			}
		}
	}

	m_bodynum = tmp;

	// scale complex hitboxes
	int hitboxset = g_MDLViewer->GetCurrentHitboxSet();

	mstudiobbox_t *pbboxes = pStudioHdr->pHitbox( 0, hitboxset );
	for (i = 0; i < pStudioHdr->iHitboxCount( hitboxset ); i++)
	{
		VectorScale (pbboxes[i].bbmin, scale, pbboxes[i].bbmin);
		VectorScale (pbboxes[i].bbmax, scale, pbboxes[i].bbmax);
	}

	// scale bounding boxes
	for (i = 0; i < pStudioHdr->GetNumSeq(); i++)
	{
		mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( i );
		Vector tmp;

		tmp = seqdesc.bbmin;
		VectorScale( tmp, scale, tmp );
		seqdesc.bbmin = tmp;

		tmp = seqdesc.bbmax;
		VectorScale( tmp, scale, tmp );
		seqdesc.bbmax = tmp;

	}

	// maybe scale exeposition, pivots, attachments
}
Пример #2
0
void	CLODConvertApp::FileOpen(CString FileName)
{

		EditList[ModelSelected].Name="";
		// Ok... Load the model
		CFile File;
		File.Open(FileName, CFile::modeRead, &CFileException(CFileException::generic, NULL));
		DWORD	FileSize=(DWORD)File.GetLength();
		void *FileBuffer=malloc(FileSize);
		File.Read(FileBuffer, FileSize);
		FileTitle=File.GetFileTitle();
		File.Close();
		TheModelPath=FileName;
		
		while(RenderPhase) Delay(5);
		// Eventually clear the model
		ClearModel(&EditList[ModelSelected]);
		// Linearize the model and assign to selected item
		DeIndexModel(FileBuffer, &EditList[ModelSelected]);
		E_FixModelFeatures(&EditList[ModelSelected]);
		EditList[ModelSelected].Name=FileTitle;
	
		SetupModel();
		AddToRecentFileList(FileName);

}
Пример #3
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HGLRC hglrc;
    static GLuint program;
    static GLuint width, height, texture;
    static GLuint imgWidth, imgHeight;

    switch (uMsg)
    {
    case WM_CREATE:
        hglrc = CreateOpenGLContext(hwnd);
        InitOpenGLFunctions();
        RegisterErrorCallback();
        program = LoadShader();

        width = glGetUniformLocation(program, "width");
        height = glGetUniformLocation(program, "height");

        texture = glGetUniformLocation(program, "texture");
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, LoadTexture(ID_TEXTURE));
        glUniform1i(texture, 0);

        imgWidth = glGetUniformLocation(program, "img_width");
        imgHeight = glGetUniformLocation(program, "img_height");
        glUniform1f(imgWidth, 400.0f);
        glUniform1f(imgHeight, 300.0f);

        SetupModel(hwnd);
        glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
        return 0;

    case WM_PAINT:
        Paint(hwnd);
        return 0;

    case WM_SIZE:
        glViewport(0, 0, LOWORD(lParam), HIWORD(lParam));
        glUniform1f(width, LOWORD(lParam));
        glUniform1f(height, HIWORD(lParam));
        InvalidateRect(hwnd, nullptr, FALSE);
        return 0;

    case WM_DESTROY:
        DeleteOpenGLContext(hglrc);
        PostQuitMessage(0);
        return 0;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}
void TestIndividualImage(string imagePath, string categoryName, int database_type)
{
	//Load image 
	Mat testImage = imread(imagePath);

	//Load database
	vector<Mat> trainData, trainLabels;
	vector<float> videoFPS;
	vector<string> _listDataName = SetupModel(categoryName, trainData, trainLabels, videoFPS, database_type);

	//Load dictionary for BOW model
	if (database_type == 1)
		bowDE.setVocabulary(LoadBOWDictionaryFromFile("Data/Training_Data/" + categoryName + "_BOW_dictionary.xml"));

	clock_t t;

	t = clock();

	//---Extract feature based on database_type
	Mat queryFeature;
	if (database_type == 1)
		queryFeature = ExtractBOWFeature(bowDE, detector, testImage);
	else
		queryFeature = ExtractMPEGFeature(testImage);

	//For each test image, retrieve list of video and check if there's any correct video in candidate list
	vector<int> predictLabels = RetrieveVideo(_listDataName.size(), queryFeature, trainData);
	if (predictLabels.size() > 0)
	{
		cout << "This image can belong to: " << endl;
		for (int j = 0; j < 3; j++)
		{
			int predictLabel = predictLabels[j];
			cout << GetName(_listDataName[predictLabel]) << endl;

//			string videoName = "Data/Raws/" + categoryName + "/" + _listRawClass[predictLabel];
			RetrieveShot(videoFPS[predictLabel], trainData[predictLabel], trainLabels[predictLabel], queryFeature);
		}
		cout << endl;
	}
	else
	{
		cout << "No video match the query image" << endl << endl;
	}

	t = clock() - t;

	cout << "It took " << ((float)t) / CLOCKS_PER_SEC << " seconds to complete all tasks" << endl;
}
Пример #5
0
/*
================
StudioModel::DrawModel
inputs:
	currententity
	r_entorigin
================
*/
void StudioModel::DrawModel( )
{
	int i;

	g_smodels_total++; // render data cache cookie

	g_pxformverts = &g_xformverts[0];
	g_pvlightvalues = &g_lightvalues[0];

	if (m_pstudiohdr->numbodyparts == 0)
		return;

	glPushMatrix ();

    glTranslatef (m_origin[0],  m_origin[1],  m_origin[2]);

    glRotatef (m_angles[1],  0, 0, 1);
    glRotatef (m_angles[0],  0, 1, 0);
    glRotatef (m_angles[2],  1, 0, 0);

	// glShadeModel (GL_SMOOTH);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	// glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

	SetUpBones ( );

	SetupLighting( );
	
	for (i=0 ; i < m_pstudiohdr->numbodyparts ; i++) 
	{
		SetupModel( i );
		DrawPoints( );
	}

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	// glShadeModel (GL_FLAT);

	// glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glPopMatrix ();
}
void StudioModel::scaleMeshes (float scale)
{
	if (!m_pstudiohdr)
		return;

	int i, j, k;

	// scale verts
	int tmp = m_bodynum;
	for (i = 0; i < m_pstudiohdr->numbodyparts; i++)
	{
		mstudiobodyparts_t *pbodypart = (mstudiobodyparts_t *)((byte *)m_pstudiohdr + m_pstudiohdr->bodypartindex) + i;
		for (j = 0; j < pbodypart->nummodels; j++)
		{
			SetBodygroup (i, j);
			SetupModel (i);

			vec3_t *pstudioverts = (vec3_t *)((byte *)m_pstudiohdr + m_pmodel->vertindex);

			for (k = 0; k < m_pmodel->numverts; k++)
				VectorScale (pstudioverts[k], scale, pstudioverts[k]);
		}
	}

	m_bodynum = tmp;

	// scale complex hitboxes
	mstudiobbox_t *pbboxes = (mstudiobbox_t *) ((byte *) m_pstudiohdr + m_pstudiohdr->hitboxindex);
	for (i = 0; i < m_pstudiohdr->numhitboxes; i++)
	{
		VectorScale (pbboxes[i].bbmin, scale, pbboxes[i].bbmin);
		VectorScale (pbboxes[i].bbmax, scale, pbboxes[i].bbmax);
	}

	// scale bounding boxes
	mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pstudiohdr + m_pstudiohdr->seqindex);
	for (i = 0; i < m_pstudiohdr->numseq; i++)
	{
		VectorScale (pseqdesc[i].bbmin, scale, pseqdesc[i].bbmin);
		VectorScale (pseqdesc[i].bbmax, scale, pseqdesc[i].bbmax);
	}

	// maybe scale exeposition, pivots, attachments
}
Пример #7
0
 MaeGibbs(int nu, vec2d y, vec3d X) { SetupModel(nu, y, X); }
void TestShotRetrieval(string categoryName, int database_type, int num_retrieve)
{
	string resultFile = "Data/Result_" + categoryName + "_ShotRetrieval.txt";
	ofstream out(resultFile);

	//Load database
	vector<Mat> trainData, trainLabels;
	vector<float> videoFPS;
	vector<string> _listDataName = SetupModel(categoryName, trainData, trainLabels, videoFPS, database_type);
	
	//Load dictionary for BOW model
	if (database_type == 1)
		bowDE.setVocabulary(LoadBOWDictionaryFromFile("Data/Training_Data/" + categoryName + "_BOW_dictionary.xml"));

	//Get list of test frames
	string pathTest = "Data/Test_images/" + categoryName + "/";
	vector<string> _listTestClass = ReadFileList(pathTest);


	vector<vector<float>> _listWeightScore;
	for (int index = 0; index < _listTestClass.size(); index++)
	{
		vector<float> avgWeigthScore;
		avgWeigthScore.resize(num_retrieve);

		string pathClass = pathTest + _listTestClass[index] + "/";
		vector<string> _listTestImage = ReadFileList(pathClass);
		for (int i = 0; i < _listTestImage.size(); i++)
		{
			string testpath = pathClass + _listTestImage[i];
			Mat testImage = imread(testpath);

			//---Extract feature based on database_type
			Mat queryFeature;
			if (database_type == 1)
				queryFeature = ExtractBOWFeature(bowDE, detector, testImage);
			else
				queryFeature = ExtractMPEGFeature(testImage);

			//For each test image, retrieve list of shot and check if there's any correct shot in candidate list
			int trueShotID = IdentifyShotFromKeyFrame(_listTestImage[i]);

			cout << "Retrieve shot in video " << GetName(_listDataName[index]) << " using " << _listTestImage[i] << endl;
			vector<int> _listShotID = RetrieveShot(videoFPS[index], trainData[index], trainLabels[index], queryFeature);

			//Calculate precision and recall
			for (int numRetrieve = 0; numRetrieve < num_retrieve; numRetrieve++)
			{
				float weightScore = ShotRetrievalPerformance(_listShotID, trueShotID, numRetrieve+1);
				avgWeigthScore[numRetrieve] += weightScore;
			}

			cout << endl;
		}

		for (int i = 0; i < num_retrieve; i++)
		{
			avgWeigthScore[i] /= _listTestImage.size();
		}

		_listWeightScore.push_back(avgWeigthScore);
	}

	vector<float> avgWeightScorePerNumRetrieval;
	avgWeightScorePerNumRetrieval.resize(num_retrieve);
	for (int i = 0; i < _listWeightScore.size(); i++)
	{
		float avgPrecision = 0.0f;
		out << _listTestClass[i].c_str() << endl;
		for (int j = 0; j < num_retrieve; j++)
		{
			out << j+1 << ". " << _listWeightScore[i][j] << endl;
			avgWeightScorePerNumRetrieval[j] += _listWeightScore[i][j];
		}
		out << endl;
	}

	out << endl << "Average weight score: " << endl;
	for (int i = 0; i < num_retrieve; i++)
	{ 
		avgWeightScorePerNumRetrieval[i] /= (float)_listWeightScore.size();
		out << i + 1 << ". " << avgWeightScorePerNumRetrieval[i] << endl;
	}

	out.close();
}
void TestVideoRetrieval(string categoryName, int database_type)
{
	//Load database
	vector<Mat> trainData, trainLabels;
	vector<float> videoFPS;
	vector<string> _listDataName = SetupModel(categoryName, trainData, trainLabels, videoFPS, database_type);

	//Load dictionary for BOW model
	if (database_type == 1)
		bowDE.setVocabulary(LoadBOWDictionaryFromFile("Data/Training_Data/" + categoryName + "_BOW_dictionary.xml"));

	float avgReciprocalRank = 0.0f;
	float avgPrecision = 0.0f;
	float avgRecall = 0.0f;
	string pathTest = "Data/Test_images/" + categoryName + "/";
	vector<string> _listTestClass = ReadFileList(pathTest);

	int countTotal = 0;
	for (int index = 0; index < _listTestClass.size(); index++)
	{
		float avgClassRR = 0.0f;

		string pathClass = pathTest + _listTestClass[index] + "/";
		vector<string> _listTestImage = ReadFileList(pathClass);
		for (int i = 0; i < _listTestImage.size(); i++)
		{
			string testpath = pathClass + _listTestImage[i];
			Mat testImage = imread(testpath);

			//---Extract feature based on database_type
			Mat queryFeature;
			if (database_type == 1)
				queryFeature = ExtractBOWFeature(bowDE, detector, testImage);
			else
				queryFeature = ExtractMPEGFeature(testImage);

			//For each test image, retrieve list of video and check if there's any correct video in candidate list
			int countMatch = 0;
			int countMatchRank = 0;
			int countRetrievedMatch = 0;
			int numMatchRetrieve = 3;
			vector<int> predictLabels = RetrieveVideo(_listTestClass.size(), queryFeature, trainData);

			//Calculate precision and recall from retrieved list
			if (predictLabels.size() > 0)
			{
				cout << _listTestImage[i] << " in video " << _listTestClass[index] << " can belong to: " << endl;
				for (int j = 0; j < predictLabels.size(); j++)
				{
					int predictLabel = predictLabels[j];
					cout << _listTestClass[predictLabel] << endl;

					countMatchRank++;
					if (predictLabel == index)
					{
						if (j < numMatchRetrieve)
						{
							countRetrievedMatch++;
						}
						countMatch++;
						break;
					}
				}
				cout << endl;
			}
			else
			{
				cout << "No video match the query image" << endl << endl;
			}

			float reciprocalrank = 0.0f;
			float precision = 0.0f;
			float recall = 0.0f;
			if (predictLabels.size() > 0)
			{
				reciprocalrank = (float)countMatch / (float)countMatchRank;
				precision = (float)countRetrievedMatch / (float)numMatchRetrieve;
				recall = countRetrievedMatch;
			}
				
			avgClassRR += reciprocalrank;
			avgPrecision += precision;
			avgRecall += recall;
		}

		countTotal += _listTestImage.size();

		avgReciprocalRank += avgClassRR;
	}

	avgReciprocalRank = avgReciprocalRank / countTotal * 100.0f;
	avgPrecision = avgPrecision / countTotal * 100.0f;
	avgRecall = avgRecall / countTotal * 100.0f;

	cout << "MAP = " << avgReciprocalRank << endl;
	cout << "Average Precision = " << avgPrecision << endl;
	cout << "Average Recall = " << avgRecall << endl;
}
Пример #10
0
// Initialize scene
bool CViewerScene::Init ()
{
    if (m_bInited)
        return true;

    glewInit();

    m_pRenderer = GetRenderer();
    m_pRenderer->SetViewport(m_ResX, m_ResY, 4.0f, 4500.0f, 0.67f);

    m_pResourceMgr = GetResourceMgr();
    m_pSg = GetSceneGraph();
    m_pCamera = m_pRenderer->GetCamera();
    m_pActorMgr = GetActorManager();

    OGVec3 vTarget (0, 0, 0);
    OGVec3 vDir (0, -1.0f, 0.4f);
    vDir = vDir.normalize();
    OGVec3 vUp = vDir.cross (OGVec3(1, 0, 0));
    m_pCamera->Setup (vTarget - (vDir*m_fCameraDistance), vTarget, vUp);

    OGVec3 vLightDir = OGVec3(0,1,0);
    OGVec4 vLightColor = OGVec4(1,1,1,1);
    IOGLight* pMainLight = m_pRenderer->GetLightMgr()->CreateLight();
    pMainLight->type = OG_LIGHT_DIRECTIONAL;
    pMainLight->vPosition = vLightDir;
    pMainLight->fIntensity = 100.0f;
    pMainLight->vAmbientColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
    pMainLight->vDiffuseColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
    pMainLight->vSpecularColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);

    glDisable(GL_CULL_FACE);
    glEnable(GL_NORMALIZE);

    if (m_pResourceMgr->Load(OG_RESPOOL_GAME) == false)
    {
        return false;
    }

    if (GetActorParamsMgr()->Init())
    {
        std::list<IOGActorParams*> ActorsParamsList;
        GetActorParamsMgr()->GetParamsList(ActorsParamsList);
        std::list<IOGActorParams*>::const_iterator iter = ActorsParamsList.begin();
        for (; iter != ActorsParamsList.end(); ++iter)
        {
            if ((*iter)->type == OG_ACTOR_MISSILE ||
                (*iter)->type == OG_ACTOR_PLASMAMISSILE ||
                (*iter)->type == OG_ACTOR_GAUSSRAY )
            {
                continue;
            }

            CommonToolEvent<ResLoadEventData> cmd(EVENTID_RESLOAD);
            cmd.SetEventCustomData(ResLoadEventData(wxT((*iter)->alias.c_str()), 
                wxT(ActorTypeToGroupName((*iter)->type).c_str()),
                wxT((*iter)->icon.c_str())));
            GetEventHandlersTable()->FireEvent(EVENTID_RESLOAD, &cmd);
        }
    }
    else
    {
        return false;
    }

    SetupModel(NULL);
    m_bInited = true;

    return true;
}
	virtual void ParseModelInfo( KeyValues *inResourceData )
	{
		BaseClass::ParseModelInfo(inResourceData);

		SetupModel();
	}