From 3bb238f91c540b906e680513ca14b46cf5f0803f Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Sun, 9 Mar 2014 17:28:15 +0100
Subject: [PATCH] Prepared first implementation for Duvenhage algorithm.

For now, only the (incomplete) API and classes hierarchy has been set
up. The tile is still a simple tile and does not yet creates the min/max
kd-tree. The algorithm doesn't do anything.
---
 .../core/duvenhage/DuvenhagedRugged.java      | 48 ++++++++++++
 .../rugged/core/duvenhage/MinMaxTreeTile.java | 73 +++++++++++++++++++
 .../core/duvenhage/MinMaxTreeTileFactory.java | 32 ++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/DuvenhagedRugged.java
 create mode 100644 rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java
 create mode 100644 rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileFactory.java

diff --git a/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/DuvenhagedRugged.java b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/DuvenhagedRugged.java
new file mode 100644
index 00000000..59bc991a
--- /dev/null
+++ b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/DuvenhagedRugged.java
@@ -0,0 +1,48 @@
+/* Copyright 2013-2014 CS Systèmes d'Information
+ * Licensed to CS Systèmes d'Information (CS) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * CS licenses this file to You 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.orekit.rugged.core.duvenhage;
+
+import org.orekit.rugged.api.TileUpdater;
+import org.orekit.rugged.core.AbstractRugged;
+import org.orekit.rugged.core.dem.TilesCache;
+
+/** Direct and inverse localization using Duvenhage's algorithm.
+ * <p>
+ * The algorithm is described in the 2009 paper:
+ * <a href="http://researchspace.csir.co.za/dspace/bitstream/10204/3041/1/Duvenhage_2009.pdf">Using
+ * An Implicit Min/Max KD-Tree for Doing Efficient Terrain Line of Sight Calculations</a>.
+ * </p>
+ * @author Luc Maisonobe
+ */
+public class DuvenhagedRugged extends AbstractRugged {
+
+    /** Cache for DEM tiles. */
+    private TilesCache<MinMaxTreeTile> cache;
+
+    /** Simple constructor.
+     */
+    public DuvenhagedRugged() {
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setUpTilesManagement(TileUpdater updater, int maxCachedTiles) {
+        cache = new TilesCache<MinMaxTreeTile>(new MinMaxTreeTileFactory(),
+                                               updater, maxCachedTiles);
+    }
+
+}
diff --git a/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java
new file mode 100644
index 00000000..21fc4761
--- /dev/null
+++ b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java
@@ -0,0 +1,73 @@
+/* Copyright 2013-2014 CS Systèmes d'Information
+ * Licensed to CS Systèmes d'Information (CS) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * CS licenses this file to You 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.orekit.rugged.core.duvenhage;
+
+import org.orekit.rugged.api.RuggedException;
+import org.orekit.rugged.core.dem.AbstractTile;
+import org.orekit.rugged.core.dem.Tile;
+
+/** Simple implementation of a {@link Tile} with a min/max kd tree.
+ * @see MinMaxTreeTileFactory
+ * @author Luc Maisonobe
+ */
+public class MinMaxTreeTile extends AbstractTile {
+
+    /** Elevation array. */
+    private double[] elevations;
+
+    /** Simple constructor.
+     * <p>
+     * Creates an empty tile.
+     * </p>
+     */
+    MinMaxTreeTile() {
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setGeometry(final double minLatitude, final double minLongitude,
+                            final double latitudeStep, final double longitudeStep,
+                            final int latitudeRows, final int longitudeColumns) {
+        super.setGeometry(minLatitude, minLongitude, latitudeStep, longitudeStep,
+                          latitudeRows, longitudeColumns);
+        this.elevations = new double[latitudeRows * longitudeColumns];
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void tileUpdateCompleted() throws RuggedException {
+        // TODO: compute min/max tree
+        throw RuggedException.createInternalError(null);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setElevation(final int latitudeIndex, final int longitudeIndex,
+                             final double elevation) throws RuggedException {
+        checkIndices(latitudeIndex, longitudeIndex);
+        elevations[latitudeIndex * getLongitudeColumns() + longitudeIndex] = elevation;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double getElevationAtIndices(int latitudeIndex, int longitudeIndex)
+        throws RuggedException {
+        checkIndices(latitudeIndex, longitudeIndex);
+        return elevations[latitudeIndex * getLongitudeColumns() + longitudeIndex];
+    }
+
+}
diff --git a/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileFactory.java b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileFactory.java
new file mode 100644
index 00000000..259d81ac
--- /dev/null
+++ b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileFactory.java
@@ -0,0 +1,32 @@
+/* Copyright 2013-2014 CS Systèmes d'Information
+ * Licensed to CS Systèmes d'Information (CS) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * CS licenses this file to You 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.orekit.rugged.core.duvenhage;
+
+import org.orekit.rugged.core.dem.TileFactory;
+
+/** Simple implementation of a {@link TileFactory} for {@link MinMaxTreeTile}.
+ * @author Luc Maisonobe
+ */
+public class MinMaxTreeTileFactory implements TileFactory<MinMaxTreeTile> {
+
+    /** {@inheritDoc} */
+    @Override
+    public MinMaxTreeTile createTile() {
+        return new MinMaxTreeTile();
+    }
+
+}
-- 
GitLab