data

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package data holds basic data structures and interfaces used by GoSlice.

Index

Constants

View Source
const MaxMicrometer = Micrometer(math.MaxInt64)
View Source
const MinMicrometer = Micrometer(math.MinInt64)

Variables

This section is empty.

Functions

func ToRadians

func ToRadians(angle float64) float64

Types

type BrimSkirtOptions

type BrimSkirtOptions struct {
	// SkirtCount is the amount of skirt lines around the initial layer.
	SkirtCount int

	// SkirtDistance is the distance between the model (or the most outer brim lines) and the most inner skirt line.
	SkirtDistance Millimeter

	// BrimCount specifies the amount of brim lines around the parts of the initial layer.
	BrimCount int
}

BrimSkirtOptions contains all options for the brim and skirt generation.

type Face

type Face interface {
	Points() [3]MicroVec3
}

Face represents a triangle face which is defined by three vectors.

type FanSpeedOptions

type FanSpeedOptions struct {
	LayerToSpeedLUT map[int]int
}

FanSpeedOptions used to control fan speed at given layers.

func NewDefaultFanSpeedOptions

func NewDefaultFanSpeedOptions() FanSpeedOptions

NewDefaultFanSpeedOptions Creates instance FanSpeedOptions and sets a of full fan (255) at layer 3.

func (*FanSpeedOptions) Set

func (f *FanSpeedOptions) Set(s string) error

Set takes string in format layerNo2=FanSpeed2,LayerNo2=FanSpeed2 Checks fan speed is within allowed range 0-255. Also confirms layer is at at least 0 or above.

func (FanSpeedOptions) String

func (f FanSpeedOptions) String() string

func (FanSpeedOptions) Type

func (f FanSpeedOptions) Type() string

type FilamentOptions

type FilamentOptions struct {
	// FilamentDiameter is the filament diameter used by the printer in micrometer.
	FilamentDiameter Micrometer

	// InitialBedTemperature is the temperature for the heated bed for the first layers.
	InitialBedTemperature int

	// InitialHotendTemperature is the temperature for the hot end for the first layers.
	InitialHotEndTemperature int

	// BedTemperature is the temperature for the heated bed after the first layers.
	BedTemperature int

	// HotEndTemperature is the temperature for the hot end after the first layers.
	HotEndTemperature int

	// InitialTemperatureLayerCount is the number of layers which use the initial temperatures.
	// After this amount of layers, the normal temperatures are used.
	InitialTemperatureLayerCount int

	// RetractionSpeed is the speed used for retraction in mm/s.
	RetractionSpeed Millimeter

	// RetractionLength is the amount to retract in millimeter.
	RetractionLength Millimeter

	// RetractionZHop is the amount to lift head when retracting in millimeter.
	RetractionZHop Millimeter

	// Primary (fan 0) speed, at given layers
	FanSpeed FanSpeedOptions

	// ExtrusionMultiplier is the multiplier in % used to change the amount of filament being extruded.
	ExtrusionMultiplier int
}

FilamentOptions contains all Filament specific GoSlice options.

type GCodeHunk added in v0.4.0

type GCodeHunk struct {
	GCodeLines []string
}

GCodeHunk stores a hunk of gcode as an array of strings.

func NewGCodeHunk added in v0.4.0

func NewGCodeHunk(rows []string) GCodeHunk

NewGCodeHunk instantiates a new GCodeHunk with the provided array of strings.

func (GCodeHunk) DoesInstructionContainCodes added in v0.4.0

func (gch GCodeHunk) DoesInstructionContainCodes(targetCodes []string) bool

DoesInstructionContainCodes looks at the codes retrieved from the provided gcodes strings and determines if the expected codes are contained in it. Check is for any, not all, and succeeds fast, ie. on first instance will return true.

func (GCodeHunk) GetInstructionCode added in v0.4.0

func (gch GCodeHunk) GetInstructionCode() []string

GetInstructionCode parses the provided strings for retrieve the first part of the line and creates an array of ones that are M or G codes.

func (*GCodeHunk) Set added in v0.4.0

func (gch *GCodeHunk) Set(s string) error

Set is used by pflag to set the value based on the command line input

func (GCodeHunk) String added in v0.4.0

func (gch GCodeHunk) String() string

String is used by pflag to show example based on default settings

func (GCodeHunk) Type added in v0.4.0

func (gch GCodeHunk) Type() string

Type is used by pflag for building the help text

type GoSliceOptions

type GoSliceOptions struct {
	// PrintVersion indicates if the GoSlice version should be printed.
	PrintVersion bool

	// InputFilePath specifies the path to the input stl file.
	InputFilePath string

	// OutputFilePath specifies the path to the output gcode file.
	OutputFilePath string

	// Logger can be used to redirect the log output to anything you want.
	// All output in GoSlice just calls this logger.
	Logger *log.Logger
}

