Skip to content

Commit

Permalink
properties.go: Add a 'LayerZ()' function to get the (rounded) layer h…
Browse files Browse the repository at this point in the history
…eight

Summary:
- Fixes #85
  • Loading branch information
ezrec committed Jul 14, 2020
1 parent 3ed1e92 commit f9a4b85
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cws/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (cws *CWS) Layer(index int) (layer uv3dp.Layer) {
panic(err)
}

layer.Z = float32(index) * cws.properties.Size.LayerHeight
layer.Z = cws.properties.LayerZ(index)
layer.Image = pngImage.(*image.Gray)
layer.Exposure = cws.properties.LayerExposure(index)

Expand Down
2 changes: 1 addition & 1 deletion empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (empty *EmptyPrintable) Properties() (prop Properties) {
func (empty *EmptyPrintable) Layer(index int) (layer Layer) {
prop := empty.Properties()

layer.Z = prop.Size.LayerHeight * float32(index)
layer.Z = prop.LayerZ(index)
layer.Image = image.NewGray(prop.Bounds())

if index < prop.Bottom.Count {
Expand Down
6 changes: 6 additions & 0 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package uv3dp

import (
"image"
"math"
)

type SizeMillimeter struct {
Expand Down Expand Up @@ -118,3 +119,8 @@ func (prop *Properties) LayerExposure(index int) (exposure Exposure) {

return
}

// LayerZ get the default Z height at a layer index
func (prop *Properties) LayerZ(index int) (z float32) {
return float32(math.Round(float64(prop.Size.LayerHeight)*float64(index+1)*100) / 100.0)
}
2 changes: 1 addition & 1 deletion pws/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func (pws *Print) Layer(index int) (layer uv3dp.Layer) {
panic(fmt.Sprintf("pws: layer %v/%v: %s", index+1, prop.Size.Layers, err))
}

layer.Z = float32(index) * prop.Size.LayerHeight
layer.Z = prop.LayerZ(index)
layer.Image = slice
return
}
2 changes: 1 addition & 1 deletion sl1/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (sl1 *Sl1) Layer(index int) (layer uv3dp.Layer) {
panic(err)
}

layer.Z = float32(index) * sl1.properties.Size.LayerHeight
layer.Z = sl1.properties.LayerZ(index)
layer.Image = pngImage.(*image.Gray)
layer.Exposure = sl1.properties.LayerExposure(index)

Expand Down
2 changes: 1 addition & 1 deletion uvj/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (uvj *UVJ) Layer(index int) (layer uv3dp.Layer) {

if len(uvj.Config.Layers) == 0 {
layer = uv3dp.Layer{
Z: float32(index) * uvj.Config.Properties.Size.LayerHeight,
Z: uvj.Config.Properties.LayerZ(index),
Exposure: uvj.Config.Properties.LayerExposure(index),
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions uvj/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const (
},
"Layers": [
{
"Z": 0,
"Z": 0.05,
"Exposure": {
"LightOnTime": 30.5,
"LightOffTime": 2.25,
Expand All @@ -119,7 +119,7 @@ const (
}
},
{
"Z": 0.05,
"Z": 0.1,
"Exposure": {
"LightOnTime": 30.5,
"LightOffTime": 2.25,
Expand All @@ -130,7 +130,7 @@ const (
}
},
{
"Z": 0.1,
"Z": 0.15,
"Exposure": {
"LightOnTime": 16.5,
"LightOffTime": 2.25,
Expand All @@ -142,7 +142,7 @@ const (
}
},
{
"Z": 0.15,
"Z": 0.2,
"Exposure": {
"LightOnTime": 16.5,
"LightOffTime": 2.25,
Expand Down
2 changes: 1 addition & 1 deletion zcodex/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func (zcodex *Zcodex) Layer(index int) (layer uv3dp.Layer) {
grayImage = asGray(pngImage)
}

layer.Z = float32(index) * zcodex.properties.Size.LayerHeight
layer.Z = zcodex.properties.LayerZ(index)
layer.Image = grayImage
layer.Exposure = zcodex.properties.LayerExposure(index)

Expand Down

0 comments on commit f9a4b85

Please sign in to comment.