Exemplo n.º 1
0
// Krefine returns a new Nurbs with knots refined
// Note: X[gnd][numNewKnots]
func (o *Nurbs) Krefine(X [][]float64) (O *Nurbs) {

	// check
	if len(X) != o.gnd {
		chk.Panic("size of new knots array X must be [gnd==%d][numNewKnots]. len==%d of first dimension is incorrect", o.gnd, len(X))
	}

	// number of new knots and first and last knots
	nk, a, b := make([]int, 3), make([]int, 3), make([]int, 3)
	for d := 0; d < o.gnd; d++ {
		nk[d] = len(X[d])
		a[d] = o.b[d].find_span(X[d][0])
		b[d] = o.b[d].find_span(X[d][nk[d]-1])
	}

	// new knots array
	Unew := make([][]float64, o.gnd)
	Unew[0] = make([]float64, o.b[0].m+nk[0])
	if o.gnd > 1 {
		Unew[1] = make([]float64, o.b[1].m+nk[1])
	}
	if o.gnd > 2 {
		Unew[2] = make([]float64, o.b[2].m+nk[2])
	}

	// refine
	var Qnew [][][][]float64
	switch o.gnd {
	case 1:
		Qnew = utl.Deep4alloc(o.n[0]+nk[0], o.n[1], o.n[2], 4)
		krefine(Unew, Qnew, o.Q, 0, X[0], o.b[0].T, o.n, o.p, a[0], b[0])
	case 2:
		// along 0
		Qtmp := utl.Deep4alloc(o.n[0]+nk[0], o.n[1], o.n[2], 4)
		krefine(Unew, Qtmp, o.Q, 0, X[0], o.b[0].T, o.n, o.p, a[0], b[0])
		// along 1
		nn := make([]int, 3)
		copy(nn, o.n)
		nn[0] += nk[0]
		Qnew = utl.Deep4alloc(nn[0], o.n[1]+nk[1], o.n[2], 4)
		krefine(Unew, Qnew, Qtmp, 1, X[1], o.b[1].T, nn, o.p, a[1], b[1])
	case 3:
		chk.Panic("nurbs.go: Krefine: gnd=3 not implemented yet")
	}

	// initialize new nurbs
	O = new(Nurbs)
	O.Init(o.gnd, o.p, Unew)
	O.Q = Qnew
	return
}
Exemplo n.º 2
0
// CloneCtrlsAlongCurve returns a copy of control points @ 2D boundary
func (o *Nurbs) CloneCtrlsAlongCurve(iAlong, jAt int) (Qnew [][][][]float64) {
	Qnew = utl.Deep4alloc(o.n[iAlong], 1, 1, 4)
	var i, j int
	for m := 0; m < o.n[iAlong]; m++ {
		i, j = m, jAt
		if iAlong == 1 {
			i, j = jAt, m
		}
		for e := 0; e < 4; e++ {
			Qnew[m][0][0][e] = o.Q[i][j][0][e]
		}
	}
	return
}
Exemplo n.º 3
0
// Init initialises Nurbs
func (o *Nurbs) Init(gnd int, ords []int, knots [][]float64) {

	// essential
	o.gnd = gnd
	o.p = make([]int, 3)

	// B-splines
	o.b = make([]Bspline, o.gnd)
	o.n = make([]int, 3)
	for d := 0; d < o.gnd; d++ {
		o.p[d] = ords[d]
		o.b[d].Init(knots[d], o.p[d])
		o.n[d] = o.b[d].NumBasis()
		if o.n[d] < 2 {
			chk.Panic("number of knots is incorrect for dimension %d. n == %d is invalid", d, o.n[d])
		}
	}
	for d := o.gnd; d < 3; d++ {
		o.n[d] = 1
	}

	// ids of control points
	nctrl := o.n[0] * o.n[1] * o.n[2]
	o.l2i = make([][]int, nctrl)
	for l := 0; l < nctrl; l++ {
		o.l2i[l] = make([]int, 3)
		switch o.gnd {
		case 1:
			o.l2i[l][0] = l
		case 2:
			o.l2i[l][0] = l % o.n[0] // i
			o.l2i[l][1] = l / o.n[0] // j
		case 3:
			c := l % (o.n[0] * o.n[1])
			o.l2i[l][0] = c % o.n[0]            // i
			o.l2i[l][1] = c / o.n[0]            // j
			o.l2i[l][2] = l / (o.n[0] * o.n[1]) // k
		}
	}

	// auxiliary
	o.span = make([]int, 3)
	o.idx = make([]int, 3)
	o.cw = make([]float64, 4)
	o.rr = utl.Deep3alloc(o.p[0]+1, o.p[1]+1, o.p[2]+1)
	o.drr = utl.Deep4alloc(o.p[0]+1, o.p[1]+1, o.p[2]+1, o.gnd)
	o.dww = make([]float64, o.gnd)
}
Exemplo n.º 4
0
// CloneCtrlsAlongSurface returns a copy of control points @ 3D boundary
func (o *Nurbs) CloneCtrlsAlongSurface(iAlong, jAlong, kAt int) (Qnew [][][][]float64) {
	Qnew = utl.Deep4alloc(o.n[iAlong], o.n[jAlong], 1, 4)
	var i, j, k int
	for m := 0; m < o.n[iAlong]; m++ {
		for n := 0; n < o.n[jAlong]; n++ {
			switch {
			case iAlong == 0 && jAlong == 1:
				i, j, k = m, n, kAt
			case iAlong == 1 && jAlong == 2:
				i, j, k = kAt, m, n
			case iAlong == 2 && jAlong == 0:
				i, j, k = n, kAt, m
			default:
				chk.Panic("clone Q surface is specified by 'along' indices in (0,1) or (1,2) or (2,0). (%d,%d) is incorrect", iAlong, jAlong)
			}
			for e := 0; e < 4; e++ {
				Qnew[m][n][0][e] = o.Q[i][j][k][e]
			}
		}
	}
	return
}
Exemplo n.º 5
0
// SetControl sets control points from list of global vertices
func (o *Nurbs) SetControl(verts [][]float64, ctrls []int) {

	// check
	nctrl := o.n[0] * o.n[1] * o.n[2]
	if nctrl != len(ctrls) {
		chk.Panic("number of control points must be equal to %d. nctrl == %d is incorrect", nctrl, len(ctrls))
	}

	// set control points
	o.Q = utl.Deep4alloc(o.n[0], o.n[1], o.n[2], 4)
	for i := 0; i < o.n[0]; i++ {
		for j := 0; j < o.n[1]; j++ {
			for k := 0; k < o.n[2]; k++ {
				l := i + j*o.n[0] + k*o.n[0]*o.n[1]
				g := ctrls[l]
				for e := 0; e < 3; e++ {
					o.Q[i][j][k][e] = verts[g][e] * verts[g][3]
				}
				o.Q[i][j][k][3] = verts[g][3]
			}
		}
	}
}