GoSliceOptions contains all options related to GoSlice itself.

type Layer

type Layer interface {
	Polygons() Paths
}

Layer represents one layer which can consist of several polygons. These polygons can consist of several paths, with some of them just representing holes. Holes have to be clockwise and outlines counter clockwise.

type LayerPart

type LayerPart interface {
	Outline() Path
	Holes() Paths

	// Attributes can be any additional data, referenced by a key.
	// Note that you have to know what type the attribute has to
	// use proper type assertion.
	//
	// If the implementation does not support attributes, it should return nil.
	// If the implementation supports attributes but doesn't have any, it should return an empty map.
	Attributes() map[string]interface{}
}

LayerPart represents one part of a layer. It consists of an outline and may have several holes Some implementations may also provide Attributes for it.

func NewBasicLayerPart

func NewBasicLayerPart(outline Path, holes Paths) LayerPart

NewBasicLayerPart returns a new, simple LayerPart.

type MicroPoint

type MicroPoint interface {
	X() Micrometer
	Y() Micrometer

	SetX(x Micrometer)
	SetY(y Micrometer)

	// Add returns a new vector which is the sum of the vectors. (this + vec)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Add(vec MicroPoint) MicroPoint

	// Sub returns a new vector which is the difference of the vectors. (this - vec)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Sub(vec MicroPoint) MicroPoint

	// Mul returns a new vector which is the multiplication by the given value. (this * value)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Mul(value Micrometer) MicroPoint

	// Div returns a new vector which is the division by the given value. (this / value)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Div(value Micrometer) MicroPoint

	// Rotate returns a new vector which is rotated around (0|0) by the given degree value.
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Rotate(degree float64) MicroPoint

	// ShorterThanOrEqual checks if the length of the vector fits inside the given length.
	// Returns true if the vector length is <= the given length.
	ShorterThanOrEqual(length Micrometer) bool

	// Size2 returns the length of the vector^2.
	//
	// Use this whenever possible as it may be faster than Size().
	Size2() Micrometer

	// Size2 returns the length of the vector.
	//
	// Use Size2() whenever possible as it may be faster than Size().
	Size() Micrometer

	// SizeMM returns the length of the vector in mm.
	SizeMM() Millimeter

	// Copy returns a completely new copy of the vector.
	Copy() MicroPoint
}

MicroPoint represents a point in 2d space which is in a 1 micrometer sized grid.

func NewMicroPoint

func NewMicroPoint(x, y Micrometer) MicroPoint

type MicroVec3

type MicroVec3 interface {
	X() Micrometer
	Y() Micrometer
	Z() Micrometer

	SetX(x Micrometer)
	SetY(y Micrometer)
	SetZ(z Micrometer)

	// PointXY returns a new point only with the x and y coordinates of the vector.
	PointXY() MicroPoint

	// Add returns a new vector which is the sum of the vectors. (this + vec)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Add(vec MicroVec3) MicroVec3

	// Sub returns a new vector which is the difference of the vectors. (this - vec)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Sub(vec MicroVec3) MicroVec3

	// Mul returns a new vector which is the multiplication by the given value. (this * value)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Mul(value Micrometer) MicroVec3

	// Div returns a new vector which is the division by the given value. (this / value)
	//
	// By convention it should never mutate the instance and instead return a new copy.
	Div(value Micrometer) MicroVec3

	Max() Micrometer

	// ShorterThanOrEqual checks if the length of the vector fits inside the given length.
	// Returns true if the vector length is <= the given length.
	ShorterThanOrEqual(length Micrometer) bool

	// Size2 returns the length of the vector^2.
	//
	// Use this whenever possible as it may be faster than Size().
	Size2() Micrometer

	// Size2 returns the length of the vector.
	//
	// Use Size2() this whenever possible as it may be faster than Size().
	Size() Micrometer

	// Copy returns a completely new copy of the vector.
	Copy() MicroVec3

	// String implements the value interface needed for the options.
	String() string
	// Set implements the value interface needed for the options.
	Set(s string) error
	// Type implements the value interface needed for the options.
	Type() string
}

MicroVec3 represents a point in 3d space which is in a Micrometer-grid. A value of 1 represents 0.001 mm. Micro vectors are used as soon as possible to avoid rounding errors because the Micrometer datatype uses integers.

func NewMicroVec3

func NewMicroVec3(x Micrometer, y Micrometer, z Micrometer) MicroVec3

NewMicroVec3 returns a new vector in 3D space which is in a 1 micrometer sized grid.

type Micrometer

type Micrometer int64

Micrometer represents a value in 0.001 mm

func DotProduct

func DotProduct(a, b MicroPoint) Micrometer

DotProduct calculates the dot product of two points

