Esempio n. 1
0
//-------------------------------------------------------------------------
void MontanaRusa::build(){
     
	GLfloat intervaloToma = 2*2*M_PI/NQ;  // Hay que dar dos vueltas porque hay puntos con 2 valores
	
	Poligon *poli = new Poligon(new PV3D(),NP,tam);  // un polígono del tamaño y con los lados que queremos
    vector<PV3D*>* puntos= poli->getVertex();  
        
    for(int i=0;i<NQ;i++){  // Esto ocurre en cada "sección" del gusano
            GLfloat toma=intervaloToma*i;				// Este valor hace que a cada vuelta la "matriz" sea única
            
            PV3D* fderivate = fDerivate(toma);			// Se calculan los valores que ayudan al cálculo de los puntos
			PV3D* sderivate = sDerivate(toma);

			PV3D* Tt=fDerivate(toma); Tt->normalize();
            PV3D* Bt=fderivate->crossProduct(sderivate); Bt->normalize();
            PV3D* Nt=Bt->crossProduct(Tt);
            PV3D* Ct=function(toma);

			for(int j=0;j<NP;j++){									// Esto ocurre con cada uno de los vértices del polígono
                int numV=NP*i+j;
                PV3D* clon=puntos->at(j)->clone();					// Un clon del punto del polígono para trabajar
                PV3D* punto=clon->matrixProduct(Nt,Bt,Tt,Ct);
				vertex->at(numV)=punto;								// El punto recibe un identificador y siempre con sentido
                delete clon;  
            }

            //deletes de los objetos ya no necesarios
            delete sderivate;	delete fderivate;	delete Tt;
			delete Bt;			delete Nt;			delete Ct;

    }
    // Se construyen las caras

	for(int numFace=0;numFace<faces->size();numFace++){      //  |>Recorremos todas las caras en orden
        faces->at(numFace)= new Cara(4);
        vector<VerticeNormal*>* auxNormals= new vector<VerticeNormal*>(4);

		int a= (numFace) % (NP*NQ);
        int b= (nextVertex(numFace) )% (NP*NQ);		// Teniendo cuidado de cerrar bien el círculo
        int c= (nextVertex(numFace) +NP)% (NP*NQ);
        int d= (numFace+NP)% (NP*NQ);

        auxNormals->at(0)=new VerticeNormal(a,numFace);
        auxNormals->at(1)=new VerticeNormal(b,numFace);
        auxNormals->at(2)=new VerticeNormal(c,numFace);
        auxNormals->at(3)=new VerticeNormal(d,numFace);
        
        faces->at(numFace)->setIndicesVN(auxNormals); 
     }
	// Se hacen las normales

    for(int i=0;i<this->numFaces;i++){
            normals->at(i)= this->doVectorNormalNewell(faces->at(i));
    }
	
    delete poli;
	
}
Esempio n. 2
0
/**
 * Inserts a new vertex into the graph and labels it.
 * @param label the label for the vertex
 * @return a copy of the vertex that was inserted
 */
