static void TestFunc(void) { int x = GrSizeX(); int y = GrSizeY(); int ww = (x / 2) - 10; int wh = (y / 2) - 10; GrColor c; GrContext *w1 = GrCreateSubContext(5, 5, ww+4, wh+4, NULL, NULL); GrContext *w2 = GrCreateSubContext(15+ww, 5, ww+ww+14, wh+4, NULL, NULL); GrContext *w3 = GrCreateSubContext(5, 15+wh, ww+4, wh+wh+14, NULL, NULL); GrContext *w4 = GrCreateSubContext(15+ww, 15+wh, ww+ww+14, wh+wh+14, NULL, NULL); GrSetContext(w1); c = GrAllocColor(200, 100, 100); drawing(0, 0, ww, wh, c, GrBlack()); GrBox(0, 0, ww-1, wh-1, c); GrSetContext(w2); c = GrAllocColor(100, 200, 200); drawing(0, 0, ww, wh, c, GrBlack()); GrBox(0, 0, ww-1, wh-1, c); GrSetContext(w3); c = GrAllocColor(200, 200, 0); drawing(0, 0, ww, wh, c, GrBlack()); GrBox(0, 0,ww-1, wh-1, c); GrSetContext(w4); c = GrAllocColor(0, 100, 200); drawing(0, 0, ww, wh, c, GrBlack()); GrBox(0, 0, ww-1, wh-1, c); GrSetContext(NULL); }
void tachyon_video::on_process() { char buf[8192]; flt runtime; scenedef *scene = (scenedef *) global_scene; updating_mode = scene->displaymode == RT_DISPLAY_ENABLED; recycling = false; pausing = false; do { updating = updating_mode; timer start_timer = gettimer(); rt_renderscene(global_scene); timer end_timer = gettimer(); runtime = timertime(start_timer, end_timer); sprintf(buf, "%s: %.3f seconds", global_window_title, runtime); rt_ui_message(MSG_0, buf); title = buf; show_title(); // show time spent for rendering if(!updating) { updating = true; drawing_memory dm = get_drawing_memory(); drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen } rt_finalize(); title = global_window_title; show_title(); // reset title to default } while(recycling && running); }
/* 基本动作——左转 */ void turnLeft(Person * x) { x->direction = x->direction + 1; x->direction = x->direction%4; drawing(); return ; }
static void parallel_thread(void) { unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); #if RUNTIME == RUNTIME_SERIAL for ( int y = starty; y < stopy; y++ ) #elif RUNTIME == RUNTIME_OPENMP #pragma omp parallel for for ( int y = starty; y < stopy; y++ ) #elif RUNTIME == RUNTIME_CILK _Cilk_for(int y = starty; y < stopy; y++) #elif RUNTIME == RUNTIME_TBB tbb::parallel_for(starty, stopy, [mboxsize] (int y) #endif { unsigned int serial = 1; unsigned int local_mbox[mboxsize]; memset(local_mbox, 0, mboxsize); drawing_area drawing(startx, totaly - y, stopx - startx, 1); for ( int x = startx; x < stopx; x++ ) { color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } video->next_frame(); } #if RUNTIME == RUNTIME_TBB ); #endif }
int main() { int x, y, ww, wh; GrxColor c; GrxContext *w1, *w2, *w3, *w4; GError *error = NULL; grx_set_driver("memory gw 400 gh 400 nc 256", NULL); if (!grx_set_mode(GRX_GRAPHICS_MODE_GRAPHICS_DEFAULT, &error)) { g_error("%s", error->message); } x = grx_get_width(); y = grx_get_height(); ww = (x / 2) - 10; wh = (y / 2) - 10; w1 = grx_context_new_subcontext(5,5,ww+4,wh+4,NULL,NULL); w2 = grx_context_new_subcontext(15+ww,5,ww+ww+14,wh+4,NULL,NULL); w3 = grx_context_new_subcontext(5,15+wh,ww+4,wh+wh+14,NULL,NULL); w4 = grx_context_new_subcontext(15+ww,15+wh,ww+ww+14,wh+wh+14,NULL,NULL); grx_set_current_context(w1); c = grx_color_get(200,100,100); drawing(0,0,ww,wh,c,GRX_COLOR_BLACK); grx_draw_box(0,0,ww-1,wh-1,c); grx_set_current_context(w2); c = grx_color_get(100,200,200); drawing(0,0,ww,wh,c,GRX_COLOR_BLACK); grx_draw_box(0,0,ww-1,wh-1,c); grx_set_current_context(w3); c = grx_color_get(200,200,0); drawing(0,0,ww,wh,c,GRX_COLOR_BLACK); grx_draw_box(0,0,ww-1,wh-1,c); grx_set_current_context(w4); c = grx_color_get(0,100,200); drawing(0,0,ww,wh,c,GRX_COLOR_BLACK); grx_draw_box(0,0,ww-1,wh-1,c); grx_set_current_context( NULL ); // GrSaveBmpImage( "memtest.bmp",NULL,0,0,639,479 ); grx_context_save_to_ppm( NULL,"memtest.ppm","GRX MemTest",NULL ); return 0; }
void makeImage(char* fileName) { drawing_3d_t drawing(fileName); imageWidth = drawing.getWindowWidth(); imageHeight = drawing.getWindowHeight(); pipeline_t mypipeline(drawing, 0); buffer.setFrameBuffer(imageWidth, imageHeight); startRasterizing(drawing); setCameraPositions(drawing); drawing_perspective = drawing; }
void operator() (const tbb::blocked_range2d<int> &r) const { // task-local storage unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); memset(local_mbox,0,mboxsize); #ifdef MARK_RENDERING_AREA // compute thread number while first task run thread_id_t::reference thread_id = thread_ids.local(); if (thread_id == -1) thread_id = thread_number++; // choose thread color int pos = thread_id % NUM_COLORS; if(video->running) { drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin()); for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) { drawing.set_pos(0, drawing.size_y-i); for (int x = r.cols().begin(); x != r.cols().end(); x++) { int d = (y % 3 == 0) ? 2 : 1; drawing.put_pixel(video->get_color(colors[pos][0]/d, colors[pos][1]/d, colors[pos][2]/d)); } } } #endif if(video->next_frame()) { drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin()); for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) { drawing.set_pos(0, drawing.size_y-i); for (int x = r.cols().begin(); x != r.cols().end(); x++) { #ifdef MARK_RENDERING_AREA float alpha = y==r.rows().begin()||y==r.rows().end()-1||x==r.cols().begin()||x==r.cols().end()-1 ? border_alpha : inner_alpha; color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy, colors[pos], alpha); #else color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); #endif drawing.put_pixel(c); } } } }
void TImageSnapshot::setImage(QImage img) { if (picMode->_colorMapChanged && val16.size() != 0) { val.clear(); picMode->convert16BitData(val16, val); img = picMode->setImage(dimX, dimY, val); wgt->image = img; } wgt->widthScrBar->setMaximum(wgt->image.width()); wgt->heightScrBar->setMaximum(wgt->image.height()); img = setPropertiesOnImg(img); drawing(img); }
void showCorners(void* image_buffer, pixel_t type) { // render a small red cross for each corner on the given image. int idx, x, y, w = cmap.w, h = cmap.h, total = cmap.w * cmap.h; if (w <= 0 || h <= 0 || cmap.data == NULL) return; CornerPoint **mp = (CornerPoint**)(cmap.data); ImageDrawer<float> drawing( w, h, type, image_buffer ); for (idx = 0; idx < total; idx++) { if (mp[idx] == NULL) continue; x = idx % w; y = idx / w; if (y < 3 || y >= h-3) continue; drawing.drawCross( x, y, 2, '+', 255, 0, 0 ); } }
void operator() (const tbb::blocked_range<int> &r) const { // task-local storage unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); memset(local_mbox,0,mboxsize); for (int y = r.begin(); y != r.end(); ++y) { { drawing_area drawing(startx, totaly-y, stopx-startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } } if(!video->next_frame()) return; } }
//todo: comment out following routine in TBB implementation ///* static void draw_task (void) { // thread-local storage unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); memset(local_mbox,0,mboxsize); for (int y = starty; y < stopy; y++) { { drawing_area drawing(startx, totaly-y, stopx-startx, 1); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } } if(!video->next_frame()) return; } }
/* 基本动作——指定方向移动一步 */ void step(Person * x) { int i = x->positionx; int j = x->positiony; switch(x->direction) { case DIR_RIGHT: if(i+1<POSWIDTH) { map[j][i] = 0; x->positionx = i+1; } break; case DIR_UP: if(j-1>=0) { map[j][i] = 0; x->positiony=j-1; } break; case DIR_LEFT: if(i-1>=0) { map[j][i] = 0; x->positionx = i-1; } break; case DIR_DOWN: if(j+1<POSHEIGHT) { map[j][i] = 0; x->positiony=j+1; } break; default: break; } drawing(); drawPerson(&xiaoming); drawPerson(&xiaohong); return ; }
int main(int argc, char** argv) { Fl_Window window(5*75,400); window.box(FL_NO_BOX); Fl_Scroll scroll(0,0,5*75,300); Fl_Group g(0, 0, 5*75, 8*25); int n = 0; for (int y=0; y<16; y++) for (int x=0; x<5; x++) { char buf[20]; sprintf(buf,"%d",n++); if (y==8 && x==0) g.end(); Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25,strdup(buf)); b->color(n); b->selection_color(n); b->label_color(FL_WHITE); b->selection_text_color(FL_WHITE); } g.end(); Drawing drawing(0,8*25,5*75,5*75,0); scroll.end(); window.resizable(scroll); Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll box.box(FL_FLAT_BOX); Fl_Toggle_Button but1(150, 310, 200, 25, "box"); but1.set(); but1.callback(box_cb); Fl_Choice choice(150, 335, 200, 25, "type():"); choice.menu(choices); choice.value(3); Fl_Choice achoice(150, 360, 200, 25, "scrollbar_align():"); achoice.menu(align_choices); achoice.value(3); thescroll = &scroll; //scroll.box(FL_DOWN_BOX); //scroll.type(Fl_Scroll::VERTICAL); window.end(); window.show(argc,argv); return Fl::run(); }
int main(int argc, char **argv) { Aria::init(); ArServerBase server; ArGlobalFunctor2<ArServerClient *, ArNetPacket *> sendEmptyCB(&sendEmpty); if (!server.open(7272)) { printf("Could not open server port\n"); exit(1); } ArServerInfoDrawings drawing(&server); ArDrawingData arrows("polyarrow", ArColor(0, 0, 255), 5, 50); ArDrawingData dots("polydots", ArColor(0, 255, 0), 12, 50); drawing.addDrawing(&arrows, "arrows", &sendEmptyCB); drawing.addDrawing(&dots, "dots", &sendEmptyCB); server.run(); }
static void paint_screen(void) { GrContext *grc; paint_board(&brd); paint_button_group(bgact); paint_board(&brdimg); grc = GrCreateSubContext(brdimg.x + 4, brdimg.y + 4, brdimg.x + brdimg.wide - 5, brdimg.y + brdimg.high - 5, grcglob, NULL); if (bgact == &bgp1) GrLoadContextFromPnm(grc, "pnmtest.ppm"); else GrLoadContextFromPnm(grc, "pnmtest2.ppm"); GrDestroyContext(grc); the_info(500, 215); drawing(400, 290, 200, 150, BROWN, DARKGRAY); the_title(500, 330); paint_foot("Hold down left mouse buttom to see a comment"); }
void tachyon_video::on_key(int key) { key &= 0xff; recycling = true; if(key == esc_key) running = false; else if(key == ' ') { if(!updating) { updating = true; drawing_memory dm = get_drawing_memory(); drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen } updating = updating_mode = !updating_mode; } else if(key == 'p') { pausing = !pausing; if(pausing) { title = "Press ESC to exit or 'p' to continue after rendering completion"; show_title(); } } }
void init() { /* 初始化位置方向速度 */ xiaoming.positionx = 1; xiaoming.positiony = 1; xiaoming.direction = DIR_RIGHT; xiaoming.speed = 100; xiaohong.positionx = 12; xiaohong.positiony = 1; xiaohong.direction = DIR_RIGHT; xiaohong.speed = 50; endx = 19; endy = 18; /* 墙 */ loadimage(&WallImg, "wall.bmp", IMGWIDTH, IMGHEIGHT, true); /* 空地 */ loadimage(&BlankImg, "blank.bmp", IMGWIDTH, IMGHEIGHT, true); /* 终点 */ loadimage(&EndImg, "end.bmp", IMGWIDTH, IMGHEIGHT, true); /* 人物 */ loadimage(&PersonImg[DIR_RIGHT], "right.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_UP], "up.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_LEFT], "left.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_DOWN], "down.bmp", IMGWIDTH, IMGHEIGHT, true); setfont(14, 0, _T("黑体")); outtextxy(410, 310, _T("操作说明")); outtextxy(410, 330, _T("s:走一步")); outtextxy(410, 350, _T("l:左转")); outtextxy(410, 370, _T("m:自定义移动")); drawing(); return ; }
void control(t_en *en) { en->x = 0; while (en->x < WIDTH) { init_while(en); define_step(en); while (en->hit == 0) is_hit(en); color(en); en->hit = 0; if (en->side == 0) en->perpwall = fabs((en->map.x - en->raypos.x + \ (1 - en->step.x) / 2) / en->ray.x); else en->perpwall = fabs((en->map.y - en->raypos.y + \ (1 - en->step.y) / 2) / en->ray.y); drawing(en); en->x++; } }
void operator () (const tbb::blocked_range <int> &r) const { unsigned int serial = 1; unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20); unsigned int * local_mbox = (unsigned int *) alloca(mboxsize); memset(local_mbox,0,mboxsize); for (int y=r.begin(); y!=r.end(); ++y) { drawing_area drawing(startx, totaly-y, stopx-startx, 1); // Acquire mutex to protect pixel calculation from multithreaded access (Needed?) // pthread_mutex_lock (&rgb_mutex); for (int x = startx; x < stopx; x++) { color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy); drawing.put_pixel(c); } // Release the mutex after pixel calculation complete // pthread_mutex_unlock (&rgb_mutex); if(!video->next_frame()) tbb::task::self().cancel_group_execution(); } }
int main(int argc, char** argv) { Fl_Double_Window window(300,500); Drawing drawing(10,10,280,280); d = &drawing; int y = 300; for (int n = 0; n<7; n++) { Fl_Value_Slider* s = new Fl_Value_Slider(50,y,240,25,name[n]); y += 25; s->type(Fl_Slider::HORIZONTAL); if (n<4) {s->minimum(0); s->maximum(300);} else if (n==6) {s->minimum(0); s->maximum(360);} else {s->minimum(-360); s->maximum(360);} s->type(Fl_Slider::HORIZONTAL | Fl_Slider::TICK_ABOVE); s->step(1); s->value(args[n]); s->clear_flag(FL_ALIGN_MASK); s->set_flag(FL_ALIGN_LEFT); s->callback(slider_cb, (void*)n); } window.end(); window.show(argc,argv); return Fl::run(); }
void GLWidget::line_rel(double delta_x, double delta_y) { drawing(x, y, x+delta_x, y+delta_y); x += delta_x; y += delta_y; }
int main() { //устанавливаем уровень сглаживания sf::ContextSettings settings; settings.antialiasingLevel = 8; //создаем окно приложения sf::RenderWindow window(sf::VideoMode(screenWidth, screenHeight), "My Analog Clock", sf::Style::Close, settings); float windowX = float(window.getSize().x); float windowY = float(window.getSize().y); //Определяем центр окна sf::Vector2f windowCenter = sf::Vector2f(windowX / 2.0f, windowY / 2.0f); //создаем точки sf::CircleShape dot[60]; createDots(dot,windowCenter); //создаем внешний контур sf::CircleShape clockCircle(clockCircleSize); //настраиваем внешний контур setCircle(&clockCircle,100, clockCircleThickness, sf::Color::Black,0, windowX / 2 + clockCircleThickness, windowY / 2 + clockCircleThickness); //создаем центральный круг sf::CircleShape centerCircle(10); //настраиваем центральный круг setCircle(¢erCircle, 100, 1, sf::Color::Yellow,1, windowX / 2, windowY / 2); //создаем стрелки sf::RectangleShape hourHand(sf::Vector2f(5, 150)); sf::RectangleShape minuteHand(sf::Vector2f(3, 200)); sf::RectangleShape secondsHand(sf::Vector2f(2, 220)); //массив стрелок sf::RectangleShape *strelki[3]; strelki[0] = &hourHand; strelki[1] = &minuteHand; strelki[2] = &secondsHand; //настройка стрелок setStrelki(strelki, windowCenter); //задний фон часов sf::Texture clockImage; if (!clockImage.loadFromFile("C:/Workshpase/Clock/fon.jpg")) { return EXIT_FAILURE; } clockCircle.setTexture(&clockImage); clockCircle.setTextureRect(sf::IntRect(40, 0, 500, 500)); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } //Поворачиваем стрелки moveStrelki(strelki); //Отрисовываем drawing(&window, dot, strelki, clockCircle, centerCircle); } return EXIT_SUCCESS; }
void paintGL() { updatestatus(); drawing(); }
void MainWindow::on_pushButton_Check_clicked() { QString fileNumber; fileNumber = ui->lineEdit_FindPart->text(); int partNumber = fileNumber.toInt(); int directoryMin = (partNumber /1000)* (1000) + 1;// rounding number int directoryMax = directoryMin + 999; if(fileNumber == "0") { QMessageBox::information(this, "Enter a valid number", "Enter a number other than 0"); } else if(fileNumber == "") { QMessageBox::information(this, "Empty", "Enter a number"); } else if (partNumber <= 10000)// if part number is between 1 and 10000 use the static directory AND ADD DASH (-) { //SHOW PART NUMBER ui->label_LastChecked->setText("B-"+fileNumber); //static directory QString directoryRange = "B-0001-B10000"; QFile drawing("N:/SolidWorksDrawing/B---/" + directoryRange + "/B-" + fileNumber + ".slddrw"); QFile pdf("P:/S_Works-Dwgs/B---/B-" + fileNumber + ".pdf"); QFile dxf("P:/SW_Track/B-" + fileNumber + ".dxf"); if(drawing.exists()) { ui->graphicsView_Drawing->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Drawing->setStyleSheet("background-color:#ff0000"); } // PDF if(pdf.exists()) { ui->graphicsView_Pdf->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Pdf->setStyleSheet("background-color:#ff0000"); } // DXF if(dxf.exists()) { ui->graphicsView_Dxf->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Dxf->setStyleSheet("background-color:#ff0000"); } } else { //SHOW PART NUMBER ui->label_LastChecked->setText("B"+fileNumber); //converting ints to strings and concatinating them QString directoryRange = "B"+ QString::number(directoryMin)+ "-" + "B" + QString::number(directoryMax); QFile drawing("N:/SolidWorksDrawing/B---/" + directoryRange + "/B" + fileNumber + ".slddrw"); QFile pdf("P:/S_Works-Dwgs/B---/B" + fileNumber + ".pdf"); QFile dxf("P:/SW_Track/B" + fileNumber + ".dxf"); if(drawing.exists()) { ui->graphicsView_Drawing->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Drawing->setStyleSheet("background-color:#ff0000"); } // PDF if(pdf.exists()) { ui->graphicsView_Pdf->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Pdf->setStyleSheet("background-color:#ff0000"); } // DXF if(dxf.exists()) { ui->graphicsView_Dxf->setStyleSheet("background-color:#00ff00"); } else { ui->graphicsView_Dxf->setStyleSheet("background-color:#ff0000"); } } }//CHECK ENDS HERE
//----------------------------------------------------------------------------- // call function: compute an UML layout for graph umlGraph //----------------------------------------------------------------------------- void PlanarizationLayoutUML::call(UMLGraph ¨Graph) { m_nCrossings = 0; if(umlGraph.constGraph().empty()) return; // check necessary preconditions preProcess(umlGraph); //--------------------------------------------------- // preprocessing: insert a merger for generalizations umlGraph.insertGenMergers(); PlanRepUML pr(umlGraph); const int numCC = pr.numberOfCCs(); // (width,height) of the layout of each connected component Array<DPoint> boundingBox(numCC); // alignment section (should not be here, because planarlayout should // not know about the meaning of layouter options and should not cope // with them), move later // we have to distinguish between cc's with and without generalizations // if the alignment option is set int l_layoutOptions = m_planarLayouter.get().getOptions(); bool l_align = ((l_layoutOptions & umlOpAlign) > 0); //end alignment section //------------------------------------------ //now planarize CCs and apply drawing module for(int i = 0; i < numCC; ++i) { //--------------------------------------- // 1. crossing minimization //--------------------------------------- // alignment: check wether gens exist, special treatment is necessary bool l_gensExist = false; // set this for all CC's, start with first gen, //this setting can be mixed among CC's without problems EdgeArray<Graph::EdgeType> savedType(pr); EdgeArray<Graph::EdgeType> savedOrigType(pr.original()); //for deleted copies EdgeArray<int> costOrig(pr.original(), 1); //edgearray for reinserter call: which edge may never be crossed? EdgeArray<bool> noCrossingEdge(pr.original(), false); edge e; forall_edges(e,pr) { edge eOrig = pr.original(e); if (pr.typeOf(e) == Graph::generalization) { if (l_align) l_gensExist = true; OGDF_ASSERT(!eOrig || !(noCrossingEdge[eOrig])); // high cost to allow alignment without crossings if (l_align && ( (eOrig && (pr.typeOf(e->target()) == Graph::generalizationMerger)) || pr.alignUpward(e->adjSource()) )) costOrig[eOrig] = 10; } } int cr; m_crossMin.get().call(pr, i, cr, &costOrig); m_nCrossings += cr; //--------------------------------------- // 2. embed resulting planar graph //--------------------------------------- // We currently compute any embedding and choose the maximal face as external face // if we use FixedEmbeddingInserter, we have to re-use the computed // embedding, otherwise crossing nodes can turn into "touching points" // of edges (alternatively, we could compute a new embedding and // finally "remove" such unnecessary crossings). if(!pr.representsCombEmbedding()) planarEmbed(pr); adjEntry adjExternal = 0; if(pr.numberOfEdges() > 0) { CombinatorialEmbedding E(pr); face fExternal = findBestExternalFace(pr,E); adjExternal = fExternal->firstAdj(); } //--------------------------------------------------------- // 3. compute layout of planarized representation //--------------------------------------------------------- Layout drawing(pr); // distinguish between CC's with/without generalizations // this changes the input layout modules options! if (l_gensExist) m_planarLayouter.get().setOptions(l_layoutOptions); else m_planarLayouter.get().setOptions((l_layoutOptions & ~umlOpAlign)); // call the Layouter for the CC's UMLGraph m_planarLayouter.get().call(pr, adjExternal, drawing); // copy layout into umlGraph // Later, we move nodes and edges in each connected component, such // that no two overlap. for(int j = pr.startNode(); j < pr.stopNode(); ++j) { node vG = pr.v(j); umlGraph.x(vG) = drawing.x(pr.copy(vG)); umlGraph.y(vG) = drawing.y(pr.copy(vG)); adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); drawing.computePolylineClear(pr,eG,umlGraph.bends(eG)); } } // the width/height of the layout has been computed by the planar // layout algorithm; required as input to packing algorithm boundingBox[i] = m_planarLayouter.get().getBoundingBox(); }//for cc's
void PlanarizationLayoutUML::doSimpleCall(GraphAttributes &GA) { m_nCrossings = 0; if(GA.constGraph().empty()) return; PlanRepUML pr = PlanRepUML(GA); const int numCC = pr.numberOfCCs(); // (width,height) of the layout of each connected component Array<DPoint> boundingBox(numCC); //------------------------------------------ //now planarize CCs and apply drawing module for(int i = 0; i < numCC; ++i) { //--------------------------------------- // 1. crossing minimization //--------------------------------------- int cr; m_crossMin.get().call(pr, i, cr); m_nCrossings += cr; //--------------------------------------- // 2. embed resulting planar graph //--------------------------------------- adjEntry adjExternal = 0; m_embedder.get().call(pr, adjExternal); //--------------------------------------------------------- // 3. compute layout of planarized representation //--------------------------------------------------------- Layout drawing(pr); //call the Layouter for the CC's UMLGraph m_planarLayouter.get().call(pr,adjExternal,drawing); // copy layout into umlGraph // Later, we move nodes and edges in each connected component, such // that no two overlap. for(int j = pr.startNode(); j < pr.stopNode(); ++j) { node vG = pr.v(j); GA.x(vG) = drawing.x(pr.copy(vG)); GA.y(vG) = drawing.y(pr.copy(vG)); adjEntry adj; forall_adj(adj,vG) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); drawing.computePolylineClear(pr, eG, GA.bends(eG)); } } // the width/height of the layout has been computed by the planar // layout algorithm; required as input to packing algorithm boundingBox[i] = m_planarLayouter.get().getBoundingBox(); } //---------------------------------------- // 4. arrange layouts of connected components //---------------------------------------- arrangeCCs(pr, GA, boundingBox); }
int main(void) { static int firstgr = 1; GrEvent ev; GrSetDriver(NULL); if(GrCurrentVideoDriver() == NULL) { printf("No graphics driver found\n"); exit(1); } for( ; ; ) { int i,w,h,px,py; char m1[41]; nmodes = (int)(collectmodes(GrCurrentVideoDriver(),grmodes) - grmodes); if(nmodes == 0) { printf("No graphics modes found\n"); exit(1); } qsort(grmodes,nmodes,sizeof(grmodes[0]),vmcmp); printf( "Graphics driver: \"%s\"\n" " graphics defaults: %dx%d %ld colors\n" " text defaults: %dx%d %ld colors\n\n", GrCurrentVideoDriver()->name, GrDriverInfo->defgw, GrDriverInfo->defgh, (long)GrDriverInfo->defgc, GrDriverInfo->deftw, GrDriverInfo->defth, (long)GrDriverInfo->deftc ); PrintModes(); printf("\nEnter choice #, or anything else to quit> "); fflush(stdout); if(!fgets(m1,40,stdin) || (sscanf(m1,"%d",&i) != 1) || (i < 1) || (i > nmodes)) { exit(0); } if(firstgr) { printf( "When in graphics mode, press any key to return to menu.\n" "Now press <CR> to continue..." ); fflush(stdout); fgets(m1,40,stdin); firstgr = 0; } i--; GrSetMode( GR_width_height_bpp_graphics, grmodes[i].w, grmodes[i].h, grmodes[i].bpp ); if(grmodes[i].bpp<15) { w = GrScreenX() >> 1; h = GrScreenY() >> 1; px = w + 5; py = h + 5; w -= 10; h -= 10; drawing( 5,5,w,h, GrBlack(), GrWhite() ); drawing( px,5,w,h, GrAllocColor(255,0,0), GrAllocColor(0,255,0) ); drawing( 5,py,w,h, GrAllocColor(0,0,255), GrAllocColor(255,255,0) ); drawing( px,py,w,h, GrAllocColor(255,0,255), GrAllocColor(0,255,255) ); } else {
//the call function that lets ClusterPlanarizationLayout compute a layout //for the input using \a weight for the computation of the cluster planar subgraph void ClusterPlanarizationLayout::call( Graph& G, ClusterGraphAttributes& acGraph, ClusterGraph& cGraph, EdgeArray<double>& edgeWeight, bool simpleCConnect) //default true { m_nCrossings = 0; bool subGraph = false; // c-planar subgraph computed? //check some simple cases if (G.numberOfNodes() == 0) return; //------------------------------------------------------------- //we set pointers and arrays to the working graph, which can be //the original or, in the case of non-c-planar input, a copy Graph* workGraph = &G; ClusterGraph* workCG = &cGraph; ClusterGraphAttributes* workACG = &acGraph; //potential copy of original if non c-planar Graph GW; //list of non c-planarity causing edges List<edge> leftEdges; //list of nodepairs to be connected (deleted edges) List<NodePair> leftWNodes; //store some information //original to copy NodeArray<node> resultNode(G); EdgeArray<edge> resultEdge(G); ClusterArray<cluster> resultCluster(cGraph); //copy to original NodeArray<node> orNode(G); EdgeArray<edge> orEdge(G); ClusterArray<cluster> orCluster(cGraph); for(node workv : G.nodes) { resultNode[workv] = workv; //will be set to copy if non-c-planar orNode[workv] = workv; } for(edge worke : G.edges) { resultEdge[worke] = worke; //will be set to copy if non-c-planar orEdge[worke] = worke; } for (cluster workc : cGraph.clusters) { resultCluster[workc] = workc; //will be set to copy if non-c-planar orCluster[workc] = workc; } //----------------------------------------------- //check if instance is clusterplanar and embed it CconnectClusterPlanarEmbed CCPE; //cccp bool cplanar = CCPE.embed(cGraph, G); List<edge> connectEdges; //if the graph is not c-planar, we have to check the reason and to //correct the problem by planarising or inserting connection edges if (!cplanar) { bool connect = false; if ( (CCPE.errCode() == CconnectClusterPlanarEmbed::nonConnected) || (CCPE.errCode() == CconnectClusterPlanarEmbed::nonCConnected) ) { //we insert edges to make the input c-connected makeCConnected(cGraph, G, connectEdges, simpleCConnect); //save edgearray info for inserted edges for(edge e : connectEdges) { resultEdge[e] = e; orEdge[e] = e; } connect = true; CCPE.embed(cGraph, G); if ( (CCPE.errCode() == CconnectClusterPlanarEmbed::nonConnected) || (CCPE.errCode() == CconnectClusterPlanarEmbed::nonCConnected) ) { cerr << "no correct connection made\n"<<flush; OGDF_THROW(AlgorithmFailureException); } }//if not cconnected if ((CCPE.errCode() == CconnectClusterPlanarEmbed::nonPlanar) || (CCPE.errCode() == CconnectClusterPlanarEmbed::nonCPlanar)) { subGraph = true; EdgeArray<bool> inSubGraph(G, false); CPlanarSubClusteredGraph cps; if (edgeWeight.valid()) cps.call(cGraph, inSubGraph, leftEdges, edgeWeight); else cps.call(cGraph, inSubGraph, leftEdges); #ifdef OGDF_DEBUG // for(edge worke : G.edges) { // if (inSubGraph[worke]) // acGraph.strokeColor(worke) = "#FF0000"; // } #endif //--------------------------------------------------------------- //now we delete the copies of all edges not in subgraph and embed //the subgraph (use a new copy) //construct copy workGraph = &GW; workCG = new ClusterGraph(cGraph, GW, resultCluster, resultNode, resultEdge); //---------------------- //reinit original arrays orNode.init(GW, nullptr); orEdge.init(GW, nullptr); orCluster.init(*workCG, nullptr); //set array entries to the appropriate values for (node workv : G.nodes) orNode[resultNode[workv]] = workv; for (edge worke : G.edges) orEdge[resultEdge[worke]] = worke; for (cluster workc : cGraph.clusters) orCluster[resultCluster[workc]] = workc; //---------------------------------------------------- //create new ACG and copy values (width, height, type) workACG = new ClusterGraphAttributes(*workCG, workACG->attributes()); for (node workv : GW.nodes) { //should set same attributes in construction!!! if (acGraph.attributes() & GraphAttributes::nodeType) workACG->type(workv) = acGraph.type(orNode[workv]); workACG->height(workv) = acGraph.height(orNode[workv]); workACG->width(workv) = acGraph.width(orNode[workv]); } if (acGraph.attributes() & GraphAttributes::edgeType) { for (edge worke : GW.edges) { workACG->type(worke) = acGraph.type(orEdge[worke]); //all other attributes are not needed or will be set } } for(edge ei : leftEdges) { edge e = resultEdge[ei]; NodePair np; np.m_src = e->source(); np.m_tgt = e->target(); leftWNodes.pushBack(np); GW.delEdge(e); } CconnectClusterPlanarEmbed CCP; #ifdef OGDF_DEBUG bool subPlanar = #endif CCP.embed(*workCG, GW); OGDF_ASSERT(subPlanar); }//if not planar else { if (!connect) OGDF_THROW_PARAM(PreconditionViolatedException, pvcClusterPlanar); } }//if //if multiple CCs are handled, the connectedges (their copies resp.) //can be deleted here //now CCPE should give us the external face ClusterPlanRep CP(*workACG, *workCG); OGDF_ASSERT(CP.representsCombEmbedding()); const int numCC = CP.numberOfCCs(); //equal to one //preliminary OGDF_ASSERT(numCC == 1); // (width,height) of the layout of each connected component Array<DPoint> boundingBox(numCC); for (int ikl = 0; ikl < numCC; ikl++) { CP.initCC(ikl); CP.setOriginalEmbedding(); OGDF_ASSERT(CP.representsCombEmbedding()) Layout drawing(CP); //m_planarLayouter.get().setOptions(4);//progressive adjEntry ae = nullptr; //internally compute adjEntry for outer face //edges that are reinserted in workGraph (in the same //order as leftWNodes) List<edge> newEdges; m_planarLayouter.get().call(CP, ae, drawing, leftWNodes, newEdges, *workGraph); OGDF_ASSERT(leftWNodes.size()==newEdges.size()) OGDF_ASSERT(leftEdges.size()==newEdges.size()) ListConstIterator<edge> itE = newEdges.begin(); ListConstIterator<edge> itEor = leftEdges.begin(); while (itE.valid()) { orEdge[*itE] = *itEor; ++itE; ++itEor; } //hash index over cluster ids HashArray<int, ClusterPosition> CA; computeClusterPositions(CP, drawing, CA); // copy layout into acGraph // Later, we move nodes and edges in each connected component, such // that no two overlap. for(int i = CP.startNode(); i < CP.stopNode(); ++i) { node vG = CP.v(i); acGraph.x(orNode[vG]) = drawing.x(CP.copy(vG)); acGraph.y(orNode[vG]) = drawing.y(CP.copy(vG)); for(adjEntry adj : vG->adjEdges) { if ((adj->index() & 1) == 0) continue; edge eG = adj->theEdge(); edge orE = orEdge[eG]; if (orE) drawing.computePolylineClear(CP,eG,acGraph.bends(orE)); } }//for //even assignment for all nodes is not enough, we need all clusters for(cluster c : workCG->clusters) { int clNumber = c->index(); //int orNumber = originalClId[c]; cluster orCl = orCluster[c]; if (c != workCG->rootCluster()) { OGDF_ASSERT(CA.isDefined(clNumber)); acGraph.height(orCl) = CA[clNumber].m_height; acGraph.width(orCl) = CA[clNumber].m_width; acGraph.y(orCl) = CA[clNumber].m_miny; acGraph.x(orCl) = CA[clNumber].m_minx; }//if real cluster } // the width/height of the layout has been computed by the planar // layout algorithm; required as input to packing algorithm boundingBox[ikl] = m_planarLayouter.get().getBoundingBox(); }//for connected components //postProcess(acGraph); // // arrange layouts of connected components // Array<DPoint> offset(numCC); m_packer.get().call(boundingBox,offset,m_pageRatio); // The arrangement is given by offset to the origin of the coordinate // system. We still have to shift each node, edge and cluster by the offset // of its connected component. const Graph::CCsInfo &ccInfo = CP.ccInfo(); for(int i = 0; i < numCC; ++i) { const double dx = offset[i].m_x; const double dy = offset[i].m_y; HashArray<int, bool> shifted(false); // iterate over all nodes in ith CC for(int j = ccInfo.startNode(i); j < ccInfo.stopNode(i); ++j) { node v = ccInfo.v(j); acGraph.x(orNode[v]) += dx; acGraph.y(orNode[v]) += dy; // update cluster positions accordingly //int clNumber = cGraph.clusterOf(orNode[v])->index(); cluster cl = cGraph.clusterOf(orNode[v]); if ((cl->index() > 0) && !shifted[cl->index()]) { acGraph.y(cl) += dy; acGraph.x(cl) += dx; shifted[cl->index()] = true; }//if real cluster for(adjEntry adj : v->adjEdges) { if ((adj->index() & 1) == 0) continue; edge e = adj->theEdge(); //edge eOr = orEdge[e]; if (orEdge[e]) { DPolyline &dpl = acGraph.bends(orEdge[e]); for(DPoint &p : dpl) { p.m_x += dx; p.m_y += dy; } } } }//for nodes }//for numcc while (!connectEdges.empty()) { G.delEdge(connectEdges.popFrontRet()); } if (subGraph) { //originalClId.init(); orCluster.init(); orNode.init(); orEdge.init(); delete workCG; delete workACG; }//if subgraph created acGraph.removeUnnecessaryBendsHV(); }//call