Java heap space error in using aspose ITable - java

I am using Aspose for automating a ppt generation process after reading some CSV files:
ITable tbl = sld.getShapes().addTable(20, 49, dbCols,dblRows);
dbCols is 7 & dbRows is 15, but it is throwing:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Can someone suggest something? Does Aspose limit the number of rows on a particular table?

No, Aspose does not limit number of rows or columns on any table.
Using the Aspose.Slides API, you can add a table with 7 columns and 15 rows.
double[] dblCols = { 30, 30, 30, 30, 30, 30, 30 };
double[] dblRows = { 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20 };
//Add table shape to slide
ITable tbl = slide.getShapes().addTable(100, 50, dblCols, dblRows);
Where 30 is the width of each column, 20 is the height of each row; 100 and 50 are the x,y coordinates of top left corner of the table.
I work with Aspose as a Support Developer.

Related

Java OpenCV cant copy from MatOfInt4 into MatOfInt4

I have an OpenCV 4.2.0 application using HoughLinesP to detect lines in an image that's working fine with C++ and Objective-C. Now I need to have the same functionality working for java on Android.  
I've been fighting with it for a couple of days now and boiled it down to the following issue.  I can't copy a value from one MatOfInt4 to another MatOfInt4 using a for loop with lines2.put(i,0, lines.get(i, 0));
Below is the piece of code and the log outputs.  There are no compiler errors or runtime errors, just no values saved in the lines2 destination MatOfInt4. Either I have misunderstood how the put method works or there is something else wrong.
Does anyone know where this could be going wrong?  Any experts with Java and OpenCV able to give any guidance or corrections to the code below so that it will work?
You can see lines has 180 entries, the for loop counts 180 loops but lines2 is empty when it's finished.  I can get() the values correctly from lines and I'm using the values in other parts of the code, but I can't put() anything into lines2.
MatOfInt4 lines = new MatOfInt4();
lines = houghLinesP(sub);
Log.i(TAG, "Total Sub Lines Returned: " + lines.size());
MatOfInt4 lines2 = new MatOfInt4();
for(int i = 0; i < lines.rows(); i++) {
lines2.put(i,0, lines.get(i, 0));
Log.i(TAG, "Count of loop: " + i);
}
Log.i(TAG, "Dump of lines2 Returned: " + lines2.dump());
Log.i(TAG, "Total Lines2 Returned: " + lines2.size());
Results of test code:
Total Sub Lines Returned: 1x180
Dump of lines2 Returned: []
Count of loop: 180
Total Lines2 Returned: 0x0
Any help or guidance would be greatly appreciated.
The lines2 matrix has no size, so you cannot set values in it. To solve the problem you can allocate the matrix with the appropriate size, e.g.
MatOfInt4 lines2 = new MatOfInt4();
lines2.create(1,lines.rows(), lines.type());
// alternatively:
Mat lines2 = new Mat(1,lines.rows(), lines.type());
If you don't do anything else in the loop you could also just transpose the matrix to achieve the same result:
Mat lines2 = lines.t();
This transposed matrix will already contain the correct values. For my example image this produces the following output:
Total Sub Lines Returned: 1x295
Dump of lines2 Returned: [9, 187, 137, 201, 353, 211, 430, 213, 95, etc...
Total Lines2 Returned: 295x1

Mesuring Derby speed with hibernate. Strange values

I'm writing application to mesure speed of CRUD with hibernate for Derby.
This is my function :
#Override
public BulkTestResult testBulkInsertScenario(Long volume, Integer repeat) {
StopWatch sw = new StopWatch();
BulkTestResult bulkTestResult = new BulkTestResult();
bulkTestResult.setStartDate(Instant.now());
bulkTestResult.setCountTest(volume);
bulkTestResult.setTestRepeat(repeat);
familyService.clear();
for(int i =0; i < repeat; i++) {
List<ProjectEntity> projects = dataAnonymization.generateProjectEntityList(volume);
runBulkTest(sw, bulkTestResult, projects, true);
}
bulkTestResult.setEndDate(Instant.now());
return bulkTestResult;
}
private void runBulkTest(StopWatch sw, BulkTestResult bulkTestResult, List<ProjectEntity> projects, boolean resetAfter) {
sw.reset();
sw.start();
familyService.save(projects);
sw.stop();
bulkTestResult.addMsSpeedResult(sw.getTime());
if (resetAfter) familyService.clear();
sw.reset();
}
clear method remove all record from DB.
The problem that I have is values that I recieved as output of application.
Testing data : 1000 record, and 10 repeats
Example speed values recieved running this test few times:
311, 116, 87, (...)38
32, 27, 30, (...) 24
22, 19, 18, (...) 21
19, 18, 18, (...) 19
Why there are so many difference and why for first time insert is always slower ?
It could be any hardware acceleration ?
I found solution.
This issue is related to optimalization. After Disable JIT, recieved values are correct.
-Djava.compiler=NONE -Xint

Apache POI XSLFAutoShape - Shape OffSet property

I am drawing a pptx from scratch using ApachePOI-XSLF (ooxml implementation) and I am struggling to find good documentation and good examples. Also the library isn't easy to follow and not straight forward.
I would like to know how do I set the offset of two shapes of XSFLAutoShape connected by XSLFConnectorShape.
This is my code right now:
XMLSlideShow pptx = new XMLSlideShow();
XSLFSlide slide = pptx.createSlide();
XSLFAutoShape rectangle = slide.createAutoShape();
rectangle.setShapeType(ShapeType.RECT);
rectangle.setAnchor(new Rectangle2D.Double(100, 100, 100, 50));
rectangle.setLineColor(Color.blue);
rectangle.setFillColor(Color.lightGray);
XSLFAutoShape miniCircle = slide.createAutoShape();
miniCircle.setShapeType(ShapeType.ELLIPSE);
miniCircle.setAnchor(new Rectangle2D.Double(rectangle.getAnchor().getMaxX() + 200, rectangle.getAnchor().getCenterY()+50, 1, 1));
miniCircle.setLineColor(Color.yellow);
miniCircle.setFillColor(Color.yellow);
connect(slide, rectangle, miniCircle);
XSLFAutoShape anotherRectangle = slide.createAutoShape();
anotherRectangle.setShapeType(ShapeType.RECT);
anotherRectangle.setAnchor(new Rectangle2D.Double(miniCircle.getAnchor().getMaxX() + 200, 100, 100, 50));
anotherRectangle.setLineColor(Color.blue);
anotherRectangle.setFillColor(Color.lightGray);
connect(slide, miniCircle, anotherRectangle);
and the connect method:
public static void connect(XSLFSlide slide, XSLFAutoShape start, XSLFAutoShape end){
XSLFConnectorShape connector = slide.createConnector();
connector.setAnchor(new Rectangle2D.Double(start.getAnchor().getX() + 100, start.getAnchor().getCenterY(), 100, 1));
CTConnector ctConnector = (CTConnector)connector.getXmlObject();
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
// connection start
CTConnection stCxn = cx.addNewStCxn();
stCxn.setId(start.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
stCxn.setIdx(3);
CTConnection endCxn = cx.addNewEndCxn();
endCxn.setId(end.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
endCxn.setIdx(3);
}
The output of is:
This is the output
But I want this:
This is what I want
p.s. I edit the post because someone thumbs down the post without a reason. I added more info but still complicated because the library is complicated :-/. would mind help and thumbs up again ? If you cannot help at least do not destroy my reputation. I am serious developer. Tkx.

Creating 24bit BMP fails (only with a particular resolution)

I'm creating a 24bit bmp which in general works fine (I've been using this functionality for some time). Now I've tried to write a bmp with 970 x 970 pixels and I'm ending up in corrupt files (I've exported bigger images before, I'm having problems with this particular resolution).
This is how I build the header:
private static byte[] createHeader(int width, int height) {
int size = width * height * 3 + 54;
byte[] ret = new byte[54];
set(ret, 0, (byte) 'B', (byte) 'M');
set(ret, 2, intToDWord(size));
set(ret, 6, intToDWord(0));
set(ret, 10, intToDWord(54));
set(ret, 14, intToDWord(40));
set(ret, 18, intToDWord(width));
set(ret, 22, intToDWord(height));
set(ret, 26, intToWord(1));
set(ret, 28, intToWord(24));
set(ret, 30, intToDWord(0));
set(ret, 34, intToDWord(width * height * 3));
set(ret, 38, intToDWord(0));
set(ret, 42, intToDWord(0));
set(ret, 46, intToDWord(0));
set(ret, 50, intToDWord(0));
return ret;
}
Here is the resulting image (this test image should be completely red):
test_corrupt.bmp (2.6mb)
I've analyzed the header, checked the size, I can't find the reason why this image is not a valid BMP.
Does anyone have a clue? I'm not making any progress.
It may be because of BMP files expects row lengths to be a multiple of 4 bytes. This changes the size you specified in header offset 34 and therefore the size in offset 2. Please refer to the following for details:
http://en.wikipedia.org/wiki/BMP_file_format
Related Part:
For file storage purposes, only the size of each row must be a multiple of 4 bytes while the file offset can be arbitrary
You can compare file by creating a 970x970 Red BMP file using MS Paint.

GeoTIFF import in worldwind ::: cannot read raster : unable to decipher image organization

I'm trying to import some (Matlab-generated) GeoTIFF files into WorldWind but seem to have no luck whatsoever. Any useful hints would greatly be appreciated. The GeoTIFF files do display fine in ArcGIS (allowing me to create a .tfw file when I export), but WorldWind gives me the following message:
SEVERE: Cannot read raster: C:\Users\Matthias\Desktop\geotiff\fldextent_02-
Jan-1977(1)renderedno0.tif : gov.nasa.worldwind.formats.tiff.GeotiffImageReader.read(): unable
to decipher image organization
Jul 09, 2013 6:54:33 PM gov.nasa.worldwind.data.CachedDataRaster drawOnTo
SEVERE: C:\Users\Matthias\Desktop\geotiff\fldextent_02-Jan-1977(1)renderedno0.tif : Cannot read
raster: C:\Users\Matthias\Desktop\geotiff\fldextent_02-Jan-1977(1)renderedno0.tif :
gov.nasa.worldwind.formats.tiff.GeotiffImageReader.read(): unable to decipher image organization
gov.nasa.worldwind.exception.WWRuntimeException: Cannot read raster: C:\Users\Matthias\Desktop
\geotiff\fldextent_02-Jan-1977(1)renderedno0.tif :
gov.nasa.worldwind.formats.tiff.GeotiffImageReader.read(): unable to decipher image organization
at gov.nasa.worldwind.data.CachedDataRaster.getDataRasters(CachedDataRaster.java:255)
at gov.nasa.worldwind.data.CachedDataRaster.drawOnTo(CachedDataRaster.java:290)
at gov.nasa.worldwind.data.TiledRasterProducer.drawDataSources(TiledRasterProducer.java:576)
[...]
I have also looked at the attributes of the GeoTIFF file in FWTools which gives me:
C:\Users\Matthias\Desktop\geotiff>gdalinfo fldextent_02-Jan-1977(1)renderedno0.tif
Driver: GTiff/GeoTIFF
Files: fldextent_02-Jan-1977(1)renderedno0.tif
fldextent_02-Jan-1977(1)renderedno0.tfw
Size is 7200, 7200
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (99.000000000000000,7.000000000000000)
Pixel Size = (0.000833333333333,-0.000833333333333)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 99.0000000, 7.0000000) ( 99d 0'0.00"E, 7d 0'0.00"N)
Lower Left ( 99.0000000, 1.0000000) ( 99d 0'0.00"E, 1d 0'0.00"N)
Upper Right ( 105.0000000, 7.0000000) (105d 0'0.00"E, 7d 0'0.00"N)
Lower Right ( 105.0000000, 1.0000000) (105d 0'0.00"E, 1d 0'0.00"N)
Center ( 102.0000000, 4.0000000) (102d 0'0.00"E, 4d 0'0.00"N)
Band 1 Block=128x128 Type=Byte, ColorInterp=Gray
NoData Value=0
The .tfw file reads:
0.0008333333
0.0000000000
0.0000000000
-0.0008333333
99.0004166667
6.9995833333
I have found the issue finally:
The important thing is to create a CLEAN GeoTIFF file in Matlab (RGB and alpha layer for transparency). Here some Matlab guidance, the resulting GeoTIFF can directly be imported into WorldWind:
%%% read intensity values Z (2D matrix) - with values of 0 and above
%%% (we want 0 to be completely transparent in the final geotiff) -
%%% together with spatialref.GeoRasterReference ss
[Z, ss] = geotiffread('./flddph_1976-01-01.tif');
info_3 = geotiffinfo('./flddph_1976-01-01.tif');
%%% generate indexed image with 0 to 255 (255 equals max. intensity)
indexedimage = gray2ind(Z);
indexedimage = double(indexedimage);
%%% normalize so that everything between 0 and 1
normalizedimg = (indexedimage) / 255;
%%% scaling data and applying colormap
imgscaled = uint8(256*normalizedimg); % scale data
cmp = makeColorMap([1 1 0],[1 0.75 0],[1 0 0],256);
% 256 element colormap yellow - orange - red
% (download appropriate function MAKECOLORMAP)
imgrgb = ind2rgb(imgscaled,cmp);
%%% check plot
% subplot(2,1,1)
% imagesc(indexedimage)
% title('indexed image')
% subplot(2,1,2)
% image(img)
% title('rgb image')
%%% generating alpha layer for transparency
%%% (255 for non-transparent, 0 for transparent)
alpha3 = Z;
alpha3(alpha3>0)=255;
alpha3 = uint8(alpha3);
out2 = cat(3,imgrgb,alpha3);
geotiffwrite('test_rgbhope_flddph.tif',out2,ss);

Categories

Resources