jchart2D Multiple Y-axis titles grouped together - java

I've been using the jchart2D class by Achim Westerman for some time now and just happened upon an instance where I'm trying to make 3 Y-axes on the right hand side of my graph.
The code for making the 3 axes is as follows
//Create Y Axis 1
AAxis<IAxisScalePolicy> yAxisShaftSpeed =
new AxisLinear<IAxisScalePolicy>();
yAxisShaftSpeed.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisShaftSpeed.setMinorTickSpacing(10);
yAxisShaftSpeed.setStartMajorTick(true);
yAxisShaftSpeed.setPaintGrid(false);
yAxisShaftSpeed.setAxisTitle(new IAxis.AxisTitle("Shaft Speed (RPM)"));
IRangePolicy rangePolicyYShaftSpeed =
new RangePolicyFixedViewport(new Range(0,225));
//Create Y axis 2
AAxis<IAxisScalePolicy> yAxisWindSpeed =
new AxisLinear<IAxisScalePolicy>();
yAxisWindSpeed.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisWindSpeed.setMinorTickSpacing(10);
yAxisWindSpeed.setStartMajorTick(true);
yAxisWindSpeed.setPaintGrid(false);
yAxisWindSpeed.setAxisTitle(new IAxis.AxisTitle("Wind Speed (m/s))"));
IRangePolicy rangePolicyYWindSpeed =
new RangePolicyFixedViewport(new Range(0,25));
//Create Y axis 3
AAxis<IAxisScalePolicy> yAxisPressure =
new AxisLinear<IAxisScalePolicy>();
yAxisPressure.setAxisScalePolicy(new AxisScalePolicyManualTicks());
yAxisPressure.setMinorTickSpacing(10);
yAxisPressure.setStartMajorTick(true);
yAxisPressure.setPaintGrid(false);
yAxisPressure.setAxisTitle(new IAxis.AxisTitle("Pressure (hPa)"));
IRangePolicy rangePolicyYPressure =
new RangePolicyFixedViewport(new Range(700,1100));
I then go on to add and set the right hand Y axes as follows
timePlotZoomableChart.setAxisYRight(yAxisShaftSpeed,0);
timePlotZoomableChart.addAxisYRight(yAxisWindSpeed);
timePlotZoomableChart.addAxisYRight(yAxisPressure);
Unfortunately, when the graph comes up, the three Y axes are on the right as expected but all the titles are stacked up on each other under the first added right Y axis (yAxisShaftSpeed). Anyone have any thoughts?
Thanks in advance.

might be a bug (I never tested this). Feel free to post a bug report including the minimal runnable code, the version of jchart2d, the OS and java version at sourceforge.
kind regards,
Achim

Related

MPAndroid Chart connect different points on the scatterchart