func Max

func Max(a, b Micrometer) Micrometer

func Min

func Min(a, b Micrometer) Micrometer

func PerpendicularDistance2

func PerpendicularDistance2(a, b, point MicroPoint) Micrometer

PerpendicularDistance2 calculates the (perpendicular Distance)^2 of a point to a line

func (*Micrometer) Set

func (m *Micrometer) Set(s string) error

func (Micrometer) String

func (m Micrometer) String() string

func (Micrometer) ToMillimeter

func (m Micrometer) ToMillimeter() Millimeter

func (Micrometer) Type

func (m Micrometer) Type() string

type Millimeter

type Millimeter float32

Millimeter represents a value in mm It should not be used for calculations, convert to micrometer. using ToMicrometer() before calculating to prevent rounding errors because of the float-type.

func (*Millimeter) Set

func (m *Millimeter) Set(s string) error

func (Millimeter) String

func (m Millimeter) String() string

func (Millimeter) ToMicrometer

func (m Millimeter) ToMicrometer() Micrometer

func (Millimeter) Type

func (m Millimeter) Type() string

type Model

type Model interface {
	FaceCount() int
	Face(index int) Face
	Min() MicroVec3
	Max() MicroVec3
}

Model represents a full model.

type OptimizedFace

type OptimizedFace interface {
	Face
	TouchingFaceIndices() [3]int
	MinZ() Micrometer
	MaxZ() Micrometer
}

OptimizedFace represents a full but optimized face. It additionally provides indices of touching faces. The corresponding other faces can be found in a matching OptimizedModelInstance. So you always need an OptimizedModel instance.

type OptimizedModel

type OptimizedModel interface {
	Model

	// Bounds returns the amount of faces.
	Size() MicroVec3

	OptimizedFace(index int) OptimizedFace
	SaveDebugSTL(filename string) error
}

OptimizedModel represents a full but optimized model. Each face contains the the indices of touching faces.

type Options

type Options struct {
	Slicing  SlicingOptions
	Printer  PrinterOptions
	Filament FilamentOptions
	Print    PrintOptions
	GoSlice  GoSliceOptions
}

Options contains all GoSlice options.

func DefaultOptions

func DefaultOptions() Options

func ParseFlags

func ParseFlags() Options

ParseFlags parses the command line flags. It returns the default options but sets all passed options.

func (Options) SetHasHeatedBed added in v0.4.0

func (o Options) SetHasHeatedBed(val bool) Options

type PartitionedLayer

type PartitionedLayer interface {
	LayerParts() []LayerPart

	// Attributes can be any additional data, referenced by a key.
	// Note that you have to know what type the attribute has to
	// use proper type assertion.
	//
	// If the implementation does not support attributes, it should return nil.
	// If the implementation supports attributes but doesn't have ane, it should return an empty map.
	Attributes() map[string]interface{}

	// Bounds returns the min and max Points which specify the bounding box.
	Bounds() (MicroPoint, MicroPoint)
}

PartitionedLayer represents one layer with separated layer parts. In contrast to the interface Layer this one contains already processed polygons in the form of LayerParts.

func NewPartitionedLayer

func NewPartitionedLayer(parts []LayerPart) PartitionedLayer

NewPartitionedLayer returns a new simple PartitionedLayer which just contains several LayerParts.

type Path

type Path []MicroPoint

Path is a simple list of points. It can be used to represent polygons (if they are closed) or just lines.

func DouglasPeucker

func DouglasPeucker(points Path, epsilon Micrometer) Path

DouglasPeucker is an algorithm for simplifying / smoothing polygons by removing some points. see https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm

func (Path) Bounds

func (p Path) Bounds() (MicroPoint, MicroPoint)

Bounds calculates the bounding box of the Path The returned points are the min-X-Y-Point and the max-X-Y-Point.

func (Path) IsAlmostFinished

func (p Path) IsAlmostFinished(distance Micrometer) bool

IsAlmostFinished returns true if the path represents an almost closed polygon. It checks if the distance between the first and last point is smaller than the given threshold distance.

func (Path) Len

func (p Path) Len() int

func (Path) Rotate

func (p Path) Rotate(degree float64)

Rotate rotates all points around (0|0) by the given degree.

func (Path) Simplify

func (p Path) Simplify(smallestLineSegmentSquared, allowedErrorDistanceSquared Micrometer) Path

Simplify removes consecutive line segments with same orientation and changes this polygon. If a parameter is -1 a default value is used.

Removes verts which are connected to line segments which are both too small. Removes verts which detour from a direct line from the previous and next vert by a too small amount.

