-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·175 lines (137 loc) · 4.36 KB
/
main.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "bathymetrictools.h"
/*
* This file contains:
* - Main function
* - Input parameter functions
* - Process functions to export contours and
* smoothed surfaces
*/
/*
* Simple main function:
*/
int main(int argc, const char *argv[]) {
if (argc == 2 && strcmp(argv[1], "-ui") == 0) {
clearScreen();
while (1) {
// Print menu:
printf("Bathymetric surface tools - select option:\n\
\n 1. Rolling Coin surface smoothing (Navigationally safe 2.5D surface smoothing) \
\n 2. Laplacian surface smoothing (Navigationally safe 2.5D surface smoothing)\
\n 3. Test coin radius and trimming \
\n 4. Clear screen \
\n 5. Exit \
\n\n");
char action = intInput(1, 5, "Choose action: ");
if (action == 1) {
rollingCoinSmoothing();
} else if (action == 2) {
laplacianSmoothing();
} else if (action == 3) {
testCoins();
} else if (action == 4) {
clearScreen();
} else if (action == 5) {
clearScreen();
break;
}
}
} else if (argc > 3) {
cli(argc, argv);
} else {
clearScreen();
printHelp();
}
return 0;
}
/*
* Rolling Coin surface smoothing process.
* - 2.5D
* - Safe for navigation
* - With or without shoal buffering (3x3 max filter)
*/
void rollingCoinSmoothing(void) {
clearScreen();
printf("Rolling Coin surface smoothing (2.5D):\n");
// Import data and build a "FloatSurface" (NULL:ask for input path):
struct FloatSurface *surf = inputDepthModel(NULL);
// Use shoal buffering?
char buffering = intInput(0, 1, "Buffer shoals to ensure contour safety? (0: No buffering, 1: Buffer shoals): ");
// Build a "Coin":
int coin_r = intInput(1, 50, "Enter coin radius in cells (for example 5): ");
char trim = intInput(0, 1, "Trim coin edges? (0: No trim, 1: Trim outer edges): ");
struct Coin *penny = createCoin(coin_r, trim);
// Buffer shoals if buffering is selected:
if (buffering == 1) {
maxFilterSurface(surf);
}
// Generalize/smooth surface:
coinRollSurface(surf, penny);
// Export file (GeoTIFF format):
// Use default output filename:
writeSurfaceToFile(surf, NULL);
// Free allocated memory:
printf("Freeing memory..");
freeCoin(penny);
freeFloatSurface(surf);
printf("done\n\n");
}
/*
* Iterative Laplacian interpolation based surface smoothing.
* Safe for navigation.
*/
void laplacianSmoothing(void) {
clearScreen();
printf("Laplacian surface smoothing (2.5D):\n");
// Import data and build a "FloatSurface" (NULL:ask for input path):
struct FloatSurface *surf = inputDepthModel(NULL);
// Number of iterations:
int iterations = intInput(1, 500, "Enter number of smoothing iterations (1 - 500): ");
// Smooth:
smoothLaplacian(iterations, surf);
// Export file (GeoTIFF format):
// Use default output filename:
writeSurfaceToFile(surf, NULL);
// Free allocated memory:
printf("Freeing memory..");
freeFloatSurface(surf);
printf("done\n\n");
}
/*
* Function to test coin creation.
* - Prints coin on screen
* - Development aid
*/
void testCoins(void) {
clearScreen();
printf("Test coins:\n");
int coin_r = intInput(1, 50, "Enter coin radius in cells (for example 5): ");
char trim = intInput(0, 1, "Trim coin edges? (0: No trim, 1: Trim outer edges): ");
struct Coin *penny = createCoin(coin_r, trim);
printCoin(penny);
freeCoin(penny);
printf("\n");
}
/*
* Function to clear the screen.
* - Somewhat portable, somewhat ugly
*/
void clearScreen(void) {
system("clear||cls");
}
/*
* Function for integer input:
*/
int intInput(const int lower, const int upper, const char *text) {
char st[40];
int result = 0;
int number;
printf("%s", text);
while (result != 1 || number < lower || number > upper) {
fgets(st, sizeof(st), stdin);
result = sscanf(st, "%d", &number);
if (result != 1 || (number < lower || number > upper)){
printf("Invalid input. Enter a number between [%d, %d]: ", lower, upper);
}
}
return number;
}