Skip to content

Commit

Permalink
cmd: Allow decimate to operate on both bottom and normal layers at once
Browse files Browse the repository at this point in the history
Summary:
- Fixes #87
  • Loading branch information
ezrec committed Jul 18, 2020
1 parent f9a4b85 commit b650518
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ The command line tool is designed to be used in a 'pipeline' style, for example:

Options for 'decimate':

-b, --bottom Decimate bottom layers only
-n, --normal Decimate normal layers only
-p, --passes int Number of decimation passes (default 1)
-b, --bottom int Number of bottom layer passes
-n, --normal int Number of normal layer passes (default 1)

Options for 'exposure':

Expand Down
40 changes: 18 additions & 22 deletions cmd/uv3dp/decimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
package main

import (
"fmt"

"github.com/spf13/pflag"

"github.com/ezrec/uv3dp"
"github.com/spf13/pflag"
)

type DecimateCommand struct {
*pflag.FlagSet

Passes int
Bottom bool
Normal bool
Bottom int
Normal int
}

func NewDecimateCommand() (cmd *DecimateCommand) {
Expand All @@ -28,39 +24,39 @@ func NewDecimateCommand() (cmd *DecimateCommand) {
FlagSet: flagSet,
}

cmd.BoolVarP(&cmd.Bottom, "bottom", "b", false, "Decimate bottom layers only")
cmd.BoolVarP(&cmd.Normal, "normal", "n", false, "Decimate normal layers only")
cmd.IntVarP(&cmd.Passes, "passes", "p", 1, "Number of decimation passes")
cmd.IntVarP(&cmd.Bottom, "bottom", "b", 0, "Number of bottom layer passes")
cmd.IntVarP(&cmd.Normal, "normal", "n", 1, "Number of normal layer passes")

cmd.SetInterspersed(false)

return
}

func (cmd *DecimateCommand) Filter(input uv3dp.Printable) (output uv3dp.Printable, err error) {
if cmd.Bottom && cmd.Normal {
err = fmt.Errorf("only one of --bottom and --normal may be selected")
return
}

dec := uv3dp.NewDecimatedPrintable(input)

dec.Passes = cmd.Passes

layers := input.Properties().Size.Layers
botCount := input.Properties().Bottom.Count

if cmd.Bottom {
if cmd.Bottom > 0 {
dec := uv3dp.NewDecimatedPrintable(input)

dec.Passes = cmd.Bottom
dec.FirstLayer = 0
dec.Layers = botCount

input = dec
}

if cmd.Normal {
if cmd.Normal > 0 {
dec := uv3dp.NewDecimatedPrintable(input)

dec.Passes = cmd.Normal
dec.FirstLayer = botCount
dec.Layers = layers - botCount

input = dec
}

output = dec
output = input

return
}

0 comments on commit b650518

Please sign in to comment.