What does sun.awt.geom.Crossings do? - java

I've been away from Java for several years, so forgive my rust. I inherited some code targeting Java SE 1.5. When building under Java 1.7.0, there are several build warnings with the text:
Crossings is internal proprietary API and may be removed in a future
release.
I would like to remedy this build warning, probably by replacing this code with my own. On examining the code, I see that the full class in question is sun.awt.geom.Crossings. The OpenJDK code is available, of course, but I do not understand the overall purpose of the class or its concrete implementations. What is the purpose of sun.awt.geom.Crossings? Where can I find more documentation?

Since #ee. has not come back to rewrite his or her comments as an answer, I will do so here. #ee., if you do stop by, I'd be happy to put the checkmark by your answer instead.
Check this http://docstore.mik.ua/orelly/java/awt/ch02_01.htm#JAWT-CH-2-FIG-9:
Filling polygons is a complex topic. It is not as easy as filling rectangles or ovals because a polygon may not be closed and its edges may cross. AWT uses an even-odd rule to fill polygons. This algorithm works by counting the number of times each scan line crosses an edge of the polygon. If the total number of crossings to the left of the current point is odd, the point is colored. If it is even, the point is left alone.
You can see Crossings class is used here; for example: Area.contains() to check the crossings of a rectangular area inside an area. in http://kickjava.com/src/java/awt/geom/Area.java.htm. Since its application is mostly used inside other commonly used classes, you don't have to worry so much. But, if you use it directly, then you may have a problem in the future!

Related

Check if given coordinates are within letter of a text object

Greeting, wise ones!
I am trying to make a generator for pictures like this one. My idea is to make 2 patterns (vertical lines and horizontal lines). After that, I need to make vertical lines only appear "within" the letter but go a bit beyound if they don't intersect a horizontal line. Same for horizontal line, just for being "outside" the letter.
To perform this I need to know, which pixels are "within" letters of the text() object and which are not. This is the only thing, that I can't get my head around. Any ideas on how to implement this?
(If you have a simpler idea of how to make this generator, I'll happily read about them as well, I'm not too sure that mine is the best)
TL;DR: solution
So, initially, I was doing it in Java Processing and was thinking in terms of points and "if" conditions. I couldn't get any meaningful help and abandoned the problem, doing the thing by hand.
However, later I encountered a problem with detecting if a point is within a polygon in Unity and found a solution that includes the concept of raycasting. It's easily implemented in Unity but will require some extra work in something like Java Processing. In any case, this is an excellent answer to my question. I hope it helps anyone who encounters a similar problem.

AnyLogic: compensating for double overflow in GISRegion.area()

I'm trying to sort a collection of AnyLogic GISRegions by their geographical area. Said area is calculated using GISRegion.area(units), which is straightforward enough. The areas I'm using, however, are city-scale and the method returns a double. This appears to cause overflow problems:
I don't think I'm doing anything wrong with my code, so presumably this is an AnyLogic problem. For brevity, I've included a line that prints each region's area rather than the sorting steps:
// For each region of the Australian Capital Territory, print its area in km^2:
areas.forEach(next -> traceln(""+next.name+": " + next.gisRegion.area(SQ_KILOMETER)));
Has anyone encountered this issue? How did you get around it?
For non-AnyLogic users, I have all the lat-long points in each geoshape. How might I calculate the area using those points?
[Not really a full answer, but the ideas are too long for a comment.]
I assume you've raised an AnyLogic support request since it seems 100% a bug. Since this is just a basic 'calculate area' function, I can't see any way round it other than, as you suggest, calculating it in an alternative manner from the vertex lat/longs that you have, and can get via getPoints() on the GISRegion.
Since this is just an N-sided polygon, surely there must be standard Java libraries that could calculate that, though that's not allowing for the GIS projection (not sure what level of error that might introduce); you'd expect open GIS libraries to cope with the latter. Since a GISRegion has a createOMGraphicObject() method to create an OpenMap standard(?) format graphic, that could be useful if that's a standard format other libraries can work with.
There's code on glennon's answer to this GIS StackOverflow question that claims to perform the calculation (or you make be able to hook in to PostGIS as in fmark's answer).

Is there a good free implementation of Sugiyama Layout for Java?

I am using JUNG library for network-graphs. I also found an implementation of the sugiyama layout: http://sourceforge.net/tracker/?func=detail&aid=2944336&group_id=73840&atid=539121
But unfortunatly its edge-crossing method seems not to work and I can't solve it. The vertical alignment of the nodes is all but correct.
(Unless theres no error free version of this JUNG algorithm)
Does anyone know of of another implementation? As long as it's free and possible to wrap the it, any Java code (so not necessarily JUNG) would be sufficient.
If theres a very good Library in another language that would take a graph and return a graphml file with fixed positions for nodes it would help also :)
This layout works fine for me:
http://code.google.com/p/daglayout/
I had to make a modification to the code that I couldn't check in : line 275 should be "continue" instead of "return". Other than that, the algorithm seems to work if you give it enough space for your particular graph. I have a heuristic I use based on total nodes and total tree depth.
There is one in this project:
It contains the classic Sugiyama (with all of the generated vertices), the Eiglsperger optimization (pvertex and qvertex), a splay tree, brandes kopf horizontal alignment, 4 kinds of layering:
(top down, longest path, coffman-graham, network simplex)
The code is in the jungrapht-layout module and jar, which has no java.awt dependencies, so it would be easier to use with non-awt rendering (like JavaFX).
scroll down for a picture. The code is here

