TECH TREES WHOO
Implemented procedural tech tree generation by porting GraphSharp to Unity. Also, some database editor convenience changes.
This commit is contained in:
parent
7cd24147ae
commit
d5f2e3734a
573 changed files with 31001 additions and 222 deletions
|
|
@ -0,0 +1,403 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public class FSAAlgorithm<TObject> : FSAAlgorithm<TObject, IOverlapRemovalParameters>
|
||||
where TObject : class
|
||||
{
|
||||
public FSAAlgorithm( IDictionary<TObject, Rect> rectangles, IOverlapRemovalParameters parameters )
|
||||
: base( rectangles, parameters )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tim Dwyer <20>ltal JAVA-ban implement<6E>lt FSA algoritmus portol<6F>sa .NET al<61>.
|
||||
///
|
||||
/// http://adaptagrams.svn.sourceforge.net/viewvc/adaptagrams/trunk/RectangleOverlapSolver/placement/FSA.java?view=markup
|
||||
/// </summary>
|
||||
public class FSAAlgorithm<TObject, TParam> : OverlapRemovalAlgorithmBase<TObject, TParam>
|
||||
where TObject : class
|
||||
where TParam : IOverlapRemovalParameters
|
||||
{
|
||||
public FSAAlgorithm( IDictionary<TObject, Rect> rectangles, TParam parameters )
|
||||
: base( rectangles, parameters )
|
||||
{
|
||||
}
|
||||
|
||||
protected override void RemoveOverlap()
|
||||
{
|
||||
DateTime t0 = DateTime.Now;
|
||||
float cost = HorizontalImproved();
|
||||
DateTime t1 = DateTime.Now;
|
||||
|
||||
Debug.WriteLine( "PFS horizontal: cost=" + cost + " time=" + ( t1 - t0 ) );
|
||||
|
||||
t1 = DateTime.Now;
|
||||
cost = VerticalImproved();
|
||||
DateTime t2 = DateTime.Now;
|
||||
Debug.WriteLine( "PFS vertical: cost=" + cost + " time=" + ( t2 - t1 ) );
|
||||
Debug.WriteLine( "PFS total: time=" + ( t2 - t0 ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Megadja a k<>t t<>glalap k<>t<EFBFBD>tt fell<6C>p<EFBFBD> er<65>t.
|
||||
/// </summary>
|
||||
/// <param name="vi">Egyik t<>glalap.</param>
|
||||
/// <param name="vj">M<>sik t<>glalap.</param>
|
||||
/// <returns></returns>
|
||||
protected float2 force( Rect vi, Rect vj )
|
||||
{
|
||||
var f = new float2( 0, 0 );
|
||||
float2 d = vj.GetCenter() - vi.GetCenter();
|
||||
float adx = Math.Abs( d.x );
|
||||
float ady = Math.Abs( d.y );
|
||||
float gij = d.y / d.x;
|
||||
float Gij = ( vi.y + vj.y ) / ( vi.x + vj.x );
|
||||
if ( Gij >= gij && gij > 0 || -Gij <= gij && gij < 0 || gij == 0 )
|
||||
{
|
||||
// vi and vj touch with y-direction boundaries
|
||||
f.x = d.x / adx * ( ( vi.x + vj.x ) / 2.0f - adx );
|
||||
f.y = f.x * gij;
|
||||
}
|
||||
if ( Gij < gij && gij > 0 || -Gij > gij && gij < 0 )
|
||||
{
|
||||
// vi and vj touch with x-direction boundaries
|
||||
f.y = d.y / ady * ( ( vi.y + vj.y ) / 2.0f - ady );
|
||||
f.x = f.y / gij;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
protected float2 force2( Rect vi, Rect vj )
|
||||
{
|
||||
var f = new float2( 0, 0 );
|
||||
float2 d = vj.GetCenter() - vi.GetCenter();
|
||||
float gij = d.y / d.x;
|
||||
if ( vi.IntersectsWith( vj ) )
|
||||
{
|
||||
f.x = ( vi.x + vj.x ) / 2.0f - d.x;
|
||||
f.y = ( vi.y + vj.y ) / 2.0f - d.y;
|
||||
// in the x dimension
|
||||
if ( f.x > f.y && gij != 0 )
|
||||
{
|
||||
f.x = f.y / gij;
|
||||
}
|
||||
f.x = Math.Max( f.x, 0 );
|
||||
f.y = Math.Max( f.y, 0 );
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
protected int XComparison( RectangleWrapper<TObject> r1, RectangleWrapper<TObject> r2 )
|
||||
{
|
||||
float r1CenterX = r1.CenterX;
|
||||
float r2CenterX = r2.CenterX;
|
||||
|
||||
if ( r1CenterX < r2CenterX )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ( r1CenterX > r2CenterX )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected void Horizontal()
|
||||
{
|
||||
wrappedRectangles.Sort( XComparison );
|
||||
int i = 0, n = wrappedRectangles.Count;
|
||||
while ( i < n )
|
||||
{
|
||||
// x_i = x_{i+1} = ... = x_k
|
||||
int k = i;
|
||||
RectangleWrapper<TObject> u = wrappedRectangles[i];
|
||||
//TODO plus 1 check
|
||||
for ( int j = i + 1; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[j];
|
||||
if ( u.CenterX == v.CenterX )
|
||||
{
|
||||
u = v;
|
||||
k = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// delta = max(0, max{f.x(m,j)|i<=m<=k<j<n})
|
||||
float delta = 0;
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
float2 f = force( wrappedRectangles[m].Rectangle, wrappedRectangles[j].Rectangle );
|
||||
if ( f.x > delta )
|
||||
{
|
||||
delta = f.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[j];
|
||||
r.Rectangle.x += delta;
|
||||
}
|
||||
i = k + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected float HorizontalImproved()
|
||||
{
|
||||
wrappedRectangles.Sort( XComparison );
|
||||
int i = 0, n = wrappedRectangles.Count;
|
||||
|
||||
//bal szelso
|
||||
RectangleWrapper<TObject> lmin = wrappedRectangles[0];
|
||||
float sigma = 0, x0 = lmin.CenterX;
|
||||
var gamma = new float[wrappedRectangles.Count];
|
||||
var x = new float[wrappedRectangles.Count];
|
||||
while ( i < n )
|
||||
{
|
||||
RectangleWrapper<TObject> u = wrappedRectangles[i];
|
||||
|
||||
//i-vel azonos k<>z<EFBFBD>pponttal rendelkez<65> t<>glalapok meghat<61>roz<6F>sa
|
||||
int k = i;
|
||||
for ( int j = i + 1; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[j];
|
||||
if ( u.CenterX == v.CenterX )
|
||||
{
|
||||
u = v;
|
||||
k = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
float g = 0;
|
||||
|
||||
//i-k intervallumban l<>v<EFBFBD> t<>glalapokra er<65>sz<73>m<EFBFBD>t<EFBFBD>s a t<>l<EFBFBD>k balra l<>v<EFBFBD>kkel
|
||||
if ( u.CenterX > x0 )
|
||||
{
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
float ggg = 0;
|
||||
for ( int j = 0; j < i; j++ )
|
||||
{
|
||||
float2 f = force( wrappedRectangles[j].Rectangle, wrappedRectangles[m].Rectangle );
|
||||
ggg = Math.Max( f.x + gamma[j], ggg );
|
||||
}
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[m];
|
||||
float gg =
|
||||
v.Rectangle.x + ggg < lmin.Rectangle.x
|
||||
? sigma
|
||||
: ggg;
|
||||
g = Math.Max( g, gg );
|
||||
}
|
||||
}
|
||||
//megjegyezz<7A>k az elemek eltol<6F>s<EFBFBD>st x t<>mbbe
|
||||
//bal sz<73>l<EFBFBD> elemet <20>jra meghat<61>rozzuk
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
gamma[m] = g;
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[m];
|
||||
x[m] = r.Rectangle.x + g;
|
||||
if ( r.Rectangle.x < lmin.Rectangle.x )
|
||||
{
|
||||
lmin = r;
|
||||
}
|
||||
}
|
||||
|
||||
//az i-k intervallum n<>gyzeteit<69>l jobbra l<>v<EFBFBD>kkel er<65>sz<73>m<EFBFBD>t<EFBFBD>s, legnagyobb er<65> t<>rol<6F>sa
|
||||
// delta = max(0, max{f.x(m,j)|i<=m<=k<j<n})
|
||||
float delta = 0;
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
float2 f = force( wrappedRectangles[m].Rectangle, wrappedRectangles[j].Rectangle );
|
||||
if ( f.x > delta )
|
||||
{
|
||||
delta = f.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
sigma += delta;
|
||||
i = k + 1;
|
||||
}
|
||||
float cost = 0;
|
||||
for ( i = 0; i < n; i++ )
|
||||
{
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[i];
|
||||
float oldPos = r.Rectangle.x;
|
||||
float newPos = x[i];
|
||||
|
||||
r.Rectangle.x = newPos;
|
||||
|
||||
float diff = oldPos - newPos;
|
||||
cost += diff * diff;
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
protected int YComparison( RectangleWrapper<TObject> r1, RectangleWrapper<TObject> r2 )
|
||||
{
|
||||
float r1CenterY = r1.CenterY;
|
||||
float r2CenterY = r2.CenterY;
|
||||
|
||||
if ( r1CenterY < r2CenterY )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ( r1CenterY > r2CenterY )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected void Vertical()
|
||||
{
|
||||
wrappedRectangles.Sort( YComparison );
|
||||
int i = 0, n = wrappedRectangles.Count;
|
||||
while ( i < n )
|
||||
{
|
||||
// y_i = y_{i+1} = ... = y_k
|
||||
int k = i;
|
||||
RectangleWrapper<TObject> u = wrappedRectangles[i];
|
||||
for ( int j = i; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[j];
|
||||
if ( u.CenterY == v.CenterY )
|
||||
{
|
||||
u = v;
|
||||
k = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// delta = max(0, max{f.y(m,j)|i<=m<=k<j<n})
|
||||
float delta = 0;
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
float2 f = force2( wrappedRectangles[m].Rectangle, wrappedRectangles[j].Rectangle );
|
||||
if ( f.y > delta )
|
||||
{
|
||||
delta = f.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[j];
|
||||
r.Rectangle.y += delta;
|
||||
}
|
||||
i = k + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected float VerticalImproved()
|
||||
{
|
||||
wrappedRectangles.Sort( YComparison );
|
||||
int i = 0, n = wrappedRectangles.Count;
|
||||
RectangleWrapper<TObject> lmin = wrappedRectangles[0];
|
||||
float sigma = 0, y0 = lmin.CenterY;
|
||||
var gamma = new float[wrappedRectangles.Count];
|
||||
var y = new float[wrappedRectangles.Count];
|
||||
while ( i < n )
|
||||
{
|
||||
RectangleWrapper<TObject> u = wrappedRectangles[i];
|
||||
int k = i;
|
||||
for ( int j = i + 1; j < n; j++ )
|
||||
{
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[j];
|
||||
if ( u.CenterY == v.CenterY )
|
||||
{
|
||||
u = v;
|
||||
k = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
float g = 0;
|
||||
if ( u.CenterY > y0 )
|
||||
{
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
float ggg = 0;
|
||||
for ( int j = 0; j < i; j++ )
|
||||
{
|
||||
float2 f = force2( wrappedRectangles[j].Rectangle, wrappedRectangles[m].Rectangle );
|
||||
ggg = Math.Max( f.y + gamma[j], ggg );
|
||||
}
|
||||
RectangleWrapper<TObject> v = wrappedRectangles[m];
|
||||
float gg =
|
||||
v.Rectangle.y + ggg < lmin.Rectangle.y
|
||||
? sigma
|
||||
: ggg;
|
||||
g = Math.Max( g, gg );
|
||||
}
|
||||
}
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
gamma[m] = g;
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[m];
|
||||
y[m] = r.Rectangle.y + g;
|
||||
if ( r.Rectangle.y < lmin.Rectangle.y )
|
||||
{
|
||||
lmin = r;
|
||||
}
|
||||
}
|
||||
// delta = max(0, max{f.x(m,j)|i<=m<=k<j<n})
|
||||
float delta = 0;
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
float2 f = force( wrappedRectangles[m].Rectangle, wrappedRectangles[j].Rectangle );
|
||||
if ( f.y > delta )
|
||||
{
|
||||
delta = f.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
sigma += delta;
|
||||
i = k + 1;
|
||||
}
|
||||
|
||||
float cost = 0;
|
||||
for ( i = 0; i < n; i++ )
|
||||
{
|
||||
RectangleWrapper<TObject> r = wrappedRectangles[i];
|
||||
float oldPos = r.Rectangle.y;
|
||||
float newPos = y[i];
|
||||
|
||||
r.Rectangle.y = newPos;
|
||||
|
||||
float diff = oldPos - newPos;
|
||||
cost += diff * diff;
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a76a622ecfc1e8140982de9abd03457a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public interface IOverlapRemovalAlgorithm<TObject> : IAlgorithm
|
||||
{
|
||||
IDictionary<TObject, Rect> Rectangles { get; }
|
||||
|
||||
IOverlapRemovalParameters GetParameters();
|
||||
}
|
||||
|
||||
public interface IOverlapRemovalAlgorithm<TObject, TParam> : IOverlapRemovalAlgorithm<TObject>
|
||||
where TParam : IOverlapRemovalParameters
|
||||
{
|
||||
TParam Parameters { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3f4b5bec667d2014d9302ec043354935
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public interface IOverlapRemovalAlgorithmFactory<TVertex>
|
||||
where TVertex : class
|
||||
{
|
||||
/// <summary>
|
||||
/// List of the available algorithms.
|
||||
/// </summary>
|
||||
IEnumerable<string> AlgorithmTypes { get; }
|
||||
|
||||
IOverlapRemovalAlgorithm<TVertex> CreateAlgorithm( string newAlgorithmType, IOverlapRemovalContext<TVertex> context, IOverlapRemovalParameters parameters );
|
||||
|
||||
IOverlapRemovalParameters CreateParameters( string algorithmType, IOverlapRemovalParameters oldParameters );
|
||||
|
||||
bool IsValidAlgorithm( string algorithmType );
|
||||
|
||||
string GetAlgorithmType( IOverlapRemovalAlgorithm<TVertex> algorithm );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 332cd4d13f94d114996108bd46222790
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public interface IOverlapRemovalContext<TVertex>
|
||||
{
|
||||
IDictionary<TVertex, Rect> Rectangles { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4870dac2fa44ac941acb34e9c67a5330
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public interface IOverlapRemovalParameters : IAlgorithmParameters
|
||||
{
|
||||
float VerticalGap { get; }
|
||||
float HorizontalGap { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f2f149b8b93984b439939b7f720810be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public class OneWayFSAAlgorithm<TObject> : FSAAlgorithm<TObject, OneWayFSAParameters>
|
||||
where TObject : class
|
||||
{
|
||||
public OneWayFSAAlgorithm( IDictionary<TObject, Rect> rectangles, OneWayFSAParameters parameters )
|
||||
: base( rectangles, parameters )
|
||||
{
|
||||
}
|
||||
|
||||
protected override void RemoveOverlap()
|
||||
{
|
||||
switch ( Parameters.Way )
|
||||
{
|
||||
case OneWayFSAWayEnum.Horizontal:
|
||||
HorizontalImproved();
|
||||
break;
|
||||
case OneWayFSAWayEnum.Vertical:
|
||||
VerticalImproved();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected new float HorizontalImproved()
|
||||
{
|
||||
wrappedRectangles.Sort( XComparison );
|
||||
int i = 0, n = wrappedRectangles.Count;
|
||||
|
||||
//bal szelso
|
||||
var lmin = wrappedRectangles[0];
|
||||
float sigma = 0, x0 = lmin.CenterX;
|
||||
var gamma = new float[wrappedRectangles.Count];
|
||||
var x = new float[wrappedRectangles.Count];
|
||||
while ( i < n )
|
||||
{
|
||||
var u = wrappedRectangles[i];
|
||||
|
||||
//i-vel azonos középponttal rendelkező téglalapok meghatározása
|
||||
int k = i;
|
||||
for ( int j = i + 1; j < n; j++ )
|
||||
{
|
||||
var v = wrappedRectangles[j];
|
||||
if ( u.CenterX == v.CenterX )
|
||||
{
|
||||
u = v;
|
||||
k = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
float g = 0;
|
||||
|
||||
//ne legyenek ugyanabban a pontban
|
||||
for ( int z = i + 1; z <= k; z++ )
|
||||
{
|
||||
var v = wrappedRectangles[z];
|
||||
v.Rectangle.x += ( z - i ) * 0.0001f;
|
||||
}
|
||||
|
||||
//i-k intervallumban lévő téglalapokra erőszámítás a tőlük balra lévőkkel
|
||||
if ( u.CenterX > x0 )
|
||||
{
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
float ggg = 0;
|
||||
for ( int j = 0; j < i; j++ )
|
||||
{
|
||||
var f = force( wrappedRectangles[j].Rectangle, wrappedRectangles[m].Rectangle );
|
||||
ggg = Math.Max( f.x + gamma[j], ggg );
|
||||
}
|
||||
var v = wrappedRectangles[m];
|
||||
float gg = v.Rectangle.x + ggg < lmin.Rectangle.x ? sigma : ggg;
|
||||
g = Math.Max( g, gg );
|
||||
}
|
||||
}
|
||||
//megjegyezzük az elemek eltolásást x tömbbe
|
||||
//bal szélő elemet újra meghatározzuk
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
gamma[m] = g;
|
||||
var r = wrappedRectangles[m];
|
||||
x[m] = r.Rectangle.x + g;
|
||||
if ( r.Rectangle.x < lmin.Rectangle.x )
|
||||
{
|
||||
lmin = r;
|
||||
}
|
||||
}
|
||||
|
||||
//az i-k intervallum négyzeteitől jobbra lévőkkel erőszámítás, legnagyobb erő tárolása
|
||||
// delta = max(0, max{f.x(m,j)|i<=m<=k<j<n})
|
||||
float delta = 0;
|
||||
for ( int m = i; m <= k; m++ )
|
||||
{
|
||||
for ( int j = k + 1; j < n; j++ )
|
||||
{
|
||||
var f = force( wrappedRectangles[m].Rectangle, wrappedRectangles[j].Rectangle );
|
||||
if ( f.x > delta )
|
||||
{
|
||||
delta = f.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
sigma += delta;
|
||||
i = k + 1;
|
||||
}
|
||||
float cost = 0;
|
||||
for ( i = 0; i < n; i++ )
|
||||
{
|
||||
var r = wrappedRectangles[i];
|
||||
float oldPos = r.Rectangle.x;
|
||||
float newPos = x[i];
|
||||
|
||||
r.Rectangle.x = newPos;
|
||||
|
||||
float diff = oldPos - newPos;
|
||||
cost += diff * diff;
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c30f87ddfd0d24408a933c66fbdba2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public enum OneWayFSAWayEnum {
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
|
||||
public class OneWayFSAParameters : OverlapRemovalParameters
|
||||
{
|
||||
private OneWayFSAWayEnum way;
|
||||
public OneWayFSAWayEnum Way
|
||||
{
|
||||
get { return way; }
|
||||
set
|
||||
{
|
||||
if ( way != value )
|
||||
{
|
||||
way = value;
|
||||
NotifyChanged( "Way" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f0b4f387a07b226478df70eeb8dceba9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Windows;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public abstract class OverlapRemovalAlgorithmBase<TObject, TParam> : AlgorithmBase, IOverlapRemovalAlgorithm<TObject, TParam>
|
||||
where TObject : class
|
||||
where TParam : IOverlapRemovalParameters
|
||||
{
|
||||
protected IDictionary<TObject, Rect> originalRectangles;
|
||||
public IDictionary<TObject, Rect> Rectangles
|
||||
{
|
||||
get { return originalRectangles; }
|
||||
}
|
||||
|
||||
public TParam Parameters { get; private set; }
|
||||
|
||||
public IOverlapRemovalParameters GetParameters()
|
||||
{
|
||||
return Parameters;
|
||||
}
|
||||
|
||||
protected List<RectangleWrapper<TObject>> wrappedRectangles;
|
||||
|
||||
|
||||
public OverlapRemovalAlgorithmBase( IDictionary<TObject, Rect> rectangles, TParam parameters )
|
||||
{
|
||||
//eredeti t<>glalapok list<73>ja
|
||||
originalRectangles = rectangles;
|
||||
|
||||
//wrapping the old rectangles, to remember which one belongs to which object
|
||||
wrappedRectangles = new List<RectangleWrapper<TObject>>();
|
||||
int i = 0;
|
||||
foreach ( var kvpRect in rectangles )
|
||||
{
|
||||
wrappedRectangles.Insert( i, new RectangleWrapper<TObject>( kvpRect.Value, kvpRect.Key ) );
|
||||
i++;
|
||||
}
|
||||
|
||||
Parameters = parameters;
|
||||
}
|
||||
|
||||
protected sealed override void InternalCompute()
|
||||
{
|
||||
AddGaps();
|
||||
|
||||
RemoveOverlap();
|
||||
|
||||
RemoveGaps();
|
||||
|
||||
foreach ( var r in wrappedRectangles )
|
||||
originalRectangles[r.Id] = r.Rectangle;
|
||||
}
|
||||
|
||||
protected virtual void AddGaps()
|
||||
{
|
||||
foreach ( var r in wrappedRectangles )
|
||||
{
|
||||
r.Rectangle.width += Parameters.HorizontalGap;
|
||||
r.Rectangle.height += Parameters.VerticalGap;
|
||||
r.Rectangle.x -= Parameters.HorizontalGap / 2;
|
||||
r.Rectangle.y -= Parameters.VerticalGap / 2;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RemoveGaps()
|
||||
{
|
||||
foreach ( var r in wrappedRectangles )
|
||||
{
|
||||
r.Rectangle.width -= Parameters.HorizontalGap;
|
||||
r.Rectangle.height -= Parameters.VerticalGap;
|
||||
r.Rectangle.x += Parameters.HorizontalGap / 2;
|
||||
r.Rectangle.y += Parameters.VerticalGap / 2;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void RemoveOverlap();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 22e255da707cf7140b6c3ee0e5a7f8e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Windows;
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public class OverlapRemovalContext<TVertex> : IOverlapRemovalContext<TVertex>
|
||||
{
|
||||
public IDictionary<TVertex, Rect> Rectangles { get; private set; }
|
||||
|
||||
public OverlapRemovalContext( IDictionary<TVertex, Rect> rectangles )
|
||||
{
|
||||
Rectangles = rectangles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9c6c56fbf921aa240ba81c9f283fd215
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public static class OverlapRemovalHelper
|
||||
{
|
||||
public static float2 GetCenter( this Rect r )
|
||||
{
|
||||
return new float2( r.x + r.width / 2, r.y + r.height / 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f6dea1aafb7b334aa5b9c37d0685395
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public class OverlapRemovalParameters : IOverlapRemovalParameters
|
||||
{
|
||||
private float verticalGap = 10;
|
||||
private float horizontalGap = 10;
|
||||
|
||||
public float VerticalGap
|
||||
{
|
||||
get { return verticalGap; }
|
||||
set
|
||||
{
|
||||
if ( verticalGap != value )
|
||||
{
|
||||
verticalGap = value;
|
||||
NotifyChanged( "VerticalGap" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float HorizontalGap
|
||||
{
|
||||
get { return horizontalGap; }
|
||||
set
|
||||
{
|
||||
if ( horizontalGap != value )
|
||||
{
|
||||
horizontalGap = value;
|
||||
NotifyChanged( "HorizontalGap" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
|
||||
protected void NotifyChanged( string propertyName )
|
||||
{
|
||||
if ( PropertyChanged != null )
|
||||
PropertyChanged( this, new System.ComponentModel.PropertyChangedEventArgs( propertyName ) );
|
||||
}
|
||||
|
||||
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: df845e26e779d8c4c9378a0bd6897552
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
using Unity.Mathematics;
|
||||
using Unity.Tiny;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
/// <summary>
|
||||
/// A System.Windows.Rect egy strukt<6B>ra, ez<65>rt a heap-en t<>rol<6F>dik. Bizonyos esetekben ez nem
|
||||
/// szerencs<63>s, <20>gy sz<73>ks<6B>g van erre a wrapper oszt<7A>lyra. Mivel ez class, ez<65>rt nem
|
||||
/// <20>rt<72>k szerinti <20>tad<61>s van.
|
||||
/// </summary>
|
||||
public class RectangleWrapper<TObject>
|
||||
where TObject : class
|
||||
{
|
||||
private readonly TObject id;
|
||||
public TObject Id
|
||||
{
|
||||
get { return id; }
|
||||
}
|
||||
|
||||
public Rect Rectangle;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="rectangle"></param>
|
||||
/// <param name="id">Az adott t<>glalap azonos<6F>t<EFBFBD>ja (az overlap-removal v<>g<EFBFBD>n tudnunk kell, hogy
|
||||
/// melyik t<>glalap melyik objektumhoz tartozik. Az azonos<6F>t<EFBFBD>s megoldhat<61> lesz id alapj<70>n.</param>
|
||||
public RectangleWrapper( Rect rectangle, TObject id )
|
||||
{
|
||||
Rectangle = rectangle;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public float CenterX
|
||||
{
|
||||
get { return Rectangle.x + Rectangle.width / 2; }
|
||||
}
|
||||
|
||||
public float CenterY
|
||||
{
|
||||
get { return Rectangle.y + Rectangle.height / 2; }
|
||||
}
|
||||
|
||||
public float2 Center
|
||||
{
|
||||
get { return new float2( CenterX, CenterY ); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c550fcad2040b774788dc4aa2ef6b20a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace GraphSharp.Algorithms.OverlapRemoval
|
||||
{
|
||||
public class StandardOverlapRemovalAlgorithmFactory<TVertex> : IOverlapRemovalAlgorithmFactory<TVertex>
|
||||
where TVertex : class
|
||||
{
|
||||
protected static readonly string[] algorithmTypes = new string[] { "FSA", "OneWayFSA" };
|
||||
public IEnumerable<string> AlgorithmTypes
|
||||
{
|
||||
get { return algorithmTypes; }
|
||||
}
|
||||
|
||||
public IOverlapRemovalAlgorithm<TVertex> CreateAlgorithm( string newAlgorithmType, IOverlapRemovalContext<TVertex> context, IOverlapRemovalParameters parameters )
|
||||
{
|
||||
if ( context == null || context.Rectangles == null )
|
||||
return null;
|
||||
|
||||
switch ( newAlgorithmType )
|
||||
{
|
||||
case "FSA":
|
||||
return new FSAAlgorithm<TVertex>( context.Rectangles, parameters );
|
||||
case "OneWayFSA":
|
||||
return new OneWayFSAAlgorithm<TVertex>( context.Rectangles, parameters as OneWayFSAParameters );
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IOverlapRemovalParameters CreateParameters( string algorithmType, IOverlapRemovalParameters oldParameters )
|
||||
{
|
||||
switch ( algorithmType )
|
||||
{
|
||||
case "FSA":
|
||||
return oldParameters as OverlapRemovalParameters == null
|
||||
? new OverlapRemovalParameters()
|
||||
: (IOverlapRemovalParameters)(oldParameters as OverlapRemovalParameters).Clone();
|
||||
case "OneWayFSA":
|
||||
return ( oldParameters as OneWayFSAParameters ) == null
|
||||
? new OneWayFSAParameters()
|
||||
: (IOverlapRemovalParameters)oldParameters.Clone();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetAlgorithmType( IOverlapRemovalAlgorithm<TVertex> algorithm )
|
||||
{
|
||||
if ( algorithm is FSAAlgorithm<TVertex> )
|
||||
return "FSA";
|
||||
else if ( algorithm is OneWayFSAAlgorithm<TVertex> )
|
||||
return "OneWayFSA";
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public bool IsValidAlgorithm( string algorithmType )
|
||||
{
|
||||
return AlgorithmTypes.Contains( algorithmType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e1d078bdccd5fb47a5178ffc4e51528
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue