示例#1
0
func Test_SimpleExample(t *testing.T) {

	Convey("Simple Example", t, func() {

		pipe := DefaultFilePipe()

		/* use a custom unique generator with a prefix for the light handles */
		lights := NewPrefixLightUniqueGenerator("light_")

		mgr := NewHandleManager(nil, lights, nil)

		ctx := NewContext(pipe, mgr, &Configuration{PrettyPrint: true})
		ri := RI(ctx)
		ri.Begin("output/exampleSimple.rib")
		ri.Display("sphere.tif", "file", "rgb")
		ri.Format(320, 240, 1)
		ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30))
		ri.Translate(0, 0, 6)
		ri.WorldBegin()
		ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5))
		ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0})
		ri.Color(RtColor{1, 0, 0})
		ri.Sphere(1, -1, 1, 360)
		ri.WorldEnd()

		So(ri.End(), ShouldBeNil)

		/* output gathered stats */
		p := pipe.GetByName(PipeToStats{}.Name())
		So(p, ShouldNotBeNil)
		s, ok := p.(*PipeToStats)
		So(s, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		p = pipe.GetByName(PipeTimer{}.Name())
		So(p, ShouldNotBeNil)
		t, ok := p.(*PipeTimer)
		So(t, ShouldNotBeNil)
		So(ok, ShouldBeTrue)

		fmt.Printf("%s%s", s, t)
	})

	Convey("Simple Example Flattened", t, func() {

		pipe := DefaultFilePipe()

		ctx := NewContext(pipe, nil, &Configuration{PrettyPrint: false})
		ri := RI(ctx)
		ri.Begin("output/exampleSimpleFlattened.rib")

		f, err := os.Open("output/exampleSimple.rib")
		So(err, ShouldBeNil)
		defer f.Close()
		So(ri.ParseRIB(f), ShouldBeNil)
		ri.End()
	})
}
示例#2
0
/* go test -bench=. */
func Benchmark_SimpleExampleNumberHandlers(b *testing.B) {

	for i := 0; i < b.N; i++ {
		ri, _ := DefaultPipeline(nil)
		ri.Begin("simple.rib")
		ri.Display("sphere.tif", "file", "rgb")
		ri.Format(320, 240, 1)
		ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30))
		ri.Translate(0, 0, 6)
		ri.WorldBegin()
		ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5))
		ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0})
		ri.Color(RtColor{1, 0, 0})
		ri.Sphere(1, -1, 1, 360)
		ri.WorldEnd()
		ri.End()
	}
}
示例#3
0
func Test_HandleCallbacks(t *testing.T) {

	lighthandle := func(name RtName, light RtLightHandle) {

		fmt.Printf("LightHandle -- %s %s\n", name, light)
	}

	Convey("Handle callbacks pipelining", t, func() {

		pipe := NewPipe()
		callback := new(PipeHookHandleCallback)
		callback.LightHandler = lighthandle

		pipe.Append(callback)

		mgr := NewHandleManager(nil, NewPrefixLightUniqueGenerator("light_"), nil)

		ri := RI(NewContext(pipe, mgr, nil))

		So(ri.Begin("output/filters-simple.rib"), ShouldBeNil)
		ri.Display("sphere.tif", "file", "rgb")
		ri.Format(320, 240, 1)
		ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30))
		ri.Translate(0, 0, 6)
		ri.WorldBegin()

		ambient, _ := ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5))
		So(ambient, ShouldNotBeNil)

		ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0})
		ri.Illuminate(ambient, false)
		ri.Color(RtColor{1, 0, 0})
		ri.Sphere(1, -1, 1, 360)

		ri.WorldEnd()
		So(ri.End(), ShouldBeNil)

	})
}
示例#4
0
func Benchmark_SimpleExampleUniqueHandlers(b *testing.B) {

	for i := 0; i < b.N; i++ {
		pipe := NullPipe()
		mgr := NewHandleManager(nil, NewLightUniqueGenerator(), nil)

		ctx := NewContext(pipe, mgr, nil)
		ri := RI(ctx)
		ri.Begin("simple.rib")
		ri.Display("sphere.tif", "file", "rgb")
		ri.Format(320, 240, 1)
		ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30))
		ri.Translate(0, 0, 6)
		ri.WorldBegin()
		ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5))
		ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0})
		ri.Color(RtColor{1, 0, 0})
		ri.Sphere(1, -1, 1, 360)
		ri.WorldEnd()
		ri.End()
	}
}