[1
I have made a scatter plot with 3 different datasets. I want the lines between the points (in the same x-axis) to join such as to form the graph above.
This is how it looks right now, all I wanna do is to join them by a line. Is it possible with MPAndroid chart? I am currently using that library.
I tried to use combinedchart, but the result is this:
Got it! I used a candlechart. That worked like a charm. Except I just had to put my high and low values.
CandleDataSet dataSet1 = new CandleDataSet(entries,"hr");
CandleData candleData = new CandleData(time_steps,dataSet1);
candleStickChart.setData(candleData);
candleStickChart.setDrawGridBackground(false);
candleStickChart.getAxisLeft().setDrawGridLines(false);
candleStickChart.getXAxis().setDrawGridLines(false);
candleStickChart.getAxisRight().setDrawGridLines(false);
candleStickChart.setDrawBorders(false);
candleStickChart.getXAxis().setTextColor(Color.parseColor("#FFF37D63"));
candleStickChart.setBackgroundColor(Color.TRANSPARENT);
candleStickChart.getLegend().setEnabled(false);
candleStickChart.setDescription("");
candleStickChart.getAxisLeft().setTextColor(Color.parseColor("#FFF37D63"));
candleStickChart.getAxisRight().setEnabled(false);
candleStickChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
candleStickChart.setPinchZoom(false);
candleStickChart.setDoubleTapToZoomEnabled(false);

Rendering a model basic on JPCT-AE with ARToolkit in Android

i want to render model via JPCT-AE and use the ARToolkit to realizing AR Application.
so , i inject the code as below into the ARToolkit Project:
Matrix projMatrix = new Matrix();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVector translation = projMatrix.getTranslation();
SimpleVector dir = projMatrix.getZAxis();
SimpleVector up = projMatrix.getYAxis();
cameraController.setPosition(translation);
cameraController.setOrientation(dir, up);
Matrix transformM = new Matrix();
transformM .setDump(ARNativeActivity.getTransformationM());
transformM .transformToGL();
model.clearTranslation();
model.translate(transformM .getTranslation());
dump.setRow(3,0.0f,0.0f,0.0f,1.0f);
model.clearRotation();
model.setRotationMatrix(transformM );
And then , the model can be render on the screen but always lie on the mark in the screen, ever i using model.rotateX/Y/Z( (float)Math.PI/2 );
Actually, the matrix output from the ARToolkit::ARNativeActivity.getTransformationMatrix() is correct, and then i split this 4*4Matrix into translation Matrix and Rotation Matrix and set into the model like this:
model.translate(transformM .getTranslation());
model.setRotationMatrix(transformM );
But still no work.
I would suggest to organize better your code, and work with matrices to separate the transformations to make to your model and the transformations to place the model in the marker.
What I suggest is:
First, use an additional matrix. It may be called modelMatrix, as it will store the transformation done to the model (scale, rotation and translation).
Then, declare all matrices outside this method (it is for performance reasons only, but is recommended), and on each frame simply setIdentity to them:
projMatrix.setIdentity();
transformM.setIdentity();
modelM.setIdentity();
later, make the model transformations on the modelM matrix. This transformations will apply to the model, after placed on the marker.
modelM.rotateZ((float) Math.toRadians(-angle+180));
modelM.translate(movementX, movementY, 0);
then, multiply the modelM matrix by the trasnformM (this means you get all the transformations done, and move and rotate them as the transformM describes, which in our case means that all the transformations done to the model are moved on top of the marker).
//now multiply trasnformationMat * modelMat
modelM.matMul(trasnformM);
And finally, apply the rotation and translation to your model:
model.setRotationMatrix(modelM);
model.setTranslationMatrix(modelM);
so the whole code would look as:
projMatrix.setIdentity();
projMatrix.setDump(ARNativeActivity.getProjectM());
projMatrix.transformToGL();
SimpleVector translation = projMatrix.getTranslation();
SimpleVector dir = projMatrix.getZAxis();
SimpleVector up = projMatrix.getYAxis();
cameraController.setPosition(translation);
cameraController.setOrientation(dir, up);
model.clearTranslation();
model.clearRotation();
transformM.setIdentity();
transformM .setDump(ARNativeActivity.getTransformationM());
transformM .transformToGL();
modelM.setIdentity()
//do whatever you want to your model
modelM.rotateZ((float)Math.toRadians(180));
modelM.matMul(transformM);
model.setRotationMatrix(modelM );
model.setTranslationMatrix(modelM);
I strongly reccomend to look at this tutorial about matrices and OpenGL, it is not about JPCT, but all concepts may apply also to there, and it is what I've used to place correctly models in markers with the ARSimple example as you may see in this blog entry I made.
Hope this helps!

How to render a 3D alien imported from Blender?

I'm getting mixed results trying to render a basic alien that was done in Blender:
I export in to Ogre 3D and load it in Eclipse:
Then when I load it in my code and try to render it the material won't render:
Could you tell me what I must do to achieve the full alien in my scene? The code I use in Jmonkeyengine is
Spatial model3 = assetManager
.loadModel("objects/creatures/alien/alien.mesh.xml");
model3.scale(0.3f, 0.3f, 0.3f);
model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
rootNode.attachChild(model3);
Update
I've got material files like these from the export:
dev#dev-OptiPlex-745:~$ ls workspace/DungeonWorld2/assets/objects/creatures/alien/
alien.mesh Material.002.material Material.005.material
alien.mesh.xml Material.003.material
alien.skeleton.xml Material.004.material
dev#dev-OptiPlex-745:~$
This material code actually produces a material in the scene but it's not the one from blender:
model3.setMaterial( new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md") );
Result:
However, loading a 3D model of an alephant without defining the material does work:
Spatial elephant = (Spatial) assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
float scale = 0.05f;
elephant.scale(scale,scale,scale);
elephant.setLocalTranslation(-50.0f, 3.5f, -20.0f);
control = elephant.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
for (String anim : control.getAnimationNames())
System.out.println("elephant can:"+anim);
The above code correctly renders the elephant so why can't I export a mesh like that for the alien? I tried to explcitly load the material but it's not working for me:
Spatial model3 = assetManager
.loadModel("objects/creatures/alien/alien.mesh.xml");
model3.scale(0.3f, 0.3f, 0.3f);
model3.setLocalTranslation(-40.0f, 3.5f, -20.0f);
model3.setMaterial( new Material(assetManager,
"objects/creatures/alien/alien.material") );
rootNode.attachChild(model3);
The above generates an exception and I don't really know what material file it is that I'm loading and what do to with the two or three other material files that the export generated:
java.lang.ClassCastException: com.jme3.material.MaterialList cannot be cast to com.jme3.material.MaterialDef
at com.jme3.material.Material.<init>(Material.java:116)
at adventure.Main.simpleInitApp(Main.java:309)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:679)
Update
Loading other models this way is working:
BlenderKey blenderKey = new BlenderKey(
"objects/creatures/troll/troll.mesh.xml");
Spatial troll = (Spatial) assetManager.loadModel(blenderKey);
troll.setLocalTranslation(new Vector3f(-145, 15, -10));
rootNode.attachChild(troll);
BlenderKey blenderKey2 = new BlenderKey(
"objects/creatures/spaceman/man.mesh.xml");
Spatial man = (Spatial) assetManager.loadModel(blenderKey2);
man.setLocalTranslation(new Vector3f(-140, 15, -10));
rootNode.attachChild(man);
I get the models inside my game and they look alreight, both the troll and the spaceman that both originally were .blend files.
Now it's much better when I did it over and it is loading the material. The only problem with the alien left now is the holes in the head that was also answered here.
BlenderKey blenderKey = new BlenderKey(
"objects/creatures/alien/alien.mesh.xml");
Spatial alien = (Spatial) assetManager.loadModel(blenderKey);
alien.setLocalTranslation(new Vector3f(-145, 15, -10));
rootNode.attachChild(alien);
You didn't write anything about your material - did you write one and used it correctly? The problem you get seems to be the lack of material to me.
In general you'll need some *.material file and probably some textures (if you used them in Blender). For the beginning you can use one of the materials that come with Ogre, you'll just need to add:
model3.setMaterialName( "Examples/Rockwall" );
Then look if it changes anything. If you still get the problem you can look into 'Ogre.log' file - it's always worth checking because all the errors goes there.
I also see the second problem here - you render the object as 'one sided' while blender probably render is as two-sided mesh, so you get the holes on the head. You can select in the material to be two sided, but it's better (and faster during rendering) to just create your models without the holes :).

achartengine graph not painting correctly in RelativeLayout

I have an issue with an achartengine graph - as in this screenshot:
It looks like the X axis is given too much bottom padding, and the values are duplicated (one representation of each value is in the graph proper, and reacts properly to panning, while the other is located at the bottom of the graph view, but can't be manipulated in any way).
Here's the code used to create the graph:
protected void onCreate(Bundle savedInstanceState) {
...
gDataset = new XYMultipleSeriesDataset();
gRenderer = new XYMultipleSeriesRenderer();
gRenderer.setApplyBackgroundColor(true);
gRenderer.setPointSize(10);
chart = new TimeBarChart(gDataset, gRenderer);
graphView = new GraphicalView(this, chart);
graphHolder.addView(graphView);
//Mode is just an internal enum
chart.setDateFormat(curMode == Mode.DAY ? "HH:mm dd.MM.yyyy" : "dd.MM.yyyy");
....
}
And to populate it:
...
//some DB stuff goes here, result is the cursor
curSeries = new XYSeries("");
gDataset.addSeries(curSeries);
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.POINT);
gRenderer.addSeriesRenderer(renderer);
while (!result.isAfterLast()) {
.....
curSeries.add(timestamp,value);
....
}
.....
graphView.invalidate();
graphView.repaint();
And here's the graph holder's view definition in the layout XML (main container is RelativeLayout of course) :
<LinearLayout
android:id="#+id/graphHolder"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:minHeight="200dp">
</LinearLayout>
A couple of things:
I'm using the 0.7 version.
The TimeBarChart class is nothing else than a TimeChart with the simple change to extend BarChart instead. The code is copied from the 0.7 revision. Regardless, I was using ChartFactory#getTimeChartView() previously and the result was the same - so this isn't the cause of the problem.
I've tried checking whether the height layout parameter causes the problem, but that wasn't it as well.
graphHolder is injected by RoboGuice.
the problem was encountered in the 2.3 emulator.
Obviously, I'm doing something wrong, but I'm at a loss what. Any help is greatly appreciated.
PS. I've tried to post it on the achartengine group, but it looks like the mods are hibernating for the winter ;).
I finally had time to reinvestigate this, and figured it out.
The gist:
The bars on the bottom are the legend. I had a bug in my code that caused it to create a series for each datapoint, hence the multiple "bars", in reality legend graphics. The series had no names, which added to the confusion.
Fixing the bug and adding setShowLegend(false) dealed with the issue.
I've discovered this while evaluating AndroidPlot (BTW, I recommend it as an alternative to achartengine, as graphs can be defined in XML, and can be way more liberally customized graphically than the screenshots suggest).
I somehow failed to notice the legend in the achartengine screenshots, but I recognized them in AndroidPlot. And yes, I do feel quite stupid now :).

