//-------------------------------------------------------------- void testApp::update(){ ofBackground(100,100,100); bool bNewFrame = false; #ifdef _USE_LIVE_VIDEO vidGrabber.grabFrame(); bNewFrame = vidGrabber.isFrameNew(); #else vidPlayer.idleMovie(); bNewFrame = vidPlayer.isFrameNew(); #endif if (bNewFrame){ #ifdef _USE_LIVE_VIDEO colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); #else colorImg.setFromPixels(vidPlayer.getPixels(), 320,240); #endif grayImage = colorImg; if (bLearnBakground == true){ grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) bLearnBakground = false; } // take the abs value of the difference between background and incoming and then threshold: grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); // find contours which are between the size of 20 pixels and 1/3 the w*h pixels. // also, find holes is set to true so we will get interior contours as well.... // contourFinder.findContours(grayDiff, 20, (340*240)/3, 1, true); // find holes findEdges( &colorImg, low_threshold, high_threshold, aperature ); createPoints(); } }
string alienOrder(vector<string>& words) { string res; if (words.size() == 0) return res; if (words.size() == 1) return words[0]; bool graph[26][26] = {false}; for (char c : words[0]) { graph[c-'a'][c-'a'] = true; } for (int i = 1; i < words.size(); i++) { for (char c : words[i]) { graph[c-'a'][c-'a'] = true; } findEdges(words[i-1], words[i], graph); } for (int i = 0; i < 26; i++) { bool rootNode = graph[i][i]; if (graph[i][i]) { for (int j = 0; j < 26; j++) { if (j != i && graph[j][i]) { rootNode = false; break; } } } if (rootNode) { string tmpRes = ""; int mask = 0; // vector<bool> tmpMask(26, false); if (dfs(tmpRes, mask, graph, i)) return ""; else res += tmpRes; } } for (int i = 0; i < 26; i++) { if (graph[i][i]) return ""; } return res; }
int main(int argc, const char * argv[]) { ifstream fstream("input.txt"); ofstream edges("edges.txt"); ofstream coords("coords.txt"); ofstream obs("obs.txt"); ofstream json("fca.json"); vector<string> input; string line; if (fstream.is_open()) { while (getline(fstream, line)) { input.push_back(line); } fstream.close(); int num_obs = (int)input.size(); unordered_set<bitset<MAX> > concepts; vector<BitObj*> extents; findConc(input, concepts, extents); vector<bitset<MAX> > relation(concepts.size()); nodeJSON(extents, json); findEdges(extents, relation, edges); linkJSON(json); findCoords(extents, coords); nodeObs(extents, obs, num_obs); //Set operations ifstream com("com.txt"); cout << "Computing operations...\n"; string line; while (getline(com, line)) { cout << '\n'; bitset<MAX> A = convInput(line.substr(2), num_obs); cout << "Input A: "; printObj(A, cout, num_obs); switch (line[0]) { case 'c': cout << "Closure of A: "; printObj(closure(extents, A).second, cout, num_obs); break; case 'b': cout << "Boundary of A: "; printObj(boundary(extents, A, num_obs).second, cout, num_obs); break; case 'i': cout << "Interior of A: "; printObj(interior(extents, A, num_obs), cout, num_obs); break; case 'd': cout << "Derived set of A: "; printObj(derived(extents, A, num_obs), cout, num_obs); break; case 's': cout << "Isolated point of A: "; printObj(isolated(extents, A, num_obs), cout, num_obs); break; } } for (BitObj *b : extents) delete b; } else cerr << "Unable to open file" << endl; return 0; }
// // program entry point // int main(int argc, char *argv[]) { FILE *input, *output; matrix_t *matrix1, *result; element_t *item; int rows, cols, x, y; float allowedDifference, *averages; // open input file for read input = fopen("in.dat", "r"); if(input == NULL){ perror("failed to open in.dat for read"); return EXIT_FAILURE; } // read rows and columns from input file fscanf(input, "%d %d\n", &rows, &cols); // create matrix1 from input file if(!matrix_create(&matrix1, rows, cols)){ perror("failed to create matrix1"); fclose(input); return EXIT_FAILURE; } // create result from input file if(!matrix_create(&result, rows, cols)){ perror("failed to create result"); fclose(input); return EXIT_FAILURE; } // create array for averages if((averages = (float *)malloc(sizeof(float) * cols * rows)) == NULL){ perror("failed to create averages array"); fclose(input); return EXIT_FAILURE; } // open output file for write output = fopen("out.dat", "w"); if(output == NULL){ perror("failed to open out.dat for write"); fclose(input); return EXIT_FAILURE; } for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ // get matrix position item = matrix_index(matrix1, x, y); // read the elements fscanf(input, "%d %d %d ", &item->red, &item->green, &item->blue); // sanity check parameters if((item->red < 0 || item->red > 255) || (item->green < 0 || item->green > 255) || (item->blue < 0 || item->blue > 255)){ perror("Value must be between 0-255"); matrix_free(&matrix1); fclose(input); return EXIT_FAILURE; } // average averages[y * cols + x] = elementAverage(item); } } // print matrix1 to screen for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ item = matrix_index(matrix1, x, y); printf("matrix1[%d, %d] = { %3d, %3d, %3d }\n", x, y, item->red, item->green, item->blue); } } printf("\n"); // print matrix1 to file for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ item = matrix_index(matrix1, x, y); fprintf(output, "matrix1[%d, %d] = { %3d, %3d, %3d }\n", x, y, item->red, item->green, item->blue); } } printf("\n"); // print averages to screen for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ printf("averages[%d, %d] = %f\n", x, y, averages[y * cols + x]); } } printf("\n"); // print averages to file for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ fprintf(output, "averages[%d, %d] = %f\n", x, y, averages[y * cols + x]); } } // get percentage printf("enter allowed difference:\n"); fflush(stdout); scanf("%f", &allowedDifference); result = findEdges(matrix1, allowedDifference); printf("\n"); // print result to screen for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ item = matrix_index(result, x, y); printf("result[%d, %d] = { %3d, %3d, %3d }\n", x, y, item->red, item->green, item->blue); } } printf("\n"); // print result to file for(y = 0; y < rows; y++){ for(x = 0; x < cols; x++){ item = matrix_index(result, x, y); fprintf(output,"result[%d, %d] = { %3d, %3d, %3d }\n", x, y, item->red, item->green, item->blue); } } // free memory allocated to matrices matrix_free(&matrix1); matrix_free(&result); // close previously opened files fclose(output); fclose(input); system("pause"); return EXIT_SUCCESS; }
void Light2D::draw(ConvexHull *objectList, int objectCount, LightProperties *lightList, int lightCount, float depth) { if(!visible) return; DWORD ambientColor = Color_Black; for(int i = 0; i < lightCount; ++i) { // Clear the alpha values in the backbuffer // Draw the light gradient //graphics.fillGradientEllipse(lightList[i].position, lightList[i].radius, lightList[i].radius, 0, 0, COLOR_RGBA_DWORD(255, 255, 255, 255), COLOR_RGBA_DWORD(255, 255, 255, 0), depth); // Remove the shadows from the light gradient //Vector2 edge0UmbraVector, edge1UmbraVector; for(int j = 0; j < objectCount; ++j) { int index0, index1; findEdges(lightList[i], objectList[j], &index0, &index1); if(index0 == index1) { continue; } /*Vector2 edge0, edge1; edge0 = objectList[j].getVertex(index0); edge1 = objectList[j].getVertex(index1); float distanceToStartingVertex = math.distance(lightList[i].position, edge0); Vector2 centerVector; centerVector = edge0 - lightList[i].position; Vector2 perpendicularVector = Vector2(-centerVector.y, centerVector.x).normal(); Vector2 penumbraVector = centerVector - perpendicularVector * lightList[i].sourceRadius; edge0UmbraVector = (centerVector + perpendicularVector * lightList[i].sourceRadius).normal(); if(distanceToStartingVertex) { int newAlpha = COLOR_GET_A(lightList[i].color) * (1.0 - distanceToStartingVertex / lightList[i].radius); graphics.fillTriangle(edge0, lightList[i].position + penumbraVector.normal() * lightList[i].radius * 100, lightList[i].position + edge0UmbraVector.normal() * lightList[i].radius * 100, COLOR_RGBA(0, 0, 0, 255), COLOR_RGBA(0, 0, 0, 255), COLOR_RGBA(0, 0, 0, 255), depth, lightMap); } float distanceToEndingVertex = math.distance(lightList[i].position, edge1); centerVector = edge1 - lightList[i].position; perpendicularVector = Vector2(-centerVector.y, centerVector.x).normal(); penumbraVector = centerVector + perpendicularVector * lightList[i].sourceRadius; edge1UmbraVector = (centerVector - perpendicularVector * lightList[i].sourceRadius).normal(); if(distanceToEndingVertex) { int newAlpha = COLOR_GET_A(lightList[i].color) * (1.0 - distanceToEndingVertex / lightList[i].radius); graphics.fillTriangle(edge1, lightList[i].position + penumbraVector.normal() * lightList[i].radius * 100, lightList[i].position + edge1UmbraVector.normal() * lightList[i].radius * 100, COLOR_RGBA(0, 0, 0, 255), COLOR_RGBA(0, 0, 0, 255), COLOR_RGBA(0, 0, 0, 255), depth, lightMap); }*/ if(index0 == index1) { graphics.fillEllipse(lightList[i].position, lightList[i].radius, lightList[i].radius, 0, 0, COLOR_RGBA(0, 0, 0, 0), depth); continue; } int vertexCount = objectList[j].getVertexCount(); int loopStart, loopEnd; int difference; if(index0 < index1) { loopStart = index0; loopEnd = index1; } else { loopStart = index0; loopEnd = vertexCount + index1; } difference = loopEnd - loopStart - 1; int l = 0; for(int k = loopStart; k < loopEnd; ++k) { Vector2 edge0, edge1; edge0 = objectList[j].getVertex(k % vertexCount); edge1 = objectList[j].getVertex((k + 1) % vertexCount); Vector2 normal0, normal1; normal0 = (edge0 - lightList[i].position).normal(); normal1 = (edge1 - lightList[i].position).normal(); /*normal0 = ((edge0UmbraVector * (difference - l) + edge1UmbraVector * l) / difference).normal(); l++; normal1 = ((edge0UmbraVector * (difference - l) + edge1UmbraVector * l) / difference).normal();*/ graphics.fillQuadrilateral(edge0.x, edge0.y, edge1.x, edge1.y, edge0.x + lightList[i].radius * normal0.x * 1000, edge0.y + lightList[i].radius * normal0.y * 1000, edge1.x + lightList[i].radius * normal1.x * 1000, edge1.y + lightList[i].radius * normal1.y * 1000, COLOR_RGBA(0, 0, 0, 0), COLOR_RGBA(0, 0, 0, 0), COLOR_RGBA(0, 0, 0, 0), COLOR_RGBA(0, 0, 0, 0), depth); } } //graphics.setAmbientLightColor(lightList[i].color.getDWORD()); graphics.fillRectangle(lightList[i].position - Vector2(lightList[i].radius, lightList[i].radius), lightList[i].position + Vector2(lightList[i].radius, lightList[i].radius), COLOR_RGBA(255, 255, 255, 255), depth); //for(int j = 0; j < objectCount; ++j) objectList[j].draw(COLOR_RGB(255, 255, 255).getDWORD(), depth); } //graphics.setAmbientLightColor(ambientColor); }