void getParam(pathNode * curr) { if(curr->next->next==NULL) { endofList = 1; return; } search(curr->id); searchEdge(foundNode,curr->next->id); printf("%d ID found in Vertex Node %d.\n",foundEdge -> id, curr ->id); res_params->turn = foundEdge->turn; res_params->timer = foundEdge->distance; }
void removeEdge(List *list, int edge) { Node *prev = NULL; Node *del = NULL; del = searchEdge(list->head, edge, &prev); if (del != NULL) { if(del == list->head) { list->head = del->next; } else if(prev != NULL) { prev->next = del->next; } free(del); } }
void deleteVertexNode ( vertexNode* nodeA) { vertexNode * iter = head; vertexNode * temp = head; if (nodeA == NULL) { return; } //printf("Head ID: %d\n",iter -> id); while (iter) { printf("ID: %d\n",iter -> id); if (iter == nodeA) { edgeNode * head = nodeA -> head; edgeNode *delNode; while(head -> next) { delNode = head -> next; head -> next = delNode -> next; free(delNode); //printf("NotReached\n"); } free(head); nodeA -> tail = NULL; } else { if (iter -> next == nodeA) { temp = iter; } searchEdge(iter,nodeA -> id); if (foundEdge) { printf("Searched Vertex Node %d\n",iter->id); deleteEdgeAtoB(iter, nodeA); } } iter = iter -> next; } temp -> next = nodeA -> next; free(nodeA); printf("Done.\n"); }
int newGraph(int N,int v){ int conex = TRUE; Grafo *newInst; newInst = malloc(sizeof(newInst)); newInst->graphList = createList(&N); if(v == 1) pointOutput(newInst->graphList, N); conex = searchEdge(newInst->graphList, N); free(newInst); return conex; }
bool ContourFinder::searchRow(int y, std::vector<MoveBall*>& balls, int numBalls) { //search in row for (int x=0;x<img->w;++x) { Vec2 currentPos=Vec2(x,y); ColorRgb pCol=img->getPixel(currentPos); bool allFound=true; for (int i=0; i<numBalls; i++) { ColorHsv ballOut = ColorHsv(balls[i]->ballOutColor); if (balls[i]->ballFound) continue; float sim=ballOut.similarity(ColorHsv(pCol)); if (sim>0) { balls[i]->ballPerceptedColor=ColorHsv(pCol); balls[i]->position=currentPos; // check if there is much similarity in the first 10 pixels for (int j=0; j<10; j++) { currentPos.x+=1; if (currentPos.x>=img->w) break; pCol=img->getPixel(currentPos); sim+=ballOut.similarity(ColorHsv(pCol)); } if (sim>400) { balls[i]->ballFound=true; searchEdge(balls[i]); continue; } } allFound=false; } if(allFound) return true; } return false; }
void ContourFinder::findBalls(std::vector<MoveBall*>& balls, int numBalls) { bool needToComb = false; for (int i=0; i<numBalls; i++) { // if the center of the previous ball is in the new ball, don't search for it if (balls[i]->ballFound && balls[i]->getMask(balls[i]->position)>BALL_MARGIN) { balls[i]->position.x--; // search the left contour searchEdge(balls[i]); } // if not, we need to comb the whole image else { balls[i]->ballFound=false; needToComb=true; } } // comb image if needed if (needToComb) { combImage(balls, numBalls); } for (int i=0; i<numBalls; i++) { if (balls[i]->ballFound) { // find the contour of each ball findContour((balls[i])); // if the contour is too small, discard it if (balls[i]->ballContour.size()<3) { balls[i]->ballFound=false; continue; } } } }
double lessConnectivity(int N){ int conex = TRUE; Grafo *newInst; double lessEdge = sqrt(2), maxFloor = 0, x = 1; newInst = malloc(sizeof(newInst)); newInst->graphList = createList(&N); while(x > 0.0021 ){ conex = searchEdge(newInst->graphList, N); resetFlag (newInst->graphList,N); if (conex == TRUE){ if (edge < lessEdge) lessEdge = edge; edge = edge*0.9; } else{ if (edge > maxFloor) maxFloor = edge; edge = edge*0.05 + edge; } x = lessEdge-maxFloor; } seed = (ceil(newInst->graphList[0].x*newInst->graphList[0].y*rand())); free(newInst); return lessEdge; }
void Octree::findIntersections(Evaluator* eval) { // If this is a leaf cell, check every edge and use binary search to // find intersections on edges that have mismatched signs if (type == LEAF) { for (auto e : cellEdges) { if (corner(e.first) != corner(e.second)) { if (corner(e.first)) { intersections.push_back( searchEdge(pos(e.first), pos(e.second), eval)); } else { intersections.push_back( searchEdge(pos(e.second), pos(e.first), eval)); } } } } // If this is a branch cell, then accumulate intersections from all the // children with the max rank (de-duplicating to avoid weighting // intersections incorrectly) else if (type == BRANCH) { // pts stores a list of unique points (within some epsilon) std::list<glm::vec3> pts; // Compute epsilon from the cell size and edge search count const float epsilon = std::max( {X.upper() - X.lower(), Y.upper() - Y.lower(), Z.upper() - Z.lower()}) / (4 << SEARCH_COUNT); // Find the max rank among children, then only accumulate // intersections from children with that rank const unsigned max_rank = std::accumulate( children.begin(), children.end(), (unsigned)0, [](const unsigned& a, const std::unique_ptr<Octree>& b) { return std::max(a, b->rank);} ); for (uint8_t i=0; i < 8; ++i) { if (child(i)->rank == max_rank) { for (auto n : child(i)->intersections) { // Only store this intersection point if it hasn't // been stored already (to a given epsilon of // floating-point error) if (!std::any_of(pts.begin(), pts.end(), [&](glm::vec3 p) { return glm::length(n.pos - p) < epsilon; })) { pts.push_back(n.pos); intersections.push_back(n); } } } } } }