Example #1
0
int main(int argc, char ** argv)
{
   if (argc < 4) UsageExit();

#ifdef WIN32
   // Windows requires this to start up the networking API
   WORD versionWanted = MAKEWORD(1, 1);
   WSADATA wsaData;
   (void) WSAStartup(versionWanted, &wsaData);
#else 
   // avoid SIGPIPE signals caused by sending on a closed socket
   signal(SIGPIPE, SIG_IGN);
#endif

   bool isSend = false;
        if (strcmp(argv[1], "send")    == 0) isSend = true;
   else if (strcmp(argv[1], "receive") != 0) UsageExit();

   const char * fileName = argv[2];

   ip_address ip = isSend ? GetHostByName(argv[3]) : 0;
   uint16 port = 0;
   const char * portColon = strchr(argv[3], ':');
   port = portColon ? atoi(portColon+1) : 0;
   if (port == 0) port = 9999;

   if (isSend) SendFile(ip, port, fileName);
          else ReceiveFile(port, fileName);

   printf("Exiting, bye!\n");
   return 0;
}
Example #2
0
int main(int argc, char *argv[])
{
    if (argc != 2)
	UsageExit();

    LoadFile(argv[1]);
    Initialize();

    XEvent ev;

    while (1) { // イベントループ
	XNextEvent(disp, &ev);

	switch (ev.type) {
	case Expose:
	    puts("recalc");
	    Recalculate();
	    puts ("redraw");
	    Redraw();
	    break;
	case KeyPress:
	    HandleKeyPress((XKeyEvent *) &ev);
	    break;
	default:
	    ;
	}
    }

    CleanUp();
}
Example #3
0
int
main (int argc,char **argv )
{
#ifdef _DEBUG
	printf("SIZE OF CELL: %d\n",sizeof(Cell));
	printf("SIZE OF EdiTCOmmitData: %d\n",sizeof(EditCommitAuxData));
	printf("SIZE OF RenderAuxData: %d\n",sizeof(RenderAuxData));
	printf("SIZE OF FBOOL: %d\n",sizeof(FBool));
	printf("SIZE OF BoolVector: %d\n",sizeof(BoolVector));
	printf("SIZE OF Chain<GIndex>: %d\n",sizeof(Chain<GIndex>));
	printf("SIZE OF std::map<unsigned int,unsigned int>: %d\n",sizeof(std::map<unsigned int,unsigned int>));
	printf("waste: %d\n",sizeof(FBool)*5+sizeof(BoolVector)*3+sizeof(Chain<GIndex>)+sizeof(std::map<unsigned int,unsigned int>));

	printf("SIZE OF Chain<GIndex>: %d\n",sizeof(Chain<GIndex>));
	printf("SIZE OF Chain<OFace>: %d\n",sizeof(Chain<OFace>));
	printf("SIZE OF Chain<OVertex>: %d\n",sizeof(Chain<OVertex>));
	printf("SIZE OF Chain<OVertex>::Chunk: %d\n",sizeof(Chain<OVertex>::Chunk));
	printf("SIZE OF CachePolicy: %d\n",sizeof(CachePolicy));
	printf("SIZE OF std::string: %d\n",sizeof(std::string));
	printf("SIZE OF vcgMesh: %d\n",sizeof(vcgMesh));
	printf("SIZE OF Impostor: %d\n",sizeof(Impostor));
#endif

 	
	std::vector<std::wstring>  refvecFiles;
	std::wstring        refcstrRootDirectory(L".");
	std::wstring        refcstrExtension(L"ply");
	bool                     bSearchSubdirectories = true;
                    
//	_CrtSetBreakAlloc(1281429);
	std::vector<std::string> files_to_load;
	struct stat buf;
	


{


	int c;
	int digit_optind = 0;
	unsigned int meshadded = 0,
        max_meshes = 1000 /*std::numeric_limits<unsigned int>::max()*/,
        min_meshes = 0,
        min_meshes_aln = 0,
        max_meshes_aln= 1000 /*std::numeric_limits<unsigned int>::max()*/,
        cache_memory_limit = 200,
        berkeley_page_size = 1024,
        side_factor = 50;

	std::string ocmename,tra_ma_file;
	bool logging  = false;
	bool save_impostors  = false;
	bool overwrite_database = false;
	bool transform = false;
	bool verify = false;
	bool only_vertices = false;
	bool compute_normals = false;
	bool all_plys = false;
	bool compute_stats = false;
	bool recompute_impostors = false;
    vcg::Matrix44f tra_ma;tra_ma.SetIdentity();

#ifdef _DEBUG
        printf("ocme builder DEBUG MODE\n");
#endif
	 

  std::string stat_file = std::string(""); 
  if(argc==1)
	  UsageExit();
  while (1)
    {
      int this_option_optind = optind ? optind : 1;

	  c = getopt (argc, argv, "IVFsqciosnvp:t:m:l:f:L:a:A:k:S:");
      if (c == EOF)
        break;

      switch (c)
        {
        case 'q':
          verify = true;
          break;
        case 'i':
          save_impostors = true;
          break;
        case 'I':
          recompute_impostors = true;
          break;
        case 'n':
          compute_normals = true;
          break;
        case 's':
          only_vertices = true;
          break;
        case 'V':
          compute_stats = true;
          break;
#ifdef _WIN32
		case 'F':
			all_plys = true;
			SearchDirectory(refvecFiles,refcstrRootDirectory,refcstrExtension,false);
			break;
#endif
        case 't':
          transform = true;
		  printf("filename %s\n",optarg );tra_ma_file = std::string(optarg);
		  LoadTraMa(tra_ma_file.c_str(),tra_ma);
          break;

        case 'S':
		  printf("filename %s\n",optarg );stat_file = std::string(optarg);
          break;

		case 'o':
          overwrite_database = true;
          break;
		case 'f':
		printf("filename %s\n",optarg );ocmename = std::string(optarg);
          break;

		case 'a':
		 min_meshes_aln = atoi(optarg);
          break;

		case 'k':
		 side_factor = atoi(optarg);
          break;

		case 'A':
		 max_meshes_aln = atoi(optarg);
          break;

		case 'l':
		 min_meshes = atoi(optarg);
          break;

		case 'L':
		 max_meshes = atoi(optarg);
          break;

		case 'm':
		  cache_memory_limit = 	atoi(optarg);
		  break;

		case 'p':
		  berkeley_page_size = 	atoi(optarg);
		  break;

		case 'v':
			logging = true;
		  break;

		default:
          printf("unknown parameter 0%o ??\n", c);
		  UsageExit();
        }
    }

 /* .................................. */
  Impostor::Gridsize()= 8;

  if(stat_file.empty()) 
	  stat_file = ocmename + std::string("_log.txt");
  
  lgn = new Logging(stat_file.c_str());
  lgn->Append("starting");
  lgn->Push();
  

   TIM::Begin(1);
   STAT::Begin(N_STAT);

 	meshona = new OCME();
	meshona->params.side_factor = side_factor;
 	meshona->oce.cache_policy->memory_limit  = cache_memory_limit * (1<<20);

	lgn->off = !logging;
	if(!verify && !compute_stats && !recompute_impostors){
 		meshona->streaming_mode = true;	


 		int start = clock();
 		int totalstart = start;

#ifdef SIMPLE_DB
    if(overwrite_database)
          meshona->Create((std::string(ocmename)).c_str(),berkeley_page_size);
    else
          meshona->Open((std::string(ocmename)+std::string(".socm")).c_str());
#else
    if(overwrite_database)
        meshona->Create((std::string(ocmename) +std::string(".kch") ).c_str(),berkeley_page_size);
    else
        meshona->Open((std::string(ocmename)+std::string(".kch")).c_str());
#endif

	  if(all_plys)
		  for(int i  = 0 ;  i < refvecFiles.size()  ;++i) 
			  files_to_load.push_back( std::string( refvecFiles[i].begin(),refvecFiles[i].end()));
	  else	
		  for(int i  = optind ; (i < argc) ;++i) 
			files_to_load.push_back(argv[i]);


		for(int i  = min_meshes; (i < files_to_load.size())&&  (i<max_meshes)&& !Interrupt();++i){
		
			unsigned int wh = std::string(files_to_load[i]).find(std::string(".aln"));

			if(wh == std::string(files_to_load[i]).length()-4)
			
			// it is an aln file
			{
				std::vector<std::pair<std::string,vcg::Matrix44f> > aln;
				LoadAln(files_to_load[i].c_str(),aln);

				printf("aln.size()  = %d\n",aln.size());
				for(unsigned int idm = min_meshes_aln; (idm<  std::min(max_meshes_aln,aln.size())) && !Interrupt();++idm){
									STAT::Reset();
									start = clock();
					vcgMesh m;
					stat(aln[idm].first.c_str(),&buf);

					++meshona->stat.n_files;
					meshona->stat.input_file_size+=buf.st_size;
					TIM::Begin(0);
					vcg::tri::io::ImporterPLY<vcgMesh>::Open(m,aln[idm].first.c_str());
					TIM::End(0);
					meshona->stat.n_triangles += m.fn;
					meshona->stat.n_vertices += m.fn;				

					printf("%d of %d in %f sec\n",idm,aln.size(),(clock()-start)/float(CLOCKS_PER_SEC));
					vcg::tri::UpdatePosition<vcgMesh>::Matrix(m,aln[idm].second);
					unsigned int newstart = clock();
					if(!m.face.empty()){

						if(only_vertices){
							if(compute_normals)
								vcg::tri::UpdateNormals<vcgMesh>::PerVertexPerFace(m);
							m.fn = 0;
						}	
						if(transform){
							sprintf(lgn->Buf(),"Apply transform" );
							lgn->Push();
							vcg::tri::UpdatePosition<vcgMesh>::Matrix(m,tra_ma);
						}
 		 				meshona->AddMesh(m);
						++meshadded;
					}
					printf("Sizeof meshona->oce %d\n", meshona->oce.SizeOfMem());
					samples.push_back(Sample( m.fn,(clock()-newstart)/float(CLOCKS_PER_SEC),meshona->cells.size(),
															  STAT::V(0),STAT::V(1),STAT::V(6),STAT::V(3),STAT::V(5)));
					PrintFacesSec();
				}
			}
			else
				// It is a ply file
			{

				STAT::Reset();
				start = clock();
 				vcgMesh m;
				unsigned long n_faces  =0;
	 
		
				sprintf(lgn->Buf(),"Adding mesh %s (%d of %d)..Loading",files_to_load[i].c_str(),i, files_to_load.size());
				lgn->Push();

				stat(files_to_load[i].c_str(),&buf);
				meshona->stat.input_file_size+=buf.st_size;
			 	if(buf.st_size < 100 * (1<<20))
				//	if(false)
				{// if the file is less that 50MB load the mesh in memory and then add it

					int mask = 0;

					TIM::Begin(0);

									
					AttributeMapper am;
					vcg::tri::io::ImporterPLY<vcgMesh>::LoadMask(files_to_load[i].c_str(),mask);

					if(mask & vcg::tri::io::Mask::IOM_VERTCOLOR){
						m.vert.EnableColor();
						am.vert_attrs.push_back("Color4b");
					}

					vcg::tri::io::ImporterPLY<vcgMesh>::Open(m,files_to_load[i].c_str(),cb);

					meshona->stat.n_triangles += m.fn;
					meshona->stat.n_vertices += m.vn;

					if(transform){
						sprintf(lgn->Buf(),"Apply transform" );
						lgn->Push();
						vcg::tri::UpdatePosition<vcgMesh>::Matrix(m,tra_ma);
	
//					vcg::tri::io::ExporterPLY<vcgMesh>::Save(m,std::string(argv[i]).append("T.ply").c_str());
					}
					TIM::End(0);	

					n_faces = m.fn;
					sprintf(lgn->Buf(),"loaded in %f seconds\n",(clock()-start)/float(CLOCKS_PER_SEC));
					lgn->Push();

					assert( MemDbg::CheckHeap(0));

					++meshona->stat.n_files;

					if(only_vertices){
						if(compute_normals) {
								vcg::tri::UpdateNormals<vcgMesh>::PerVertexPerFace(m);
								am.vert_attrs.push_back("Normal3f");
						}
							m.fn = 0;
						}	
					meshona->AddMesh(m,am);
					++meshadded;

					sprintf(lgn->Buf(),"#cells: %d \n", meshona->cells.size());
					lgn->Push();
				}
				else
				{
					TIM::Begin(2);
					// if the file is more that 50 MB build directly from file
					n_faces = vcg::tri::io::ImporterOCMPLY<vcgMesh>::Open(m,meshona,files_to_load[i].c_str(),tra_ma,true,cb);
					TIM::End(2);
				}
				
				sprintf(lgn->Buf(),"added in %f seconds\n",(clock()-start)/float(CLOCKS_PER_SEC));
							lgn->Push();
							samples.push_back(Sample( n_faces,(clock()-start)/float(CLOCKS_PER_SEC),meshona->cells.size(),
													  STAT::V(0),STAT::V(1),STAT::V(6),STAT::V(3),STAT::V(5)));
				PrintFacesSec();
							printf("accesses % d \n",STAT::V(N_ACCESSES));

			}

		}
			meshona->RemoveEmptyCells();
 			start = clock();
			printf("number of cells: %d \n number of chains %d\n",
				meshona->cells.size(),
				meshona->oce.chains.size());

			if(save_impostors){
				vcgMesh impostorMesh;
				vcg::tri::io::PlyInfo pi;
				pi.mask |=  vcg::tri::io::Mask::IOM_VERTCOLOR | vcg::tri::io::Mask::IOM_VERTNORMAL;
				impostorMesh.vert.EnableColor();
				meshona->ImpostorsToMesh(impostorMesh);
				vcg::tri::io::ExporterPLY<vcgMesh>::Save(impostorMesh,(std::string(ocmename)+std::string("_imp.ply")).c_str(),pi.mask);
			}

			meshona->Close(true);
			
			TIM::End(1);

			PrintFacesSec();

			printf("closed %ld seconds\n",(clock()-start)/CLOCKS_PER_SEC);
			printf("total %ld seconds\n",(clock()-totalstart)/CLOCKS_PER_SEC);
	//
			PrintStats();
}
else
{
#ifdef SIMPLE_DB
	meshona->Open(( ocmename+std::string(".socm")).c_str());
#else
        meshona->Open(( ocmename+std::string(".kch")).c_str());
#endif
	if(verify)
		meshona->Verify();
	if(compute_stats){
		meshona->ComputeStatistics();
		printf("tri: %d, ver %d]\n",meshona->stat.n_triangles,meshona->stat.n_vertices);
	}
	if(recompute_impostors)
		meshona->ComputeImpostors();
	meshona->Close(false);
}

		delete meshona;
}	
		
		samples.clear();


		MemDbg::End();
		MemDbg::DumpMemoryLeaks();
}
Example #4
0
/*******************************************************************************
 MAIN FUNCTION
*******************************************************************************/
int main(int ac, char **av)
{
	FILE *fp;
	int	fd;
	int  pid;

	int i, j, ln, err, kf, dRet;
	int init_only_one = 0;
	int verbose_flag = 0;

	char buf[BUF_SIZE];
	char fname[BUF_SIZE];
	char block_name[BUF_SIZE];
	char tmpbuf[128], errbuf[2048];

	signal(SIGHUP, SIG_IGN);
	signal(SIGCHLD, SIG_IGN);
	signal(SIGQUIT, init_isr);

	dRet = dGetUserPermission();
    if( dRet == 0 )
    {
        sprintf(errbuf, "INAVLID USER PERMISSION\n" );
        PrintOut(TIFB_FAIL, errbuf);

        return 1;
    }

	dRet = dGetBlocks(FILE_MC_INIT,STR_TSW_COM);
	if( dRet < 0 ){
        sprintf(errbuf, "FAILED IN McInit\n" );
        PrintOut(TIFB_FAIL, errbuf);

        return 1;

	}
	else{
		dCurrBlockCnt = dRet;
	}

	if( init_proc() < 0 ){
		exit(0);
	}

	if (ac == 1)	/*** ALL START ********************************************/
	{
		strcpy(fname, FILE_MC_INIT); /*** "McInit" File ****************************/
	}
	else if (ac > 3)
	{
		UsageExit();
	}
	else
	{
		for(i = 1;i < ac;i++)
		{
			if (av[i][0] != '-')
			{
				UsageExit();
			}
			else if(av[i][1] == 'b')
			{
				if( ac < 3 )
				{
					UsageExit();
				}
				else	/*** ONLY ONE BLOCK START *****************************/
				{
					++i;
					init_only_one = 1;
 					for(j = 0;j < strlen(av[i]);j++)
						block_name[j] = toupper(av[i][j]);
					block_name[j] = 0;
				}
			}
			else if( av[i][1] == 'v' )	/*** ALL START ************************/
			{
				verbose_flag = 1;
			}
			else if(av[i][1] == 'd') {

                /* FOR SYSTEM AUTO RESTART : WAIT BOOTTING COMPLETE */
                sleep(300);
                verbose_flag = 1;
            }
			else
			{
				UsageExit();
			}
		}
	}

 	//freopen("/dev/null", "w", stdout);

	/*** 한개 블럭을 기동 시킴 ************************************************/
	if (init_only_one)
	{
		pid = InitOnlyOneBlock(block_name);
        if(pid > 0)
        {
            sprintf(errbuf, "NEW BLOCK : %s\n  PROCESS ID: %d\n", block_name, pid);
            PrintOut(TIFB_SUCCESS, errbuf);

            for(i=0; i< dCurrBlockCnt; i++)
            {
				if( STR_TSW_COM[i] == NULL )
					continue;

                if( !strcasecmp(block_name, STR_TSW_COM[i]) )
                {
                    send_pid_msg(i, pid);
                    break;
                }
            }
        }
		exit(0);
	}

	/***************************************************************************
	 READ FIDB_FILE, SET SHARED MEMORY VALUE
	***************************************************************************/
	if ((fd = open (FILE_FIDB, O_RDONLY, 0666)) < 0)
    {
    }
	else
	{
		remove( FILE_FIDB );
	}

	strcpy(fname, FILE_MC_INIT);

	if((fp = fopen(fname, "r")) == NULL)
	{
		sprintf(errbuf, "CAN'T OPEN FILE %s\n", fname);
		PrintOut(TIFB_FAIL, errbuf);
		exit(1);
	}

	ln = cntr = 0;

	/***************************************************************************
	 READ McInit File. SET blocks(bname, fname) VALUE
	***************************************************************************/
	while(fgets(buf, BUF_SIZE, fp) != NULL)
	{
		ln++;
		if (AnalyzeLine(buf) < 0)
		{
			fclose(fp);
			close(fd);
			sprintf(errbuf, "SYNTAX ERROR (FILE: %s, LINE: %d)\n", fname, ln);
			PrintOut(TIFB_FAIL, errbuf);
			exit(1);
		}
	}

	fclose(fp);

	/***************************************************************************
	 WHEN ALL BLOCK IS STARTED, CHECK 2 TIMES
	***************************************************************************/
	if( verbose_flag == 0 )
	{
		fprintf(stderr, "\n\tBlocks to initialize are follows.\n");
		PrintBlocks();

		fprintf(stderr, "\tDo you want initialize (y/n) ? ");
		err = GetYorN();
		if(err == _NO)
		{
			sprintf(errbuf, "STOPPED BY USER REQUEST\n");
			PrintOut(TIFB_SUCCESS, errbuf);
			exit(0);
		}
		fprintf(stderr, "\n\tDo you really want initialize (y/n) ? ");
		err = GetYorN();
		if(err == _NO)
		{
			sprintf(errbuf, "STOPPED BY USER REQUEST\n");
			PrintOut(TIFB_SUCCESS, errbuf);
			exit(0);
		}
	}

    sprintf(errbuf, "MAIN COMPUTER PROCESSS INITIALIZATION STARTED\n");
	PrintOut( TIFB_SUCCESS , errbuf );

	signal(SIGINT, init_isr);


	/*** 프로세스 기동을 개시함 ***********************************************/
	for(i=0; i<cntr; i++)
	{
		/*** 파일의 존재 및 수행가능성 조사 ***********************************/
		if( IsCorrectBlock(i) < 0 )
		{
			if( verbose_flag == 1 )
			{
				continue;
			}
			else
			{
				sprintf(errbuf, "FILE %s DOES NOT EXIST\n", blocks[i].fname);

				PrintOut(TIFB_FAIL, errbuf);

				fprintf(stderr, "\n\tDo you want to continue (y/n) ? ");

				err = GetYorN();

				if(err == _YES)
				{
					inits[i].isinit = _FALSE;
					continue;
				}
				else
				{
					final_isr();
				}
			}
		}

		/*** 이미 실행중인지 여부를 검사 **************************************/
		if ( (pid = GetProcessID(blocks[i].bname)) > 0 )
		{
			/* 이미 실행중인 경우 */

			if( verbose_flag == 1 )
			{
				err = _YES ;
			}
			else
			{
				fprintf(stderr, "\n\tBlock \"%s\" is already running.\n", blocks[i].bname);
				fprintf(stderr, "\tDo you want replace block \"%s\" (y/n) ? ", blocks[i].bname);
				err = GetYorN();
			}

			if(err == _NO)
			{
				inits[i].isinit = _FALSE;
				continue;
			}
			else
			{
				/* New Version of Killing */
				kf = kill(pid, SIGTERM);

				if (kf < 0)
				{
					//sleep(2);
					if (kill(pid, SIGTERM) < 0)
					{
			   			if (errno == ESRCH)
			       			kf = 0;
			  		}
					else
					{
			   			kf = 0;
					}
			   	}

				if ( kf && kill(pid, SIGKILL) < 0)
				{
					if( verbose_flag == 1 )
					{
						err = _YES ;
					}
					else
					{
						fprintf(stderr, "\tCan't kill process \"%d\"(%s)\n", pid, blocks[i].bname);
						fprintf(stderr, "\tDo you want to continue (y/n) ? ");
						err = GetYorN();
					}


					if(err == _YES)
					{
						inits[i].isinit = _FALSE;
						continue;
					}
					else
					{
						final_isr();
					}
				}
				else
				{
					sprintf(errbuf, "PROCESS %s(PID=%d) KILLED\n", blocks[i].fname, pid);
					PrintOut(TIFB_SUCCESS, errbuf);
				}
			}
		}

		signal(SIGTERM, init_isr);

		/***********************************************************************
		 PROCESS START
		***********************************************************************/
		err = ProcessStart(i);

		if(err == -1)
		{

			if( verbose_flag == 1 )
			{
				continue;
			}
			else
			{
				sprintf(errbuf, "CAN'T START PROCESS BLOCK: %s\n", blocks[i].bname);
				PrintOut(TIFB_FAIL, errbuf);

				fprintf(stderr, "\tDo you want to continue (y/n) ? ");
			}
		}
		else if(err == -2)
		{
			if( verbose_flag == 1 )
			{
				continue;
			}
			else
			{
				sprintf(errbuf, "PROGRAM NAME %s DOES NOT MEET NAME CONVENTION\n", blocks[i].fname);
				strcat(errbuf, "  ABANDON EXECUTING PROCESS\n");
				PrintOut(TIFB_FAIL, errbuf);

				fprintf(stderr, "\tDo you want to continue (y/n) ? ");
			}
		}

		if(err < 0)
		{
			if( verbose_flag == 1 )
			{
				err = _YES;
			}
			else
			{
				err = GetYorN();
			}


			if(err == _NO)
			{
				final_isr();
			}
			else
			{
				inits[i].isinit = _FALSE;
				continue;
			}
		}
		else
		{
			sprintf(errbuf, "A PROCESS INIAILIZATION SUCCESS\n");
			sprintf(tmpbuf, "  BLOCK NAME   : %s\n", blocks[i].bname);
			strcat(errbuf, tmpbuf);
			sprintf(tmpbuf, "  PROGRAM NAME : %s\n", blocks[i].fname);
			strcat(errbuf, tmpbuf);
			sprintf(tmpbuf, "  PROCESS ID   : %d\n", err);
			strcat(errbuf, tmpbuf);

			PrintOut(TIFB_SUCCESS, errbuf);
			sleep(1);


			for(j=0; j< dCurrBlockCnt; j++)
			{
				if( STR_TSW_COM[i] == NULL )
					continue;

				if( !strcasecmp(blocks[i].bname, STR_TSW_COM[j]) )
				{
					send_pid_msg(j, err );
					break;
				}
			}

			inits[i].isinit = _TRUE;
			inits[i].pid = err;
		}
	}

	PrintSuccessBlocks();
	printf("UPRESTO co. GTAM\n\n");
	exit(1);
}