Пример #1
0
    virtual void on_draw()
    {
        pixfmt pf(rbuf_window());
        renderer_base ren_base(pf);
        ren_base.clear(agg::rgba(1.0, 1.0, 0.95));
        renderer_scanline ren(ren_base);

        rasterizer_scanline ras;
        scanline sl;

        // Pattern source. Must have an interface:
        // width() const
        // height() const
        // pixel(int x, int y) const
        // Any agg::renderer_base<> or derived
        // is good for the use as a source.
        //-----------------------------------
        pattern_src_brightness_to_alpha p1(rbuf_img(0));
        pattern_src_brightness_to_alpha p2(rbuf_img(1));
        pattern_src_brightness_to_alpha p3(rbuf_img(2));
        pattern_src_brightness_to_alpha p4(rbuf_img(3));
        pattern_src_brightness_to_alpha p5(rbuf_img(4));
        pattern_src_brightness_to_alpha p6(rbuf_img(5));
        pattern_src_brightness_to_alpha p7(rbuf_img(6));
        pattern_src_brightness_to_alpha p8(rbuf_img(7));
        pattern_src_brightness_to_alpha p9(rbuf_img(8));

        agg::pattern_filter_bilinear_rgba<color_type> fltr;           // Filtering functor

        // agg::line_image_pattern is the main container for the patterns. It creates
        // a copy of the patterns extended according to the needs of the filter.
        // agg::line_image_pattern can operate with arbitrary image width, but if the 
        // width of the pattern is power of 2, it's better to use the modified
        // version agg::line_image_pattern_pow2 because it works about 15-25 percent
        // faster than agg::line_image_pattern (because of using simple masking instead 
        // of expensive '%' operation). 
        typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba<color_type> > pattern_type;
        typedef agg::renderer_base<pixfmt> base_ren_type;
        typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type;
        typedef agg::rasterizer_outline_aa<renderer_type>                rasterizer_type;

        //-- Create with specifying the source
        //pattern_type patt(fltr, src);   

        //-- Create uninitialized and set the source
        pattern_type patt(fltr);        
        renderer_type ren_img(ren_base, patt);
        rasterizer_type ras_img(ren_img);

        draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve());
        draw_curve(patt, ras_img, ren_img, p2, m_curve2.curve());
        draw_curve(patt, ras_img, ren_img, p3, m_curve3.curve());
        draw_curve(patt, ras_img, ren_img, p4, m_curve4.curve());
        draw_curve(patt, ras_img, ren_img, p5, m_curve5.curve());
        draw_curve(patt, ras_img, ren_img, p6, m_curve6.curve());
        draw_curve(patt, ras_img, ren_img, p7, m_curve7.curve());
        draw_curve(patt, ras_img, ren_img, p8, m_curve8.curve());
        draw_curve(patt, ras_img, ren_img, p9, m_curve9.curve());

        agg::render_ctrl(ras, sl, ren_base, m_curve1);
        agg::render_ctrl(ras, sl, ren_base, m_curve2);
        agg::render_ctrl(ras, sl, ren_base, m_curve3);
        agg::render_ctrl(ras, sl, ren_base, m_curve4);
        agg::render_ctrl(ras, sl, ren_base, m_curve5);
        agg::render_ctrl(ras, sl, ren_base, m_curve6);
        agg::render_ctrl(ras, sl, ren_base, m_curve7);
        agg::render_ctrl(ras, sl, ren_base, m_curve8);
        agg::render_ctrl(ras, sl, ren_base, m_curve9);

        agg::render_ctrl(ras, sl, ren_base, m_scale_x);
        agg::render_ctrl(ras, sl, ren_base, m_start_x);
    }
