Пример #1
0
func initVoxels() {

	s := 164096

	voxels := glvox.NewOctree(s)

	glvox.ReadBinvox("../res/skull256.binvox", voxels, 896, 896, 896)

	data := voxels.Index
	buf := gl.GenBuffer()
	buf.Bind(gl.TEXTURE_BUFFER)
	gl.BufferData(gl.TEXTURE_BUFFER, len(data)*4, data, gl.STATIC_DRAW)

	gl.ActiveTexture(gl.TEXTURE0)
	tex := gl.GenTexture()
	tex.Bind(gl.TEXTURE_BUFFER)
	gl.TexBuffer(gl.TEXTURE_BUFFER, gl.R32I, buf)

	voxelsLoc := prg.GetUniformLocation("voxels")
	voxelsLoc.Uniform1i(0)

	var value [1]int32
	gl.GetIntegerv(gl.MAX_TEXTURE_BUFFER_SIZE, value[:])
	fmt.Println("max texture buffer size:", value[0]/1024/1024, "MiB")

	sizeLoc := prg.GetUniformLocation("size")
	sizeLoc.Uniform1i(int(voxels.Size))
	fmt.Println("voxel data uploaded:", len(voxels.Index)*4/1024/1024, "MiB")
}
Пример #2
0
func TestReadBinvox(t *testing.T) {

	voxels := glvox.NewOctree(1256)
	err := glvox.ReadBinvox("skull.binvox", voxels, 0, 0, 0)
	if err != nil {
		t.Error(err)
	}

	if voxels.Size <= 0 {
		t.Error("dimension > 0 expected, was", voxels.Size)
	}

	indexCount := len(voxels.Index) / 8
	if indexCount != 642216 {
		t.Error("index size 642216 expected, was", indexCount)
	}

	longJump := int32(0)
	for i := int32(0); i < int32(indexCount); i++ {
		for j := int32(0); j < 8; j++ {
			idx := voxels.Index[i<<3+j]
			if idx <= 0 {
				continue
			}

			jump := idx - i
			if jump > longJump {
				longJump = jump
			}
		}
	}
	fmt.Println("longest jump", longJump)

	avgJump := int32(0)
	jumpCount := int32(0)
	for i := int32(0); i < int32(indexCount); i++ {
		for j := int32(0); j < 8; j++ {
			idx := voxels.Index[i<<3+j]
			if idx <= 0 {
				continue
			}

			avgJump += idx - i
			jumpCount++
		}
	}
	avgJump /= jumpCount
	fmt.Println("average jump", avgJump)
}