[terrafit] source code format only
This commit is contained in:
parent
53cb8086b3
commit
93440e4acd
1 changed files with 163 additions and 160 deletions
|
@ -24,10 +24,10 @@
|
|||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
|
@ -38,17 +38,17 @@
|
|||
#endif
|
||||
#else
|
||||
#define S_ISDIR(a) ((a)&_S_IFDIR)
|
||||
# include <windows.h>
|
||||
#include <Prep/Terra/getopt.h>
|
||||
#include <windows.h>
|
||||
#define sleep(x) Sleep(x * 1000)
|
||||
#endif
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/sg_dir.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/threads/SGQueue.hxx>
|
||||
#include <simgear/threads/SGThread.hxx>
|
||||
|
@ -59,13 +59,12 @@
|
|||
#include <Prep/Terra/Map.h>
|
||||
#include <Prep/Terra/Mask.h>
|
||||
|
||||
using std::istream;
|
||||
using simgear::Dir;
|
||||
using simgear::PathList;
|
||||
using std::istream;
|
||||
|
||||
SGLockedQueue<SGPath> global_workQueue;
|
||||
|
||||
|
||||
/*
|
||||
* Benchmark: Processing 800 individual buckets:
|
||||
* terrafit.cc: 52s 48s 48s
|
||||
|
@ -75,7 +74,9 @@ SGLockedQueue<SGPath> global_workQueue;
|
|||
*/
|
||||
class ArrayMap : public Terra::Map {
|
||||
public:
|
||||
explicit ArrayMap(TGArray& array): array(array) {
|
||||
explicit ArrayMap(TGArray& array)
|
||||
: array(array)
|
||||
{
|
||||
width = array.get_cols();
|
||||
height = array.get_rows();
|
||||
min = 30000;
|
||||
|
@ -94,15 +95,19 @@ public:
|
|||
|
||||
virtual ~ArrayMap() {}
|
||||
|
||||
virtual Terra::real eval(int i, int j) override {
|
||||
virtual Terra::real eval(int i, int j) override
|
||||
{
|
||||
return (Terra::real)array.get_array_elev(i, j);
|
||||
}
|
||||
|
||||
/* No direct reading of .arr.gz files */
|
||||
virtual void rawRead(istream&) {
|
||||
virtual void rawRead(istream&)
|
||||
{
|
||||
}
|
||||
virtual void textRead(istream&) {
|
||||
virtual void textRead(istream&)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
TGArray& array;
|
||||
};
|
||||
|
@ -124,11 +129,7 @@ unsigned int num_threads = 1;
|
|||
|
||||
inline int goal_not_met(Terra::GreedySubdivision* mesh)
|
||||
{
|
||||
return
|
||||
( mesh->maxError() > error_threshold &&
|
||||
mesh->pointCount() < point_limit ) ||
|
||||
mesh->pointCount() < min_points;
|
||||
|
||||
return (mesh->maxError() > error_threshold && mesh->pointCount() < point_limit) || mesh->pointCount() < min_points;
|
||||
}
|
||||
|
||||
static void announce_goal(Terra::GreedySubdivision* mesh)
|
||||
|
@ -140,9 +141,7 @@ static void announce_goal(Terra::GreedySubdivision* mesh)
|
|||
|
||||
void greedy_insertion(Terra::GreedySubdivision* mesh)
|
||||
{
|
||||
|
||||
while( goal_not_met(mesh) )
|
||||
{
|
||||
while (goal_not_met(mesh)) {
|
||||
if (!mesh->greedyInsert())
|
||||
break;
|
||||
}
|
||||
|
@ -150,7 +149,8 @@ void greedy_insertion(Terra::GreedySubdivision* mesh)
|
|||
announce_goal(mesh);
|
||||
}
|
||||
|
||||
bool endswith(const std::string& s1, const std::string& suffix) {
|
||||
bool endswith(const std::string& s1, const std::string& suffix)
|
||||
{
|
||||
size_t s1len = s1.size();
|
||||
size_t sufflen = suffix.size();
|
||||
|
||||
|
@ -161,7 +161,8 @@ bool endswith(const std::string& s1, const std::string& suffix) {
|
|||
return s1.compare(s1len - sufflen, sufflen, suffix) == 0;
|
||||
}
|
||||
|
||||
void fit_file(const SGPath& path) {
|
||||
void fit_file(const SGPath& path)
|
||||
{
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Working on file '" << path << "'");
|
||||
|
||||
SGPath outPath(path.dir());
|
||||
|
@ -219,8 +220,7 @@ void queue_fit_file(const SGPath& path)
|
|||
global_workQueue.push(path);
|
||||
}
|
||||
|
||||
class FitThread : public SGThread
|
||||
{
|
||||
class FitThread : public SGThread {
|
||||
public:
|
||||
virtual void run()
|
||||
{
|
||||
|
@ -233,15 +233,14 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void walk_path(const SGPath& path) {
|
||||
|
||||
void walk_path(const SGPath& path)
|
||||
{
|
||||
if (!path.exists()) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: Unable to stat '" << path.str() << "':" << strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((path.lower_extension() == "arr") || (path.complete_lower_extension() == "arr.rectified.gz") ||
|
||||
(path.complete_lower_extension() == "arr.gz")) {
|
||||
if ((path.lower_extension() == "arr") || (path.complete_lower_extension() == "arr.rectified.gz") || (path.complete_lower_extension() == "arr.gz")) {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "will queue " << path);
|
||||
queue_fit_file(path);
|
||||
} else if (path.isDir()) {
|
||||
|
@ -253,7 +252,8 @@ void walk_path(const SGPath& path) {
|
|||
}
|
||||
}
|
||||
|
||||
void usage(char* progname, const std::string& msg) {
|
||||
void usage(char* progname, const std::string& msg)
|
||||
{
|
||||
if (msg.size() != 0) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, msg);
|
||||
}
|
||||
|
@ -300,7 +300,8 @@ struct option options[]={
|
|||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
sglog().setLogLevels(SG_ALL, SG_INFO);
|
||||
int option;
|
||||
|
||||
|
@ -370,7 +371,9 @@ int main(int argc, char** argv) {
|
|||
|
||||
auto finish_time = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = finish_time - start_time;
|
||||
std::cout << std::endl << "Elapsed time: " << elapsed.count() << " seconds" << std::endl << std::endl;
|
||||
std::cout << std::endl
|
||||
<< "Elapsed time: " << elapsed.count() << " seconds" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue