int main()
{
    int i,queueSize;
    PriorityQueue myQueue,a;
    int exit, val, priority, cap,x,*arr;
    char command;
         
    exit = FALSE;
        
    while (!exit)
    {
          fflush(stdin);
          printf("Menu:\n\n\ti)nitialize\n\tm)ake empty queue\n\tn)ew element\n\te)xit\n\nEnter command:");
          scanf("%c", &command);  
          fflush(stdin);
               
          switch(command) 
          {       
                  case 'i':
                  printf("\nEnter the capacity: ");
                       scanf("%d",&cap);
                       myQueue = InitializePriorityQueue (cap);
                       break;
                  case 'b':
                   
                       arr=(int *) malloc (sizeof (int) * cap);
                       for(i=0;i<cap;i++)
                          {
                             scanf("%d",&arr[i]);
                          }
                       a=BuildPriorityQueue(cap,arr);
                       system("pause");
                       break;
                  case 'n':
                       printf("\nEnter a number: ");
                       scanf("%d",&val);
                       InsertPriorityQueue(val, myQueue);
                       break;
                       
                       
                       
                  case 'e':
                       exit = TRUE;
                       break;       
                       
                  default:
                       printf("command not recognized\n");
                       break;
          }
          
          DisplayPriorityQueue (myQueue);
          
                  
    }
    printf("\n\n");              
    system("PAUSE");	
    return 0;
}
Beispiel #2
0
	bool MeshDecimator::Decimate(size_t targetNVertices, size_t targetNTriangles, double targetError)
	{
		double qem = 0.0;
		double progressOld = -1.0;
		double progress = 0.0;    
		char msg[1024];
		double ptgStep = 1.0;

		if (m_callBack)
		{
			std::ostringstream msg;
			msg << "+ Mesh" << std::endl;
			msg << "\t # vertices                     \t" << m_nPoints << std::endl;
			msg << "\t # triangles                    \t" << m_nTriangles << std::endl;
			msg << "+ Parameters" << std::endl;
			msg << "\t target # of vertices           \t" << targetNVertices << std::endl;
			msg << "\t target # of triangles          \t" << targetNTriangles << std::endl;
			msg << "\t QEM			                  \t" << targetError << std::endl;
			(*m_callBack)(msg.str().c_str(), 0.0, 0.0, m_nPoints);
		}
		
		if (m_callBack) (*m_callBack)("+ Initialize QEM \n", 0.0, 0.0, m_nPoints);
		InitializeQEM();
		if (m_callBack) (*m_callBack)("+ Initialize priority queue \n", 0.0, 0.0, m_nPoints);
		InitializePriorityQueue();
		if (m_callBack) (*m_callBack)("+ Simplification \n", 0.0, 0.0, m_nPoints);
		double invDiag2 = 1.0 / (m_diagBB * m_diagBB);
		while((m_pqueue.size() > 0) && 
			  (m_nEdges > 0) && 
			  (m_nVertices > targetNVertices) &&
			  (m_nTriangles > targetNTriangles) &&
			  (qem < targetError))
		{
			progress = 100.0 - m_nVertices * 100.0 / m_nPoints;
			if (fabs(progress-progressOld) > ptgStep && m_callBack)
			{
				sprintf(msg, "%3.2f %% V = %lu \t QEM = %f \t \t \r", progress, static_cast<unsigned long>(m_nVertices), sqrt(qem));
				(*m_callBack)(msg, progress, qem, m_nVertices);
				progressOld = progress;
			}
			if (!EdgeCollapse(qem)) break;
			qem *= invDiag2;
		}
		if (m_callBack)
		{
			std::ostringstream msg;
			msg << "+ Simplification output" << std::endl;
			msg << "\t # vertices                     \t" << m_nVertices << std::endl;
			msg << "\t # triangles                    \t" << m_nTriangles << std::endl;
			msg << "\t QEM					          \t" << qem << std::endl;
			(*m_callBack)(msg.str().c_str(), 100.0, qem, m_nVertices);
		}
		return true;
	}