Graphing Data with Java Processing - java

I'm looking at creating a program with Processing (processing.org) in Java. The program will involve graphing a large amount of 2D data. I would like for the points to be displayed to fill the window. I've looked at their libraries and I don't see anything for data visualization. Am I missing something?

I've always used JFreechart or, for more complex graphing exporting to a text flie and then gnuplot.

another vote for JFreeChart. Although for more complex graphing I've written my own (AWT).

JUNG Is a favorite of mine.

Processing is really powerful and can be considered a "raw" language given how close you can get to actual graphic programming. I've myself created many graphs and can tell you that you have to be very careful when using this library. It's great but you have to do everything from scratch. This means creating lines for the x and y axis, creating your labels, creating the space, etc.
My suggestion is to set the number of points you'll most likely have, say 1000, and always display with that much data. If you have too little or too much, just adjust it before sending it to graph. This way you'll always have a set number. From here what you do is the following:
pushMatrix();
scale(widthOfGraph/1000, heightOfGraph/numberOfPointsUp);
beginShape(LINES);
for (int i = 0; i < 1000; i++) {
vertex(x0,y0);
vertex(x1,y1);
endShape();
popMatrix();
This will create all your lines in a single drawing operation meaning you'll save a lot of opening and closing shapes. You are also using a stack matrix to use the scale operation to adjust the displaying size of your canvas. Everything else is up to you. Hope that helps.

Related

How can I graph values that are incredibly small in Java?

Basically I am attempting to use JFreeChart right now to graph some values. The only problem is that the values are incredibly minuscule, e.g 7.069781E-13. I believe these values are too small for JFreeChart to display. How can I display these small values visually in Java in a line chart format?
It looks like this currently:
And I want to make it look similar to this:
I found a work around.
I simply multiplied all the values by a factor of 100 so the graph now looks similar to the one in the example. I will include a disclaimer in the legend saying the chart has been multiplied by a factor to clearly see the line chart.
Also consider these alternative:
Invoke setRange(), seen here, to expand the y axis in the area of interest.
Add suitable controls, seen here, to control y zoom.
Advise users how to use the mouse for zoom control, as shown here.

Turn a set of 3d coordinates into polygonal "landscape" in Java

I'm working on a visualization project. From the data I have calculated the X, Y, and Z coordinates for a large set of points. Using Processing it was very simple to draw this out with lines and dots.
From the top it looks like this:
And from a side angle you can see how it occupies 3D space
The part I'm struggling with is turning this into polygons. I need the end result to be something I can export as a .obj file, and then later open in Blender or similar 3D modelling programs.
The two main issues are that these points are not on a grid, but are instead organized in a circle based on radian angles, and that the triangle structure isn't all that simple.
I tried drawing out my own polygons (it's kinda sorta working), but I'm getting to the point where the maths are getting a bit too complex to handle and my code is bloated with arrays, if statements, and for loops...
Surely there must be a better way? Are there any plugins maybe that would help me with this task? Or some techniques I should take a look at?
Processing has screenX() and screenY() functions that take a 3D point and return a 2D point. That sounds like pretty much exactly what you're looking for. Please see the reference for more info.

How do you create and render a 3D Fractal?

So I've been assigned a recursive art project for my AP CS class and have a bunch of spare time, so I've decided to try something a little bit more ambitious.
My plan is to create a 3D fractal, either rendered and shaded in a visualization with GL, or represented via spatially mapping the respective equations' outputs to points on a cube and drawing those. If this explanation seems unclear, please check out the links at the bottom for images. Now, I don't need the fractal to be able to be modified in-program. I just need it to render a single BufferedImage, which I'll be putting directly on a JFrame.
My experience in Java, as far as this project goes, is a bit limited. I've drawn Mandelbrot and Julia set fractals before, but I have little to no experience drawing/rendering objects in 3D in Java. This is all stuff I can look up and figure out myself though, so no worries here.
Thus, the question: How does one map a fractal that should be in the 2nd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 2) to the 3rd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 3)? I'm lost trying to mathematically work this out, and I believe there is a more organized approach to go about this circumventing a lot of the math that already exists.
Also, if you are aware of a structured approach to render a 2D fractal, as drawn by a formula, and render it in 3D, provided the respective formula is provided (power is raised), please let me know. I've heard of Ray Tracers, no idea what they are, a brief summary would be cool.
Here are links with pictures of the result I want to obtain:
http://2008.sub.blue/assets/0000/4575/power8_large.jpg
https://www.youtube.com/watch?v=rK8jhCVlCtU
It looks like the image is an example of a Mandelbulb. The is a similar iteration formula to the Mandlebrot set but using 3D points and a novel idea of what raising a 3D point to a power means.

