-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d89b977
commit 7b83ffd
Showing
12 changed files
with
327 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,29 @@ | ||
<?xml version="1.0" ?> | ||
<app-layout> | ||
<layout main-frame="true" location="487,73" size="1208,922" state="0"> | ||
<layout main-frame="true" location="647,49" size="821,904" state="0"> | ||
<westToolbar> | ||
</westToolbar> | ||
<eastToolbar> | ||
</eastToolbar> | ||
<southToolbar> | ||
</southToolbar> | ||
<split orientation="1" divider-proportion="0.7118786573410034"> | ||
<left> | ||
<tabbed> | ||
<selectedTab persistentID="8e50154c-a149-4e95-9db5-4611d24cc0cc"> | ||
</selectedTab> | ||
<tab persistentID="8e50154c-a149-4e95-9db5-4611d24cc0cc"> | ||
<properties></properties> | ||
</tab> | ||
<tab persistentID="e675ab55-fea9-49a5-a04d-51daa9cd31e6"> | ||
<properties></properties> | ||
</tab> | ||
</tabbed> | ||
</left> | ||
<right> | ||
<tabbed> | ||
<selectedTab persistentID="f2308391-8388-4f90-89f0-61caca03eb18"> | ||
</selectedTab> | ||
<tab persistentID="f2308391-8388-4f90-89f0-61caca03eb18"> | ||
<properties></properties> | ||
</tab> | ||
<tab persistentID="eb1ea92b-fc66-4c54-a5a9-3e4f8203bd5d"> | ||
<properties></properties> | ||
</tab> | ||
</tabbed> | ||
</right> | ||
</split> | ||
</layout> | ||
<undocked> | ||
<simple persistentID="eb1ea92b-fc66-4c54-a5a9-3e4f8203bd5d" class-name="com.marginallyclever.weavingradon.ui.DockingPanel"> | ||
<properties></properties> | ||
</simple> | ||
<simple persistentID="e675ab55-fea9-49a5-a04d-51daa9cd31e6" class-name="com.marginallyclever.weavingradon.ui.DockingPanel"> | ||
<properties></properties> | ||
</simple> | ||
<simple persistentID="f2308391-8388-4f90-89f0-61caca03eb18" class-name="com.marginallyclever.weavingradon.ui.DockingPanel"> | ||
<properties></properties> | ||
</simple> | ||
</undocked> | ||
</app-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 53 additions & 24 deletions
77
...ingRadonJava/src/main/java/com/marginallyclever/weavingradon/core/MulticolorThreader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,76 @@ | ||
package com.marginallyclever.weavingradon.core; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A GroupRadonThreader is a RadonThreader that can handle multiple colors. | ||
*/ | ||
public class MulticolorThreader extends RadonThreader { | ||
private final List<Color> colors = new ArrayList<>(); | ||
private final List<MonochromaticThreader> colors = new ArrayList<>(); | ||
|
||
public void addColor(Color c) { | ||
colors.add(c); | ||
private static class ThreaderChoice { | ||
public MonochromaticThreader threader; | ||
public ThetaR bestThetaR; | ||
} | ||
|
||
@Override | ||
public void setLoomAndImage(Loom loom, BufferedImage image) { | ||
for(MonochromaticThreader threader : colors) { | ||
threader.setLoomAndImage(loom, image); | ||
} | ||
setLoom(loom); | ||
} | ||
|
||
@Override | ||
public void maskRadonTransformByAllThreads() { | ||
for(MonochromaticThreader threader : colors) { | ||
threader.maskRadonTransformByAllThreads(); | ||
} | ||
} | ||
|
||
/** | ||
* get the next best thread, add it to the loom, and subtract it from the current radon image. | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
public void addNextBestThread() { | ||
if (loom.allThreads.isEmpty()) return; | ||
ThetaR tr = getBestThetaR(); | ||
LoomThread bestThread = loom.findThreadClosestToThetaR(tr); | ||
Color c = radonTransform.getColor(bestThread.thetaR.theta, bestThread.thetaR.r); | ||
bestThread.col = getNearestColor(c); | ||
loom.selectThread(bestThread); | ||
radonTransform.subtractThread(bestThread); | ||
public boolean addNextBestThread() { | ||
if (loom.allThreads.isEmpty()) return false; | ||
ThreaderChoice choice = getBestThreaderChoice(); | ||
System.out.println("best thetaR: " + choice.bestThetaR.intensity);// choice.threader.getColor() + " @ "+choice.bestThetaR); | ||
if(choice.bestThetaR.intensity==0) return false; | ||
LoomThread bestThread = loom.findThreadClosestToThetaR(choice.bestThetaR); | ||
|
||
choice.threader.getRadonTransform().subtractThread(bestThread); | ||
|
||
LoomThread selection = new LoomThread(bestThread); | ||
selection.col = choice.threader.getColor(); | ||
loom.selectThread(selection); | ||
return true; | ||
} | ||
|
||
private Color getNearestColor(Color c) { | ||
Color nearest = null; | ||
double nearestDistanceSquared = Double.MAX_VALUE; | ||
for(Color color : colors) { | ||
double distanceSquared = /*Math.sqrt*/( | ||
Math.pow(color.getRed() - c.getRed(), 2) + | ||
Math.pow(color.getGreen() - c.getGreen(), 2) + | ||
Math.pow(color.getBlue() - c.getBlue(), 2) | ||
); | ||
if (distanceSquared < nearestDistanceSquared) { | ||
nearest = color; | ||
nearestDistanceSquared = distanceSquared; | ||
/** | ||
* Finds the best thread in the best color to add to the loom. | ||
*/ | ||
public ThreaderChoice getBestThreaderChoice() { | ||
ThreaderChoice bestFound = new ThreaderChoice(); | ||
|
||
double intensity = 0; | ||
for(MonochromaticThreader threader : colors) { | ||
var tr = threader.getBestThetaR(); | ||
if(intensity < tr.intensity) { | ||
bestFound.threader = threader; | ||
bestFound.bestThetaR = tr; | ||
intensity = tr.intensity; | ||
} | ||
} | ||
return nearest; | ||
return bestFound; | ||
} | ||
|
||
public void addThreader(MonochromaticThreader radonThreader) { | ||
colors.add(radonThreader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.