-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from 3dcitydb/feature-affine-transform
Add possibility to transform coordinates using a 3x4 matrix during import and export
- Loading branch information
Showing
33 changed files
with
1,337 additions
and
76 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
citydb-cli/src/main/java/org/citydb/cli/common/TransformOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* citydb-tool - Command-line tool for the 3D City Database | ||
* https://www.3dcitydb.org/ | ||
* | ||
* Copyright 2022-2025 | ||
* virtualcitysystems GmbH, Germany | ||
* https://vc.systems/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citydb.cli.common; | ||
|
||
import org.citydb.model.common.Matrix3x4; | ||
import picocli.CommandLine; | ||
|
||
import java.util.Arrays; | ||
|
||
public class TransformOptions implements Option { | ||
@CommandLine.Option(names = "--transform", paramLabel = "<m0,m1,...,m11|swap-xy>", | ||
description = "Transform coordinates using a 3x4 matrix in row-major order. Use 'swap-xy' as a shortcut.") | ||
private String transform; | ||
|
||
private Matrix3x4 transformationMatrix; | ||
|
||
public Matrix3x4 getTransformationMatrix() { | ||
return transformationMatrix; | ||
} | ||
|
||
@Override | ||
public void preprocess(CommandLine commandLine) throws Exception { | ||
if (transform != null) { | ||
if (transform.equalsIgnoreCase("swap-xy")) { | ||
transformationMatrix = Matrix3x4.ofRowMajor( | ||
0, 1, 0, 0, | ||
1, 0, 0, 0, | ||
0, 0, 1, 0); | ||
} else { | ||
String[] values = transform.split(","); | ||
if (values.length == 12) { | ||
try { | ||
transformationMatrix = Matrix3x4.ofRowMajor(Arrays.stream(values) | ||
.map(Double::parseDouble) | ||
.toList()); | ||
} catch (NumberFormatException e) { | ||
throw new CommandLine.ParameterException(commandLine, | ||
"Error: The elements of a 3x4 matrix must be floating point numbers but were '" + | ||
String.join(",", values) + "'"); | ||
} | ||
} else { | ||
throw new CommandLine.ParameterException(commandLine, | ||
"Error: A 3x4 matrix must be in M0,M1,...,M11 format but was '" + transform + "'"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
citydb-model/src/main/java/org/citydb/model/common/Matrix2x2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* citydb-tool - Command-line tool for the 3D City Database | ||
* https://www.3dcitydb.org/ | ||
* | ||
* Copyright 2022-2025 | ||
* virtualcitysystems GmbH, Germany | ||
* https://vc.systems/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citydb.model.common; | ||
|
||
import org.citydb.model.util.matrix.Matrix; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Matrix2x2 extends Matrix { | ||
|
||
private Matrix2x2() { | ||
super(2, 2); | ||
} | ||
|
||
private Matrix2x2(Matrix matrix) { | ||
super(matrix.getElements(), 2, 2); | ||
} | ||
|
||
public static Matrix2x2 newInstance() { | ||
return new Matrix2x2(); | ||
} | ||
|
||
public static Matrix2x2 of(Matrix matrix) { | ||
Objects.requireNonNull(matrix, "The matrix must not be null."); | ||
int rows = matrix.getRows(); | ||
int columns = matrix.getColumns(); | ||
return new Matrix2x2(rows != 2 || columns != 2 ? | ||
Matrix.identity(2, 2).setSubMatrix(0, Math.min(rows, 2) - 1, 0, Math.min(columns, 2) - 1, matrix) : | ||
matrix); | ||
} | ||
|
||
public static Matrix2x2 ofRowMajor(List<Double> values) { | ||
Objects.requireNonNull(values, "The matrix values must not be null."); | ||
if (values.size() > 3) { | ||
return new Matrix2x2(new Matrix(values.subList(0, 4), 2)); | ||
} else { | ||
throw new IllegalArgumentException("A 2x2 matrix requires 4 values."); | ||
} | ||
} | ||
|
||
public static Matrix2x2 ofRowMajor(double... values) { | ||
return ofRowMajor(values != null ? Arrays.stream(values).boxed().toList() : null); | ||
} | ||
|
||
public static Matrix2x2 identity() { | ||
return new Matrix2x2(Matrix.identity(2, 2)); | ||
} | ||
} |
Oops, something went wrong.