view cmd/octree2contour/main.go @ 681:a8d32a11b113 octree

octree: more consistent traversal order in contour tool.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 Sep 2018 18:39:03 +0200
parents c79c7be29a7a
children a2f107f1e4e7
line wrap: on
line source

package main

import (
	"flag"
	"log"
	"time"
)

var (
	one  = flag.Bool("o", false, "create only a single contour")
	step = flag.Float64("s", 0.5, "step with")
	max  = flag.Float64("m", 10, "max height from lowest point")
)

func process(tree *octree) {
	var triangles int
	start := time.Now()
	if *one {
		tree.horizontal(*step, func([]int32) {
			triangles++
		})
	} else {
		for h := tree.min.z; h <= tree.max.z; h += *step {
			var level int
			tree.horizontal(h, func([]int32) {
				level++
			})
			log.Printf("level %f: %d\n", h, level)
			triangles += level
		}
	}
	log.Printf("traversal took: %v\n", time.Since(start))
	log.Printf("num triangles: %d\n", triangles)
}

func main() {
	flag.Parse()

	for _, fname := range flag.Args() {
		log.Printf("processing %s\n", fname)
		start := time.Now()
		tree, err := loadOctree(fname)
		if err != nil {
			log.Printf("error: %v\n", err)
			continue
		}
		log.Printf("loading took: %v\n", time.Since(start))
		process(tree)
	}
}