Пример #1
0
func main() {
	flag.BoolVar(showHelp, "h", false, "Show help message")
	flag.Usage = usage
	flag.Parse()

	if *showHelp {
		flag.Usage()
		os.Exit(0)
	}

	// Get required arguments
	args := flag.Args()
	if len(args) < 3 {
		usage()
		os.Exit(2)
	}
	voxelProofDir := args[0]
	zrangeStr := args[1]
	tileSizeStr := args[2]
	outputDir := args[3]

	fmt.Println("VoxelProof data directory:", voxelProofDir)
	zrange, err := dvid.PointStr(zrangeStr).Point2d()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Z range %d -> %d\n", zrange[0], zrange[1])
	tileSize, err := dvid.PointStr(tileSizeStr).Point2d()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Tile size: %d x %d pixels\n", tileSize[0], tileSize[1])
	fmt.Println("Output DVID database:", outputDir)

	// Initialize the database
	uuidStr := initDatastore(outputDir)
	fmt.Printf("Initialized datastore with root version %s.\n", uuidStr)

	// Startup a server for this new datastore.  It will exit when this program exits.
	cmd := exec.Command("dvid", "-datastore="+outputDir, "serve")
	if err := cmd.Start(); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Making sure DVID server has started...")
	time.Sleep(3 * time.Second)

	// Shutdown the server no matter how we exit
	defer runCommand("dvid", "shutdown")

	// Capture ctrl+c and handle graceful shutdown (flushing of cache, etc.)
	ctrl_c := make(chan os.Signal, 1)
	go func() {
		for sig := range ctrl_c {
			log.Printf("Captured %v.  Shutting down...\n", sig)
			runCommand("dvid", "shutdown")
			os.Exit(0)
		}
	}()
	signal.Notify(ctrl_c, os.Interrupt)

	// Create dataset for grayscale
	runCommand("dvid", "dataset", "grayscale", "grayscale8")

	// Create dataset for labels
	runCommand("dvid", "dataset", "labels", "labels32")

	// Add grayscale
	vol := dvid.VoxelCoord{700, 700, 620}
	tileXMax := vol[0] / tileSize[0]
	tileYMax := vol[1] / tileSize[1]
	fmt.Printf("X Tiles from [0,%d), Y Tiles from [0,%d)\n", tileXMax, tileYMax)

	numTiles := tileXMax * tileYMax
	for z := zrange[0]; z <= zrange[1]; z++ {
		for y := int32(0); y < tileYMax; y++ {
			for x := int32(0); x < tileXMax; x++ {
				fname := fmt.Sprintf("%d-%d.png", y, x)
				tilepath := filepath.Join(voxelProofDir, "z", strconv.Itoa(int(z)), fname)
				ox := x * tileSize[0]
				oy := y * tileSize[1]
				oz := z - zrange[0]
				offsetStr := fmt.Sprintf("%d,%d,%d", ox, oy, oz)
				err = runCommand("dvid", "grayscale", "server-add",
					uuidStr, offsetStr, tilepath)
				if err != nil {
					log.Fatalf("Error in command: %s\n", err.Error())
				}
			}
		}
		fmt.Printf("Added %d grayscale tiles from z = %d...\n", numTiles, z)
	}

	// Add labels
	for z := zrange[0]; z <= zrange[1]; z++ {
		for y := int32(0); y < tileYMax; y++ {
			for x := int32(0); x < tileXMax; x++ {
				fname := fmt.Sprintf("%d-%d.png", y, x)
				tilepath := filepath.Join(voxelProofDir, "comps", "z",
					strconv.Itoa(int(z)), fname)
				ox := x * tileSize[0]
				oy := y * tileSize[1]
				oz := z - zrange[0]
				offsetStr := fmt.Sprintf("%d,%d,%d", ox, oy, oz)
				err = runCommand("dvid", "labels", "server-add",
					uuidStr, offsetStr, tilepath)
				if err != nil {
					log.Fatalf("Error in command: %s\n", err.Error())
				}
			}
		}
		fmt.Printf("Added %d label tiles from z = %d...\n", numTiles, z)
	}
}
Пример #2
0
func main() {
	flag.BoolVar(showHelp, "h", false, "Show help message")
	flag.Usage = usage
	flag.Parse()

	if *showHelp {
		flag.Usage()
		os.Exit(0)
	}

	// Get required arguments
	args := flag.Args()
	if len(args) < 5 {
		usage()
		os.Exit(2)
	}
	uuidStr := args[0]
	datasetName := args[1]
	tilesDir := args[2]
	offsetStr := args[3]
	sizeStr := args[4]

	fmt.Println("Tiles directory:", tilesDir)
	offset, err := dvid.PointStr(offsetStr).VoxelCoord()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Offset: %s\n", offset)
	size, err := dvid.PointStr(sizeStr).Point3d()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Size: %s\n", size)

	// Add tiles within the bounds.
	endVoxel := offset.AddSize(size)
	startTileX := offset[0] / tileSize
	startTileY := offset[1] / tileSize
	endTileX := endVoxel[0] / tileSize
	endTileY := endVoxel[1] / tileSize

	for z := offset[2]; z <= endVoxel[2]; z++ {
		numTiles := 0
		for tileY := startTileY; tileY <= endTileY; tileY++ {
			for tileX := startTileX; tileX <= endTileX; tileX++ {
				offsetStr := fmt.Sprintf("%d,%d,%d", tileX*tileSize, tileY*tileSize, z)
				if *loadSuperpixels {
					filename := filepath.Join(tilesDir, tileFilename(tileY, tileX, z, true))
					err = runCommand("dvid", datasetName, "server-add", uuidStr, offsetStr, filename)
					if err != nil {
						log.Fatalf("Error in command: %s\n", err.Error())
					}
				}
				if *loadGrayscale {
					filename := filepath.Join(tilesDir, tileFilename(tileY, tileX, z, false))
					err = runCommand("dvid", datasetName, "server-add", uuidStr, offsetStr, filename)
					if err != nil {
						log.Fatalf("Error in command: %s\n", err.Error())
					}
				}
				numTiles++
			}
		}
		fmt.Printf("Added %d %s tiles from z = %d...\n", numTiles, datasetName, z)
	}
}