Exemplo n.º 1
0
int  Font::FindFaceNameIndex(const String& name) {
	if(name == "STDFONT")
		return 0;
	for(int i = 1; i < GetFaceCount(); i++)
		if(GetFaceName(i) == name)
			return i;
	String n = Filter(name, FontFilter);
	for(int i = 1; i < GetFaceCount(); i++)
		if(Filter(GetFaceName(i), FontFilter) == n)
			return i;
	if(n == "serif")
		return SERIF;
	if(n == "sansserif")
		return SANSSERIF;
	if(n == "monospace")
		return MONOSPACE;
	if(n == "stdfont")
		return STDFONT;
	return 0;
}
Exemplo n.º 2
0
void CSceneObject::OnFrame()
{
	inherited::OnFrame();
	if (!m_pReference) return;
	if (m_pReference) m_pReference->OnFrame();
	if (psDeviceFlags.is(rsStatistic)){
    	if (IsStatic()||IsMUStatic()||Selected()){
            Device.Statistic->dwLevelSelFaceCount 	+= GetFaceCount();
            Device.Statistic->dwLevelSelVertexCount += GetVertexCount();
        }
    }
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------
// Skeleton functions
//----------------------------------------------------------------------------
bool CEditableObject::ImportMAXSkeleton(CExporter* E)
{
	bool bResult				= true;
	CEditableMesh* MESH			= xr_new<CEditableMesh>(this);
	m_Meshes.push_back(MESH);
	// import mesh
	if (!MESH->Convert(E))		return FALSE;
	// BONES
	m_Bones.reserve(E->m_Bones.size());
	for (int B=0; B!=E->m_Bones.size(); B++){
		m_Bones.push_back(xr_new<CBone>());
		CBone* BONE				= m_Bones.back(); 
		CBoneDef* bone			= E->m_Bones[B];
		CBoneDef* parent_bone	= bone->parent;

		Fvector offset,rotate;
		float length= 0.1f;

		Fmatrix m;
		if (parent_bone)	m.mul(parent_bone->matOffset,bone->matInit);
		else				m.set(bone->matInit);

		m.getXYZi			(rotate);
		offset.set			(m.c);

		BONE->SetWMap		(bone->name.c_str());
		BONE->SetName		(bone->name.c_str());
		BONE->SetParentName	(Helper::ConvertSpace(string(bone->pBone->GetParentNode()->GetName())).c_str());
		BONE->SetRestParams	(length,offset,rotate);
	}

	// DEFAULT BONE PART
	m_BoneParts.push_back(SBonePart());
	SBonePart& BP = m_BoneParts.back();
	BP.alias = "default";
	for (int b_i=0; b_i<(int)m_Bones.size(); b_i++)
		BP.bones.push_back(Bones()[b_i]->Name());

	m_objectFlags.set(CEditableObject::eoDynamic,TRUE);

	if ((0==GetVertexCount())||(0==GetFaceCount())){ 
		bResult = false;
	}else{
		ELog.Msg(mtInformation,"Model '%s' contains: %d points, %d faces, %d bones", E->m_MeshNode->GetName(), GetVertexCount(), GetFaceCount(), Bones().size());
	}

	return bResult;
}
DataSplitter::DataSplitter(std::unordered_map<long, std::list<Recording>> idToSamplesMap, double trainingRatio)
{
    srand (13);
    int numSubjectsUsed = 0;
    
    for (std::unordered_map<long, std::list<Recording>>::iterator it = idToSamplesMap.begin(); it != idToSamplesMap.end(); it++)
    {
	// only want ppl with 12+ face images
	if (GetFaceCount(it->second) < 12)
	{
	    continue;
	}
	
	for (std::list<Recording>::iterator listIt = it->second.begin(); listIt != it->second.end(); listIt++)
	{
	    if (!listIt->HasFace())
	    {
		continue;
	    }
	    
	    cv::Mat currentImage = cv::imread(listIt->GetFilePath(), cv::IMREAD_GRAYSCALE);
	    
	    cv::Mat equalizedCurrentImage;
	    cv::equalizeHist(currentImage, equalizedCurrentImage);
	    
	    if (rand()%10 < trainingRatio*10)
	    {
		std::cout << "Using " << listIt->GetRecordingId() << "(" << listIt->GetSubjectId() << ") for TRAINING." << std::endl;		
		_trainingList.push_back(std::make_tuple(equalizedCurrentImage, listIt->GetSubjectId(), listIt->GetRecordingId()));
	    }
	    else
	    {
		std::cout << "Using " << listIt->GetRecordingId() << "(" << listIt->GetSubjectId() << ") for TESTING." << std::endl;
		_testList.push_back(std::make_tuple(equalizedCurrentImage, listIt->GetSubjectId(), listIt->GetRecordingId()));	    
	    }
	}	
	
	if (numSubjectsUsed++ > 40)
	{
	    break;
	}
    }
    
    std::cout << "Number of Subjects Used: " << numSubjectsUsed << std::endl;
    std::cout << "Training size: " << _trainingList.size() << std::endl;
    std::cout << "Testing size: " << _testList.size() << std::endl;
    
}
Exemplo n.º 5
0
bool CEditableMesh::Convert( INode *node )
{
	// prepares & checks
	BOOL bDeleteObj;
	bool bResult = true;
	TriObject *obj = ExtractTriObject( node, bDeleteObj );

	if( !obj ){
		ELog.Msg(mtError,"%s -> Can't convert to TriObject", node->GetName() );
		return false; }

	if( obj->mesh.getNumFaces() <=0 ){
		ELog.Msg(mtError,"%s -> There are no faces ?", node->GetName() );
		if (bDeleteObj) delete (obj);
		return false; }

	Mtl *pMtlMain = node->GetMtl();
	DWORD cSubMaterials=0;

	if (pMtlMain){
		// There is at least one material. We're in case 1) or 2)
		cSubMaterials = pMtlMain->NumSubMtls();
		if (cSubMaterials < 1){
			// Count the material itself as a submaterial.
			cSubMaterials = 1;
		}
	}

	// build normals
	obj->mesh.buildRenderNormals();

	// vertices
	m_VertCount = obj->mesh.getNumVerts();
	m_Vertices = xr_alloc<Fvector>(m_VertCount);
	for (int v_i=0; v_i<m_VertCount; v_i++){
		Point3* p = obj->mesh.verts+v_i;
		m_Vertices[v_i].set(p->x,p->y,p->z);
	}

	// set smooth group MAX type
	m_Flags.set(flSGMask,TRUE);

	// faces
	m_FaceCount		= obj->mesh.getNumFaces();
	m_Faces			= xr_alloc<st_Face>	(m_FaceCount);
	m_SmoothGroups	= xr_alloc<u32>		(m_FaceCount);

	m_VMRefs.reserve(m_FaceCount*3);
	if (0==obj->mesh.mapFaces(1))
	{
		bResult = false;
		ELog.Msg(mtError,"'%s' hasn't UV mapping!", node->GetName());
	}
	if (bResult)
	{
		CSurface* surf=0;
		for (int f_i=0; f_i<m_FaceCount; ++f_i)
		{
			Face*	vf = obj->mesh.faces+f_i;
			TVFace* tf = obj->mesh.mapFaces(1) + f_i;
			if (!tf)
			{
				bResult = false;
				ELog.Msg(mtError,"'%s' hasn't UV mapping!", node->GetName());
				break;
			}
			m_SmoothGroups[f_i]					= vf->getSmGroup();
			for (int k=0; k<3; ++k)
			{
				m_Faces[f_i].pv[k].pindex = vf->v[k];
				m_VMRefs.push_back(st_VMapPtLst());
				st_VMapPtLst&	vm_lst = m_VMRefs.back();
				vm_lst.count	= 1;
				vm_lst.pts		= xr_alloc<st_VMapPt>(vm_lst.count);
				for (DWORD vm_i=0; vm_i<vm_lst.count; ++vm_i)
				{
					vm_lst.pts[vm_i].vmap_index	= 0;
					vm_lst.pts[vm_i].index 		= tf->t[k];
				}
				m_Faces[f_i].pv[k].vmref	= m_VMRefs.size()-1;
				if (!bResult) break;
			}
			if (pMtlMain)
			{
				int m_id = obj->mesh.getFaceMtlIndex(f_i);
				if (cSubMaterials == 1)
				{
					m_id = 0;
				}else
				{
					// SDK recommends mod'ing the material ID by the valid # of materials, 
					// as sometimes a material number that's too high is returned.
					m_id %= cSubMaterials;
				}
				surf = m_Parent->CreateSurface(pMtlMain,m_id);
				if (!surf) bResult = false;
			}
			if (!bResult) break;
			m_SurfFaces[surf].push_back(f_i);
		}
	}

	// vmaps
	if( bResult ){
		int vm_cnt = obj->mesh.getNumTVerts();
		m_VMaps.resize(1);
		st_VMap*& VM = m_VMaps.back();
		VM = xr_new<st_VMap>("Texture",vmtUV,false);
		for (int tx_i=0; tx_i<vm_cnt; tx_i++){
			UVVert* tv = obj->mesh.tVerts + tx_i;
			VM->appendUV(tv->x,1-tv->y);
		}
	}

	if ((GetVertexCount()<4)||(GetFaceCount()<2))
	{
		ELog.Msg(mtError,"Invalid mesh: '%s'. Faces<2 or Verts<4");
		bResult = false;
	}

	if (bResult ){
		ELog.Msg(mtInformation,"Model '%s' contains: %d points, %d faces",
			node->GetName(), m_VertCount, m_FaceCount);
	}

	if (bResult)
	{
		RecomputeBBox	();
		OptimizeMesh	(false);
		RebuildVMaps	();
		ELog.Msg(mtInformation,"Model '%s' converted: %d points, %d faces",
			node->GetName(), GetVertexCount(), GetFaceCount());
	}

	if (bDeleteObj) delete (obj);
	return bResult;
}
Exemplo n.º 6
0
bool CEditableMesh::Convert(CExporter* E)
{
	bool bResult		= true;

	m_Name				= E->m_MeshNode->GetName();

	// maps
	// Weight maps 
	m_VMaps.resize(E->m_Bones.size()+1);
	for (DWORD b_i=0; b_i<E->m_Bones.size(); b_i++)
		m_VMaps[b_i]	= xr_new<st_VMap>(E->m_Bones[b_i]->name.c_str(),vmtWeight,false);;
	// UV map
	int VM_UV_idx		= m_VMaps.size()-1;
	st_VMap*& VM_UV		= m_VMaps[VM_UV_idx];
	VM_UV				= xr_new<st_VMap>("texture",vmtUV,false);

	// points
	{
		m_VertCount		= E->m_ExpVertices.size();
		m_Vertices		= xr_alloc<Fvector>(m_VertCount);
		Fvector* p_it	= m_Vertices;

		for (ExpVertIt ev_it=E->m_ExpVertices.begin(); ev_it!=E->m_ExpVertices.end(); ev_it++,p_it++){
			p_it->set		((*ev_it)->P);
			VM_UV->appendUV	((*ev_it)->uv.x,(*ev_it)->uv.y);
		}
	}
	// faces 
	{
		// set smooth group MAX type
		m_Flags.set(flSGMask,TRUE);
		// reserve space for faces and references
		m_FaceCount		= E->m_ExpFaces.size();
		m_Faces			= xr_alloc<st_Face>	(m_FaceCount);
		m_SmoothGroups	= xr_alloc<u32>		(m_FaceCount);
		m_VMRefs.resize	(m_VertCount);

		int f_id=0;
		for (ExpFaceIt ef_it=E->m_ExpFaces.begin(); ef_it!=E->m_ExpFaces.end(); ef_it++,f_id++){
			// FACES
			m_SmoothGroups[f_id]	= (*ef_it)->sm_group;
			st_Face& F				= m_Faces[f_id];
			for (int k=0; k<3; ++k)
			{
				int v_idx			= (*ef_it)->v[k];
				st_FaceVert& vt		= F.pv[k];
				st_VERT* V			= E->m_ExpVertices[v_idx];
				vt.pindex			= v_idx;
				st_VMapPtLst& vm_lst= m_VMRefs[vt.pindex];
				vm_lst.count		= V->data.size()+1;
				vm_lst.pts			= xr_alloc<st_VMapPt>(vm_lst.count);
				vm_lst.pts[0].vmap_index= VM_UV_idx;
				vm_lst.pts[0].index 	= vt.pindex;
				for (VDIt vd_it=V->data.begin(); vd_it!=V->data.end(); vd_it++){
					DWORD idx		= vd_it-V->data.begin()+1;
					st_VMap* vm		= m_VMaps[vd_it->bone];
					vm->appendW		(vd_it->weight);
					vm_lst.pts[idx].vmap_index	= vd_it->bone;
					vm_lst.pts[idx].index 		= vm->size()-1;
				}
				vt.vmref			= vt.pindex;
			}
			CSurface* surf = m_Parent->CreateSurface(E->m_MtlMain,(*ef_it)->m_id);
			if (!surf){
				bResult = FALSE;
				break;
			}
			m_SurfFaces[surf].push_back(f_id);
		}
	}
	if ((GetVertexCount()<4)||(GetFaceCount()<2))
	{
		Log("!Invalid mesh: '%s'. Faces<2 or Verts<4",*Name());
		bResult = false;
	}
	if (bResult)
	{
		RecomputeBBox	();
		OptimizeMesh	(true);//false);
		RebuildVMaps	();
	}
	return bResult;
}