Java game looks like it runs slow?

I'm making a game which involves multiple "balls" using the same class, I have everything working the way I want it to using a ArrayList but my problem is that the more of the balls I add the slower it renders them. This makes the game look like it is going slow and it will flicker, I can't provide a video sorry, but I can provide the code I am using the draw the balls:
code:
for(int i=0;i<balls.size(); i++){
Ball tmp = (Ball) balls.get(i);
g2d.drawImage(tmp.getImage(), tmp.getX(),tmp.getY(),null);
}
Could you give me examples or direction for a better way to render the balls?
Thanks.
For the flickering, you'll want to learn about double buffering. If the slowness is something aside from perception due to not double buffering, you'll have to profile it or maybe show some more code.
I'm not sure of the speed ramifications (probably not much), but you should be specifying a type when using an ArrayList (i.e ArrayList<Ball>) instead of typecasting everything as you get it.

Object detection with a generic webcam

Here’s my task which I want to solve with as little effort as possible (preferrably with QT & C++ or Java): I want to use webcam video input to detect if there’s a (or more) crate(s) in front of the camera lens or not. The scene can change from "clear" to "there is a crate in front of the lens" and back while the cam feeds its video signal to my application. For prototype testing/ learning I have 2-3 images of the “empty” scene, and 2-3 images with one or more crates.
Do you know straightforward idea how to tackle this task? I found OpenCV, but isn't this framework too bulky for this simple task? I'm new to the field of computer vision. Is this generally a hard task or is it simple and robust to detect if there's an obstacle in front of the cam in live feeds? Your expert opinion is deeply appreciated!
Here's an approach I've heard of, which may yield some success:
Perform edge detection on your image to translate it into a black and white image, whereby edges are shown as black pixels.
Now create a histogram to record the frequency of black pixels in each vertical column of pixels in the image. The theory here is that a high frequency value in the histogram in or around one bucket is indicative of a vertical edge, which could be the edge of a crate.
You could also consider a second histogram to measure pixels on each row of the image.
Obviously this is a fairly simple approach and is highly dependent on "simple" input; i.e. plain boxes with "hard" edges against a blank background (preferable a background that contrasts heavily with the box).
You dont need a full-blown computer-vision library to detect if there is a crate or no crate in front of the camera. You can just take a snapshot and make a color-histogram (simple). To capture the snapshot take a look here:
http://msdn.microsoft.com/en-us/library/dd742882%28VS.85%29.aspx
Lots of variables here including any possible changes in ambient lighting and any other activity in the field of view. Look at implementing a Canny edge detector (which OpenCV has and also Intel Performance Primitives have as well) to look for the outline of the shape of interest. If you then kinda know where the box will be, you can perhaps sum pixels in the region of interest. If the box can appear anywhere in the field of view, this is more challenging.
This is not something you should start in Java. When I had this kind of problems I would start with Matlab (OpenCV library) or something similar, see if the solution would work there and then port it to Java.
To answer your question I did something similar by XOR-ing the 'reference' image (no crate in your case) with the current image then either work on the histogram (clustered pixels at right means large difference) or just sum the visible pixels and compare them with a threshold. XOR is not really precise but it is fast.
My point is, it took me 2hrs to install Scilab and the toolkits and write a proof of concept. It would have taken me two days in Java and if the first solution didn't work each additional algorithm (already done in Mat-/Scilab) another few hours. IMHO you are approaching the problem from the wrong angle.
If really Java/C++ are just some simple tools that don't matter then drop them and use Scilab or some other Matlab clone - prototyping and fine tuning would be much faster.
There are 2 parts involved in object detection. One is feature extraction, the other is similarity calculation. Some obvious features of the crate are geometry, edge, texture, etc...
So you can find some algorithms to extract these features from your crate image. Then comparing these features with your training sample images.

Categories

Resources