Quick Drop Enthusiasts

Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.
Highlighted

Need help with some pixel calculations

I've got a cool idea for a Quick Drop keyboard shortcut, but I'm having trouble wrapping my head around one key part of it. Can somebody write me a subVI that, given a position value and an array of rects, can calculate the largest rect that can be created with the given position value (as the top/left of the rect) that doesn't overlap any of the rects in the given array?

DNatt, LV R&D
0 Kudos
Message 1 of 14
(782 Views)
13 REPLIES

Re: Need help with some pixel calculations

I think I could do this, but I don't fully understand what you are asking for.  So if you have an XY position, you want to draw the largest rect you can, that doesn't overlap the rects that are given.  Does that mean moving to the left, right, top and bottom, until hitting a rect border, and figuring out which generates the largest area?  Meaning the XY position given might not be at the center of the rect drawn.  It might even be at the edge?  What about cases when the rect to be drawn can extend forever in one direction?


Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
Interesting in learning all you can about automotive CAN bus communication? Checkout my 12 part CAN Blog series.

0 Kudos
Message 2 of 14
(755 Views)

Re: Need help with some pixel calculations

Just spit-balling ideas here (i'm not an algorithm designer, so there are probably better ways).  What if you did something like below where you start at your initial position (X) and go down until you hit an object, then go right until you hit an object then assume your first rectangle (Green box).  Then do the same starting right then down to assume second rectangle (orange box).  Calculate area to get the largest box.  There may be other possible rectangles if you take different paths but this will at least give you a start.  

rectangles.png

 

 

Is this what you're thinking about or am I interpreting incorrectly?

 

--David_L, CLA

0 Kudos
Message 3 of 14
(744 Views)

Re: Need help with some pixel calculations


@Hooovahh@Hooovahh wrote:

I think I could do this, but I don't fully understand what you are asking for.  So if you have an XY position, you want to draw the largest rect you can, that doesn't overlap the rects that are given.  Does that mean moving to the left, right, top and bottom, until hitting a rect border, and figuring out which generates the largest area?  Meaning the XY position given might not be at the center of the rect drawn.  It might even be at the edge?  What about cases when the rect to be drawn can extend forever in one direction?


The given XY position is always the top-left of the desired rect. I'm hoping that makes it easier, as you only need to go right and down from that spot. Also, if the rect can go forever, we'll just set a max size.

DNatt, LV R&D
0 Kudos
Message 4 of 14
(727 Views)

Re: Need help with some pixel calculations


@David_LDavid_L wrote:

 

Is this what you're thinking about or am I interpreting incorrectly?


Yup, that's the idea. But when I sat down to write the code, I just couldn't get a toe hold.

DNatt, LV R&D
0 Kudos
Message 5 of 14
(726 Views)

Re: Need help with some pixel calculations

Ya it's harder than I thought.  I spent an hour this morning trying to figure it out but then had to get back to work.  My approach was using the "Computational Geometry" palette to find intersections in polygons and basically creating a rectangle of size 1x1, check if intersection if not, increase the rectangle size in one direction and repeat.  The problem is that the geometry palette uses one type of data, the drawing palette uses a different type, a standard VI Server rectangle is a third type and most of my time was spent just manipulating data.  Maybe I'll try again when I need a mental break from real work.

0 Kudos
Message 6 of 14
(717 Views)

Re: Need help with some pixel calculations

Actually this is a very interesting problem: https://en.wikipedia.org/wiki/Largest_empty_rectangle

It is a pity I was never good in such optimization math "tricks", but I am sure some people will turn up and give some cool solution Smiley Happy

 

edit: I have found some interesting articles, but I do not have access to scientific papers from home. I try to download some promising articles tomorrow, and if the published algorithm is not over my skills, I will try to implement it in LabVIEW...

0 Kudos
Message 7 of 14
(716 Views)

Re: Need help with some pixel calculations

Here is my initial thoughts. assuming left to right and top to bottom are positive.

 

  1. Start at the point and go right
  2. Stop at each left and right edge of each box
  3. Save the top most edge postion
  4. If the top most edge ever goes less than or equal to point's top position then stop and keep the right and top potions
  5. Repeat but go down using top bottom edges saving the smallest left position
  6. When finished you will have 2 points so take the lowest value of each point to make the smallest allowable rectangle.
  7. select the largest rectangle from the 2 boxes if there are 2.

Do you see any holes in this theory?

0 Kudos
Message 8 of 14
(685 Views)

Re: Need help with some pixel calculations

I'm not above showing half finished, terribly written, broken code.  Here is what I came up with yesterday and assumed I'd get time to finish it today, that doesn't seem to be the case.  It partially works but as you can see from my example code the Red box is too large, and actually crosses over a defined rect due to the second half of the rules not being completed right.


Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
Interesting in learning all you can about automotive CAN bus communication? Checkout my 12 part CAN Blog series.

0 Kudos
Message 9 of 14
(676 Views)

Re: Need help with some pixel calculations

I also could not finish it today, and I got a bit confused during the implementation of a brute force approach, based on a paper from the 80's. I attach the paper, and my project which I just started, someone might get faster than me. I think one thing which needs to be clarified, is the position of the origo. It might be, that in the paper, I think, the origo is bottom left instead of the native LV top-left position coordinate system...

 

In the paper look for the section 3: "The algorithms". I started to implement first this "brute force" approach, which always take Ordo(n^2) steps as I understood.

The relevant subVI is the  "maximum_empty_rectangle.vi".

0 Kudos
Message 10 of 14
(668 Views)
Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.