use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class VisitorTest method intersectionCoverageTest.
/**
* Coverage visitor test
*/
@Test
@Ignore("Need to revisit DataBuffer construction.")
public void intersectionCoverageTest() throws Exception {
final float[][] data = new float[180][360];
for (int i = 0; i < 180; i++) Arrays.fill(data[i], 15f);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setValues(BufferedImages.toDataBuffer1D(data), null);
final AffineTransform trs = new AffineTransform(1, 0, 0, -1, -180, 90);
gcb.setDomain(new GridGeometry(new GridExtent(360, 180), PixelInCell.CELL_CENTER, new AffineTransform2D(trs), CommonCRS.WGS84.normalizedGeographic()));
gcb.setRanges(new SampleDimension.Builder().setName(0).build());
final MapLayer cml = MapBuilder.createLayer(new InMemoryGridCoverageResource(gcb.build()));
MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
context.getComponents().add(cml);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final Dimension dim = new Dimension(360, 180);
// starting at top left corner
final Shape shparea = new Rectangle(195, 75, 2, 2);
final ListVisitor visitor = new ListVisitor();
DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
assertTrue(visitor.coverages.size() != 0);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testReprojectionCoverageARGB.
@Test
public void testReprojectionCoverageARGB() throws TransformException, PortrayalException, NoSuchAuthorityCodeException, FactoryException {
// create a test coverage
final BufferedImage img = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, 500, 500);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, 0, 20);
env.setRange(1, 0, 20);
final GridCoverage coverage = new GridCoverage2D(new GridGeometry(null, env, GridOrientation.HOMOTHETY), null, img);
// display it
final MapLayers context = MapBuilder.createContext();
final MapLayer cl = MapBuilder.createCoverageLayer(coverage, SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER), "coverage");
context.getComponents().add(cl);
final Envelope envelope = Envelopes.transform(env, CRS.forCode("EPSG:3031"));
final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), envelope);
cdef.setBackground(Color.WHITE);
final BufferedImage result = DefaultPortrayalService.portray(cdef, new SceneDef(context));
// background is opaque we should obtain an RGB color model since raster styles
// are unpredictable
assertTrue(!(result.getColorModel() instanceof IndexColorModel));
assertEquals(ColorSpace.TYPE_RGB, result.getColorModel().getColorSpace().getType());
assertEquals(3, result.getColorModel().getNumComponents());
assertEquals(3, result.getColorModel().getNumColorComponents());
// check we don't have any black reprojection pixels
int[] buffer = new int[4];
final Raster raster = result.getData();
for (int x = 0; x < raster.getWidth(); x++) {
for (int y = 0; y < raster.getHeight(); y++) {
raster.getPixel(x, y, buffer);
if (buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0) {
// black pixel
fail("reprojection should not have generated black pixels.");
}
}
}
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testSolidColorBackgroundWithAA.
@Test
public void testSolidColorBackgroundWithAA() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
final MapLayers context = MapBuilder.createContext();
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
cdef.setBackground(Color.GREEN);
final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, new Hints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)));
// background is single color opaque we should obtain an RGB color model because of active
// anti-aliasing
assertTrue(!(img.getColorModel() instanceof IndexColorModel));
assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
assertEquals(3, img.getColorModel().getNumComponents());
assertEquals(3, img.getColorModel().getNumColorComponents());
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testOpaqueUnpredictableBackground.
@Test
public void testOpaqueUnpredictableBackground() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
final MapLayers context = MapBuilder.createContext();
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
cdef.setBackground(Color.GREEN);
final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context, null, new PortrayalExtension() {
@Override
public void completeCanvas(J2DCanvas canvas) throws PortrayalException {
canvas.setBackgroundPainter(new GradiantColorPainter());
}
}));
// background is opaque we should obtain an RGB color model
assertTrue(!(img.getColorModel() instanceof IndexColorModel));
assertEquals(ColorSpace.TYPE_RGB, img.getColorModel().getColorSpace().getType());
assertEquals(3, img.getColorModel().getNumComponents());
assertEquals(3, img.getColorModel().getNumColorComponents());
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class ColorModelTest method testSolidColorBackground.
@Test
public void testSolidColorBackground() throws NoSuchAuthorityCodeException, FactoryException, PortrayalException {
final MapLayers context = MapBuilder.createContext();
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.geographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final CanvasDef cdef = new CanvasDef(new Dimension(800, 600), env);
cdef.setBackground(Color.GREEN);
final BufferedImage img = DefaultPortrayalService.portray(cdef, new SceneDef(context));
assertTrue(img.getColorModel() instanceof IndexColorModel);
final IndexColorModel icm = (IndexColorModel) img.getColorModel();
// we should have only two value
assertEquals(2, icm.getMapSize());
assertTrue(Color.GREEN.getRGB() == icm.getRGB(0) || Color.GREEN.getRGB() == icm.getRGB(1));
}
Aggregations