changeset 3768:9e3d92785918 simplify-sounding-results

Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 25 Jun 2019 17:44:20 +0200
parents aea53775a3a7
children 6838526df94c
files cmd/srsimplify/main.go
diffstat 1 files changed, 97 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/srsimplify/main.go	Tue Jun 25 17:44:20 2019 +0200
@@ -0,0 +1,97 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2019 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+package main
+
+import (
+	"bufio"
+	"flag"
+	"fmt"
+	"io"
+	"log"
+	"os"
+	"strconv"
+	"strings"
+
+	"gemma.intevation.de/gemma/pkg/octree"
+)
+
+func loadXYZ(r io.Reader) (octree.MultiPointZ, error) {
+
+	scanner := bufio.NewScanner(r)
+
+	points := make(octree.MultiPointZ, 0, 2000000)
+
+	var x, y, z float64
+	var err error
+
+	for scanner.Scan() {
+		line := strings.TrimSpace(scanner.Text())
+		if len(line) == 0 || strings.HasPrefix(line, "#") {
+			continue
+		}
+		parts := strings.SplitN(line, " ", 3)
+		if len(parts) != 3 {
+			continue
+		}
+
+		if x, err = strconv.ParseFloat(parts[0], 64); err != nil {
+			return nil, err
+		}
+		if y, err = strconv.ParseFloat(parts[1], 64); err != nil {
+			return nil, err
+		}
+		if z, err = strconv.ParseFloat(parts[2], 64); err != nil {
+			return nil, err
+		}
+		points = append(points, octree.Vertex{X: x, Y: y, Z: z})
+	}
+
+	return points, nil
+}
+
+func storeXYZ(points octree.MultiPointZ, w io.Writer) error {
+	out := bufio.NewWriter(w)
+	for i := range points {
+		fmt.Fprintf(out, "%.5f %.5f %.5f\n",
+			points[i].X, points[i].Y, points[i].Z)
+	}
+	return out.Flush()
+}
+
+func simplify(points octree.MultiPointZ, tolerance float64) octree.MultiPointZ {
+
+	// TODO: Implement me!
+	return points
+}
+
+func main() {
+
+	var tolerance float64
+
+	flag.Float64Var(&tolerance, "t", 0.1, "accepted tolerance (shorthand)")
+	flag.Float64Var(&tolerance, "tolerance", 0.1, "accepted tolerance")
+
+	flag.Parse()
+
+	points, err := loadXYZ(os.Stdin)
+	if err != nil {
+		log.Fatalf("err: %v\n", err)
+	}
+
+	points = simplify(points, tolerance)
+
+	if err := storeXYZ(points, os.Stdout); err != nil {
+		log.Fatalf("err: %v\n", err)
+	}
+}