initial upload
This commit is contained in:
33
archive/sphFilter/.gitignore
vendored
Normal file
33
archive/sphFilter/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.ex
|
162
archive/sphFilter/group-seed.txt
Normal file
162
archive/sphFilter/group-seed.txt
Normal file
@@ -0,0 +1,162 @@
|
||||
0.000000000000 90.000000000000 12.0
|
||||
0.000000000000 26.565051177078 12.0
|
||||
72.000000000000 26.565051177078 12.0
|
||||
144.000000000000 26.565051177078 12.0
|
||||
-144.000000000000 26.565051177078 12.0
|
||||
-72.000000000000 26.565051177078 12.0
|
||||
36.000000000000 -26.565051177078 12.0
|
||||
108.000000000000 -26.565051177078 12.0
|
||||
180.000000000000 -26.565051177078 12.0
|
||||
-108.000000000000 -26.565051177078 12.0
|
||||
-36.000000000000 -26.565051177078 12.0
|
||||
0.000000000000 -90.000000000000 12.0
|
||||
0.000000000000 58.282525588539 12.0
|
||||
36.000000000000 31.717474411461 12.0
|
||||
72.000000000000 58.282525588539 12.0
|
||||
0.000000000000 75.454563439053 12.0
|
||||
36.000000000000 63.434948822922 12.0
|
||||
72.000000000000 75.454563439053 12.0
|
||||
16.035371256114 30.151976787043 12.0
|
||||
22.386177559197 46.353072891204 12.0
|
||||
0.000000000000 41.110487738025 12.0
|
||||
72.000000000000 41.110487738025 12.0
|
||||
49.613822440803 46.353072891204 12.0
|
||||
55.964628743886 30.151976787043 12.0
|
||||
108.000000000000 31.717474411461 12.0
|
||||
144.000000000000 58.282525588539 12.0
|
||||
108.000000000000 63.434948822922 12.0
|
||||
144.000000000000 75.454563439053 12.0
|
||||
88.035371256114 30.151976787043 12.0
|
||||
94.386177559197 46.353072891204 12.0
|
||||
144.000000000000 41.110487738025 12.0
|
||||
121.613822440803 46.353072891204 12.0
|
||||
127.964628743886 30.151976787043 12.0
|
||||
180.000000000000 31.717474411461 12.0
|
||||
-144.000000000000 58.282525588539 12.0
|
||||
180.000000000000 63.434948822922 12.0
|
||||
-144.000000000000 75.454563439053 12.0
|
||||
160.035371256114 30.151976787043 12.0
|
||||
166.386177559197 46.353072891204 12.0
|
||||
-144.000000000000 41.110487738025 12.0
|
||||
-166.386177559197 46.353072891204 12.0
|
||||
-160.035371256114 30.151976787043 12.0
|
||||
-108.000000000000 31.717474411461 12.0
|
||||
-72.000000000000 58.282525588539 12.0
|
||||
-108.000000000000 63.434948822922 12.0
|
||||
-72.000000000000 75.454563439053 12.0
|
||||
-127.964628743886 30.151976787043 12.0
|
||||
-121.613822440803 46.353072891204 12.0
|
||||
-72.000000000000 41.110487738025 12.0
|
||||
-94.386177559197 46.353072891204 12.0
|
||||
-88.035371256114 30.151976787043 12.0
|
||||
-36.000000000000 31.717474411461 12.0
|
||||
-36.000000000000 63.434948822922 12.0
|
||||
-55.964628743886 30.151976787043 12.0
|
||||
-49.613822440803 46.353072891204 12.0
|
||||
-22.386177559197 46.353072891204 12.0
|
||||
-16.035371256114 30.151976787043 12.0
|
||||
18.000000000000 0.000000000000 12.0
|
||||
54.000000000000 0.000000000000 12.0
|
||||
8.772355118394 14.545436560947 12.0
|
||||
26.267698552298 16.045057135336 12.0
|
||||
44.772355118394 -14.545436560947 12.0
|
||||
36.000000000000 0.000000000000 12.0
|
||||
27.227644881607 -14.545436560947 12.0
|
||||
45.732301447702 16.045057135336 12.0
|
||||
63.227644881607 14.545436560947 12.0
|
||||
72.000000000000 -31.717474411461 12.0
|
||||
90.000000000000 0.000000000000 12.0
|
||||
72.000000000000 0.000000000000 12.0
|
||||
80.772355118393 14.545436560947 12.0
|
||||
52.035371256114 -30.151976787043 12.0
|
||||
62.267698552298 -16.045057135336 12.0
|
||||
99.227644881606 -14.545436560947 12.0
|
||||
81.732301447702 -16.045057135336 12.0
|
||||
91.964628743886 -30.151976787043 12.0
|
||||
126.000000000000 0.000000000000 12.0
|
||||
98.267698552298 16.045057135336 12.0
|
||||
116.772355118394 -14.545436560947 12.0
|
||||
108.000000000000 0.000000000000 12.0
|
||||
117.732301447702 16.045057135336 12.0
|
||||
135.227644881606 14.545436560947 12.0
|
||||
144.000000000000 -31.717474411461 12.0
|
||||
162.000000000000 0.000000000000 12.0
|
||||
144.000000000000 0.000000000000 12.0
|
||||
152.772355118394 14.545436560947 12.0
|
||||
124.035371256114 -30.151976787043 12.0
|
||||
134.267698552298 -16.045057135336 12.0
|
||||
171.227644881606 -14.545436560947 12.0
|
||||
153.732301447702 -16.045057135336 12.0
|
||||
163.964628743886 -30.151976787043 12.0
|
||||
-162.000000000000 0.000000000000 12.0
|
||||
170.267698552298 16.045057135336 12.0
|
||||
-171.227644881606 -14.545436560947 12.0
|
||||
180.000000000000 0.000000000000 12.0
|
||||
-170.267698552298 16.045057135336 12.0
|
||||
-152.772355118394 14.545436560947 12.0
|
||||
-144.000000000000 -31.717474411461 12.0
|
||||
-126.000000000000 0.000000000000 12.0
|
||||
-144.000000000000 0.000000000000 12.0
|
||||
-135.227644881606 14.545436560947 12.0
|
||||
-163.964628743886 -30.151976787043 12.0
|
||||
-153.732301447702 -16.045057135336 12.0
|
||||
-116.772355118394 -14.545436560947 12.0
|
||||
-134.267698552298 -16.045057135336 12.0
|
||||
-124.035371256114 -30.151976787043 12.0
|
||||
-90.000000000000 0.000000000000 12.0
|
||||
-117.732301447702 16.045057135336 12.0
|
||||
-99.227644881607 -14.545436560947 12.0
|
||||
-108.000000000000 0.000000000000 12.0
|
||||
-98.267698552298 16.045057135336 12.0
|
||||
-80.772355118394 14.545436560947 12.0
|
||||
-72.000000000000 -31.717474411461 12.0
|
||||
-54.000000000000 0.000000000000 12.0
|
||||
-72.000000000000 0.000000000000 12.0
|
||||
-63.227644881607 14.545436560947 12.0
|
||||
-91.964628743886 -30.151976787043 12.0
|
||||
-81.732301447702 -16.045057135336 12.0
|
||||
-44.772355118394 -14.545436560947 12.0
|
||||
-62.267698552298 -16.045057135336 12.0
|
||||
-52.035371256114 -30.151976787043 12.0
|
||||
-18.000000000000 0.000000000000 12.0
|
||||
-45.732301447702 16.045057135336 12.0
|
||||
-27.227644881607 -14.545436560947 12.0
|
||||
-36.000000000000 0.000000000000 12.0
|
||||
-26.267698552298 16.045057135336 12.0
|
||||
-8.772355118394 14.545436560947 12.0
|
||||
-0.000000000000 -31.717474411461 12.0
|
||||
-0.000000000000 0.000000000000 12.0
|
||||
-19.964628743886 -30.151976787043 12.0
|
||||
-9.732301447702 -16.045057135336 12.0
|
||||
9.732301447702 -16.045057135336 12.0
|
||||
19.964628743886 -30.151976787043 12.0
|
||||
36.000000000000 -58.282525588539 12.0
|
||||
108.000000000000 -58.282525588539 12.0
|
||||
36.000000000000 -41.110487738025 12.0
|
||||
58.386177559197 -46.353072891204 12.0
|
||||
108.000000000000 -75.454563439053 12.0
|
||||
72.000000000000 -63.434948822922 12.0
|
||||
36.000000000000 -75.454563439053 12.0
|
||||
85.613822440803 -46.353072891204 12.0
|
||||
108.000000000000 -41.110487738025 12.0
|
||||
180.000000000000 -58.282525588539 12.0
|
||||
130.386177559197 -46.353072891204 12.0
|
||||
180.000000000000 -75.454563439053 12.0
|
||||
144.000000000000 -63.434948822922 12.0
|
||||
157.613822440803 -46.353072891204 12.0
|
||||
180.000000000000 -41.110487738025 12.0
|
||||
-108.000000000000 -58.282525588539 12.0
|
||||
-157.613822440803 -46.353072891204 12.0
|
||||
-108.000000000000 -75.454563439053 12.0
|
||||
-144.000000000000 -63.434948822922 12.0
|
||||
-130.386177559197 -46.353072891204 12.0
|
||||
-108.000000000000 -41.110487738025 12.0
|
||||
-36.000000000000 -58.282525588539 12.0
|
||||
-85.613822440803 -46.353072891204 12.0
|
||||
-36.000000000000 -75.454563439053 12.0
|
||||
-72.000000000000 -63.434948822922 12.0
|
||||
-58.386177559197 -46.353072891204 12.0
|
||||
-36.000000000000 -41.110487738025 12.0
|
||||
-13.613822440803 -46.353072891204 12.0
|
||||
-0.000000000000 -63.434948822922 12.0
|
||||
13.613822440803 -46.353072891204 12.0
|
99
archive/sphFilter/main.cpp
Normal file
99
archive/sphFilter/main.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "sphFilter.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout << "sphFilter - v0.1 data process under the spherical coordinates" << endl
|
||||
<< "Author: zhangyi.cugwuhan@gmail.com" << endl << endl
|
||||
<< "usage: sphFilter -i<input-file>[+d<x-col>,<y-col>,<val-col>] [-l<input-loc>[+d<x-col>,<y-col>]] -o<output-file> -t<type> -s<search-degree> -g<seed-file> [-h]" << endl
|
||||
<< "\t-i\tinput data table. a +d option could be attached to the filename to select data columns of the input data, the default is 0,1,2. Note that any line starts with '#' will be skipped" << endl
|
||||
<< "\t-l\tinput locations, a +d option could be attached to the filename to select data columns of the input data, the default is 0,1. Note that any line starts with '#' will be skipped" << endl
|
||||
<< "\t-o\toutput file name" << endl
|
||||
<< "\t-t\tcalculation type, 'area-mean' for area averaged value (default), 'interpolate' for spherical interpolation, 'area-std' for local STD" << endl
|
||||
<< "\t-s\tsearch degree" << endl
|
||||
<< "\t-g\tseed file for initializing groups, the default will use 'group-seed.txt' in the source code folder" << endl
|
||||
<< "\t-h\tshow this info" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
sphFilter sf;
|
||||
char infilename[1024] = "NULL";
|
||||
char infileloc[1024] = "NULL";
|
||||
char outfilename[1024] = "NULL";
|
||||
char caltype[1024] = "area-mean";
|
||||
char searchPara[1024] = "NULL";
|
||||
char seedFile[1024] = "/Users/zhangyi/Code/GitHub/selfpro/sphFilter/group-seed.txt";
|
||||
|
||||
opterr = 0; //内置参数 若不为0则会在发生遭遇错误时输出一条信息到屏幕
|
||||
|
||||
int curr;
|
||||
/*循环拾取参数 最后一个参数为-1 需要变量的参数后跟一个冒号 可有可无参数跟两个冒号*/
|
||||
while((curr = getopt(argc,argv,"hi:l:o:t:s:g:")) != -1)
|
||||
{
|
||||
/*匹配命令*/
|
||||
switch (curr)
|
||||
{
|
||||
case 'h': //显示帮助信息
|
||||
disp_help();
|
||||
break;
|
||||
case 'i':
|
||||
if (1!=sscanf(optarg,"%s",infilename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
if (1!=sscanf(optarg,"%s",outfilename))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (1!=sscanf(optarg,"%s",infileloc))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (1!=sscanf(optarg,"%s",caltype))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (1!=sscanf(optarg,"%s",searchPara))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if (1!=sscanf(optarg,"%s",seedFile))
|
||||
{
|
||||
cout << "error ==> wrong format of " << optarg << endl;
|
||||
}
|
||||
break;
|
||||
case '?': //处理未定义或错误参数
|
||||
if (optopt == 'i' || optopt == 'o' || optopt == 'l' || optopt == 't' || optopt == 's')
|
||||
{
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else if (isprint(optopt))
|
||||
{
|
||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
sf.routine(infilename,infileloc,outfilename,seedFile,searchPara,caltype);
|
||||
return 0;
|
||||
}
|
15
archive/sphFilter/makefile
Normal file
15
archive/sphFilter/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = g++-8
|
||||
PROM = /usr/local/sbin/sphFilter
|
||||
CFLAGS = -I.
|
||||
DEPS = $(shell find . -name "*.h")
|
||||
SRC = $(shell find . -name "*.cpp")
|
||||
OBJ = $(SRC:%.cpp=%.o)
|
||||
|
||||
$(PROM): $(OBJ)
|
||||
$(CC) -o $(PROM) $(OBJ) $(CFLAGS) -O2
|
||||
|
||||
%.o:%.cpp $(DEPS)
|
||||
$(CC) -c $< -o $@ $(CFLAGS) -O2
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
154
archive/sphFilter/progressBar_imp.h
Normal file
154
archive/sphFilter/progressBar_imp.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#ifndef _PROGRESS_BAR_
|
||||
#define _PROGRESS_BAR_
|
||||
|
||||
//#ifdef _WINDOWS
|
||||
//#include <windows.h>
|
||||
//#else
|
||||
//#include <sys/ioctl.h>
|
||||
//#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#define TOTAL_PERCENTAGE 100.0
|
||||
#define CHARACTER_WIDTH_PERCENTAGE 4
|
||||
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
|
||||
ProgressBar();
|
||||
ProgressBar(unsigned long n_, const char *description_="", std::ostream& out_=std::cerr);
|
||||
|
||||
void SetFrequencyUpdate(unsigned long frequency_update_);
|
||||
void SetStyle(const char* unit_bar_, const char* unit_space_);
|
||||
|
||||
void Progressed(unsigned long idx_);
|
||||
|
||||
private:
|
||||
|
||||
unsigned long n;
|
||||
unsigned int desc_width;
|
||||
unsigned long frequency_update;
|
||||
std::ostream* out;
|
||||
|
||||
const char *description;
|
||||
const char *unit_bar;
|
||||
const char *unit_space;
|
||||
|
||||
void ClearBarField();
|
||||
int GetConsoleWidth();
|
||||
int GetBarLength();
|
||||
|
||||
};
|
||||
|
||||
ProgressBar::ProgressBar() {}
|
||||
|
||||
ProgressBar::ProgressBar(unsigned long n_, const char* description_, std::ostream& out_){
|
||||
|
||||
n = n_;
|
||||
frequency_update = n_;
|
||||
description = description_;
|
||||
out = &out_;
|
||||
|
||||
unit_bar = "\u2588";
|
||||
unit_space = "-";
|
||||
desc_width = std::strlen(description); // character width of description field
|
||||
|
||||
}
|
||||
|
||||
void ProgressBar::SetFrequencyUpdate(unsigned long frequency_update_){
|
||||
|
||||
if(frequency_update_ > n){
|
||||
frequency_update = n; // prevents crash if freq_updates_ > n_
|
||||
}
|
||||
else{
|
||||
frequency_update = frequency_update_;
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressBar::SetStyle(const char* unit_bar_, const char* unit_space_){
|
||||
|
||||
unit_bar = unit_bar_;
|
||||
unit_space = unit_space_;
|
||||
}
|
||||
|
||||
int ProgressBar::GetConsoleWidth(){
|
||||
|
||||
int width;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
width = csbi.srWindow.Right - csbi.srWindow.Left;
|
||||
#else
|
||||
struct winsize win;
|
||||
ioctl(0, TIOCGWINSZ, &win);
|
||||
width = win.ws_col;
|
||||
#endif
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
int ProgressBar::GetBarLength(){
|
||||
|
||||
// get console width and according adjust the length of the progress bar
|
||||
|
||||
int bar_length = static_cast<int>((GetConsoleWidth() - desc_width - CHARACTER_WIDTH_PERCENTAGE) / 2.);
|
||||
|
||||
return bar_length;
|
||||
}
|
||||
|
||||
void ProgressBar::ClearBarField(){
|
||||
|
||||
for(int i=0;i<GetConsoleWidth();++i){
|
||||
*out << " ";
|
||||
}
|
||||
*out << "\r" << std::flush;
|
||||
}
|
||||
|
||||
void ProgressBar::Progressed(unsigned long idx_)
|
||||
{
|
||||
try{
|
||||
if(idx_ > n) throw idx_;
|
||||
|
||||
// determines whether to update the progress bar from frequency_update
|
||||
if ((idx_ != n-1) && ((idx_+1) % (n/frequency_update) != 0)) return;
|
||||
|
||||
// calculate the size of the progress bar
|
||||
int bar_size = GetBarLength();
|
||||
|
||||
// calculate percentage of progress
|
||||
double progress_percent = idx_* TOTAL_PERCENTAGE/(n-1);
|
||||
|
||||
// calculate the percentage value of a unit bar
|
||||
double percent_per_unit_bar = TOTAL_PERCENTAGE/bar_size;
|
||||
|
||||
// display progress bar
|
||||
*out << " " << description << " |";
|
||||
|
||||
for(int bar_length=0;bar_length<=bar_size-1;++bar_length){
|
||||
if(bar_length*percent_per_unit_bar<progress_percent){
|
||||
*out << unit_bar;
|
||||
}
|
||||
else{
|
||||
*out << unit_space;
|
||||
}
|
||||
}
|
||||
|
||||
if(idx_ == n-1)
|
||||
*out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush << std::endl;
|
||||
else *out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush;
|
||||
}
|
||||
catch(unsigned long e){
|
||||
ClearBarField();
|
||||
std::cerr << "PROGRESS_BAR_EXCEPTION: _idx (" << e << ") went out of bounds, greater than n (" << n << ")." << std::endl << std::flush;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
4
archive/sphFilter/readme.md
Normal file
4
archive/sphFilter/readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# 球面滤波器
|
||||
|
||||
1. 利用球冠范围计算局部均值
|
||||
2. 利用球冠范围进行插值计算
|
372
archive/sphFilter/sphFilter.h
Normal file
372
archive/sphFilter/sphFilter.h
Normal file
@@ -0,0 +1,372 @@
|
||||
#ifndef _SPHFILTER_H
|
||||
#define _SPHFILTER_H
|
||||
#include "sysDefine.h"
|
||||
#include "progressBar_imp.h"
|
||||
|
||||
/**
|
||||
* 我们这里有一个策略 我们用一组在球面上均匀分布的点位做为对输入和输出点位的分组依据 减少搜索次数提高速度
|
||||
*/
|
||||
|
||||
class sphFilter
|
||||
{
|
||||
public:
|
||||
sphFilter(){}
|
||||
~sphFilter(){}
|
||||
int routine(char*,char*,char*,char*,char*,char*);
|
||||
int initGroup(char*);
|
||||
int readInput(char*); //读取输入数据
|
||||
int readOutput(char*); //读入输出数据点位 若文件为NULL 则直接将数据数据点位复制给数据点位
|
||||
int outRes(char*); //输出计算结果
|
||||
void assignGroups(); //对输入数据进行分组
|
||||
void InverseDisInterp(vertArray,vertArray&,double); //按球心角范围搜索并按照球心角平方反比求输出点位上的插值
|
||||
void shpCapMean(vertArray,vertArray&,double); //按球心角范围搜索求区域内均值
|
||||
void shpCapSTD(vertArray,vertArray&,double); //按球心角范围搜索求区域内均值并计算标准差
|
||||
private:
|
||||
double searchDeg; //搜索角度阈值
|
||||
vertArray group;
|
||||
vertArray inputVert; //输入数据 球坐标+数据 这里我们默认所有球坐标半径均为defaultR 将半径也视为一种数据
|
||||
vertArray outputVert;
|
||||
};
|
||||
|
||||
int sphFilter::routine(char* inname,char* inname2,char* outname,char* seedfile,char* para,char* type)
|
||||
{
|
||||
sscanf(para,"%lf",&searchDeg);
|
||||
if(initGroup(seedfile)) return -1;
|
||||
if(readInput(inname)) return -1;
|
||||
if(readOutput(inname2)) return -1;
|
||||
assignGroups();
|
||||
if (!strcmp(type,"area-mean"))
|
||||
{
|
||||
shpCapMean(inputVert,outputVert,searchDeg);
|
||||
}
|
||||
else if (!strcmp(type,"interpolate"))
|
||||
{
|
||||
InverseDisInterp(inputVert,outputVert,searchDeg);
|
||||
}
|
||||
else if (!strcmp(type,"area-std"))
|
||||
{
|
||||
shpCapSTD(inputVert,outputVert,searchDeg);
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "Unknown running type: " << type << endl;
|
||||
return -1;
|
||||
}
|
||||
if(outRes(outname)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sphFilter::initGroup(char* filepara)
|
||||
{
|
||||
char filename[1024];
|
||||
int orders[3] = {0,1,2}; //默认的读入的数据列为前三列
|
||||
|
||||
//解析文件名中是否含有+d标示 如果有则将+d以前解释为filename 之后为需要读入的数据列 默认为逗号分隔
|
||||
//否则将filepara赋值为filename
|
||||
if (4 != sscanf(filepara,"%[^\+]+d%d,%d,%d",filename,&orders[0],&orders[1],&orders[2]))
|
||||
strcpy(filename,filepara);
|
||||
|
||||
ifstream infile;
|
||||
if (open_infile(infile,filename)) return -1;
|
||||
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_d;
|
||||
_1dArray temp_row;
|
||||
vert temp_vert;
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss << temp_str;
|
||||
if(!temp_row.empty()) temp_row.clear();
|
||||
while(temp_ss >> temp_d)
|
||||
temp_row.push_back(temp_d);
|
||||
|
||||
temp_vert.ps.lon = temp_row[orders[0]];
|
||||
temp_vert.ps.lat = temp_row[orders[1]];
|
||||
temp_vert.ps.rad = defaultR;
|
||||
//检查输入数据范围
|
||||
if (temp_vert.ps.lon < -180.0 || temp_vert.ps.lon > 180.0 || temp_vert.ps.lat < -90.0 || temp_vert.ps.lat > 90.0)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "The input data exceed the range of spherical coordinates: " << endl << temp_str << endl;
|
||||
return -1;
|
||||
}
|
||||
temp_vert.val = temp_row[orders[2]];
|
||||
temp_vert.setup(temp_vert.ps);
|
||||
group.push_back(temp_vert);
|
||||
}
|
||||
infile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读入输入数据包含球坐标位置与待操作的值
|
||||
* @param filepara 输入文件名
|
||||
* @return 执行状态
|
||||
*/
|
||||
int sphFilter::readInput(char* filepara)
|
||||
{
|
||||
char filename[1024];
|
||||
int orders[3] = {0,1,2}; //默认的读入的数据列为前三列
|
||||
|
||||
//解析文件名中是否含有+d标示 如果有则将+d以前解释为filename 之后为需要读入的数据列 默认为逗号分隔
|
||||
//否则将filepara赋值为filename
|
||||
if (4 != sscanf(filepara,"%[^\+]+d%d,%d,%d",filename,&orders[0],&orders[1],&orders[2]))
|
||||
strcpy(filename,filepara);
|
||||
|
||||
ifstream infile;
|
||||
if (open_infile(infile,filename)) return -1;
|
||||
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_d;
|
||||
_1dArray temp_row;
|
||||
vert temp_vert;
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss << temp_str;
|
||||
if(!temp_row.empty()) temp_row.clear();
|
||||
while(temp_ss >> temp_d)
|
||||
temp_row.push_back(temp_d);
|
||||
|
||||
temp_vert.ps.lon = temp_row[orders[0]];
|
||||
temp_vert.ps.lat = temp_row[orders[1]];
|
||||
temp_vert.ps.rad = defaultR;
|
||||
//检查输入数据范围
|
||||
//if (temp_vert.ps.lon < -180.0 || temp_vert.ps.lon > 180.0 || temp_vert.ps.lat < -90.0 || temp_vert.ps.lat > 90.0)
|
||||
//{
|
||||
// cerr << BOLDRED << "error ==> " << RESET << "The input data exceed the range of spherical coordinates: " << endl << temp_str << endl;
|
||||
// return -1;
|
||||
//}
|
||||
if (temp_vert.ps.lon > 180){
|
||||
temp_vert.ps.lon -= 360;
|
||||
temp_vert.ps.convert = 1;
|
||||
}
|
||||
temp_vert.val = temp_row[orders[2]];
|
||||
temp_vert.setup(temp_vert.ps);
|
||||
inputVert.push_back(temp_vert);
|
||||
|
||||
temp_vert.ps.convert = 0;
|
||||
}
|
||||
infile.close();
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* 读入输出数据点位
|
||||
* @param filepara 输入文件名
|
||||
* @return 执行状态
|
||||
*/
|
||||
int sphFilter::readOutput(char* filepara)
|
||||
{
|
||||
char filename[1024];
|
||||
int orders[2] = {0,1}; //默认的读入的数据列为前两列
|
||||
|
||||
//解析文件名中是否含有+d标示 如果有则将+d以前解释为filename 之后为需要读入的数据列 默认为逗号分隔
|
||||
//否则将filepara赋值为filename
|
||||
if (3 != sscanf(filepara,"%[^\+]+d%d,%d",filename,&orders[0],&orders[1]))
|
||||
strcpy(filename,filepara);
|
||||
|
||||
if (!strcmp(filename,"NULL"))
|
||||
{
|
||||
outputVert.reserve(inputVert.size());
|
||||
//直接拷贝信息 注意val值也被拷贝 所以我们把它重新初始化一下吧
|
||||
for (int i = 0; i < inputVert.size(); i++)
|
||||
{
|
||||
outputVert.push_back(inputVert[i]);
|
||||
outputVert[i].val = MAX_DBL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ifstream infile;
|
||||
if (open_infile(infile,filename)) return -1;
|
||||
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
double temp_d;
|
||||
_1dArray temp_row;
|
||||
vert temp_vert;
|
||||
while(getline(infile,temp_str))
|
||||
{
|
||||
if (*(temp_str.begin()) == '#') continue;
|
||||
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss << temp_str;
|
||||
if(!temp_row.empty()) temp_row.clear();
|
||||
while(temp_ss >> temp_d)
|
||||
temp_row.push_back(temp_d);
|
||||
|
||||
temp_vert.ps.lon = temp_row[orders[0]];
|
||||
temp_vert.ps.lat = temp_row[orders[1]];
|
||||
temp_vert.ps.rad = defaultR;
|
||||
//检查输入数据范围
|
||||
if (temp_vert.ps.lon < -180.0 || temp_vert.ps.lon > 180.0 || temp_vert.ps.lat < -90.0 || temp_vert.ps.lat > 90.0)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "The input data exceed the range of spherical coordinates: " << endl << temp_str << endl;
|
||||
return -1;
|
||||
}
|
||||
temp_vert.setup(temp_vert.ps);
|
||||
outputVert.push_back(temp_vert);
|
||||
}
|
||||
infile.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sphFilter::outRes(char* filename)
|
||||
{
|
||||
ofstream outfile;
|
||||
if(open_outfile(outfile,filename)) return -1;
|
||||
|
||||
for (int i = 0; i < outputVert.size(); i++)
|
||||
{
|
||||
if (outputVert[i].val != MAX_DBL){
|
||||
if (outputVert[i].ps.convert)
|
||||
outfile << setprecision(12) << outputVert[i].ps.lon + 360 << " " << outputVert[i].ps.lat << " " << outputVert[i].val << endl;
|
||||
else
|
||||
outfile << setprecision(12) << outputVert[i].ps.lon << " " << outputVert[i].ps.lat << " " << outputVert[i].val << endl;
|
||||
}
|
||||
else{
|
||||
if (outputVert[i].ps.convert)
|
||||
outfile << setprecision(12) << outputVert[i].ps.lon + 360 << " " << outputVert[i].ps.lat << " nan" << endl;
|
||||
else
|
||||
outfile << setprecision(12) << outputVert[i].ps.lon << " " << outputVert[i].ps.lat << " nan" << endl;
|
||||
}
|
||||
}
|
||||
outfile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sphFilter::assignGroups()
|
||||
{
|
||||
double areaSum;
|
||||
int areaCount;
|
||||
|
||||
ProgressBar *bar = new ProgressBar(group.size(),"assigning groups");
|
||||
for (int i = 0; i < group.size(); i++)
|
||||
{
|
||||
bar->Progressed(i);
|
||||
for (int j = 0; j < inputVert.size(); j++)
|
||||
{
|
||||
if (angleCpoint(group[i].pc,inputVert[j].pc) < group[i].val)
|
||||
{
|
||||
group[i].listId.push_back(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sphFilter::InverseDisInterp(vertArray inVert,vertArray& outVert,double LimDeg)
|
||||
{
|
||||
double tempAng;
|
||||
double totalWeight;
|
||||
|
||||
ProgressBar *bar = new ProgressBar(outVert.size(),"interpolating");
|
||||
for (int i = 0; i < outVert.size(); i++)
|
||||
{
|
||||
bar->Progressed(i);
|
||||
totalWeight = 0.0;
|
||||
outVert[i].val = 0.0;
|
||||
for (int n = 0; n < group.size(); n++)
|
||||
{
|
||||
if (angleCpoint(outVert[i].pc,group[n].pc) < LimDeg+group[n].val) //小圆和大圆相交
|
||||
{
|
||||
for (int j = 0; j < group[n].listId.size(); j++)
|
||||
{
|
||||
tempAng = angleCpoint(outVert[i].pc,inVert[group[n].listId[j]].pc);
|
||||
if (tempAng <= LimDeg)
|
||||
{
|
||||
outVert[i].val += inVert[group[n].listId[j]].val/(tempAng*tempAng+ZERO);
|
||||
totalWeight += 1.0/(tempAng*tempAng+ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (totalWeight != 0.0)
|
||||
outVert[i].val /= totalWeight;
|
||||
else outVert[i].val = MAX_DBL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sphFilter::shpCapMean(vertArray inVert,vertArray& outVert,double LimDeg)
|
||||
{
|
||||
double areaSum;
|
||||
int areaCount;
|
||||
|
||||
ProgressBar *bar = new ProgressBar(outVert.size(),"averaging");
|
||||
for (int i = 0; i < outVert.size(); i++)
|
||||
{
|
||||
bar->Progressed(i);
|
||||
areaSum = 0.0; areaCount = 0;
|
||||
for (int n = 0; n < group.size(); n++)
|
||||
{
|
||||
if (angleCpoint(outVert[i].pc,group[n].pc) < LimDeg+group[n].val) //小圆和大圆相交
|
||||
{
|
||||
for (int j = 0; j < group[n].listId.size(); j++)
|
||||
{
|
||||
if (angleCpoint(outVert[i].pc,inVert[group[n].listId[j]].pc) <= LimDeg)
|
||||
{
|
||||
areaSum += inVert[group[n].listId[j]].val;
|
||||
areaCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (areaCount != 0)
|
||||
outVert[i].val = areaSum/(areaCount*1.0);
|
||||
else
|
||||
outVert[i].val = MAX_DBL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sphFilter::shpCapSTD(vertArray inVert,vertArray& outVert,double LimDeg)
|
||||
{
|
||||
double areaSum,areaMean;
|
||||
int areaCount;
|
||||
_1dArray temp_list;
|
||||
|
||||
ProgressBar *bar = new ProgressBar(outVert.size(),"averaging");
|
||||
for (int i = 0; i < outVert.size(); i++)
|
||||
{
|
||||
bar->Progressed(i);
|
||||
areaSum = 0.0; areaCount = 0;
|
||||
if (!temp_list.empty()) temp_list.clear();
|
||||
for (int n = 0; n < group.size(); n++)
|
||||
{
|
||||
if (angleCpoint(outVert[i].pc,group[n].pc) < LimDeg+group[n].val) //小圆和大圆相交
|
||||
{
|
||||
for (int j = 0; j < group[n].listId.size(); j++)
|
||||
{
|
||||
if (angleCpoint(outVert[i].pc,inVert[group[n].listId[j]].pc) <= LimDeg)
|
||||
{
|
||||
temp_list.push_back(group[n].listId[j]);
|
||||
areaSum += inVert[group[n].listId[j]].val;
|
||||
areaCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (areaCount != 0)
|
||||
areaMean = areaSum/(areaCount*1.0);
|
||||
else
|
||||
areaMean = MAX_DBL;
|
||||
|
||||
areaSum = 0.0;
|
||||
if (areaCount != 0)
|
||||
{
|
||||
for (int j = 0; j < areaCount; j++)
|
||||
{
|
||||
areaSum += pow(inVert[temp_list[j]].val - areaMean,2);
|
||||
}
|
||||
outVert[i].val = sqrt(areaSum/areaCount);
|
||||
}
|
||||
else outVert[i].val = MAX_DBL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
121
archive/sphFilter/sysDefine.h
Normal file
121
archive/sphFilter/sysDefine.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#ifndef _SYSDEFINE_H
|
||||
#define _SYSDEFINE_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "vector"
|
||||
#include "map"
|
||||
#include "algorithm"
|
||||
#include "ctime"
|
||||
|
||||
#define MAX_DBL 1.0e+30
|
||||
#define MIN_BDL -1.0e+30
|
||||
#define ZERO 1.0e-20
|
||||
|
||||
#define pi (4.0*atan(1.0))
|
||||
#define defaultR 1e+5
|
||||
|
||||
#define BOLDRED "\033[1m\033[31m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//操作计时
|
||||
clock_t start,finish;
|
||||
|
||||
//全局函数
|
||||
int open_infile(ifstream &infile,char* filename)
|
||||
{
|
||||
infile.open(filename);
|
||||
if (!infile)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_outfile(ofstream &outfile,char* filename)
|
||||
{
|
||||
outfile.open(filename);
|
||||
if (!outfile)
|
||||
{
|
||||
cerr << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef vector<int> _1iArray;
|
||||
typedef vector<vector<int> > _2iArray;
|
||||
typedef vector<double> _1dArray;
|
||||
typedef vector<vector<double> > _2dArray;
|
||||
|
||||
struct cpoint
|
||||
{
|
||||
double x,y,z;
|
||||
cpoint(){x=y=z=MAX_DBL;}
|
||||
};
|
||||
typedef vector<cpoint> cpointArray;
|
||||
|
||||
struct spoint
|
||||
{
|
||||
int convert = 0;
|
||||
double lon,lat,rad;
|
||||
spoint(){lon=lat=rad=MAX_DBL;}
|
||||
};
|
||||
typedef vector<spoint> spointArray;
|
||||
|
||||
struct vert
|
||||
{
|
||||
cpoint pc;
|
||||
spoint ps;
|
||||
double val;
|
||||
_1iArray listId;
|
||||
vert(){val=MAX_DBL;}
|
||||
void setup(cpoint c)
|
||||
{
|
||||
pc.x = c.x; pc.y = c.y; pc.z = c.z;
|
||||
ps.rad = sqrt(pow(pc.x,2)+pow(pc.y,2)+pow(pc.z,2));
|
||||
if (fabs(ps.rad)<ZERO) //点距离原点极近 将点置于原点
|
||||
{
|
||||
ps.lat = ps.lon = ps.rad = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ps.lat = 90.0 - acos(pc.z/ps.rad)*180.0/pi;
|
||||
ps.lon = atan2(pc.y,pc.x)*180.0/pi;
|
||||
}
|
||||
}
|
||||
void setup(spoint s)
|
||||
{
|
||||
ps.lon = s.lon; ps.lat = s.lat; ps.rad = s.rad;
|
||||
pc.x = ps.rad*sin((0.5 - ps.lat/180.0)*pi)*cos((2.0 + ps.lon/180.0)*pi);
|
||||
pc.y = ps.rad*sin((0.5 - ps.lat/180.0)*pi)*sin((2.0 + ps.lon/180.0)*pi);
|
||||
pc.z = ps.rad*cos((0.5 - ps.lat/180.0)*pi);
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
val=MAX_DBL;
|
||||
if(!listId.empty()) listId.clear();
|
||||
}
|
||||
};
|
||||
typedef vector<vert> vertArray;
|
||||
|
||||
double dot(cpoint a, cpoint b) //矢量点乘
|
||||
{
|
||||
return a.x*b.x+a.y*b.y+a.z*b.z;
|
||||
}
|
||||
|
||||
double angleCpoint(cpoint a,cpoint b) //计算两个从原点出发的矢量的夹角
|
||||
{
|
||||
return acos(dot(a,b)/(sqrt(a.x*a.x+a.y*a.y+a.z*a.z)*sqrt(b.x*b.x+b.y*b.y+b.z*b.z)))*180.0/pi;
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user