コード例 #1
0
ファイル: govtk.go プロジェクト: PatrickSchm/gosl
// Run shows Scene in interactive mode or saving a .png file
func (o *Scene) Run() (err error) {

	// input data
	axeslen := (C.double)(o.AxesLen)
	hydroline := (C.long)(b2i(o.HydroLine))
	reverse := (C.long)(b2i(o.Reverse))
	fullaxes := (C.long)(b2i(o.FullAxes))
	withplanes := (C.long)(b2i(o.WithPlanes))
	interact := (C.long)(b2i(o.Interact))
	saveonexit := (C.long)(b2i(o.SaveOnExit))
	fnk := C.CString(o.Fnk)
	defer C.free(unsafe.Pointer(fnk))

	// connect Go and C
	GOVTK_X = make([]float64, 3)
	C.GOVTK_F = (*C.double)(unsafe.Pointer(&GOVTK_F))
	C.GOVTK_VX = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_VY = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_VZ = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_X = (*C.double)(unsafe.Pointer(&GOVTK_X[0]))
	C.GOVTK_I = (*C.long)(unsafe.Pointer(&GOVTK_I))

	// alloc win
	o.win = C.win_alloc(reverse)
	defer C.win_dealloc(o.win)
	if o.win == nil {
		return chk.Err("C.scene_begin failed\n")
	}

	// arrows
	for _, O := range o.arrows {
		x0 := (*C.double)(unsafe.Pointer(&O.X0[0]))
		v := (*C.double)(unsafe.Pointer(&O.V[0]))
		cone_pct := (C.double)(O.ConePct)
		cone_rad := (C.double)(O.ConeRad)
		cyli_rad := (C.double)(O.CyliRad)
		resolution := (C.long)(O.Resolution)
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		O.arr = C.arrow_addto(o.win, x0, v, cone_pct, cone_rad, cyli_rad, resolution, color)
		defer C.arrow_dealloc(O.arr)
	}

	// spheres
	for _, O := range o.spheres {
		cen := (*C.double)(unsafe.Pointer(&O.Cen[0]))
		r := (C.double)(O.R)
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		O.sph = C.sphere_addto(o.win, cen, r, color)
		defer C.sphere_dealloc(O.sph)
	}

	// isosurfs
	for _, O := range o.isosurfs {

		// input data
		limits := (*C.double)(unsafe.Pointer(&O.Limits[0]))
		ndiv := (*C.long)(unsafe.Pointer(&O.Ndiv[0]))
		frange := (*C.double)(unsafe.Pointer(&O.Frange[0]))
		octrotate := (C.long)(b2i(O.OctRotate))
		nlevels := (C.long)(O.Nlevels)
		cmaptype := C.CString(O.CmapType)
		cmapnclrs := (C.long)(O.CmapNclrs)
		cmaprangetype := (C.long)(O.CmapRangeType)
		cmapfrange := (*C.double)(unsafe.Pointer(&O.CmapFrange[0]))
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		showwire := (C.long)(b2i(O.ShowWire))
		gridshowpts := (C.long)(b2i(O.GridShowPts))
		defer C.free(unsafe.Pointer(cmaptype))

		// connect Go and C
		idx := len(GOVTK_FCN)
		GOVTK_FCN = append(GOVTK_FCN, O.fcn)

		// call C routine: add isosurf
		index := (C.long)(idx)
		O.isf = C.isosurf_addto(o.win, index, limits, ndiv, frange, octrotate, nlevels, cmaptype, cmapnclrs, cmaprangetype, cmapfrange, color, showwire, gridshowpts)
		defer C.isosurf_dealloc(O.isf)
	}

	// call C routine: end
	status := C.scene_run(o.win, axeslen, hydroline, reverse, fullaxes, withplanes, interact, saveonexit, fnk)
	if status != 0 {
		return chk.Err("C.scene_end failed\n")
	}
	return
}
コード例 #2
0
ファイル: govtk.go プロジェクト: yunpeng1/gosl
// Run shows Scene in interactive mode or saving a .png file
func (o *Scene) Run() (err error) {

	// input data
	axeslen := (C.double)(o.AxesLen)
	hydroline := (C.long)(b2i(o.HydroLine))
	reverse := (C.long)(b2i(o.Reverse))
	fullaxes := (C.long)(b2i(o.FullAxes))
	withplanes := (C.long)(b2i(o.WithPlanes))
	interact := (C.long)(b2i(o.Interact))
	saveeps := (C.long)(b2i(o.SaveEps))
	savepng := (C.long)(b2i(o.SavePng))
	pngmag := (C.long)(o.PngMag)
	fnk := C.CString(o.Fnk)
	defer C.free(unsafe.Pointer(fnk))

	// connect Go and C
	GOVTK_X = make([]float64, 3)
	C.GOVTK_F = (*C.double)(unsafe.Pointer(&GOVTK_F))
	C.GOVTK_VX = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_VY = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_VZ = (*C.double)(unsafe.Pointer(&GOVTK_VX))
	C.GOVTK_X = (*C.double)(unsafe.Pointer(&GOVTK_X[0]))
	C.GOVTK_I = (*C.long)(unsafe.Pointer(&GOVTK_I))

	// alloc win
	o.win = C.win_alloc(reverse)
	defer C.win_dealloc(o.win)
	if o.win == nil {
		return chk.Err("C.scene_begin failed\n")
	}

	// arrows
	for _, O := range o.arrows {
		x0 := (*C.double)(unsafe.Pointer(&O.X0[0]))
		v := (*C.double)(unsafe.Pointer(&O.V[0]))
		cone_pct := (C.double)(O.ConePct)
		cone_rad := (C.double)(O.ConeRad)
		cyli_rad := (C.double)(O.CyliRad)
		resolution := (C.long)(O.Resolution)
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		O.arr = C.arrow_addto(o.win, x0, v, cone_pct, cone_rad, cyli_rad, resolution, color)
		defer C.arrow_dealloc(O.arr)
	}

	// spheres
	for _, O := range o.spheres {
		cen := (*C.double)(unsafe.Pointer(&O.Cen[0]))
		r := (C.double)(O.R)
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		O.sph = C.sphere_addto(o.win, cen, r, color)
		defer C.sphere_dealloc(O.sph)
	}

	// spheres set
	for _, O := range o.spheresSet {
		n := len(O.X)
		if n < 1 {
			continue
		}
		if len(O.Y) != n || len(O.Z) != n || len(O.R) != n {
			return chk.Err("cannot add set of spheres because X,Y,Z,R have different dimensions")
		}
		x := (*C.double)(unsafe.Pointer(&O.X[0]))
		y := (*C.double)(unsafe.Pointer(&O.Y[0]))
		z := (*C.double)(unsafe.Pointer(&O.Z[0]))
		r := (*C.double)(unsafe.Pointer(&O.R[0]))
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		O.sset = C.spheres_addto(o.win, (C.long)(n), x, y, z, r, color)
		defer C.spheres_dealloc(O.sset)
	}

	// isosurfs
	for _, O := range o.isosurfs {

		// input data
		limits := (*C.double)(unsafe.Pointer(&O.Limits[0]))
		ndiv := (*C.long)(unsafe.Pointer(&O.Ndiv[0]))
		frange := (*C.double)(unsafe.Pointer(&O.Frange[0]))
		octrotate := (C.long)(b2i(O.OctRotate))
		nlevels := (C.long)(O.Nlevels)
		cmaptype := C.CString(O.CmapType)
		cmapnclrs := (C.long)(O.CmapNclrs)
		cmaprangetype := (C.long)(O.CmapRangeType)
		cmapfrange := (*C.double)(unsafe.Pointer(&O.CmapFrange[0]))
		color := (*C.double)(unsafe.Pointer(&O.Color[0]))
		showwire := (C.long)(b2i(O.ShowWire))
		gridshowpts := (C.long)(b2i(O.GridShowPts))
		defer C.free(unsafe.Pointer(cmaptype))

		// connect Go and C
		idx := len(GOVTK_FCN)
		GOVTK_FCN = append(GOVTK_FCN, O.fcn)

		// call C routine: add isosurf
		index := (C.long)(idx)
		O.isf = C.isosurf_addto(o.win, index, limits, ndiv, frange, octrotate, nlevels, cmaptype, cmapnclrs, cmaprangetype, cmapfrange, color, showwire, gridshowpts)
		defer C.isosurf_dealloc(O.isf)
	}

	// labels
	if o.LblX == "" {
		o.LblX = "X"
	}
	if o.LblY == "" {
		o.LblY = "Y"
	}
	if o.LblZ == "" {
		o.LblZ = "Z"
	}
	lblX := C.CString(o.LblX)
	defer C.free(unsafe.Pointer(lblX))
	lblY := C.CString(o.LblY)
	defer C.free(unsafe.Pointer(lblY))
	lblZ := C.CString(o.LblZ)
	defer C.free(unsafe.Pointer(lblZ))
	lblSz := (C.long)(o.LblSz)
	lblClr := (*C.double)(unsafe.Pointer(&o.LblClr))

	// call C routine: end
	status := C.scene_run(o.win, axeslen, hydroline, reverse, fullaxes, withplanes, interact, saveeps, savepng, pngmag, fnk, lblX, lblY, lblZ, lblSz, lblClr)
	if status != 0 {
		return chk.Err("C.scene_end failed\n")
	}
	if savepng > 0 {
		io.Pfblue2("file <%s.png> written\n", o.Fnk)
	}
	if saveeps > 0 {
		io.Pfblue2("file <%s.eps> written\n", o.Fnk)
	}
	return
}