//-------------------------------------------------------------- void Particle::setup() { param.eCenter = ofPoint( ofRandom(ofGetWidth()), ofRandom(ofGetHeight()) ); font.loadFont("frabk.ttf", 24); pos = param.eCenter + randomPointInScreen( param.eRad ); //pos.x = ofGetWidth()-(wordLen/2); pos.y = ofGetHeight()/2; vel = randomPointInScreen( param.velRad ); time = 0; lifetime = param.lifetime; live = true; follow = false; //load the text file and all all the words to a vector string vector<string> list; string word; ifstream wordfile("/Users/mtvogel/Documents/of_v0.8.4_osx_release/apps/myACIApps/Assignment_4_Code_Poetry/bin/data/textfile.txt"); while (wordfile >> word) { list.push_back(word); } if (!wordfile.eof()) { cerr << "Hey there! Something went wrong when reading the list of words!\n"; return 1; } //pick a random element in the word list vector int sentenceLen = ofRandom(2, 10); for (int i = 0; i<sentenceLen; i++) { int randElement = ofRandom(list.size()); randWord =list.at( ofRandom(list.size()) ); randSentence = randSentence.append(randWord); randSentence = randSentence.append(" "); } wordLen = randSentence.length()*16; wordHeight = -17; cerr << wordLen<<endl; //set color of text //ofSetColor( ofRandom(255), ofRandom(255), ofRandom(255) ); }
int main (int argc, char* argv []) { #define check(ol, al) if (argv [i][ol] || \ badarg(argc - i - 1,argv + i + 1, al)) \ goto badopt #define check_bool(olen, var) switch (argv [i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; \ } int loadflags = IO_CHECK | IO_SCENE | IO_TREE | IO_BOUNDS, rval, i, j, n; char **portLp = photonPortList, **sensLp = photonSensorList, **amblp = NULL; struct stat pmstat; /* Global program name */ progname = fixargv0(argv [0]); /* Initialize object types */ initotypes(); /* Parse options */ for (i = 1; i < argc; i++) { /* Eggs-pand arguments */ while ((rval = expandarg(&argc, &argv, i))) if (rval < 0) { sprintf(errmsg, "cannot eggs-pand '%s'", argv [i]); error(SYSTEM, errmsg); } if (argv[i] == NULL) break; if (!strcmp(argv [i], "-version")) { puts(VersionID); quit(0); } if (!strcmp(argv [i], "-defaults") || !strcmp(argv [i], "-help")) { printdefaults(); quit(0); } /* Get octree */ if (i == argc - 1) { octname = argv [i]; break; } switch (argv [i][1]) { case 'a': /* Ambient */ switch (argv [i][2]) { case 'i': /* Ambient include */ case 'I': check(3, "s"); if (ambincl != 1) { ambincl = 1; amblp = amblist; } if (argv [i][2] == 'I') { /* Add modifiers from file */ rval = wordfile(amblp, AMBLLEN - (amblp - amblist), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open ambient include file \"%s\"", argv [i]); error(SYSTEM, errmsg); } amblp += rval; } else { /* Add modifier from next arg */ *amblp++ = savqstr(argv [++i]); *amblp = NULL; } break; case 'e': /* Ambient exclude */ case 'E': check(3, "s"); if (ambincl != 0) { ambincl = 0; amblp = amblist; } if (argv [i][2] == 'E') { /* Add modifiers from file */ rval = wordfile(amblp, AMBLLEN - (amblp - amblist), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open ambient exclude file \"%s\"", argv [i]); error(SYSTEM, errmsg); } amblp += rval; } else { /* Add modifier from next arg */ *amblp++ = savqstr(argv [++i]); *amblp = NULL; } break; case 'p': /* Pmap-specific */ switch (argv [i][3]) { case 'g': /* Global photon map */ check(4, "ss"); globalPmapParams.fileName = argv [++i]; globalPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!globalPmapParams.distribTarget) goto badopt; globalPmapParams.minGather = globalPmapParams.maxGather = 0; break; case 'p': /* Precomputed global photon map */ check(4, "ssi"); preCompPmapParams.fileName = argv [++i]; preCompPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!preCompPmapParams.distribTarget) goto badopt; preCompPmapParams.minGather = preCompPmapParams.maxGather = atoi(argv [++i]); if (!preCompPmapParams.maxGather) goto badopt; break; case 'c': /* Caustic photon map */ check(4, "ss"); causticPmapParams.fileName = argv [++i]; causticPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!causticPmapParams.distribTarget) goto badopt; break; case 'v': /* Volume photon map */ check(4, "ss"); volumePmapParams.fileName = argv [++i]; volumePmapParams.distribTarget = parseMultiplier(argv [++i]); if (!volumePmapParams.distribTarget) goto badopt; break; case 'd': /* Direct photon map */ check(4, "ss"); directPmapParams.fileName = argv [++i]; directPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!directPmapParams.distribTarget) goto badopt; break; case 'C': /* Contribution photon map */ check(4, "ss"); contribPmapParams.fileName = argv [++i]; contribPmapParams.distribTarget = parseMultiplier(argv [++i]); if (!contribPmapParams.distribTarget) goto badopt; break; case 'D': /* Predistribution factor */ check(4, "f"); preDistrib = atof(argv [++i]); if (preDistrib <= 0) error(USER, "predistrib factor must be > 0"); break; case 'M': /* Max predistribution passes */ check(4, "i"); maxPreDistrib = atoi(argv [++i]); if (maxPreDistrib <= 0) error(USER, "max predistrib passes must be > 0"); break; #if 1 /* Kept for backwards compat, to be phased out by -lr */ case 'm': /* Max photon bounces */ check(4, "i"); photonMaxBounce = atol(argv [++i]); if (photonMaxBounce <= 0) error(USER, "max photon bounces must be > 0"); break; #endif #ifdef PMAP_EKSPERTZ case 'i': /* Add region of interest */ check(4, "ffffff"); n = pmapNumROI; pmapROI = realloc(pmapROI, ++pmapNumROI * sizeof(PhotonMapROI)); if (!pmapROI) error(SYSTEM, "failed to allocate ROI"); pmapROI [n].min [0] = atof(argv [++i]); pmapROI [n].min [1] = atof(argv [++i]); pmapROI [n].min [2] = atof(argv [++i]); pmapROI [n].max [0] = atof(argv [++i]); pmapROI [n].max [1] = atof(argv [++i]); pmapROI [n].max [2] = atof(argv [++i]); for (j = 0; j < 3; j++) if (pmapROI [n].min [j] >= pmapROI [n].max [j]) error(USER, "invalid region of interest " "(swapped min/max?)"); break; #endif case 'P': /* Global photon precomp ratio */ check(4, "f"); finalGather = atof(argv [++i]); if (finalGather <= 0 || finalGather > 1) error(USER, "global photon precomputation ratio " "must be in range ]0, 1]"); break; case 'o': /* Photon port */ case 'O': check(4, "s"); if (argv [i][3] == 'O') { /* Add port modifiers from file */ rval = wordfile(portLp, MAXSET - (portLp - photonPortList), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open photon port file %s", argv [i]); error(SYSTEM, errmsg); } portLp += rval; } else { /* Add port modifier from next arg, mark end with * NULL */ *portLp++ = savqstr(argv [++i]); *portLp = NULL; } break; case 'r': /* Random seed */ check(4, "i"); randSeed = atoi(argv [++i]); break; case 's': /* Antimatter sensor */ case 'S': check(4, "s"); if (argv[i][3] == 'S') { /* Add sensor modifiers from file */ rval = wordfile(sensLp, MAXSET - (sensLp - photonSensorList), getpath(argv [++i], getrlibpath(), R_OK)); if (rval < 0) { sprintf(errmsg, "cannot open antimatter sensor file %s", argv [i]); error(SYSTEM, errmsg); } sensLp += rval; } else { /* Append modifier to sensor list, mark end with * NULL */ *sensLp++ = savqstr(argv [++i]); *sensLp = NULL; } break; default: goto badopt; } break; default: goto badopt; } break; case 'b': /* Back face visibility */ if (argv [i][2] == 'v') { check_bool(3, backvis); } else goto badopt; break; case 'd': /* Direct */ switch (argv [i][2]) { case 'p': /* PDF samples */ check(3, "f"); pdfSamples = atof(argv [++i]); break; case 's': /* Source partition size ratio */ check(3, "f"); srcsizerat = atof(argv [++i]); break; default: goto badopt; } break; case 'e': /* Diagnostics file */ check(2, "s"); diagFile = argv [++i]; break; case 'f': /* Force overwrite */ if (argv [i][2] == 'o') { check_bool(3, clobber); } else goto badopt; break; #ifdef PMAP_EKSPERTZ case 'l': /* Limits */ switch (argv [i][2]) { case 'd': /* Limit photon path distance */ check(3, "f"); photonMaxDist = atof(argv [++i]); if (photonMaxDist <= 0) error(USER, "max photon distance must be > 0"); break; case 'r': /* Limit photon bounces */ check(3, "i"); photonMaxBounce = atol(argv [++i]); if (photonMaxBounce <= 0) error(USER, "max photon bounces must be > 0"); break; default: goto badopt; } break; #endif case 'm': /* Medium */ switch (argv[i][2]) { case 'e': /* Eggs-tinction coefficient */ check(3, "fff"); setcolor(cextinction, atof(argv [i + 1]), atof(argv [i + 2]), atof(argv [i + 3])); i += 3; break; case 'a': /* Albedo */ check(3, "fff"); setcolor(salbedo, atof(argv [i + 1]), atof(argv [i + 2]), atof(argv [i + 3])); i += 3; break; case 'g': /* Scattering eccentricity */ check(3, "f"); seccg = atof(argv [++i]); break; default: goto badopt; } break; #if NIX case 'n': /* Num parallel processes (NIX only) */ check(2, "i"); nproc = atoi(argv [++i]); if (nproc > PMAP_MAXPROC) { nproc = PMAP_MAXPROC; sprintf(errmsg, "too many parallel processes, clamping to " "%d\n", nproc); error(WARNING, errmsg); } break; #endif case 't': /* Timer */ check(2, "i"); photonRepTime = atoi(argv [++i]); break; case 'v': /* Verbosity */ check_bool(2, verbose); break; #ifdef EVALDRC_HACK case 'A': /* Angular source file */ check(2,"s"); angsrcfile = argv[++i]; break; #endif default: goto badopt; } } /* Open diagnostics file */ if (diagFile) { if (!freopen(diagFile, "a", stderr)) quit(2); fprintf(stderr, "**************\n*** PID %5d: ", getpid()); printargs(argc, argv, stderr); putc('\n', stderr); fflush(stderr); } #ifdef NICE /* Lower priority */ nice(NICE); #endif if (octname == NULL) error(USER, "missing octree argument"); /* Allocate photon maps and set parameters */ for (i = 0; i < NUM_PMAP_TYPES; i++) { setPmapParam(photonMaps + i, pmapParams + i); /* Don't overwrite existing photon map unless clobbering enabled */ if (photonMaps [i] && !stat(photonMaps [i] -> fileName, &pmstat) && !clobber) { sprintf(errmsg, "photon map file %s exists, not overwritten", photonMaps [i] -> fileName); error(USER, errmsg); } } for (i = 0; i < NUM_PMAP_TYPES && !photonMaps [i]; i++); if (i >= NUM_PMAP_TYPES) error(USER, "no photon maps specified"); readoct(octname, loadflags, &thescene, NULL); #ifdef EVALDRC_HACK if (angsrcfile) readobj(angsrcfile); /* load angular sources */ #endif nsceneobjs = nobjects; /* Get sources */ marksources(); /* Do forward pass and build photon maps */ if (contribPmap) /* Just build contrib pmap, ignore others */ distribPhotonContrib(contribPmap, nproc); else distribPhotons(photonMaps, nproc); /* Save photon maps; no idea why GCC needs an explicit cast here... */ savePmaps((const PhotonMap**)photonMaps, argc, argv); cleanUpPmaps(photonMaps); quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); #undef check #undef check_bool return 0; }
// Definition of stringsearch() function void session::stringsearch(){ // Whole body is in loop // Loop ends if the list is empty or a certain number of urls have been parsed do{ // File that stores source code of URLs std::ofstream FILE("source.txt"); std::ofstream wordfile("index.txt", std::ios::app|std::ios::out); // Object of url class created url u(list.front()); // Object of Http class (found in SFML) created // Http class only takes host names as input, so host name passed sf::Http site(u.host()); //Generate the request, i.e the path within the webpage sf::Http::Request request(u.path()); // Send the request to generate a response sf::Http::Response response = site.sendRequest(request); // Check the status code and display the result sf::Http::Response::Status status = response.getStatus(); if (status == sf::Http::Response::Ok){ FILE << response.getBody() << std::endl; } else{ std::cout << "Error " << status << std::endl; std::cout << "Skipping webpage. " << std::endl; list.pop(); continue; } FILE.close(); std::cout << "Popping URL: " << list.front() << std::endl << std::endl; Sleep(1000); // Condition check to see if file is of html format if (check_html() == false){ std::cout << "\nWebpage not in html format. Skipping... " << std::endl << std::endl; list.pop(); continue; } // Condition check to ensure URL hasn't been crawled previously. First URL is skipped if (count > 1 && check_urls(list.front()) == true){ std::cout << "\nWebpage has already been crawled. Skipping...\n\n"; list.pop(); continue; } // Opens file for reading std::ifstream file("source.txt"); std::string s1; // String stores lines from html file std::string s2 = "href=\""; // Reference string to locate hyperlinks char s3[300]; // C string variable to store hyperlink URLs // Condition check to ensure file is open if (file.is_open()){ do{ // Both string storage variables initialised to null s1 = ""; std::getline(file, s1); // Gets line by line information from the page source std::size_t location = s1.find(s2); // Variable to point to location in string int i = 0; // Check to see if location is within string, i.e the desired element has been found if (location != std::string::npos){ std::cout << "Hyperlink found: "; // Location set to first element of hyperlink // Adding 6 accounts for the 6 tag characters, i.e href" std::size_t x = location + 6; // Loop adds characters to array until quotation mark is reached while (s1.at(x) != '\"'){ s3[i] = s1.at(x); x++; i++; } // Last character set to termination character s3[i] = '\0'; std::string s4 = s3; // Converts C string to std::string std::cout << s4 << std::endl; // Creates url object that takes s4 as constructor argument url u2(s4); // Condition check to see if hyperlink has a host // If it doesn't, it means it is an extension of the current webpage // So current webpage is appended to it if (u2.host() == ""){ s4 = u.protocol() + "://" + u.host() + s4; } std::cout << "Adding URL to queue..." << std::endl; // Hyperlink is added to queue list.push(s4); std::cout << s4 << std::endl << std::endl; } if (wordfile.is_open()){ std::string word = "Boost"; std::size_t point = s1.find(word); if (point != std::string::npos){ // while () wordfile << list.front() << std::endl; wordfile << word << std::endl; } // else{ // std::cout << "word not found" << std::endl; //std::cout << "\n"; // } } else{ std::cout << "index could not be opened" << std::endl; } } while (!file.eof()); // Adds current webpage to list of URLs parsed urls_parsed(list.front()); // Removes current webpage from queue list.pop(); file.close(); wordfile.close(); std::cout << "\n\nCount: " << count << std::endl; count++; Sleep(1000); } else{ std::cout << "Error in opening file" << std::endl; exit(-1); } //Sleep(1000); } while (count <= 10 && list.empty() == false); remove("source.txt"); remove("urls.txt"); return; }