2014-09-09 15:22:29 +02:00
|
|
|
// Copyright 2014 by Sascha L. Teichmann
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2014-09-07 21:46:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2014-09-10 18:58:12 +02:00
|
|
|
"image/color"
|
2014-09-07 21:46:55 +02:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"bitbucket.org/s_l_teichmann/mtredisalize/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var (
|
|
|
|
port int
|
|
|
|
host string
|
|
|
|
x, y, z int
|
|
|
|
width, height, depth int
|
2014-09-09 15:01:14 +02:00
|
|
|
colorsfile string
|
2014-09-10 18:58:12 +02:00
|
|
|
outfile string
|
2014-09-07 21:46:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
flag.IntVar(&port, "port", 6379, "port to of mtredisalize server")
|
2014-09-10 18:58:12 +02:00
|
|
|
flag.IntVar(&port, "p", 6379, "port to of mtredisalize server (shorthand)")
|
2014-09-07 21:46:55 +02:00
|
|
|
flag.StringVar(&host, "host", "localhost", "host to mtredisalize server")
|
|
|
|
flag.IntVar(&x, "x", -9, "x of query cuboid")
|
|
|
|
flag.IntVar(&y, "y", -75, "y of query cuboid")
|
|
|
|
flag.IntVar(&z, "z", -9, "z of query cuboid")
|
|
|
|
flag.IntVar(&width, "width", 18, "width of query cuboid")
|
|
|
|
flag.IntVar(&height, "height", 18, "height of query cuboid")
|
|
|
|
flag.IntVar(&depth, "depth", 150, "depth of query cuboid")
|
|
|
|
flag.IntVar(&width, "w", 18, "width of query cuboid (shorthand)")
|
|
|
|
flag.IntVar(&height, "h", 18, "height of query cuboid (shorthand)")
|
|
|
|
flag.IntVar(&depth, "d", 150, "depth of query cuboid (shorthand)")
|
2014-09-09 15:01:14 +02:00
|
|
|
flag.StringVar(&colorsfile, "colors", "colors.txt", "definition of colors")
|
2014-09-10 18:58:12 +02:00
|
|
|
flag.StringVar(&outfile, "output", "out.png", "image file of result")
|
|
|
|
flag.StringVar(&outfile, "o", "out.png", "image file of result (shorthand)")
|
2014-09-07 21:46:55 +02:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
2014-09-09 15:01:14 +02:00
|
|
|
var err error
|
2014-09-09 23:33:53 +02:00
|
|
|
var colors *Colors
|
2014-09-09 15:01:14 +02:00
|
|
|
|
|
|
|
if colors, err = ParseColors(colorsfile); err != nil {
|
|
|
|
log.Fatalf("Cannot open color file: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-09-07 21:46:55 +02:00
|
|
|
address := fmt.Sprintf("%s:%d", host, port)
|
|
|
|
|
|
|
|
var client *Client
|
|
|
|
|
|
|
|
if client, err = NewClient("tcp", address); err != nil {
|
|
|
|
log.Fatalf("Cannot connect to '%s': %s", address, err)
|
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
q1x, q1y, q1z := int16(x), int16(y), int16(z)
|
|
|
|
q2x, q2y, q2z := q1x+int16(width)-1, q1y+int16(depth)-1, q1z+int16(height)-1
|
|
|
|
c1 := common.Coord{X: q1x, Y: q1y, Z: q1z}
|
|
|
|
c2 := common.Coord{X: q2x, Y: q2y, Z: q2z}
|
|
|
|
cuboid := common.Cuboid{P1: common.MinCoord(c1, c2), P2: common.MaxCoord(c1, c2)}
|
|
|
|
|
2014-09-10 18:58:12 +02:00
|
|
|
renderer := NewRenderer(q1x, q1z, width, height)
|
2014-09-09 17:48:39 +02:00
|
|
|
|
2014-09-10 18:58:12 +02:00
|
|
|
drawBlock := func(block *common.Block) {
|
|
|
|
if err := renderer.RenderBlock(block, colors.NameIndex); err != nil {
|
|
|
|
log.Printf("WARN: rendering block failed: %s", err)
|
2014-09-09 17:48:39 +02:00
|
|
|
}
|
2014-09-07 21:46:55 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 18:58:12 +02:00
|
|
|
if err = client.QueryCuboid(cuboid, drawBlock); err != nil {
|
2014-09-07 21:46:55 +02:00
|
|
|
log.Fatalf("query failed: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-09-10 18:58:12 +02:00
|
|
|
image := renderer.CreateImage(
|
|
|
|
colors.Colors, color.RGBA{R: 0, G: 0, B: 0, A: 0xff})
|
2014-09-09 17:48:39 +02:00
|
|
|
|
2014-09-10 18:58:12 +02:00
|
|
|
if err = SaveAsPNG(outfile, image); err != nil {
|
|
|
|
log.Fatalf("writing image failed: %s", err)
|
2014-09-09 17:48:39 +02:00
|
|
|
}
|
2014-09-10 23:49:27 +02:00
|
|
|
|
|
|
|
fmt.Printf("Rejected blocks: %d\n", renderer.RejectedBlocks)
|
2014-09-07 21:46:55 +02:00
|
|
|
}
|