TFB_ColorMap * TFB_GetColorMap (int index) { TFB_ColorMap *map; LockMutex (maplock); map = get_colormap (index); UnlockMutex (maplock); return map; }
/* Create a new backing pixmap of the appropriate size */ int ScribbleDrawingArea::configure_event_impl (GdkEventConfigure * /* event */) { Gdk_Font font ( "-*-courier-bold-*-*-*-*-240-*-*-*-*-*-*"); list<NNode*>::iterator curnode; list<NNode*> seenlist; Gdk_Color red("red"); Gdk_Color white("white"); Gdk_Color black("black"); get_colormap().alloc(black); get_colormap().alloc(white); char text[20]; win = get_window(); visual = win.get_visual(); if (pixmap) pixmap.release(); pixmap.create(get_window(), width(), height()); if (!gc) { gc = Gdk_GC(pixmap); gc.set_foreground(white); } //gc = get_style()->get_white_gc(); gc.set_foreground(white); pixmap.draw_rectangle (gc, TRUE, 0, 0, width(), height()); //Draw network off of the drawlist drawrows(nodes); return TRUE; }
/* Draw a rectangle on the screen */ void PopulationDrawingArea::draw_brush (gdouble x, gdouble y) { GdkRectangle update_rect; update_rect.x = (int)x - 5; update_rect.y = (int)y - 5; update_rect.width = 5; update_rect.height = 5; // we can't create the brush gc in the ctor because there was not window // so we will initialize it here once, and use it from then on. if (!brush_gc) { brush_gc = Gdk_GC(pixmap); Gdk_Color red("red"); get_colormap().alloc(red); brush_gc.set_foreground(red); } pixmap.draw_rectangle( brush_gc, TRUE, update_rect.x, update_rect.y, update_rect.width, update_rect.height); draw(&update_rect); }
LayerWindow::LayerWindow(MainWindow & mw) : OptionBox("Layers"), m_currentModel(0) { // destroy.connect(slot(this, &LayerWindow::destroy_handler)); // Gtk::VBox * vbox = manage( new Gtk::VBox(false, 2) ); Gtk::VBox * vbox = this; Gtk::HBox * tophbox = manage( new Gtk::HBox() ); tophbox->pack_start(*(manage( new Gtk::Label("Model:") )), Gtk::PACK_SHRINK, 2); m_modelMenu = manage( new Gtk::OptionMenu() ); tophbox->pack_start(*m_modelMenu, Gtk::PACK_EXPAND_WIDGET, 2); tophbox->pack_start(*(manage( new Gtk::Label("WOOT") ) ), Gtk::PACK_SHRINK, 2); vbox->pack_start(*tophbox, Gtk::PACK_SHRINK, 2); m_columns = new Gtk::TreeModelColumnRecord(); m_visColumn = new Gtk::TreeModelColumn<bool>(); m_typeColumn = new Gtk::TreeModelColumn<Glib::ustring>(); m_nameColumn = new Gtk::TreeModelColumn<Glib::ustring>(); m_ptrColumn = new Gtk::TreeModelColumn<Layer*>(); m_columns->add(*m_visColumn); m_columns->add(*m_typeColumn); m_columns->add(*m_nameColumn); m_columns->add(*m_ptrColumn); m_treeModel = Gtk::ListStore::create(*m_columns); m_treeView = manage( new Gtk::TreeView() ); m_treeView->set_model( m_treeModel ); Gtk::CellRendererToggle * crt = manage( new Gtk::CellRendererToggle() ); crt->signal_toggled().connect( sigc::mem_fun(*this, &LayerWindow::visibleToggled) ); int column_no = m_treeView->append_column("Visible", *crt); Gtk::TreeViewColumn * column = m_treeView->get_column(column_no - 1); column->add_attribute(crt->property_active(), *m_visColumn); column->set_clickable(); m_treeView->append_column("Type", *m_typeColumn); m_treeView->append_column("Name", *m_nameColumn); m_refTreeSelection = m_treeView->get_selection(); m_refTreeSelection->set_mode(Gtk::SELECTION_SINGLE); m_refTreeSelection->signal_changed().connect( sigc::mem_fun(*this, &LayerWindow::selectionChanged) ); vbox->pack_start(*manage(new Gtk::HSeparator()), Gtk::PACK_SHRINK); Gtk::ScrolledWindow *scrolled_window = manage(new Gtk::ScrolledWindow()); scrolled_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); scrolled_window->set_size_request(250,150); scrolled_window->add(*m_treeView); vbox->pack_start(*scrolled_window); Gtk::HBox * bothbox = manage( new Gtk::HBox() ); Gtk::Button * b = manage( new Gtk::Button() ); Glib::RefPtr<Gdk::Bitmap> pixmask; Glib::RefPtr<Gdk::Pixmap> p = Gdk::Pixmap::create_from_xpm(get_colormap(), pixmask, newlayer_xpm); b->add_pixmap(p, pixmask); b->signal_clicked().connect(sigc::mem_fun(*this, &LayerWindow::newLayerRequested)); bothbox->pack_start(*b, Gtk::PACK_EXPAND_PADDING, 6); b = manage( new Gtk::Button() ); p = Gdk::Pixmap::create_from_xpm(get_colormap(), pixmask, raise_xpm); b->add_pixmap(p, pixmask); b->signal_clicked().connect(sigc::mem_fun(*this, &LayerWindow::raiseLayer)); bothbox->pack_start(*b, Gtk::PACK_EXPAND_PADDING, 6); b = manage( new Gtk::Button() ); p = Gdk::Pixmap::create_from_xpm(get_colormap(), pixmask, lower_xpm); b->add_pixmap(p, pixmask); b->signal_clicked().connect(sigc::mem_fun(*this, &LayerWindow::lowerLayer)); bothbox->pack_start(*b, Gtk::PACK_EXPAND_PADDING, 6); b = manage( new Gtk::Button() ); p = Gdk::Pixmap::create_from_xpm(get_colormap(), pixmask, duplicate_xpm); b->add_pixmap(p, pixmask); bothbox->pack_start(*b, Gtk::PACK_EXPAND_PADDING, 6); b = manage( new Gtk::Button() ); p = Gdk::Pixmap::create_from_xpm(get_colormap(), pixmask, delete_xpm); b->add_pixmap(p, pixmask); bothbox->pack_start(*b, Gtk::PACK_EXPAND_PADDING, 6); vbox->pack_start(*bothbox, Gtk::PACK_SHRINK, 6); // add(*vbox); // set_title("Layers"); set_sensitive(false); // FIXME Organise the xpms //m_eye = gdk_pixmap_create_from_xpm_d(m_clist->gtkobj()->clist_window, //&m_eyemask, >K_WIDGET(m_clist->gtkobj())->style->white, eye_xpm); //m_null = gdk_pixmap_create_from_xpm_d(m_clist->gtkobj()->clist_window, //&m_nullmask, >K_WIDGET(m_clist->gtkobj())->style->white, null_xpm); m_newLayerWindow = new NewLayerWindow(); // show_all(); mw.modelAdded.connect(sigc::mem_fun(*this, &LayerWindow::modelAdded)); mw.currentModelChanged.connect(sigc::mem_fun(*this, &LayerWindow::currentModelChanged)); signal_delete_event().connect(sigc::mem_fun(*this, &LayerWindow::deleteEvent)); }
//This is an old way of drawing a network by recursively drawing as //program descends through the networks. However, this means //visiting each node potentially mutliple times, which is pointless //when we already have a drawlist which was constructed when the command //to draw was issued and row levels were computed. void ScribbleDrawingArea::drawrows_old(NNode *curnode,list<NNode*> &seenlist) { list<Link*> innodes=curnode->incoming; list<Link*>::iterator curlink; list<NNode*>::iterator location; char text[20]; Gdk_Font font ( "-*-courier-bold-*-*-*-*-240-*-*-*-*-*-*"); Gdk_Color blue("blue"); get_colormap().alloc(blue); Gdk_Color black("black"); get_colormap().alloc(black); Gdk_Color red("red"); get_colormap().alloc(red); if (!((curnode->type)==SENSOR)) { for(curlink=innodes.begin();curlink!=innodes.end();++curlink) { location=find(seenlist.begin(),seenlist.end(),((*curlink)->in_node)); //if (location==seenlist.end()) { seenlist.push_back((*curlink)->in_node); cout<<"Connecting "<<curnode<<" TO "<<((*curlink)->in_node)<<endl; //Draw the node as a rectangle! //gc=get_style()->get_black_gc(); //Only draw each node once, if it hasn't been seen if (location==seenlist.end()) { gc.set_foreground(red); pixmap.draw_rectangle (gc, TRUE, ((*curlink)->in_node)->xpos-15, ((*curlink)->in_node)->ypos-15, 30, 30); } if ((*curlink)->weight<0) gc.set_foreground(blue); else gc.set_foreground(black); gc.set_line_width(floor(fabs(2*((*curlink)->weight)))); pixmap.draw_line(gc, curnode->xpos, curnode->ypos, ((*curlink)->in_node)->xpos, ((*curlink)->in_node)->ypos); //cout<<"Drawing text: "<<((*curlink)->in_node)->node_id<<endl; //Label the node gc.set_foreground(black); itoa(((*curlink)->in_node)->node_id,text); //cout<<"len: "<<strlen(text)<<endl; pixmap.draw_text (font, gc, ((*curlink)->in_node)->xpos+15, ((*curlink)->in_node)->ypos+5, text, strlen(text)); drawrows_old((*curlink)->in_node,seenlist); // } } }
/* Create a new backing pixmap of the appropriate size */ int PopulationDrawingArea::configure_event_impl (GdkEventConfigure * /* event */) { Gdk_Font font ( "-*-courier-bold-*-*-*-*-120-*-*-*-*-*-*"); list<Generation_viz*>::iterator curgen; Generation_viz *lastgen=0; list<Species_viz*>::iterator curspec; list<Species_viz*>::iterator curspec2; Species_viz *samespec=0; Gdk_Color red("red"); Gdk_Color white("white"); Gdk_Color black("black"); Gdk_Color blue("blue"); Gdk_Color cyan("cyan"); Gdk_Color yellow("yellow"); Gdk_Color green("green"); Gdk_Color orange("orange"); Gdk_Color purple("purple"); GdkPoint points[4]; //The polygonal area to fill get_colormap().alloc(black); get_colormap().alloc(white); get_colormap().alloc(red); get_colormap().alloc(blue); get_colormap().alloc(cyan); get_colormap().alloc(yellow); get_colormap().alloc(green); get_colormap().alloc(orange); get_colormap().alloc(purple); int ypos=3; int xpos=3; double ypixels=height()-6; double xpixels=width()-6; int ystep; int xstep; int num_gens=stop_gen-start_gen+1; //Total number of generations int gen_count; int print_number_every=(int) num_gens/10; bool y_for_gens; //Flag for deciding on which axis is which //Markers for points where the color should change with fitness //Mark 3 is the MEAN //Mark 1 and 2 are 2 and 1 std. away respectively, going down //Mark 4 and 5 are 1 and 2 std. away respectively, going up double mark1,mark2,mark3,mark4,mark5; if (num_gens<10) print_number_every=1; if (width()>height()) y_for_gens=false; else y_for_gens=true; mark3=pop->mean_fitness; mark2=mark3-(pop->standard_deviation); mark1=mark2-(pop->standard_deviation); mark4=mark3+(pop->standard_deviation); mark5=mark4+(pop->standard_deviation); //cout<<"blue "<<mark1<<" cyan "<<mark2<<" green "<<mark3<<" orange "<<mark4<<" purple "<<mark5<<" red"<<endl; cout<<"blue "<<mark3<<" black "<<mark5<<" red"<<endl; //Computer the step if (y_for_gens) ystep=(int) floor(ypixels/((double) num_gens)); else xstep=(int) floor(xpixels/((double) num_gens)); char text[20]; win = get_window(); visual = win.get_visual(); if (pixmap) pixmap.release(); pixmap.create(get_window(), width(), height()); if (!gc) { gc = Gdk_GC(pixmap); gc.set_foreground(white); } //gc = get_style()->get_white_gc(); gc.set_foreground(white); pixmap.draw_rectangle (gc, TRUE, 0, 0, width(), height()); //Set the current generation to the start gen curgen=(pop->generation_snapshots).begin(); for(gen_count=1;gen_count<start_gen;gen_count++) ++curgen; //DRAW THE POPULATION HERE for(gen_count=start_gen;gen_count<=stop_gen;gen_count++) { //Print the gen_num in the left or bottom column space every few gens if ((gen_count%print_number_every)==0) { gc.set_foreground(black); itoa(gen_count,text); if (y_for_gens) pixmap.draw_text (font, gc, 1, ypos+5, text, strlen(text)); else pixmap.draw_text (font, gc, xpos-5, height()-10, text, strlen(text)); } //Draw each Species in the current generation for(curspec=((*curgen)->species_list).begin();curspec!=((*curgen)->species_list).end();++curspec) { //Determine the line color for this species if (((*curspec)->max_fitness)<mark1) { gc.set_foreground(blue); //gc.set_line_width(1); } else if (((*curspec)->max_fitness)<mark2) { gc.set_foreground(blue); //gc.set_line_width(1); } else if (((*curspec)->max_fitness)<mark3) { gc.set_foreground(blue); //gc.set_line_width(2); } else if (((*curspec)->max_fitness)<mark4) { gc.set_foreground(black); //gc.set_line_width(2); } else if (((*curspec)->max_fitness)<mark5) { gc.set_foreground(black); //gc.set_line_width(3); } else { gc.set_foreground(red); //gc.set_line_width(3); } //If this is the first gen, then everything is a straight line if (gen_count==start_gen) { //gc.set_foreground(black); //gc.set_line_width(floor(fabs(2*((*curlink)->weight)))); if (y_for_gens) pixmap.draw_line(gc, (*curspec)->startx, ypos, (*curspec)->endx, ypos); else pixmap.draw_line(gc, xpos, (*curspec)->starty, xpos, (*curspec)->endy); } else { //Check the previous generation for this same Species curspec2=(lastgen->species_list).begin(); while ((curspec2!=(lastgen->species_list).end())&& (((*curspec2)->id)!=((*curspec)->id))) ++curspec2; //If it is not found, just draw a horizontal line if (curspec2==(lastgen->species_list).end()) { if (y_for_gens) pixmap.draw_line(gc, (*curspec)->startx, ypos, (*curspec)->endx, ypos); else pixmap.draw_line(gc, xpos, (*curspec)->starty, xpos, (*curspec)->endy); } //Otherwise, if it existed before, connect the 2 endpoint pairs else { //Instead of just linking lines, draw a filled polygon //contained by them if (y_for_gens) { points[0].x=(*curspec)->startx; points[0].y=ypos; points[1].x=(*curspec)->endx; points[1].y=ypos; points[2].x=(*curspec2)->endx; points[2].y=ypos-ystep; points[3].x=(*curspec2)->startx; points[3].y=ypos-ystep; } else { points[0].x=xpos; points[0].y=(*curspec)->starty; points[1].x=xpos; points[1].y=(*curspec)->endy;; points[2].x=xpos-xstep; points[2].y=(*curspec2)->endy; points[3].x=xpos-xstep; points[3].y=(*curspec2)->starty; } pixmap.draw_polygon (gc, TRUE, points, 4); //Make white borders gc.set_foreground(white); gc.set_line_width(1); if (y_for_gens) { pixmap.draw_line(gc, (*curspec)->startx, ypos, (*curspec2)->startx, ypos-ystep); pixmap.draw_line(gc, (*curspec)->endx, ypos, (*curspec2)->endx, ypos-ystep); } else { pixmap.draw_line(gc, xpos, (*curspec)->starty, xpos-xstep, (*curspec2)->starty); pixmap.draw_line(gc, xpos, (*curspec)->endy, xpos-xstep, (*curspec2)->endy); } } //Print the Species' id for high fitness if ((*curspec)->max_fitness>mark5) { gc.set_foreground(black); itoa((*curspec)->id,text); if (y_for_gens) pixmap.draw_text (font, gc, (int) ((((*curspec)->endx)+((*curspec)->startx))/2.0), ypos, text, strlen(text)); else pixmap.draw_text (font, gc, xpos-5, (int) ((((*curspec)->endy)+((*curspec)->starty))/2.0)+5.0, text, strlen(text)); } } } //End for on curspec //Increment pos ypos+=ystep; xpos+=xstep; //Remember the last generation lastgen=(*curgen); ++curgen; } //End for on curgen //Print labels in a separate loop so they don't get painted over //Set the current generation to the start gen curgen=(pop->generation_snapshots).begin(); for(gen_count=1;gen_count<start_gen;gen_count++) ++curgen; ypos=3; xpos=3; for(gen_count=start_gen;gen_count<=stop_gen;gen_count++) { //Draw each Species in the current generation for(curspec=((*curgen)->species_list).begin();curspec!=((*curgen)->species_list).end();++curspec) { if ((*curspec)->max_fitness>mark5) { gc.set_foreground(black); itoa((*curspec)->id,text); if (y_for_gens) pixmap.draw_text (font, gc, (int) ((((*curspec)->endx)+((*curspec)->startx))/2.0), ypos, text, strlen(text)); else pixmap.draw_text (font, gc, xpos-7, (int) ((((*curspec)->endy)+((*curspec)->starty))/2.0)+5.0, text, strlen(text)); } } //Increment pos ypos+=ystep; xpos+=xstep; //Remember the last generation lastgen=(*curgen); ++curgen; } return TRUE; }
void ScribbleDrawingArea::drawrows(list<NNode*> *drawlist) { list<Link*>::iterator curlink; list<NNode*>::iterator curnode; char text[20]; int arrowadd; //For positioning arrowtips Gdk_Font font ( "-*-courier-bold-*-*-*-*-240-*-*-*-*-*-*"); Gdk_Color blue("blue"); get_colormap().alloc(blue); Gdk_Color black("black"); get_colormap().alloc(black); Gdk_Color red("red"); get_colormap().alloc(red); //Draw all links for all nodes first so that nodes will appear on top for(curnode=drawlist->begin();curnode!=drawlist->end();++curnode) { //Draw links for this node for(curlink=((*curnode)->incoming).begin();curlink!=((*curnode)->incoming).end();++curlink) { if ((*curlink)->weight<0) gc.set_foreground(blue); else gc.set_foreground(black); gc.set_line_width(floor(fabs(2*((*curlink)->weight)))); if (!((*curlink)->is_recurrent)) { pixmap.draw_line(gc, (*curnode)->xpos, (*curnode)->ypos, ((*curlink)->in_node)->xpos, ((*curlink)->in_node)->ypos); //If the link is between two nodes on the same row, //draw an arrowtip to make it clear which way it goes if (((*curnode)->row)==(((*curlink)->in_node)->row)) { if (((*curnode)->xpos)<(((*curlink)->in_node)->xpos)) arrowadd=15; else arrowadd=-15; pixmap.draw_line(gc, (*curnode)->xpos+arrowadd, (*curnode)->ypos, (*curnode)->xpos+arrowadd+arrowadd, (*curnode)->ypos+15); pixmap.draw_line(gc, (*curnode)->xpos+arrowadd, (*curnode)->ypos, (*curnode)->xpos+arrowadd+arrowadd, (*curnode)->ypos-15); } } //The way to draw a recur if ((*curlink)->is_recurrent) { gc.set_line_width(2); pixmap.draw_line(gc, ((*curlink)->in_node)->xpos, ((*curlink)->in_node)->ypos, ((*curlink)->in_node)->xpos-20, ((*curlink)->in_node)->ypos-20); pixmap.draw_line(gc, ((*curlink)->in_node)->xpos-20, ((*curlink)->in_node)->ypos-20, ((*curlink)->in_node)->xpos-25, ((*curlink)->in_node)->ypos-20); pixmap.draw_line(gc, ((*curlink)->in_node)->xpos-25, ((*curlink)->in_node)->ypos-20, ((*curlink)->in_node)->xpos-25, (*curnode)->ypos+20); pixmap.draw_line(gc, ((*curlink)->in_node)->xpos-25, (*curnode)->ypos+20, (*curnode)->xpos, (*curnode)->ypos+20); pixmap.draw_line(gc, (*curnode)->xpos, (*curnode)->ypos+20, (*curnode)->xpos, (*curnode)->ypos); } } } //Now draw all the nodes and labels for(curnode=drawlist->begin();curnode!=drawlist->end();++curnode) { //Draw the node gc.set_foreground(red); pixmap.draw_rectangle (gc, TRUE, (*curnode)->xpos-15, (*curnode)->ypos-15, 30, 30); //Label the node gc.set_foreground(black); itoa((*curnode)->node_id,text); //cout<<"len: "<<strlen(text)<<endl; pixmap.draw_text (font, gc, (*curnode)->xpos+15, (*curnode)->ypos+5, text, strlen(text)); } }