int main(int argc, char** argv) { cout<<"start\n"; wiringPiSetupGpio(); pinMode(16,INPUT); pullUpDnControl(16, PUD_UP); pinMode(19,INPUT); pullUpDnControl(19, PUD_UP); int p1= digitalRead(19); int p2= digitalRead(16); Driver driver = Driver(); driver.scan(); Checkerboard cb = Checkerboard(driver.table); RGB ledBoard[8][8]; driver.clear_led(); while(cb.canStart(driver) == false){ } bool player1 = false; bool player2 = false; if(p1 == 1) player1=true; if(p2 == 1) player2=true; cout << "P1: " << player1 << endl; cout << "P2: " << player2 << endl; game checkers; checkers.playTheGame(player1, player2, driver, cb); return 0; }
void Initialize() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // glOrtho(-1.0, 1.0, -1.0, 1.0, -3.0, 3.0); // Lighting set up glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); // Set lighting intensity and color GLfloat qaAmbientLight[] = {0.1, 0.1, 0.1, 1.0}; GLfloat qaDiffuseLight[] = {0.8, 0.8, 0.8, 1.0}; GLfloat qaSpecularLight[] = {0.6, 0.6, 0.6, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, qaDiffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight); glMaterialf(GL_FRONT, GL_SHININESS, 30); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Set the light position GLfloat qaLightPosition[] = {4.0, 2.0, 3.0, 5.0}; glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition); checkerboard.create(); Vector4f a = Vector4f(0,0,0,1); Vector4f a1 = Vector4f(1.0,0,0,1); Vector4f b0 = Vector4f(1.5,0,0,1); Vector4f b = Vector4f(2,0,0,1); Vector4f c = Vector4f(3,0,0,1); Vector4f e = Vector4f(4,0,0,1); Vector4f d = Vector4f(1,0,0,0); number_of_arms = 6; Link l0 = Link(a,d,1); arm.push_back(l0); Link l00 = Link(a1, d, 0.5); arm.push_back(l00); Link l1 = Link(b0,d,0.5); arm.push_back(l1); Link l2 = Link(b,d,1); arm.push_back(l2); Link l3 = Link(c,d,1); arm.push_back(l3); Link l4 = Link(e,d,1); arm.push_back(l4); };
int main(int argc, char *argv[]) { PNMreader reader(argv[1]); Crop crop; crop.SetRegion(300, 1400, 50, 400); crop.SetInput(reader.GetOutput()); Transpose t; t.SetInput(crop.GetOutput()); Invert i; i.SetInput(t.GetOutput()); Color color(50, 1101, 0, 0, 128); LRConcat lr; lr.SetInput(color.GetOutput()); lr.SetInput2(i.GetOutput()); Color white(401, 1101, 255, 255, 255); Checkerboard cb; cb.SetInput(lr.GetOutput()); cb.SetInput2(white.GetOutput()); cb.GetOutput()->Update(); PNMwriter writer; writer.SetInput(cb.GetOutput()); writer.Write(argv[2]); /*CheckSum cs; cs.SetInput(cb.GetOutput()); cs.OutputCheckSum("proj3G_checksum");*/ }
int main(int argc, char *argv[]) { if (argc < 2) { cerr << "Usage: " << argv[0] << " <username>" << endl; exit(EXIT_FAILURE); } char event[1024]; sprintf(event, "Entered program from %s\n", argv[1]); Logger::LogEvent(event); /* START STUDENT MODIFIABLE SECTION */ PNMreader reader("../images/puddles.pnm"); Shrinker shrinker1; Shrinker shrinker2; LRConcat lrconcat1; LRConcat lrconcat2; TBConcat tbconcat1; TBConcat tbconcat2; Checkerboard blender; shrinker1.SetInput(reader.GetOutput()); shrinker2.SetInput2(shrinker1.GetOutput()); lrconcat1.SetInput(shrinker1.GetOutput()); lrconcat1.SetInput2(shrinker2.GetOutput()); tbconcat1.SetInput(shrinker1.GetOutput()); tbconcat2.SetInput2(shrinker2.GetOutput()); blender.SetInput(reader.GetOutput()); blender.SetInput2(tbconcat1.GetOutput()); /* Make the image "finalImage" be the image at the bottom of your pipeline */ Image *finalImage = blender.GetOutput(); /* END STUDENT MODIFIABLE SECTION */ try { finalImage->Update(); } catch (DataFlowException &) { ofstream ofile("my_exception"); if (ofile.fail()) { cerr << "Something is wrong ... can't open my_exception" << " for opening" << endl; exit(EXIT_FAILURE); } ofile << "Exception found!" << endl; exit(EXIT_SUCCESS); } CheckSum cs; cs.SetInput(finalImage); cs.OutputCheckSum("my_checksum"); if (argc == 3) { PNMwriter writer; writer.SetInput(finalImage); writer.Write("3H.pnm"); } Logger::Finalize(); }
int main(int argc, char *argv[]) { if (argc < 2) { cerr << "Usage: " << argv[0] << " <username>" << endl; exit(EXIT_FAILURE); } char event[1024]; sprintf(event, "Entered program from %s\n", argv[1]); Logger::LogEvent(event); /* START STUDENT MODIFIABLE SECTION */ PNMreader reader("../images/hank.pnm"); Checkerboard b; Invert i; i.SetInput(reader.GetOutput()); b.SetInput(reader.GetOutput()); b.SetInput2(i.GetOutput()); LRConcat lr; lr.SetInput(i.GetOutput()); lr.SetInput2(b.GetOutput()); LRConcat LR; LR.SetInput(reader.GetOutput()); LR.SetInput2(i.GetOutput()); TBConcat tb; tb.SetInput(lr.GetOutput()); tb.SetInput2(LR.GetOutput()); LRConcat Lr; Lr.SetInput(tb.GetOutput()); Lr.SetInput2(tb.GetOutput()); Image *finalImage = Lr.GetOutput(); /* END STUDENT MODIFIABLE SECTION */ try { finalImage->Update(); } catch (DataFlowException &) { ofstream ofile("my_exception"); if (ofile.fail()) { cerr << "Something is wrong ... can't open my_exception" << " for opening" << endl; exit(EXIT_FAILURE); } ofile << "Exception found!" << endl; exit(EXIT_SUCCESS); } CheckSum cs; cs.SetInput(finalImage); cs.OutputCheckSum("my_checksum"); if (argc == 3) { PNMwriter writer; writer.SetInput(finalImage); writer.Write("3H.pnm"); } Logger::Finalize(); }
int main(int argc, char* argv[]){ std::string pose_offset_filename = "./poseoffset"; unsigned cv_width = 128; unsigned cv_height = 128; unsigned cv_depth = 128; float cv_min_d = 0.5; float cv_max_d = 3.0; bool undistort = false; unsigned idwneighbours = 10; bool using_nni = false; CMDParser p("basefilename samplesfilename checkerboardviewinitfilename"); p.addOpt("p",1,"poseoffetfilename", "specify the filename of the poseoffset on disk, default: " + pose_offset_filename); p.addOpt("s",3,"size", "use this calibration volume size (width x height x depth), default: 128 128 256"); p.addOpt("d",2,"depthrange", "use this depth range: 0.5 4.5"); p.addOpt("u", -1, "undistort", "enable undistortion of images before chessboardsampling, default: false"); p.addOpt("n",1,"numneighbours", "the number of neighbours that should be used for IDW inverse distance weighting, default: 10"); p.addOpt("i",-1,"nni", "do use natural neighbor interpolation if possible, default: false"); p.init(argc,argv); if(p.getArgs().size() != 3) p.showHelp(); if(p.isOptSet("p")){ pose_offset_filename = p.getOptsString("p")[0]; std::cout << "setting poseoffetfilename to " << pose_offset_filename << std::endl; } if(p.isOptSet("s")){ cv_width = p.getOptsInt("s")[0]; cv_height = p.getOptsInt("s")[1]; cv_depth = p.getOptsInt("s")[2]; } if(p.isOptSet("d")){ cv_min_d = p.getOptsInt("d")[0]; cv_max_d = p.getOptsInt("d")[1]; } if(p.isOptSet("u")){ undistort = true; } if(p.isOptSet("n")){ idwneighbours = p.getOptsInt("n")[0]; std::cout << "setting to numneighbours " << idwneighbours << std::endl; } if(p.isOptSet("i")){ using_nni = true; } std::string basefilename = p.getArgs()[0]; std::string filename_xyz(basefilename + "_xyz"); std::string filename_uv(basefilename + "_uv"); const std::string filename_yml(basefilename + "_yml"); std::string filename_samples(p.getArgs()[1]); CalibVolume cv(cv_width, cv_height, cv_depth, cv_min_d, cv_max_d); RGBDConfig cfg; cfg.read(filename_yml.c_str()); RGBDSensor sensor(cfg); Checkerboard cb; cb.load_pose_offset(pose_offset_filename.c_str()); ChessboardSampling cbs(p.getArgs()[2].c_str(), cfg, undistort); cbs.init(); glm::mat4 eye_d_to_world = sensor.guess_eye_d_to_world_static(cbs, cb); std::cerr << "extrinsic of sensor is: " << eye_d_to_world << std::endl; std::cerr << "PLEASE note, the extrinsic guess can be improved by averaging" << std::endl; for(unsigned z = 0; z < cv.depth; ++z){ for(unsigned y = 0; y < cv.height; ++y){ for(unsigned x = 0; x < cv.width; ++x){ const unsigned cv_index = (z * cv.width * cv.height) + (y * cv.width) + x; const float depth = (z + 0.5) * (cv.max_d - cv.min_d)/cv.depth + cv.min_d; const float xd = (x + 0.5) * sensor.config.size_d.x * 1.0/cv.width; const float yd = (y + 0.5) * sensor.config.size_d.y * 1.0/cv.height; glm::vec3 pos3D_local = sensor.calc_pos_d(xd, yd, depth); glm::vec2 pos2D_rgb = sensor.calc_pos_rgb(pos3D_local); pos2D_rgb.x /= sensor.config.size_rgb.x; pos2D_rgb.y /= sensor.config.size_rgb.y; glm::vec4 pos3D_world = eye_d_to_world * glm::vec4(pos3D_local.x, pos3D_local.y, pos3D_local.z, 1.0); xyz pos3D; pos3D.x = pos3D_world.x; pos3D.y = pos3D_world.y; pos3D.z = pos3D_world.z; cv.cv_xyz[cv_index] = pos3D; uv posUV; posUV.u = pos2D_rgb.x; posUV.v = pos2D_rgb.y; cv.cv_uv[cv_index] = posUV; } } } // load samples from filename std::vector<samplePoint> sps; std::ifstream iff(filename_samples.c_str(), std::ifstream::binary); const unsigned num_samples_in_file = calcNumFrames(iff, sizeof(float) + sizeof(uv) + sizeof(uv) + sizeof(xyz) + sizeof(uv) + sizeof(glm::vec3) + sizeof(float)); for(unsigned i = 0; i < num_samples_in_file; ++i){ samplePoint s; iff.read((char*) &s.depth, sizeof(float)); iff.read((char*) &s.tex_color, sizeof(uv)); iff.read((char*) &s.tex_depth, sizeof(uv)); iff.read((char*) &s.pos_offset, sizeof(xyz)); iff.read((char*) &s.tex_offset, sizeof(uv)); iff.read((char*) glm::value_ptr(s.pos_real), sizeof(glm::vec3)); iff.read((char*) &s.quality, sizeof(float)); sps.push_back(s); } iff.close(); // reapply correction offsets for(unsigned i = 0; i < sps.size(); ++i){ const unsigned cv_width = cv.width; const unsigned cv_height = cv.height; const unsigned cv_depth = cv.depth; const float x = cv_width * ( sps[i].tex_depth.u) / cfg.size_d.x; const float y = cv_height * ( sps[i].tex_depth.v)/ cfg.size_d.y; const float z = cv_depth * ( sps[i].depth - cv.min_d)/(cv.max_d - cv.min_d); xyz pos = getTrilinear(cv.cv_xyz, cv_width, cv_height, cv_depth, x , y , z ); uv tex = getTrilinear(cv.cv_uv, cv_width, cv_height, cv_depth, x , y , z ); sps[i].pos_offset.x = sps[i].pos_real[0] - pos.x; sps[i].pos_offset.y = sps[i].pos_real[1] - pos.y; sps[i].pos_offset.z = sps[i].pos_real[2] - pos.z; sps[i].tex_offset.u = sps[i].tex_color.u/cfg.size_rgb.x - tex.u; sps[i].tex_offset.v = sps[i].tex_color.v/cfg.size_rgb.y - tex.v; sps[i].quality = 1.0f; } Calibrator c; c.using_nni = using_nni; c.applySamples(&cv, sps, cfg, idwneighbours, basefilename.c_str()); cv.save(filename_xyz.c_str(), filename_uv.c_str()); return 0; }
Checkerboard::Checkerboard(const Checkerboard & board) : _size(board.getSize()),_square(board.getQSquare()) { }
void myDraw(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, 1, 0.5, 80); // glOrtho(20, 20, 20, 20, 0.5, 20); // Set material properties glMaterialfv(GL_FRONT, GL_AMBIENT, qaRed); glMaterialfv(GL_FRONT, GL_DIFFUSE, qaRed); glMaterialfv(GL_FRONT, GL_SPECULAR, qaWhite); glMaterialf(GL_FRONT, GL_SHININESS, 128.0); glLightfv(GL_LIGHT0, GL_AMBIENT, qaLowAmbient); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(lookfrmx, lookfrmy, lookfrmz, lookatx, lookaty, lookatz, lookupx, lookupy, lookupz); glRotatef(default_orbit, 1, 0.0f, 0.0f); glRotatef(default_orbit2, 0.0f, 1, 0.0f); //**************** Draw something segment, function call required *************** curve_init(curve_name); checkerboard.draw(); draw_wall(); for(int i = 0; i < number_of_arms; i++){ drawCone(arm[i]); } Vector3D theta2xyz; if (curve_name == "Torus"){ theta2xyz = Torus_knot(goal_theta); } else if (curve_name == "Tornado"){ theta2xyz = Tornado(goal_theta); } goal_x = theta2xyz.x; goal_y = theta2xyz.y; goal_z = theta2xyz.z; // cout << real_x << " " << real_y << " " << real_z << endl; Vector4f goal = Vector4f(goal_x, goal_y, goal_z, 1); // cout << "now goal's y is " << goal[1] << endl; reachGoal(goal); glMaterialfv(GL_FRONT, GL_AMBIENT, qaGreen); drawpoint(goal); // cout << "arm's configuration is now: " << arm[3].direction << endl; for ( int i = 0; i < number_of_arms; i++) { glMaterialfv(GL_FRONT, GL_AMBIENT, qaBlue); glColor3f( 0.95f, 0.207, 0.031f ); Vector4f point = arm[i].startpoint; if (i==number_of_arms-1){ Vector4f endpoint = arm[number_of_arms-1].startpoint + arm[number_of_arms-1].get_link_direction()*arm[number_of_arms-1].length; drawpoint(point); // drawline(point, endpoint); cout << "end arm directs at: \n" << endpoint-point << endl; drawpoint(endpoint); } else{ Vector4f point2 = arm[i+1].startpoint; drawpoint(point); // drawline(point, point42); } } if (on_start){ goal_theta += goal_delta; glutPostRedisplay(); } //**************** Draw something segment, function call required *************** glFlush(); glutSwapBuffers(); }