ROSOutAppender::ROSOutAppender() : shutting_down_(false) , publish_thread_(boost::bind(&ROSOutAppender::logThread, this)) { AdvertiseOptions ops; ops.init<rosgraph_msgs::Log>(names::resolve("/rosout"), 0); ops.latch = true; SubscriberCallbacksPtr cbs(boost::make_shared<SubscriberCallbacks>()); TopicManager::instance()->advertise(ops, cbs); }
int GameClientApp::main() { Trace("Game start"); std::ofstream logFile("log.txt"); FileFormatter fileFormatter; core::logging::Sink fileSink(core::logging::g_globalManager, logFile, core::util::BitSet< LL >() | LL::Error | LL::Info | LL::Trace | LL::Warning | LL::User1 | LL::User2 | LL::User3 | LL::User4, fileFormatter); game::Settings settings; if (!appshared::parseProtoFromFile("./data/client_settings.pb", settings)) { Log(LL::Warning) << "Missing or corrupt game_settings.pb in runtime directory. " << "Game may fail." << std::endl; #if FISHY_DEBUG settings = game::Settings::Builder(settings) .set_login_server(core::net::ServerDef::Builder() .set_connection_timeout_sec(60) .set_dns_name("localhost") .set_port(12002) .set_max_connections(20) .build()) .build(); #endif } volatile bool active = true; volatile bool hidden = false; core::window::Window window; core::input::InputManager inputManager; if (!settings.has_window_settings()) { const game::WindowSettings &windowSettings = settings.get_window_settings(); core::window::DisplayCaps displaySettings = window.getSettings(); displaySettings.m_fullScreen = windowSettings.has_fullscreen() ? windowSettings.get_fullscreen() : false; displaySettings.m_width = windowSettings.has_width() ? static_cast<u32>(windowSettings.get_width()) : 1024u; displaySettings.m_height = windowSettings.has_height() ? static_cast<u32>(windowSettings.get_height()) : 640u; displaySettings.m_lockCursor = windowSettings.has_lock_cursor() ? windowSettings.get_lock_cursor() : false; displaySettings.m_hideCursor = windowSettings.has_hide_cursor() ? windowSettings.get_hide_cursor() : false; window.setSettings(displaySettings); } Callbacks cbs(active, hidden, inputManager, window); window.setCallbackInterface(&cbs); window.setTitle("Silent Star"); window.create(); GameLoop loop(active, hidden, settings, inputManager, window); loop.run(); window.destroy(); core::logging::g_globalManager.unregisterSink(fileSink); return eExitCode::OK; }
void UlamElement_Test::Test_RunTests() { for (u32 i = 0; i < sizeof(allCases)/sizeof(allCases[0]); ++i) { CharBufferByteSource cbs(allCases[i].mangled, strlen(allCases[i].mangled)); UlamTypeInfo utin; assert(utin.InitFrom(cbs)); OString512 os; utin.PrintMangled(os); assert(!strcmp(allCases[i].mangled,os.GetZString())); os.Reset(); utin.PrintPretty(os); assert(!strcmp(allCases[i].pretty,os.GetZString())); } }
int main(int argc, char** argv) { // Fetch a bootstrap object. The bootstrap object is a special 'root' object // from which you can get at everything else. CreateCellMLBootstrap() is a // C++ binding specific method, which fetches the CellMLBootstrap object. // It is the only non-OO method that you should ever call from the CellML // API. // ObjRef is a template defined in cellml-api-cxx-support.hpp. CreateCellMLBootstrap // has already_Addrefd<iface::cellml_api::CellMLBootstrap> as its return type, // which is the signal that a reference is added (i.e. the reference count is // incremented on the return value, and the caller must ensure it is decremented). // ObjRef will, when given an already_Addrefd argument, not increment the reference // count, but will decrement it when it goes out of scope. If an ObjRef is constructed // from a pointer or another ObjRef, it will add a reference on construction, // and release the reference on destruction. ObjRef<iface::cellml_api::CellMLBootstrap> cbs(CreateCellMLBootstrap()); // Now would be a good time to see what methods we can call. In the // CellML_DOM_API source, find interfaces/CellML_APISPEC.idl. // This defines the interfaces you can call. Search down to find // this text... /* interface CellMLBootstrap : XPCOM::IObject { ... */ // We want to load a model, so we want the modelLoader attribute. We fetch // the attribute like this... ObjRef<iface::cellml_api::DOMModelLoader> ml(cbs->modelLoader()); // Suppose we only had a general model loader... ObjRef<iface::cellml_api::ModelLoader> generalModelLoader(ml); // if we wanted to get from this to a DOM model loader, we can't just cast, // because the API is designed so it can work through bridges and we might // need to switch to a different bridge (you can cast from an interface to a // parent interface in the inheritance hierarchy, but not the other way). // Instead, we call query_interface to ask the underlying object if it // supports the interface we want, and to return us a value. ObjRef<iface::cellml_api::DOMModelLoader> ml2(do_QueryInterface(generalModelLoader)); // ml2 would be null if generalModelLoader didn't support DOMModelLoader. // Start a try, because we might get an exception... try { // We now have a DOMModelLoader, stored in ml. DOMModelLoader inherits from // ModelLoader, which defines a loadFromURL operation (check in the IDL). // Be warned that is a synchronous (blocking) load. In a real application, // you are probably better to download the file using another asynchronous // http library, and then creating the model from the serialised text. ObjRef<iface::cellml_api::Model> model(ml->loadFromURL(L"http://www.cellml.org/models/beeler_reuter_1977_version04/download")); // Fetch the models cmeta:id (there obviously lots of other things we could // do here!) std::wstring cmid = model->cmetaId(); printf("Model's cmeta:id is %S\n", cmid.c_str()); } // Most parts of the CellML API raise this exception. The DOM/MathML API, on the // other hand, raises iface::dom::DOMException. catch (iface::cellml_api::CellMLException&) { // Unfortunately, due to the need to support the 'lowest common // denominator' of functionality in our bindings, exceptions can't have // supplementary information (to suit XPCOM). However, many classes have // a way to get the last error, e.g. lastErrorMessage on ModelLoader. // However, threadsafety is potentially an issue with this. std::wstring msg = ml->lastErrorMessage(); printf("Got a CellML Exception loading a model. Error was %S\n", msg.c_str()); return 1; } return 0; }
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; }