Vertex Graph::insertVertex(string label /* = "" */)
{
    Vertex vertex = nextVertex();
    graph.insert(make_pair(vertex, EdgeMap()));
    vertexLabels.insert(make_pair(vertex, label));
    return vertex;
}
Esempio n. 3
0
QgsRectangle QgsAbstractGeometry::calculateBoundingBox() const
{
  double xmin = std::numeric_limits<double>::max();
  double ymin = std::numeric_limits<double>::max();
  double xmax = -std::numeric_limits<double>::max();
  double ymax = -std::numeric_limits<double>::max();

  QgsVertexId id;
  QgsPointV2 vertex;
  double x, y;
  while ( nextVertex( id, vertex ) )
  {
    x = vertex.x();
    y = vertex.y();
    if ( x < xmin )
      xmin = x;
    if ( x > xmax )
      xmax = x;
    if ( y < ymin )
      ymin = y;
    if ( y > ymax )
      ymax = y;
  }

  return QgsRectangle( xmin, ymin, xmax, ymax );
}
int * Augmentation(){
	//int Pre[V]={-1};
	int i=0;
	int counter=0;
	for(i=0;i<V;i++)
	  Path[i]=-1;
	int* ptrPath;
	ptrPath=&Path[0];
//  	for(i=0;i<V;i++)
//   		printf("%d\t",*(ptrPath+i));
// 	printf("\n");
	Path[0]=Resource;
	nextVertex(Resource,ptrPath);
	
 	for(i=0;i<V;i++){
 		//printf("%d\t",*(ptrPath+i));
 		if(*(ptrPath+i)==Sink)
 			counter++;
 	}
 	if(counter==0){
 		printf("No Path Found!\n");
 		for(i=0;i<V;i++)
		  *(ptrPath+i)=-1;
 	}
	return ptrPath;
}
int * Augmentation() {
    //int Pre[V]={-1};
    int i=0;
    int counter=0;
    int* Explored = malloc(V*sizeof(int));
    for(i=0; i<V; i++) {
        Path[i]=-1;
        *(Explored+i)=-1;
    }
    int* ptrPath;
    ptrPath=&Path[0];
//  	for(i=0;i<V;i++)
//   		printf("%d\t",*(ptrPath+i));
// 	printf("\n");
    Path[0]=Resource;
    nextVertex(Resource,ptrPath,Explored);

    for(i=0; i<V; i++) {
        //printf("%d\t",*(ptrPath+i));
        if(*(ptrPath+i)==Sink)
            counter++;
    }
    if(counter==0) {
        printf("No Path Found!\n");
        for(i=0; i<V; i++)
            *(ptrPath+i)=-1;
    }
    else if(!ptrPath) {
        printf("error!");
        exit(1);
    }
    return ptrPath;
}
Esempio n. 6
0
/**
 * 深度遍历一个顶点(!!!只遍历一个顶点)
 * @param G       [description]
 * @param i       [遍历开始的顶点]
 * @param visited [存放已经遍历过的点(初始化为0)]
 */
void DFSVertex(MGraph G, int i, int *visited)
{
	
	printf("%c  ", G.vertexs[i]);
	visited[i] = 1;
	
	// 首先找到出发点的一个邻接顶点
	for(int w = firstVertex(G, i); w >= 0; w = nextVertex(G, i, w))
	{
		// 如果没有被访问,继续访问得到这个点的邻接点
		// 如果已经被访问过了,就跳过这个点搜索下一个点
		if(!visited[w])
			DFSVertex(G, w, visited);
	} 
}
Esempio n. 7
0
/**
 * 广度优先搜索(类似于树的层次遍历)
 * @param G [description]
 */
