int main(int args, char ** argv) { misc::process_args(args, argv); load_image(file_name[0], left_pyramid[0].rgb, left_pyramid[0].H, left_pyramid[0].W); load_image(file_name[1], right_pyramid[0].rgb, right_pyramid[0].H, right_pyramid[0].W); if (left_pyramid[0].H != right_pyramid[0].H || left_pyramid[0].W != right_pyramid[0].W) { printf("The size of two pictures differ!! quit...."); return 0; } if (left_pyramid[0].H >= MAX_HEIGHT || right_pyramid[0].W >= MAX_WIDTH) { printf("Input : %d x %d, program : %d %d\n", left_pyramid[0].H, left[0].W, MAX_HEIGHT, MAX_WIDTH); puts("Image too big. change settings.hpp and re-compile."); return 0; } timer.reset(); if (use_lab) { left_pyramid[0].computeLab(); right_pyramid[0].computeLab(); } for (int i = 0; i + 1 < levels; ++i) { left_pyramid[i+1].shrinkPicture(left_pyramid[i+1].rgb, left_pyramid[i].rgb, left_pyramid[i].H, left_pyramid[i].W); right_pyramid[i+1].shrinkPicture(right_pyramid[i+1].rgb, right_pyramid[i].rgb, right_pyramid[i].H, right_pyramid[i].W); if (use_lab) { left_pyramid[i+1].shrinkPicture(left_pyramid[i+1].lab, left_pyramid[i].lab, left_pyramid[i].H, left_pyramid[i].W); right_pyramid[i+1].shrinkPicture(right_pyramid[i+1].lab, right_pyramid[i].lab, right_pyramid[i].H, right_pyramid[i].W); } } for (int lvl = levels - 1; lvl >= 0; -- lvl) { int idx = lvl % OBJ_NUM; left[idx].init(left_pyramid[lvl]); right[idx].init(right_pyramid[lvl]); if (lvl == levels - 1) { left[idx].noPrediction(max_disparity / (1 << lvl)); } else { DP::getSupportProb(left[idx].rgb, right[idx].rgb, left[idx].H, left[idx].W, max_disparity / (1 << lvl)); DP::getProbMatrix(lvl, max_disparity / (1 << (lvl + 1)), max_disparity / (1 << lvl), dataset); DP::getInterval(pixel_intv_threshold * (1 << lvl)/*, tot_threshold*/); left[idx].readPrediction(left[(lvl + 1)%OBJ_NUM].disparity); // left[idx].intersectInterval(left[(lvl + 1) % OBJ_NUM]); } // Now use the INTERVAL to find the new disparities. left_pyramid[lvl].computeGradient(); right_pyramid[lvl].computeGradient(); left[idx].buildForest(tree_intv_threshold, use_lab); left[idx].noPrediction(max_disparity / (1 << lvl)); left[idx].initDisparity(); updateTable(255 * 0.1); left[idx].stereoMatch(right[idx], 1, use_lab); misc::median_filter(left[idx].disparity, left[idx].H, left[idx].W, 3); // save_image(layername[lvl][0], left[idx].disparity, left[idx].H, left[idx].W, scale * (1 << lvl)); } // end of layer iteration. timer.check("all"); save_image(file_name[2], left[0].disparity, left[0].H, left[0].W, scale); return 0; }
int main(int args, char ** argv) { misc::process_args(args, argv); load_image(file_name[0], left_layer.rgb, left_layer.H, left_layer.W); load_image(file_name[1], right_layer.rgb, right_layer.H, right_layer.W); timer.reset(); left.init(left_layer); right.init(right_layer); //misc::median_filter_rgb(left.rgb, left.H, left.W, 1); //misc::median_filter_rgb(right.rgb, right.H, right.W, 1); if (use_lab) { left_layer.computeLab(); // misc::median_filter_rgb(left.lab, left.H, left.W, 1); } left.buildTree(use_lab); left_layer.computeGradient(); right_layer.computeGradient(); // next part : compute disparity left.initDisparity(); updateTable(255 * 0.1); // timer.check("build forest"); left.stereoMatch(right, 1, max_disparity, use_lab); misc::median_filter(left.disparity, left.H, left.W); //TODO: why radius = 2, not 3 as dp timer.check("all"); //save save_image(file_name[2], left.disparity, left.H, left.W, scale); //save_image(file_name[3], right.disparity, right.H, right.W, scale); return 0; }
/** Create object from file. * If file or file+.mhd exists, use this, * Otherwise assume input is split over several * files and try to load all mhdFile + i + ".mhd". * forall i. */ USFrameDataPtr USFrameData::create(QString inputFilename) { QFileInfo info(inputFilename); TimeKeeper timer; QString mhdSingleFile = info.absolutePath()+"/"+info.completeBaseName()+".mhd"; if (QFileInfo(mhdSingleFile).exists()) { vtkImageDataPtr image = MetaImageReader().loadVtkImageData(mhdSingleFile); // load from single file USFrameDataPtr retval = USFrameData::create(ImagePtr(new Image(mhdSingleFile, image))); retval->mName = QFileInfo(mhdSingleFile).completeBaseName(); timer.printElapsedms(QString("Loading single %1").arg(inputFilename)); return retval; } else { USFrameDataPtr retval(new USFrameData()); retval->mName = QFileInfo(inputFilename).completeBaseName(); retval->mImageContainer.reset(new cx::CachedImageDataContainer(inputFilename, -1)); retval->resetRemovedFrames(); return retval; } }
void Simulation::timeEvolutionUntilNextOutput(const TimeKeeper &tk) { pair<double, string> t = tk.nextTime(); pair<double, string> s = tk.nextStrain(); if (t.second.empty()) { // no next time sys.timeEvolution(-1, s.first); } else if (s.second.empty()) { // no next strain sys.timeEvolution(t.first, -1); } else { // either next time or next strain sys.timeEvolution(t.first, s.first); } handleEvents(); }
/* * Main simulation */ void Simulation::simulationSteadyShear(string in_args, vector<string>& input_files, bool binary_conf, double dimensionless_number, string input_scale, string control_variable, string simu_identifier) { string indent = " Simulation::\t"; control_var = control_variable; setupSimulation(in_args, input_files, binary_conf, dimensionless_number, input_scale, simu_identifier); time_t now; time_strain_1 = 0; now = time(NULL); time_strain_0 = now; setupEvents(); cout << indent << "Time evolution started" << endl << endl; TimeKeeper tk = initTimeKeeper(); int binconf_counter = 0; while (keepRunning()) { timeEvolutionUntilNextOutput(tk); set<string> output_events = tk.getElapsedClocks(sys.get_time(), sys.get_curvilinear_strain()); generateOutput(output_events, binconf_counter); printProgress(); if (time_strain_1 == 0 && sys.get_curvilinear_strain() > 1) { now = time(NULL); time_strain_1 = now; timestep_1 = sys.get_total_num_timesteps(); } } now = time(NULL); time_strain_end = now; timestep_end = sys.get_total_num_timesteps(); outputComputationTime(); string filename_parameters = input_files[1]; if (filename_parameters.find("init_relax", 0) != string::npos) { /* To prepare relaxed initial configuration, * we can use Brownian simulation for a short interval. * Here is just to export the position data. */ string filename_configuration = input_files[0]; outputFinalConfiguration(filename_configuration); } cout << indent << "Time evolution done" << endl << endl; }
TimeKeeper Simulation::initTimeKeeper() { TimeKeeper tk; if (p.log_time_interval) { tk.addClock("data", LogClock(p.initial_log_time, p.time_end, p.nb_output_data_log_time, input_values["time_end"].unit == "strain")); } else { tk.addClock("data", LinearClock(p.time_interval_output_data, input_values["time_interval_output_data"].unit == "strain")); } if (p.log_time_interval) { tk.addClock("config", LogClock(p.initial_log_time, p.time_end, p.nb_output_config_log_time, input_values["time_end"].unit == "strain")); } else { tk.addClock("config", LinearClock(p.time_interval_output_config, input_values["time_interval_output_config"].unit == "strain")); } return tk; }
void on_update(const UpdateEvent & e) override { // Around 60 fps if (fixedTimer.milliseconds().count() >= 16 && turret.fired) { float timestep_ms = fixedTimer.milliseconds().count() / 1000.f; turret.projectile.fixed_update(timestep_ms); std::cout << timestep_ms << std::endl; //std::cout << turret.projectile.p.position << std::endl; fixedTimer.reset(); } cameraController.update(e.timestep_ms); time += e.timestep_ms; shaderMonitor.handle_recompile(); // If a new mesh is ready, retrieve it if (pointerFuture.valid()) { auto status = pointerFuture.wait_for(std::chrono::seconds(0)); if (status != std::future_status::timeout) { auto m = pointerFuture.get(); supershape = m; supershape.pose.position = {0, 2, -2}; pointerFuture = {}; } } // If we don't currently have a background task, begin working on the next mesh if (!pointerFuture.valid() && regeneratePointer) { pointerFuture = std::async([]() { return make_supershape_3d(16, ssM, ssN1, ssN2, ssN3); }); } }
int main(int argc,char* argv[]) { bool justAddress=false; string blockDir=""; string feeAmt=""; string fileName=""; string action=""; string fromAccount=""; bool beginningStart=false; for(int i=1;i<argc;i++) { if(strcmp(argv[i],"-d")==0) { i++; if(i==argc) { argumentError(); } blockDir=string(argv[i]); } else if(strcmp(argv[i],"-b")==0) { if(beginningStart) { argumentError(); } beginningStart=true; } else if(strcmp(argv[i],"-j")==0) { if(justAddress) { argumentError(); } justAddress=true; } else if(strcmp(argv[i],"-h")==0) { cout << "The following describes how to use bitstamp" << endl; help(); exit(0); } else if(strcmp(argv[i],"-v")==0) { if(verbose) { argumentError(); } verbose=true; } else if(strcmp(argv[i],"-a")==0) { i++; if(i==argc) { argumentError(); } fromAccount=string(argv[i]); } else if(strcmp(argv[i],"-f")==0) { i++; if(i==argc) { argumentError(); } feeAmt=string(argv[i]); } else if(action=="") { action=string(argv[i]); if(action!="validate"&&action!="stamp") { argumentError(); } } else if(fileName=="") { fileName=string(argv[i]); } else { argumentError(); } } if(fileName==""||action=="") { argumentError(); } unsigned long int bytesToSkip; if(beginningStart) { bytesToSkip=0; } else { //bytesToSkip=7142202419; // bytesToSkip=99243107-8+157388147-8+6839349118-8; bytesToSkip=7135458961; } unsigned char hash[SHA_DIGEST_LENGTH]; calcSha1(fileName.c_str(),hash); if(action=="validate") { Matcher m((char*)hash,SHA_DIGEST_LENGTH); TimeKeeper t; if(blockDir=="") { char* homeDir=getenv("HOME"); if(homeDir==NULL) { cout << "error no HOME environment variable" << endl; } blockDir=string(homeDir)+"/.bitcoin"; } set<string> blockFiles=getBlockFiles(blockDir); unsigned long int unchangedSkipBytes=bytesToSkip; for(set<string>::iterator i=blockFiles.begin();i!=blockFiles.end();i++) { struct stat s; if(stat((*i).c_str(),&s)==-1) { cout << "Couldn't stat " << (*i) << endl; exit(1); } if(verbose) { cout << bytesToSkip << " " << s.st_size << endl; } if(((unsigned long int)s.st_size)<=bytesToSkip) { bytesToSkip-=s.st_size; if(verbose) { cout << "skipping file " << (*i) << endl; } continue; } string blockName=(*i); FILE* file=fopen(blockName.c_str(),"rb"); fseek(file,(long)bytesToSkip,SEEK_CUR); if(verbose) { cout << "opened file " << blockName << endl; } if(verbose&&bytesToSkip>0) { cout << "skipping " << bytesToSkip << " bytes" << endl; } bytesToSkip=0; if(file==NULL) { cout << "error openening block chain file " << blockName << endl; exit(1); } int c=fgetc(file); while(c!=EOF) { if(m.check(c)) { cout << "Stamp found! \"" << fileName << "\" was timestamped at " << t.getTime(); if(verbose) { cout << t.getBytesRead() << " bytes actually read" << endl; cout << "total " << (unchangedSkipBytes+t.getBytesRead()) << " bytes read" << endl; } exit(0); } t.read(c); c=fgetc(file); } fclose(file); } cout << "Stamp for " << fileName << " never found" << endl; if(verbose) { cout << t.getBytesRead() << " bytes actually read" << endl; cout << "total " << (unchangedSkipBytes+t.getBytesRead()) << " bytes read" << endl; } exit(0); } else if(action=="stamp") { string base58Hash=hashToAddress(hash); if(justAddress) { cout << "Send a BTC payment of any amount to " << base58Hash << " to bitstamp the file " << fileName << endl; exit(0); } if(feeAmt!="") { string cmd="bitcoind settxfee "+feeAmt; if(verbose) { cout << cmd << endl; } if(system(cmd.c_str())==-1) { cout << "couldn't set transaction fee" << endl; exit(1); } } bool walletLocked = IsWalletLocked(); if(walletLocked) { SetStdinEcho(false); string passphrase = ""; cout << "Enter your wallet passphrase (will not echo): \n"; getline(cin,passphrase); string cmd="bitcoind walletpassphrase \""+passphrase+"\" 2"; passphrase = ""; // paranoia SetStdinEcho(true); if(verbose) { cout << "bitcoind walletpassphrase [your passphrase here] 2" << endl; } if(system(cmd.c_str())==-1) { cout << "couldn't decrypt wallet" << endl; exit(1); } } if(fromAccount!="") { string cmd="bitcoind sendtoaddress "+fromAccount+" "+base58Hash+" 0.00000001"; if(verbose) { cout << cmd << endl; } if(system(cmd.c_str())==-1) { cout << "couldn't send bitcoins" << endl; exit(1); } } else { string cmd="bitcoind sendtoaddress "+base58Hash+" 0.00000001"; if(verbose) { cout << cmd << endl; } if(system(cmd.c_str())==-1) { cout << "couldn't send bitcoins" << endl; exit(1); } } if(walletLocked) { string cmd="bitcoind walletlock"; if(verbose) { cout << cmd << endl; } if(system(cmd.c_str())==-1) { cout << "couldn't relock wallet" << endl; exit(1); } } } else { argumentError(); } }
int main( void ) { myEnvelope.setSustain( 100 ); myEnvelope.setAttack( 50, 100 ); myEnvelope.setDecay( 193, 60 ); myEnvelope.setRelease( 50, 80 ); myEnvelope.setAttackHold( 255 ); myEnvelope2.setSustain( 110 ); myEnvelope2.setAttack( 200, -127 ); myEnvelope2.setDecay( 50, 60 ); myEnvelope2.setRelease( 50, 35 ); myEnvelope2.setAttackHold( 255 ); long msTicks = 0; long lastService = 0; //Has quit. Now write a file msTicks = 0; lastService = 0; noQuit = 1; //Make the delays TimeKeeper testTK; uint8_t noteOnServiced = 0; uint8_t noteOnServiced2 = 0; uint8_t noteOffServiced = 0; uint8_t noteOffServiced2 = 0; uint8_t noteOnShadowServiced = 0; uint16_t lastTestTK = 0; uint8_t lastNoteState = 0; // make_bitmap_1(); bitmap_image image(1024,768); image_drawer draw(image); image.set_region(3,3,1018,762,bitmap_image::red_plane,255); image.set_region(3,3,1018,762,bitmap_image::blue_plane,255); image.set_region(3,3,1018,762,bitmap_image::green_plane,255); uint16_t origin[2] = {6,261}; uint16_t maxBox[2] = {1011,255}; uint16_t lastXY[2] = {6,261}; uint16_t lastXY2[2] = {6,261}; uint16_t origin2[2] = {6,374}; uint16_t maxBox2[2] = {1011,96}; uint16_t lastXY3[2] = {6,374}; uint16_t Box2origin[2] = {6, 645}; uint16_t Box2maxBox[2] = {1011,255}; uint16_t Box2lastXY[2] = {6,645}; uint16_t Box2lastXY2[2] = {6,645}; uint16_t Box2origin2[2] = {6,759}; uint16_t Box2maxBox2[2] = {1011,96}; uint16_t Box2lastXY3[2] = {6,759}; uint16_t Box2lastXY4[2] = {6,759}; //Grid prep draw.pen_color(200,200,200); draw.pen_width(1); //First Grid int grid; for(grid = 0; grid < maxBox[0]; grid = grid + 10) { draw.vertical_line_segment(origin[1],origin[1] - maxBox[1],origin[0]+grid); } for(grid = 0; grid < maxBox[1]; grid = grid + 16) { draw.horiztonal_line_segment(origin[0],origin[0]+maxBox[0],origin[1]-grid); } uint16_t mX1 = origin[0]; uint16_t mY1 = origin[1]; uint16_t mX2 = origin[0] + maxBox[0]; uint16_t mY2 = origin[1] - maxBox[1]; draw.rectangle(mX1,mY1,mX2,mY2); //Second Grid for(grid = 0; grid < maxBox2[0]; grid = grid + 10) { draw.vertical_line_segment(origin2[1],origin2[1] - maxBox2[1],origin2[0]+grid); } for(grid = 0; grid < maxBox2[1]; grid = grid + 16) { draw.horiztonal_line_segment(origin2[0],origin2[0]+maxBox2[0],origin2[1]-grid); } mX1 = origin2[0]; mY1 = origin2[1]; mX2 = origin2[0] + maxBox2[0]; mY2 = origin2[1] - maxBox2[1]; draw.rectangle(mX1,mY1,mX2,mY2); //Third Grid for(grid = 0; grid < Box2maxBox[0]; grid = grid + 10) { draw.vertical_line_segment(Box2origin[1],Box2origin[1] - Box2maxBox[1],Box2origin[0]+grid); } for(grid = 0; grid < Box2maxBox[1]; grid = grid + 16) { draw.horiztonal_line_segment(Box2origin[0],Box2origin[0]+Box2maxBox[0],Box2origin[1]-grid); } mX1 = Box2origin[0]; mY1 = Box2origin[1]; mX2 = Box2origin[0] + Box2maxBox[0]; mY2 = Box2origin[1] - Box2maxBox[1]; draw.rectangle(mX1,mY1,mX2,mY2); //Fourth Grid for(grid = 0; grid < Box2maxBox2[0]; grid = grid + 10) { draw.vertical_line_segment(Box2origin2[1],Box2origin2[1] - Box2maxBox2[1],Box2origin2[0]+grid); } for(grid = 0; grid < Box2maxBox2[1]; grid = grid + 16) { draw.horiztonal_line_segment(Box2origin2[0],Box2origin2[0]+Box2maxBox2[0],Box2origin2[1]-grid); } mX1 = Box2origin2[0]; mY1 = Box2origin2[1]; mX2 = Box2origin2[0] + Box2maxBox2[0]; mY2 = Box2origin2[1] - Box2maxBox2[1]; draw.rectangle(mX1,mY1,mX2,mY2); //Help gotoxy(0,0); printf("Writing output files.\n"); draw.pen_color(0,0,0); draw.pen_width(2); //Format: //[time] //[event] //[serviced flag] uint16_t events[20][3]; uint8_t eventPointer = 0; events[0][0] = 100; events[0][1] = 1; events[0][2] = 0; events[1][0] = 2000; events[1][1] = 1; events[1][2] = 0; events[2][0] = 3000; events[2][1] = 0; events[2][2] = 0; events[3][0] = 6000; events[3][1] = 1; events[3][2] = 0; events[4][0] = 6300; events[4][1] = 0; events[4][2] = 0; events[9][0] = 10000; events[9][1] = 255; //quit events[9][2] = 0; //Format: //[time] //[event] //[serviced flag] uint16_t events2[20][3]; uint8_t event2Pointer = 0; events2[0][0] = 100; events2[0][1] = 1; events2[0][2] = 0; events2[1][0] = 1400; events2[1][1] = 0; events2[1][2] = 0; events2[2][0] = 1800; events2[2][1] = 1; events2[2][2] = 0; events2[3][0] = 2300; events2[3][1] = 0; events2[3][2] = 0; events2[4][0] = 4100; events2[4][1] = 11; events2[4][2] = 0; events2[5][0] = 6000; events2[5][1] = 0; events2[5][2] = 0; events2[6][0] = 6500; events2[6][1] = 1; events2[6][2] = 0; events2[7][0] = 6700; events2[7][1] = 0; events2[7][2] = 0; events2[8][0] = 7200; events2[8][1] = 1; events2[8][2] = 0; events2[9][0] = 7950; events2[9][1] = 0; events2[9][2] = 0; while(noQuit) { msTicks = msTicks + ENVTICKRATEMS; testTK.mIncrement( ENVTICKRATEMS ); //Sleep(ENVTICKRATEMS); //This is made to tick every 10 ms if( msTicks > (lastService + ENVTICKRATEMS)) { lastService = lastService + ENVTICKRATEMS; myEnvelope.tick( ENVTICKRATEMS ); myEnvelope2.tick( ENVTICKRATEMS ); } //Check serviced until clear, then move on if(events[eventPointer][2] == 0) { //check time if(testTK.mGet() > events[eventPointer][0]) { //expired! needs service. switch( events[eventPointer][1] ) { case 0: myEnvelope.setNoteOff(); break; case 1: myEnvelope.setNoteOn(); break; case 12: myEnvelope.setSustain( 255 ); break; case 255: noQuit = 0; default: break; } //Now check serviced box events[eventPointer][2] = 1; } } else { //Increment point eventPointer++; } //Check serviced until clear, then move on if(events2[event2Pointer][2] == 0) { //check time if(testTK.mGet() > events2[event2Pointer][0]) { //expired! needs service. switch( events2[event2Pointer][1] ) { case 0: myEnvelope2.setNoteOff(); break; case 1: myEnvelope2.setNoteOn(); break; case 11: myEnvelope2.setAttackHold( 0 ); myEnvelope2.setNoteOn(); break; case 255: noQuit = 0; default: break; } //Now check serviced box events2[event2Pointer][2] = 1; } } else { //Increment point event2Pointer++; } //Present the output here draw.pen_color(255,0,0); draw.line_segment(lastXY2[0],lastXY2[1],origin[0] + msTicks/10,origin[1]-myEnvelope.shadowAmp); lastXY2[0] = origin[0] + msTicks/10; lastXY2[1] = ((int)origin[1]-myEnvelope.shadowAmp); draw.pen_color(0,0,0); draw.line_segment(lastXY[0],lastXY[1],origin[0] + msTicks/10,origin[1]-myEnvelope.amp); lastXY[0] = origin[0] + msTicks/10; lastXY[1] = ((int)origin[1]-myEnvelope.amp); draw.pen_color(255,127,0); draw.line_segment(lastXY3[0],lastXY3[1],origin2[0] + msTicks/10,origin2[1]-(32*myEnvelope.noteState + 16)); lastXY3[0] = origin2[0] + msTicks/10; lastXY3[1] = ((int)origin2[1]-(32*myEnvelope.noteState + 16)); draw.pen_color(0,255,0); draw.line_segment(Box2lastXY2[0],Box2lastXY2[1],Box2origin[0] + msTicks/10,Box2origin[1]-myEnvelope2.shadowAmp); Box2lastXY2[0] = Box2origin[0] + msTicks/10; Box2lastXY2[1] = ((int)Box2origin[1]-myEnvelope2.shadowAmp); draw.pen_color(0,0,0); draw.line_segment(Box2lastXY[0],Box2lastXY[1],Box2origin[0] + msTicks/10,Box2origin[1]-myEnvelope2.amp); Box2lastXY[0] = Box2origin[0] + msTicks/10; Box2lastXY[1] = ((int)Box2origin[1]-myEnvelope2.amp); draw.pen_color(0,0,255); draw.line_segment(Box2lastXY4[0],Box2lastXY4[1],Box2origin2[0] + msTicks/10,Box2origin2[1]-((myEnvelope2.envAttackHold.timeScale*255/25/4) + 16)); Box2lastXY4[0] = Box2origin2[0] + msTicks/10; Box2lastXY4[1] = ((int)Box2origin2[1]-((myEnvelope2.envAttackHold.timeScale*255/25/4) + 16)); draw.pen_color(255,0,255); draw.line_segment(Box2lastXY3[0],Box2lastXY3[1],Box2origin2[0] + msTicks/10,Box2origin2[1]-(32*myEnvelope2.noteState + 16)); Box2lastXY3[0] = Box2origin2[0] + msTicks/10; Box2lastXY3[1] = ((int)Box2origin2[1]-(32*myEnvelope2.noteState + 16)); } image.save_image("newfile.bmp"); }
void test_findClosestConnection() { srand(1234); if (false) { Polygon poly2; poly2.add(Point(0,300)); poly2.add(Point(100,300)); // ____ poly2.add(Point(100,200)); // | | poly2.add(Point(50,250)); // | /\ | poly2.add(Point(0,200)); // |/ \| Polygon poly1; poly1.add(Point(0,0)); poly1.add(Point(100,0)); // poly1.add(Point(100,100)); // |\ /| poly1.add(Point(50,50)); // | \/ | poly1.add(Point(0,100)); // |____| ClosestPolygonPoint result1 (poly1); ClosestPolygonPoint result2 (poly2); findSmallestConnection(result1, result2, 3); std::cerr << result1.location << " -- " << result2.location << std::endl; } if (false) { Polygon poly2; poly2.add(Point(0,300)); poly2.add(Point(100,300)); // ____ poly2.add(Point(100,200)); // | | poly2.add(Point(50,250)); // | /\ | poly2.add(Point(10,105)); // |/ \| Polygon poly1; poly1.add(Point(0,0)); poly1.add(Point(100,0)); // poly1.add(Point(100,100)); // |\ /| poly1.add(Point(50,50)); // | \/ | poly1.add(Point(0,100)); // |____| ClosestPolygonPoint result1 (poly1); ClosestPolygonPoint result2 (poly2); findSmallestConnection(result1, result2, 3); std::cerr << result1.location << " -- " << result2.location << std::endl; } double creationTime = 0; double evalTime = 0; long totalLength = 0; TimeKeeper timer; for (int i = 0; i < 10000; i++) { // for vizualization as csv with e.g. Rstudio Polygon poly1; double dist = 100; for (double a = 0; a < 360; a += 1) { dist += int(rand()%3) -1; Point p(static_cast<int>(dist * std::cos(a/180.0*3.1415)), static_cast<int>(dist * std::sin(a/180.0*3.1415))); p = p + Point(0, 200); if ( a ==0) poly1.add(p); else poly1.add((poly1.back() + p) / 2); // std::cerr << poly1.back().X << ", " << poly1.back().Y << std::endl; } // std::cerr << " " << std::endl; Polygon poly2; dist = 100; for (double a = 0; a < 360; a += 1) { dist += int(rand()%3) - 1; Point p(static_cast<int>(dist * std::cos(a/180.0*3.1415)), static_cast<int>(dist * std::sin(a/180.0*3.1415))); if ( a ==0) poly2.add(p); else poly2.add((poly2.back() + p) / 2); // std::cerr << poly2.back().X << ", " << poly2.back().Y << std::endl; } creationTime += timer.restart(); ClosestPolygonPoint result1 (poly1); ClosestPolygonPoint result2 (poly2); findSmallestConnection(result1, result2, 240); totalLength += vSize(result1.location - result2.location); evalTime += timer.restart(); // std::cerr << " " << std::endl; // std::cerr << result1.location.X << " , " << result1.location.Y << std::endl; // std::cerr << result2.location.X << " , " << result2.location.Y << std::endl; // std::cerr << " " << std::endl; } std::cerr << "creationTime : " << creationTime << std::endl; std::cerr << "evalTime : " << evalTime << std::endl; std::cerr << "totalLength : " << totalLength << std::endl; }
void SetTimeCommand::execute(){ time.setAllTime(timeValue); }
void Simulation::simulationInverseYield(string in_args, vector<string>& input_files, bool binary_conf, double dimensionless_number, string input_scale, string control_variable, string simu_identifier) { control_var = control_variable; setupSimulation(in_args, input_files, binary_conf, dimensionless_number, input_scale, simu_identifier); int jammed = 0; time_t now; time_strain_1 = 0; now = time(NULL); time_strain_0 = now; /******************** OUTPUT INITIAL DATA ********************/ sys.calcStress(); outputData(); // new outputConfigurationBinary(); outputConfigurationData(); /*************************************************************/ TimeKeeper tk; tk.addClock("data", LinearClock(p.time_interval_output_data, input_values["time_interval_output_data"].unit == "strain")); tk.addClock("config", LinearClock(p.time_interval_output_config, input_values["time_interval_output_config"].unit == "strain")); int binconf_counter = 0; while (keepRunning()) { pair<double, string> t = tk.nextTime(); pair<double, string> s = tk.nextStrain(); if (t.second.empty()) { // no next time sys.timeEvolution(-1, s.first); } else if (s.second.empty()) { // no next strain sys.timeEvolution(t.first, -1); } else { // either next time or next strain sys.timeEvolution(t.first, s.first); } set<string> output_events = tk.getElapsedClocks(sys.get_time(), sys.get_curvilinear_strain()); generateOutput(output_events, binconf_counter); cout << "time: " << sys.get_time() << " / " << p.time_end << endl; if (!sys.zero_shear && abs(sys.get_shear_rate()) < p.rest_threshold) { cout << "shear jamming " << jammed << endl; jammed ++; if (jammed > 20) { sys.set_shear_rate(1); cout << "target_stress = " << target_stress_input << endl; target_stress_input *= 0.95; sys.target_stress = target_stress_input/6/M_PI; throw runtime_error("use of updateUnscaledContactmodel() invalid"); // sys.updateUnscaledContactmodel(); cout << "new target_stress = " << target_stress_input << endl; jammed = 0; } } else { jammed = 0; } if (time_strain_1 == 0 && sys.get_curvilinear_strain() > 1) { now = time(NULL); time_strain_1 = now; timestep_1 = sys.get_total_num_timesteps(); } } now = time(NULL); time_strain_end = now; timestep_end = sys.get_total_num_timesteps(); outputComputationTime(); string filename_parameters = input_files[1]; if (filename_parameters.find("init_relax", 0) != string::npos) { /* To prepare relaxed initial configuration, * we can use Brownian simulation for a short interval. * Here is just to export the position data. */ string filename_configuration = input_files[0]; outputFinalConfiguration(filename_configuration); } }
int ConstraintConsensus::Run(Point &S){ //cout << "ConstraintConsensus: Run" << endl; lPoints.clear(); lPoints.push_back(S); lTimes.clear(); TimeKeeper Tk; //start measuring elapsed time lTimes.push_back(0.0); //give inital point time zero Point *P = &lPoints.back(); //get the initial point int nvar=P->m_pModel->n_var; //store number of variables locally int ncon=P->m_pModel->n_con; //store number of constraints locally int n_inf; //number of infeasible constraints FeasibilityVector Fv(nvar); //create feasibiltiy vector instance FeasibilityVector *pFv; //ptr to feasibility vector pFv = &Fv; //assign pointer if(P->getMaxVio()<FeasThres){ //check if initial point is feasible //cout << "initial point is feasible" << endl; return 0; //return successfully without doing anything more } else{ //cout << "MaxVio of initial point is: " << P->getMaxVio() << endl; } for(int u=0; u<mu; u++){ //MAIN LOOP: repeat mu times //cout << "u: " << u << endl; n_inf=0; //initialize loop if(u>0) //if not initial loop P=&lPoints.back(); //get the most recent point for(int i=0; i<P->m_pModel->nlc; i++){ //for every nonlinear constraint if(abs(P->getConVio(i))>0.0){ //if constraint i violated if(Fv.calc(P,i) > pow(alpha,2)){ //if feasibility distance > than feasibility tolerance n_inf++; //constraint is infeasible at current point updateCounters(pFv,P); } } } if(n_inf==0){ //no violated constraints? //cout << "No violated nonlinear constraints!" << endl; return 0; //then exit successfully } if(calcCv(nvar)<pow(beta,2)){ //||cv||^2 < beta^2, is the concensus vector less than the movement tolerance return 1; //return unsuccessfully due to lack of movement } else{ //cout << "make copy of point" << endl; Point nP(*P); //make copy of current point if(nP.addVec(cv, nvar)>0){ //add the consensus vector to the new point //cout << "Error: Basic::Run(): calculating new iterate" << endl; return 1; } //cout << "maxVio: " << nP.getMaxVio() << " time: " << Tk.getElapsedTimeSec() << endl; lPoints.push_back(nP); //add new point to list lTimes.push_back(Tk.getElapsedTimeSec()); if(Tk.getElapsedTimeSec()>maxTime){ //cout << "CC out of time!" << endl; return 3; } } } //cout << "Run() end" << endl; //cout << "CC out of iterations!" << endl; return 2; //did not exit within main loop };
ExperimentalApp() : GLFWApp(1280, 800, "Geometric Algorithm Development App") { glfwSwapInterval(0); igm.reset(new gui::ImGuiManager(window)); gui::make_dark_theme(); fixedTimer.start(); lights[0] = {{0, 10, -10}, {0, 0, 1}}; lights[1] = {{0, 10, 10}, {0, 1, 0}}; int width, height; glfwGetWindowSize(window, &width, &height); glViewport(0, 0, width, height); grid = RenderableGrid(1, 100, 100); cameraController.set_camera(&camera); camera.look_at({0, 2.5, -2.5}, {0, 2.0, 0}); simpleShader = make_watched_shader(shaderMonitor, "../assets/shaders/simple_vert.glsl", "assets/shaders/simple_frag.glsl"); normalDebugShader = make_watched_shader(shaderMonitor, "../assets/shaders/normal_debug_vert.glsl", "assets/shaders/normal_debug_frag.glsl"); Renderable debugAxis = Renderable(make_axis(), false, GL_LINES); debugAxis.pose = Pose(float4(0, 0, 0, 1), float3(0, 1, 0)); debugModels.push_back(std::move(debugAxis)); // Initial supershape settings supershape = Renderable(make_supershape_3d(16, 5, 7, 4, 12)); supershape.pose.position = {0, 2, -2}; // Initialize PTF stuff { std::array<float3, 4> controlPoints = {float3(0.0f, 0.0f, 0.0f), float3(0.667f, 0.25f, 0.0f), float3(1.33f, 0.25f, 0.0f), float3(2.0f, 0.0f, 0.0f)}; ptf = make_parallel_transport_frame_bezier(controlPoints, 32); for (int i = 0; i < ptf.size(); ++i) { Renderable p = Renderable(make_cube()); ptfBoxes.push_back(std::move(p)); } } // Initialize Parabolic pointer stuff { // Set up the ground plane used as a nav mesh for the parabolic pointer worldSurface = make_plane(48, 48, 96, 96); for (auto & p : worldSurface.vertices) { float4x4 model = make_rotation_matrix({1, 0, 0}, -ANVIL_PI / 2); p = transform_coord(model, p); } worldSurfaceRenderable = Renderable(worldSurface); parabolicPointer = make_parabolic_pointer(worldSurface, params); } // Initialize objects for ballistic trajectory tests { turret.source = Renderable(make_tetrahedron()); turret.source.pose = Pose({-5, 2, 5}); turret.target = Renderable(make_cube()); turret.target.pose = Pose({0, 0, 40}); turret.bullet = Renderable(make_sphere(1.0f)); } float4x4 tMat = mul(make_translation_matrix({3, 4, 5}), make_rotation_matrix({0, 0, 1}, ANVIL_PI / 2)); auto p = make_pose_from_transform_matrix(tMat); std::cout << tMat << std::endl; std::cout << p << std::endl; gl_check_error(__FILE__, __LINE__); }