Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibLaserCut
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Elektronikföreningen Admittansen
LibLaserCut
Commits
3cd0a662
Commit
3cd0a662
authored
12 years ago
by
Thomas Oster
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' into feature/dpi
parents
de2a8367
49955deb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/com/t_oster/liblasercut/utils/VectorOptimizer.java
+152
-0
152 additions, 0 deletions
src/com/t_oster/liblasercut/utils/VectorOptimizer.java
with
152 additions
and
0 deletions
src/com/t_oster/liblasercut/utils/VectorOptimizer.java
0 → 100644
+
152
−
0
View file @
3cd0a662
package
com.t_oster.liblasercut.utils
;
import
com.t_oster.liblasercut.LaserProperty
;
import
com.t_oster.liblasercut.VectorCommand
;
import
com.t_oster.liblasercut.VectorPart
;
import
com.t_oster.liblasercut.platform.Point
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public
class
VectorOptimizer
{
public
enum
OrderStrategy
{
FILE
,
//INNER_FIRST,
NEAREST
}
class
Element
{
LaserProperty
prop
;
Point
start
;
List
<
Point
>
moves
=
new
LinkedList
<
Point
>();
Point
getEnd
()
{
return
moves
.
isEmpty
()
?
start
:
moves
.
get
(
moves
.
size
()-
1
);
}
}
private
OrderStrategy
strategy
=
OrderStrategy
.
FILE
;
public
VectorOptimizer
(
OrderStrategy
s
)
{
this
.
strategy
=
s
;
}
private
List
<
Element
>
divide
(
VectorPart
vp
)
{
List
<
Element
>
result
=
new
LinkedList
<
Element
>();
Element
cur
=
null
;
Point
lastMove
=
null
;
LaserProperty
lastProp
=
null
;
boolean
stop
=
false
;
for
(
VectorCommand
cmd
:
vp
.
getCommandList
())
{
switch
(
cmd
.
getType
())
{
case
MOVETO:
{
lastMove
=
new
Point
(
cmd
.
getX
(),
cmd
.
getY
());
stop
=
true
;
break
;
}
case
LINETO:
{
if
(
stop
)
{
stop
=
false
;
if
(
cur
!=
null
)
{
result
.
add
(
cur
);
}
cur
=
new
Element
();
cur
.
start
=
lastMove
;
cur
.
prop
=
lastProp
;
}
cur
.
moves
.
add
(
new
Point
(
cmd
.
getX
(),
cmd
.
getY
()));
break
;
}
case
SETPROPERTY:
{
lastProp
=
cmd
.
getProperty
();
stop
=
true
;
break
;
}
}
}
if
(
cur
!=
null
)
{
result
.
add
(
cur
);
}
return
result
;
}
private
double
dist
(
Point
a
,
Point
b
)
{
return
Math
.
sqrt
((
a
.
y
-
b
.
y
)*(
a
.
y
-
b
.
y
)+(
a
.
x
-
b
.
x
)*(
a
.
x
-
b
.
x
));
}
private
List
<
Element
>
sort
(
List
<
Element
>
e
)
{
List
<
Element
>
result
=
new
LinkedList
<
Element
>();
switch
(
strategy
)
{
case
FILE:
{
result
.
addAll
(
e
);
break
;
}
case
NEAREST:
{
result
.
add
(
e
.
remove
(
0
));
while
(!
e
.
isEmpty
())
{
Point
end
=
result
.
get
(
result
.
size
()-
1
).
getEnd
();
//find next
int
next
=
0
;
double
dst
=
-
1
;
for
(
int
i
=
1
;
i
<
e
.
size
();
i
++)
{
double
nd
=
dist
(
e
.
get
(
i
).
getEnd
(),
end
);
if
(
nd
<
dst
||
dst
==
-
1
)
{
next
=
i
;
dst
=
nd
;
}
}
//add next
result
.
add
(
e
.
remove
(
next
));
}
break
;
}
}
return
result
;
}
public
VectorPart
optimize
(
VectorPart
vp
)
{
List
<
Element
>
opt
=
this
.
sort
(
this
.
divide
(
vp
));
LaserProperty
cp
=
opt
.
get
(
0
).
prop
;
VectorPart
result
=
new
VectorPart
(
opt
.
get
(
0
).
prop
);
for
(
Element
e
:
opt
)
{
if
(!
e
.
prop
.
equals
(
cp
))
{
result
.
setProperty
(
e
.
prop
);
cp
=
e
.
prop
;
}
result
.
moveto
(
e
.
start
.
x
,
e
.
start
.
y
);
for
(
Point
p
:
e
.
moves
)
{
result
.
lineto
(
p
.
x
,
p
.
y
);
}
}
return
result
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment