Example #1
0
int main(int argc, char** argv)
{
	//OpenMesh::IO::Options r_options, w_options; 
	//string tmeshfile = "C:\\Users\\duan_qi\\Desktop\\Reconstruction\\PhotoSynthToolkit11\\templeRing\\pmvs\\models\\pmvs_options.txt.ply";
	//string fmeshfile = "C:\\Users\\duan_qi\\Desktop\\Reconstruction\\PhotoSynthToolkit11\\templeRing\\pmvs\\models\\pmvs_options.txt.filtered.off";
	//r_options.set(OpenMesh::IO::Options::VertexColor); w_options.set(OpenMesh::IO::Options::VertexColor);
	//OpenMesh::IO::read_mesh(ObjTriMesh, tmeshfile, r_options);
	//if ( !r_options.check( OpenMesh::IO::Options::VertexColor ) ) {
	//	cout << "Color is not loaded.." << endl;
	//}
	//int rcount = 0;
	//for (MyMesh::VertexIter v_it = ObjTriMesh.vertices_begin(); v_it != ObjTriMesh.vertices_end(); ++ v_it) {
	//	OpenMesh::Vec3f tColor;
	//	tColor[0] = ObjTriMesh.color(v_it).data()[0];
	//	tColor[1] = ObjTriMesh.color(v_it).data()[1];
	//	tColor[2] = ObjTriMesh.color(v_it).data()[2];
	//	if (tColor.norm() < 40) {
	//		ObjTriMesh.delete_vertex(v_it, false);
	//		rcount ++;
	//	}
	//}
	//ObjTriMesh.garbage_collection();
	//OpenMesh::IO::write_mesh(ObjTriMesh, fmeshfile, w_options);

	ParseParam(argc,argv, MOptions);
	ScaleDelta = MOptions.ScaleDelta;
	AnisotropicLaplace = MOptions.AnisotropicLaplace;
	RecordColor = MOptions.RecordColor;
	if (MOptions.UseMatlabSolver) {
		cout << "Use matlab solver for linear equations." << endl;
		if (!(m_ep = engOpen("\0"))) {
			std::cout << "Can not start Matlab engine" << std::endl;
			return false;
		}
		engSetVisible(m_ep, false);
	}
	ScaleDelta?cout<<"Scale delta P each time. ":cout<<" "; AnisotropicLaplace?cout<<"Using anisotropic laplacian term.":cout<<" "; 
	RecordColor?cout<<"Record vertex color to mesh. ":cout<<" "; cout << endl;
	path = MOptions.DirName;
	printf("Number of threads %d\n",omp_get_num_procs());
	omp_set_num_threads(omp_get_num_procs());
	omp_set_num_threads(8);
	double timer_start = (double)cv::getTickCount();
	if (!FileExisted( (MOptions.DirName + "InitialPoissonModel.ply").c_str() )) {
		if (!LoadMVSResult()) 
		{
			readMiddleBuryData2(MOptions.DirName);
			chooseStereoPairs();	

			stereoMatching();
			printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)/cv::getTickFrequency());

			buildTracks();
			printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)/cv::getTickFrequency());

			//writeToOBJ();
			//printf("\nTime = %lfs\n",((double)getTickCount()-timer_start)/getTickFrequency());

			calNormals();
			printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)/cv::getTickFrequency());

			verifyTracks();
			printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)/cv::getTickFrequency());
			
			SaveMVSResult();
		}
		writeToNPTS2(tracks,(MOptions.DirName + "PointInfo.npts"));
		//outputVerticesWithNormals(tracks,(MOptions.DirName + "PointModel.ply"));
		printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)/cv::getTickFrequency());
		//printf("\nTime = %lfs\n",((double)cv::getTickCount()-timer_start)w/cv::getTickFrequency());
		string PlyModelName = MOptions.DirName + "PoissonModel";
		PoissonReconstruction((MOptions.DirName + "PointInfo.npts"), PlyModelName);
		MyCopyFile(PlyModelName, (MOptions.DirName + "InitialPoissonModel.ply"));
	}

	readMiddleBuryData2(MOptions.DirName);

	//read the initial generated Poisson object model
	OpenMesh::IO::Options read_options, write_options;

	string ObjName = MOptions.DirName; 
	if (ObjName.find_last_of("\\") == ObjName.length()-1) {
		ObjName.erase(ObjName.end()-1);
	} 
	ObjName = ObjName.substr(ObjName.find_last_of("\\")+1, ObjName.length());   MOptions.meshname = ObjName;
	string meshfile = (MOptions.DirName + ObjName +"-remeshed.off");
	if (!FileExisted(meshfile.c_str())) {
		string cmd = "meshfix.exe "; cmd += MOptions.DirName + "InitialPoissonModel.ply";
		WinExec(cmd.c_str(),0);
		::Sleep(5000);
		MyMoveFile(MOptions.DirName + "InitialPoissonModel_fixed.off", MOptions.DirName + "temp.off");
		for (int i = 0; i < 5; ++ i) {
			cmd = "meshfix.exe "; cmd += MOptions.DirName + "temp.off";
			WinExec(cmd.c_str(),0);
			::Sleep(5000);
			MyMoveFile(MOptions.DirName + "temp_fixed.off", MOptions.DirName + "temp.off");
		}
		MyMoveFile(MOptions.DirName + "temp.off", meshfile);
	}
	fstream fin(meshfile,ios::in); string tag, temp_str;
	fin>>tag; fin>>temp_str;
	if (temp_str[0] == '#') {
		// need to load and rewrite the off file
		char buffer[100];
		fin.getline(buffer, 100);	fin.getline(buffer, 100);
		fstream fout(meshfile+"tmp",ios::out);
		int vnum, trinum, flag; double x, y, z; int a1, v0, v1, v2;
		fout<<tag<<endl;
		fin>>vnum>>trinum>>flag; fout<<vnum<<" "<<trinum<<" "<<flag<<endl;
		for (int i = 0; i < vnum; ++ i) {
			fin>>x>>y>>z; fout<<x<<" "<<y<<" "<<z<<endl;
		}
		for (int i = 0; i < trinum; ++i) {
			fin>>a1>>v0>>v1>>v2; fout<<a1<<" "<<v0<<" "<<v1<<" "<<v2<<endl;
		}
		fout.close();
		MyMoveFile(meshfile+"tmp", meshfile);
	} fin.close();
