how to split region data?

K

Kristopher Wragg

Hi,

I'm currently working on an application for my dissertation for my
final year at University.

I'm having a little trouble with the System.Drawing.Region class.

The application is being designed to help create and study the use of
Euler/Venn diagrams, the user can draw various shapes which are stored
as GraphicsPaths.

They can also shade the intersections of these paths to signify that
the two (or more) objects have no relation.

To do this I am using region.Intersect and region.Xor to get the
data... this works fine but I need some help solving a problem.

See image: http://www.xafiers-home.com/euler/euler.jpg

Here the two objects overlap, when creating the region with an Xor it
produces shading either side of the vertical shape.

I want to be able to differentiate between these two shaded regions in
the region, but I can not find any functionality to get at the data
and find each group of data.

If anyone could help I'd apprechiate it.

Regards,
Kris Wragg
 
B

Bob Powell [MVP]

You can get to the scan line data in a region using the
Region.GetRegionScans method.

#1 sort the scans into X and Y order.

#2 Step through the scans and see if the current scan overlaps with the
previous one. If yes, add it to the list that it overlaps with, if
not, start a new list.

#3 continue to do this for all scans

#4 check all scans in all regions for overlap with scans in other
regions, if any overlap, combine the two lists, do this until you cannot
reduce the number of lists.

the resulting lists represent separate and contiguous areas

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
K

Kristopher Wragg

Hi,

Thanks for your reply, I've had an attempt at trying to do what you
said but so far haven't got it working correctly.

It seems an awfully long winded and processor intensive operation to
do something that should be fairly simple.

What I tried was to first get all the RectangleF's from the
GetRegionScan, then sorted them in order of Y then X.

Then I looped through them seeing whether rect intersects with
rect[i+1] when rect[i+1] had been moved by -1,-1 then inflated by 2,2.

This worked to an extent but wasn't a very good solution, is there a
more optimal way of doing this? or perhaps you have an example of it
being used in practise?

many thanks,
Kris Wragg
 
B

Bob Powell [MVP]

I used this algorithm to find out how many different glyphs were on a
page of text and colour them with a different colour.

I didn't mess about inflating the rectangles but just looked to see if
any rectangle in the current Y+1 had a left-right overlap with the
current rectangle. You just need to see if any left-right boundary falls
in the length of the other rectangle.

I seem to remember processing a page of text in about 15 seconds.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top