BOOL CTomGineThread::OnTask() { m_running.Lock(); m_mutex.Lock(); tgEngine m_engine(m_width, m_height, 5.0f, 0.01f, "TomGine", true); if(m_use_campars) { TomGine::tgCamera cam; cam.Load(m_camPars); m_engine.SetCamera(cam); m_engine.UpdateCameraViews(cam); } m_mutex.Unlock(); tgMaterial matBlueBlend; matBlueBlend.Color(0.0f, 0.0f, 1.0f, 0.5f); m_cone.m_material = matBlueBlend; tgShapeCreator m_shape_creator; m_shape_creator.CreateSphere(m_sphere, 0.1, 5, ICOSAHEDRON); m_shape_creator.CreateCone(m_cone, 1.0, 1.0, 16, 1, false); // tgModel &model, float radius, float height, int slices, int stacks, bool closed glClearColor(1,1,1,0); while(!m_quit) { m_mutex.Lock(); // Draw model m_pose.Activate(); m_model.DrawFaces(); // for(unsigned i=0; i<m_viewlist.size(); i++) // { // m_viewlist[i].Activate(); // m_cone.DrawFaces(); // } // TODO test if Siftex is visible // Draw points glColor3f(0.0f,1.0f,0.0f); glDisable(GL_LIGHTING); glPointSize(2); glBegin(GL_POINTS); for(unsigned int i=0; i<m_siftexlist.size(); i++) { glVertex3f(m_siftexlist[i].pos.x, m_siftexlist[i].pos.y, m_siftexlist[i].pos.z); } glEnd(); glEnable(GL_LIGHTING); // Draw normals glColor3f(0.0f, 0.0f, 1.0f); glDisable(GL_LIGHTING); glBegin(GL_LINES); for(unsigned int i=0; i<m_lastsiftexlist.size(); i++) { glVertex3f(m_lastsiftexlist[i].pos.x, m_lastsiftexlist[i].pos.y, m_lastsiftexlist[i].pos.z); glVertex3f( m_lastsiftexlist[i].pos.x - m_lastsiftexlist[i].viewray.x, m_lastsiftexlist[i].pos.y - m_lastsiftexlist[i].viewray.y, m_lastsiftexlist[i].pos.z - m_lastsiftexlist[i].viewray.z); } glEnd(); glEnable(GL_LIGHTING); for(unsigned i=0; i<m_viewlist.size(); i++) { m_viewlist[i].Activate(); glPushMatrix(); glScalef(m_viewscale[i].x,m_viewscale[i].y,m_viewscale[i].z); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); m_cone.DrawFaces(); glDisable(GL_BLEND); glPopMatrix(); m_viewlist[i].Deactivate(); } m_pose.Deactivate(); m_mutex.Unlock(); Sleep(10); m_engine.Update(); } m_running.Unlock(); return TRUE; }
int main(int argc, char * argv[]) { sf::RenderWindow window(sf::VideoMode(640, 480), "OpenGL"); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); g_Resources->SetShaderPath("/home/gergondet/ros/perception_blort/blort_ros/Tracker/shader/"); TomGine::tgCamera::Parameter camPar; TomGine::tgCamera camera; camPar.width = 640; camPar.height = 480; camPar.fx = 568.168672; camPar.fy = 566.360327; camPar.cx = 349.631248; camPar.cy = 256.295344; camPar.k1 = -0.059636; camPar.k2 = 0.232352; camPar.k3 = 0; camPar.p1 = -0.003432; camPar.p2 = 0.017361; camPar.pos.x = 0.31188; camPar.pos.y = -0.3; camPar.pos.z = 0.243049; vec3 rotv; rotv.x = -1.917587; rotv.y = -0.453044; rotv.z = 0.389306; camPar.rot.fromRotVector(rotv); camera.Load(camPar); Tracking::TrackerModel * model = new Tracking::TrackerModel(); Tracking::ModelLoader loader; loader.LoadPly(*model, "/home/gergondet/ros/perception_blort/blort_ros/Resources/ply/can.ply"); bool running = true; while (running) { // handle events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { // end the program running = false; } else if (event.type == sf::Event::Resized) { // adjust the viewport when the window is resized glViewport(0, 0, event.size.width, event.size.height); } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); window.clear(sf::Color(0x77, 0x77, 0x77, 255)); window.pushGLStates(); window.popGLStates(); camera.Activate(); model->drawPass(); window.display(); } delete model; return 0; }
int main (int argc, char * argv[]) { std::string tsp_file; size_t width(800), height(600); int start(0), end(1), res(16); if (argc > 3) { tsp_file = argv[1]; start = atoi(argv[2]); end = atoi(argv[3]); } else { printf("Usage: TsplineViewer tsp_file_sequence start_index end_index\n"); printf(" tsp-file-sequence: filename_%%d.tsp\n\n"); return 0; } if(argc > 4) res = atoi(argv[4]); std::ostringstream os; os << "T-spline Sequence (" << tsp_file << ")"; tgTomGineThread viewer (width, height, os.str()); viewer.SetClearColor(1.0f); viewer.SetInputSpeeds(0.1); // schnipp TomGine::tgCamera cam = viewer.GetCamera(); // dino_sparse_front float ext_data[16] = { -0.382363, -0.097398, -0.918871, 0.000105, -0.181148, 0.983042, -0.028819, -0.027788, 0.906093, 0.155430, -0.393519, -0.365332, 0.000000, 0.000000, 0.000000, 1.000000 }; // dino float int_data[16] = { 10.344999, 0.000000, 0.010219, 0.000000, 0.000000, 13.856250, -0.164375, 0.000000, 0.000000, 0.000000, -1.000200, -0.020002, 0.000000, 0.000000, -1.000000, 0.000000}; TomGine::mat4 E(ext_data); TomGine::mat4 I(int_data); cam.SetIntrinsic(I.transpose()); cam.SetExtrinsic(E.transpose()); viewer.SetCamera(cam); // schnapp SequenceViewer sv(viewer); sv.meshes.resize(end-start+1); for(int i=start; i<=end && !viewer.Stopped(); i++) { // Tspline char file[256]; sprintf(file, tsp_file.c_str(), i); printf("[main] Loading T-spline %d: '%s'\n", i, file); Tspline tsp; File::Load(tsp, file); TomGine::tgTextureModel& mesh = sv.meshes[i]; mesh.m_material.Color( 0.1,0.1,0.1,1.0, 0.6,1.0,0.6,1.0, 0.5,0.5,0.5,1.0, 50); mesh.SetColor(0.5f,0.5f,0.5f,0.5f); convertTspline2tgModel(tsp, mesh, res, res, true); convertTsplineControl2tgModel(tsp, mesh); // convertTsplineEdges2tgModel(tsp, mesh, 4, 1e-4); mesh.m_line_color = TomGine::vec3(0,0,0); mesh.m_line_width = 5.0f; mesh.m_point_color = TomGine::vec3(0,0,0); mesh.m_point_size = 15.0f; if(!tsp.texture.empty()) { // texture from tspline printf("[main] tseigen normalizep.texture.size: %lu tsp.texture: %s\n", tsp.texture.size(), tsp.texture.c_str()); unsigned found = tsp_file.find_last_of("/\\"); std::string texture = tsp_file.substr(0,found) + "/" + tsp.texture; mesh.m_tex_cv.push_back(cv::imread(texture)); mesh.m_face_tex_id.assign(mesh.m_faces.size(), 0); mesh.SetColor(1.0f,1.0f,1.0f); } // convertTsplineControl2tgModel(tsp, mesh); // TomGine::vec3 cor(0,0,0); // for(size_t i=0; i<mesh.m_lines.size(); i++) // { // vec3 a = mesh.m_lines[i].start; // vec3 b = mesh.m_lines[i].end; // viewer.AddLine3D(a.x,a.y,a.z, b.x,b.y,b.z, 0,0,128, 1.0); // } // size_t cpi(0); // Tspline::Vertex_iterator vit; // for(vit=tsp.vertices_begin(); vit!=tsp.vertices_end(); vit++) // { // Point3d cp = vit->data().GetCP(); // viewer.AddPoint3D(cp.x(),cp.y(),cp.z(), 0,0,255, 5.0f); // std::ostringstream os; // os << cpi; // viewer.AddLabel3D(os.str(), 12, cp.x(),cp.y(),cp.z()); // cor+=vec3(cp.x(),cp.y(),cp.z()); // cpi++; // } // cor /= cpi; // viewer.LookAt(cor); // viewer.SetRotationCenter(cor); // mesh.m_lines.clear(); // mesh.m_points.clear(); // convertTsplineEdges2tgModel(tsp, mesh, 4); // mesh.m_line_color = TomGine::vec3(1,0,0); // mesh.m_line_width = 4.0; if(i==start) { mesh.ComputeBoundingSphere(); viewer.SetInputSpeeds(1.0f, mesh.m_bs.radius, mesh.m_bs.radius); viewer.SetRotationCenter(mesh.m_bs.center); } } printf("[main] Loading T-splines done\n"); // viewer.AddModel3D(meshes); viewer.Update(); viewer.WaitForEvent (TMGL_Press, TMGL_Escape); return (0); }