void BFSTraverse(MGraph G)
{
	/*
	 * 定义一个队列存储已经遍历过的节点,等待取出来作为下一次遍历的初始节点	
	 */ 
	int queue[MAX] = {0};
	int head = 0;
	int rear = 0;

	int visited[MAX];
	for(int i = 0; i < G.vertexNum; i++)
	{
		visited[i] = 0;
	}

	printf("BFS: ");
	// 遍历全部节点,每一次选取一个节点作为广度搜索的初始节点
	for(int i = 0; i < G.vertexNum; i++)
	{
		if(!visited[i])
		{
			visited[i] = 1;
			printf("%c  ", G.vertexs[i]);
			
			// 将未发现的节点入队
			queue[rear++] = i;
		}

		while(head != rear)
		{
			// 取出遍历过的节点作为出发节点
			int j = queue[head++];
			for(int k = firstVertex(G, j); k >= 0; k = nextVertex(G, j, k))
			{
				if(!visited[k])
				{
					visited[k] = 1;
					printf("%c  ", G.vertexs[k]);
					queue[rear++] = k;
				}
			}

		}
	}
	printf("\n");
}
int nextVertex(int u, int* Path){
	int i,j,k,jump;
	int y=0;
	
	//printf("This is node %d\n",u);
	for(i=0;i<V;i++){
		jump=0;
		for(k=0;k<V;k++)
			if(*(Path+k)==i){
				jump=1;
				break;
			}
		if(jump==1)
			continue;
				//jump=1;
		if(Edge[u][i]>0){
			printf("Edge[%d][%d] is selected.\n",u,i);
			for(j=0;j<V;j++)
				if(*(Path+j)==u){
					*(Path+j+1)=i;
					printf("%d is added.\n",i);
					break;
				
				}
			if(i!=Sink){
				y=nextVertex(i,Path);	
				if(y==1)
					break;
			}
			else{
				y=1;
				break;	
			}
		}
		else if(i==V-1)
			for(j=0;j<V;j++)
				if(*(Path+j)==u){
					*(Path+j)=-1;
					printf("%d is deleted.\n",u);
				}
		
	}
	return y;		

}
int nextVertex(int u, int* ptrPath){
	int i,j,k,jump;
	int y=0;
	
	//printf("This is node %d (V=%d)\n",u,V);
	for(i=0;i<V;i++){
		//printf("i=%d",i);
		jump=0;
		for(k=0;k<V;k++)
			if(*(ptrPath+k)==i){
				jump=1;
				break;
			}
		if(jump==1&&i!=V-1)
			continue;
		else if(jump==1&&i==V-1){
		  for(j=0;j<V;j++)
			if(*(ptrPath+j)==u){
				*(ptrPath+j)=-1;
				break;
					//printf("%d is deleted from position %d.\n",u,j);
			}
		  continue;
		}
				//jump=1;
		if(Edge[u][i]>0){
			//printf("Edge[%d][%d] is selected (%lf).\n",u,i,Edge[u][i]);
			for(j=0;j<V;j++)
				if(*(ptrPath+j)==u){
					*(ptrPath+j+1)=i;
					//printf("%d is added to posistion %d. (Edge[%d][%d]=%lf)\n",i,j+1,u,i,Edge[u][i]);
					break;
				
				}
			if(i!=Sink){
				//printf("Search for the next node for %d.\n",i);
				y=nextVertex(i,ptrPath);	
				if(y==1){
				  //printf("Path has been found. (%d)\n",i);
					break;
				}
			}
			else{
				y=1;
				//printf("Path has been found. (%d)\n",i);
				break;	
			}
		}
		else if(V-1==i){
			//printf("All other nodes has been reached.\n");
			for(j=0;j<V;j++)
				if(*(ptrPath+j)==u){
					*(ptrPath+j)=-1;
					//printf("%d is deleted from position %d.\n",u,j);
				}
		}
// 		else if(V-1!=i)
// 		  printf("V=%d i=%d",V,i);
		
	}
	return y;		

}
Esempio n. 10
0
bool QgsAbstractGeometryV2::isEmpty() const
{
    QgsVertexId vId;
    QgsPointV2 vertex;
    return !nextVertex( vId, vertex );
}
int nextVertex(int u, int* ptrPath, int* Explored) {
    int i,j,k,jump;
    int y=0;
    int pre;

    //printf("This is node %d (V=%d)\n",u,V);
    for(i=0; i<V; i++) {
        //if(y==0)
        jump=0;
        pre=0;
        //suc=0;
        //jump=1;
        if(Edge[u][i]>0.00009&&u!=i) {
            for(k=0; k<V; k++) {
                if(*(ptrPath+k)==i||*(Explored+k)==i) {
                    jump=1;
                    //break;
                    //suc=k;
                }
                if(*(ptrPath+k)==u) {
                    pre=k;
                    //printf("(%d)%d at %d(%d)\n",i,u,pre,k);
                }
            }
            //printf("jump=%d when i=%d\n",jump,i);
            if(jump==1&&i!=V-1)
                continue;
            else if(jump==1&&i==V-1) {
//			  for(j=0;j<V;j++)
                *(ptrPath+pre)=-1;
// 				if(*(ptrPath+j)==u){
                //*(ptrPath+j)=-1;//
                //printf("1. %d is deleted from position %d.\n",u,pre);
// 					break;
//
// 				}
                continue;
            }
            //printf("Edge[%d][%d] is selected (%lf).\n",u,i,Edge[u][i]);
// 			for(j=0;j<V;j++)
// 			  if(*(Explored+j)==i)

            *(ptrPath+(pre+1))=i;
// 				if(*(ptrPath+j)==u){
// 					*(ptrPath+j+1)=i;
            //printf("%d is added to posistion %d. (Edge[%d][%d]=%lf)\n",i,pre+1,u,i,Edge[u][i]);
// 					break;
//
// 				}
            if(i!=Sink) {
                //printf("Search for the next node for %d.\n",i);
                y=nextVertex(i,ptrPath,Explored);
                //printf("stop before hrer");
                if(y==1) {
                    //printf("Path has been found. (%d)\n",i);
                    break;
                }
                else {
                    for(j=0; j<V; j++)
                        if(*(Explored+j)==-1) {
                            *(Explored+j)=i;
                            break;
                        }
                }
            }
            else {
                y=1;
                //printf("Path has been found. (%d)\n",i);
                break;
            }
        }
        else if(V-1==i) {
            //printf("All other nodes has been reached.\n");
            for(j=0; j<V; j++)
                if(*(ptrPath+j)==u) {
                    *(ptrPath+j)=-1;
                    //printf("2. %d is deleted from position %d.\n",u,j);
                }
        }
//  		else if(V-1!=i)
// 		  printf("V=%d i=%d",V,i);

    }
    return y;

}