Magnifying Lens examples using JUNG - jung

I am trying to use the JUNG library on a project.
But I am having trouble identifying if there is a simple way already to change the size of the magnifying lens on the example projects.
Currently in all the examples the magnifying lens are bounded to the size of the graph view and to the window size.
Is there a method to set only the size of the lens and break the link to the window size?
I am using the latest available JUNG version.
Thank you so much in advance!
regards,
Nelson

The local fix that you made (adding a constructor parameter to ViewLensSupport to specify the lens size directly) appears to be both necessary and sufficient to fix your problem.
I agree that it makes sense to be able to control the lens size independently; feel free to send us a pull request: https://github.com/jrtom/jung/pulls

Did you see that you can use the mouse to resize the lens by pressing and dragging on its edge? The code that is called in that case is this:
lensTransformer.setViewRadius(r);
In the edu.uci.ics.jung.samples.LensDemo, I was able to set the initial size of the lens (to 20) by modifying the code like this:
(Note that you can still use the mouse on the edge of the lens to resize it later)
final JRadioButton hyperView = new JRadioButton("Hyperbolic View");
hyperView.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
// added to set the lens size to 20
if (e.getStateChange() == ItemEvent.SELECTED) {
MutableTransformer mt = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
((LensTransformer) mt).setViewRadius(20);
}
}
});
final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout");
hyperModel.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
// added to set the lens size to 20
if (e.getStateChange() == ItemEvent.SELECTED) {
MutableTransformer mt = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
((LensTransformer) mt).setViewRadius(20);
}
}
});

Related

Is it possible to create a Q-Q plot when lacking a coordinate system?

I'm looking to create a Q-Q plot within Rascal using the Vis library. I have been told there is no positional system. Is this true? If true, how would I go about plotting this or any scatterplot? Does anyone have an example of this in use?
That's an excellent question. Certainly Rascal's Vis library is "point free" in the sense that its layout mechanism has no absolute coordinate system. However, there are certain Figure kinds which have a relative coordinate system wrt their own "origin". When you combine several of those using horizontal, vertical or overlay boxes (and align them properly), you can create the effect of bar charts, scatterplots and whatever you desire.
In particular the overlay Figure composition is interesting: http://tutor.rascal-mpl.org/Rascal/Libraries/Vis/Figure/Figure.html#/Rascal/Libraries/Vis/Figure/Figures/overlay/overlay.html
Figure point(num x, num y){ return ellipse(shrink(0.05),fillColor("red"),align(x,y));}
coords = [<0.0,0.0>,<0.5,0.5>,<0.8,0.5>,<1.0,0.0>];
ovl = overlay([point(x,y) | <x,y> <- coords]);
render(ovl);
Produces this (both code and image taken from the documentation linked above):
Each point is an ellipse which is aligned at the (x, y) position relative to the origin of the enclosing overlay box.
The origin by default of this overlay seems to be the upper-left corner, when no other FProperty's are given to the overlay. It's possible other alignment options for the overlay Figure also change the position of its origin.
With the help of Jurgen Vinju I wrote this code, hope it helps someone: https://gist.github.com/rlmhermans/c9e82a6a623b65f0c6957ab3ff2742cf

How to generate different 2D displays in Repast Simphony (gui or style code?)?

I have built a 3D model in repast simphony and it is working (fairly) well. However, due to the nature of the model, agents tend to form dense clumps. I was wondering if there is a way to generate a 2D slice or cross section through the middle of the clump to see what agents are doing inside the clumps, by either generating a continuously updating 2D display or an end-state view.
I have explored the display options in the gui and experimented with different layering of the agents, but due to the density, none of these have worked. Would there be a way to alter this aspect of the gui slightly to give a 2D view (for example) of the yz plane at x=25 in a 50x50x50 grid.
Thank you in advance for your help!
You can change the transparency of shapes in the 3D display by changing the transparency attributes in the style class based on a visibility attribute of the agent. For example, your agents could check their current position in 3D space and only return isVisible() true when the agent is in the plane of space you'd like to visualize. This will only show agents in the 3D display that exist on your defined plane, which can be any x,y,z orientation through the space. In your style class you will need to update the transparency in the getAppearance(...) method as follows:
public TaggedAppearance getAppearance(MyAgent agent, TaggedAppearance taggedAppearance, Object shapeID) {
if (taggedAppearance == null) {
taggedAppearance = new TaggedAppearance();
// Customize your agent style here...
AppearanceFactory.setMaterialAppearance(taggedAppearance.getAppearance(), Color.white);
}
if (trans == null) {
trans = new TransparencyAttributes();
trans.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
trans.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
trans.setCapability(TransparencyAttributes.ALLOW_MODE_READ);
trans.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
trans.setTransparencyMode(TransparencyAttributes.FASTEST);
taggedAppearance.getAppearance().setTransparencyAttributes(trans);
}
if (agent.isVisible())
trans.setTransparency(0.0f);
else
trans.setTransparency(1.0f);
return taggedAppearance;
}
You could also adjust the transparency value from 0 to 1 to provide different levels of transparency, so that the agents of interest are purely opaque (0.0f) while agents in the periphery are very transparent (0.8f).