Problem creating a mosaic of images using JAI

I'm trying to use JAI to create a single mosaic consisting of 4 TIF images each of which is 5000 x 5000. The code I have written is as follows ..
RenderedOp mosaic=null;
ParameterBlock pbMosaic=new ParameterBlock();
pbMosaic.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
RenderedOp in=null;
// Get 4 tiles and add them to the Mosaic
in=returnRenderedOp(path,"northwest.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"northeast.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"southwest.tif");
pbMosaic.addSource(in);
in=returnRenderedOp(path,"southeast.tif");
pbMosaic.addSource(in);
// Setup the ImageLayout
ImageLayout imageLayout=new ImageLayout(0,0,10000,10000);
imageLayout.setTileWidth(5000);
imageLayout.setTileHeight(5000);
imageLayout.setColorModel(in.getColorModel());
imageLayout.setSampleModel(in.getSampleModel());
mosaic=JAI.create("mosaic",pbMosaic,new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout));
The problem is that all 4 images are being positioned in the same place in the top left hand corner of the mosaic so the other three quarters of it is empty. Can anyone tell me how I can choose the position of each picture that makes up the mosaic so each appears in the correct place ?
Thanks
Ian
http://download.oracle.com/docs/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/MosaicDescriptor.html
I think you misunderstood the doc you need to set the minX minY for EACH source image before the operation.
northwest.tif should have minX=0 and minY=0,
northeast.tif should have minX=5000 and minY=0,
southwest.tif should have minX=0, minY=5000 and
southeast.tif should have minx=5000 and minY = 5000
In the doc they suggest you deserialize the files directly "moved" by using rendering hint on the deserialization operation.
Somehow, mosaic is just a normal compositing operation.

Categories