Looking for a polygon drawing order algorithm

Looking for a polygon drawing order algorithm

Post by Brian OBrie » Tue, 26 Jun 2001 04:55:04



I have a list of 2D polygons that needs to be sorted
according to drawing order.  i.e. the outer most polygons
are rendered first and then polygons within polygons are rendered
later over the tops of parent polygon.

I want to implement this as a linked or doubly linked list.  Polygons
are added in ANY order to the list and the list is built such that no
sorting is needed to render.  i.e. simply traverse the list from front
to tail.  I could have just implemented a linked list and just added
sequentially then did a bubble sort at the end, but this doesn't seem
efficient. Yet....

Seems simple enough at first but, I seem to be having problems
when a parent polygon has more then one subpolygon.

Suggestions or pointers please?
Notes: I have polygon interior/exterior tests working.
I'm working in C++.

TIA
Brian O'Brien.

 
 
 

Looking for a polygon drawing order algorithm

Post by Hans-Bernhard Broeke » Tue, 26 Jun 2001 18:12:27



> I have a list of 2D polygons that needs to be sorted according to
> drawing order.  i.e. the outer most polygons are rendered first and
> then polygons within polygons are rendered later over the tops of
> parent polygon.

This omits handling of one very important case: intersecting polygons.
You had better be sure that this never happens in your input, because
otherwise the problem is ill-defined.

Ordinary sorting algorithms won't work, because containment does not
define the type of ordering they need --- it can return "no preference
in either direction" too easily. More precisely, writing '==' for
"neither is contained in the other"

        a == b  && b==c

is not equivalent to

        a == c

for this case.

You'll probably need a graph theory based approach. You'll have to
construct a directed acyclic graph and traverse that.
--

Even if all the snow were burnt, ashes would remain.

 
 
 

Looking for a polygon drawing order algorithm

Post by Robin Tucke » Tue, 26 Jun 2001 18:28:56


This problem I think would be most easily implemented in a tree-type
structure.  You can't be sure about rendering the next parent, if you aren't
sure you've rendered all of the first parents children.  If you have an
unsorted list, you won't know if you've rendered all the first parents
children until you've reached the end of the list.  This means you will have
to traverse the list once for every parent - and that includes children that
are also parents ( etc. ).


Quote:> I have a list of 2D polygons that needs to be sorted
> according to drawing order.  i.e. the outer most polygons
> are rendered first and then polygons within polygons are rendered
> later over the tops of parent polygon.

> I want to implement this as a linked or doubly linked list.  Polygons
> are added in ANY order to the list and the list is built such that no
> sorting is needed to render.  i.e. simply traverse the list from front
> to tail.  I could have just implemented a linked list and just added
> sequentially then did a bubble sort at the end, but this doesn't seem
> efficient. Yet....

> Seems simple enough at first but, I seem to be having problems
> when a parent polygon has more then one subpolygon.

> Suggestions or pointers please?
> Notes: I have polygon interior/exterior tests working.
> I'm working in C++.

> TIA
> Brian O'Brien.

 
 
 

Looking for a polygon drawing order algorithm

Post by Brian OBrie » Wed, 27 Jun 2001 01:09:34


The polygons do not intersect.
However they may overlap completely.



> > I have a list of 2D polygons that needs to be sorted according to
> > drawing order.  i.e. the outer most polygons are rendered first and
> > then polygons within polygons are rendered later over the tops of
> > parent polygon.

> This omits handling of one very important case: intersecting polygons.
> You had better be sure that this never happens in your input, because
> otherwise the problem is ill-defined.

> Ordinary sorting algorithms won't work, because containment does not
> define the type of ordering they need --- it can return "no preference
> in either direction" too easily. More precisely, writing '==' for
> "neither is contained in the other"

> a == b  && b==c

> is not equivalent to

> a == c

> for this case.

> You'll probably need a graph theory based approach. You'll have to
> construct a directed acyclic graph and traverse that.
> --

> Even if all the snow were burnt, ashes would remain.

 
 
 

Looking for a polygon drawing order algorithm

Post by Hans-Bernhard Broeke » Wed, 27 Jun 2001 01:33:14



> The polygons do not intersect.
> However they may overlap completely.

"Overlap" as in: one is completely inside the other, or as in: they're
identical? If the latter, you may be in some trouble.

Otherwise, everything's fine, I think: containment defines a directed
graph of the type graph theorists call a 'forest': a collection of
tree graphs. To construct it, you'ld start at the leaves (polygons
containing no other polygons at all), and work your way upwards.
--

Even if all the snow were burnt, ashes would remain.

 
 
 

Looking for a polygon drawing order algorithm

Post by Tom Duf » Wed, 27 Jun 2001 01:39:26



> The polygons do not intersect.
> However they may overlap completely.

In that case, you can just sort them in order of area
and draw the largest first.

--
Tom Duff.  Our core competencies are office moves and corporate
apoptosis.

 
 
 

Looking for a polygon drawing order algorithm

Post by Mik » Thu, 28 Jun 2001 08:37:22




> > The polygons do not intersect.
> > However they may overlap completely.

> In that case, you can just sort them in order of area
> and draw the largest first.

Oh sure.  Make everybody else look bad.  <g>
 
 
 

Looking for a polygon drawing order algorithm

Post by Brian OBrie » Sun, 01 Jul 2001 12:21:59


Actually.  All the idea's were good.  If only I had found the original bug
which was
my polygon bounding box was wrong! :(




> > > The polygons do not intersect.
> > > However they may overlap completely.

> > In that case, you can just sort them in order of area
> > and draw the largest first.

> Oh sure.  Make everybody else look bad.  <g>

 
 
 

1. Looking for a polygon drawing algorithm

I'm looking for a fast polygon drawing algorithm (filling with a solid
color).
Can anyone point me in the right direction?

Thanks!
-kevin
--
|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\
|/-\|/-\|/-\  Kevin Tieskoetter |/-\|/-\   Mac Programmer   |/-\|/-\|/-\
|/-\|/-\|/-\ Drake Looniversity |/-\|/-\ MicroFrontier, Inc |/-\|/-\|/-\
|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\

2. Help Us Stamp Out Piracy-Earn Yourself A Reward!

3. Drawing order of polygons in 3D space

4. newsgroup for discreet* ?

5. Polygon draw order and antialiasing

6. PSP 6 Tip Re: File Associations

7. Looking for complex polygon-polygon clip algorithm/code

8. DXF for ACAD 13 format ??

9. Please help with algorithm to improve drawing of adjacent polygons

10. Algorithm for Drawing Centered Lines with Polygons?

11. algorithm that draw a regular polygons!

12. algorithm that draw regular polygon!

13. algorithm that draws regular polygon!