How do I annotate my graph using JUNG's annotation system? - java

I cannot seem to find any documentation on annotating my JUNG graph. The most I've cobbled together is:
AnnotationRenderer renderer = new AnnotationRenderer();
AnnotationPaintable annotate = new AnnotationPaintable(viewer.getRenderContext(), renderer);
Shape square = new Rectangle(0, 0, 50, 50);
Annotation<Shape> a = new Annotation<Shape>(square, Annotation.Layer.UPPER, null, true,
new Point2D.Double(0, 0));
annotate.add(a);
How do I take this and start drawing the actual annotations within the AnnotationPaintable object?

The answer is to add it to your visualization viewer:
viewer.addPostRenderPaintable(...)

Related

Java JTS Polygon contains Another Polgyon

I am trying to use JTS to tell if one Polygon contains another Polygon.
I have resources here. How do I utilize the syntax? this is giving me errors. The next step is to apply contains. If anyone has experience with JTS, it would be helpful.
https://gis.stackexchange.com/questions/368520/jts-geometry-contains-not-detecting-point-of-an-inner-polygon-on-edge-of-outer
https://gis.stackexchange.com/questions/262751/how-to-determine-if-one-polygon-is-contained-in-another
https://locationtech.github.io/jts/javadoc/org/locationtech/jts/geom/Polygon.html
Polygon item1 = ((0 0, 1000 0, 1000 1000, 0 1000, 0 0))
Polygon item2 = ((500 500, 1000 500, 600 600, 500 600, 500 500))
You cannot create a polygon just like that. JTS is a rather heavy framework, so you need to go the full route.
Everything starts with GeometryFactorydocs. It is responsible for creating all geometries, it is necessary because it takes into account a few things like PrecisionModel for example.
You need to understand the hierarchy of geometries, Polygon is described by a line - LineRig or LineString (the difference is out of the scope for this question).
You need to realize that every line consists of points, which can be described either by Point or Coordinate. So if you want to create a Polygon
The code would look like this:
GeometryFactory factory = new GeometryFactory(); //default
Coordinate[] coordinates1 = {
new CoordinateXY(0,0),
new CoordinateXY(1000,0),
new CoordinateXY(1000, 1000),
new CoordinateXY(0, 1000),
new CoordinateXY(0, 0)
};
Coordinate[] coordinates2 = {
new CoordinateXY(500,500),
new CoordinateXY(1000,500),
new CoordinateXY(600, 600),
new CoordinateXY(500, 600),
new CoordinateXY(500, 500)
};
LinearRing linearRing1 = factory.createLinearRing(coordinates1);
LinearRing linearRing2 = factory.createLinearRing(coordinates2);
Polygon polygon1 = factory.createPolygon(linearRing1);
Polygon polygon2 = factory.createPolygon(linearRing2);
assertTrue(polygon1.contains(polygon2));

JavaFX - Maintain Shape Borders after using Shape.union()

Is there a way to maintain the borders/strokes on a JavaFX Shape after using the union function? For example here is my code:
Shape rect = new Rectangle(150, 150);
rect.setFill(Color.WHITE);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(4);
Line line = new Line(0, 40, 150, 40);
line.setStrokeWidth(2);
Shape combined = Shape.union(line, rect);
combined.setFill(Color.WHITE);
combined.setStroke(Color.BLACK);
pane.getChildren().add(combined);
Expected Output:
Actual Output:
Is there anyway that I can union the two together so that I can drag and drop them together?
your problem is combined.setFill(Color.WHITE); ,because it clear all previous shape changes .
Try something like this
Line line = new Line(0, 40, 150, 40);
Shape rect = new Rectangle(150, 150);
Shape combined = Shape.subtract(rect,line);
combined.setFill(Color.WHITE);
combined.setStroke(Color.BLACK);
rect.setFill(Color.WHITE);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(4);
line.setStrokeWidth(2);
line.setStroke(Color.BLACK);
line.setFill(Color.BLACK);
pane.getChildren().add(combined);
out put will like be this
For more info about shape.union,subtract,intersect go here

Java iText Rotate a Link Rectangle

