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.
Related
I want my PDF to render properly and instantly as they normally render, on first try & with reasonable file size and resolution.
Actual results:
Clicking "print button" the first time produces a blank page in print adapter. This also takes around 5 seconds to render. Clicking "print button" a second time takes 5 seconds or more to finally load the PDF. Additionally, the PDF file is a staggering 2.16MB for a 1 page output.
I believe this must be a memory problem, understandably.
What I'm doing:
I have a relatively large view fully rendered, its invisible to user and in a print friendly color sceme to be printed. It measures 900dp X 300dp. This is a sort of tableview/scrollview dependency, pretty much a super simple spreadsheet with some numbers. I load this view into a View to Bitmap capturing dependency. I then load this into the android provided print helper for printing a Bitmap.
Dependency:
https://github.com/HelloHuDi/ViewCapture
My button click code:
printableVersion.setOnClickListener {
printChartCreate(unitDimensionImperialEven.text.toString().toInt()) // Create chart
val bitmap: Bitmap? = ViewCapture.with(printableTableMetricCoursing).bitmap // I guess this initializes bitmap from chart
bitmap.set
this.also { context ->
PrintHelper(context).apply {
scaleMode = PrintHelper.SCALE_MODE_FILL
}.also { printHelper ->
printHelper.printBitmap("droids.jpg - test print", bitmap!!)
}
}
}
So far I've tried implementing bitmap.createBitmap() method so to recreate the bitmap with a lower resolution but get errors and crash with everything i've tried. The current resolution/inch on inspection is 520dpi. How can I reduce the resolution with this configuration above to 300 or less? I believe this smaller file will solve all the above problems.
EDIT: I've also tried 3 different bitmap capturing dependencies and this is the same output or crashes.
I'm developing a game and use batcher.drawSprite method to draw all images in the game (background and all characters)
in assets.java :
charAtlas = new Texture(game, "charAtlas.png");
charEnemy = new TextureRegion(charAtlas, 0,0,250,300);
in worldGame.java :
batcher.beginBatch(Assets.charAtlas); // set atlas
batcher.drawSprite(130, 628, 120,140, Assets.charEnemy);
//assets.charEnemy
is it right to use this method in all condition ?
I have 3 atlas in game , i even use 2048x2048 atlas size so i can include all my images in there..
However, the image looks blurry in game (Tested in galaxy note, tab, and galaxy young). looks at the code above, i even have the enemy char take size in my atlas as much as 250x300 , it's not make sense that it'll look blurry as i only draw it in 120x140.
note : i use no layout (i mean no layout file in res folder) .. i use drawsprite to draw all image (Character,menu, button, etc)..
update :
I tried to use character image files from other game that i unzipped, when i run the app, it also looks blurry and jagged. while in the original game, it's so smooth and sharp. why is that ?
check your code, you might use scaledbitmap , see if you can set like this.
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
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 :).
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
I'd like to apply a Median Filter to a bi-level image and output a bi-level image. The JAI median filter seems to output an RGB image, which I'm having trouble downconverting back to bi-level.
Currently I can't even get the image back into gray color-space, my code looks like this:
BufferedImage src; // contains a bi-level image
ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
pb.add(3);
RenderedOp result = JAI.create("MedianFilter", pb);
ParameterBlock pb2 = new ParameterBlock();
pb2.addSource(result);
pb2.add(new double[][]{{0.33, 0.34, 0.33, 0}});
RenderedOp grayResult = JAI.create("BandCombine", pb2);
BufferedImage foo = grayResult.getAsBufferedImage();
This code hangs on the grayResult line and appears not to return. I assume that I'll eventually need to call the "Binarize" operation in JAI.
Edit: Actually, the code appears to be stalling once I call getAsBufferedImage(), but returns nearly instantly when the second operation ("BandCombine") is removed.
Is there a better way to keep the Median Filtering in the source color domain? If not, how do I downconvert back to binary?
Unfortunately it seems like the BandCombine operation doesn't behave as expected here. The appropriate tactic for getting back to bilevel is to use a flavor of ColorConvertOp -- doing so enables use of the MedianFilter operation which will (again, unfortunately) always lead to an RGB image.