Skip to content

Commit c1c8d0c

Browse files
committed
Created based class FourierDescClass
1 parent 89a7b3d commit c1c8d0c

File tree

4 files changed

+78
-108
lines changed

4 files changed

+78
-108
lines changed

AlgorithmsLibrary/AlgorithmsLibrary.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Features\TripletComputation.cs" />
7272
<Compile Include="FourierDescAlgm\FourierDescAlgm.cs" />
7373
<Compile Include="FourierDescAlgm\FourierDescClass.cs" />
74+
<Compile Include="FourierDescAlgm\FourierDescFatherClass.cs" />
7475
<Compile Include="FourierDescAlgm\FourierNotClosedDescClass.cs" />
7576
<Compile Include="FourierDescAlgm\LineSegmentClass.cs" />
7677
<Compile Include="FourierDescAlgm\PolygonClass.cs" />

AlgorithmsLibrary/FourierDescAlgm/FourierDescClass.cs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
namespace AlgorithmsLibrary
88
{
9-
public class Fourier
9+
public class Fourier : FourierDescFatherClass
1010
{
1111
//Набор точек
1212
private List<MapPoint> pointCol = null;
1313
//Резервный набор точек. Возмомжно не нужен....
1414
//private List<MapPoint> newPointCol = null;
1515

1616
private long m_PointNum = 0;
17-
private long nTerm = 0;
17+
1818

1919
//Si
2020
private double[] m_accuDist = null;
@@ -27,7 +27,7 @@ public class Fourier
2727
private double[] Ay = null;
2828
private double[] By = null;
2929

30-
private double[] d = null;
30+
3131

3232
private double[] Power = null;
3333

@@ -108,7 +108,7 @@ public void CalculateAllValue()
108108
GetAllDist();
109109
GetFourierXparameter();
110110
GetFourierYparameter();
111-
CalculateShapeVector();
111+
CalculateShapeVector(true);
112112
}
113113

114114
//public void GetAllDist()
@@ -342,28 +342,6 @@ public void GetSinglePt(long nTerm, double s, out MapPoint pt)
342342
// }
343343
//}
344344

345-
public double[] CalculateShapeVector()
346-
{
347-
long n = nTerm + 1;
348-
double[] D = new double[n];
349-
d = new double[n - 1];
350-
ratio = new double[n - 1];
351-
double sum = 0;
352-
for (int i = 1; i < n; i++)
353-
{
354-
double CX = Ax[i] + By[i];
355-
double CY = Bx[i] - Ay[i];
356-
D[i] = Math.Abs(Math.Sqrt(CX * CX + CY * CY));
357-
sum = sum + D[i];
358-
}
359-
for (int i = 1; i < n; i++)
360-
{
361-
ratio[i - 1] = D[i] / sum;
362-
d[i - 1] = D[i] / D[1];
363-
}
364-
return d;
365-
}
366-
367345
public double[] CalculatePower()
368346
{
369347
long n = nTerm + 1;
@@ -525,28 +503,6 @@ public double[] CalculateEntropy()
525503
return Entropy;
526504
}
527505

528-
public double[] CalculateEntropy2(long Number)
529-
{
530-
double[] Proportion = new double[Number];
531-
532-
double d_sum = default(double);
533-
534-
for (int i = 0; i < Proportion.Length; i++)
535-
{
536-
d_sum += d[i + 1];
537-
}
538-
539-
for (int i = 0; i < Proportion.Length; i++)
540-
{
541-
Proportion[i] = d[i + 1] / d_sum;
542-
}
543-
544-
double[] Entropy = new double[Proportion.Length];
545-
for (int i = 0; i < Entropy.Length; i++)
546-
{
547-
Entropy[i] = -Proportion[i] * Math.Log(Proportion[i], 2);
548-
}
549-
return Entropy;
550-
}
506+
551507
}
552508
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AlgorithmsLibrary
8+
{
9+
public abstract class FourierDescFatherClass
10+
{
11+
public double[] d = null;
12+
public long nTerm = 0;
13+
14+
public double[] CalculateShapeVector(bool closed)
15+
{
16+
long n = nTerm + 1;
17+
double[] D = new double[n];
18+
d = new double[n - 1];
19+
ratio = new double[n - 1];
20+
double sum = 0;
21+
for (int i = 1; i < n; i++)
22+
{
23+
double CX = Ax[i] + By[i];
24+
double CY = Bx[i] - Ay[i];
25+
dobule t = Math.Sqrt(CX * CX + CY * CY);
26+
D[i] = closed ? Math.Abs(t) : t;
27+
sum = sum + D[i];
28+
}
29+
for (int i = 1; i < n; i++)
30+
{
31+
ratio[i - 1] = D[i] / sum;
32+
d[i - 1] = D[i] / D[1];
33+
}
34+
return d;
35+
}
36+
public double[] CalculateEntropy2(long Number)
37+
{
38+
double[] Proportion = new double[Number];
39+
40+
double d_sum = default(double);
41+
42+
for (int i = 0; i < Proportion.Length; i++)
43+
{
44+
d_sum += d[i + 1];
45+
}
46+
47+
for (int i = 0; i < Proportion.Length; i++)
48+
{
49+
Proportion[i] = d[i + 1] / d_sum;
50+
}
51+
52+
double[] Entropy = new double[Proportion.Length];
53+
for (int i = 0; i < Entropy.Length; i++)
54+
{
55+
Entropy[i] = -Proportion[i] * Math.Log(Proportion[i], 2);
56+
}
57+
return Entropy;
58+
}
59+
60+
61+
62+
}
63+
}

