Qt_widget::Qt_widget(QWidget *parent, const char *name) : QWidget(parent, name), set_scales_to_be_done(false), Locked(0), _pointSize(4), _pointStyle(DISC) { setCaption("CGAL::Qt_widget"); // initialize ranges and scales xmin_old = xmin = -1; xmax_old = xmax = 1; ymin_old = ymin = -1; ymax_old = ymax = 1; constranges=false; set_scales(); emit(rangesChanged()); // initialize the pixmap and the painter painter = new QPainter; printer = new QPrinter; pixmap = new QPixmap; matrix = new QWMatrix; pixmap->resize(size()); painter->begin(pixmap); painter->setWorldMatrix(*matrix); // set properties painter->setRasterOp(CopyROP); setBackgroundColor(Qt::white); painter->setPen(QPen(Qt::black,2)); clear(); }
void Qt_widget::showEvent(QShowEvent* e) { if( set_scales_to_be_done ) set_scales(); return QWidget::showEvent(e); }
void analizer::load_file(char * _filename){ filename = _filename; pattern_generator -> load_file(_filename); set_scales(); set_date(); set_station_id(); }
void Qt_widget::resizeEvent(QResizeEvent*) { resize_pixmap(); xmin = xmin_old; xmax = xmax_old; ymin = ymin_old; ymax = ymax_old; set_scales(); redraw(); }
void Qt_widget::set_window(const double x_min, const double x_max, const double y_min, const double y_max, bool const_ranges) { xmin_old = xmin = x_min; xmax_old = xmax = x_max; ymin_old = ymin = y_min; ymax_old = ymax = y_max; constranges = const_ranges; set_scales(); redraw(); emit(rangesChanged()); }
void GL_widget_2::set_window(double x_min, double x_max, double y_min, double y_max) { xmin_old = xmin = x_min; xmax_old = xmax = x_max; ymin_old = ymin = y_min; ymax_old = ymax = y_max; set_scales(); double xratio,yratio,bxmin,bxmax,bymin,bymax; switch (rendering_effect) { case RENDERING_PENCIL: pbuffer->makeCurrent(); xratio = 2048.0/width(); bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2; bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2; yratio = 2048.0/height(); bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2; bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2; glViewport(0,0,2048,2048); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(bxmin, bxmax, bymin, bymax, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; default: makeCurrent(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(xmin, xmax, ymin, ymax, -1, 1); break; } repaintGL(); // updateGL(); }
void GL_widget_2::set_center(const double x, const double y) { if(xscal<1) { xmin = x - (int)(width()/xscal)/2; xmax = x + (int)(width()/xscal)/2; ymin = y - (int)(height()/yscal)/2; ymax = y + (int)(height()/yscal)/2; } else { xmin = x - (width()/xscal)/2; xmax = x + (width()/xscal)/2; ymin = y - (height()/yscal)/2; ymax = y + (height()/yscal)/2; } // this is so that we can not zoom out higher than the maximum rendering area (for infinite lines and rays) bool need_set_scales = false; double new_min, new_max; if (xmax > GL_MAX_DRAWING_COORDINATE) { xmax = GL_MAX_DRAWING_COORDINATE; new_min=(ymin+ymax)/2-(ymax-ymin)/100; new_max=(ymin+ymax)/2+(ymax-ymin)/100; ymin=new_min; ymax=new_max; need_set_scales = true; } if (xmin < -GL_MAX_DRAWING_COORDINATE) { xmin = -GL_MAX_DRAWING_COORDINATE; new_min=(ymin+ymax)/2-(ymax-ymin)/100; new_max=(ymin+ymax)/2+(ymax-ymin)/100; ymin=new_min; ymax=new_max; need_set_scales = true; } if (ymax > GL_MAX_DRAWING_COORDINATE) { ymax = GL_MAX_DRAWING_COORDINATE; new_min=(xmin+xmax)/2-(xmax-xmin)/100; new_max=(xmin+xmax)/2+(xmax-xmin)/100; xmin=new_min; xmax=new_max; need_set_scales = true; } if (ymin < -GL_MAX_DRAWING_COORDINATE) { ymin = -GL_MAX_DRAWING_COORDINATE; new_min=(xmin+xmax)/2-(xmax-xmin)/100; new_max=(xmin+xmax)/2+(xmax-xmin)/100; xmin=new_min; xmax=new_max; need_set_scales = true; } if (need_set_scales) set_scales(); xmin_old = xmin; xmax_old = xmax; ymin_old = ymin; ymax_old = ymax; double xratio,yratio,bxmin,bxmax,bymin,bymax; switch (rendering_effect) { case RENDERING_PENCIL: pbuffer->makeCurrent(); xratio = 2048.0/width(); bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2; bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2; yratio = 2048.0/height(); bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2; bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2; glViewport(0,0,2048,2048); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(bxmin, bxmax, bymin, bymax, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; default: makeCurrent(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(xmin, xmax, ymin, ymax, -1, 1); break; } repaintGL(); }
void GL_widget_2::initializeGL () { makeCurrent(); init_common(); set_scales(); //init shaders glewInit(); if (glewIsSupported("GL_VERSION_2_0")) { std::cout << "OpenGL 2.0 is supported" << std::endl; GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); std::cout << "Maximum texture size: " << texSize << std::endl; char *vs,*fs; GLuint f,v; v = glCreateShader(GL_VERTEX_SHADER); f = glCreateShader(GL_FRAGMENT_SHADER); vs = read_text_from_file(":/pencil.vert"); fs = read_text_from_file(":/pencil.frag"); const char * vv = vs; const char * ff = fs; glShaderSource(v, 1, &vv,NULL); glShaderSource(f, 1, &ff,NULL); free(vs);free(fs); glCompileShader(v); int success; glGetShaderiv(v, GL_COMPILE_STATUS, &success); if (success!=GL_TRUE) std::cout << LOG_ERROR << "Vertex shader NOT compiled" << std::endl; glCompileShader(f); glGetShaderiv(f, GL_COMPILE_STATUS, &success); if (success!=GL_TRUE) std::cout << LOG_ERROR << "Fragment shader NOT compiled" << std::endl; npr_shader_program = glCreateProgram(); glAttachShader(npr_shader_program,v); glAttachShader(npr_shader_program,f); glLinkProgram(npr_shader_program); glGetProgramiv(npr_shader_program, GL_LINK_STATUS, &success); if (success!=GL_TRUE) std::cout << LOG_ERROR << "Shader program NOT compiled" << std::endl; glUseProgram(npr_shader_program); GLint noise_uniform = glGetUniformLocation(npr_shader_program, "hatchmap"); // glGenTextures(1, &noise_texture); glActiveTexture(GL_TEXTURE0+6); noise_texture = bindTexture(QPixmap(":/perlin.png"), GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, noise_texture); noise_uniform = glGetUniformLocation(npr_shader_program, "hatchmap"); glUniform1i(noise_uniform,6); glActiveTexture(GL_TEXTURE0); paper_texture = bindTexture(QPixmap(":/paper.png"), GL_TEXTURE_2D); QSettings settings; GLint hatchscale_location = glGetUniformLocation(npr_shader_program, "hatchScale"); glUniform1f(hatchscale_location, settings.value("npr-render-distortion").toDouble()); GLint edge_location = glGetUniformLocation(npr_shader_program, "edgeSize"); glUniform1f(edge_location, settings.value("npr-render-edge-detection-width").toDouble()); //glBindTexture(GL_TEXTURE_2D, paper_texture); //glBindTexture( GL_TEXTURE_2D, 0); glUseProgram(0); } else { std::cout << LOG_ERROR << "OpenGL 2.0 is not supported" << std::endl; } double xratio,yratio,bxmin,bxmax,bymin,bymax, half_width,half_height; switch (rendering_effect) { case RENDERING_PENCIL: // free old pencil buffer if exists if (pbuffer) { pbuffer->releaseFromDynamicTexture(); glDeleteTextures(1, &dynamic_texture); delete pbuffer; } // create new pencil buffer and init pbuffer = new QGLPixelBuffer(QSize(2048, 2048), format(), this); pbuffer->makeCurrent(); init_common(); // generate texture that has the same size/format as the pbuffer dynamic_texture = pbuffer->generateDynamicTexture(); // bind the dynamic texture to the pbuffer - this is a no-op under X11 pbuffer->bindToDynamicTexture(dynamic_texture); // set projection matrix such that the 2048x2048 covers the view screen xratio = 2048.0/width(); bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2; bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2; yratio = 2048.0/height(); bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2; bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2; glViewport(0,0,2048,2048); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(bxmin, bxmax, bymin, bymax, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // update the widget projection such that it is a window in the middle of 2048x2048 makeCurrent(); glViewport(0, 0, width(), height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); half_width=width()/2; half_height=height()/2; glOrtho(1024-half_width, 1024+half_width, 1024-half_height, 1024+half_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; default: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width(), 0, height(), -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; } }
void GL_widget_2::resizeGL ( int w, int h ) { xmin = xmin_old; xmax = xmax_old; ymin = ymin_old; ymax = ymax_old; emit widget_resized_to(QRect(0,0,w,h)); set_scales(); double xratio,yratio,bxmin,bxmax,bymin,bymax, half_width,half_height; switch (rendering_effect) { case RENDERING_PENCIL: // free old pencil buffer if exists if (pbuffer) { pbuffer->releaseFromDynamicTexture(); glDeleteTextures(1, &dynamic_texture); delete pbuffer; } // create new pencil buffer and init pbuffer = new QGLPixelBuffer(QSize(2048, 2048), format(), this); pbuffer->makeCurrent(); init_common(); // generate texture that has the same size/format as the pbuffer dynamic_texture = pbuffer->generateDynamicTexture(); // bind the dynamic texture to the pbuffer - this is a no-op under X11 pbuffer->bindToDynamicTexture(dynamic_texture); // set projection matrix such that the 2048x2048 covers the view screen xratio = 2048.0/w; bxmin = ((1-xratio)*xmax + (1+xratio)*xmin)/2; bxmax = ((1+xratio)*xmax + (1-xratio)*xmin)/2; yratio = 2048.0/h; bymin = ((1-yratio)*ymax + (1+yratio)*ymin)/2; bymax = ((1+yratio)*ymax + (1-yratio)*ymin)/2; glViewport(0,0,2048,2048); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(bxmin, bxmax, bymin, bymax, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // update the widget projection such that it is a window in the middle of 2048x2048 makeCurrent(); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); half_width=width()/2; half_height=height()/2; glOrtho(1024-half_width, 1024+half_width, 1024-half_height, 1024+half_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; default: makeCurrent(); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(xmin, xmax, ymin, ymax, -1, 1); break; } }
void GL_widget_2::repaintGL() { set_scales(); updateGL(); emit repaitedGL(); }