Skip to content

Commit aeb36b7

Browse files
authored
Merge pull request #3 from tomburke-rse/switch-bson-with-json
Rewrite to json from bson
2 parents b0dffc0 + b658367 commit aeb36b7

38 files changed

+374
-1522
lines changed

labeling.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<orderEntry type="library" name="Maven: com.googlecode.efficient-java-matrix-library:ejml:0.24" level="project" />
2020
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
2121
<orderEntry type="library" name="Maven: net.sf.trove4j:trove4j:3.0.3" level="project" />
22-
<orderEntry type="library" name="Maven: org.mongodb:bson:4.2.3" level="project" />
22+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
2323
<orderEntry type="library" name="Maven: io.scif:scifio:0.41.1" level="project" />
2424
<orderEntry type="library" name="Maven: io.scif:scifio-jai-imageio:1.1.1" level="project" />
2525
<orderEntry type="library" name="Maven: net.imagej:imagej-common:0.34.0" level="project" />

pom.xml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
67
<groupId>org.scijava</groupId>
78
<artifactId>pom-scijava</artifactId>
89
<version>30.0.0</version>
9-
<relativePath />
10+
<relativePath/>
1011
</parent>
1112

1213
<groupId>net.imglib2</groupId>
@@ -110,14 +111,18 @@
110111

111112
<!-- Other dependencies -->
112113
<dependency>
113-
<groupId>org.mongodb</groupId>
114-
<artifactId>bson</artifactId>
115-
<version>4.2.3</version>
114+
<groupId>com.google.code.gson</groupId>
115+
<artifactId>gson</artifactId>
116+
<version>${gson.version}</version>
116117
</dependency>
117118
<dependency>
118119
<groupId>io.scif</groupId>
119120
<artifactId>scifio</artifactId>
120121
</dependency>
122+
<dependency>
123+
<groupId>org.scijava</groupId>
124+
<artifactId>scijava-common</artifactId>
125+
</dependency>
121126

122127
<!-- Test dependencies -->
123128
<dependency>

src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java

+129-197
Large diffs are not rendered by default.

src/main/java/net/imglib2/labeling/LabelingIOService.java

+30-76
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
* %%
1212
* Redistribution and use in source and binary forms, with or without
1313
* modification, are permitted provided that the following conditions are met:
14-
*
14+
*
1515
* 1. Redistributions of source code must retain the above copyright notice,
1616
* this list of conditions and the following disclaimer.
1717
* 2. Redistributions in binary form must reproduce the above copyright notice,
1818
* this list of conditions and the following disclaimer in the documentation
1919
* and/or other materials provided with the distribution.
20-
*
20+
*
2121
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2222
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2323
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -34,11 +34,9 @@
3434
package net.imglib2.labeling;
3535

3636
import net.imagej.ImageJService;
37-
import net.imglib2.labeling.codecs.LabelingMappingCodec;
3837
import net.imglib2.labeling.data.Container;
3938
import net.imglib2.roi.labeling.ImgLabeling;
4039
import net.imglib2.type.numeric.IntegerType;
41-
import org.bson.codecs.Codec;
4240

