1#include "image_drawable.h" 
    3#include <cgv/media/image/image_reader.h> 
    4#include <cgv/media/image/image_writer.h> 
    5#include <cgv/media/axis_aligned_box.h> 
    6#include <cgv/base/import.h> 
    7#include <cgv/math/ftransform.h> 
    8#include <cgv/render/attribute_array_binding.h> 
    9#include <cgv_gl/gl/gl_tools.h> 
   10#include <cgv_gl/gl/gl.h> 
   22image_drawable::image_drawable() : 
min_value(0,0,0,0), 
max_value(1,1,1,1), gamma4(1,1,1,1)
 
   41    pan_tilt = 
vec2(0.0f);
 
   43    k1 = k2 = k3 = k4 = k5 = k6 = p1 = p2 = 0.0f;
 
   44    checker_lambda = 0.0f;
 
 
   51    if (tex_ids.size() > 1 && start_time != -2) {
 
   53            if (start_time == -1) {
 
   56                for (
unsigned i = 0; 
i<current_image; ++
i) {
 
   57                    start_time -= durations[
i];
 
   58                    anim_time += durations[
i];
 
   63                if (
dt > anim_time+durations[current_image]) {
 
   64                    while (
dt > anim_time+durations[current_image]) {
 
   65                        anim_time += durations[current_image];
 
   67                        if (current_image >= tex_ids.size()) {
 
   69                            start_time += anim_time;
 
 
   89    std::vector<vertex> 
V;
 
   90    V.push_back({ 
vec2(-1.0f,-1.0f), 
vec2(0.0f,0.0f) });
 
   91    V.push_back({ 
vec2( 1.0f,-1.0f), 
vec2(1.0f,0.0f) });
 
   92    V.push_back({ 
vec2( 1.0f, 1.0f), 
vec2(1.0f,1.0f) });
 
   93    V.push_back({ 
vec2(-1.0f, 1.0f), 
vec2(0.0f,1.0f) });
 
   96    aab.
set_attribute_array(ctx, 0, cgv::render::get_element_type(
V.front().position), vbo, 0, 
V.size(), 
sizeof(vertex));
 
   98    aab.
set_attribute_array(ctx, 1, cgv::render::get_element_type(
V.front().texcoord), vbo, 
offsetof(vertex, texcoord), 
V.size(), 
sizeof(vertex));
 
 
  109    if (!tex_ids.empty())
 
 
  135    for (
unsigned i=0; 
i<
_files.size(); ++
i) {
 
  137            true, &aspect, &use_blending);
 
  140        tex_ids.push_back(tex_id);
 
  141        durations.push_back(0.04f);
 
 
  172    if (files.size() > 
nr)
 
  175    for (
unsigned i=0; 
i<
nr; ++
i) {
 
  177        if (
i < files.size()) {
 
  182        std::vector<data_format> palette_formats;
 
  189            std::cerr << 
ir.get_last_error().c_str() << std::endl;
 
  192        palettes.resize(palette_formats.size());
 
  203        unsigned nr = 
ir.get_nr_images();
 
  205        for (
unsigned i=0; 
i<
nr; ++
i) {
 
  207            for (
unsigned j=0; 
j<palette_formats.size(); ++
j) {
 
  211            double duration = 
ir.get_image_duration();
 
  212            if (!
ir.read_image(dv)) {
 
  213                std::cerr << 
ir.get_last_error() << std::endl;
 
  222                for (
int j=0; 
j<h; ++
j) {
 
  229                std::cerr << 
iw.get_last_error() << std::endl;
 
 
  247        ctx.
mul_modelview_matrix(cgv::math::translate4<double>(-1, -1, 0) * cgv::math::scale4<double>(2.0 / 
W, 2.0 / H, 1));
 
  253        P.push_back(
vec2(x, y));
 
  254        P.push_back(
vec2(x + w, y));
 
  255        P.push_back(
vec2(x + w, y + h));
 
  256        P.push_back(
vec2(x, y + h));
 
  269    if (tex_ids.size() > 0) {
 
  274        if (use_mixing && mix_with != -1 && mix_with < tex_ids.size()) {
 
  280        if (start_time == -2)
 
  297        prog.
set_uniform(ctx, 
"checker_lambda", checker_lambda);
 
  309        prog.
set_uniform(ctx, 
"use_texture", tex_ids.size() > 0);
 
  310        prog.
set_uniform(ctx, 
"tessellation_level", tess_level);
 
 
complete implementation of method actions that only call one method when entering a node
 
size_t get_step_size(unsigned int dim) const
return the step size in bytes in the i-th dimension
 
cgv::type::func::transfer_const< P, S * >::type get_ptr() const
return a data pointer to type S
 
the data view gives access to a data array of one, two, three or four dimensions.
 
bool enable(context &ctx)
enable whole the attribute array binding object
 
static bool enable_global_array(const context &ctx, int loc)
enable attribute array of given location
 
bool create(const context &ctx)
create the attribute array binding object
 
void destruct(const context &ctx)
destruct attribute array binding object
 
static bool set_global_attribute_array(const context &ctx, int loc, const vertex_buffer &vbo, type_descriptor td, size_t size, size_t offset, unsigned stride=0)
point array of vertex attribute at location loc to vertex buffer array array stored in CPU memory; in...
 
bool disable(context &ctx)
disable whole attribute array binding object
 
static bool disable_global_array(const context &ctx, int loc)
disable attribute array of given location
 
bool enable_array(const context &ctx, int loc)
enable array for vertex attribute at location loc
 
bool set_attribute_array(const context &ctx, int loc, const T &array)
set vertex attribute location to given array and enable array
 
base class for all drawables, which is independent of the used rendering API.
 
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
 
virtual void set_color(const rgba &clr)
set the current color
 
virtual shader_program & ref_default_shader_program(bool texture_support=false)=0
return a reference to a shader program used to render without illumination
 
void pop_modelview_matrix()
see push_V for an explanation
 
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
 
void tesselate_unit_square(bool flip_normals=false, bool edges=false)
tesselate a unit square in the xy-plane with texture coordinates
 
void post_redraw()
posts a redraw event to the current context if one is available
 
void clear(context &)
destruct textures and shader program
 
image_drawable()
construct base image drawable
 
bool init(context &)
construct shader program
 
void timer_event(double t, double dt)
timer event that can be used for animation, connect this to some animation trigger
 
bool save_images(const std::string &output_file_name)
function to save all images
 
bool read_images(const std::string &_file_name, const std::vector< std::string > &_files)
function to read a list of images
 
bool read_image(const std::string &_file_name)
function to read a single image
 
bool show_selection
whether to show the selection rectangle
 
ibox2 selection
extent selection box
 
void draw(context &)
draw the image
 
a shader program combines several shader code fragments to a complete definition of the shading pipel...
 
bool enable(context &ctx)
enable the shader program
 
bool disable(context &ctx)
disable shader program and restore fixed functionality
 
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
 
void destruct(const context &ctx)
destruct shader program
 
bool is_linked() const
return whether program is linked
 
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false)
successively calls create, attach_program and link.
 
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
 
void destruct(const context &ctx)
destruct the render buffer
 
the base namespace holds the base hierarchy, support for plugin registration and signals
 
namespace for data management components
 
bool read_image_to_textures(const std::string &file_name, std::vector< unsigned > &tex_ids, std::vector< float > &durations, bool mipmaps, double *aspect_ptr, bool *has_alpha_ptr)
read several images from one image file that can contain an animation
 
unsigned int read_image_to_texture(const std::string &file_name, bool mipmaps, double *aspect_ptr, bool *has_alpha_ptr)
read the given image file into a texture and return the texture id or -1 in case of failure.
 
namespace for api independent GPU programming
 
namespace that holds tools that dont fit any other namespace
 
T min_value(ForwardIt first, ForwardIt last, T fallback)
Find the minimum value in the range [first, last) or return fallback if the range is empty.
 
T max_value(ForwardIt first, ForwardIt last, T fallback)
Find the maximum value in the range [first, last) or return fallback if the range is empty.
 
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
 
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
 
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors