Skip to content

Commit

Permalink
Move color difference function to Color.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vort committed Jan 7, 2017
1 parent 9597bb1 commit d0a134d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
19 changes: 18 additions & 1 deletion Color.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
namespace RiverTrace
using ColorMine.ColorSpaces;
using ColorMine.ColorSpaces.Comparisons;

namespace RiverTrace
{
struct Color
{
private static Cie1976Comparison cie;

static Color()
{
cie = new Cie1976Comparison();
}

public Color(byte r, byte g, byte b)
{
R = r;
G = g;
B = b;
}

public double DifferenceTo(Color c)
{
Rgb rgb1 = new Rgb { R = R, G = G, B = B };
Rgb rgb2 = new Rgb { R = c.R, G = c.G, B = c.B };
return rgb1.Compare(rgb2, cie);
}

public byte R;
public byte G;
public byte B;
Expand Down
4 changes: 2 additions & 2 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ static Config()
lon1 = 52.2209239,
lat2 = 64.9032122,
lon2 = 52.2213061,
iterationCount = 800,
iterationCount = 500,
sampleWidthScale = 1.7,
sampleLengthScale = 0.6,
shoreContrast = 10.0,
maxDifference = 12.0,
maxDifference = 14.0,
debug = false
};
if (File.Exists(fileName))
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.2.0")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyVersion("0.0.3.0")]
[assembly: AssemblyFileVersion("0.0.3.0")]
17 changes: 3 additions & 14 deletions Tracer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ColorMine.ColorSpaces;
using ColorMine.ColorSpaces.Comparisons;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
Expand All @@ -9,7 +7,6 @@ namespace RiverTrace
{
class Tracer
{
private Cie1976Comparison cie;
private int sampleWidth;
private int sampleLength;
private double riverWidthM;
Expand Down Expand Up @@ -47,13 +44,6 @@ void WriteOsm(List<Vector> result)
Console.WriteLine("</osm>");
}

double GetColorDifference(Color c1, Color c2)
{
Rgb rgb1 = new Rgb { R = c1.R, G = c1.G, B = c1.B };
Rgb rgb2 = new Rgb { R = c2.R, G = c2.G, B = c2.B };
return rgb1.Compare(rgb2, cie);
}

void CalcSampleDimensions(Vector startPoint, Vector direction)
{
int pickCount = 5;
Expand All @@ -70,7 +60,7 @@ void CalcSampleDimensions(Vector startPoint, Vector direction)
{
pickPoint2 += sideDirs[j];
Color checkColor = tileMap.GetPixel(pickPoint2.X, pickPoint2.Y);
double diff = GetColorDifference(refColor, checkColor);
double diff = refColor.DifferenceTo(checkColor);
if (diff > Config.Data.shoreContrast)
break;
riverHalfWidth[j] += 1.0;
Expand Down Expand Up @@ -115,7 +105,7 @@ double GetSampleDifference(SimpleBitmap s1, SimpleBitmap s2)
{
Color c1 = s1.GetPixel(i, j);
Color c2 = s2.GetPixel(i, j);
double pixelDelta = GetColorDifference(c1, c2);
double pixelDelta = c1.DifferenceTo(c2);
totalDelta += pixelDelta;
}
return totalDelta / (sampleWidth * sampleLength);
Expand Down Expand Up @@ -176,7 +166,6 @@ public Tracer()
Stopwatch sw = new Stopwatch();
sw.Start();

cie = new Cie1976Comparison();
tileMap = new TileMap(Config.Data.zoom);

var way = new List<Vector>();
Expand Down

0 comments on commit d0a134d

Please sign in to comment.