AlgorithmsLibrary/FourierDescAlgm/FourierNotClosedDescClass.cs

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,28 @@
66

77
namespace AlgorithmsLibrary
88
{
9-
public class Fourier_NotClosed
9+
public class Fourier_NotClosed : FourierDescFatherClass
1010
{
1111
#region After
12-
//点集
1312
private List<MapPoint> pointCol = null;
14-
//还原点集?(截至2017-11-7未使用)
1513
//private IPointCollection newPointCol = null;
16-
//点的数量
14+
1715
private long m_PointNum = 0;
18-
//算子数量
19-
private long nTerm = 0;
16+
2017
//Si
2118
private double[] m_accuDist = null;
22-
//点i-1到点Si的距离
2319
private double[] m_dis_betPoint = null;
24-
//总长度
20+
2521
private double m_totalS = 0.0;
26-
//Ax,Bx,Ay,By系数数组
22+
2723
private double[] Ax = null;
2824
private double[] Bx = null;
2925
private double[] Ay = null;
3026
private double[] By = null;
31-
//傅里叶算子
32-
private double[] d = null;
33-
//每个算子所占比例
27+
3428
private double[] ratio = null;
3529

36-
//清除距离过近的点
30+
3731
public Fourier_NotClosed(List<MapPoint> pointcollection, long nTerm)
3832
{
3933
this.nTerm = nTerm;
@@ -105,7 +99,7 @@ public void CalculateAllValue()
10599
GetAllDist();
106100
GetFourierXparameter();
107101
GetFourierYparameter();
108-
CalculateShapeVector();
102+
CalculateShapeVector(false);
109103
}
110104

111105
//返回总长度
@@ -337,28 +331,6 @@ public void GetSinglePt(long nTerm, double s, out MapPoint pt)
337331
// }
338332
//}
339333

340-
public double[] CalculateShapeVector()
341-
{
342-
long n = nTerm + 1;
343-
double[] D = new double[n];
344-
d = new double[n - 1];
345-
ratio = new double[n - 1];
346-
double sum = 0;
347-
for (int i = 1; i < n; i++)
348-
{
349-
double CX = Ax[i] + By[i];
350-
double CY = Bx[i] - Ay[i];
351-
D[i] = Math.Sqrt(CX * CX + CY * CY);
352-
sum = sum + D[i];
353-
}
354-
for (int i = 1; i < n; i++)
355-
{
356-
ratio[i - 1] = D[i] / sum;
357-
d[i - 1] = D[i] / D[1];
358-
}
359-
return d;
360-
}
361-
362334
public double[,] GetRecoveryPoints(long FittingPointNumber, long Fouriers)
363335
{
364336
double x = Ax[0];
@@ -488,29 +460,7 @@ public double[] CalculateEntropy()
488460
return Entropy;
489461
}
490462

491-
public double[] CalculateEntropy2(long Number)
492-
{
493-
double[] Proportion = new double[Number];
494-
495-
double d_sum = default(double);
496-
497-
for (int i = 0; i < Proportion.Length; i++)
498-
{
499-
d_sum += d[i + 1];
500-
}
501-
502-
for (int i = 0; i < Proportion.Length; i++)
503-
{
504-
Proportion[i] = d[i + 1] / d_sum;
505-
}
506-
507-
double[] Entropy = new double[Proportion.Length];
508-
for (int i = 0; i < Entropy.Length; i++)
509-
{
510-
Entropy[i] = -Proportion[i] * Math.Log(Proportion[i], 2);
511-
}
512-
return Entropy;
513-
}
463+
514464
#endregion
515465
}
516466
}

0 commit comments

Comments
 (0)