-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrendSurfaceThread.java
More file actions
86 lines (77 loc) · 3.46 KB
/
Copy pathTrendSurfaceThread.java
File metadata and controls
86 lines (77 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package heyingzhe;
import java.awt.Color;
import java.io.IOException;
import java.nio.file.Paths;
import java.sql.SQLException;
import static heyingzhe.TrendSurfaceInterpolation.trendSurfaceInterpolation;
public class TrendSurfaceThread extends Thread {
private double[][] data;
private String outputPath;
private Color color1;
private Color color2;
private String outputTrendSurfaceImage;
private String dbUserName;
private String dbPassword;
public TrendSurfaceThread(double[][] data, String outputPath, String outputTrendSurfaceImage, Color color1, Color color2, String dbUserName, String dbPassword) {
this.data = data;
this.outputPath = outputPath;
this.color1 = color1;
this.color2 = color2;
this.outputTrendSurfaceImage = outputTrendSurfaceImage;
this.dbUserName = dbUserName;
this.dbPassword = dbPassword;
}
public void run() {
System.out.println("正在进行趋势面插值……");
// 检查是否有足够的非零点
int nonZeroCount = 0;
for (double[] row : data) {
for (double val : row) {
if (val != 0) nonZeroCount++;
}
}
if (nonZeroCount < 3) {
System.out.println("输入数据中非零点不足 3 个,无法进行趋势面插值!");
} else {
double[][] trendSurfaceInterpolationResult = trendSurfaceInterpolation(data); //趋势面插值
System.out.println("趋势面插值完成");
// 插值结果输出图片
ImageVisualizer imageVision = new ImageVisualizer();
imageVision.colorizeWithLevels(trendSurfaceInterpolationResult, color1, color2, 20);
try {
imageVision.saveImage(Paths.get(outputPath, outputTrendSurfaceImage).toString(), "png");
} catch (IOException e) {
throw new RuntimeException(e);
}
//储存数据到数据库
SaveResult saveProcessing = new SaveResult();
// 配置数据库
saveProcessing.setMySQLProperty(dbUserName, dbPassword);
try {
saveProcessing.createDatabase("result");
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
System.out.println("趋势面插值:数据库连接成功!");
System.out.println("正在将趋势面插值结果上传至数据库……");
try {
saveProcessing.createTable("result", "TrendSurfaceInterpolationResult");
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
saveProcessing.saveArrayToAscFile(trendSurfaceInterpolationResult, outputPath, "trendSurface.asc"); //保存为二进制文件
//saveProcessing.saveArrayToMySQL(trendSurfaceInterpolationResult, "trendSurfaceInterpolation");
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("数据已经添加到数据库里面");
}
}
}