Пример #2
0
void display(void){
  glClear(GL_COLOR_BUFFER_BIT);

  glPushMatrix();
  tbMatrix();
  //Drawing the points
  glPointSize(5);

  glBegin(GL_POINTS);
  for (int i = 0; i < points->size(); i++){
    double * coordinates = (*points)[i].coor;
    if ((*points)[i].cluster->ref == 0)
      glColor3f(1,1,1);
    else if ((*points)[i].cluster->ref == 1)
      glColor3f(1,0,0);
    else if ((*points)[i].cluster->ref == 2)
      glColor3f(0,1,0);
    else if ((*points)[i].cluster->ref == 3)
      glColor3f(0,0,1);
    else if ((*points)[i].cluster->ref == 4)
      glColor3f(0,1,1);
    
    glVertex3f(coordinates[0]/SCALE,coordinates[1]/SCALE,coordinates[2]/SCALE);
    //cout<<coordinates[0]<<" "<<coordinates[1]<<" "<<coordinates[2]<<endl;
  }
    
  glEnd();

  glPopMatrix();
  
  double centers[num_of_clusters][4];
  
    for (std::vector<POINT>::iterator it=points->begin(); it<points->end(); it++) {
        centers[(*it).cluster->ref][0]+=(*it).coor[0];
        centers[(*it).cluster->ref][1]+=(*it).coor[1];
        centers[(*it).cluster->ref][2]+=(*it).coor[2];
        centers[(*it).cluster->ref][3]+=1;
    }
    for (int cluster = 0; cluster<num_of_clusters; cluster++) {
        centers[cluster][0]/=centers[cluster][3];
        centers[cluster][1]/=centers[cluster][3];
        centers[cluster][2]/=centers[cluster][3];
    }//Find the center of each cluster


    GLfloat Ctrl[4][3];
    for (std::vector<POINT>::iterator this_cluster=points->begin(); this_cluster<points->end(); this_cluster++) {
        for (std::vector<POINT>::iterator other_cluster=points->begin(); other_cluster<points->end(); other_cluster++) {
            if ((*this_cluster).cluster->ref == (*other_cluster).cluster->ref) {
                continue;
            }
            Ctrl[0][0] = (*this_cluster).coor[0];
            Ctrl[0][1] = (*this_cluster).coor[1];
            Ctrl[0][2] = (*this_cluster).coor[2];
            Ctrl[1][0] = centers[(*this_cluster).cluster->ref][0];
            Ctrl[1][1] = centers[(*this_cluster).cluster->ref][1];
            Ctrl[1][2] = centers[(*this_cluster).cluster->ref][2];
            Ctrl[2][0] = centers[(*other_cluster).cluster->ref][0];
            Ctrl[2][1] = centers[(*other_cluster).cluster->ref][1];
            Ctrl[2][2] = centers[(*other_cluster).cluster->ref][2];
            Ctrl[3][0] = (*other_cluster).coor[0];
            Ctrl[3][1] = (*other_cluster).coor[1];
            Ctrl[3][2] = (*other_cluster).coor[2];
    		draw_curve(Ctrl);
		}
    }//Compute the control points

  for(int this_center = 0; this_center<num_of_clusters; this_center++){
  	for(int next_center = this_center+1; next_center<num_of_clusters; next_center++){
	  glLineWidth(2.5); 
	  glColor3f(1.0, 1.0, 1.0);
	  glBegin(GL_LINES);
	  glVertex3f(centers[this_center][0]/SCALE,centers[this_center][1]/SCALE, centers[this_center][2]/SCALE);
	  glVertex3f(centers[next_center][0]/SCALE,centers[next_center][1]/SCALE, centers[next_center][2]/SCALE);
	  glVertex3f(15, 0, 0);
	  glEnd();
	}
  }

  for(std::vector<POINT>::iterator this_point=points->begin(); this_point<points->end(); this_point++){
  	glLineWidth(2.5); 
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_LINES);
	glVertex3f((*this_point).coor[0]/SCALE,(*this_point).coor[1]/SCALE,(*this_point).coor[2]/SCALE);
	glVertex3f(centers[(*this_point).cluster->ref][0]/SCALE,centers[(*this_point).cluster->ref][1]/SCALE,centers[(*this_point).cluster->ref][2]/SCALE);
	glEnd();
  }

  std::cout << "done" << std::endl;

  glutSwapBuffers();
}
void Canvas_Delegate_Riemann_Mapping::paint_event()
{
    /*if (left_canvas_)
    {
        std::cout << "Entering left Canvas_Delegate_Riemann_Mapping::paint_event" << std::endl;
    }
    else
    {
        std::cout << "Entering right Canvas_Delegate_Riemann_Mapping::paint_event" << std::endl;
    }*/

    if (image_mode_ && *draw_2_curves_flag_ == DRAWING_CURVES && !shower_)
    {
        draw_background_image();
    }


    if (tiling_->nb_vertices()>0 && *draw_2_curves_flag_ == DRAWING_CURVES)
    {
        draw_tiling(*tiling_);
    }

    if ((*draw_2_curves_flag_ == DRAWING_CURVES || !shower_)
            && input_triangulation_->nb_triangles() > 0)
    {
        if (input_triangulation_->nb_triangles() == input_triangulation_->nb_colors())
        {
            if (shower_)
            {
                draw_empty_triangulation(*input_triangulation_);
            }
            else
            {

                if (image_mode_)
                {
                    draw_triangulation_from_image();
                }
                else
                {
                    draw_triangulation(*input_triangulation_);
                }
            }
        }
        else
        {
            std::cout << "ERROR in Canvas_Delegate_Riemann_Mapping::paint_event: tried to draw unfit triangulation" << std::endl;
        }
    }
    else if(shower_)
    {
        if (image_mode_)
        {
            draw_shower_triangulation_from_image();
        }
        else
        {
            draw_triangulation(*output_triangulation_);
        }
    }

    if (is_vertex_highlighted_ && (!is_node_point_under_mouse_) && (!is_node_point_selected_) &&
            (*draw_2_curves_flag_==DRAW_2_CURVES_DONE || !shower_) && (!is_tangent_control_point_under_mouse_))
    {
        //std::cout << "about to hightlight triangle" << std::endl;
        if (*draw_2_curves_flag_ == DRAW_2_CURVES_DONE && shower_)
        {
            if (index_vertex_highlighted_ < output_triangulation_->nb_triangles())
            {
                Triangle T;
                if (output_triangulation_->get_triangle(index_vertex_highlighted_, T))
                {
                    mark_triangle(T, QColor("red"));
                }
            }
            else
            {
                std::cout << "ERROR in Canvas_Delegate_Riemann_Mapping::paint_event: tried to draw a triangle with bad index" << std::endl;
            }
        }
        else
        {
            if (index_vertex_highlighted_ < input_triangulation_->nb_triangles())
            {
                Triangle T;
                if (input_triangulation_->get_triangle(index_vertex_highlighted_, T))
                {
                    mark_triangle(T, QColor("red"));
                }
            }
            else
            {
                std::cout << "ERROR in Canvas_Delegate_Riemann_Mapping::paint_event: tried to draw a triangle with bad index" << std::endl;
            }
        }
        //std::cout << "triangle highlighted" << std::endl;
    }

    draw_nodes(*nodes_, nodes_radius_in_pixels_/scale_);

    if (*draw_curve_flag_==DRAW_CURVE_NODES && nodes_->size()>0)
    {
        mark_circle(Circle((*nodes_)[0], nodes_radius_in_pixels_/scale_), QColor("red"));
        draw_incomplete_curve(*nodes_);
    }
    else
    {
        draw_curve(*curve_);
    }

    if (beziers_mode())
    {
        draw_tangents(*nodes_, *tangent_factors_, 0.8*nodes_radius_in_pixels_/scale_);
    }

    if (is_node_point_under_mouse_)
    {
        if(node_point_under_mouse_<nodes_->size())
        {
            mark_circle(Circle((*nodes_)[node_point_under_mouse_], nodes_radius_in_pixels_/scale_), QColor("green"));
        }
        else
        {
            std::cout << "ERROR in Canvas_Delegate_Riemann_Mapping::paint_event: node index problem" << std::endl;
            throw(QString("ERROR in Canvas_Delegate_Riemann_Mapping::paint_event: node index problem"));
        }
    }

    if (is_tangent_control_point_under_mouse_ && !is_node_point_under_mouse_ && beziers_mode())
    {
        if(tangent_control_point_under_mouse_<nodes_->size() && tangent_factors_->size() == nodes_->size())
        {
            unsigned int i = tangent_control_point_under_mouse_, N = nodes_->size();
            Point T((*nodes_)[i].get_affix() +
                    (*tangent_factors_)[i] * ((*nodes_)[(i+1)%N].get_affix() - (*nodes_)[(N+i-1)%N].get_affix()));
            mark_circle(Circle(T, 0.8*nodes_radius_in_pixels_/scale_), QColor("green"));
        }
        else
        {
            std::cout << "ERROR in Canvas_Delegate_Draw_Curve::paint_event: tangent index problem" << std::endl;
            throw(QString("ERROR in Canvas_Delegate_Draw_Curve::paint_event: tangent index problem"));
        }
    }

    /*if (left_canvas_)
    {
        std::cout << "Leaving left Canvas_Delegate_Riemann_Mapping::paint_event" << std::endl;
    }
    else
    {
        std::cout << "Leaving right Canvas_Delegate_Riemann_Mapping::paint_event" << std::endl;
    }*/
    return;
}
Пример #4
0
void mydisplay() {
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_POINT_SMOOTH);
	glEnable(GL_BLEND);
	glPointSize(6.0);

	for (int p = 0; p < qpoints; p++) {

		// Mostra os pontos determinados pelo usuario
		if (!hide_points) {
			glBegin(GL_POINTS);
			glColor3f(0, 0, 0);
			glVertex2f(ds[p].x, ds[p].y);
			glEnd();
		}

		// Poligonal de controle dos pontos escolhidos pelo usuario
		if (qpoints > 1 && !hide_lines && p > 0) {
			glBegin(GL_LINES);
			glColor3f(0, 0, 0);
			glVertex2f(ds[p].x, ds[p].y);
			glVertex2f(ds[p-1].x, ds[p-1].y);
			glEnd();
		}

	}

	// Pinta a curva com no max. 4 pontos escolhidos pelo usuario.
	if (!hide_curve && qpoints > 1 && qpoints <= 4) {

		numpoints = qpoints;

		// Os pontos de controle são os mesmos do usuario
		for (int p = 0; p < qpoints; p++) {
			control_points[p] = ds[p];
		}

		glPointSize(1.5);
		draw_curve();
		glPointSize(6.0);

	// Pinta a curva com mais de 4 pontos
	} else if (qpoints > 4) {

		numpoints = 3*(qpoints-3) + 1;
        
		find_control_points(); // Calcula os pontos de controle para a B-Spline

		if (!hide_control_points) {

			// Pinta os pontos de controle de verde na tela
			for (int p = 0; p < numpoints; p++) {
				glBegin(GL_POINTS);
				glColor3f(0.0, 255.0, 0.0);
				glVertex2f(control_points[p].x, control_points[p].y);
				glEnd();
			}

		}

		// Pinta a poligonal de controle da B-spline
		if (!hide_control_polygon) {

			for (int p = 1; p < numpoints; p++) {
				glBegin(GL_LINES);
				glColor3f(0.0, 250.0, 0.0);
				glVertex2f(control_points[p].x, control_points[p].y);
				glVertex2f(control_points[p-1].x, control_points[p-1].y);
				glEnd();
			}			

		}

		// Pinta a B-spline
		if (!hide_curve) {
			glPointSize(1.5);
			draw_curve();
			glPointSize(6.0);
		}

	}

	glFlush();
}