Feature/blob correlation and histogram analysis

I'm working on a sketch search engine that correlates whatever someone's sketching with a picture in the database (the db is just about 40 pictures now). I'm doing this mostly for fun so I'm not that well-versed in computer imaging techniques.
First of all, are there any rules of thumb on how one should create histograms (bin sizes, ranges, etc)? I'm using some histogram code found at http://www.scribd.com/doc/6194304/Histograms (but ported to JavaCV). Sometimes I get good results, sometimes I get bad results, most of the time I get "meh" results. I've been experimenting a TON with bin sizes and ranges and I'm wondering if comparing higher dimensional histograms may be the answer here.
Second of all, it seems that black makes a very strong presence in my current histogram setup (even a black dot shifts the entire result set). Should this be expected? Or did I screw something up? Example:
And after the dot:
Note how I'm already getting pictures of "earthrise" as "close" matches.
I'm also wondering what methods I should use for blob or feature analysis. I think that stuff like SURF may be overkill because I only want to broadly compare blobs, not accurately map templates. Is there any way I can compare the edges after being passed through a Canny filter? (Low complexity if possible):
For example, here, I want the two smiley faces to be at the top because the needle smiley "blob" is more closely related to the smily face shape than to a bunch of passion fruit or a galaxy.
Phew long question. If you want to try out the engine for yourself, go to http://skrch.dvt.name/ (shameless plug, I know, I know -- only works in FF/Chrome/Safari). Maybe more experienced computer vision people can make suggestions based on results. Oh, I'm using the CV_COMP_BHATTACHARYYA distance when comparing histograms (it seemed that it gave the best results although chi-square isn't bad either).
Is there a background ?
IS it significant ?
Maybe you need to look at whether there is a user-supplied background or not.
then you "just" need to have 2 histogram per db entry, one with bg, one without.
That'll stop earthrise looking like an apple with a dot.
for basic bg separation, try a canny, then taking "outside" and removing it from a copy of the original.

How do I find the overlapping area between two arbitrary polygons

I'm trying to create a method that will take in two arbitrary lists of nodes, for a subject and a clipping polygon, and output either:
a) the area of the overlap
b) a list of nodes for the resulting (clipped) polygon so that I can calculate the area
I've found lots of examples which clip an arbitrary polygon using a rectangular window (which is fairly standard in graphics) but that's not what I need. I understand that it's fairly complex, particularly when you get holes, convex polygons and the like. The only simplifying assumption which I can make is that the arbitrary polygons will not contain any holes.
I'm not at all an expert in this field, so would something like the Sutherland-Hodgman algorithm work? Are there any libraries out there which already do this, or is my best bet to simply implement the algorithm as described in pseudo-code on Wikipedia?
Thanks for the help!
Are there any libraries out there which already do this ...
Polygon clipping is a complex task. I wouldn't recommend trying to do it yourself unless you want to spend many months on it.
Wikipedia lists a number of clipping libraries (and IIRC in that list only Clipper is free for use in commercial applications):
http://en.wikipedia.org/wiki/Boolean_operations_on_polygons#External_links
ps: I admit to a personal bias for Clipper since I'm the author :)
More info here: http://angusj.com/delphi/clipper.php
Sounds like Weiler-Atherton is the one you need:
The algorithm requires polygons to be
clockwise and not reentrant (self
intersecting). The algorithm can
support holes (as counter-clockwise
polygons wholly inside their parent
polygon), but requires additional
algorithms to decide which polygons
are holes.
Your polygons fit those criteria, right?
I don't know about implementations, but it sounds like you would be better off implementing W-A than S-H if either of your polygons could be concave.
Try gpc.
I found that using the JavaGeom library worked very well. It integrates the code from the Java port of GPC (which is no longer available) and thus allows arbitrary polygon operations. Using SimplePolygon2D and Polygon2DUtils.intersection() I was able to get the desired operation.
I've tried a lot of different libraries and the one that worked best was the JTS Topological Suite which is pure Java and LGPL2 licensed.

Categories