implemented graphviz builderin dot.go to build dot files for graphviz
This commit is contained in:
@@ -1,3 +1,37 @@
|
|||||||
package viz
|
package viz
|
||||||
|
|
||||||
//init
|
import (
|
||||||
|
"bspviz/internal/bsp"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EmitDOT(root *bsp.Node, path string) error {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteString("digraph BSP {\n")
|
||||||
|
buf.WriteString(" node [fontname=\"Helvetica\"];\n")
|
||||||
|
|
||||||
|
id := 0
|
||||||
|
var walk func(*bsp.Node) int
|
||||||
|
walk = func(n *bsp.Node) int {
|
||||||
|
my := id
|
||||||
|
id++
|
||||||
|
if n.Leaf != nil {
|
||||||
|
fmt.Fprintf(&buf, " n%d [label=\"Leaf\\nSegs=%d\", shape=ellipse, style=filled, fillcolor=lightgray];\n",
|
||||||
|
my, len(n.Leaf.Segs))
|
||||||
|
return my
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&buf, " n%d [label=\"Split\\nO=(%.0f,%.0f) D=(%.0f,%.0f)\"];\n",
|
||||||
|
my, n.O.X, n.O.Y, n.D.X, n.D.Y)
|
||||||
|
l := walk(n.Left)
|
||||||
|
r := walk(n.Right)
|
||||||
|
fmt.Fprintf(&buf, " n%d -> n%d [label=\"L\"];\n", my, l)
|
||||||
|
fmt.Fprintf(&buf, " n%d -> n%d [label=\"R\"];\n", my, r)
|
||||||
|
return my
|
||||||
|
}
|
||||||
|
walk(root)
|
||||||
|
|
||||||
|
buf.WriteString("}\n")
|
||||||
|
return os.WriteFile(path, buf.Bytes(), 0644)
|
||||||
|
}
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"bspviz/internal/bsp"
|
"bspviz/internal/bsp"
|
||||||
"bspviz/internal/geom"
|
"bspviz/internal/geom"
|
||||||
"bspviz/internal/mapfmt"
|
"bspviz/internal/mapfmt"
|
||||||
|
"bspviz/internal/viz"
|
||||||
"bspviz/internal/wad"
|
"bspviz/internal/wad"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -30,6 +31,7 @@ func main() {
|
|||||||
depth := flag.Int("maxdepth", 32, "max. Rekursionstiefe")
|
depth := flag.Int("maxdepth", 32, "max. Rekursionstiefe")
|
||||||
cands := flag.Int("cands", 16, "Anzahl Kandidaten (Subsample)")
|
cands := flag.Int("cands", 16, "Anzahl Kandidaten (Subsample)")
|
||||||
seed := flag.Int64("seed", 0, "RNG-Seed (0 = default)")
|
seed := flag.Int64("seed", 0, "RNG-Seed (0 = default)")
|
||||||
|
dotOut := flag.String("dot", "", "DOT-Export-Datei (optional)")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -190,6 +192,14 @@ func main() {
|
|||||||
st.Nodes, st.Leaves, st.MaxDepth, st.TotalSegs)
|
st.Nodes, st.Leaves, st.MaxDepth, st.TotalSegs)
|
||||||
fmt.Printf(" params: alpha=%.2f beta=%.2f eps=%.1e leafMax=%d maxDepth=%d cands=%d seed=%d\n",
|
fmt.Printf(" params: alpha=%.2f beta=%.2f eps=%.1e leafMax=%d maxDepth=%d cands=%d seed=%d\n",
|
||||||
p.Alpha, p.Beta, p.Eps, p.LeafMax, p.MaxDepth, p.Cands, p.Seed)
|
p.Alpha, p.Beta, p.Eps, p.LeafMax, p.MaxDepth, p.Cands, p.Seed)
|
||||||
|
|
||||||
|
if *dotOut != "" {
|
||||||
|
if err := viz.EmitDOT(root, *dotOut); err != nil {
|
||||||
|
log.Fatalf("write DOT: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("DOT export geschrieben: %s (mit 'dot -Tpng %s -o tree.png' rendern)\n",
|
||||||
|
*dotOut, *dotOut)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user