em2d::Images get_projections(const ParticlesTemp &ps, const RegistrationResults ®istration_values, int rows, int cols, const ProjectingOptions &options, Strings names) { IMP_LOG_VERBOSE("Generating projections from registration results" << std::endl); if (options.save_images && (names.size() < registration_values.size())) { IMP_THROW("get_projections: Insufficient number of image names provided", IOException); } unsigned long n_projs = registration_values.size(); em2d::Images projections(n_projs); // Precomputation of all the possible projection masks for the particles MasksManagerPtr masks( new MasksManager(options.resolution, options.pixel_size)); masks->create_masks(ps); for (unsigned long i = 0; i < n_projs; ++i) { IMP_NEW(em2d::Image, img, ()); img->set_size(rows, cols); img->set_was_used(true); String name = ""; if (options.save_images) name = names[i]; get_projection(img, ps, registration_values[i], options, masks, name); projections[i] = img; } return projections; }
vector<float> euclid_lsh::calculate_lsh(const common::sfv_t& query) const { vector<float> hash(mixable_storage_->get_model()->all_lsh_num()); for (size_t i = 0; i < query.size(); ++i) { const uint32_t seed = common::hash_util::calc_string_hash(query[i].first); const vector<float> proj = get_projection(seed); for (size_t j = 0; j < hash.size(); ++j) { hash[j] += query[i].second * proj[j]; } } for (size_t j = 0; j < hash.size(); ++j) { hash[j] /= bin_width_; } return hash; }
void InterpolatedCamera::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_SCENE: { if (get_scene()->is_editor_hint() && enabled) set_fixed_process(false); } break; case NOTIFICATION_PROCESS: { if (!enabled) break; if (has_node(target)) { Spatial *node = get_node(target)->cast_to<Spatial>(); if (!node) break; float delta = speed*get_process_delta_time(); Transform target_xform = node->get_global_transform(); Transform local_transform = get_transform(); local_transform = local_transform.interpolate_with(target_xform,delta); set_global_transform(local_transform); if (node->cast_to<Camera>()) { Camera *cam = node->cast_to<Camera>(); if (cam->get_projection()==get_projection()) { float new_near = Math::lerp(get_znear(),cam->get_znear(),delta); float new_far = Math::lerp(get_zfar(),cam->get_zfar(),delta); if (cam->get_projection()==PROJECTION_ORTHOGONAL) { float size = Math::lerp(get_size(),cam->get_size(),delta); set_orthogonal(size,new_near,new_far); } else { float fov = Math::lerp(get_fov(),cam->get_fov(),delta); set_perspective(fov,new_near,new_far); } } } } } break; } }
void Flyer::draw() { glUseProgram(program); // Send in additional params glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, get_projection()); glUniformMatrix4fv(glGetUniformLocation(program, "baseMatrix"), 1, GL_FALSE, get_base().data()); float t = glutGet(GLUT_ELAPSED_TIME)/500.0; glUniform1f(glGetUniformLocation(program, "t"), t); DrawModel(object); }
int UbermasterProcess::main_loop() { boost::timer::auto_cpu_timer t; program_options.splash_screen(); //parse the options program_options.startup(); // tests for existence of necessary files, etc. //if desired, display the options if (program_options.verbose_level()>=3) program_options.display_current_options(); parse_preproc_data("preproc_data", &solve_options.PPD); int num_vars = get_num_vars_PPD(solve_options.PPD); NumericalIrreducibleDecomposition witness_data; witness_data.populate(&solve_options.T); WitnessSet W = witness_data.choose(program_options); if (W.num_points()==0) { std::cout << "no witness points, cannot decompose anything..." << std::endl; return 1; } W.get_variable_names(num_vars); W.set_input_filename(program_options.input_filename()); if (program_options.verbose_level()>=1) { W.print_to_screen(); } VertexSet V(num_vars); V.set_tracker_config(&solve_options.T); V.set_same_point_tolerance(1e1*solve_options.T.real_threshold); vec_mp *pi = (vec_mp *) br_malloc(W.dimension()*sizeof(vec_mp )); for (int ii=0; ii<W.dimension(); ii++) { init_vec_mp2(pi[ii],W.num_variables(), solve_options.T.AMP_max_prec); pi[ii]->size = W.num_variables(); } get_projection(pi, program_options, W.num_variables(), W.dimension()); for (int ii=0; ii<W.dimension(); ii++) { V.add_projection(pi[ii]); } if (program_options.primary_mode()==BERTINIREAL) { bertini_real(W,pi,V); } else if(program_options.primary_mode()==CRIT) { critreal(W,pi,V); } for (int ii=0; ii<W.dimension(); ii++) clear_vec_mp(pi[ii]); free(pi); // dismiss the workers int sendme = TERMINATE; MPI_Bcast(&sendme, 1, MPI_INT, 0, MPI_COMM_WORLD); return SUCCESSFUL; }
void Ground::draw() { static const int x = 0; static const int y = 1; static const int z = 2; print_error("display ground00"); glUseProgram(program); print_error("display ground0"); Vector3f camera_position = dynamic_cast<Camera*>(parent)->position(); glUniform3fv(glGetUniformLocation(program, "camera_position"), 1, camera_position.data()); camera_position[1] = config["base_level"].as<float>(0.0); base.translation() = camera_position; // Send in additional params glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, get_projection()); glUniformMatrix4fv(glGetUniformLocation(program, "baseMatrix"), 1, GL_FALSE, get_base().data()); print_error("display ground1"); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0 print_error("display ground3"); glBindVertexArray(groundVertexArrayObjectID); // Select VAO glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0L); print_error("display ground4"); }
int main(int argc, char** argv) { // initialize guacamole gua::init(argc, argv); auto load_mat = [](std::string const& file){ gua::MaterialShaderDescription desc; desc.load_from_file(file); auto shader(std::make_shared<gua::MaterialShader>(file, std::make_shared<gua::MaterialShaderDescription>(desc))); gua::MaterialShaderDatabase::instance()->add(shader); return shader->make_new_material(); }; // setup scene gua::SceneGraph graph("main_scenegraph"); gua::TriMeshLoader loader; auto transform = graph.add_node<gua::node::TransformNode>("/", "transform"); // load material and create monkey geometry auto projective_material(load_mat("data/materials/Projective_Texture_Material.gmd")); projective_material->set_uniform("projective_texture", std::string("data/textures/smiley.jpg")); auto monkey(loader.create_geometry_from_file("monkey", "data/objects/monkey.obj", projective_material, gua::TriMeshLoader::NORMALIZE_POSITION | gua::TriMeshLoader::NORMALIZE_SCALE)); monkey->scale(3); monkey->translate(0.0, 0.0, -1.0); graph.add_node("/transform", monkey); auto light2 = graph.add_node<gua::node::LightNode>("/", "light2"); light2->data.set_type(gua::node::LightNode::Type::POINT); light2->data.brightness = 150.0f; light2->scale(12.f); light2->translate(-3.f, 5.f, 5.f); auto screen = graph.add_node<gua::node::ScreenNode>("/", "screen"); screen->data.set_size(gua::math::vec2(1.92f, 1.08f)); screen->translate(0, 0, 1.0); // add mouse interaction gua::utils::Trackball trackball(0.01, 0.002, 0.2); // setup rendering pipeline and window auto resolution = gua::math::vec2ui(1920, 1080); auto camera = graph.add_node<gua::node::CameraNode>("/screen", "cam"); camera->translate(0, 0, 2.0); camera->config.set_resolution(resolution); camera->config.set_screen_path("/screen"); camera->config.set_scene_graph_name("main_scenegraph"); camera->config.set_output_window_name("main_window"); camera->config.set_enable_stereo(false); camera->get_pipeline_description()->add_pass(std::make_shared<gua::DebugViewPassDescription>()); // projector transform node, screen and transform node auto projector_transform = graph.add_node<gua::node::TransformNode>("/", "projector_transform"); projector_transform->translate(0.7, 0.0, 0.7); projector_transform->rotate(45.0, 0.0, 1.0, 0.0); graph.add_node("/", projector_transform); auto projector_screen = graph.add_node<gua::node::ScreenNode>("/projector_transform", "projector_screen"); projector_screen->data.set_size(gua::math::vec2(0.5f, 0.5f)); projector_screen->translate(0.0, 0.0, -1.0); graph.add_node("/projector_transform", projector_screen); auto projector_geometry(loader.create_geometry_from_file("projector_geometry", "data/objects/projector.obj", gua::TriMeshLoader::NORMALIZE_POSITION | gua::TriMeshLoader::LOAD_MATERIALS)); projector_geometry->scale(0.1); graph.add_node("/projector_transform", projector_geometry); auto window = std::make_shared<gua::GlfwWindow>(); gua::WindowDatabase::instance()->add("main_window", window); window->config.set_enable_vsync(false); window->config.set_size(resolution); window->config.set_resolution(resolution); window->config.set_stereo_mode(gua::StereoMode::MONO); window->on_resize.connect([&](gua::math::vec2ui const& new_size) { window->config.set_resolution(new_size); camera->config.set_resolution(new_size); screen->data.set_size(gua::math::vec2(0.001 * new_size.x, 0.001 * new_size.y)); }); window->on_move_cursor.connect([&](gua::math::vec2 const& pos) { trackball.motion(pos.x, pos.y); }); window->on_button_press.connect(std::bind(mouse_button, std::ref(trackball), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); window->open(); gua::Renderer renderer; // application loop gua::events::MainLoop loop; gua::events::Ticker ticker(loop, 1.0/500.0); ticker.on_tick.connect([&]() { // apply trackball matrix to object gua::math::mat4 modelmatrix = scm::math::make_translation(gua::math::float_t(trackball.shiftx()), gua::math::float_t(trackball.shifty()), gua::math::float_t(trackball.distance())) * gua::math::mat4(trackball.rotation()); projector_transform->set_transform(modelmatrix); // use the guacamole frustum to calculate a view mat and projection mat for the projection auto projection_frustum = gua::Frustum::perspective(projector_transform->get_world_transform(), projector_screen->get_scaled_world_transform(), 0.1f, 1000.0f); auto projection_mat = projection_frustum.get_projection(); auto view_mat = projection_frustum.get_view(); // set these matrices as uniforms for the projection material projective_material->set_uniform("projective_texture_matrix", gua::math::mat4f(projection_mat * view_mat)); projective_material->set_uniform("view_texture_matrix", gua::math::mat4f(view_mat)); window->process_events(); if (window->should_close()) { renderer.stop(); window->close(); loop.stop(); } else { renderer.queue_draw({&graph}); } }); loop.start(); return 0; }