Skip to content

Commit

Permalink
MultiViewIO
Browse files Browse the repository at this point in the history
- Switcher over to using try with resource
- Removed close() calls when the function didn't "own" the unput
  • Loading branch information
lessthanoptimal committed Sep 7, 2024
1 parent c12f245 commit a4ed1bc
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions main/boofcv-io/src/main/java/boofcv/io/geo/MultiViewIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
public class MultiViewIO {

public static void save( LookUpSimilarImages db, String path ) {
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8);
try (var writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8)) {
save(db, writer);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -74,7 +73,7 @@ public static void save( LookUpSimilarImages db, String path ) {
* @param outputWriter (Output) where the graph is writen to
*/
public static void save( LookUpSimilarImages db, Writer outputWriter ) {
PrintWriter out = new PrintWriter(outputWriter);
var out = new PrintWriter(outputWriter);

Yaml yaml = createYmlObject();

Expand Down Expand Up @@ -152,8 +151,7 @@ public static void save( LookUpSimilarImages db, Writer outputWriter ) {
}

public static void save( PairwiseImageGraph graph, String path ) {
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8);
try (var writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8)) {
save(graph, writer);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -167,7 +165,7 @@ public static void save( PairwiseImageGraph graph, String path ) {
* @param outputWriter (Output) where the graph is writen to
*/
public static void save( PairwiseImageGraph graph, Writer outputWriter ) {
PrintWriter out = new PrintWriter(outputWriter);
var out = new PrintWriter(outputWriter);

Yaml yaml = createYmlObject();

Expand Down Expand Up @@ -208,13 +206,10 @@ public static void save( PairwiseImageGraph graph, Writer outputWriter ) {
data.put("version", 0);

yaml.dump(data, out);

out.close();
}

public static void save( SceneStructureMetric scene, String path ) {
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8);
try (var writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8)) {
save(scene, writer);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -228,7 +223,7 @@ public static void save( SceneStructureMetric scene, String path ) {
* @param outputWriter (Output) where the scene is writen to
*/
public static void save( SceneStructureMetric scene, Writer outputWriter ) {
PrintWriter out = new PrintWriter(outputWriter);
var out = new PrintWriter(outputWriter);

Yaml yaml = createYmlObject();

Expand Down Expand Up @@ -257,8 +252,6 @@ public static void save( SceneStructureMetric scene, Writer outputWriter ) {
data.put("version", 0);

yaml.dump(data, out);

out.close();
}

/**
Expand Down Expand Up @@ -287,8 +280,6 @@ public static void save( SceneObservations scene, Writer outputWriter ) {
data.put("version", 0);

yaml.dump(data, out);

out.close();
}

public static void save( SceneObservations scene, File destination ) {
Expand All @@ -301,7 +292,7 @@ public static void save( SceneObservations scene, File destination ) {

private static Map<String, Object> encodeSceneView( SceneStructureMetric scene,
SceneStructureMetric.View v ) {
Map<String, Object> encoded = new HashMap<>();
var encoded = new HashMap<String, Object>();
encoded.put("camera", v.camera);
encoded.put("parent_to_view", v.parent_to_view);
if (v.parent != null)
Expand All @@ -310,14 +301,14 @@ private static Map<String, Object> encodeSceneView( SceneStructureMetric scene,
}

private static Map<String, Object> encodeSceneMotion( SceneStructureMetric.Motion m ) {
Map<String, Object> encoded = new HashMap<>();
var encoded = new HashMap<String, Object>();
encoded.put("known", m.known);
encoded.put("motion", putSE3(m.parent_to_view));
return encoded;
}

private static Map<String, Object> encodeSceneRigid( SceneStructureMetric.Rigid r ) {
Map<String, Object> encoded = new HashMap<>();
var encoded = new HashMap<String, Object>();
encoded.put("known", r.known);
encoded.put("object_to_world", putSE3(r.object_to_world));
encoded.put("indexFirst", r.indexFirst);
Expand All @@ -331,14 +322,14 @@ private static Map<String, Object> encodeSceneRigid( SceneStructureMetric.Rigid
}

private static Map<String, Object> encodeScenePoint( SceneStructureCommon.Point p ) {
Map<String, Object> encoded = new HashMap<>();
var encoded = new HashMap<String, Object>();
encoded.put("coordinate", p.coordinate);
encoded.put("views", p.views.toArray());
return encoded;
}

private static Map<String, Object> encodeObservationView( SceneObservations.View v ) {
Map<String, Object> encoded = new HashMap<>();
var encoded = new HashMap<String, Object>();
encoded.put("point", v.point.toArray());
encoded.put("observations", v.observations.toArray());
if (v.cameraState != null) {
Expand Down Expand Up @@ -443,8 +434,7 @@ private static BundleCameraState decodeCameraState( Map<String, Object> encoded
}

public static SceneStructureMetric load( String path, @Nullable SceneStructureMetric graph ) {
try {
Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8);
try (var reader = new InputStreamReader(new FileInputStream(path), UTF_8)) {
return load(reader, graph);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -522,8 +512,7 @@ public static SceneStructureMetric load( Reader reader, @Nullable SceneStructure
}

public static SceneObservations load( String path, @Nullable SceneObservations graph ) {
try {
Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8);
try (var reader = new InputStreamReader(new FileInputStream(path), UTF_8)) {
return load(reader, graph);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -585,8 +574,7 @@ private static void loadObservations( FastAccess<SceneObservations.View> views,
}

public static LookUpSimilarImages loadSimilarImages( String path ) {
try {
Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8);
try (Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8)) {
return loadSimilarImages(reader);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -657,8 +645,7 @@ public static LookUpSimilarImages loadSimilarImages( Reader reader ) {
}

public static PairwiseImageGraph load( String path, @Nullable PairwiseImageGraph graph ) {
try {
Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8);
try (Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8)) {
return load(reader, graph);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -743,8 +730,7 @@ private static void decodeInliers( List<Map<String, Object>> encoded, DogArray<A
}

public static void save( SceneWorkingGraph working, String path ) {
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8);
try (var writer = new OutputStreamWriter(new FileOutputStream(path), UTF_8)) {
save(working, writer);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -802,8 +788,7 @@ public static void save( SceneWorkingGraph working, Writer outputWriter ) {
}

public static SceneWorkingGraph load( String path, PairwiseImageGraph pairwise, @Nullable SceneWorkingGraph working ) {
try {
Reader reader = new InputStreamReader(new FileInputStream(path), UTF_8);
try (var reader = new InputStreamReader(new FileInputStream(path), UTF_8)) {
return load(reader, pairwise, working);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -863,7 +848,7 @@ public static SceneWorkingGraph load( Reader reader, PairwiseImageGraph pairwise
}

public static List<Object> putInlierInfo( FastAccess<InlierInfo> listInliers ) {
List<Object> list = new ArrayList<>();
var list = new ArrayList<Object>();
for (int infoIdx = 0; infoIdx < listInliers.size; infoIdx++) {
InlierInfo inliers = listInliers.get(infoIdx);

Expand Down Expand Up @@ -932,7 +917,7 @@ public static BundlePinholeSimplified loadPinholeSimplified( Map<String, Object>
}

public static Map<String, Object> putPinholeSimplified( BundlePinholeSimplified intrinsic ) {
Map<String, Object> map = new HashMap<>();
var map = new HashMap<String, Object>();

map.put("f", intrinsic.f);
map.put("k1", intrinsic.k1);
Expand All @@ -942,7 +927,7 @@ public static Map<String, Object> putPinholeSimplified( BundlePinholeSimplified
}

public static Map<String, Object> putSE3( Se3_F64 m ) {
Map<String, Object> map = new HashMap<>();
var map = new HashMap<String, Object>();

map.put("x", m.T.x);
map.put("y", m.T.y);
Expand Down

0 comments on commit a4ed1bc

Please sign in to comment.