Polygonal filling algorithm

xiaoxiao2021-03-06  25

Polygonal filling algorithm

// ---------- ------- Define basic data ------------------ // // -------------------- Struct_Def.h ------ ---------------------------------------------------------------------------------------------------------------------------------------

Const int max_y = 1028; const Int max_x = 1024; const Int max_arc = 100; // The total number of fixed edges is up to 100

TypedEf struct arcnode // definitions Belt {INT X1, Y1; INT X2, Y2;} ArcNode; typef struct node // definition EOT, the list of linked list in the AET table {int ymin; float xs; float xx; node * next; Elemnode, * elemlink; typedef struct nodey // Y barrel table {elemlink link; int y;} nodey; typef strunt table // Table EOT and table AET also structure {nodey nodey [max_y];} * TableList;

TableList createEOTList (ArcNode arrayARC [MAX_ARC], int n); void ShowTable (const Table * table); void InsertArcNode (TableList table, Node * const node, int Y); TableList EOT_to_AET (const TableList table);

// -------------------------------- Decreated algorithm ------------ -----------------------

TableList CreateEotList (ArcNode Arrayarc [MAX_ARC], INT N) {TableList Eotlist = New Table; INT i; for (i = 0; I Nodey [i] .link = Null; eotlist-> nodey [i] .y = i;}

Int y; for (i = 0; i ymin = arrayarc [i] .y1; node-> xs = (float) arrayarc [i] .x2; y = arrayarc [i] .y2; / / !!!!!!!} f (arrayarc [i] .y1> arrayarc [i] .y2) // Y1> Y2, Y1 == y2 Do not {node-> ymin = arrayarc [i] .y2 Node-> xs = (float) arrayarc [i] .x1; y = arrayarc [i] .y1;} node-> xx = (float) - (Arrayarc [i] .x2-arrayarc [i] .x1) / (Arrayarc [i] .y2-arrayarc [i] .y1); node-> next = null; insertarcNode (Eotlist, node, y);}}}}}

Void InsertarcNode (TableList Table, Node * const node, int y) {if (Table-> Nodey [Y] .LINK == NULL) {// Header is empty Table-> Nodey [y] .LINK = Node; Node -> next = null; return; else {elemlink head_node = table-> node = Table-> nodey [y] .link; elemony * temp_node = head_node; if (((Node-> xs xs) || (head_node-> xs == Node-> xx xx)) {// plug-in table Table-> node [y] .link = node; node-> next = head_node; return;} else {while (temp_node-> next! = null) {if ((Node-> XS Next-> XS) || (Temp_node-> Next-> XS == Node-> XS && Node-> xx next-> xx) {node-> next = Temp_node-> next; temp_node-> next = node; return;} else temp_node = temp_node-> next;} // End while if (temp_node-> next == null ) {Temp_node-> next = node; node-> next = null; return;}}} // end else}}} // END ELSE} TABLIST EOT_TO_AET (Const TableList Table) {INT I, J, Y; FL Oat sum; elemlink head = new node; TABLIST TABLEAET = New TABLE;

For (i = 0; i Nodey [i] .Link = null; Tableaet-> node [i] .y = i;} for (i = max_y-1; i> 0; i-) // i = max_y-1 {head = Table-> nodey [i] .LINK; Y = Table-> nodey [i] .y; while (Head ) {Node * Temp = new node; temp-> xs = head-> xs; temp-> ymin = head-> ymin; temp-> xx = head-> xx; temp-> next = null; insertarcnode (Tableaet, Temp, y); sum = head-> xs; for (j = y-1; j> head-> ymin; j -) {sum = sum head-> xx; node * addnode = new node; addnode- > Ymin = head-> ymin; addnode-> xx = head-> xx; addnode-> xs = sum; addnode-> next = null; insertarcnode (Tableaet, addnode, j);} head = head-> next;} // end while} returnitaet;} // Define an array in the DOC, get an array with PDOC-> Arrayarc and in the display, the array inputs through the dialog box, color optional!

void CTestHTView :: OnDraw (CDC * pDC) {CTestHTDoc * pDoc = GetDocument (); ASSERT_VALID (pDoc); int i, j; TableList tableEOT = new Table; tableEOT = createEOTList (pDoc-> ArrayARC, pDoc-> num); // TableList Tableaet = New Table; Tableaet = Eot_to_aet (Tableeot);

Node; int x1, x2; for (i = max_y-1; i> = 0; i -) {head = Tableaet-> node [i] .link; while (head) {x1 = head -> xs; head = head-> next; x2 = head-> xs; for (j = x1; j setpixel (j, i, rgb (m_r, m_g, m_b)); Head = Head-> next;}}

转载请注明原文地址:https://www.9cbs.com/read-39588.html

New Post(0)