I need to rotate a link rectangle using Java iText.
The original link rectangle appears in red. The rotated link rectangle appears in green.
My code:
PdfReader reader = new PdfReader( "input/blank.pdf" );
PdfStamper stamper = new PdfStamper( reader, new FileOutputStream( "output/blank_stamped.pdf" ) );
Rectangle linkLocation = new Rectangle( 100, 700, 100 + 200, 700 + 25 );
PdfName highlight = PdfAnnotation.HIGHLIGHT_INVERT;
PdfAnnotation linkRed = PdfAnnotation.createLink( stamper.getWriter(), linkLocation, highlight, "red" );
PdfAnnotation linkGreen = PdfAnnotation.createLink( stamper.getWriter(), linkLocation, highlight, "green" );
BaseColor baseColorRed = new BaseColor(255,0,0);
BaseColor baseColorGreen = new BaseColor(0,255,0);
linkRed.setColor(baseColorRed);
linkGreen.setColor(baseColorGreen);
double angleDegrees = 10;
double angleRadians = Math.PI*angleDegrees/180;
stamper.addAnnotation(linkRed, 1);
linkGreen.applyCTM(AffineTransform.getRotateInstance(angleRadians));
stamper.addAnnotation(linkGreen, 1);
stamper.close();
But this code does not rotate the recangle.
Please take a look at the following screen shot:
I have added 5 annotations to a simple Hello World file.
The first two are link annotations. Their position is defined by the rectangles linkLocation1 and linkLocation2:
Rectangle linkLocation1 = new Rectangle(30, 770, 120, 800);
PdfAnnotation link1 = PdfAnnotation.createLink(stamper.getWriter(),
linkLocation1, PdfAnnotation.HIGHLIGHT_INVERT, action);
link1.setColor(BaseColor.RED);
stamper.addAnnotation(link1, 1);
Rectangle linkLocation2 = new Rectangle(30, 670, 60, 760);
PdfAnnotation link2 = PdfAnnotation.createLink(stamper.getWriter(),
linkLocation2, PdfAnnotation.HIGHLIGHT_INVERT, action);
link2.setColor(BaseColor.GREEN);
stamper.addAnnotation(link2, 1);
The green rectangle looks like a rotated version of the red rectangle, but that's not really true: we just defined the "clickable" area that way. I don't understand why you'd want to get this effect by introducing a rotation. Why? Because a rotation always needs a rotating point. Suppose that you would introduce a rotation, what would be your rotation point? The (0, 0) coordinate? That would lead to strange results, wouldn't it?
Introducing a rotation for does make sense for some types of annotations though. In my example, I introduced three stamp annotations:
Rectangle linkLocation3 = new Rectangle(150, 770, 240, 800);
PdfAnnotation stamp1 = PdfAnnotation.createStamp(stamper.getWriter(), linkLocation3, "Landscape", "Confidential");
stamper.addAnnotation(stamp1, 1);
Rectangle linkLocation4 = new Rectangle(150, 670, 240, 760);
PdfAnnotation stamp2 = PdfAnnotation.createStamp(stamper.getWriter(), linkLocation4, "Portrait", "Confidential");
stamp2.setRotate(90);
stamper.addAnnotation(stamp2, 1);
Rectangle linkLocation5 = new Rectangle(250, 670, 340, 760);
PdfAnnotation stamp3 = PdfAnnotation.createStamp(stamper.getWriter(), linkLocation5, "Portrait", "Confidential");
stamp3.setRotate(45);
stamper.addAnnotation(stamp3, 1);
In this case, I introduce a rotation angle using the setRotate() method. This rotates the CONFIDENTIAL stamp inside the rectangle we defined. As you can see, this makes sense because the annotation does have actual content: the rotation has an impact on the way you read the word CONFIDENTIAL. In the case of the clickable area of the link annotation, there is no such content to be rotated.
If this doesn't answer your question, please rephrase your question because I don't think anyone can answer it in its current state.
Update
Please take a look at ISO-32000-1 aka the PDF specification. You'll discover that a rectangle is defined using 4 values: the x and y coordinate of the lower-left corner of the rectangle and the x and y coordinate of the upper-right corner of the rectangle. These are the two starting points of the horizontal and vertical sides. You want a rectangle that has sides that aren't horizontal/vertical. Obviously that isn't possible as you'd need the coordinates of 4 corner points to achieve that (8 values, not 4). You can achieve this using a polygon defined by QuadPoints.
See ITextShape Clickable Polygon or path

BetterCharacterControl not applying RigidBody at the right Position

So Im new to JME3 and I have a few problems understanding the BetterCharacterControl.
When I try to apply a BetterCharacterControl to a box it always "expands" from the upper part of the box instead of the center. (A picture explains that better:)
I cant find any functions to change the location it gets applied at, I already tried to create a subclass in which I changed the RigidBody to the BoxCollisionShape directly but that seems to somehow screw up the isOnGround Method. Also if I want to use slopes later it would be nice to have the capsule shape.
Box box2 = new Box(10, 15, 10);
player = new Geometry("Player", box2);
player.setLocalTranslation(new Vector3f(0, 20, 0));
Material mat = new Material(assetManager,
"Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", ColorRGBA.Blue);
mat.setColor("Diffuse", ColorRGBA.Blue);
player.setMaterial(mat);
playerC = new BetterCharacterControl(12, 30, 0);
playerC.setJumpForce(new Vector3f(0, 700, 0));
player.addControl(playerC);
rootNode.attachChild(player);
bulletAppState.getPhysicsSpace().add(playerC);
On a different note, it seems like I i have to apply a huge vector for the jump force for it to do anything (I didnt change any gravity values)
Im glad for any help
i had this same problem. The way I resolved it is not usual. I coded a class and did inherit from BetterCharacterControl overwriting getShape() method as follows:
protected CollisionShape getShape() {
//TODO: cleanup size mess..
CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));
CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
//Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); REMOVED LINE
Vector3f addLocation = new Vector3f(0, 0, 0); //NEW LINE
compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation);
return compoundCollisionShape;
}
This works because the original code is a composite created in such a way so that the child node is offset by the value: (getFinalHeight () / 2.0f). The new line adds not realize this shift, leaving the object in the center position of the box set. However, this way of solving the problem, it can create problems when actually a composite mesh is used in the final object.

AndroidPlot and RectRegion

I am using Androidplot (v0.5.0) and I want segments of my plotted series to be different colours.
I think I need to use RectRegion but the region never shows.
XYSeries series = new SimpleXYSeries(timestamps, item.getValues(), "");
LineAndPointFormatter seriesFmt = new LineAndPointFormatter(
Color.rgb(0, 200, 0),
Color.rgb(0, 100, 0),
Color.rgb(150, 190, 150));
XYRegionFormatter regionFmter = new XYRegionFormatter(Color.RED);
RectRegion region = new RectRegion(0, 10, 0, 10);
seriesFmt.addRegion(region, regionFmter);
I cant find the doco anymore for this but I can find old images from the old tutorials of what I was trying to achieve.
http://androidplot.com/w/images/thumb/1/12/RectRegions_final.jpg/398px-RectRegions_final.jpg
Here's a link to the full source code that generated the graphic you posted - hopefully that provides answers you are looking for :)
https://androidplot.jira.com/source/browse/ANDROIDPLOT/trunk/Examples/DemoApp/src/com/androidplot/demos/XYRegionExampleActivity.java?hb=true

Categories

Resources