4341
import java.io.IOException;
4442
import java.util.function.LongFunction;
@@ -48,111 +46,67 @@
4846
* A service to easily access a load/save functionality for BSON-based labeling data files.
4947
* Basic support for primitive types and BSON standard types is already included. For non-primitive types,
5048
* a codec must be set and the class must be given as an argument to the methods.
51-
* Examples for Codecs can be found at {@link LabelingMappingCodec}.
5249
*
5350
* @author Tom Burke
5451
*/
5552
public interface LabelingIOService extends ImageJService {
5653

57-
<T, I extends IntegerType<I>> ImgLabeling<T,I> load(String file) throws IOException;
58-
59-
<T, I extends IntegerType<I>> ImgLabeling<T,I> load(String file, Class<T> clazz, Codec<T>... codecs) throws IOException;
60-
61-
<T, I extends IntegerType<I>> void save(ImgLabeling<T,I> imgLabeling, String file) throws IOException;
62-
63-
<T, I extends IntegerType<I>> void save(ImgLabeling<T,I> imgLabeling, String file, Class<T> clazz, Codec<T>... codecs) throws IOException;
54+
<T, I extends IntegerType<I>> ImgLabeling<T, I> load(String file, Class<T> labelType, Class<I> backingType) throws IOException;
6455

56+
<T, I extends IntegerType<I>> void save(ImgLabeling<T, I> imgLabeling, String file) throws IOException;
6557

6658
/**
6759
* Load a labeling container from the given file path as string.
6860
* The file path must point to the bson file containing the labeling data.
6961
*
70-
* @param file The path to the file
71-
* @param codecs One or more codecs necessary to convert the data to clazz.
72-
* @param metadataClazz the metadata class
73-
* @param <T> the label value
74-
* @param <I> IntegerType for the pixel value
75-
* @param <S> Class of the meta data
76-
* @throws IOException on file read fail
62+
* @param file The path to the file
63+
* @param metadataType the metadata class
64+
* @param <T> the label value
65+
* @param <I> IntegerType for the pixel value
66+
* @param <S> Class of the meta data
7767
* @return a container object holding the ImgLabeling (as well as an optional source mapping)
78-
*/
79-
<S, T, I extends IntegerType<I>> Container<S, T, I> loadWithMetadata(String file, Class<S> metadataClazz, Codec<?>... codecs) throws IOException;
80-
81-
82-
/**
83-
* Load a labeling container from the given file path as string.
84-
* The file path must point to the bson file containing the labeling data.
85-
*
86-
* @param file The path to the file
87-
* @param clazz The class to convert the contains of the file to
88-
* @param metadataClazz the metadata class
89-
* @param codecs One or more codecs necessary to convert the data to clazz.
90-
* @param <T> the label value
91-
* @param <I> IntegerType for the pixel value
92-
* @param <S> Class of the meta data
9368
* @throws IOException on file read fail
94-
* @return a container object holding the ImgLabeling (as well as an optional source mapping)
9569
*/
96-
<S, T, I extends IntegerType<I>> Container<S, T, I> loadWithMetadata(String file, Class<T> clazz, Class<S> metadataClazz, Codec<?>... codecs) throws IOException;
70+
<S, T, I extends IntegerType<I>> Container<S, T, I> loadWithMetadata(String file, Class<S> metadataType, Class<T> labelType, Class<I> backingType) throws IOException;
9771

9872
/**
9973
* Load a labeling container from the given file path as string.
10074
* The file path must point to the bson file containing the labeling data.
10175
*
102-
* @param file The path to the file
103-
* @param idToLabel a function transforming the label of type T into something else
76+
* @param file The path to the file
77+
* @param idToLabel a function transforming the label of type T into something else
10478
* @param metadataClazz the metadata class
105-
* @param codecs One or more codecs necessary to convert the data to clazz.
106-
* @param <T> the label value
107-
* @param <I> IntegerType for the pixel value
108-
* @param <S> Class of the meta data
109-
* @throws IOException on file read fail
79+
* @param <T> the label value
80+
* @param <I> IntegerType for the pixel value
81+
* @param <S> Class of the meta data
11082
* @return a container object holding the ImgLabeling (as well as an optional source mapping)
83+
* @throws IOException on file read fail
11184
*/
112-
<S, T, I extends IntegerType<I>> Container<S, T, I> loadWithMetadata(String file, LongFunction<T> idToLabel, Class<S> metadataClazz, Codec<?>... codecs) throws IOException;
113-
114-
/**
115-
* Save an ImgLabelingContainer in the file-path, transforming it into a bson file and an image.
116-
* The path must contain the filename (ending does not matter).
117-
*
118-
* @param codecs one or more codecs to convert clazz into something bsonifyable
119-
* @param container the container with the ImgLabeling and a metadata object
120-
* @param file the path pointing to the file, including the filename
121-
* @param metadataClazz the metadata class
122-
* @param <T> the label value
123-
* @param <I> IntegerType for the pixel value
124-
* @param <S> Class of the meta data
125-
*/
126-
<S, T, I extends IntegerType<I>> void saveWithMetaData(Container<S, T, I> container, String file, Class<S> metadataClazz, Codec<?>... codecs);
85+
<S, T, I extends IntegerType<I>> Container<S, T, I> loadWithMetadata(String file, LongFunction<T> idToLabel, Class<S> metadataClazz) throws IOException;
12786

12887
/**
12988
* Save an ImgLabelingContainer in the file-path, transforming it into a bson file and an image.
13089
* The path must contain the filename (ending does not matter).
13190
*
132-
* @param clazz the class of the type T that is contained in the labeling
133-
* @param codecs one or more codecs to convert clazz into something bsonifyable
134-
* @param container the container with the ImgLabeling and a metadata object
135-
* @param file the path pointing to the file, including the filename
136-
* @param metadataClazz the metadata class
137-
* @param <T> the label value
138-
* @param <I> IntegerType for the pixel value
139-
* @param <S> Class of the meta data
91+
* @param imgLabeling the imglabeling object that needs to be serialized
92+
* @param file the path pointing to the file, including the filename
93+
* @param <T> the label value
94+
* @param <I> IntegerType for the pixel value
95+
* @param <S> Class of the meta data
14096
*/
141-
<S, T, I extends IntegerType<I>> void saveWithMetaData(Container<S, T, I> container, String file, Class<T> clazz, Class<S> metadataClazz, Codec<?>... codecs);
97+
<S, T, I extends IntegerType<I>> void saveWithMetaData(ImgLabeling<T, I> imgLabeling, String file, S metadata) throws IOException;
14298

14399
/**
144100
* Save an ImgLabelingContainer in the file-path, transforming it into a bson file and an image.
145101
* The path must contain the filename (ending does not matter).
146102
*
147-
* @param labelToId a function to convert the type T to a long value.
148-
* @param container the container with the ImgLabeling and a metadata object
149-
* @param codecs one or more codecs to convert clazz into something bsonifyable
150-
* @param file the path pointing to the file, including the filename
151-
* @param metadataClazz the metadata class
152-
* @param <T> the label value
153-
* @param <I> IntegerType for the pixel value
154-
* @param <S> Class of the meta data
103+
* @param imgLabeling the imglabeling object that needs to be serialized
104+
* @param labelToId a function to convert the type T to a long value.
105+
* @param file the path pointing to the file, including the filename
106+
* @param <T> the label value
107+
* @param <I> IntegerType for the pixel value
108+
* @param <S> Class of the meta data
155109
*/
156-
<S, T, I extends IntegerType<I>> void saveWithMetaData(Container<S, T, I> container, String file, ToLongFunction<T> labelToId, Class<S> metadataClazz, Codec<?>... codecs);
110+
<S, T, I extends IntegerType<I>> void saveWithMetaData(ImgLabeling<T, I> imgLabeling, String file, ToLongFunction<T> labelToId, S metadata) throws IOException;
157111

158112
}

0 commit comments

Comments
 (0)