@Test public void testGetCoreTileRenderParameters() throws Exception { final String json = "{\n" + " \"tileId\" : \"1,3484_aligned_0_1_flip\",\n" + " \"z\" : 3484.0, \"minX\" : 1896.0, \"minY\" : 876.0, \"maxX\" : 2919.0, \"maxY\" : 1899.0,\n" + " \"width\" : 1024.0, \"height\" : 1024.0,\n" + " \"mipmapLevels\" : {\n" + " \"0\" : {\n" + " \"imageUrl\" : \"file: " }\n" + " },\n" + " \"transforms\" : {\n" + " \"type\" : \"list\",\n" + " \"specList\" : [ {\n" + " \"className\" : \"mpicbg.trakem2.transform.AffineModel2D\",\n" + " \"dataString\" : \"1.0000000000 0.0000000000 0.0000000000 1.0000000000 1896.0000000000 -876.0000000000\"\n" + " }, {\n" + " \"className\" : \"mpicbg.trakem2.transform.AffineModel2D\",\n" + " \"dataString\" : \"1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 1752.0000000000\"\n" + " } ]\n" + " }\n" + "}"; TileSpec tileSpec = TileSpec.fromJson(json); RenderParameters renderParameters = TileDataService.getCoreTileRenderParameters(null, null, null, null, null, null, null, tileSpec); Assert.assertEquals("invalid width for tile", 1024, renderParameters.getWidth()); Assert.assertEquals("invalid height for tile", 1024, renderParameters.getHeight()); tileSpec = TileSpec.fromJson(json); renderParameters = TileDataService.getCoreTileRenderParameters(null, null, null, true, null, null, null, tileSpec); List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); Assert.assertEquals("invalid number of tile specs returned after normalization", 1, tileSpecs.size()); TileSpec flattenedTileSpec = tileSpecs.get(0); ListTransformSpec transforms = flattenedTileSpec.getTransforms(); Assert.assertEquals("invalid number of transforms after normalization", 1, transforms.size()); tileSpec = TileSpec.fromJson(json); renderParameters = TileDataService.getCoreTileRenderParameters(null, null, null, true, Collections.emptySet(), Collections.emptySet(), null, tileSpec); tileSpecs = renderParameters.getTileSpecs(); Assert.assertEquals("invalid number of tile specs returned with empty sets", 1, tileSpecs.size()); flattenedTileSpec = tileSpecs.get(0); transforms = flattenedTileSpec.getTransforms(); Assert.assertEquals("invalid number of transforms with empty sets", 1, transforms.size()); }
static RenderParameters getCoreTileRenderParameters(final Integer width, final Integer height, final Double scale, final Boolean normalizeForMatching, final Set<String> excludeAfterLastLabels, final Set<String> excludeFirstAndAllAfterLabels, final Boolean excludeAllTransforms, final TileSpec tileSpec) { final boolean useLabelNormalization = (excludeAllTransforms != null) || ((excludeAfterLastLabels != null) && (excludeAfterLastLabels.size() > 0)) || ((excludeFirstAndAllAfterLabels != null) && (excludeFirstAndAllAfterLabels.size() > 0)); final boolean useLegacyNormalization = (normalizeForMatching != null) && normalizeForMatching; if (useLabelNormalization) { tileSpec.flattenAndFilterTransforms(excludeAllTransforms, excludeAfterLastLabels, excludeFirstAndAllAfterLabels); tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else if (useLegacyNormalization) { if (tileSpec.hasTransformWithLabel(TransformSpecMetaData.LENS_CORRECTION_LABEL)) { tileSpec.flattenAndFilterTransforms(null, EXCLUDE_AFTER_LENS, null); } else { tileSpec.flattenTransforms(); tileSpec.removeLastTransformSpec(); while (tileSpec.getTransforms().size() > 3) { tileSpec.removeLastTransformSpec(); } } tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else { tileSpec.flattenTransforms(); } double tileRenderX = tileSpec.getMinX(); double tileRenderY = tileSpec.getMinY(); if (useLegacyNormalization) { tileRenderX = 0.0; tileRenderY = 0.0; } final int tileRenderWidth; if (width == null) { tileRenderWidth = (int) (tileSpec.getMaxX() - tileSpec.getMinX() + 1); } else { tileRenderWidth = width; } final int tileRenderHeight; if (height == null) { tileRenderHeight = (int) (tileSpec.getMaxY() - tileSpec.getMinY() + 1); } else { tileRenderHeight = height; } final RenderParameters parameters = new RenderParameters(null, tileRenderX, tileRenderY, tileRenderWidth, tileRenderHeight, scale); parameters.addTileSpec(tileSpec); return parameters; }
TileDataService { static RenderParameters getCoreTileRenderParameters(final Integer width, final Integer height, final Double scale, final Boolean normalizeForMatching, final Set<String> excludeAfterLastLabels, final Set<String> excludeFirstAndAllAfterLabels, final Boolean excludeAllTransforms, final TileSpec tileSpec) { final boolean useLabelNormalization = (excludeAllTransforms != null) || ((excludeAfterLastLabels != null) && (excludeAfterLastLabels.size() > 0)) || ((excludeFirstAndAllAfterLabels != null) && (excludeFirstAndAllAfterLabels.size() > 0)); final boolean useLegacyNormalization = (normalizeForMatching != null) && normalizeForMatching; if (useLabelNormalization) { tileSpec.flattenAndFilterTransforms(excludeAllTransforms, excludeAfterLastLabels, excludeFirstAndAllAfterLabels); tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else if (useLegacyNormalization) { if (tileSpec.hasTransformWithLabel(TransformSpecMetaData.LENS_CORRECTION_LABEL)) { tileSpec.flattenAndFilterTransforms(null, EXCLUDE_AFTER_LENS, null); } else { tileSpec.flattenTransforms(); tileSpec.removeLastTransformSpec(); while (tileSpec.getTransforms().size() > 3) { tileSpec.removeLastTransformSpec(); } } tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else { tileSpec.flattenTransforms(); } double tileRenderX = tileSpec.getMinX(); double tileRenderY = tileSpec.getMinY(); if (useLegacyNormalization) { tileRenderX = 0.0; tileRenderY = 0.0; } final int tileRenderWidth; if (width == null) { tileRenderWidth = (int) (tileSpec.getMaxX() - tileSpec.getMinX() + 1); } else { tileRenderWidth = width; } final int tileRenderHeight; if (height == null) { tileRenderHeight = (int) (tileSpec.getMaxY() - tileSpec.getMinY() + 1); } else { tileRenderHeight = height; } final RenderParameters parameters = new RenderParameters(null, tileRenderX, tileRenderY, tileRenderWidth, tileRenderHeight, scale); parameters.addTileSpec(tileSpec); return parameters; } }
TileDataService { static RenderParameters getCoreTileRenderParameters(final Integer width, final Integer height, final Double scale, final Boolean normalizeForMatching, final Set<String> excludeAfterLastLabels, final Set<String> excludeFirstAndAllAfterLabels, final Boolean excludeAllTransforms, final TileSpec tileSpec) { final boolean useLabelNormalization = (excludeAllTransforms != null) || ((excludeAfterLastLabels != null) && (excludeAfterLastLabels.size() > 0)) || ((excludeFirstAndAllAfterLabels != null) && (excludeFirstAndAllAfterLabels.size() > 0)); final boolean useLegacyNormalization = (normalizeForMatching != null) && normalizeForMatching; if (useLabelNormalization) { tileSpec.flattenAndFilterTransforms(excludeAllTransforms, excludeAfterLastLabels, excludeFirstAndAllAfterLabels); tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else if (useLegacyNormalization) { if (tileSpec.hasTransformWithLabel(TransformSpecMetaData.LENS_CORRECTION_LABEL)) { tileSpec.flattenAndFilterTransforms(null, EXCLUDE_AFTER_LENS, null); } else { tileSpec.flattenTransforms(); tileSpec.removeLastTransformSpec(); while (tileSpec.getTransforms().size() > 3) { tileSpec.removeLastTransformSpec(); } } tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else { tileSpec.flattenTransforms(); } double tileRenderX = tileSpec.getMinX(); double tileRenderY = tileSpec.getMinY(); if (useLegacyNormalization) { tileRenderX = 0.0; tileRenderY = 0.0; } final int tileRenderWidth; if (width == null) { tileRenderWidth = (int) (tileSpec.getMaxX() - tileSpec.getMinX() + 1); } else { tileRenderWidth = width; } final int tileRenderHeight; if (height == null) { tileRenderHeight = (int) (tileSpec.getMaxY() - tileSpec.getMinY() + 1); } else { tileRenderHeight = height; } final RenderParameters parameters = new RenderParameters(null, tileRenderX, tileRenderY, tileRenderWidth, tileRenderHeight, scale); parameters.addTileSpec(tileSpec); return parameters; } @SuppressWarnings({"UnusedDeclaration", "WeakerAccess"})  TileDataService(); private  TileDataService(final RenderDao renderDao); }
TileDataService { static RenderParameters getCoreTileRenderParameters(final Integer width, final Integer height, final Double scale, final Boolean normalizeForMatching, final Set<String> excludeAfterLastLabels, final Set<String> excludeFirstAndAllAfterLabels, final Boolean excludeAllTransforms, final TileSpec tileSpec) { final boolean useLabelNormalization = (excludeAllTransforms != null) || ((excludeAfterLastLabels != null) && (excludeAfterLastLabels.size() > 0)) || ((excludeFirstAndAllAfterLabels != null) && (excludeFirstAndAllAfterLabels.size() > 0)); final boolean useLegacyNormalization = (normalizeForMatching != null) && normalizeForMatching; if (useLabelNormalization) { tileSpec.flattenAndFilterTransforms(excludeAllTransforms, excludeAfterLastLabels, excludeFirstAndAllAfterLabels); tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else if (useLegacyNormalization) { if (tileSpec.hasTransformWithLabel(TransformSpecMetaData.LENS_CORRECTION_LABEL)) { tileSpec.flattenAndFilterTransforms(null, EXCLUDE_AFTER_LENS, null); } else { tileSpec.flattenTransforms(); tileSpec.removeLastTransformSpec(); while (tileSpec.getTransforms().size() > 3) { tileSpec.removeLastTransformSpec(); } } tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else { tileSpec.flattenTransforms(); } double tileRenderX = tileSpec.getMinX(); double tileRenderY = tileSpec.getMinY(); if (useLegacyNormalization) { tileRenderX = 0.0; tileRenderY = 0.0; } final int tileRenderWidth; if (width == null) { tileRenderWidth = (int) (tileSpec.getMaxX() - tileSpec.getMinX() + 1); } else { tileRenderWidth = width; } final int tileRenderHeight; if (height == null) { tileRenderHeight = (int) (tileSpec.getMaxY() - tileSpec.getMinY() + 1); } else { tileRenderHeight = height; } final RenderParameters parameters = new RenderParameters(null, tileRenderX, tileRenderY, tileRenderWidth, tileRenderHeight, scale); parameters.addTileSpec(tileSpec); return parameters; } @SuppressWarnings({"UnusedDeclaration", "WeakerAccess"})  TileDataService(); private  TileDataService(final RenderDao renderDao); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get tile spec") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) TileSpec getTileSpec(@PathParam("owner") final String owner,
                                @PathParam("project") final String project,
                                @PathParam("stack") final String stack,
                                @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}") @DELETE @ApiOperation( value = "Deletes specified tile.", notes = "This operation can only be performed against stacks in the LOADING state") @ApiResponses(value = { @ApiResponse(code = 400, message = "stack state is not LOADING"), @ApiResponse(code = 404, message = "stack not found"), }) Response deleteTile(@PathParam("owner") final String owner,
                               @PathParam("project") final String project,
                               @PathParam("stack") final String stack,
                               @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering the tile") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getRenderParameters(@PathParam("owner") final String owner,
                                                @PathParam("project") final String project,
                                                @PathParam("stack") final String stack,
                                                @PathParam("tileId") final String tileId,
                                                @BeanParam final RenderQueryParameters renderQueryParameters,
                                                @QueryParam("width") final Integer width,// full scale width
                                                @QueryParam("height") final Integer height,// full scale height
                                                @QueryParam("normalizeForMatching") final Boolean normalizeForMatching,
                                                @QueryParam("excludeTransformsAfterLast") final Set<String> excludeAfterLastLabels,
                                                @QueryParam("excludeFirstTransformAndAllAfter") final Set<String> excludeFirstAndAllAfterLabels,
                                                @QueryParam("excludeAllTransforms") final Boolean excludeAllTransforms); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/validation-info") @GET @Produces(MediaType.TEXT_PLAIN) @ApiOperation( value = "Get information indicating whether a tile exists and is valid") @ApiResponses(value = { @ApiResponse(code = 200, message = "tile exists and is valid"), @ApiResponse(code = 400, message = "tile not valid"), @ApiResponse(code = 404, message = "tile not found"), }) Response getValidationInfo(@PathParam("owner") final String owner,
                                      @PathParam("project") final String project,
                                      @PathParam("stack") final String stack,
                                      @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/source/scale/{scale}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering tile source image (without transformations or mask)") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileSourceRenderParameters(@PathParam("owner") final String owner,
                                                          @PathParam("project") final String project,
                                                          @PathParam("stack") final String stack,
                                                          @PathParam("tileId") final String tileId,
                                                          @PathParam("scale") final Double scale,
                                                          @BeanParam final RenderQueryParameters renderQueryParameters); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/mask/scale/{scale}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering tile mask image (without transformations)") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileMaskRenderParameters(@PathParam("owner") final String owner,
                                                        @PathParam("project") final String project,
                                                        @PathParam("stack") final String stack,
                                                        @PathParam("tileId") final String tileId,
                                                        @PathParam("scale") final Double scale,
                                                        @BeanParam final RenderQueryParameters renderQueryParameters); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/withNeighbors/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering a tile with its neighbors") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileWithNeighborsRenderParameters(@PathParam("owner") final String owner,
                                                                 @PathParam("project") final String project,
                                                                 @PathParam("stack") final String stack,
                                                                 @PathParam("tileId") final String tileId,
                                                                 @QueryParam("widthFactor") Double widthFactor,
                                                                 @QueryParam("heightFactor") Double heightFactor,
                                                                 @BeanParam final RenderQueryParameters renderQueryParameters); }
TileDataService { static RenderParameters getCoreTileRenderParameters(final Integer width, final Integer height, final Double scale, final Boolean normalizeForMatching, final Set<String> excludeAfterLastLabels, final Set<String> excludeFirstAndAllAfterLabels, final Boolean excludeAllTransforms, final TileSpec tileSpec) { final boolean useLabelNormalization = (excludeAllTransforms != null) || ((excludeAfterLastLabels != null) && (excludeAfterLastLabels.size() > 0)) || ((excludeFirstAndAllAfterLabels != null) && (excludeFirstAndAllAfterLabels.size() > 0)); final boolean useLegacyNormalization = (normalizeForMatching != null) && normalizeForMatching; if (useLabelNormalization) { tileSpec.flattenAndFilterTransforms(excludeAllTransforms, excludeAfterLastLabels, excludeFirstAndAllAfterLabels); tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else if (useLegacyNormalization) { if (tileSpec.hasTransformWithLabel(TransformSpecMetaData.LENS_CORRECTION_LABEL)) { tileSpec.flattenAndFilterTransforms(null, EXCLUDE_AFTER_LENS, null); } else { tileSpec.flattenTransforms(); tileSpec.removeLastTransformSpec(); while (tileSpec.getTransforms().size() > 3) { tileSpec.removeLastTransformSpec(); } } tileSpec.deriveBoundingBox(tileSpec.getMeshCellSize(), true); } else { tileSpec.flattenTransforms(); } double tileRenderX = tileSpec.getMinX(); double tileRenderY = tileSpec.getMinY(); if (useLegacyNormalization) { tileRenderX = 0.0; tileRenderY = 0.0; } final int tileRenderWidth; if (width == null) { tileRenderWidth = (int) (tileSpec.getMaxX() - tileSpec.getMinX() + 1); } else { tileRenderWidth = width; } final int tileRenderHeight; if (height == null) { tileRenderHeight = (int) (tileSpec.getMaxY() - tileSpec.getMinY() + 1); } else { tileRenderHeight = height; } final RenderParameters parameters = new RenderParameters(null, tileRenderX, tileRenderY, tileRenderWidth, tileRenderHeight, scale); parameters.addTileSpec(tileSpec); return parameters; } @SuppressWarnings({"UnusedDeclaration", "WeakerAccess"})  TileDataService(); private  TileDataService(final RenderDao renderDao); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get tile spec") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) TileSpec getTileSpec(@PathParam("owner") final String owner,
                                @PathParam("project") final String project,
                                @PathParam("stack") final String stack,
                                @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}") @DELETE @ApiOperation( value = "Deletes specified tile.", notes = "This operation can only be performed against stacks in the LOADING state") @ApiResponses(value = { @ApiResponse(code = 400, message = "stack state is not LOADING"), @ApiResponse(code = 404, message = "stack not found"), }) Response deleteTile(@PathParam("owner") final String owner,
                               @PathParam("project") final String project,
                               @PathParam("stack") final String stack,
                               @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering the tile") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getRenderParameters(@PathParam("owner") final String owner,
                                                @PathParam("project") final String project,
                                                @PathParam("stack") final String stack,
                                                @PathParam("tileId") final String tileId,
                                                @BeanParam final RenderQueryParameters renderQueryParameters,
                                                @QueryParam("width") final Integer width,// full scale width
                                                @QueryParam("height") final Integer height,// full scale height
                                                @QueryParam("normalizeForMatching") final Boolean normalizeForMatching,
                                                @QueryParam("excludeTransformsAfterLast") final Set<String> excludeAfterLastLabels,
                                                @QueryParam("excludeFirstTransformAndAllAfter") final Set<String> excludeFirstAndAllAfterLabels,
                                                @QueryParam("excludeAllTransforms") final Boolean excludeAllTransforms); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/validation-info") @GET @Produces(MediaType.TEXT_PLAIN) @ApiOperation( value = "Get information indicating whether a tile exists and is valid") @ApiResponses(value = { @ApiResponse(code = 200, message = "tile exists and is valid"), @ApiResponse(code = 400, message = "tile not valid"), @ApiResponse(code = 404, message = "tile not found"), }) Response getValidationInfo(@PathParam("owner") final String owner,
                                      @PathParam("project") final String project,
                                      @PathParam("stack") final String stack,
                                      @PathParam("tileId") final String tileId); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/source/scale/{scale}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering tile source image (without transformations or mask)") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileSourceRenderParameters(@PathParam("owner") final String owner,
                                                          @PathParam("project") final String project,
                                                          @PathParam("stack") final String stack,
                                                          @PathParam("tileId") final String tileId,
                                                          @PathParam("scale") final Double scale,
                                                          @BeanParam final RenderQueryParameters renderQueryParameters); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/mask/scale/{scale}/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering tile mask image (without transformations)") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileMaskRenderParameters(@PathParam("owner") final String owner,
                                                        @PathParam("project") final String project,
                                                        @PathParam("stack") final String stack,
                                                        @PathParam("tileId") final String tileId,
                                                        @PathParam("scale") final Double scale,
                                                        @BeanParam final RenderQueryParameters renderQueryParameters); @Path("v1/owner/{owner}/project/{project}/stack/{stack}/tile/{tileId}/withNeighbors/render-parameters") @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Get parameters for rendering a tile with its neighbors") @ApiResponses(value = { @ApiResponse(code = 404, message = "tile not found"), }) RenderParameters getTileWithNeighborsRenderParameters(@PathParam("owner") final String owner,
                                                                 @PathParam("project") final String project,
                                                                 @PathParam("stack") final String stack,
                                                                 @PathParam("tileId") final String tileId,
                                                                 @QueryParam("widthFactor") Double widthFactor,
                                                                 @QueryParam("heightFactor") Double heightFactor,
                                                                 @BeanParam final RenderQueryParameters renderQueryParameters);  }