void SweepContext::AddHole(std::vector<Point*> polyline) { InitEdges(polyline); for(unsigned int i = 0; i < polyline.size(); i++) { points_.push_back(polyline[i]); } }
SweepContext::SweepContext(std::vector<Point*> polyline) : front_(0), head_(0), tail_(0), af_head_(0), af_middle_(0), af_tail_(0) { basin = Basin(); edge_event = EdgeEvent(); points_ = polyline; InitEdges(points_); }
void ScanlineFill() { Matrix polygon; int boxLeft, boxRight, boxHigh, boxLow; int i,j,k; int edgeXat_i,lim_y_up,lim_y_down; Matrix xlist; AcceptPolygon(&polygon); InitGraph(); DrawPolygon(&polygon); InitEdges(&polygon); MinMax(&polygon,0,0,polygon.rows-1,&boxLeft,&boxRight); MinMax(&polygon,1,0,polygon.rows-1,&boxLow,&boxHigh); InitMatrix(&xlist,polygon.rows-1,1); for(i=boxLow+1,k=0;i<boxHigh;i++,k=0) { for(j=0;j<polygon.rows-1;j++) { if((int)polygon.matrix[j][0] == (int)polygon.matrix[j+1][0]) edgeXat_i = polygon.matrix[j][0]; else if((int)polygon.matrix[j][1] == (int)polygon.matrix[j+1][1]) edgeXat_i = polygon.matrix[j][0]<polygon.matrix[j+1][0]?polygon.matrix[j][0]:polygon.matrix[j+1][0]; else edgeXat_i = (i - polygon.matrix[j][3])/polygon.matrix[j][2]; if(edgeXat_i>=boxLeft && edgeXat_i<=boxRight ) { lim_y_up = polygon.matrix[j][1]<polygon.matrix[j+1][1]?polygon.matrix[j][1]:polygon.matrix[j+1][1]; lim_y_down = polygon.matrix[j][1]>polygon.matrix[j+1][1]?polygon.matrix[j][1]:polygon.matrix[j+1][1]; if(lim_y_up<=i && i<=lim_y_down) xlist.matrix[k++][0] = edgeXat_i; } DPQS(&xlist,0,0,k-1); } for(j=0;j<k;j+=2) line(xlist.matrix[j][0]+1,i,xlist.matrix[j+1][0],i); } }
/* FbxMesh pMesh : the original mesh load from fbx file FbxScene pScene : the FbxScene load from fbx file float threshold : */ void GenerateLOD::Reduction_EdgesCollapse_UV(FbxNode *node, FbxMesh *pMesh, FbxManager *pManager, FbxScene *pScene) { // Clear the ralated data structure (*ControlP).clear(); (*Triangles).clear(); (*Edges).clear(); (*CostToEdge).clear(); // Clear the HeapCost while (!HeapCost->empty()) HeapCost->pop(); FbxVector4 *pControlPoints = pMesh->GetControlPoints(); int AddTriangleIndex = pMesh->GetPolygonCount(); int AddEdgeIndex = pMesh->GetMeshEdgeCount(); int threshold_1 = static_cast<int>(AddTriangleIndex * model_1.GetReductionRate()); int threshold_2 = static_cast<int>(AddTriangleIndex * model_2.GetReductionRate()); int threshold_3 = static_cast<int>(AddTriangleIndex * model_3.GetReductionRate()); double start = GetTickCount(); //# Init the ditc of (*Triangles) and the dict of (*ControlP) Init_Triangles_And_ControlP_EdgeCollapse(pMesh, pControlPoints);///////////////////////////// //Before Reduction, Now Init the Original VertexBuffer Init_Buffer(pMesh, model_0); //# Init the ditc of (*Edges) InitEdges(pMesh); ////////////////////////////////// // Now, Simplify Iterator int Ring = 0; bool flag1 = true; bool flag2 = true; while (true) { int idx; if (0 == HeapCost->size()) idx = -1; else { //First Get the top element, namely the minmum cost //Second pop the minmum cost from HeapCost FbxDouble PopCost = HeapCost->top(); HeapCost->pop(); if (0 == (*CostToEdge)[PopCost].size()) continue; idx = (*CostToEdge)[PopCost][0]; } //int idx = GetMinEdgeCost(); if (-1 == idx) { MessageBox(NULL, "When execute Simplification, there has No any edges should be collapse.", "The title", 0); break; } // Execute the current Edge Collapse and Update the (*ControlP), (*Triangles), (*Edges). CollapseEdge_And_UpdateCost(idx, pControlPoints, AddTriangleIndex, AddEdgeIndex); Ring += 1; if (flag1 && (int)(*Triangles).size() < threshold_1) { // After Reduction, Now Init Reduction VertexBuffer Init_Buffer(pMesh, model_1); model = model_1; FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene); // Update the Node Atrribute node->RemoveNodeAttribute(pMesh); node->SetNodeAttribute(newMesh); // Export new Mesh std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_1.GetReductionRate() * 100)) + "%)" + ".FBX"; saveScene(tmp.c_str(), pManager, pScene, true); node->RemoveNodeAttribute(newMesh); node->SetNodeAttribute(pMesh); flag1 = false; } if (flag2 && (int)(*Triangles).size() < threshold_2) { // After Reduction, Now Init Reduction VertexBuffer Init_Buffer(pMesh, model_2); FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene); // Update the Node Atrribute node->RemoveNodeAttribute(pMesh); node->SetNodeAttribute(newMesh); // Export new Mesh std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_2.GetReductionRate() * 100)) + "%)" + ".FBX"; saveScene(tmp.c_str(), pManager, pScene, true); node->RemoveNodeAttribute(newMesh); node->SetNodeAttribute(pMesh); flag2 = false; } if ((int)(*Triangles).size() < threshold_3) { // After Reduction, Now Init Reduction VertexBuffer Init_Buffer(pMesh, model_3); FbxMesh *newMesh = CreateNewMesh(pControlPoints, pMesh, pScene); // Update the Node Atrribute node->RemoveNodeAttribute(pMesh); node->SetNodeAttribute(newMesh); // Export new Mesh std::string tmp = std::string(".\\LODs\\") + std::string("Save") + srcFbxName.substr(0, srcFbxName.size() - 4) + "_(" + std::to_string(int(model_3.GetReductionRate() * 100)) + "%)" + ".FBX"; saveScene(tmp.c_str(), pManager, pScene, true); node->RemoveNodeAttribute(newMesh); node->SetNodeAttribute(pMesh); break; } } }
int main(int argc,char *argv[]) { int *g; int *new_g; int *new_edges; int seed = 1; int gsize; int count; int i; int j; int k; int best_count; int best_i; int best_j; void *taboo_list; /* * start with graph of size 15 */ gsize = 15; g = (int *)malloc(gsize*gsize*sizeof(int)); if(g == NULL) { exit(1); } /* * make a fifo to use as the taboo list */ taboo_list = FIFOInitEdge(TABOOSIZE); if(taboo_list == NULL) { exit(1); } /* * start out with half 1 and half 0. */ InitGraph(g, gsize, seed); /* * while we do not have a publishable result */ while(gsize < 102) { /* * find out how we are doing */ count = CliqueCount(g,gsize); /* * if we have a counter example */ if(count == 0) { printf("Eureka! Counter-example found!\n"); PrintGraph(g,gsize); OutputGraph(g,gsize, seed); /* * make a new graph one size bigger */ new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int)); if(new_g == NULL) exit(1); /* * copy the old graph into the new graph leaving the * last row and last column alone */ CopyGraph(g,gsize,new_g,gsize+1); /* * half-half the last column and zero out the last row */ new_edges = (int *)malloc(gsize*sizeof(int)); InitEdges(new_edges, gsize, seed); k = 0; for(i=0; i < gsize; i++) { new_g[i*(gsize+1) + gsize] = new_edges[k]; // last column new_g[gsize*(gsize+1) + i] = 0; // last row k ++; } new_g[(gsize+1)*(gsize+1)] = 0; free(new_edges); /* * throw away the old graph and make new one the * graph */ free(g); g = new_g; gsize = gsize+1; /* * reset the taboo list for the new graph */ taboo_list = FIFOResetEdge(taboo_list); /* * keep going */ continue; } /* * otherwise, we need to consider flipping an edge * * let's speculative flip each edge, record the new count, * and unflip the edge. We'll then remember the best flip and * keep it next time around * * only need to work with upper triangle of matrix => * notice the indices */ best_count = BIGCOUNT; for(i=0; i < gsize; i++) { for(j=i+1; j < gsize; j++) { /* * flip it */ g[i*gsize+j] = 1 - g[i*gsize+j]; //printf("The best count is %d, and the count is %d.", best_count, count); count = CliqueCount_EA(g,gsize,best_count); //count = CliqueCount(g, gsize); /* * is it better and the i,j,count not taboo? */ if((count < best_count) && // !FIFOFindEdge(taboo_list,i,j)) !FIFOFindEdgeCount(taboo_list,i,j,count)) { best_count = count; best_i = i; best_j = j; } /* * flip it back */ g[i*gsize+j] = 1 - g[i*gsize+j]; } } if(best_count == BIGCOUNT) { printf("no best edge found, terminating\n"); exit(1); } /* * keep the best flip we saw */ g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j]; /* * taboo this graph configuration so that we don't visit * it again */ count = CliqueCount(g,gsize); // FIFOInsertEdge(taboo_list,best_i,best_j); FIFOInsertEdgeCount(taboo_list,best_i,best_j,count); printf("ce size: %d, best_count: %d, best edge: (%d,%d), new color: %d\n", gsize, best_count, best_i, best_j, g[best_i*gsize+best_j]); /* * rinse and repeat */ } FIFODeleteGraph(taboo_list); return(0); }