Example #2
0
DWORD
WINAPI
WorkingThread (
			   void* pParam
			   )
{
	HRESULT hResult = S_OK;
	PVOID pClientContext = pParam;

	PVOID pMessage;
	PMKLIF_EVENT_HDR pEventHdr;
	ULONG MessageSize;
	MKLIF_REPLY_EVENT Verdict;

	
	hResult = MKL_BuildMultipleWait( pClientContext, 1 );
	
	if ( SUCCEEDED( hResult ) )
	while(TRUE)
	{

		hResult = MKL_GetSingleMessage( pClientContext, &pMessage, &MessageSize, &pEventHdr, 1000, &gbStop );

		if (!SUCCEEDED( hResult) )
		{
			MessageBoxW( NULL, L"MKL_GetSingleMessage", L"Error", MB_OK );
			break;
		}
		else
		{
			
			PWCHAR wcFullFileName = NULL;
			PWCHAR wcVirtFullFileName = NULL;
			__try
			{
				WCHAR VolumeDosName[4], VirtVolumeDosName[4];
				ULONG wcFileNameSize = 0;
				ULONG wcFullFileNameSize = 0;
				ULONG wcVirtFileNameSize = 0;
				ULONG wcVirtFullFileNameSize = 0;

				//DebugBreak();
				memset( &Verdict, 0, sizeof(Verdict) );
				Verdict.m_VerdictFlags = efVerdict_Pending;
				Verdict.m_ExpTime = 3600;

				PSINGLE_PARAM pFileName = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_URL_W, FALSE );
				PSINGLE_PARAM pVolumeName = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_VOLUME_NAME_W, FALSE );

				PSINGLE_PARAM pVirtFileName = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_URL_DEST_W, FALSE );
				PSINGLE_PARAM pVirtVolumeName = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_VOLUME_NAME_DEST_W, FALSE );

				PSINGLE_PARAM pParamSID = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_SID, FALSE );

				PSINGLE_PARAM pAction = MKL_GetEventParam( pMessage, MessageSize, _PARAM_OBJECT_ACCESSATTR, FALSE );

				hResult = MKL_ReplyMessage( pClientContext, pMessage, &Verdict );

				Verdict.m_VerdictFlags = efVerdict_Default;
				Verdict.m_ExpTime = 0;

				if ( pVolumeName )
				{


					hResult = MKL_GetVolumeName(pClientContext,
						(PWCHAR) pVolumeName->ParamValue,
						VolumeDosName,
						sizeof(VolumeDosName) / sizeof(WCHAR));

					if ( IS_ERROR( hResult ) )
					{
						MessageBoxW( NULL, L"MKL_GetVolumeName  - pVolumeName", L"Error", MB_OK );
						__leave;
					}


				}



				if ( pVirtVolumeName )
				{
					hResult = MKL_GetVolumeName(pClientContext,
						(PWCHAR) pVirtVolumeName->ParamValue,
						VirtVolumeDosName,
						sizeof(VirtVolumeDosName) / sizeof(WCHAR));
					if ( IS_ERROR( hResult ) )
					{
						MessageBoxW( NULL, L"MKL_GetVolumeName  - pVirtVolumeName", L"Error", MB_OK );
						__leave;
					}
				}



				wcFileNameSize = pFileName->ParamSize - pVolumeName->ParamSize;
				wcFullFileNameSize = sizeof(VolumeDosName) + wcFileNameSize + sizeof(WCHAR);

				wcFullFileName = (WCHAR *) new char [ wcFullFileNameSize ]; 
				
				if ( !wcFullFileName )
				{
					MessageBoxW( NULL, L"Allocate memory is Error", L"Error", MB_OK );
					__leave;
				}

				memset( wcFullFileName, 0, wcFullFileNameSize );
				wcsncat(wcFullFileName, VolumeDosName, (sizeof(VolumeDosName)-sizeof(WCHAR))/sizeof(WCHAR) );
				
 				wcsncat(
 					wcFullFileName, 
 					(WCHAR*)((char*)pFileName->ParamValue+pVolumeName->ParamSize - sizeof(WCHAR) ), 
 					(pFileName->ParamSize - pVolumeName->ParamSize)/sizeof(WCHAR)  );

				wcVirtFileNameSize = pVirtFileName->ParamSize - pVirtVolumeName->ParamSize;
				wcVirtFullFileNameSize = sizeof(VirtVolumeDosName) + wcVirtFileNameSize + sizeof(WCHAR);

				wcVirtFullFileName = (WCHAR *) new char [ wcVirtFullFileNameSize ]; 
				if ( !wcVirtFullFileName )
				{
					MessageBoxW( NULL, L"Allocate memory is Error", L"Error", MB_OK );
					__leave;
				}

				memset( wcVirtFullFileName, 0, wcVirtFullFileNameSize );
				wcsncat(wcVirtFullFileName, VirtVolumeDosName, (sizeof(VirtVolumeDosName)-sizeof(WCHAR))/sizeof(WCHAR) );
				wcsncat(
					wcVirtFullFileName, 
					(WCHAR*)((char*)pVirtFileName->ParamValue+pVirtVolumeName->ParamSize - sizeof(WCHAR) ), 
					(pVirtFileName->ParamSize - pVirtVolumeName->ParamSize)/sizeof(WCHAR)  );


				Verdict.m_ExpTime = 0;
				switch( *(VIRT_ACTION*)pAction->ParamValue )
				{

				case VA_MakeDir:
					Verdict.m_VerdictFlags = MyMakeDirectory( wcVirtFullFileName );
					break;

				case VA_CopyFile:
					Verdict.m_VerdictFlags = MyCopyFile( wcVirtFullFileName, wcFullFileName );
					break;

				default:

					break;
				}
			}
			__finally
			{
				if ( wcVirtFullFileName )
				{
					delete [] wcVirtFullFileName;
					wcVirtFullFileName = NULL;
				}
				
				if ( wcFullFileName )
				{
					delete [] wcFullFileName;
					wcVirtFullFileName = NULL;
				}
				
				MKL_SetVerdict(pClientContext, pMessage, &Verdict );
				MKL_FreeSingleMessage( pClientContext, &pMessage );
			}
			
		}
	}
	
// 	if ( pClientContext )
// 	{
// 		MKL_ChangeClientActiveStatus( pClientContext, FALSE );
// 		MKL_DelAllFilters( pClientContext );
// 		MKL_ClientUnregister( (PVOID*)&pClientContext );
// 
// 		pClientContext = NULL;
// 	}

	return 0;
}