Skip to content

Commit 29e3d89

Browse files
committed
switched from passing rotation angles to transformation matrix in draw stage model
1 parent e1e451a commit 29e3d89

4 files changed

Lines changed: 11 additions & 61 deletions

File tree

config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package rasterizer
22

3+
import "github.com/Patch2PDF/GDTF-Mesh-Reader/v2/pkg/MeshTypes"
4+
35
type RasterizerConfig struct {
46
CanvasConfig CanvasConfig
57
RenderLabels bool
6-
Rotation Rotation
8+
Rotation MeshTypes.Matrix
79
OverrideColors OverrideColorMap
810
}
911

examples/main.go

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"runtime/pprof"
1010

1111
GDTFMeshReader "github.com/Patch2PDF/GDTF-Mesh-Reader/v2"
12+
"github.com/Patch2PDF/GDTF-Mesh-Reader/v2/pkg/MeshTypes"
1213
MVRParser "github.com/Patch2PDF/MVR-Parser"
1314
MVRTypes "github.com/Patch2PDF/MVR-Parser/pkg/types"
1415
rasterizer "github.com/Patch2PDF/Stagemodel-Rasterizer"
@@ -43,14 +44,6 @@ func main() {
4344
}
4445
GDTFMeshReader.LoadPrimitives()
4546

46-
// content, err := gdtf.ParseGDTFByFilename("test.gdtf", true, false)
47-
// // content, err := gdtf.ParseGDTFByFilename("test3.gdtf", true, false)
48-
// if err != nil {
49-
// log.Fatalf("%s", err)
50-
// }
51-
// mesh, err := content.BuildMesh("32Ch")
52-
// // mesh, err := content.BuildMesh("36 channel")
53-
5447
mvr, err := zip.OpenReader("test5.mvr")
5548
if err != nil {
5649
log.Fatal(err)
@@ -87,13 +80,6 @@ func main() {
8780

8881
stage_model := mvrData.GetStageModel(model_config)
8982

90-
stageModelCopy1 := stage_model.Copy()
91-
stageModelCopy2 := stage_model.Copy()
92-
// TODO: instead of copy, rotate back? (multiply new matrix with inverse of previous) --> need to add function to Mesh-Reader module
93-
94-
// buf1 := &bytes.Buffer{}
95-
// buf2 := &bytes.Buffer{}
96-
9783
overrideColors := rasterizer.OverrideColorMap{
9884
// rasterizer.ModelTypeFixture: map[rasterizer.GeometryType]*color.NRGBA{
9985
// rasterizer.GeometryTypeAxis: {R: 255, G: 0, B: 0, A: 255},
@@ -109,29 +95,21 @@ func main() {
10995
LabelFontSize: 10,
11096
}
11197

112-
canvas1, err := rasterizer.Draw(&stageModelCopy1, rasterizer.RasterizerConfig{RenderLabels: true, Rotation: rasterizer.Rotation{Alpha: 80, Beta: 0, Gamma: 200}, OverrideColors: overrideColors, CanvasConfig: canvasConfig})
98+
rotation1 := MeshTypes.GenerateRotationMatrix(80, 0, 200)
99+
canvas1, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: false, Rotation: rotation1, OverrideColors: overrideColors, CanvasConfig: canvasConfig})
113100
if err != nil {
114101
log.Fatal(err)
115102
}
116-
// canvas1.SaveAsPNG(buf1)
103+
104+
rotation2 := MeshTypes.GenerateRotationMatrix(90, 0, 180)
105+
rotation2 = rotation2.ReverseTransformation(rotation1)
117106
rasterizer.SaveCanvasAsPNGFile("side.png", canvas1)
118-
canvas2, err := rasterizer.Draw(&stageModelCopy2, rasterizer.RasterizerConfig{RenderLabels: true, Rotation: rasterizer.Rotation{Alpha: 90, Beta: 0, Gamma: 180}, OverrideColors: overrideColors, CanvasConfig: canvasConfig})
107+
canvas2, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: true, Rotation: rotation2, OverrideColors: overrideColors, CanvasConfig: canvasConfig})
119108
if err != nil {
120109
log.Fatal(err)
121110
}
122-
// canvas2.SaveAsPNG(buf2)
123111
rasterizer.SaveCanvasAsPNGFile("front.png", canvas2)
124112

125-
// eg := errgroup.Group{}
126-
127-
// for range 2 {
128-
// eg.Go(func() error {
129-
// rasterizer.SaveCanvasAsPNGFile()
130-
// })
131-
// }
132-
133-
// wg.Wait()
134-
135113
pprof.StopCPUProfile()
136114

137115
runtime.GC() // Get up-to-date statistics
@@ -141,26 +119,3 @@ func main() {
141119

142120
f.Close()
143121
}
144-
145-
// func main() {
146-
// // fmt.Printf("%s", rasterizer.DrawLabel(0, 0))
147-
// // rasterizer.InitFace()
148-
149-
// // dst := image.NewNRGBA(image.Rect(0, 0, 110, 50))
150-
151-
// // fmt.Println(rasterizer.DrawLabelBox(dst, 0, 0, "Lgtm rtfm\nexcept you"))
152-
153-
// // f, err := os.Create("out.png")
154-
// // if err != nil {
155-
// // log.Fatalf("failed to create file: %v", err)
156-
// // }
157-
// // defer f.Close()
158-
159-
// // if err := png.Encode(f, dst); err != nil {
160-
// // log.Fatalf("failed to encode image: %v", err)
161-
// // }
162-
// err := rasterizer.DrawLabel(0, 0, "Lgtm rtfm\nexcept you")
163-
// if err != nil {
164-
// log.Fatal(err)
165-
// }
166-
// }

model_manipulation.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ func calculateStageModelMinAndMax(stageModel *StageModel) (min MeshTypes.Vector,
6969
return min, max
7070
}
7171

72-
func normalizeAndRotateStageModel(canvas *Canvas, stageModel *StageModel, rotation Rotation) {
72+
func normalizeAndRotateStageModel(canvas *Canvas, stageModel *StageModel, rotationMatrix MeshTypes.Matrix) {
7373
// rotate
74-
rotationMatrix := generateRotationMatrix(rotation.Alpha, rotation.Beta, rotation.Gamma)
7574
rotateAndTranslateStageModel(stageModel, rotationMatrix)
7675

7776
// get bounding box

rasterizer.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
MVRTypes "github.com/Patch2PDF/MVR-Parser/pkg/types"
1212
)
1313

14-
type Rotation struct {
15-
Alpha float64
16-
Beta float64
17-
Gamma float64
18-
}
19-
2014
type boundingBox struct {
2115
left int
2216
top int

0 commit comments

Comments
 (0)