Edge detection on pool table

I am currently working on an algorithm to detect the playing area of a pool table. For this purpose, I captured an image, transformed it to grayscale, and used a Sobel operator on it. Now I want to detect the playing area as a box with 4 corners located in the 4 corners of the table.
Detecting the edges of the table is quite straightforward, however, it turns out that detecting the 4 corners is not so easy, as there are pockets in the pool table. Now I just want to fit a line to each of the side edges, and from those lines, I can compute the intersects, which are the corners for my table.
I am stuck here, because I could not yet come up with a good solution to find these lines in my image. I can see it very easily when I used the Sobel operator. But what would be a good way of detecting it and computing the position of the corners?
EDIT: I added some sample Images
Basic Image:
Grayscale Image
Sobel Filter (horizontal only)
For a general solution, there will be many sources of noise: problems with cloth around the rails, wood texture (or no texture) on the rails, varying lighting, shadows, stains on the cloth, chalk on the rails, and so on.
When color and lighting aren't dependable, and when you want to find the edges of geometric objects, then it's best to think in terms of edge pixels rather than gray/color pixels.
A while back I was thinking of making a phone-based app to save ball positions for later review, including online, so I've though a bit about this problem. Although I can provide some guidance for your current question, it occurs to me you'll run into new problems each step of the way, so I'll try to provide a more complete answer.
Convert the image to grayscale. If we can't get an algorithm to work in grayscale, we'll inevitably run into problems with color. (See below)
[TBD] Do some preprocessing to reduce noise.
Find edge points using Sobel or (if you must) Canny.
Run Hough lines detection, but with a few caveats and parameterizations as described below.
Find the lines described a keystone-shaped quadrilateral. (This will likely be the inner quadrilateral of two: one inside the rail on the bed, and the other slightly larger quadrilateral at the cloth/wood rail edge at top.)
(Optional) Use the side pockets to help determine the orientation of the quadrilateral.
Use an affine transform to map the perspective-distorted table bed to a rectangle of [thankfully] known relative dimensions. We know the bed sizes in advance, so you can remap the distorted rectangle to a proper rectangle. (We'll ignore some optical effects for now.)
Remap the color image to the perspective-corrected rectangle. You'll probably need to tweak the positions of some balls.
General notes:
Filtering by color in the general sense can be difficult. It's tempting to think of the cloth as being simply green, blue, or red (or some other color), but when you look at the actual RGB values and try to separate colors you'll begin to appreciate what a nightmare working in color can be.
Optical distortion might throw off some edges.
The far short rail may be difficult to detect, BUT you do this: find the inside lines for the two long rails, then search vertically between the two rails for the first strong horizontal-ish edge at the far side of the image. That'll be the far short rail.
Although you probably want to use your phone camera for convenience, using a Kinect camera or similar (preferably smaller) device would make the problem easier. Not only would you have both color data and 3D data, but you would eliminate some problems with lighting since the depth data wouldn't depend on visible lighting.
For your app, consider limiting the search region for rail edges to a perspective-distorted rectangle. The user might be able to adjust the search region. This could greatly simplify the processing, and could help you work around problems if the table isn't lit well (as can be the case).
If color segmentation (as suggested by #Dima) works, get the outline of the blob using contour following. Then simplify the outline to a quadrilateral (or a polygon of few sides) by the Douglas-Peucker algorithm. You should find the four table edges this way.
For more accuracy, you can refine the edge location by local search of transitions across it and perform line fitting. Then intersect the lines to get the corners.
The following answer assumes you have already found the positions of the lines in the image. This however can be done "easily" by directly looking at the pixels and seeing if they are in a "line". Usually it is easier to detect this if the image has been deskewed first as well, i.e. Rotated so the rectangle (pool table) is more like this: [] than like /=/. Then it is just a case of scanning the pixels and if there are ones of similar colour alongside it assuming a line is between them.
The code works by looping over the lines found in the image. Whenever the end points of each line falls within a tolerance on within the x and y coordinates it is marked as a corner. Once the corners are found I take the average value between them to find where the corner lies. For example:
A horizontal line ending at 10, 10 and a vertical line starting at 12, 12 will be found to be a corner if there is a tolerance of 2 or more. The corner found will be at: 11, 11
NOTE: This is just to find Top Left corners but can easily be adapted to find all of them. The reason it has been done like this is because in the application where I use it, it is faster to sort each array first into an order where relevant values will be found first, see: Why is processing a sorted array faster than an unsorted array?.
Also note that my code finds the first corner for each line which might not be applicable for you, this is mainly for performance reasons. However the code can easily be adapted to find all the corners with all the lines then either select the "more likely" corner or average through them all.
Also note my answer is written in C#.
private IEnumerable<Point> FindTopLeftCorners(IEnumerable<Line> horizontalLines, IEnumerable<Line> verticalLines)
{
List<Point> TopLeftCorners = new List<Point>();
Line[] laHorizontalLines = horizontalLines.OrderBy(l => l.StartPoint.X).ThenBy(l => l.StartPoint.Y).ToArray();
Line[] laVerticalLines = verticalLines.OrderBy(l => l.StartPoint.X).ThenBy(l => l.StartPoint.Y).ToArray();
foreach (Line verticalLine in laVerticalLines)
{
foreach (Line horizontalLine in laHorizontalLines)
{
if (verticalLine.StartPoint.X <= (horizontalLine.StartPoint.X + _nCornerTolerance) && verticalLine.StartPoint.X >= (horizontalLine.StartPoint.X - _nCornerTolerance))
{
if (horizontalLine.StartPoint.Y <= (verticalLine.StartPoint.Y + _nCornerTolerance) && horizontalLine.StartPoint.Y >= (verticalLine.StartPoint.Y - _nCornerTolerance))
{
int nX = (verticalLine.StartPoint.X + horizontalLine.StartPoint.X) / 2;
int nY = (verticalLine.StartPoint.Y + horizontalLine.StartPoint.Y) / 2;
TopLeftCorners.Add(new Point(nX, nY));
break;
}
}
}
}
return TopLeftCorners;
}
Where Line is the following class:
public class Line
{
public Point StartPoint { get; private set; }
public Point EndPoint { get; private set; }
public Line(Point startPoint, Point endPoint)
{
this.StartPoint = startPoint;
this.EndPoint = endPoint;
}
}
And _nCornerTolerance is an int of a configurable amount.
A playing area of a pool table typically has a distinctive color, like green or blue. I would try a color-based segmentation approach first. The Color Thresholder app in MATLAB gives you an easy way to try different color spaces and thresholds.

Bounding box only for the visible part of the layer

I was wondering if there is a way to get the bounding box of not the complete layer, but only the part of the layer that is visible in the current zoom level of the map?
So, I need to get the screen coordinates of the bounding box of the layer drawn on the screen. I could not find a way to achieve this.
EDIT:
Unfortunately this is not solving my problem. This is exactly the point that I got to latest and in some cases it is not working. Since stackoverflow does not allow me to upload images because of my reputation I will try to describe:
Imagine that I have a path which is crossing the screen almost parallel to y axis, however outside the screen it is at least x-axis long. In this case the solution proposed will return min and max screen coordinates for x axis, where it needs to be a short interval that it is crossing the screen. In a way I need the bounding box of the visible part of the layer.
EDIT 2:
Thank you all for your answers. I tried to use "getFeaturesInExtent" function, but I get an error saying: "Uncaught TypeError: undefined is not a function". I am using the latest OpenLayers which is version 3.4.0. I suppose I am getting this error because this function is not implemented in this version.
The way I am using is the following:
var mapExtent = map.getView().calculateExtent(map.getSize());
var features = result.getSource().getFeaturesInExtent(mapExtent);
What kind of solution do you suggest for me? (I tried to use master version downloading ZIP from: https://github.com/openlayers/ol3, but the map did not work in this case.)
Thanks again!
I think the only things what you need is the extent of the view and the extent of the layer and the ol.extent.getIntersection() Function.
You can get the Extent of the current View by f.ex
map.getView().calculateExtent(map.getSize());
The global extent of your layer by
`layer.getExtent()`.
And the intersecting Extent with.
ol.extent.getIntersection(extent1, extent2,opt_extent)
Should return the intersecting extent of the current view and your layer. Be aware that not all mentioned functions are stable.
I found the solution in the following:
var mapExtent = map.getView().calculateExtent(map.getSize());
var intersectedFeatures = [];
for (var i = 0; i < points.length; i++){
if(ol.extent.containsCoordinate(mapExtent, points[i]))
intersectedFeatures.push(points[i]);
}
var visibleLayerExtent = ol.extent.boundingExtent(intersectedFeatures);
Thank you all for the help!

How to center align watermark when using burning image plugin in Grails

I need to apply watermarks to the uploaded images. According to the documentation for the burning image this is done with following code:
def orginalFileName
burningImageService.doWith('path/to/my/file.jpg', 'path/to/output/dir')
.execute {
it.scaleApproximate(800, 600)
orginalFileName = it.watermark('path/to/watermark',
['right':10, 'bottom': 10])
}
.execute ('thumbnail', {
it.scaleAccurate(200, 200)
})
Is there an easy way to center align the watermark without needing to calculate the coordinates? I cannot use the given size (800,600) since it is an approximate size. I cannot use scaleAccurate because I don't want to crop the image.
Just remove the position coordinate from the parameters and it will center the watermark by default.
burningImageService.doWith('path/to/my/file', 'path/to/output/dir')
.execute {
it.watermark('path/to/watermark')
}
For more info please refer:
https://code.google.com/p/burningimage/wiki/Images_manipulation_handling

Resources