int main()
{
	Init_Buffer();
	int test = 12;
	int MyTestArray[50] = { 30 };
	test = Send_Message(MyTestArray,19);
	Send_Done();
	
	Deque();

    return 0;
}
Esempio n. 2
0
int DecDCTvlc(u_short *mdec_bs,u_short *mdec_rl)
{
//	u_short *mdec_bs = mdecbs,*mdec_rl = mdecrl
	u_short *rl_end;
	u_long bitbuf;
	int incnt; /* 16-有効bit数 x86=char risc = long */
	int q_code;
	int type,n;
	int last_dc[3];

/* BS_HDR  u_short rlsize,magic,ver,q_scale */

	//printf("%04x,%04x,",mdec_bs[0],mdec_bs[1]);
	*(long*)mdec_rl=*(long*)mdec_bs;
	mdec_rl+=2;
	rl_end = mdec_rl+(int)mdec_bs[0]*2;
	q_code = (mdec_bs[2]<<10); /* code = q */
	type = mdec_bs[3];
	mdec_bs+=4;

	Init_Buffer();

	n = 0;
	last_dc[0]=last_dc[1]=last_dc[2] = 0;
	while(mdec_rl<rl_end) {
	  u_long code2;
		/* DC */
	  if (type==2) {
		code2 = Show_Bits(10)|(10<<16); /* DC code */
	  } else {
		code2 = Show_Bits(6);
		if (n>=2) {
			/* Y */
			if (code2<48) {
				code2 = DC_Ytab0[code2];
				code2 = (code2&0xffff0000)|((last_dc[2]+=VALOF(code2)*4)&0x3ff);
			} else {
				int nbit,val;
				int bit = 3;
				while(Show_Bits(bit)&1) { bit++;}
				bit++;
				nbit = bit*2-1;
				val = Show_Bits(nbit)&((1<<bit)-1);
				if ((val&(1<<(bit-1)))==0)
					val -= (1<<bit)-1;
				val = (last_dc[2]+=val*4);
				code2 = (nbit<<16) | (val&0x3ff);
			}
			//printf("%d ",last_dc[2]);
		} else {
			/* U,V */
			if (code2<56) {
				code2 = DC_UVtab0[code2];
				code2 = (code2&0xffff0000)|((last_dc[n]+=VALOF(code2)*4)&0x3ff);
			} else {
				int nbit,val;
				int bit = 4;
				while(Show_Bits(bit)&1) { bit++;}
				nbit = bit*2;
				val = Show_Bits(nbit)&((1<<bit)-1);
				if ((val&(1<<(bit-1)))==0)
					val -= (1<<bit)-1;
				val = (last_dc[n]+=val*4);
				code2 = (nbit<<16) | (val&0x3ff);
			}
			//printf("%d ",last_dc[n]);
		}
		if (++n==6) n=0;
	  }
	//	printf("%d ",VALOF(code2));
	  code2 |= q_code;

		/* AC */
	  for(;;){
//		u_long code;
#define	code code2
#define	SBIT	17
		*mdec_rl++=code2;
		Flush_Buffer(BITOF(code2));
		code = Show_Bits(SBIT);
		if      (code>=1<<(SBIT- 2)) {
			code2 = VLCtabnext[(code>>12)-8];
			if (code2==EOB_CODE) break;
		}
		else if (code>=1<<(SBIT- 6)) {
			code2 = VLCtab0[(code>>8)-8];
			if (code2==ESCAPE_CODE) {
				Flush_Buffer(6); /* ESCAPE len */
				code2 = Show_Bits(16)| (16<<16);
			}
		}
Esempio n. 3
0
/*
FbxMesh pMesh : the original mesh load from fbx file
FbxScene pScene : the FbxScene load from fbx file
float threshold :
*/
void GenerateLOD::Reduction_EdgesCollapse_UV(FbxNode *node, FbxMesh *pMesh, FbxManager *pManager, FbxScene *pScene)
{
	// Clear the ralated data structure
	(*ControlP).clear();
	(*Triangles).clear();
	(*Edges).clear();
	(*CostToEdge).clear();
	// Clear the HeapCost
	while (!HeapCost->empty())
		HeapCost->pop();

	FbxVector4 *pControlPoints = pMesh->GetControlPoints();
	int AddTriangleIndex = pMesh->GetPolygonCount();
	int AddEdgeIndex = pMesh->GetMeshEdgeCount();

	int threshold_1 = static_cast<int>(AddTriangleIndex * model_1.GetReductionRate());
	int threshold_2 = static_cast<int>(AddTriangleIndex * model_2.GetReductionRate());
	int threshold_3 = static_cast<int>(AddTriangleIndex * model_3.GetReductionRate());

	double start = GetTickCount();
	//# Init the ditc of (*Triangles) and the dict of (*ControlP)
	Init_Triangles_And_ControlP_EdgeCollapse(pMesh, pControlPoints);/////////////////////////////

	//Before Reduction, Now Init the Original VertexBuffer
	Init_Buffer(pMesh, model_0);

	//# Init the ditc of (*Edges)
	InitEdges(pMesh); //////////////////////////////////

					  // Now, Simplify Iterator
	int Ring = 0;
	bool flag1 = true;
	bool flag2 = true;
	while (true) {
		int idx;
		if (0 == HeapCost->size())
			idx = -1;
		else {
			//First Get the top element, namely the minmum cost
			//Second pop the minmum cost from HeapCost
			FbxDouble PopCost = HeapCost->top();
			HeapCost->pop();
			if (0 == (*CostToEdge)[PopCost].size())
				continue;
			idx = (*CostToEdge)[PopCost][0];
		}

		//int idx = GetMinEdgeCost();
		if (-1 == idx) {
			MessageBox(NULL,
				"When execute Simplification, there has No any edges should be collapse.",
				"The title", 0);
			break;
		}

		// Execute the current Edge Collapse and Update the (*ControlP), (*Triangles), (*Edges).
		CollapseEdge_And_UpdateCost(idx, pControlPoints, AddTriangleIndex, AddEdgeIndex);

		Ring += 1;

		if (flag1 && (int)(*Triangles).size() < threshold_1) {
			// After Reduction, Now Init Reduction VertexBuffer
			Init_Buffer(pMesh, model_1);
			model = model_1;

			FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene);
			// Update the Node Atrribute
			node->RemoveNodeAttribute(pMesh);
			node->SetNodeAttribute(newMesh);
			// Export new Mesh
			std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_1.GetReductionRate() * 100)) + "%)" + ".FBX";
			saveScene(tmp.c_str(), pManager, pScene, true);

			node->RemoveNodeAttribute(newMesh);
			node->SetNodeAttribute(pMesh);
			flag1 = false;
		}

		if (flag2 && (int)(*Triangles).size() < threshold_2) {
			// After Reduction, Now Init Reduction VertexBuffer
			Init_Buffer(pMesh, model_2);

			FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene);
			// Update the Node Atrribute
			node->RemoveNodeAttribute(pMesh);
			node->SetNodeAttribute(newMesh);
			// Export new Mesh
			std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_2.GetReductionRate() * 100)) + "%)" + ".FBX";
			saveScene(tmp.c_str(), pManager, pScene, true);

			node->RemoveNodeAttribute(newMesh);
			node->SetNodeAttribute(pMesh);
			flag2 = false;
		}

		if ((int)(*Triangles).size() < threshold_3) {
			// After Reduction, Now Init Reduction VertexBuffer
			Init_Buffer(pMesh, model_3);

			FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene);
			// Update the Node Atrribute
			node->RemoveNodeAttribute(pMesh);
			node->SetNodeAttribute(newMesh);
			// Export new Mesh
			std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_3.GetReductionRate() * 100)) + "%)" + ".FBX";
			saveScene(tmp.c_str(), pManager, pScene, true);

			node->RemoveNodeAttribute(newMesh);
			node->SetNodeAttribute(pMesh);
			break;
		}
	}
}