void add_to(view<T> out) const { if (out.size() != in_.size()) throw size_mismatch(); for (size_t i = 0; i != in_.size(); ++i) out.data()[i] += in_[i]; }
void add_to(view<T> out) const { if (out.size() != (size_t)in_.rows()) throw size_mismatch(); typename eigen<T>::col_map out_map(out.data(), out.size()); out_map += in_; }
void draw(cairo_t* cr = NULL) { cairo_t* target = cr; if (subject->buffered || !cr) { if (!buffer) { buffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, subject->size.x, subject->size.y); } } else { if (buffer) { cairo_surface_destroy(buffer); buffer = NULL; } } if (buffer) { target = cairo_create(buffer); } if (cr) { cairo_save(cr); cairo_translate(cr, subject->position.x, subject->position.y); } subject->draw(target, this); if (buffer) { cairo_destroy(target); } if (cr && target != cr) { cairo_set_source_surface(cr, buffer, 0, 0); cairo_paint(cr); } if (cr) { cairo_restore(cr); } }
void cone::gl_render(view& scene) { if (degenerate()) return; init_model(scene); clear_gl_error(); // See sphere::gl_render() for a description of the level of detail calc. double coverage = scene.pixel_coverage( pos, radius); int lod = 0; if (coverage < 0) lod = 5; else if (coverage < 10) lod = 0; else if (coverage < 30) lod = 1; else if (coverage < 90) lod = 2; else if (coverage < 250) lod = 3; else if (coverage < 450) lod = 4; else lod = 5; lod += scene.lod_adjust; if (lod < 0) lod = 0; else if (lod > 5) lod = 5; gl_matrix_stackguard guard; const double length = axis.mag(); model_world_transform( scene.gcf, vector( length, radius, radius ) ).gl_mult(); color.gl_set(opacity); if (translucent()) { gl_enable cull_face( GL_CULL_FACE); // Render the back half. glCullFace( GL_FRONT); scene.cone_model[lod].gl_render(); // Render the front half. glCullFace( GL_BACK); scene.cone_model[lod].gl_render(); } else { scene.cone_model[lod].gl_render(); } check_gl_error(); }
void sphere::gl_render( view& geometry) { if (degenerate()) return; //init_model(); init_model(geometry); // coverage is the radius of this sphere in pixels: double coverage = geometry.pixel_coverage( pos, radius); int lod = 0; if (coverage < 0) // Behind the camera, but still visible. lod = 4; else if (coverage < 30) lod = 0; else if (coverage < 100) lod = 1; else if (coverage < 500) lod = 2; else if (coverage < 5000) lod = 3; else lod = 4; lod += geometry.lod_adjust; // allow user to reduce level of detail if (lod > 5) lod = 5; else if (lod < 0) lod = 0; gl_matrix_stackguard guard; model_world_transform( geometry.gcf, get_scale() ).gl_mult(); color.gl_set(opacity); if (translucent()) { // Spheres are convex, so we don't need to sort gl_enable cull_face( GL_CULL_FACE); // Render the back half (inside) glCullFace( GL_FRONT ); geometry.sphere_model[lod].gl_render(); // Render the front half (outside) glCullFace( GL_BACK ); geometry.sphere_model[lod].gl_render(); } else { // Render a simple sphere. geometry.sphere_model[lod].gl_render(); } }
int32_t write(uint32_t start_index, uint32_t length, freepie_io_6dof_data *data_to_write) { auto error = check_conditions_and_init_memory(start_index, length); if(error < 0) return error; auto mapped_data = mapping.map(); for(auto i = start_index; i < length + start_index; i++) { mapped_data[i].data_id++; mapped_data[i].data = data_to_write[i - start_index]; } return 0; }
int32_t read(uint32_t start_index, uint32_t length, freepie_io_6dof_data *output) { auto error = check_conditions_and_init_memory(start_index, length); if(error < 0) return error; auto mapped_data = mapping.map(); int32_t new_values = 0; for(auto i = start_index; i < length + start_index; i++) { if(make_equal(data_ids[i], mapped_data[i].data_id)) continue; output[i - start_index] = mapped_data[i].data; new_values |= (1 << (i - start_index)); } return new_values; }
void add_to(view<T> out) const { if (out.size() != 1) throw size_mismatch(); out.data()[0] += in_; }
bool operator==(view lhs, view rhs) { return (lhs.length() == rhs.length()) && (std::memcmp(lhs.data(), rhs.data(), lhs.length()) == 0); }
namespace freepie_io { struct shared_data { int32_t data_id; freepie_io_6dof_data data; }; const size_t MaxGenericSlots = 4; typedef shared_data shared_data_array[MaxGenericSlots]; shared_memory<shared_data_array> memory; view<shared_data_array> mapping; std::map<uint32_t, int32_t> data_ids; void init_shared_memory() { if(!memory) memory = shared_memory<shared_data_array>("FPGeneric"); if(memory && !mapping) mapping = memory.open_view(); } int32_t check_conditions_and_init_memory(uint32_t start_index, uint32_t length) { if(start_index + length > MaxGenericSlots) return FREEPIE_IO_ERROR_OUT_OF_BOUNDS; init_shared_memory(); if(!memory || !mapping) return FREEPIE_IO_ERROR_SHARED_DATA; return 0; } int32_t write(uint32_t start_index, uint32_t length, freepie_io_6dof_data *data_to_write) { auto error = check_conditions_and_init_memory(start_index, length); if(error < 0) return error; auto mapped_data = mapping.map(); for(auto i = start_index; i < length + start_index; i++) { mapped_data[i].data_id++; mapped_data[i].data = data_to_write[i - start_index]; } return 0; } template<typename T> bool make_equal(T &first, T &second) { if(first == second) return true; first = second; return false; } int32_t read(uint32_t start_index, uint32_t length, freepie_io_6dof_data *output) { auto error = check_conditions_and_init_memory(start_index, length); if(error < 0) return error; auto mapped_data = mapping.map(); int32_t new_values = 0; for(auto i = start_index; i < length + start_index; i++) { if(make_equal(data_ids[i], mapped_data[i].data_id)) continue; output[i - start_index] = mapped_data[i].data; new_values |= (1 << (i - start_index)); } return new_values; } }