Example #1
0
func Write(w io.Writer, vol volume.Space16, grid g3.Grid) (err error) {
	vol.MapBoundary(func(node g3.Node) {
		nv := volume.Normal(vol, node)
		cur := grid.At(node)
		if _, err = fmt.Fprintf(w, "%f %f %f %f %f %f\n",
			cur[0], cur[1], cur[2], nv[0], nv[1], nv[2]); err != nil {
			return
		}
	})
	return
}
Example #2
0
func Coord(vol volume.Space16, index int) (x, y, z int) {
	z = index % vol.N()
	index /= vol.N()
	y = index % vol.N()
	index /= vol.N()
	x = index
	return
}
Example #3
0
func NewVolumeField(vol volume.Space16) g3.ScalarField {
	return func(p g3.Point) float64 {
		for _, v := range p {
			if v <= 0 || v >= 1 {
				return 0
			}
		}
		xx := int(p[0] * float64(vol.N()))
		yy := int(p[1] * float64(vol.N()))
		zz := int(p[2] * float64(vol.N()))
		val := vol.Get(g3.Node{xx, yy, zz})
		if val {
			return 100
		}
		return 0
	}
}
Example #4
0
func NewVolumeField2(vol volume.Space16) g3.ScalarField {
	return func(p g3.Point) float64 {
		for _, v := range p {
			if v <= 0 || v >= 1 {
				return 0
			}
		}

		fx := p[0] * float64(vol.N())
		fy := p[1] * float64(vol.N())
		fz := p[2] * float64(vol.N())

		xx := int(fx)
		yy := int(fy)
		zz := int(fz)

		dx := fx - float64(xx) - 0.5
		dy := fy - float64(yy) - 0.5
		dz := fz - float64(zz) - 0.5

		//		r02 := dx*dx + dy*dy + dz*dz + 0.1

		var val float64
		for _, cell := range cells {
			var v float64
			if vol.Get(g3.Node{xx + cell.dx, yy + cell.dy, zz + cell.dz}) {
				v = 1
			}
			ddx := dx - float64(cell.dx)
			ddy := dy - float64(cell.dy)
			ddz := dz - float64(cell.dz)
			r2 := ddx*ddx + ddy*ddy + ddz*ddz + 0.1
			val += cell.weight * v / r2
		}
		/*		v0 := float64(0)
				if vol.Get(xx, yy, zz) {
					v0 = 1
				}
				val := 0.85 * v0 / r02*/
		return val
	}
}
Example #5
0
func Optimize(vol volume.Space16, n int) {
	var q, q2 []int
	vol.SetAllFilled(1, math.MaxUint16-3)
	vol.MapBoundary(func(node g3.Node) {
		if node[2] > 8 {
			vol.Set16(node, 1)
			q = append(q, Index(vol, node[0], node[1], node[2]))
			return
		}
	})

	for len(q) > 0 {
		fmt.Fprintf(os.Stderr, "len(q): %d\n", len(q))
		q, q2 = q2[:0], q
		for _, index := range q2 {
			x, y, z := Coord(vol, index)
			v := vol.Get16(g3.Node{x, y, z})
			if v == 0 {
				panic(fmt.Sprintf("x: %d, y: %d, z: %d, v == 0", x, y, z))
			}
			for k := 0; k < 6; k++ {
				x1 := x + n6dx[k]
				y1 := y + n6dy[k]
				z1 := z + n6dz[k]
				v1 := vol.Get16(g3.Node{x1, y1, z1})
				if v1 > v+1 && int(v)+1 <= n {
					vol.Set16(g3.Node{x1, y1, z1}, v+1)
					q = append(q, Index(vol, x1, y1, z1))
				}
			}
		}
	}
	vol.SetAllFilled(uint16(n+1), 0)

	return
}
Example #6
0
func Index(vol volume.Space16, x, y, z int) int {
	return x*vol.N()*vol.N() + y*vol.N() + z
}