Criteria: 1. Never remove a vertex if either of the connected segments is larger than \p smallest_line_segment 2. Never remove a vertex if the distance between that vertex and the final resulting polygon would be higher than \p allowed_error_distance 3. Simplify uses a heuristic and doesn't necessarily remove all removable vertices under the above criteria. 4. But simplify may never violate these criteria. 5. Unless the segments or the distance is smaller than the rounding error of 5 micron

smallestLineSegmentSquared is the maximal squared length of removed line segments allowedErrorDistanceSquared is the square of the distance of the middle point to the line segment of the consecutive and previous point for which the middle point is removed

Note: this is directly ported from a newer CuraEngine version.

func (Path) Slice

func (p Path) Slice(i, j int) go_convex_hull_2d.Interface

func (Path) Swap

func (p Path) Swap(i, j int)

func (Path) Take

func (p Path) Take(i int) (x, y float64)

type Paths

type Paths []Path

Paths represents a group of Paths.

func (Paths) Bounds

func (p Paths) Bounds() (MicroPoint, MicroPoint)

Bounds calculates the bounding box of all Paths The returned points are the min-X-Y-Point and the max-X-Y-Point.

func (Paths) Rotate

func (p Paths) Rotate(degree float64)

Rotate rotates all points around (0|0) by the given degree.

type PrintOptions

type PrintOptions struct {
	// InitialLayerSpeed is the speed only for the first layer in mm per second.
	IntialLayerSpeed Millimeter

	// LayerSpeed is the speed for all but the first layer in mm per second.
	LayerSpeed Millimeter

	// OuterPerimeterSpeed is the speed only for outer perimeters in mm per second.
	OuterPerimeterSpeed Millimeter

	// MoveSpeed is the speed for all non printing moves in mm per second.
	MoveSpeed Millimeter

	// InitialLayerThickness is the layer thickness for the first layer.
	InitialLayerThickness Micrometer

	// LayerThickness is the thickness for all but the first layer.
	LayerThickness Micrometer

	// InsetCount is the number of perimeters.
	InsetCount int

	// InfillOverlapPercent is the percentage of overlap into the perimeters.
	InfillOverlapPercent int

	// AdditionalInternalInfillOverlapPercent is the percentage used to make the internal
	// infill (infill not blocked by the perimeters) even bigger so that it grows a bit into the model.
	AdditionalInternalInfillOverlapPercent int

	// InfillPercent is the amount of infill which should be generated.
	InfillPercent int

	// InfillRotationDegree is the rotation used for the infill.
	InfillRotationDegree int

	// InfillZigZig sets if the infill should use connected lines in zig zag form.
	InfillZigZag bool

	// NumberBottomLayers is the amount of layers the bottom layers should grow into the model.
	NumberBottomLayers int

	// NumberBottomLayers is the amount of layers the bottom layers should grow into the model.
	NumberTopLayers int

	Support SupportOptions

	BrimSkirt BrimSkirtOptions
}

PrintOptions contains all Print specific GoSlice options.

type PrinterOptions

type PrinterOptions struct {
	// ExtrusionWidth is the diameter of your nozzle.
	ExtrusionWidth Micrometer

	// Center is the point where the model is finally placed.
	Center MicroVec3

	// ForceSafeStartStopGCode toggles enforcing setting temps at beginning/end of print.
	ForceSafeStartStopGCode bool

	// HasHeatedBed toggles whether to add bed temperature settings to gcode.
	HasHeatedBed bool

	// StartGCode contains an array of strings to prepend the generated gcode.
	StartGCode GCodeHunk

	// EndGCode contains an array of strings to postpend the genreated gcode.
	EndGCode GCodeHunk
}

PrinterOptions contains all Printer specific GoSlice options.

type SlicingOptions

type SlicingOptions struct {
	// MeldDistance is the distance which two points have to be
	// within to count them as one point.
	MeldDistance Micrometer

	// JoinPolygonSnapDistance is the distance used to check if two open
	// polygons can be snapped together to one bigger polygon.
	// Checked by the start and endpoints of the polygons.
	JoinPolygonSnapDistance Micrometer

	// FinishPolygonSnapDistance is the max distance between start end endpoint of
	// a polygon used to check if a open polygon can be closed.
	FinishPolygonSnapDistance Micrometer
}

SlicingOptions contains all options related to slice a model.

type SupportOptions

type SupportOptions struct {
	// Enabled enables the generation of support structures.
	Enabled bool

	// ThresholdAngle is the angle up to which no support is generated.
	ThresholdAngle int

	// TopGapLayers is the amount of layers without support.
	TopGapLayers int

	// InterfaceLayers is the amount of layers which are filled differently as interface to the object.
	InterfaceLayers int

	// PatternSpacing is the spacing used to create the support pattern.
	PatternSpacing Millimeter

	// Gap is the gap between the model and the support.
	Gap Millimeter
}

SupportOptions contains all Support specific GoSlice options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL