initial upload
This commit is contained in:
parent
aaa09d46a5
commit
586f543a11
38
.gitignore
vendored
38
.gitignore
vendored
@ -1,34 +1,4 @@
|
|||||||
# ---> C++
|
.DS_Store
|
||||||
# Prerequisites
|
build/
|
||||||
*.d
|
.vscode/
|
||||||
|
tmp/
|
||||||
# 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
|
|
||||||
|
|
46
CMakeLists.txt
Normal file
46
CMakeLists.txt
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.2)
|
||||||
|
# 设置项目名称与语言
|
||||||
|
project(GCTL_MESH VERSION 1.0)
|
||||||
|
# 添加配置配件编写的函数
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||||
|
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||||
|
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||||
|
|
||||||
|
find_package(GCTL REQUIRED)
|
||||||
|
find_package(GCTL_GRAPHIC REQUIRED)
|
||||||
|
message(STATUS "GCTL Version: " ${GCTL_VERSION})
|
||||||
|
message(STATUS "GCTL_GRAPHIC Version: " ${GCTL_GRAPHIC_VERSION})
|
||||||
|
#if(${GCTL_VERSION} LESS 1.0)
|
||||||
|
# message(FATAL_ERROR "GCTL's version must be v1.0 or bigger.")
|
||||||
|
#endif()
|
||||||
|
|
||||||
|
option(GCTL_MESH_EXPRTK "Use the exprtk library." ON)
|
||||||
|
option(GCTL_MESH_WAVELIB "Use the WaveLib library" ON)
|
||||||
|
# 传递安装地址给编译期宏变量
|
||||||
|
option(GCTL_MESH_INSTALL_PREFIX "Pass the install directory." ON)
|
||||||
|
set(DIR_VAR ${CMAKE_INSTALL_PREFIX})
|
||||||
|
|
||||||
|
message(STATUS "[GCTL_MESH] Pass the install directory: " ${GCTL_MESH_INSTALL_PREFIX})
|
||||||
|
message(STATUS "[GCTL_MESH] Use the exprtk library: " ${GCTL_MESH_EXPRTK})
|
||||||
|
message(STATUS "[GCTL_MESH] Use the WaveLib library: " ${GCTL_MESH_WAVELIB})
|
||||||
|
|
||||||
|
if(GCTL_MESH_WAVELIB)
|
||||||
|
if(NOT WaveLib_FOUND)
|
||||||
|
find_package(WaveLib REQUIRED)
|
||||||
|
message(STATUS "Found WaveLib")
|
||||||
|
include_directories(${WaveLib_INC_DIR})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# 加入一个头文件配置,让cmake对源码进行操作
|
||||||
|
configure_file(
|
||||||
|
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||||
|
"${PROJECT_SOURCE_DIR}/lib/mesh/gctl_mesh_config.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 添加库源文件地址
|
||||||
|
add_subdirectory(lib)
|
||||||
|
add_subdirectory(tool)
|
||||||
|
add_subdirectory(example)
|
34
GCTL_MESHConfig.cmake.in
Normal file
34
GCTL_MESHConfig.cmake.in
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_VERSION "@PROJECT_VERSION@")
|
||||||
|
set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
|
||||||
|
set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_LIB gctl_mesh)
|
||||||
|
set(@PROJECT_NAME@_LIBRARY gctl_mesh)
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_EXPRTK @GCTL_MESH_EXPRTK@)
|
||||||
|
set(@PROJECT_NAME@_WAVELIB @GCTL_MESH_WAVELIB@)
|
||||||
|
|
||||||
|
message(STATUS "[GCTL_MESH] Use the exprtk library: " @GCTL_MESH_EXPRTK@)
|
||||||
|
message(STATUS "[GCTL_MESH] Use the WaveLib library: " @GCTL_MESH_WAVELIB@)
|
||||||
|
|
||||||
|
if(NOT GCTL_FOUND)
|
||||||
|
find_package(GCTL REQUIRED)
|
||||||
|
include_directories(${GCTL_INC_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(@PROJECT_NAME@_WAVELIB)
|
||||||
|
if(NOT WaveLib_FOUND)
|
||||||
|
find_package(WaveLib REQUIRED)
|
||||||
|
include_directories(${WaveLib_INC_DIR})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# include target information
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||||
|
|
||||||
|
check_required_components(@PROJECT_NAME@)
|
3
config.h.in
Normal file
3
config.h.in
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#cmakedefine GCTL_MESH_INSTALL_PREFIX "${DIR_VAR}"
|
||||||
|
#cmakedefine GCTL_MESH_EXPRTK
|
||||||
|
#cmakedefine GCTL_MESH_WAVELIB
|
33
dep/wavelib/.travis.yml
Normal file
33
dep/wavelib/.travis.yml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
sudo: false
|
||||||
|
language: c
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
|
|
||||||
|
compiler:
|
||||||
|
- gcc
|
||||||
|
- clang
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- compiler: clang
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
# linux prereqisite packages
|
||||||
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then wget --no-check-certificate https://www.cmake.org/files/v3.2/cmake-3.2.3-Linux-x86_64.tar.gz; fi
|
||||||
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then tar -xzvf cmake-3.2.3-Linux-x86_64.tar.gz; fi
|
||||||
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then export PATH=$PWD/cmake-3.2.3-Linux-x86_64/bin:$PATH; fi
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
|
||||||
|
|
||||||
|
script:
|
||||||
|
- mkdir build.ci && cd build.ci
|
||||||
|
- cmake .. -DBUILD_UT=ON -DCMAKE_BUILD_TYPE=$BUILD_CONFIG -DUSE_STATIC_BOOST=YES
|
||||||
|
- cmake --build .
|
||||||
|
- ctest -VV
|
15
dep/wavelib/CMakeLists.txt
Normal file
15
dep/wavelib/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.2)
|
||||||
|
# 设置工程名称和语言
|
||||||
|
project(WaveLib VERSION 1.0)
|
||||||
|
# 添加配置配件编写的函数
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||||
|
# CMake默认的安装路径 Windows下为C:/Program\ Files/${Project_Name} Linux/Unix下为/usr/local
|
||||||
|
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||||
|
# CMake默认的变异类型为空
|
||||||
|
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||||
|
|
||||||
|
# 添加源文件地址
|
||||||
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(auxiliary)
|
19
dep/wavelib/COPYRIGHT
Normal file
19
dep/wavelib/COPYRIGHT
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2014, Rafat Hussain
|
||||||
|
Copyright (c) 2016, Holger Nahrstaedt
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
||||||
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
OF SUCH DAMAGE.
|
30
dep/wavelib/README.md
Normal file
30
dep/wavelib/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[](https://travis-ci.org/rafat/wavelib)
|
||||||
|
|
||||||
|
wavelib
|
||||||
|
=======
|
||||||
|
|
||||||
|
C Implementation of Discrete Wavelet Transform (DWT,SWT and MODWT), Continuous Wavelet transform (CWT) and Discrete Packet Transform ( Full Tree Decomposition and Best Basis DWPT).
|
||||||
|
|
||||||
|
Discrete Wavelet Transform Methods Implemented
|
||||||
|
|
||||||
|
DWT/IDWT and DWT2/IDWT2 A decimated Discrete Wavelet Transform implementation using implicit signal extension and up/downsampling so it is a fast implementation. A FFT based implementation is optional but will not be usually needed. Both periodic and symmetric options are available.
|
||||||
|
|
||||||
|
SWT/ISWT and SWT2/ISWT2 Stationary Wavelet Transform. It works only for signal lengths that are multiples of 2^J where J is the number of decomposition levels. For signals of other lengths see MODWT implementation.
|
||||||
|
|
||||||
|
MODWT/IMODWT and MODWT2/IMODWT2 Maximal Overlap Discrete Wavelet Transform is another undecimated transform. It is implemented for signals of any length but only orthogonal wavelets (Daubechies, Symlets and Coiflets) can be deployed. This implementation is based on the method laid out in "Wavelet Methods For Wavelet Analysis" by Donald Percival and Andrew Walden.
|
||||||
|
|
||||||
|
Discrete Wavelet Packet Transform Methods Implemented
|
||||||
|
|
||||||
|
WTREE A Fully Decimated Wavelet Tree Decomposition. This is a highly redundant transform and retains all coefficients at each node. This is not recommended for compression and denoising applications.
|
||||||
|
|
||||||
|
DWPT/IDWPT Is a derivative of WTREE method which retains coefficients based on entropy methods. This is a non-redundant transform and output length is of the same order as the input.
|
||||||
|
|
||||||
|
CWT/ICWT C translation ( with some modifications) of Continuous Wavelet Transform Software provided by C. Torrence and G. Compo, and is available at URL: http://atoc.colorado.edu/research/wavelets/'. A generalized Inverse Transform with approximate reconstruction is also added.
|
||||||
|
|
||||||
|
Documentation Available at - https://github.com/rafat/wavelib/wiki
|
||||||
|
|
||||||
|
Live Demo of 1D DWT and 1D CWT (Emscripten) - http://rafat.github.io/wavelib/
|
||||||
|
|
||||||
|
License - BSD 3-Clause
|
||||||
|
|
||||||
|
Contace - rafat.hsn@gmail.com
|
19
dep/wavelib/WaveLibConfig.cmake.in
Normal file
19
dep/wavelib/WaveLibConfig.cmake.in
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_Version "@PROJECT_VERSION@")
|
||||||
|
set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
|
||||||
|
set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_INCULDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||||
|
|
||||||
|
set(@PROJECT_NAME@_LIB wavelib)
|
||||||
|
set(@PROJECT_NAME@_LIBRARY wavelib)
|
||||||
|
set(@PROJECT_NAME@_FOUND 1)
|
||||||
|
|
||||||
|
set(WauxLib_LIB wauxlib)
|
||||||
|
set(WauxLib_LIBRARY wauxlib)
|
||||||
|
set(WauxLib_FOUND 1)
|
||||||
|
|
||||||
|
# include target information
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
16
dep/wavelib/appveyor.yml
Normal file
16
dep/wavelib/appveyor.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
os: Visual Studio 2015
|
||||||
|
|
||||||
|
platform: x64
|
||||||
|
|
||||||
|
environment:
|
||||||
|
BOOST_ROOT: C:\Libraries\boost_1_59_0
|
||||||
|
BOOST_LIBRARYDIR: C:\Libraries\boost_1_59_0\lib64-msvc-14.0
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- mkdir build
|
||||||
|
- cd build
|
||||||
|
- cmake -G "Visual Studio 14 2015 Win64" -DUSE_STATIC_BOOST=NO ..
|
||||||
|
- cmake --build . --config Debug
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- ctest -VV -C Debug
|
53
dep/wavelib/auxiliary/CMakeLists.txt
Normal file
53
dep/wavelib/auxiliary/CMakeLists.txt
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# 设定源文件文件夹
|
||||||
|
aux_source_directory(. WAUX_SRC)
|
||||||
|
|
||||||
|
# 以下部分为库的编译
|
||||||
|
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||||
|
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||||
|
add_library(wauxlib SHARED ${WAUX_SRC})
|
||||||
|
# 首先添加静态库的生成命令
|
||||||
|
add_library(wauxlib_static STATIC ${WAUX_SRC})
|
||||||
|
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||||
|
set_target_properties(wauxlib_static PROPERTIES OUTPUT_NAME "wauxlib")
|
||||||
|
# 设置输出目标属性以同时输出动态库与静态库
|
||||||
|
set_target_properties(wauxlib PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
set_target_properties(wauxlib_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
# 设置动态库的版本号
|
||||||
|
set_target_properties(wauxlib PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||||
|
|
||||||
|
target_link_libraries(wauxlib PUBLIC wavelib)
|
||||||
|
target_link_libraries(wauxlib_static PUBLIC wavelib_static)
|
||||||
|
|
||||||
|
# 设置库文件的输出地址
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
# 设置编译选项
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||||
|
|
||||||
|
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||||
|
|
||||||
|
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
INSTALL_DESTINATION ${CONFIG_FILE_PATH}
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||||
|
|
||||||
|
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
# 库的安装命令
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS wauxlib DESTINATION lib)
|
||||||
|
install(TARGETS wauxlib_static DESTINATION lib)
|
||||||
|
else()
|
||||||
|
install(TARGETS wauxlib wauxlib_static
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib)
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
install(FILES
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
endif()
|
489
dep/wavelib/auxiliary/denoise.c
Normal file
489
dep/wavelib/auxiliary/denoise.c
Normal file
@ -0,0 +1,489 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "waux.h"
|
||||||
|
#include "../header/wauxlib.h"
|
||||||
|
|
||||||
|
denoise_object denoise_init(int length, int J,const char* wname) {
|
||||||
|
denoise_object obj = NULL;
|
||||||
|
|
||||||
|
obj = (denoise_object)malloc(sizeof(struct denoise_set) +sizeof(double));
|
||||||
|
|
||||||
|
obj->N = length;
|
||||||
|
obj->J = J;
|
||||||
|
|
||||||
|
strcpy(obj->wname,wname);
|
||||||
|
|
||||||
|
//Set Default Values
|
||||||
|
strcpy(obj->dmethod,"sureshrink");
|
||||||
|
strcpy(obj->ext,"sym");
|
||||||
|
strcpy(obj->level,"all");
|
||||||
|
strcpy(obj->thresh,"soft");
|
||||||
|
strcpy(obj->wmethod,"dwt");
|
||||||
|
strcpy(obj->cmethod,"direct");
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
void visushrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised) {
|
||||||
|
int filt_len,iter,i,dlen,dwt_len,sgn, MaxIter,it;
|
||||||
|
double sigma,td,tmp;
|
||||||
|
wave_object wave;
|
||||||
|
wt_object wt;
|
||||||
|
double *dout,*lnoise;
|
||||||
|
|
||||||
|
wave = wave_init(wname);
|
||||||
|
|
||||||
|
filt_len = wave->filtlength;
|
||||||
|
|
||||||
|
MaxIter = (int) (log((double)N / ((double)filt_len - 1.0)) / log(2.0));
|
||||||
|
|
||||||
|
if (J > MaxIter) {
|
||||||
|
printf("\n Error - The Signal Can only be iterated %d times using this wavelet. Exiting\n",MaxIter);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wt = wt_init(wave,method,N,J);
|
||||||
|
if(!strcmp(method,"dwt")) {
|
||||||
|
setDWTExtension(wt,ext);
|
||||||
|
dwt(wt,signal);
|
||||||
|
} else if(!strcmp(method,"swt")) {
|
||||||
|
swt(wt,signal);
|
||||||
|
} else {
|
||||||
|
printf("Acceptable WT methods are - dwt,swt and modwt\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lnoise = (double*)malloc(sizeof(double) * J);
|
||||||
|
|
||||||
|
//Set sigma
|
||||||
|
|
||||||
|
iter = wt->length[0];
|
||||||
|
dlen = wt->length[J];
|
||||||
|
|
||||||
|
dout = (double*)malloc(sizeof(double) * dlen);
|
||||||
|
|
||||||
|
if(!strcmp(level,"first")) {
|
||||||
|
for (i = 1; i < J; ++i) {
|
||||||
|
iter += wt->length[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
dout[i] = fabs(wt->output[iter+i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sigma = median(dout,dlen) / 0.6745;
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
lnoise[it] = sigma;
|
||||||
|
}
|
||||||
|
} else if(!strcmp(level,"all")){
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
dlen = wt->length[it+1];
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
dout[i] = fabs(wt->output[iter+i]);
|
||||||
|
}
|
||||||
|
sigma = median(dout,dlen) / 0.6745;
|
||||||
|
lnoise[it] = sigma;
|
||||||
|
iter += dlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("Acceptable Noise estimation level values are - first and all \n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
dwt_len = wt->outlength;
|
||||||
|
iter = wt->length[0];
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
sigma = lnoise[it];
|
||||||
|
dlen = wt->length[it+1];
|
||||||
|
td = sqrt(2.0 * log(dwt_len)) * sigma;
|
||||||
|
|
||||||
|
if(!strcmp(thresh,"hard")) {
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
if (fabs(wt->output[iter+i]) < td) {
|
||||||
|
wt->output[iter+i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(!strcmp(thresh,"soft")) {
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
if (fabs(wt->output[iter + i]) < td) {
|
||||||
|
wt->output[iter+i] = 0;
|
||||||
|
} else {
|
||||||
|
sgn = wt->output[iter+i] >= 0 ? 1 : -1;
|
||||||
|
tmp = sgn * (fabs(wt->output[iter+i]) - td);
|
||||||
|
wt->output[iter+i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iter += wt->length[it+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strcmp(method,"dwt")) {
|
||||||
|
idwt(wt,denoised);
|
||||||
|
} else if(!strcmp(method,"swt")) {
|
||||||
|
iswt(wt,denoised);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(dout);
|
||||||
|
free(lnoise);
|
||||||
|
wave_free(wave);
|
||||||
|
wt_free(wt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sureshrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised) {
|
||||||
|
int filt_len,i,it,len,dlen,dwt_len,min_index,sgn, MaxIter,iter;
|
||||||
|
double sigma,norm,td,tv,te,ct,thr,temp,x_sum;
|
||||||
|
wave_object wave;
|
||||||
|
wt_object wt;
|
||||||
|
double *dout,*risk,*dsum,*lnoise;
|
||||||
|
|
||||||
|
wave = wave_init(wname);
|
||||||
|
|
||||||
|
filt_len = wave->filtlength;
|
||||||
|
|
||||||
|
MaxIter = (int) (log((double)N / ((double)filt_len - 1.0)) / log(2.0));
|
||||||
|
// Depends on J
|
||||||
|
if (J > MaxIter) {
|
||||||
|
printf("\n Error - The Signal Can only be iterated %d times using this wavelet. Exiting\n",MaxIter);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wt = wt_init(wave,method,N,J);
|
||||||
|
|
||||||
|
if(!strcmp(method,"dwt")) {
|
||||||
|
setDWTExtension(wt,ext);
|
||||||
|
dwt(wt,signal);
|
||||||
|
} else if(!strcmp(method,"swt")) {
|
||||||
|
swt(wt,signal);
|
||||||
|
} else {
|
||||||
|
printf("Acceptable WT methods are - dwt and swt\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = wt->length[0];
|
||||||
|
dlen = wt->length[J];
|
||||||
|
|
||||||
|
dout = (double*)malloc(sizeof(double) * dlen);
|
||||||
|
risk = (double*)malloc(sizeof(double) * dlen);
|
||||||
|
dsum = (double*)malloc(sizeof(double) * dlen);
|
||||||
|
lnoise = (double*)malloc(sizeof(double) * J);
|
||||||
|
|
||||||
|
iter = wt->length[0];
|
||||||
|
|
||||||
|
if(!strcmp(level,"first")) {
|
||||||
|
for (i = 1; i < J; ++i) {
|
||||||
|
iter += wt->length[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
dout[i] = fabs(wt->output[iter+i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sigma = median(dout,dlen) / 0.6745;
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
lnoise[it] = sigma;
|
||||||
|
}
|
||||||
|
} else if(!strcmp(level,"all")){
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
dlen = wt->length[it+1];
|
||||||
|
for(i = 0; i < dlen;++i) {
|
||||||
|
dout[i] = fabs(wt->output[iter+i]);
|
||||||
|
}
|
||||||
|
sigma = median(dout,dlen) / 0.6745;
|
||||||
|
lnoise[it] = sigma;
|
||||||
|
iter += dlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("Acceptable Noise estimation level values are - first and all \n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(it = 0; it < J;++it) {
|
||||||
|
dwt_len = wt->length[it+1];
|
||||||
|
sigma = lnoise[it];
|
||||||
|
|
||||||
|
if ( sigma < 0.00000001) {
|
||||||
|
td = 0;
|
||||||
|
} else {
|
||||||
|
tv = sqrt(2.0 * log(dwt_len));
|
||||||
|
norm = 0.0;
|
||||||
|
for(i = 0; i < dwt_len;++i) {
|
||||||
|
norm += (wt->output[len+i] *wt->output[len+i] /(sigma*sigma));
|
||||||
|
}
|
||||||
|
te =(norm - (double) dwt_len)/(double) dwt_len;
|
||||||
|
ct = pow(log((double) dwt_len)/log(2.0),1.5)/sqrt((double) dwt_len);
|
||||||
|
|
||||||
|
if (te < ct) {
|
||||||
|
td = tv;
|
||||||
|
} else {
|
||||||
|
x_sum = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < dwt_len;++i) {
|
||||||
|
dout[i] = fabs(wt->output[len+i]/sigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
qsort(dout, dwt_len, sizeof(double), compare_double);
|
||||||
|
for(i = 0; i < dwt_len;++i) {
|
||||||
|
dout[i] = (dout[i]*dout[i]);
|
||||||
|
x_sum += dout[i];
|
||||||
|
dsum[i] = x_sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0;i < dwt_len;++i) {
|
||||||
|
risk[i] = ((double)dwt_len - 2 * ((double)i + 1) +dsum[i] +
|
||||||
|
dout[i]*((double)dwt_len - 1 -(double) i))/(double)dwt_len;
|
||||||
|
}
|
||||||
|
min_index = minindex(risk,dwt_len);
|
||||||
|
thr = sqrt(dout[min_index]);
|
||||||
|
td = thr < tv ? thr : tv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td = td * sigma;
|
||||||
|
|
||||||
|
if(!strcmp(thresh,"hard")) {
|
||||||
|
for(i = 0; i < dwt_len;++i) {
|
||||||
|
if (fabs(wt->output[len+i]) < td) {
|
||||||
|
wt->output[len+i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(!strcmp(thresh,"soft")) {
|
||||||
|
for(i = 0; i < dwt_len;++i) {
|
||||||
|
if (fabs(wt->output[len + i]) < td) {
|
||||||
|
wt->output[len+i] = 0;
|
||||||
|
} else {
|
||||||
|
sgn = wt->output[len+i] >= 0 ? 1 : -1;
|
||||||
|
temp = sgn * (fabs(wt->output[len+i]) - td);
|
||||||
|
wt->output[len+i] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len += wt->length[it+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strcmp(method,"dwt")) {
|
||||||
|
idwt(wt,denoised);
|
||||||
|
} else if(!strcmp(method,"swt")) {
|
||||||
|
iswt(wt,denoised);
|
||||||
|
}
|
||||||
|
free(dout);
|
||||||
|
free(dsum);
|
||||||
|
free(risk);
|
||||||
|
free(lnoise);
|
||||||
|
wave_free(wave);
|
||||||
|
wt_free(wt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void modwtshrink(double *signal, int N, int J, const char *wname, const char *cmethod, const char *ext, const char *thresh, double *denoised) {
|
||||||
|
int filt_len, iter, i, dlen, sgn, MaxIter, it;
|
||||||
|
double sigma, td, tmp, M, llen;
|
||||||
|
wave_object wave;
|
||||||
|
wt_object wt;
|
||||||
|
double *dout, *lnoise;
|
||||||
|
|
||||||
|
wave = wave_init(wname);
|
||||||
|
|
||||||
|
filt_len = wave->filtlength;
|
||||||
|
|
||||||
|
MaxIter = (int)(log((double)N / ((double)filt_len - 1.0)) / log(2.0));
|
||||||
|
|
||||||
|
if (J > MaxIter) {
|
||||||
|
printf("\n Error - The Signal Can only be iterated %d times using this wavelet. Exiting\n", MaxIter);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wt = wt_init(wave, "modwt", N, J);
|
||||||
|
|
||||||
|
if (!strcmp(ext, "sym") && !strcmp(cmethod,"fft")) {
|
||||||
|
setWTConv(wt, "fft");
|
||||||
|
setDWTExtension(wt, "sym");
|
||||||
|
}
|
||||||
|
else if (!strcmp(ext, "sym") && !strcmp(cmethod, "direct")) {
|
||||||
|
printf("Symmetric Extension is not available for direct method");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
else if (!strcmp(ext, "per") && !strcmp(cmethod, "direct")) {
|
||||||
|
setWTConv(wt, "direct");
|
||||||
|
setDWTExtension(wt, "per");
|
||||||
|
}
|
||||||
|
else if (!strcmp(ext, "per") && !strcmp(cmethod, "fft")) {
|
||||||
|
setWTConv(wt, "fft");
|
||||||
|
setDWTExtension(wt, "per");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Signal extension can be either per or sym");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
modwt(wt, signal);
|
||||||
|
|
||||||
|
lnoise = (double*)malloc(sizeof(double)* J);
|
||||||
|
|
||||||
|
//Set sigma
|
||||||
|
|
||||||
|
iter = wt->length[0];
|
||||||
|
dlen = wt->length[J];
|
||||||
|
dout = (double*)malloc(sizeof(double)* dlen);
|
||||||
|
|
||||||
|
for (it = 0; it < J; ++it) {
|
||||||
|
dlen = wt->length[it + 1];
|
||||||
|
for (i = 0; i < dlen; ++i) {
|
||||||
|
dout[i] = fabs(wt->output[iter + i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sigma = sqrt(2.0) * median(dout, dlen) / 0.6745;
|
||||||
|
lnoise[it] = sigma;
|
||||||
|
iter += dlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
M = pow(2.0,J);
|
||||||
|
llen = log((double)wt->modwtsiglength);
|
||||||
|
// Thresholding
|
||||||
|
|
||||||
|
iter = wt->length[0];
|
||||||
|
for (it = 0; it < J; ++it) {
|
||||||
|
sigma = lnoise[it];
|
||||||
|
dlen = wt->length[it + 1];
|
||||||
|
td = sqrt(2.0 * llen / M) * sigma;
|
||||||
|
|
||||||
|
if (!strcmp(thresh, "hard")) {
|
||||||
|
for (i = 0; i < dlen; ++i) {
|
||||||
|
if (fabs(wt->output[iter + i]) < td) {
|
||||||
|
wt->output[iter + i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcmp(thresh, "soft")) {
|
||||||
|
for (i = 0; i < dlen; ++i) {
|
||||||
|
if (fabs(wt->output[iter + i]) < td) {
|
||||||
|
wt->output[iter + i] = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sgn = wt->output[iter + i] >= 0 ? 1 : -1;
|
||||||
|
tmp = sgn * (fabs(wt->output[iter + i]) - td);
|
||||||
|
wt->output[iter + i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iter += wt->length[it + 1];
|
||||||
|
M /= 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
imodwt(wt, denoised);
|
||||||
|
|
||||||
|
free(dout);
|
||||||
|
free(lnoise);
|
||||||
|
wave_free(wave);
|
||||||
|
wt_free(wt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void denoise(denoise_object obj, double *signal,double *denoised) {
|
||||||
|
if(!strcmp(obj->dmethod,"sureshrink")) {
|
||||||
|
if (!strcmp(obj->wmethod, "modwt")) {
|
||||||
|
printf("sureshrink method only works with swt and dwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
sureshrink(signal,obj->N,obj->J,obj->wname,obj->wmethod,obj->ext,obj->thresh,obj->level,denoised);
|
||||||
|
} else if(!strcmp(obj->dmethod,"visushrink")) {
|
||||||
|
if (!strcmp(obj->wmethod, "modwt")) {
|
||||||
|
printf("visushrink method only works with swt and dwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
visushrink(signal,obj->N,obj->J,obj->wname,obj->wmethod,obj->ext,obj->thresh,obj->level,denoised);;
|
||||||
|
} else if(!strcmp(obj->dmethod,"modwtshrink")) {
|
||||||
|
if (strcmp(obj->wmethod, "modwt")) {
|
||||||
|
printf("modwtshrink method only works with modwt. Please use setDenoiseWTMethod to set the correct method\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
modwtshrink(signal,obj->N,obj->J,obj->wname,obj->cmethod,obj->ext,obj->thresh,denoised);;
|
||||||
|
} else {
|
||||||
|
printf("Acceptable Denoising methods are - sureshrink and visushrink\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDenoiseMethod(denoise_object obj, const char *dmethod) {
|
||||||
|
if (!strcmp(dmethod, "sureshrink")) {
|
||||||
|
strcpy(obj->dmethod, "sureshrink");
|
||||||
|
}
|
||||||
|
else if (!strcmp(dmethod, "visushrink")) {
|
||||||
|
strcpy(obj->dmethod, "visushrink");
|
||||||
|
}
|
||||||
|
else if (!strcmp(dmethod, "modwtshrink")) {
|
||||||
|
strcpy(obj->dmethod, "modwtshrink");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Acceptable Denoising methods are - sureshrink, visushrink and modwtshrink\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDenoiseWTMethod(denoise_object obj, const char *wmethod) {
|
||||||
|
if (!strcmp(wmethod, "dwt")) {
|
||||||
|
strcpy(obj->wmethod, "dwt");
|
||||||
|
}
|
||||||
|
else if (!strcmp(wmethod, "swt")) {
|
||||||
|
strcpy(obj->wmethod, "swt");
|
||||||
|
}
|
||||||
|
else if (!strcmp(wmethod, "modwt")) {
|
||||||
|
strcpy(obj->wmethod, "modwt");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Wavelet decomposition method can be one of dwt, modwt or swt.\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDenoiseWTExtension(denoise_object obj, const char *extension) {
|
||||||
|
if (!strcmp(extension, "sym")) {
|
||||||
|
strcpy(obj->ext, "sym");
|
||||||
|
}
|
||||||
|
else if (!strcmp(extension, "per")) {
|
||||||
|
strcpy(obj->ext, "per");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Signal extension can be either per or sym");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDenoiseParameters(denoise_object obj, const char *thresh,const char *level) {
|
||||||
|
|
||||||
|
//Set thresholding
|
||||||
|
if (!strcmp(thresh, "soft")) {
|
||||||
|
strcpy(obj->thresh, "soft");
|
||||||
|
}
|
||||||
|
else if (!strcmp(thresh, "hard")) {
|
||||||
|
strcpy(obj->thresh, "hard");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Thresholding Method - soft or hard");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Noise estimation at the first level or at all levels
|
||||||
|
|
||||||
|
if (!strcmp(level, "first")) {
|
||||||
|
strcpy(obj->level, "first");
|
||||||
|
}
|
||||||
|
else if (!strcmp(level, "all")) {
|
||||||
|
strcpy(obj->level, "all");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Noise Estimation at level - first or all");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void denoise_free(denoise_object object) {
|
||||||
|
free(object);
|
||||||
|
}
|
324
dep/wavelib/auxiliary/waux.c
Normal file
324
dep/wavelib/auxiliary/waux.c
Normal file
@ -0,0 +1,324 @@
|
|||||||
|
#include "../header/wauxlib.h"
|
||||||
|
#include "waux.h"
|
||||||
|
|
||||||
|
int compare_double(const void* a, const void* b)
|
||||||
|
{
|
||||||
|
double arg1 = *(const double*)a;
|
||||||
|
double arg2 = *(const double*)b;
|
||||||
|
|
||||||
|
if (arg1 < arg2) return -1;
|
||||||
|
if (arg1 > arg2) return 1;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double mean(const double* vec, int N) {
|
||||||
|
int i;
|
||||||
|
double m;
|
||||||
|
m = 0.0;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
m+= vec[i];
|
||||||
|
}
|
||||||
|
m = m / N;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
double var(const double* vec, int N) {
|
||||||
|
double v,temp,m;
|
||||||
|
int i;
|
||||||
|
v = 0.0;
|
||||||
|
m = mean(vec,N);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
temp = vec[i] - m;
|
||||||
|
v+= temp*temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = v / N;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double median(double *x, int N) {
|
||||||
|
double sigma;
|
||||||
|
|
||||||
|
qsort(x, N, sizeof(double), compare_double);
|
||||||
|
|
||||||
|
if ((N % 2) == 0) {
|
||||||
|
sigma = (x[N/2 - 1] + x[N/2] ) / 2.0;
|
||||||
|
} else {
|
||||||
|
sigma = x[N/2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return sigma;
|
||||||
|
}
|
||||||
|
|
||||||
|
double mad(double *x, int N) {
|
||||||
|
double sigma;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
sigma = median(x,N);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
x[i] = (x[i] - sigma) > 0 ? (x[i] - sigma) : -(x[i] - sigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
sigma = median(x,N);
|
||||||
|
|
||||||
|
return sigma;
|
||||||
|
}
|
||||||
|
|
||||||
|
int minindex(const double *arr, int N) {
|
||||||
|
double min;
|
||||||
|
int index,i;
|
||||||
|
|
||||||
|
min = DBL_MAX;
|
||||||
|
index = 0;
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
if (arr[i] < min) {
|
||||||
|
min = arr[i];
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDWTAppx(wt_object wt, double *appx,int N) {
|
||||||
|
/*
|
||||||
|
Wavelet decomposition is stored as
|
||||||
|
[A(J) D(J) D(J-1) ..... D(1)] in wt->output vector
|
||||||
|
|
||||||
|
Length of A(J) , N = wt->length[0]
|
||||||
|
*/
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
appx[i] = wt->output[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDWTDetail(wt_object wt, double *detail, int N, int level) {
|
||||||
|
/*
|
||||||
|
returns Detail coefficents at the jth level where j = J,J-1,...,1
|
||||||
|
and Wavelet decomposition is stored as
|
||||||
|
[A(J) D(J) D(J-1) ..... D(1)] in wt->output vector
|
||||||
|
Use getDWTAppx() to get A(J)
|
||||||
|
Level 1 : Length of D(J), ie N, is stored in wt->length[1]
|
||||||
|
Level 2 :Length of D(J-1), ie N, is stored in wt->length[2]
|
||||||
|
....
|
||||||
|
Level J : Length of D(1), ie N, is stored in wt->length[J]
|
||||||
|
*/
|
||||||
|
int i, iter, J;
|
||||||
|
J = wt->J;
|
||||||
|
|
||||||
|
if (level > J || level < 1) {
|
||||||
|
printf("The decomposition only has 1,..,%d levels", J);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = wt->length[0];
|
||||||
|
|
||||||
|
for (i = 1; i < J-level; ++i) {
|
||||||
|
iter += wt->length[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
detail[i] = wt->output[i + iter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDWTRecCoeff(double *coeff,int *length,const char *ctype,const char *ext, int level, int J,double *lpr,
|
||||||
|
double *hpr,int lf,int siglength,double *reccoeff) {
|
||||||
|
|
||||||
|
int i,j,k,det_len,N,l,m,n,v,t,l2;
|
||||||
|
double *out,*X_lp,*filt;
|
||||||
|
out = (double*)malloc(sizeof(double)* (siglength + 1));
|
||||||
|
l2 = lf / 2;
|
||||||
|
m = -2;
|
||||||
|
n = -1;
|
||||||
|
if (!strcmp(ext, "per")) {
|
||||||
|
if (!strcmp((ctype), "appx")) {
|
||||||
|
det_len = length[0];
|
||||||
|
} else {
|
||||||
|
det_len = length[J - level + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
N = 2 * length[J];
|
||||||
|
|
||||||
|
X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||||
|
|
||||||
|
for (i = 0; i < det_len; ++i) {
|
||||||
|
out[i] = coeff[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = level; j > 0; --j) {
|
||||||
|
|
||||||
|
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||||
|
|
||||||
|
if (!strcmp((ctype), "det") && j == level) {
|
||||||
|
filt = hpr;
|
||||||
|
} else {
|
||||||
|
filt = lpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//idwt_per(wt,out, det_len, wt->output + iter, det_len, X_lp);
|
||||||
|
m = -2;
|
||||||
|
n = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < det_len + l2 - 1; ++i) {
|
||||||
|
m += 2;
|
||||||
|
n += 2;
|
||||||
|
X_lp[m] = 0.0;
|
||||||
|
X_lp[n] = 0.0;
|
||||||
|
for (l = 0; l < l2; ++l) {
|
||||||
|
t = 2 * l;
|
||||||
|
if ((i - l) >= 0 && (i - l) < det_len) {
|
||||||
|
X_lp[m] += filt[t] * out[i - l];
|
||||||
|
X_lp[n] += filt[t + 1] * out[i - l];
|
||||||
|
}
|
||||||
|
else if ((i - l) >= det_len && (i-l) < det_len + lf - 1) {
|
||||||
|
X_lp[m] += filt[t] * out[i - l - det_len];
|
||||||
|
X_lp[n] += filt[t + 1] * out[i - l - det_len];
|
||||||
|
}
|
||||||
|
else if ((i - l) < 0 && (i-l) > -l2) {
|
||||||
|
X_lp[m] += filt[t] * out[det_len + i - l] ;
|
||||||
|
X_lp[n] += filt[t + 1] * out[det_len + i - l];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = lf/2 - 1; k < 2 * det_len + lf/2 - 1; ++k) {
|
||||||
|
out[k - lf/2 + 1] = X_lp[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j != 1) {
|
||||||
|
det_len = length[J - j + 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(X_lp);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (!strcmp(ext, "sym")) {
|
||||||
|
if (!strcmp((ctype), "appx")) {
|
||||||
|
det_len = length[0];
|
||||||
|
} else {
|
||||||
|
det_len = length[J - level + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
N = 2 * length[J] - 1;
|
||||||
|
|
||||||
|
X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||||
|
|
||||||
|
for (i = 0; i < det_len; ++i) {
|
||||||
|
out[i] = coeff[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = level; j > 0; --j) {
|
||||||
|
|
||||||
|
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||||
|
|
||||||
|
if (!strcmp((ctype), "det") && j == level) {
|
||||||
|
filt = hpr;
|
||||||
|
} else {
|
||||||
|
filt = lpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//idwt_sym(wt, out, det_len, wt->output + iter, det_len, X_lp);
|
||||||
|
|
||||||
|
m = -2;
|
||||||
|
n = -1;
|
||||||
|
|
||||||
|
for (v = 0; v < det_len; ++v) {
|
||||||
|
i = v;
|
||||||
|
m += 2;
|
||||||
|
n += 2;
|
||||||
|
X_lp[m] = 0.0;
|
||||||
|
X_lp[n] = 0.0;
|
||||||
|
for (l = 0; l < lf / 2; ++l) {
|
||||||
|
t = 2 * l;
|
||||||
|
if ((i - l) >= 0 && (i - l) < det_len) {
|
||||||
|
X_lp[m] += filt[t] * out[i - l];
|
||||||
|
X_lp[n] += filt[t + 1] * out[i - l];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = lf-2; k < 2 * det_len; ++k) {
|
||||||
|
out[k - lf + 2] = X_lp[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (j != 1) {
|
||||||
|
det_len = length[J - j + 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(X_lp);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Signal extension can be either per or sym");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < siglength; ++i) {
|
||||||
|
reccoeff[i] = out[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
free(out);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void autocovar(const double* vec,int N, double* acov,int M) {
|
||||||
|
double m,temp1,temp2;
|
||||||
|
int i,t;
|
||||||
|
m = mean(vec,N);
|
||||||
|
|
||||||
|
if ( M > N) {
|
||||||
|
M = N-1;
|
||||||
|
printf("\n Lag is greater than the length N of the input vector. It is automatically set to length N - 1.\n");
|
||||||
|
printf("\n The Output Vector only contains N calculated values.");
|
||||||
|
} else if ( M < 0) {
|
||||||
|
M = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < M;i++) {
|
||||||
|
acov[i] = 0.0;
|
||||||
|
for (t = 0; t < N-i;t++) {
|
||||||
|
temp1 = vec[t] - m;
|
||||||
|
temp2 = vec[t+i] - m;
|
||||||
|
acov[i]+= temp1*temp2;
|
||||||
|
}
|
||||||
|
acov[i] = acov[i] / N;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void autocorr(const double* vec,int N,double* acorr, int M) {
|
||||||
|
double var;
|
||||||
|
int i;
|
||||||
|
if (M > N) {
|
||||||
|
M = N - 1;
|
||||||
|
printf("\n Lag is greater than the length N of the input vector. It is automatically set to length N - 1.\n");
|
||||||
|
printf("\n The Output Vector only contains N calculated values.");
|
||||||
|
}
|
||||||
|
else if (M < 0) {
|
||||||
|
M = 0;
|
||||||
|
}
|
||||||
|
autocovar(vec,N,acorr,M);
|
||||||
|
var = acorr[0];
|
||||||
|
acorr[0] = 1.0;
|
||||||
|
|
||||||
|
for(i = 1; i < M; i++) {
|
||||||
|
acorr[i] = acorr[i]/var;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
dep/wavelib/auxiliary/waux.h
Normal file
47
dep/wavelib/auxiliary/waux.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* waux.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 22, 2017
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AUXILIARY_WAUX_H_
|
||||||
|
#define AUXILIARY_WAUX_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int compare_double(const void* a, const void* b);
|
||||||
|
|
||||||
|
double mean(const double* vec, int N);
|
||||||
|
|
||||||
|
double var(const double* vec, int N);
|
||||||
|
|
||||||
|
double median(double *x, int N);
|
||||||
|
|
||||||
|
int minindex(const double *arr, int N);
|
||||||
|
|
||||||
|
void getDWTAppx(wt_object wt, double *appx,int N);
|
||||||
|
|
||||||
|
void getDWTDetail(wt_object wt, double *detail, int N, int level);
|
||||||
|
|
||||||
|
void autocovar(const double* vec,int N,double* acov, int M);
|
||||||
|
|
||||||
|
void autocorr(const double* vec,int N,double* acorr, int M);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AUXILIARY_WAUX_H_ */
|
17
dep/wavelib/config.sh
Executable file
17
dep/wavelib/config.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cmd=${1}
|
||||||
|
package=wavelib
|
||||||
|
address=/opt/stow
|
||||||
|
targetdir=/usr/local
|
||||||
|
|
||||||
|
if [[ ${cmd} == "configure" && ! -d "build/" ]]; then
|
||||||
|
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/${package} -DCMAKE_BUILD_TYPE=Release
|
||||||
|
elif [[ ${cmd} == "configure" ]]; then
|
||||||
|
cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/${package} -DCMAKE_BUILD_TYPE=Release
|
||||||
|
elif [[ ${cmd} == "build" ]]; then
|
||||||
|
cd build && make
|
||||||
|
elif [[ ${cmd} == "install" ]]; then
|
||||||
|
cd build && sudo make install
|
||||||
|
sudo stow --dir=${address} --target=${targetdir} ${package}
|
||||||
|
fi
|
60
dep/wavelib/header/wauxlib.h
Normal file
60
dep/wavelib/header/wauxlib.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2017, Rafat Hussain
|
||||||
|
*/
|
||||||
|
#ifndef WAUXLIB_H_
|
||||||
|
#define WAUXLIB_H_
|
||||||
|
|
||||||
|
#include "wavelib.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct denoise_set* denoise_object;
|
||||||
|
|
||||||
|
denoise_object denoise_init(int length, int J,const char* wname);
|
||||||
|
|
||||||
|
struct denoise_set{
|
||||||
|
int N; //signal length
|
||||||
|
int J; // Levels of Wavelet decomposition
|
||||||
|
char wname[10]; //Wavelet name
|
||||||
|
char wmethod[10]; //Wavelet decomposition method - dwt or swt
|
||||||
|
char cmethod[10]; //Cnvolution Method - direct or fft . Available only for modwt.
|
||||||
|
// SWT and DWT only use direct method.
|
||||||
|
char ext[10]; // Signal Extension - sym or per
|
||||||
|
char thresh[10]; // thresholding - soft or hard
|
||||||
|
char level[10]; // Noise Estimation level - first or all
|
||||||
|
char dmethod[20]; //Denoising Method -sureshrink or visushrink
|
||||||
|
//double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
void visushrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised);
|
||||||
|
|
||||||
|
void sureshrink(double *signal,int N,int J,const char *wname,const char *method,const char *ext,const char *thresh,const char *level,double *denoised);
|
||||||
|
|
||||||
|
void modwtshrink(double *signal, int N, int J, const char *wname, const char *cmethod, const char *ext, const char *thresh, double *denoised);
|
||||||
|
|
||||||
|
void denoise(denoise_object obj, double *signal,double *denoised);
|
||||||
|
|
||||||
|
void setDenoiseMethod(denoise_object obj, const char *dmethod);
|
||||||
|
|
||||||
|
void setDenoiseWTMethod(denoise_object obj, const char *wmethod);
|
||||||
|
|
||||||
|
void setDenoiseWTExtension(denoise_object obj, const char *extension);
|
||||||
|
|
||||||
|
void setDenoiseParameters(denoise_object obj, const char *thresh,const char *level);
|
||||||
|
|
||||||
|
void denoise_free(denoise_object object);
|
||||||
|
|
||||||
|
void getDWTRecCoeff(double *coeff,int *length,const char *ctype,const char *ext, int level, int J,double *lpr,
|
||||||
|
double *hpr,int lf,int siglength,double *reccoeff);
|
||||||
|
|
||||||
|
double mad(double *x, int N);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAUXLIB_H_ */
|
317
dep/wavelib/header/wavelib.h
Executable file
317
dep/wavelib/header/wavelib.h
Executable file
@ -0,0 +1,317 @@
|
|||||||
|
#ifndef WAVELIB_H_
|
||||||
|
#define WAVELIB_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(disable : 4200)
|
||||||
|
#pragma warning(disable : 4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef fft_type
|
||||||
|
#define fft_type double
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef cplx_type
|
||||||
|
#define cplx_type double
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct cplx_t {
|
||||||
|
cplx_type re;
|
||||||
|
cplx_type im;
|
||||||
|
} cplx_data;
|
||||||
|
|
||||||
|
typedef struct wave_set* wave_object;
|
||||||
|
|
||||||
|
wave_object wave_init(const char* wname);
|
||||||
|
|
||||||
|
struct wave_set{
|
||||||
|
char wname[50];
|
||||||
|
int filtlength;// When all filters are of the same length. [Matlab uses zero-padding to make all filters of the same length]
|
||||||
|
int lpd_len;// Default filtlength = lpd_len = lpr_len = hpd_len = hpr_len
|
||||||
|
int hpd_len;
|
||||||
|
int lpr_len;
|
||||||
|
int hpr_len;
|
||||||
|
double *lpd;
|
||||||
|
double *hpd;
|
||||||
|
double *lpr;
|
||||||
|
double *hpr;
|
||||||
|
double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct fft_t {
|
||||||
|
fft_type re;
|
||||||
|
fft_type im;
|
||||||
|
} fft_data;
|
||||||
|
|
||||||
|
typedef struct fft_set* fft_object;
|
||||||
|
|
||||||
|
fft_object fft_init(int N, int sgn);
|
||||||
|
|
||||||
|
struct fft_set{
|
||||||
|
int N;
|
||||||
|
int sgn;
|
||||||
|
int factors[64];
|
||||||
|
int lf;
|
||||||
|
int lt;
|
||||||
|
fft_data twiddle[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct fft_real_set* fft_real_object;
|
||||||
|
|
||||||
|
fft_real_object fft_real_init(int N, int sgn);
|
||||||
|
|
||||||
|
struct fft_real_set{
|
||||||
|
fft_object cobj;
|
||||||
|
fft_data twiddle2[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct conv_set* conv_object;
|
||||||
|
|
||||||
|
conv_object conv_init(int N, int L);
|
||||||
|
|
||||||
|
struct conv_set{
|
||||||
|
fft_real_object fobj;
|
||||||
|
fft_real_object iobj;
|
||||||
|
int ilen1;
|
||||||
|
int ilen2;
|
||||||
|
int clen;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct wt_set* wt_object;
|
||||||
|
|
||||||
|
wt_object wt_init(wave_object wave,const char* method, int siglength, int J);
|
||||||
|
|
||||||
|
struct wt_set{
|
||||||
|
wave_object wave;
|
||||||
|
conv_object cobj;
|
||||||
|
char method[10];
|
||||||
|
int siglength;// Length of the original signal.
|
||||||
|
int modwtsiglength; // Modified signal length for MODWT
|
||||||
|
int outlength;// Length of the output DWT vector
|
||||||
|
int lenlength;// Length of the Output Dimension Vector "length"
|
||||||
|
int J; // Number of decomposition Levels
|
||||||
|
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||||
|
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||||
|
char ext[10];// Type of Extension used - "per" or "sym"
|
||||||
|
char cmethod[10]; // Convolution Method - "direct" or "FFT"
|
||||||
|
|
||||||
|
int N; //
|
||||||
|
int cfftset;
|
||||||
|
int zpad;
|
||||||
|
int length[102];
|
||||||
|
double *output;
|
||||||
|
double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct wtree_set* wtree_object;
|
||||||
|
|
||||||
|
wtree_object wtree_init(wave_object wave, int siglength, int J);
|
||||||
|
|
||||||
|
struct wtree_set{
|
||||||
|
wave_object wave;
|
||||||
|
conv_object cobj;
|
||||||
|
char method[10];
|
||||||
|
int siglength;// Length of the original signal.
|
||||||
|
int outlength;// Length of the output DWT vector
|
||||||
|
int lenlength;// Length of the Output Dimension Vector "length"
|
||||||
|
int J; // Number of decomposition Levels
|
||||||
|
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||||
|
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||||
|
char ext[10];// Type of Extension used - "per" or "sym"
|
||||||
|
|
||||||
|
int N; //
|
||||||
|
int nodes;
|
||||||
|
int cfftset;
|
||||||
|
int zpad;
|
||||||
|
int length[102];
|
||||||
|
double *output;
|
||||||
|
int *nodelength;
|
||||||
|
int *coeflength;
|
||||||
|
double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct wpt_set* wpt_object;
|
||||||
|
|
||||||
|
wpt_object wpt_init(wave_object wave, int siglength, int J);
|
||||||
|
|
||||||
|
struct wpt_set{
|
||||||
|
wave_object wave;
|
||||||
|
conv_object cobj;
|
||||||
|
int siglength;// Length of the original signal.
|
||||||
|
int outlength;// Length of the output DWT vector
|
||||||
|
int lenlength;// Length of the Output Dimension Vector "length"
|
||||||
|
int J; // Number of decomposition Levels
|
||||||
|
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||||
|
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||||
|
char ext[10];// Type of Extension used - "per" or "sym"
|
||||||
|
char entropy[20];
|
||||||
|
double eparam;
|
||||||
|
|
||||||
|
int N; //
|
||||||
|
int nodes;
|
||||||
|
int length[102];
|
||||||
|
double *output;
|
||||||
|
double *costvalues;
|
||||||
|
double *basisvector;
|
||||||
|
int *nodeindex;
|
||||||
|
int *numnodeslevel;
|
||||||
|
int *coeflength;
|
||||||
|
double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct cwt_set* cwt_object;
|
||||||
|
|
||||||
|
cwt_object cwt_init(const char* wave, double param, int siglength,double dt, int J);
|
||||||
|
|
||||||
|
struct cwt_set{
|
||||||
|
char wave[10];// Wavelet - morl/morlet,paul,dog/dgauss
|
||||||
|
int siglength;// Length of Input Data
|
||||||
|
int J;// Total Number of Scales
|
||||||
|
double s0;// Smallest scale. It depends on the sampling rate. s0 <= 2 * dt for most wavelets
|
||||||
|
double dt;// Sampling Rate
|
||||||
|
double dj;// Separation between scales. eg., scale = s0 * 2 ^ ( [0:N-1] *dj ) or scale = s0 *[0:N-1] * dj
|
||||||
|
char type[10];// Scale Type - Power or Linear
|
||||||
|
int pow;// Base of Power in case type = pow. Typical value is pow = 2
|
||||||
|
int sflag;
|
||||||
|
int pflag;
|
||||||
|
int npad;
|
||||||
|
int mother;
|
||||||
|
double m;// Wavelet parameter param
|
||||||
|
double smean;// Input Signal mean
|
||||||
|
|
||||||
|
cplx_data *output;
|
||||||
|
double *scale;
|
||||||
|
double *period;
|
||||||
|
double *coi;
|
||||||
|
double params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct wt2_set* wt2_object;
|
||||||
|
|
||||||
|
wt2_object wt2_init(wave_object wave, const char* method, int rows, int cols, int J);
|
||||||
|
|
||||||
|
struct wt2_set{
|
||||||
|
wave_object wave;
|
||||||
|
char method[10];
|
||||||
|
int rows;// Matrix Number of rows
|
||||||
|
int cols; // Matrix Number of columns
|
||||||
|
int outlength;// Length of the output DWT vector
|
||||||
|
int J; // Number of decomposition Levels
|
||||||
|
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||||
|
char ext[10];// Type of Extension used - "per" or "sym"
|
||||||
|
int coeffaccesslength;
|
||||||
|
|
||||||
|
int N; //
|
||||||
|
int *dimensions;
|
||||||
|
int *coeffaccess;
|
||||||
|
int params[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
void dwt(wt_object wt, const double *inp);
|
||||||
|
|
||||||
|
void idwt(wt_object wt, double *dwtop);
|
||||||
|
|
||||||
|
double *getDWTmra(wt_object wt, double *wavecoeffs);
|
||||||
|
|
||||||
|
void wtree(wtree_object wt, const double *inp);
|
||||||
|
|
||||||
|
void dwpt(wpt_object wt, const double *inp);
|
||||||
|
|
||||||
|
void idwpt(wpt_object wt, double *dwtop);
|
||||||
|
|
||||||
|
void swt(wt_object wt, const double *inp);
|
||||||
|
|
||||||
|
void iswt(wt_object wt, double *swtop);
|
||||||
|
|
||||||
|
double *getSWTmra(wt_object wt, double *wavecoeffs);
|
||||||
|
|
||||||
|
void modwt(wt_object wt, const double *inp);
|
||||||
|
|
||||||
|
void imodwt(wt_object wt, double *dwtop);
|
||||||
|
|
||||||
|
double* getMODWTmra(wt_object wt, double *wavecoeffs);
|
||||||
|
|
||||||
|
void setDWTExtension(wt_object wt, const char *extension);
|
||||||
|
|
||||||
|
void setWTREEExtension(wtree_object wt, const char *extension);
|
||||||
|
|
||||||
|
void setDWPTExtension(wpt_object wt, const char *extension);
|
||||||
|
|
||||||
|
void setDWT2Extension(wt2_object wt, const char *extension);
|
||||||
|
|
||||||
|
void setDWPTEntropy(wpt_object wt, const char *entropy, double eparam);
|
||||||
|
|
||||||
|
void setWTConv(wt_object wt, const char *cmethod);
|
||||||
|
|
||||||
|
int getWTREENodelength(wtree_object wt, int X);
|
||||||
|
|
||||||
|
void getWTREECoeffs(wtree_object wt, int X, int Y, double *coeffs, int N);
|
||||||
|
|
||||||
|
int getDWPTNodelength(wpt_object wt, int X);
|
||||||
|
|
||||||
|
void getDWPTCoeffs(wpt_object wt, int X, int Y, double *coeffs, int N);
|
||||||
|
|
||||||
|
void setCWTScales(cwt_object wt, double s0, double dj, const char *type, int power);
|
||||||
|
|
||||||
|
void setCWTScaleVector(cwt_object wt, const double *scale, int J, double s0, double dj);
|
||||||
|
|
||||||
|
void setCWTPadding(cwt_object wt, int pad);
|
||||||
|
|
||||||
|
void cwt(cwt_object wt, const double *inp);
|
||||||
|
|
||||||
|
void icwt(cwt_object wt, double *cwtop);
|
||||||
|
|
||||||
|
int getCWTScaleLength(int N);
|
||||||
|
|
||||||
|
double* dwt2(wt2_object wt, double *inp);
|
||||||
|
|
||||||
|
void idwt2(wt2_object wt,double *wavecoeff, double *oup);
|
||||||
|
|
||||||
|
double* swt2(wt2_object wt, double *inp);
|
||||||
|
|
||||||
|
void iswt2(wt2_object wt, double *wavecoeffs, double *oup);
|
||||||
|
|
||||||
|
double* modwt2(wt2_object wt, double *inp);
|
||||||
|
|
||||||
|
void imodwt2(wt2_object wt, double *wavecoeff, double *oup);
|
||||||
|
|
||||||
|
double* getWT2Coeffs(wt2_object wt,double* wcoeffs, int level,char *type, int *rows, int *cols);
|
||||||
|
|
||||||
|
void dispWT2Coeffs(double *A, int row, int col);
|
||||||
|
|
||||||
|
void wave_summary(wave_object obj);
|
||||||
|
|
||||||
|
void wt_summary(wt_object wt);
|
||||||
|
|
||||||
|
void wtree_summary(wtree_object wt);
|
||||||
|
|
||||||
|
void wpt_summary(wpt_object wt);
|
||||||
|
|
||||||
|
void cwt_summary(cwt_object wt);
|
||||||
|
|
||||||
|
void wt2_summary(wt2_object wt);
|
||||||
|
|
||||||
|
void wave_free(wave_object object);
|
||||||
|
|
||||||
|
void wt_free(wt_object object);
|
||||||
|
|
||||||
|
void wtree_free(wtree_object object);
|
||||||
|
|
||||||
|
void wpt_free(wpt_object object);
|
||||||
|
|
||||||
|
void cwt_free(cwt_object object);
|
||||||
|
|
||||||
|
void wt2_free(wt2_object wt);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVELIB_H_ */
|
52
dep/wavelib/src/CMakeLists.txt
Normal file
52
dep/wavelib/src/CMakeLists.txt
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# 设定源文件文件夹
|
||||||
|
aux_source_directory(. WAVE_SRC)
|
||||||
|
|
||||||
|
# 以下部分为库的编译
|
||||||
|
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||||
|
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||||
|
add_library(wavelib SHARED ${WAVE_SRC})
|
||||||
|
# 首先添加静态库的生成命令
|
||||||
|
add_library(wavelib_static STATIC ${WAVE_SRC})
|
||||||
|
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||||
|
set_target_properties(wavelib_static PROPERTIES OUTPUT_NAME "wavelib")
|
||||||
|
# 设置输出目标属性以同时输出动态库与静态库
|
||||||
|
set_target_properties(wavelib PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
set_target_properties(wavelib_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
# 设置动态库的版本号
|
||||||
|
set_target_properties(wavelib PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||||
|
# 设置库文件的输出地址
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
# 设置编译选项
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||||
|
|
||||||
|
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||||
|
|
||||||
|
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
INSTALL_DESTINATION ${CONFIG_FILE_PATH}
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||||
|
|
||||||
|
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
# 库的安装命令
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS wavelib DESTINATION lib)
|
||||||
|
install(TARGETS wavelib_static DESTINATION lib)
|
||||||
|
else()
|
||||||
|
install(TARGETS wavelib wavelib_static
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib)
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
install(FILES
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
endif()
|
||||||
|
# 头文件安装命令
|
||||||
|
install(FILES ../header/wavelib.h DESTINATION include)
|
||||||
|
install(FILES ../header/wauxlib.h DESTINATION include)
|
210
dep/wavelib/src/conv.c
Normal file
210
dep/wavelib/src/conv.c
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
/*
|
||||||
|
* conv.c
|
||||||
|
*
|
||||||
|
* Created on: May 1, 2013
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "conv.h"
|
||||||
|
|
||||||
|
int factorf(int M) {
|
||||||
|
int N;
|
||||||
|
N = M;
|
||||||
|
while (N%7 == 0){
|
||||||
|
N = N/7;
|
||||||
|
}
|
||||||
|
while (N%3 == 0){
|
||||||
|
N = N/3;
|
||||||
|
}
|
||||||
|
while (N%5 == 0){
|
||||||
|
N = N/5;
|
||||||
|
}
|
||||||
|
while (N%2 == 0){
|
||||||
|
N = N/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int findnext(int M) {
|
||||||
|
int N;
|
||||||
|
N = M;
|
||||||
|
|
||||||
|
while (factorf(N) != 1) {
|
||||||
|
++N;
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int findnexte(int M) {
|
||||||
|
int N;
|
||||||
|
N = M;
|
||||||
|
|
||||||
|
while (factorf(N) != 1 || N%2 != 0) {
|
||||||
|
++N;
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
conv_object conv_init(int N, int L) {
|
||||||
|
|
||||||
|
conv_object obj = NULL;
|
||||||
|
int conv_len;
|
||||||
|
conv_len = N + L - 1;
|
||||||
|
|
||||||
|
obj = (conv_object) malloc (sizeof(struct conv_set));
|
||||||
|
|
||||||
|
//obj->clen = npow2(conv_len);
|
||||||
|
//obj->clen = conv_len;
|
||||||
|
obj->clen = findnexte(conv_len);
|
||||||
|
obj->ilen1 = N;
|
||||||
|
obj->ilen2 = L;
|
||||||
|
|
||||||
|
obj->fobj = fft_real_init(obj->clen,1);
|
||||||
|
obj->iobj = fft_real_init(obj->clen,-1);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void conv_directx(fft_type *inp1,int N, fft_type *inp2, int L,fft_type *oup){
|
||||||
|
int M,k,n;
|
||||||
|
|
||||||
|
M = N + L - 1;
|
||||||
|
|
||||||
|
for (k = 0; k < M;++k) {
|
||||||
|
oup[k] = 0.0;
|
||||||
|
for ( n = 0; n < N; ++n) {
|
||||||
|
if ( (k-n) >= 0 && (k-n) < L ) {
|
||||||
|
oup[k]+= inp1[n] * inp2[k-n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void conv_direct(fft_type *inp1,int N, fft_type *inp2, int L,fft_type *oup) {
|
||||||
|
|
||||||
|
int M,k,m,i;
|
||||||
|
fft_type t1,tmin;
|
||||||
|
|
||||||
|
M = N + L -1;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
if (N >= L) {
|
||||||
|
|
||||||
|
for (k = 0; k < L; k++) {
|
||||||
|
oup[k] = 0.0;
|
||||||
|
for (m = 0; m <= k;m++) {
|
||||||
|
oup[k]+= inp1[m] * inp2[k-m];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = L; k < M; k++) {
|
||||||
|
oup[k] = 0.0;
|
||||||
|
i++;
|
||||||
|
t1 = L + i;
|
||||||
|
tmin = MIN(t1,N);
|
||||||
|
for (m = i; m < tmin;m++) {
|
||||||
|
oup[k]+= inp1[m] * inp2[k-m];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for (k = 0; k < N; k++) {
|
||||||
|
oup[k] = 0.0;
|
||||||
|
for (m = 0; m <= k;m++) {
|
||||||
|
oup[k]+= inp2[m] * inp1[k-m];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = N; k < M; k++) {
|
||||||
|
oup[k] = 0.0;
|
||||||
|
i++;
|
||||||
|
t1 = N + i;
|
||||||
|
tmin = MIN(t1,L);
|
||||||
|
for (m = i; m < tmin;m++) {
|
||||||
|
oup[k]+= inp2[m] * inp1[k-m];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup) {
|
||||||
|
int i,N,L1,L2,ls;
|
||||||
|
fft_type* a;
|
||||||
|
fft_type* b;
|
||||||
|
fft_data* c;
|
||||||
|
fft_data* ao;
|
||||||
|
fft_data* bo;
|
||||||
|
fft_type* co;
|
||||||
|
|
||||||
|
N = obj->clen;
|
||||||
|
L1 = obj->ilen1;
|
||||||
|
L2 = obj->ilen2;
|
||||||
|
ls = L1 + L2 - 1;
|
||||||
|
|
||||||
|
a = (fft_type*) malloc (sizeof(fft_data) * N);
|
||||||
|
b = (fft_type*) malloc (sizeof(fft_data) * N);
|
||||||
|
c = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
ao = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
bo = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
co = (fft_type*) malloc (sizeof(fft_data) * N);
|
||||||
|
|
||||||
|
for (i = 0; i < N;i++) {
|
||||||
|
if (i < L1) {
|
||||||
|
a[i] = inp1[i];
|
||||||
|
} else {
|
||||||
|
a[i] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < L2) {
|
||||||
|
b[i] = inp2[i];
|
||||||
|
} else {
|
||||||
|
b[i] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_r2c_exec(obj->fobj,a,ao);
|
||||||
|
fft_r2c_exec(obj->fobj,b,bo);
|
||||||
|
|
||||||
|
for (i = 0; i < N;i++) {
|
||||||
|
c[i].re = ao[i].re * bo[i].re - ao[i].im * bo[i].im;
|
||||||
|
c[i].im = ao[i].im * bo[i].re + ao[i].re * bo[i].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_c2r_exec(obj->iobj,c,co);
|
||||||
|
|
||||||
|
for (i = 0; i < ls;i++) {
|
||||||
|
oup[i] = co[i]/N;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(a);
|
||||||
|
free(b);
|
||||||
|
free(c);
|
||||||
|
free(ao);
|
||||||
|
free(bo);
|
||||||
|
free(co);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void free_conv(conv_object object) {
|
||||||
|
free_real_fft(object->fobj);
|
||||||
|
free_real_fft(object->iobj);
|
||||||
|
free(object);
|
||||||
|
}
|
47
dep/wavelib/src/conv.h
Normal file
47
dep/wavelib/src/conv.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* conv.h
|
||||||
|
*
|
||||||
|
* Created on: May 1, 2013
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONV_H_
|
||||||
|
#define CONV_H_
|
||||||
|
|
||||||
|
#include "real.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||||
|
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||||
|
|
||||||
|
conv_object conv_init(int N, int L);
|
||||||
|
|
||||||
|
int factorf(int M);
|
||||||
|
|
||||||
|
int findnext(int M);
|
||||||
|
|
||||||
|
int findnexte(int M);
|
||||||
|
|
||||||
|
void conv_direct(fft_type *inp1,int N, fft_type *inp2, int L,fft_type *oup);
|
||||||
|
|
||||||
|
void conv_directx(fft_type *inp1,int N, fft_type *inp2, int L,fft_type *oup);
|
||||||
|
|
||||||
|
//void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup);
|
||||||
|
|
||||||
|
//void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup);
|
||||||
|
|
||||||
|
void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup);
|
||||||
|
|
||||||
|
//void free_conv(conv_object object);
|
||||||
|
|
||||||
|
void free_conv(conv_object object);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONV_H_ */
|
398
dep/wavelib/src/cwt.c
Normal file
398
dep/wavelib/src/cwt.c
Normal file
@ -0,0 +1,398 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2015, Rafat Hussain
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
This code is a C translation ( with some modifications) of Wavelet Software provided by
|
||||||
|
C. Torrence and G. Compo, and is available at URL: http://atoc.colorado.edu/research/wavelets/''.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cwt.h"
|
||||||
|
|
||||||
|
double factorial(int N) {
|
||||||
|
static const double fact[41] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000,
|
||||||
|
20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000.0, 1124000727777607680000.0,
|
||||||
|
25852016738884976640000.0, 620448401733239439360000.0, 15511210043330985984000000.0, 403291461126605635584000000.0, 10888869450418352160768000000.0,
|
||||||
|
304888344611713860501504000000.0, 8841761993739701954543616000000.0, 265252859812191058636308480000000.0, 8222838654177922817725562880000000.0,
|
||||||
|
263130836933693530167218012160000000.0, 8683317618811886495518194401280000000.0, 295232799039604140847618609643520000000.0, 10333147966386144929666651337523200000000.0,
|
||||||
|
371993326789901217467999448150835200000000.0, 13763753091226345046315979581580902400000000.0, 523022617466601111760007224100074291200000000.0,
|
||||||
|
20397882081197443358640281739902897356800000000.0, 815915283247897734345611269596115894272000000000.0 };
|
||||||
|
|
||||||
|
if (N > 40 || N < 0) {
|
||||||
|
printf("This program is only valid for 0 <= N <= 40 \n");
|
||||||
|
return -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fact[N];
|
||||||
|
|
||||||
|
}
|
||||||
|
static void wave_function(int nk, double dt,int mother, double param,double scale1, double *kwave, double pi,double *period1,
|
||||||
|
double *coi1, fft_data *daughter) {
|
||||||
|
|
||||||
|
double norm, expnt, fourier_factor;
|
||||||
|
int k, m;
|
||||||
|
double temp;
|
||||||
|
int sign,re;
|
||||||
|
|
||||||
|
|
||||||
|
if (mother == 0) {
|
||||||
|
//MORLET
|
||||||
|
if (param < 0.0) {
|
||||||
|
param = 6.0;
|
||||||
|
}
|
||||||
|
norm = sqrt(2.0*pi*scale1 / dt)*pow(pi,-0.25);
|
||||||
|
|
||||||
|
for (k = 1; k <= nk / 2 + 1; ++k) {
|
||||||
|
temp = (scale1*kwave[k-1] - param);
|
||||||
|
expnt = -0.5 * temp * temp;
|
||||||
|
daughter[k - 1].re = norm * exp(expnt);
|
||||||
|
daughter[k - 1].im = 0.0;
|
||||||
|
}
|
||||||
|
for (k = nk / 2 + 2; k <= nk; ++k) {
|
||||||
|
daughter[k - 1].re = daughter[k - 1].im = 0.0;
|
||||||
|
}
|
||||||
|
fourier_factor = (4.0*pi) / (param + sqrt(2.0 + param*param));
|
||||||
|
*period1 = scale1*fourier_factor;
|
||||||
|
*coi1 = fourier_factor / sqrt(2.0);
|
||||||
|
}
|
||||||
|
else if (mother == 1) {
|
||||||
|
// PAUL
|
||||||
|
if (param < 0.0) {
|
||||||
|
param = 4.0;
|
||||||
|
}
|
||||||
|
m = (int)param;
|
||||||
|
norm = sqrt(2.0*pi*scale1 / dt)*(pow(2.0,(double)m) / sqrt((double)(m*factorial(2 * m - 1))));
|
||||||
|
for (k = 1; k <= nk / 2 + 1; ++k) {
|
||||||
|
temp = scale1 * kwave[k - 1];
|
||||||
|
expnt = - temp;
|
||||||
|
daughter[k - 1].re = norm * pow(temp,(double)m) * exp(expnt);
|
||||||
|
daughter[k - 1].im = 0.0;
|
||||||
|
}
|
||||||
|
for (k = nk / 2 + 2; k <= nk; ++k) {
|
||||||
|
daughter[k - 1].re = daughter[k - 1].im = 0.0;
|
||||||
|
}
|
||||||
|
fourier_factor = (4.0*pi) / (2.0 * m + 1.0);
|
||||||
|
*period1 = scale1*fourier_factor;
|
||||||
|
*coi1 = fourier_factor * sqrt(2.0);
|
||||||
|
}
|
||||||
|
else if (mother == 2) {
|
||||||
|
if (param < 0.0) {
|
||||||
|
param = 2.0;
|
||||||
|
}
|
||||||
|
m = (int)param;
|
||||||
|
|
||||||
|
if (m % 2 == 0) {
|
||||||
|
re = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
re = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m % 4 == 0 || m % 4 == 1) {
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
norm = sqrt(2.0*pi*scale1 / dt)*sqrt(1.0 / cwt_gamma(m + 0.50));
|
||||||
|
norm *= sign;
|
||||||
|
|
||||||
|
if (re == 1) {
|
||||||
|
for (k = 1; k <= nk; ++k) {
|
||||||
|
temp = scale1 * kwave[k - 1];
|
||||||
|
daughter[k - 1].re = norm*pow(temp,(double)m)*exp(-0.50*pow(temp,2.0));
|
||||||
|
daughter[k - 1].im = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (re == 0) {
|
||||||
|
for (k = 1; k <= nk; ++k) {
|
||||||
|
temp = scale1 * kwave[k - 1];
|
||||||
|
daughter[k - 1].re = 0.0;
|
||||||
|
daughter[k - 1].im = norm*pow(temp, (double)m)*exp(-0.50*pow(temp, 2.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fourier_factor = (2.0*pi) * sqrt(2.0 / (2.0 * m + 1.0));
|
||||||
|
*period1 = scale1*fourier_factor;
|
||||||
|
*coi1 = fourier_factor / sqrt(2.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cwavelet(const double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||||
|
double *wave, double *scale, double *period, double *coi) {
|
||||||
|
|
||||||
|
int i, j, k, iter;
|
||||||
|
double ymean, freq1, pi, period1, coi1;
|
||||||
|
double tmp1, tmp2;
|
||||||
|
double scale1;
|
||||||
|
double *kwave;
|
||||||
|
fft_object obj, iobj;
|
||||||
|
fft_data *ypad, *yfft,*daughter;
|
||||||
|
|
||||||
|
(void)s0; (void)dj; /* yes, we need these parameters unused */
|
||||||
|
|
||||||
|
pi = 4.0 * atan(1.0);
|
||||||
|
|
||||||
|
if (npad < N) {
|
||||||
|
printf("npad must be >= N \n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = fft_init(npad, 1);
|
||||||
|
iobj = fft_init(npad, -1);
|
||||||
|
|
||||||
|
ypad = (fft_data*)malloc(sizeof(fft_data)* npad);
|
||||||
|
yfft = (fft_data*)malloc(sizeof(fft_data)* npad);
|
||||||
|
daughter = (fft_data*)malloc(sizeof(fft_data)* npad);
|
||||||
|
kwave = (double*)malloc(sizeof(double)* npad);
|
||||||
|
|
||||||
|
ymean = 0.0;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
ymean += y[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ymean /= N;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
ypad[i].re = y[i] - ymean;
|
||||||
|
ypad[i].im = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = N; i < npad; ++i) {
|
||||||
|
ypad[i].re = ypad[i].im = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Find FFT of the input y (ypad)
|
||||||
|
|
||||||
|
fft_exec(obj, ypad, yfft);
|
||||||
|
|
||||||
|
for (i = 0; i < npad; ++i) {
|
||||||
|
yfft[i].re /= (double) npad;
|
||||||
|
yfft[i].im /= (double) npad;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Construct the wavenumber array
|
||||||
|
|
||||||
|
freq1 = 2.0*pi / ((double)npad*dt);
|
||||||
|
kwave[0] = 0.0;
|
||||||
|
|
||||||
|
for (i = 1; i < npad / 2 + 1; ++i) {
|
||||||
|
kwave[i] = i * freq1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = npad / 2 + 1; i < npad; ++i) {
|
||||||
|
kwave[i] = -kwave[npad - i ];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
|
||||||
|
for (j = 1; j <= jtot; ++j) {
|
||||||
|
scale1 = scale[j - 1];// = s0*pow(2.0, (double)(j - 1)*dj);
|
||||||
|
wave_function(npad, dt, mother, param, scale1, kwave, pi,&period1,&coi1, daughter);
|
||||||
|
period[j - 1] = period1;
|
||||||
|
for (k = 0; k < npad; ++k) {
|
||||||
|
tmp1 = daughter[k].re * yfft[k].re - daughter[k].im * yfft[k].im;
|
||||||
|
tmp2 = daughter[k].re * yfft[k].im + daughter[k].im * yfft[k].re;
|
||||||
|
daughter[k].re = tmp1;
|
||||||
|
daughter[k].im = tmp2;
|
||||||
|
}
|
||||||
|
fft_exec(iobj, daughter, ypad);
|
||||||
|
iter = 2 * (j - 1) * N;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
wave[iter + 2 * i] = ypad[i].re;
|
||||||
|
wave[iter + 2 * i + 1] = ypad[i].im;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 1; i <= (N + 1) / 2; ++i) {
|
||||||
|
coi[i - 1] = coi1 * dt * ((double)i - 1.0);
|
||||||
|
coi[N - i] = coi[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
free(kwave);
|
||||||
|
free(ypad);
|
||||||
|
free(yfft);
|
||||||
|
free(daughter);
|
||||||
|
|
||||||
|
free_fft(obj);
|
||||||
|
free_fft(iobj);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void psi0(int mother, double param,double *val,int *real) {
|
||||||
|
double pi,coeff;
|
||||||
|
int m,sign;
|
||||||
|
|
||||||
|
m = (int)param;
|
||||||
|
pi = 4.0 * atan(1.0);
|
||||||
|
|
||||||
|
if (mother == 0) {
|
||||||
|
// Morlet
|
||||||
|
*val = 1.0 / sqrt(sqrt(pi));
|
||||||
|
*real = 1;
|
||||||
|
}
|
||||||
|
else if (mother == 1) {
|
||||||
|
//Paul
|
||||||
|
if (m % 2 == 0) {
|
||||||
|
*real = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*real = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m % 4 == 0 || m % 4 == 1) {
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
*val = sign * pow(2.0, (double)m) * factorial(m) / (sqrt(pi * factorial(2 * m)));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (mother == 2) {
|
||||||
|
// D.O.G
|
||||||
|
*real = 1;
|
||||||
|
|
||||||
|
if (m % 2 == 0) {
|
||||||
|
if (m % 4 == 0) {
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sign = 1;
|
||||||
|
}
|
||||||
|
coeff = sign * pow(2.0, (double)m / 2) / cwt_gamma(0.5);
|
||||||
|
*val = coeff * cwt_gamma(((double)m + 1.0) / 2.0) / sqrt(cwt_gamma(m + 0.50));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*val = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int maxabs(double *array,int N) {
|
||||||
|
double maxval,temp;
|
||||||
|
int i,index;
|
||||||
|
maxval = 0.0;
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
temp = fabs(array[i]);
|
||||||
|
if (temp >= maxval) {
|
||||||
|
maxval = temp;
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double cdelta(int mother, double param, double psi0 ) {
|
||||||
|
int N,i,j,iter;
|
||||||
|
double *delta, *scale,*period,*wave,*coi,*mval;
|
||||||
|
double den,cdel;
|
||||||
|
double subscale,dt,dj,s0;
|
||||||
|
int jtot;
|
||||||
|
int maxarr;
|
||||||
|
|
||||||
|
subscale = 8.0;
|
||||||
|
dt = 0.25;
|
||||||
|
if (mother == 0) {
|
||||||
|
N = 16;
|
||||||
|
s0 = dt/4;
|
||||||
|
}
|
||||||
|
else if (mother == 1) {
|
||||||
|
N = 16;
|
||||||
|
s0 = dt / 4.0;
|
||||||
|
}
|
||||||
|
else if (mother == 2)
|
||||||
|
{
|
||||||
|
s0 = dt/8.0;
|
||||||
|
N = 256;
|
||||||
|
if (param == 2.0) {
|
||||||
|
subscale = 16.0;
|
||||||
|
s0 = dt / 16.0;
|
||||||
|
N = 2048;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dj = 1.0 / subscale;
|
||||||
|
jtot = 16 * (int) subscale;
|
||||||
|
|
||||||
|
delta = (double*)malloc(sizeof(double)* N);
|
||||||
|
wave = (double*)malloc(sizeof(double)* 2 * N * jtot);
|
||||||
|
coi = (double*)malloc(sizeof(double)* N);
|
||||||
|
scale = (double*)malloc(sizeof(double)* jtot);
|
||||||
|
period = (double*)malloc(sizeof(double)* jtot);
|
||||||
|
mval = (double*)malloc(sizeof(double)* N);
|
||||||
|
|
||||||
|
|
||||||
|
delta[0] = 1;
|
||||||
|
|
||||||
|
for (i = 1; i < N; ++i) {
|
||||||
|
delta[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < jtot; ++i) {
|
||||||
|
scale[i] = s0*pow(2.0, (double)(i)*dj);
|
||||||
|
}
|
||||||
|
|
||||||
|
cwavelet(delta, N, dt, mother, param, s0, dj, jtot, N, wave, scale, period, coi);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
mval[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < jtot; ++j) {
|
||||||
|
iter = 2 * j * N;
|
||||||
|
den = sqrt(scale[j]);
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
mval[i] += wave[iter + 2 * i]/den;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
maxarr = maxabs(mval, N);
|
||||||
|
|
||||||
|
cdel = sqrt(dt) * dj * mval[maxarr] / psi0;
|
||||||
|
|
||||||
|
free(delta);
|
||||||
|
free(wave);
|
||||||
|
|
||||||
|
free(scale);
|
||||||
|
free(period);
|
||||||
|
free(coi);
|
||||||
|
free(mval);
|
||||||
|
|
||||||
|
return cdel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void icwavelet(double *wave, int N, double *scale,int jtot,double dt,double dj,double cdelta,double psi0,double *oup) {
|
||||||
|
int i, j,iter;
|
||||||
|
double den, coeff;
|
||||||
|
|
||||||
|
coeff = sqrt(dt) * dj / (cdelta *psi0);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
oup[i] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < jtot; ++j) {
|
||||||
|
iter = 2 * j * N;
|
||||||
|
den = sqrt(scale[j]);
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
oup[i] += wave[iter + 2 * i] / den;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
oup[i] *= coeff;
|
||||||
|
}
|
||||||
|
}
|
29
dep/wavelib/src/cwt.h
Normal file
29
dep/wavelib/src/cwt.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef CWT_H_
|
||||||
|
#define CWT_H_
|
||||||
|
|
||||||
|
#include "wavefunc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void cwavelet(const double *y, int N, double dt, int mother, double param, double s0, double dj, int jtot, int npad,
|
||||||
|
double *wave, double *scale, double *period, double *coi);
|
||||||
|
|
||||||
|
void psi0(int mother, double param, double *val, int *real);
|
||||||
|
|
||||||
|
double factorial(int N);
|
||||||
|
|
||||||
|
double cdelta(int mother, double param, double psi0);
|
||||||
|
|
||||||
|
void icwavelet(double *wave, int N, double *scale, int jtot, double dt, double dj, double cdelta, double psi0, double *oup);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVELIB_H_ */
|
||||||
|
|
||||||
|
|
296
dep/wavelib/src/cwtmath.c
Normal file
296
dep/wavelib/src/cwtmath.c
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
#include "cwtmath.h"
|
||||||
|
|
||||||
|
static void nsfft_fd(fft_object obj, fft_data *inp, fft_data *oup,double lb,double ub,double *w) {
|
||||||
|
int M,N,i,j,L;
|
||||||
|
double delta,den,theta,tempr,tempi,plb;
|
||||||
|
double *temp1,*temp2;
|
||||||
|
|
||||||
|
N = obj->N;
|
||||||
|
L = N/2;
|
||||||
|
//w = (double*)malloc(sizeof(double)*N);
|
||||||
|
|
||||||
|
M = divideby(N, 2);
|
||||||
|
|
||||||
|
if (M == 0) {
|
||||||
|
printf("The Non-Standard FFT Length must be a power of 2");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp1 = (double*)malloc(sizeof(double)*L);
|
||||||
|
temp2 = (double*)malloc(sizeof(double)*L);
|
||||||
|
|
||||||
|
delta = (ub - lb)/ N;
|
||||||
|
j = -N;
|
||||||
|
den = 2 * (ub-lb);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
w[i] = (double)j/den;
|
||||||
|
j += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_exec(obj,inp,oup);
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
temp1[i] = oup[i].re;
|
||||||
|
temp2[i] = oup[i].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N - L; ++i) {
|
||||||
|
oup[i].re = oup[i + L].re;
|
||||||
|
oup[i].im = oup[i + L].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
oup[N - L + i].re = temp1[i];
|
||||||
|
oup[N - L + i].im = temp2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
plb = PI2 * lb;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
tempr = oup[i].re;
|
||||||
|
tempi = oup[i].im;
|
||||||
|
theta = w[i] * plb;
|
||||||
|
|
||||||
|
oup[i].re = delta * (tempr*cos(theta) + tempi*sin(theta));
|
||||||
|
oup[i].im = delta * (tempi*cos(theta) - tempr*sin(theta));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//free(w);
|
||||||
|
free(temp1);
|
||||||
|
free(temp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nsfft_bk(fft_object obj, fft_data *inp, fft_data *oup,double lb,double ub,double *t) {
|
||||||
|
int M,N,i,j,L;
|
||||||
|
double *w;
|
||||||
|
double delta,den,plb,theta;
|
||||||
|
double *temp1,*temp2;
|
||||||
|
fft_data *inpt;
|
||||||
|
|
||||||
|
N = obj->N;
|
||||||
|
L = N/2;
|
||||||
|
|
||||||
|
M = divideby(N, 2);
|
||||||
|
|
||||||
|
if (M == 0) {
|
||||||
|
printf("The Non-Standard FFT Length must be a power of 2");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp1 = (double*)malloc(sizeof(double)*L);
|
||||||
|
temp2 = (double*)malloc(sizeof(double)*L);
|
||||||
|
w = (double*)malloc(sizeof(double)*N);
|
||||||
|
inpt = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
|
||||||
|
delta = (ub - lb)/ N;
|
||||||
|
j = -N;
|
||||||
|
den = 2 * (ub-lb);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
w[i] = (double)j/den;
|
||||||
|
j += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
plb = PI2 * lb;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
theta = w[i] * plb;
|
||||||
|
|
||||||
|
inpt[i].re = (inp[i].re*cos(theta) - inp[i].im*sin(theta))/delta;
|
||||||
|
inpt[i].im = (inp[i].im*cos(theta) + inp[i].re*sin(theta))/delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
temp1[i] = inpt[i].re;
|
||||||
|
temp2[i] = inpt[i].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N - L; ++i) {
|
||||||
|
inpt[i].re = inpt[i + L].re;
|
||||||
|
inpt[i].im = inpt[i + L].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
inpt[N - L + i].re = temp1[i];
|
||||||
|
inpt[N - L + i].im = temp2[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_exec(obj,inpt,oup);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t[i] = lb + i*delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(w);
|
||||||
|
free(temp1);
|
||||||
|
free(temp2);
|
||||||
|
free(inpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsfft_exec(fft_object obj, fft_data *inp, fft_data *oup,double lb,double ub,double *w) {
|
||||||
|
if (obj->sgn == 1) {
|
||||||
|
nsfft_fd(obj,inp,oup,lb,ub,w);
|
||||||
|
} else if (obj->sgn == -1) {
|
||||||
|
nsfft_bk(obj,inp,oup,lb,ub,w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double fix(double x) {
|
||||||
|
// Rounds to the integer nearest to zero
|
||||||
|
if (x >= 0.) {
|
||||||
|
return floor(x);
|
||||||
|
} else {
|
||||||
|
return ceil(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int nint(double N) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = (int)(N + 0.49999);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double cwt_gamma(double x) {
|
||||||
|
/*
|
||||||
|
* This C program code is based on W J Cody's fortran code.
|
||||||
|
* http://www.netlib.org/specfun/gamma
|
||||||
|
*
|
||||||
|
* References:
|
||||||
|
"An Overview of Software Development for Special Functions",
|
||||||
|
W. J. Cody, Lecture Notes in Mathematics, 506,
|
||||||
|
Numerical Analysis Dundee, 1975, G. A. Watson (ed.),
|
||||||
|
Springer Verlag, Berlin, 1976.
|
||||||
|
|
||||||
|
Computer Approximations, Hart, Et. Al., Wiley and sons, New York, 1968.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// numerator and denominator coefficients for 1 <= x <= 2
|
||||||
|
|
||||||
|
double y,oup,fact,sum,y2,yi,z,nsum,dsum;
|
||||||
|
int swi,n,i;
|
||||||
|
|
||||||
|
double spi = 0.9189385332046727417803297;
|
||||||
|
double pi = 3.1415926535897932384626434;
|
||||||
|
double xmax = 171.624e+0;
|
||||||
|
double xinf = 1.79e308;
|
||||||
|
double eps = 2.22e-16;
|
||||||
|
double xninf = 1.79e-308;
|
||||||
|
|
||||||
|
double num[8] = { -1.71618513886549492533811e+0,
|
||||||
|
2.47656508055759199108314e+1,
|
||||||
|
-3.79804256470945635097577e+2,
|
||||||
|
6.29331155312818442661052e+2,
|
||||||
|
8.66966202790413211295064e+2,
|
||||||
|
-3.14512729688483675254357e+4,
|
||||||
|
-3.61444134186911729807069e+4,
|
||||||
|
6.64561438202405440627855e+4 };
|
||||||
|
|
||||||
|
double den[8] = { -3.08402300119738975254353e+1,
|
||||||
|
3.15350626979604161529144e+2,
|
||||||
|
-1.01515636749021914166146e+3,
|
||||||
|
-3.10777167157231109440444e+3,
|
||||||
|
2.25381184209801510330112e+4,
|
||||||
|
4.75584627752788110767815e+3,
|
||||||
|
-1.34659959864969306392456e+5,
|
||||||
|
-1.15132259675553483497211e+5 };
|
||||||
|
|
||||||
|
// Coefficients for Hart's Minimax approximation x >= 12
|
||||||
|
|
||||||
|
|
||||||
|
double c[7] = { -1.910444077728e-03,
|
||||||
|
8.4171387781295e-04,
|
||||||
|
-5.952379913043012e-04,
|
||||||
|
7.93650793500350248e-04,
|
||||||
|
-2.777777777777681622553e-03,
|
||||||
|
8.333333333333333331554247e-02,
|
||||||
|
5.7083835261e-03 };
|
||||||
|
|
||||||
|
y = x;
|
||||||
|
swi = 0;
|
||||||
|
fact = 1.0;
|
||||||
|
n = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if ( y < 0.) {
|
||||||
|
// Negative x
|
||||||
|
y = -x;
|
||||||
|
yi = fix(y);
|
||||||
|
oup = y - yi;
|
||||||
|
|
||||||
|
if (oup != 0.0) {
|
||||||
|
if (yi != fix(yi * .5) * 2.) {
|
||||||
|
swi = 1;
|
||||||
|
}
|
||||||
|
fact = -pi / sin(pi * oup);
|
||||||
|
y += 1.;
|
||||||
|
} else {
|
||||||
|
return xinf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < eps) {
|
||||||
|
if (y >= xninf) {
|
||||||
|
oup = 1.0/y;
|
||||||
|
} else {
|
||||||
|
return xinf;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (y < 12.) {
|
||||||
|
yi = y;
|
||||||
|
if ( y < 1.) {
|
||||||
|
z = y;
|
||||||
|
y += 1.;
|
||||||
|
} else {
|
||||||
|
n = ( int ) y - 1;
|
||||||
|
y -= ( double ) n;
|
||||||
|
z = y - 1.0;
|
||||||
|
}
|
||||||
|
nsum = 0.;
|
||||||
|
dsum = 1.;
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
nsum = (nsum + num[i]) * z;
|
||||||
|
dsum = dsum * z + den[i];
|
||||||
|
}
|
||||||
|
oup = nsum / dsum + 1.;
|
||||||
|
|
||||||
|
if (yi < y) {
|
||||||
|
|
||||||
|
oup /= yi;
|
||||||
|
} else if (yi > y) {
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
oup *= y;
|
||||||
|
y += 1.;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (y <= xmax) {
|
||||||
|
y2 = y * y;
|
||||||
|
sum = c[6];
|
||||||
|
for (i = 0; i < 6; ++i) {
|
||||||
|
sum = sum / y2 + c[i];
|
||||||
|
}
|
||||||
|
sum = sum / y - y + spi;
|
||||||
|
sum += (y - .5) * log(y);
|
||||||
|
oup = exp(sum);
|
||||||
|
} else {
|
||||||
|
return(xinf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swi) {
|
||||||
|
oup = -oup;
|
||||||
|
}
|
||||||
|
if (fact != 1.) {
|
||||||
|
oup = fact / oup;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oup;
|
||||||
|
}
|
22
dep/wavelib/src/cwtmath.h
Normal file
22
dep/wavelib/src/cwtmath.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef CWTMATH_H_
|
||||||
|
#define CWTMATH_H_
|
||||||
|
|
||||||
|
#include "wtmath.h"
|
||||||
|
#include "hsfft.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void nsfft_exec(fft_object obj, fft_data *inp, fft_data *oup,double lb,double ub,double *w);// lb -lower bound, ub - upper bound, w - time or frequency grid (Size N)
|
||||||
|
|
||||||
|
double cwt_gamma(double x);
|
||||||
|
|
||||||
|
int nint(double N);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVELIB_H_ */
|
1860
dep/wavelib/src/hsfft.c
Normal file
1860
dep/wavelib/src/hsfft.c
Normal file
File diff suppressed because it is too large
Load Diff
60
dep/wavelib/src/hsfft.h
Normal file
60
dep/wavelib/src/hsfft.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* hsfft.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 14, 2013
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HSFFT_H_
|
||||||
|
#define HSFFT_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PI2 6.28318530717958647692528676655900577
|
||||||
|
|
||||||
|
#ifndef fft_type
|
||||||
|
#define fft_type double
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define SADD(a,b) ((a)+(b))
|
||||||
|
|
||||||
|
#define SSUB(a,b) ((a)+(b))
|
||||||
|
|
||||||
|
#define SMUL(a,b) ((a)*(b))
|
||||||
|
*/
|
||||||
|
|
||||||
|
fft_object fft_init(int N, int sgn);
|
||||||
|
|
||||||
|
void fft_exec(fft_object obj,fft_data *inp,fft_data *oup);
|
||||||
|
|
||||||
|
int divideby(int M,int d);
|
||||||
|
|
||||||
|
int dividebyN(int N);
|
||||||
|
|
||||||
|
//void arrrev(int M, int* arr);
|
||||||
|
|
||||||
|
int factors(int M, int* arr);
|
||||||
|
|
||||||
|
void twiddle(fft_data *sig,int N, int radix);
|
||||||
|
|
||||||
|
void longvectorN(fft_data *sig, int *array, int M);
|
||||||
|
|
||||||
|
void free_fft(fft_object object);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HSFFT_H_ */
|
109
dep/wavelib/src/real.c
Normal file
109
dep/wavelib/src/real.c
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* real.c
|
||||||
|
*
|
||||||
|
* Created on: Apr 20, 2013
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "real.h"
|
||||||
|
|
||||||
|
fft_real_object fft_real_init(int N, int sgn) {
|
||||||
|
fft_real_object obj = NULL;
|
||||||
|
fft_type theta;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
obj = (fft_real_object) malloc (sizeof(struct fft_real_set) + sizeof(fft_data)* (N/2));
|
||||||
|
|
||||||
|
obj->cobj = fft_init(N/2,sgn);
|
||||||
|
|
||||||
|
for (k = 0; k < N/2;++k) {
|
||||||
|
theta = PI2*k/N;
|
||||||
|
obj->twiddle2[k].re = cos(theta);
|
||||||
|
obj->twiddle2[k].im = sin(theta);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fft_r2c_exec(fft_real_object obj,fft_type *inp,fft_data *oup) {
|
||||||
|
fft_data* cinp;
|
||||||
|
fft_data* coup;
|
||||||
|
int i,N2,N;
|
||||||
|
fft_type temp1,temp2;
|
||||||
|
N2 = obj->cobj->N;
|
||||||
|
N = N2*2;
|
||||||
|
|
||||||
|
cinp = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||||
|
coup = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||||
|
|
||||||
|
for (i = 0; i < N2; ++i) {
|
||||||
|
cinp[i].re = inp[2*i];
|
||||||
|
cinp[i].im = inp[2*i+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_exec(obj->cobj,cinp,coup);
|
||||||
|
|
||||||
|
oup[0].re = coup[0].re + coup[0].im;
|
||||||
|
oup[0].im = 0.0;
|
||||||
|
|
||||||
|
for (i = 1; i < N2; ++i) {
|
||||||
|
temp1 = coup[i].im + coup[N2-i].im ;
|
||||||
|
temp2 = coup[N2-i].re - coup[i].re ;
|
||||||
|
oup[i].re = (coup[i].re + coup[N2-i].re + (temp1 * obj->twiddle2[i].re) + (temp2 * obj->twiddle2[i].im)) / 2.0;
|
||||||
|
oup[i].im = (coup[i].im - coup[N2-i].im + (temp2 * obj->twiddle2[i].re) - (temp1 * obj->twiddle2[i].im)) / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
oup[N2].re = coup[0].re - coup[0].im;
|
||||||
|
oup[N2].im = 0.0;
|
||||||
|
|
||||||
|
for (i = 1; i < N2;++i) {
|
||||||
|
oup[N-i].re = oup[i].re;
|
||||||
|
oup[N-i].im = -oup[i].im;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(cinp);
|
||||||
|
free(coup);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup) {
|
||||||
|
|
||||||
|
fft_data* cinp;
|
||||||
|
fft_data* coup;
|
||||||
|
int i,N2;
|
||||||
|
fft_type temp1,temp2;
|
||||||
|
N2 = obj->cobj->N;
|
||||||
|
|
||||||
|
cinp = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||||
|
coup = (fft_data*) malloc (sizeof(fft_data) * N2);
|
||||||
|
|
||||||
|
for (i = 0; i < N2; ++i) {
|
||||||
|
temp1 = -inp[i].im - inp[N2-i].im ;
|
||||||
|
temp2 = -inp[N2-i].re + inp[i].re ;
|
||||||
|
cinp[i].re = inp[i].re + inp[N2-i].re + (temp1 * obj->twiddle2[i].re) - (temp2 * obj->twiddle2[i].im);
|
||||||
|
cinp[i].im = inp[i].im - inp[N2-i].im + (temp2 * obj->twiddle2[i].re) + (temp1 * obj->twiddle2[i].im);
|
||||||
|
}
|
||||||
|
|
||||||
|
fft_exec(obj->cobj,cinp,coup);
|
||||||
|
for (i = 0; i < N2; ++i) {
|
||||||
|
oup[2*i] = coup[i].re;
|
||||||
|
oup[2*i+1] = coup[i].im;
|
||||||
|
}
|
||||||
|
free(cinp);
|
||||||
|
free(coup);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_real_fft(fft_real_object object) {
|
||||||
|
free_fft(object->cobj);
|
||||||
|
free(object);
|
||||||
|
}
|
||||||
|
|
29
dep/wavelib/src/real.h
Normal file
29
dep/wavelib/src/real.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* real.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 20, 2013
|
||||||
|
* Author: Rafat Hussain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef REAL_H_
|
||||||
|
#define REAL_H_
|
||||||
|
|
||||||
|
#include "hsfft.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fft_real_object fft_real_init(int N, int sgn);
|
||||||
|
|
||||||
|
void fft_r2c_exec(fft_real_object obj,fft_type *inp,fft_data *oup);
|
||||||
|
|
||||||
|
void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup);
|
||||||
|
|
||||||
|
void free_real_fft(fft_real_object object);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* REAL_H_ */
|
4315
dep/wavelib/src/wavefilt.c
Normal file
4315
dep/wavelib/src/wavefilt.c
Normal file
File diff suppressed because it is too large
Load Diff
31
dep/wavelib/src/wavefilt.h
Normal file
31
dep/wavelib/src/wavefilt.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014, Rafat Hussain
|
||||||
|
Copyright (c) 2016, Holger Nahrstaedt
|
||||||
|
*/
|
||||||
|
#ifndef WAVEFILT_H_
|
||||||
|
#define WAVEFILT_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "conv.h"
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int filtlength(const char* name);
|
||||||
|
|
||||||
|
int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp2);
|
||||||
|
|
||||||
|
void copy_reverse(const double *in, int N, double *out);
|
||||||
|
void qmf_even(const double *in, int N, double *out);
|
||||||
|
void qmf_wrev(const double *in, int N, double *out);
|
||||||
|
void copy(const double *in, int N, double *out);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVEFILT_H_ */
|
210
dep/wavelib/src/wavefunc.c
Normal file
210
dep/wavelib/src/wavefunc.c
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
#include "wavefunc.h"
|
||||||
|
|
||||||
|
void meyer(int N,double lb,double ub,double *phi,double *psi,double *tgrid) {
|
||||||
|
int M,i;
|
||||||
|
double *w;
|
||||||
|
double delta,j;
|
||||||
|
double theta,x,x2,x3,x4,v,cs,sn;
|
||||||
|
double wf;
|
||||||
|
fft_data *phiw,*psiw,*oup;
|
||||||
|
fft_object obj;
|
||||||
|
|
||||||
|
M = divideby(N, 2);
|
||||||
|
|
||||||
|
if (M == 0) {
|
||||||
|
printf("Size of Wavelet must be a power of 2");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (lb >= ub) {
|
||||||
|
printf("upper bound must be greater than lower bound");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = fft_init(N,-1);
|
||||||
|
w = (double*)malloc(sizeof(double)*N);
|
||||||
|
phiw = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
psiw = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
oup = (fft_data*) malloc (sizeof(fft_data) * N);
|
||||||
|
|
||||||
|
delta = 2 * (ub-lb) / PI2;
|
||||||
|
|
||||||
|
j = (double) N;
|
||||||
|
j *= -1.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
w[i] = j / delta;
|
||||||
|
j += 2.0;
|
||||||
|
psiw[i].re = psiw[i].im = 0.0;
|
||||||
|
phiw[i].re = phiw[i].im = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
wf = fabs(w[i]);
|
||||||
|
if (wf <= PI2/3.0) {
|
||||||
|
phiw[i].re = 1.0;
|
||||||
|
}
|
||||||
|
if (wf > PI2/3.0 && wf <= 2 * PI2 / 3.0) {
|
||||||
|
x = (3 * wf / PI2) - 1.0;
|
||||||
|
x2 = x*x;
|
||||||
|
x3 = x2 * x;
|
||||||
|
x4 = x3 *x;
|
||||||
|
v = x4 *(35 - 84*x + 70*x2 - 20*x3);
|
||||||
|
theta = v * PI2 / 4.0;
|
||||||
|
cs = cos(theta);
|
||||||
|
sn = sin(theta);
|
||||||
|
|
||||||
|
phiw[i].re = cs;
|
||||||
|
psiw[i].re = cos(w[i]/2.0) * sn;
|
||||||
|
psiw[i].im = sin(w[i]/2.0) * sn;
|
||||||
|
}
|
||||||
|
if (wf > 2.0 * PI2/3.0 && wf <= 4 * PI2 / 3.0) {
|
||||||
|
x = (1.5 * wf / PI2) - 1.0;
|
||||||
|
x2 = x*x;
|
||||||
|
x3 = x2 * x;
|
||||||
|
x4 = x3 *x;
|
||||||
|
v = x4 *(35 - 84*x + 70*x2 - 20*x3);
|
||||||
|
theta = v * PI2 / 4.0;
|
||||||
|
cs = cos(theta);
|
||||||
|
|
||||||
|
psiw[i].re = cos(w[i]/2.0) * cs;
|
||||||
|
psiw[i].im = sin(w[i]/2.0) * cs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nsfft_exec(obj,phiw,oup,lb,ub,tgrid);
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
phi[i] = oup[i].re/N;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsfft_exec(obj,psiw,oup,lb,ub,tgrid);
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
psi[i] = oup[i].re/N;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
free(oup);
|
||||||
|
free(phiw);
|
||||||
|
free(psiw);
|
||||||
|
free(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gauss(int N,int p,double lb,double ub,double *psi,double *t) {
|
||||||
|
double delta,num,den,t2,t4;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (lb >= ub) {
|
||||||
|
printf("upper bound must be greater than lower bound");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
t[0] = lb;
|
||||||
|
t[N-1] = ub;
|
||||||
|
delta = (ub - lb) / (N-1);
|
||||||
|
for(i = 1; i < N-1;++i) {
|
||||||
|
t[i] = lb + delta * i;
|
||||||
|
}
|
||||||
|
|
||||||
|
den = sqrt(cwt_gamma(p+0.5));
|
||||||
|
|
||||||
|
if ((p+1)%2 == 0) {
|
||||||
|
num = 1.0;
|
||||||
|
} else {
|
||||||
|
num = -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
num /= den;
|
||||||
|
|
||||||
|
//printf("\n%g\n",num);
|
||||||
|
|
||||||
|
if (p == 1) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
psi[i] = -t[i] * exp(- t[i] * t[i]/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 2) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = (-1.0 + t2) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 3) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = t[i] * (3.0 - t2) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 4) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = (t2 * t2 - 6.0 * t2 + 3.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 5) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = t[i] * (-t2 * t2 + 10.0 * t2 - 15.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 6) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = (t2 * t2 * t2 - 15.0 * t2 * t2 + 45.0 * t2 - 15.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 7) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
psi[i] = t[i] * (-t2 * t2 * t2 + 21.0 * t2 * t2 - 105.0 * t2 + 105.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 8) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
t4 = t2 * t2;
|
||||||
|
psi[i] = (t4 * t4 - 28.0 * t4 * t2 + 210.0 * t4 - 420.0 * t2 + 105.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 9) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
t4 = t2 * t2;
|
||||||
|
psi[i] = t[i] * (- t4 * t4 + 36.0 * t4 * t2 - 378.0 * t4 + 1260.0 * t2 - 945.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else if (p == 10) {
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
t2 = t[i] * t[i];
|
||||||
|
t4 = t2 * t2;
|
||||||
|
psi[i] = (t4 * t4 * t2 - 45.0 * t4 * t4 + 630.0 * t4 * t2 - 3150.0 * t4 + 4725.0 * t2 - 945.0) * exp(- t2/2.0) * num;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("\n The Gaussian Derivative Wavelet is only available for Derivatives 1 to 10");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void mexhat(int N,double lb,double ub,double *psi,double *t) {
|
||||||
|
gauss(N,2,lb,ub,psi,t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void morlet(int N,double lb,double ub,double *psi,double *t) {
|
||||||
|
int i;
|
||||||
|
double delta;
|
||||||
|
|
||||||
|
if (lb >= ub) {
|
||||||
|
printf("upper bound must be greater than lower bound");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
t[0] = lb;
|
||||||
|
t[N-1] = ub;
|
||||||
|
delta = (ub - lb) / (N-1);
|
||||||
|
for(i = 1; i < N-1;++i) {
|
||||||
|
t[i] = lb + delta * i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
psi[i] = exp(- t[i] * t[i] / 2.0) * cos(5 * t[i]);
|
||||||
|
}
|
||||||
|
}
|
24
dep/wavelib/src/wavefunc.h
Normal file
24
dep/wavelib/src/wavefunc.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef WAVEFUNC_H_
|
||||||
|
#define WAVEFUNC_H_
|
||||||
|
|
||||||
|
#include "cwtmath.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void meyer(int N,double lb,double ub,double *phi,double *psi,double *tgrid);
|
||||||
|
|
||||||
|
void gauss(int N,int p,double lb,double ub,double *psi,double *t);
|
||||||
|
|
||||||
|
void mexhat(int N,double lb,double ub,double *psi,double *t);
|
||||||
|
|
||||||
|
void morlet(int N,double lb,double ub,double *psi,double *t);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVEFUNC_H_ */
|
4280
dep/wavelib/src/wavelib.c
Normal file
4280
dep/wavelib/src/wavelib.c
Normal file
File diff suppressed because it is too large
Load Diff
680
dep/wavelib/src/wtmath.c
Normal file
680
dep/wavelib/src/wtmath.c
Normal file
@ -0,0 +1,680 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2018, Rafat Hussain
|
||||||
|
*/
|
||||||
|
#include "wtmath.h"
|
||||||
|
|
||||||
|
void dwt_per_stride(double *inp, int N, double *lpd,double*hpd,int lpd_len,double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||||
|
int l, l2, isodd, i, t, len_avg,is,os;
|
||||||
|
|
||||||
|
len_avg = lpd_len;
|
||||||
|
l2 = len_avg / 2;
|
||||||
|
isodd = N % 2;
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA; ++i) {
|
||||||
|
t = 2 * i + l2;
|
||||||
|
os = i *ostride;
|
||||||
|
cA[os] = 0.0;
|
||||||
|
cD[os] = 0.0;
|
||||||
|
for (l = 0; l < len_avg; ++l) {
|
||||||
|
if ((t - l) >= l2 && (t - l) < N) {
|
||||||
|
is = (t - l) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) < l2 && (t - l) >= 0) {
|
||||||
|
is = (t - l) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) < 0 && isodd == 0) {
|
||||||
|
is = (t - l + N) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) < 0 && isodd == 1) {
|
||||||
|
if ((t - l) != -1) {
|
||||||
|
is = (t - l + N + 1) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
is = (N - 1) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((t - l) >= N && isodd == 0) {
|
||||||
|
is = (t - l - N) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) >= N && isodd == 1) {
|
||||||
|
is = (t - l - (N + 1)) * istride;
|
||||||
|
if (t - l != N) {
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
is = (N - 1) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dwt_sym_stride(double *inp, int N, double *lpd, double*hpd, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||||
|
int i, l, t, len_avg;
|
||||||
|
int is, os;
|
||||||
|
len_avg = lpd_len;
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA; ++i) {
|
||||||
|
t = 2 * i + 1;
|
||||||
|
os = i *ostride;
|
||||||
|
cA[os] = 0.0;
|
||||||
|
cD[os] = 0.0;
|
||||||
|
for (l = 0; l < len_avg; ++l) {
|
||||||
|
if ((t - l) >= 0 && (t - l) < N) {
|
||||||
|
is = (t - l) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) < 0) {
|
||||||
|
is = (-t + l - 1) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - l) >= N) {
|
||||||
|
is = (2 * N - t + l - 1) * istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void modwt_per_stride(int M, double *inp, int N, double *filt, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||||
|
int l, i, t, len_avg;
|
||||||
|
int is, os;
|
||||||
|
len_avg = lpd_len;
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA; ++i) {
|
||||||
|
t = i;
|
||||||
|
os = i *ostride;
|
||||||
|
is = t *istride;
|
||||||
|
cA[os] = filt[0] * inp[is];
|
||||||
|
cD[os] = filt[len_avg] * inp[is];
|
||||||
|
for (l = 1; l < len_avg; l++) {
|
||||||
|
t -= M;
|
||||||
|
while (t >= len_cA) {
|
||||||
|
t -= len_cA;
|
||||||
|
}
|
||||||
|
while (t < 0) {
|
||||||
|
t += len_cA;
|
||||||
|
}
|
||||||
|
os = i * ostride;
|
||||||
|
is = t * istride;
|
||||||
|
cA[os] += filt[l] * inp[is];
|
||||||
|
cD[os] += filt[len_avg + l] * inp[is];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void swt_per_stride(int M, double *inp, int N, double *lpd, double*hpd, int lpd_len, double *cA, int len_cA, double *cD, int istride, int ostride) {
|
||||||
|
int l, l2, isodd, i, t, len_avg, j;
|
||||||
|
int is, os;
|
||||||
|
len_avg = M * lpd_len;
|
||||||
|
l2 = len_avg / 2;
|
||||||
|
isodd = N % 2;
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA; ++i) {
|
||||||
|
t = i + l2;
|
||||||
|
os = i *ostride;
|
||||||
|
cA[os] = 0.0;
|
||||||
|
cD[os] = 0.0;
|
||||||
|
l = -1;
|
||||||
|
for (j = 0; j < len_avg; j += M) {
|
||||||
|
l++;
|
||||||
|
while (j >= len_cA) {
|
||||||
|
j -= len_cA;
|
||||||
|
}
|
||||||
|
if ((t - j) >= l2 && (t - j) < N) {
|
||||||
|
is = (t - j)*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - j) < l2 && (t - j) >= 0) {
|
||||||
|
is = (t - j)*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - j) < 0) {
|
||||||
|
is = (t - j + N)*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - j) >= N && isodd == 0) {
|
||||||
|
is = (t - j - N)*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else if ((t - j) >= N && isodd == 1) {
|
||||||
|
if (t - l != N) {
|
||||||
|
is = (t - j - (N + 1))*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[is];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
is = (N - 1)*istride;
|
||||||
|
cA[os] += lpd[l] * inp[is];
|
||||||
|
cD[os] += hpd[l] * inp[N - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void idwt_per_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr, int lpr_len, double *X, int istride, int ostride) {
|
||||||
|
int len_avg, i, l, m, n, t, l2;
|
||||||
|
int is, ms, ns;
|
||||||
|
|
||||||
|
len_avg = lpr_len;
|
||||||
|
l2 = len_avg / 2;
|
||||||
|
m = -2;
|
||||||
|
n = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA + l2 - 1; ++i) {
|
||||||
|
m += 2;
|
||||||
|
n += 2;
|
||||||
|
ms = m * ostride;
|
||||||
|
ns = n * ostride;
|
||||||
|
X[ms] = 0.0;
|
||||||
|
X[ns] = 0.0;
|
||||||
|
for (l = 0; l < l2; ++l) {
|
||||||
|
t = 2 * l;
|
||||||
|
if ((i - l) >= 0 && (i - l) < len_cA) {
|
||||||
|
is = (i - l) * istride;
|
||||||
|
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||||
|
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||||
|
}
|
||||||
|
else if ((i - l) >= len_cA && (i - l) < len_cA + len_avg - 1) {
|
||||||
|
is = (i - l - len_cA) * istride;
|
||||||
|
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||||
|
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||||
|
}
|
||||||
|
else if ((i - l) < 0 && (i - l) > -l2) {
|
||||||
|
is = (len_cA + i - l) * istride;
|
||||||
|
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||||
|
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void idwt_sym_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr, int lpr_len, double *X, int istride, int ostride) {
|
||||||
|
int len_avg, i, l, m, n, t, v;
|
||||||
|
int ms, ns, is;
|
||||||
|
len_avg = lpr_len;
|
||||||
|
m = -2;
|
||||||
|
n = -1;
|
||||||
|
|
||||||
|
for (v = 0; v < len_cA; ++v) {
|
||||||
|
i = v;
|
||||||
|
m += 2;
|
||||||
|
n += 2;
|
||||||
|
ms = m * ostride;
|
||||||
|
ns = n * ostride;
|
||||||
|
X[ms] = 0.0;
|
||||||
|
X[ns] = 0.0;
|
||||||
|
for (l = 0; l < len_avg / 2; ++l) {
|
||||||
|
t = 2 * l;
|
||||||
|
if ((i - l) >= 0 && (i - l) < len_cA) {
|
||||||
|
is = (i - l) * istride;
|
||||||
|
X[ms] += lpr[t] * cA[is] + hpr[t] * cD[is];
|
||||||
|
X[ns] += lpr[t + 1] * cA[is] + hpr[t + 1] * cD[is];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void imodwt_per_stride(int M, double *cA, int len_cA, double *cD, double *filt,int lf,double *X,int istride, int ostride) {
|
||||||
|
int len_avg, i, l, t;
|
||||||
|
int is, os;
|
||||||
|
|
||||||
|
len_avg = lf;
|
||||||
|
|
||||||
|
for (i = 0; i < len_cA; ++i) {
|
||||||
|
t = i;
|
||||||
|
os = i * ostride;
|
||||||
|
is = t *istride;
|
||||||
|
X[os] = (filt[0] * cA[is]) + (filt[len_avg] * cD[is]);
|
||||||
|
for (l = 1; l < len_avg; l++) {
|
||||||
|
t += M;
|
||||||
|
while (t >= len_cA) {
|
||||||
|
t -= len_cA;
|
||||||
|
}
|
||||||
|
while (t < 0) {
|
||||||
|
t += len_cA;
|
||||||
|
}
|
||||||
|
is = t *istride;
|
||||||
|
X[os] += (filt[l] * cA[is]) + (filt[len_avg + l] * cD[is]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void idwt2_shift(int shift, int rows, int cols, double *lpr, double *hpr, int lf, double *A,double *H, double *V,double *D, double *oup) {
|
||||||
|
int i, k, N, ir, ic, J, dim1, dim2;
|
||||||
|
int istride, ostride;
|
||||||
|
double *cL, *cH, *X_lp;
|
||||||
|
|
||||||
|
|
||||||
|
N = rows > cols ? 2 * rows : 2 * cols;
|
||||||
|
|
||||||
|
J = 1;
|
||||||
|
dim1 = 2 * rows;
|
||||||
|
dim2 = 2 * cols;
|
||||||
|
|
||||||
|
X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||||
|
cL = (double*)calloc(dim1*dim2, sizeof(double));
|
||||||
|
cH = (double*)calloc(dim1*dim2, sizeof(double));
|
||||||
|
|
||||||
|
ir = rows;
|
||||||
|
ic = cols;
|
||||||
|
istride = ic;
|
||||||
|
ostride = 1;
|
||||||
|
for (i = 0; i < ic; ++i) {
|
||||||
|
idwt_per_stride(A+i, ir, H+i, lpr, hpr, lf, X_lp, istride, ostride);
|
||||||
|
|
||||||
|
for (k = lf / 2 - 1; k < 2 * ir + lf / 2 - 1; ++k) {
|
||||||
|
cL[(k - lf / 2 + 1)*ic + i] = X_lp[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
idwt_per_stride(V+i, ir, D+i, lpr, hpr, lf, X_lp, istride, ostride);
|
||||||
|
|
||||||
|
for (k = lf / 2 - 1; k < 2 * ir + lf / 2 - 1; ++k) {
|
||||||
|
cH[(k - lf / 2 + 1)*ic + i] = X_lp[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ir *= 2;
|
||||||
|
istride = 1;
|
||||||
|
ostride = 1;
|
||||||
|
|
||||||
|
for (i = 0; i < ir; ++i) {
|
||||||
|
idwt_per_stride(cL + i*ic, ic, cH + i*ic, lpr, hpr, lf, X_lp, istride, ostride);
|
||||||
|
|
||||||
|
for (k = lf / 2 - 1; k < 2 * ic + lf / 2 - 1; ++k) {
|
||||||
|
oup[(k - lf / 2 + 1) + i*ic * 2] = X_lp[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ic *= 2;
|
||||||
|
|
||||||
|
|
||||||
|
if (shift == -1) {
|
||||||
|
//Save the last column
|
||||||
|
for (i = 0; i < ir; ++i) {
|
||||||
|
cL[i] = oup[(i + 1)*ic - 1];
|
||||||
|
}
|
||||||
|
// Save the last row
|
||||||
|
memcpy(cH, oup + (ir - 1)*ic, sizeof(double)*ic);
|
||||||
|
for (i = ir - 1; i > 0; --i) {
|
||||||
|
memcpy(oup + i*ic + 1, oup + (i - 1)*ic, sizeof(double)*(ic - 1));
|
||||||
|
}
|
||||||
|
oup[0] = cL[ir - 1];
|
||||||
|
for (i = 1; i < ir; ++i) {
|
||||||
|
oup[i*ic] = cL[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; i < ic; ++i) {
|
||||||
|
oup[i] = cH[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(X_lp);
|
||||||
|
free(cL);
|
||||||
|
free(cH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int upsamp(double *x, int lenx, int M, double *y) {
|
||||||
|
int N, i, j, k;
|
||||||
|
|
||||||
|
if (M < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (M == 0) {
|
||||||
|
for (i = 0; i < lenx; ++i) {
|
||||||
|
y[i] = x[i];
|
||||||
|
}
|
||||||
|
return lenx;
|
||||||
|
}
|
||||||
|
|
||||||
|
N = M * (lenx - 1) + 1;
|
||||||
|
j = 1;
|
||||||
|
k = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
j--;
|
||||||
|
y[i] = 0.0;
|
||||||
|
if (j == 0) {
|
||||||
|
y[i] = x[k];
|
||||||
|
k++;
|
||||||
|
j = M;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upsamp2(double *x, int lenx, int M, double *y) {
|
||||||
|
int N, i, j, k;
|
||||||
|
// upsamp2 returns even numbered output. Last value is set to zero
|
||||||
|
if (M < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (M == 0) {
|
||||||
|
for (i = 0; i < lenx; ++i) {
|
||||||
|
y[i] = x[i];
|
||||||
|
}
|
||||||
|
return lenx;
|
||||||
|
}
|
||||||
|
|
||||||
|
N = M * lenx;
|
||||||
|
j = 1;
|
||||||
|
k = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
j--;
|
||||||
|
y[i] = 0.0;
|
||||||
|
if (j == 0) {
|
||||||
|
y[i] = x[k];
|
||||||
|
k++;
|
||||||
|
j = M;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
int downsamp(double *x, int lenx, int M, double *y) {
|
||||||
|
int N, i;
|
||||||
|
|
||||||
|
if (M < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (M == 0) {
|
||||||
|
for (i = 0; i < lenx; ++i) {
|
||||||
|
y[i] = x[i];
|
||||||
|
}
|
||||||
|
return lenx;
|
||||||
|
}
|
||||||
|
|
||||||
|
N = (lenx - 1) / M + 1;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
y[i] = x[i*M];
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int per_ext(double *sig, int len, int a,double *oup) {
|
||||||
|
int i,len2;
|
||||||
|
// oup is of length len + (len%2) + 2 * a
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
oup[a + i] = sig[i];
|
||||||
|
}
|
||||||
|
len2 = len;
|
||||||
|
if ((len % 2) != 0) {
|
||||||
|
len2 = len + 1;
|
||||||
|
oup[a + len] = sig[len - 1];
|
||||||
|
}
|
||||||
|
for (i = 0; i < a; ++i) {
|
||||||
|
oup[a-1-i] = sig[len - 1 - i];
|
||||||
|
oup[len2 + a + i] = sig[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return len2;
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int per_ext(double *sig, int len, int a, double *oup) {
|
||||||
|
int i, len2;
|
||||||
|
double temp1;
|
||||||
|
double temp2;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
oup[a + i] = sig[i];
|
||||||
|
}
|
||||||
|
len2 = len;
|
||||||
|
if ((len % 2) != 0) {
|
||||||
|
len2 = len + 1;
|
||||||
|
oup[a + len] = sig[len - 1];
|
||||||
|
}
|
||||||
|
for (i = 0; i < a; ++i) {
|
||||||
|
temp1 = oup[a + i];
|
||||||
|
temp2 = oup[a + len2 - 1 - i];
|
||||||
|
oup[a - 1 - i] = temp2;
|
||||||
|
oup[len2 + a + i] = temp1;
|
||||||
|
}
|
||||||
|
return len2;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int symm_ext(double *sig, int len, int a, double *oup) {
|
||||||
|
int i, len2;
|
||||||
|
// oup is of length len + 2 * a
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
oup[a + i] = sig[i];
|
||||||
|
}
|
||||||
|
len2 = len;
|
||||||
|
for (i = 0; i < a; ++i) {
|
||||||
|
oup[a - 1 - i] = sig[i];
|
||||||
|
oup[len2 + a + i] = sig[len - 1 - i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return len2;
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int symm_ext(double *sig, int len, int a, double *oup) {
|
||||||
|
int i, len2;
|
||||||
|
double temp1;
|
||||||
|
double temp2;
|
||||||
|
// oup is of length len + 2 * a
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
oup[a + i] = sig[i];
|
||||||
|
}
|
||||||
|
len2 = len;
|
||||||
|
for (i = 0; i < a; ++i) {
|
||||||
|
temp1 = oup[a + i];
|
||||||
|
temp2 = oup[a + len2 - 1 - i];
|
||||||
|
oup[a - 1 - i] = temp1;
|
||||||
|
oup[len2 + a + i] = temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isign(int N) {
|
||||||
|
int M;
|
||||||
|
if (N >= 0) {
|
||||||
|
M = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
M = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return M;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int iabs(int N) {
|
||||||
|
if (N >= 0) {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -N;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void circshift(double *array, int N, int L) {
|
||||||
|
int i;
|
||||||
|
double *temp;
|
||||||
|
if (iabs(L) > N) {
|
||||||
|
L = isign(L) * (iabs(L) % N);
|
||||||
|
}
|
||||||
|
if (L < 0) {
|
||||||
|
L = (N + L) % N;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = (double*)malloc(sizeof(double) * L);
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
temp[i] = array[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N - L; ++i) {
|
||||||
|
array[i] = array[i + L];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < L; ++i) {
|
||||||
|
array[N - L + i] = temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int testSWTlength(int N, int J) {
|
||||||
|
int ret,div,i;
|
||||||
|
ret = 1;
|
||||||
|
|
||||||
|
div = 1;
|
||||||
|
for (i = 0; i < J; ++i) {
|
||||||
|
div *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (N % div) {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int wmaxiter(int sig_len, int filt_len) {
|
||||||
|
int lev;
|
||||||
|
double temp;
|
||||||
|
|
||||||
|
temp = log((double)sig_len / ((double)filt_len - 1.0)) / log(2.0);
|
||||||
|
lev = (int)temp;
|
||||||
|
|
||||||
|
return lev;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double entropy_s(double *x,int N) {
|
||||||
|
int i;
|
||||||
|
double val,x2;
|
||||||
|
|
||||||
|
val = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N; ++i) {
|
||||||
|
if (x[i] != 0) {
|
||||||
|
x2 = x[i] * x[i];
|
||||||
|
val -= x2 * log(x2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double entropy_t(double *x,int N, double t) {
|
||||||
|
int i;
|
||||||
|
double val,x2;
|
||||||
|
if (t < 0) {
|
||||||
|
printf("Threshold value must be >= 0");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
val = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N; ++i) {
|
||||||
|
x2 = fabs(x[i]);
|
||||||
|
if (x2 > t) {
|
||||||
|
val += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static double entropy_n(double *x,int N,double p) {
|
||||||
|
int i;
|
||||||
|
double val,x2;
|
||||||
|
if (p < 1) {
|
||||||
|
printf("Norm power value must be >= 1");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
val = 0.0;
|
||||||
|
for(i = 0; i < N; ++i) {
|
||||||
|
x2 = fabs(x[i]);
|
||||||
|
val += pow(x2,(double)p);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double entropy_l(double *x,int N) {
|
||||||
|
int i;
|
||||||
|
double val,x2;
|
||||||
|
|
||||||
|
val = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N; ++i) {
|
||||||
|
if (x[i] != 0) {
|
||||||
|
x2 = x[i] * x[i];
|
||||||
|
val += log(x2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
double costfunc(double *x, int N ,char *entropy,double p) {
|
||||||
|
double val;
|
||||||
|
|
||||||
|
if (!strcmp(entropy, "shannon")) {
|
||||||
|
val = entropy_s(x, N);
|
||||||
|
}
|
||||||
|
else if (!strcmp(entropy, "threshold")) {
|
||||||
|
val = entropy_t(x, N,p);
|
||||||
|
}
|
||||||
|
else if (!strcmp(entropy, "norm")) {
|
||||||
|
val = entropy_n(x, N,p);
|
||||||
|
}
|
||||||
|
else if (!strcmp(entropy, "logenergy") || !strcmp(entropy, "log energy") || !strcmp(entropy, "energy")) {
|
||||||
|
val = entropy_l(x, N);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Entropy must be one of shannon, threshold, norm or energy");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
60
dep/wavelib/src/wtmath.h
Normal file
60
dep/wavelib/src/wtmath.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014, Rafat Hussain
|
||||||
|
*/
|
||||||
|
#ifndef WTMATH_H_
|
||||||
|
#define WTMATH_H_
|
||||||
|
|
||||||
|
#include "wavefilt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void dwt_per_stride(double *inp, int N, double *lpd,double*hpd,int lpd_len,
|
||||||
|
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||||
|
|
||||||
|
void dwt_sym_stride(double *inp, int N, double *lpd, double*hpd, int lpd_len,
|
||||||
|
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||||
|
|
||||||
|
void modwt_per_stride(int M, double *inp, int N, double *filt, int lpd_len,
|
||||||
|
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||||
|
|
||||||
|
void swt_per_stride(int M, double *inp, int N, double *lpd, double*hpd, int lpd_len,
|
||||||
|
double *cA, int len_cA, double *cD, int istride, int ostride);
|
||||||
|
|
||||||
|
void idwt_per_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr,
|
||||||
|
int lpr_len, double *X, int istride, int ostride);
|
||||||
|
|
||||||
|
void idwt_sym_stride(double *cA, int len_cA, double *cD, double *lpr, double *hpr,
|
||||||
|
int lpr_len, double *X, int istride, int ostride);
|
||||||
|
|
||||||
|
void imodwt_per_stride(int M, double *cA, int len_cA, double *cD, double *filt,
|
||||||
|
int lf,double *X,int istride, int ostride);
|
||||||
|
|
||||||
|
void idwt2_shift(int shift, int rows, int cols, double *lpr, double *hpr, int lf,
|
||||||
|
double *A,double *H, double *V,double *D, double *oup);
|
||||||
|
|
||||||
|
int upsamp(double *x, int lenx, int M, double *y);
|
||||||
|
|
||||||
|
int upsamp2(double *x, int lenx, int M, double *y);
|
||||||
|
|
||||||
|
int downsamp(double *x, int lenx, int M, double *y);
|
||||||
|
|
||||||
|
int per_ext(double *sig, int len, int a,double *oup);
|
||||||
|
|
||||||
|
int symm_ext(double *sig, int len, int a,double *oup);
|
||||||
|
|
||||||
|
void circshift(double *array, int N, int L);
|
||||||
|
|
||||||
|
int testSWTlength(int N, int J);
|
||||||
|
|
||||||
|
int wmaxiter(int sig_len, int filt_len);
|
||||||
|
|
||||||
|
double costfunc(double *x, int N, char *entropy, double p);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WAVELIB_H_ */
|
48
dep/wavelib/test/CMakeLists.txt
Normal file
48
dep/wavelib/test/CMakeLists.txt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
add_executable(cwttest cwttest.c)
|
||||||
|
|
||||||
|
target_link_libraries(cwttest wavelib)
|
||||||
|
|
||||||
|
add_executable(dwttest dwttest.c)
|
||||||
|
|
||||||
|
target_link_libraries(dwttest wavelib)
|
||||||
|
|
||||||
|
add_executable(swttest swttest.c)
|
||||||
|
|
||||||
|
target_link_libraries(swttest wavelib)
|
||||||
|
|
||||||
|
add_executable(modwttest modwttest.c)
|
||||||
|
|
||||||
|
target_link_libraries(modwttest wavelib)
|
||||||
|
|
||||||
|
add_executable(dwpttest dwpttest.c)
|
||||||
|
|
||||||
|
target_link_libraries(dwpttest wavelib)
|
||||||
|
|
||||||
|
add_executable(wtreetest wtreetest.c)
|
||||||
|
|
||||||
|
target_link_libraries(wtreetest wavelib)
|
||||||
|
|
||||||
|
add_executable(denoisetest denoisetest.c)
|
||||||
|
|
||||||
|
target_link_libraries(denoisetest wauxlib wavelib)
|
||||||
|
|
||||||
|
add_executable(modwtdenoisetest modwtdenoisetest.c)
|
||||||
|
|
||||||
|
target_link_libraries(modwtdenoisetest wauxlib wavelib)
|
||||||
|
|
||||||
|
add_executable(dwt2test dwt2test.c)
|
||||||
|
|
||||||
|
target_link_libraries(dwt2test wavelib)
|
||||||
|
|
||||||
|
add_executable(swt2test swt2test.c)
|
||||||
|
|
||||||
|
target_link_libraries(swt2test wavelib)
|
||||||
|
|
||||||
|
add_executable(modwt2test modwt2test.c)
|
||||||
|
|
||||||
|
target_link_libraries(modwt2test wavelib)
|
||||||
|
|
||||||
|
set_target_properties(cwttest dwttest swttest modwttest dwpttest wtreetest denoisetest modwtdenoisetest dwt2test swt2test modwt2test
|
||||||
|
PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/test"
|
||||||
|
)
|
1024
dep/wavelib/test/PieceRegular10.txt
Normal file
1024
dep/wavelib/test/PieceRegular10.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
dep/wavelib/test/cwttest
Executable file
BIN
dep/wavelib/test/cwttest
Executable file
Binary file not shown.
109
dep/wavelib/test/cwttest.c
Normal file
109
dep/wavelib/test/cwttest.c
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i, N, J,subscale,a0,iter,nd,k;
|
||||||
|
double *inp,*oup;
|
||||||
|
double dt, dj,s0, param,mn;
|
||||||
|
double td,tn,den, num, recon_mean, recon_var;
|
||||||
|
cwt_object wt;
|
||||||
|
|
||||||
|
FILE *ifp;
|
||||||
|
double temp[1200];
|
||||||
|
|
||||||
|
char *wave = "morlet";// Set Morlet wavelet. Other options "paul" and "dog"
|
||||||
|
char *type = "pow";
|
||||||
|
|
||||||
|
N = 504;
|
||||||
|
param = 6.0;
|
||||||
|
subscale = 4;
|
||||||
|
dt = 0.25;
|
||||||
|
s0 = dt;
|
||||||
|
dj = 1.0 / (double)subscale;
|
||||||
|
J = 11 * subscale; // Total Number of scales
|
||||||
|
a0 = 2;//power
|
||||||
|
|
||||||
|
ifp = fopen("sst_nino3.dat", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
wt = cwt_init(wave, param, N,dt, J);
|
||||||
|
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
oup = (double*)malloc(sizeof(double)* N);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
inp[i] = temp[i] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCWTScales(wt, s0, dj, type, a0);
|
||||||
|
|
||||||
|
cwt(wt, inp);
|
||||||
|
|
||||||
|
printf("\n MEAN %g \n", wt->smean);
|
||||||
|
|
||||||
|
mn = 0.0;
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
mn += sqrt(wt->output[i].re * wt->output[i].re + wt->output[i].im * wt->output[i].im);
|
||||||
|
}
|
||||||
|
|
||||||
|
cwt_summary(wt);
|
||||||
|
|
||||||
|
printf("\n abs mean %g \n", mn / N);
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
printf("Let CWT w = w(j, n/2 - 1) where n = %d\n\n", N);
|
||||||
|
nd = N/2 - 1;
|
||||||
|
|
||||||
|
printf("%-15s%-15s%-15s%-15s \n","j","Scale","Period","ABS(w)^2");
|
||||||
|
for(k = 0; k < wt->J;++k) {
|
||||||
|
iter = nd + k * N;
|
||||||
|
printf("%-15d%-15lf%-15lf%-15lf \n",k,wt->scale[k],wt->period[k],
|
||||||
|
wt->output[iter].re * wt->output[iter].re + wt->output[iter].im * wt->output[iter].im);
|
||||||
|
}
|
||||||
|
|
||||||
|
icwt(wt, oup);
|
||||||
|
|
||||||
|
num = den = recon_var = recon_mean = 0.0;
|
||||||
|
printf("\n\n");
|
||||||
|
printf("Signal Reconstruction\n");
|
||||||
|
printf("%-15s%-15s%-15s \n","i","Input(i)","Output(i)");
|
||||||
|
|
||||||
|
for (i = N - 10; i < N; ++i) {
|
||||||
|
printf("%-15d%-15lf%-15lf \n", i,inp[i] , oup[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
//printf("%g %g \n", oup[i] ,inp[i] - wt->smean);
|
||||||
|
td = inp[i] ;
|
||||||
|
tn = oup[i] - td;
|
||||||
|
num += (tn * tn);
|
||||||
|
den += (td * td);
|
||||||
|
recon_mean += oup[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
recon_var = sqrt(num / N);
|
||||||
|
recon_mean /= N;
|
||||||
|
|
||||||
|
printf("\nRMS Error %g \n", sqrt(num) / sqrt(den));
|
||||||
|
printf("\nVariance %g \n", recon_var);
|
||||||
|
printf("\nMean %g \n", recon_mean);
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(oup);
|
||||||
|
cwt_free(wt);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/denoisetest
Executable file
BIN
dep/wavelib/test/denoisetest
Executable file
Binary file not shown.
139
dep/wavelib/test/denoisetest.c
Normal file
139
dep/wavelib/test/denoisetest.c
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "../header/wauxlib.h"
|
||||||
|
|
||||||
|
static double rmse(int N,double *x,double *y) {
|
||||||
|
double rms;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
rms = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
rms += (x[i] - y[i]) * (x[i] - y[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
rms = sqrt(rms/(double)N);
|
||||||
|
|
||||||
|
return rms;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double corrcoef(int N,double *x,double *y) {
|
||||||
|
double cc,xm,ym,tx,ty,num,den1,den2;
|
||||||
|
int i;
|
||||||
|
xm = ym = 0.0;
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
xm += x[i];
|
||||||
|
ym += y[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
xm = xm/N;
|
||||||
|
ym = ym / N;
|
||||||
|
num = den1 = den2 = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
tx = x[i] - xm;
|
||||||
|
ty = y[i] - ym;
|
||||||
|
num += (tx*ty);
|
||||||
|
den1 += (tx*tx);
|
||||||
|
den2 += (ty*ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
cc = num / sqrt(den1*den2);
|
||||||
|
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// gcc -Wall -I../header -L../Bin denoisetest.c -o denoise -lwauxlib -lwavelib -lm
|
||||||
|
double *sig,*inp,*oup;
|
||||||
|
int i,N,J;
|
||||||
|
FILE *ifp;
|
||||||
|
|
||||||
|
denoise_object obj;
|
||||||
|
double temp[2400];
|
||||||
|
|
||||||
|
char *wname = "db5";
|
||||||
|
char *method = "dwt";// Available - dwt, swt and modwt. modwt works only with modwtshrink. The other two methods work with
|
||||||
|
// visushrink and sureshrink
|
||||||
|
char *ext = "sym";// sym and per work with dwt. swt and modwt only use per extension when called through denoise.
|
||||||
|
// You can use sy extension if you directly call modwtshrink with cmethod set to fft. See modwtdenoisetest.c file
|
||||||
|
char *thresh = "soft";// soft or hard
|
||||||
|
char *level = "all"; // noise estimation at "first" or "all" levels. modwt only has the option of "all"
|
||||||
|
|
||||||
|
ifp = fopen("pieceregular1024.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
N = i;
|
||||||
|
J = 4;
|
||||||
|
|
||||||
|
sig = (double*)malloc(sizeof(double)* N);
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
oup = (double*)malloc(sizeof(double)* N);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
sig[i] = temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ifp = fopen("PieceRegular10.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
inp[i] = temp[i];
|
||||||
|
}
|
||||||
|
obj = denoise_init(N,J,wname);
|
||||||
|
setDenoiseMethod(obj,"visushrink");// sureshrink is also the default. The other option with dwt and swt is visushrink.
|
||||||
|
// modwt works only with modwtshrink method
|
||||||
|
setDenoiseWTMethod(obj,method);// Default is dwt. the other options are swt and modwt
|
||||||
|
setDenoiseWTExtension(obj,ext);// Default is sym. the other option is per
|
||||||
|
setDenoiseParameters(obj,thresh,level);// Default for thresh is soft. Other option is hard
|
||||||
|
// Default for level is all. The other option is first
|
||||||
|
|
||||||
|
denoise(obj,inp,oup);
|
||||||
|
|
||||||
|
// Alternative to denoise_object
|
||||||
|
// Just use visushrink, modwtshrink and sureshrink functions
|
||||||
|
//visushrink(inp,N,J,wname,method,ext,thresh,level,oup);
|
||||||
|
//sureshrink(inp,N,J,wname,method,ext,thresh,level,oup);
|
||||||
|
// modwtshrink(sig,N,J,wname,cmethod,ext,thresh,oup); See modwtdenoisetest.c
|
||||||
|
//ofp = fopen("denoiseds.txt", "w");
|
||||||
|
|
||||||
|
|
||||||
|
printf("Signal - Noisy Signal Stats \n");
|
||||||
|
printf("RMSE %g\n",rmse(N,sig,inp));
|
||||||
|
printf("Corr Coeff %g\n",corrcoef(N,sig,inp));
|
||||||
|
|
||||||
|
printf("Signal - DeNoised Signal Stats \n");
|
||||||
|
printf("RMSE %g\n",rmse(N,sig,oup));
|
||||||
|
printf("Corr Coeff %g\n",corrcoef(N,sig,oup));
|
||||||
|
|
||||||
|
free(sig);
|
||||||
|
free(inp);
|
||||||
|
denoise_free(obj);
|
||||||
|
free(oup);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/dwpttest
Executable file
BIN
dep/wavelib/test/dwpttest
Executable file
Binary file not shown.
61
dep/wavelib/test/dwpttest.c
Normal file
61
dep/wavelib/test/dwpttest.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i, J, N;
|
||||||
|
wave_object obj;
|
||||||
|
wpt_object wt;
|
||||||
|
double *inp, *oup, *diff;
|
||||||
|
|
||||||
|
char *name = "db4";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
N = 788 + 23;
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
oup = (double*)malloc(sizeof(double)* N);
|
||||||
|
diff = (double*)malloc(sizeof(double)* N);
|
||||||
|
for (i = 1; i < N + 1; ++i) {
|
||||||
|
//inp[i - 1] = -0.25*i*i*i + 25 * i *i + 10 * i;
|
||||||
|
inp[i - 1] = i;
|
||||||
|
}
|
||||||
|
J = 4;
|
||||||
|
|
||||||
|
wt = wpt_init(obj, N, J);// Initialize the wavelet transform Tree object
|
||||||
|
setDWPTExtension(wt, "per");// Options are "per" and "sym". Symmetric is the default option
|
||||||
|
setDWPTEntropy(wt, "logenergy", 0);
|
||||||
|
|
||||||
|
dwpt(wt, inp); // Discrete Wavelet Packet Transform
|
||||||
|
|
||||||
|
idwpt(wt, oup); // Inverse Discrete Wavelet Packet Transform
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
diff[i] = (inp[i] - oup[i])/inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
wpt_summary(wt); // Tree Summary
|
||||||
|
|
||||||
|
printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(oup);
|
||||||
|
free(diff);
|
||||||
|
wave_free(obj);
|
||||||
|
wpt_free(wt);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/dwt2test
Executable file
BIN
dep/wavelib/test/dwt2test
Executable file
Binary file not shown.
87
dep/wavelib/test/dwt2test.c
Normal file
87
dep/wavelib/test/dwt2test.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
double generate_rnd() {
|
||||||
|
double rnd;
|
||||||
|
|
||||||
|
rnd = (double) (rand() % 100 + 1);
|
||||||
|
|
||||||
|
return rnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt2_object wt;
|
||||||
|
int i, k, J, rows, cols,N;
|
||||||
|
double *inp, *wavecoeffs,*oup,*diff;
|
||||||
|
double *cLL;
|
||||||
|
int ir, ic;
|
||||||
|
double amax;
|
||||||
|
|
||||||
|
rows = 32;
|
||||||
|
cols = 30;
|
||||||
|
N = rows*cols;
|
||||||
|
|
||||||
|
char *name = "db2";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
srand(time(0));
|
||||||
|
inp = (double*)calloc(N, sizeof(double));
|
||||||
|
oup = (double*)calloc(N, sizeof(double));
|
||||||
|
diff = (double*)calloc(N, sizeof(double));
|
||||||
|
|
||||||
|
J = 3;
|
||||||
|
|
||||||
|
wt = wt2_init(obj, "dwt", rows,cols, J);
|
||||||
|
|
||||||
|
for (i = 0; i < rows; ++i) {
|
||||||
|
for (k = 0; k < cols; ++k) {
|
||||||
|
//inp[i*cols + k] = i*cols + k;
|
||||||
|
inp[i*cols + k] = generate_rnd();
|
||||||
|
oup[i*cols + k] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wavecoeffs = dwt2(wt, inp);
|
||||||
|
|
||||||
|
cLL = getWT2Coeffs(wt, wavecoeffs, 1, "D", &ir, &ic);
|
||||||
|
|
||||||
|
dispWT2Coeffs(cLL, ir, ic);
|
||||||
|
|
||||||
|
idwt2(wt, wavecoeffs, oup);
|
||||||
|
|
||||||
|
for (i = 0; i < rows*cols; ++i) {
|
||||||
|
diff[i] = oup[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
amax = absmax(diff, rows*cols);
|
||||||
|
|
||||||
|
wt2_summary(wt);
|
||||||
|
|
||||||
|
printf("Abs Max %g \n", amax);
|
||||||
|
|
||||||
|
wave_free(obj);
|
||||||
|
wt2_free(wt);
|
||||||
|
free(inp);
|
||||||
|
free(wavecoeffs);
|
||||||
|
free(oup);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/dwttest
Executable file
BIN
dep/wavelib/test/dwttest
Executable file
Binary file not shown.
85
dep/wavelib/test/dwttest.c
Normal file
85
dep/wavelib/test/dwttest.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt_object wt;
|
||||||
|
double *inp,*out,*diff;
|
||||||
|
int N, i,J;
|
||||||
|
|
||||||
|
FILE *ifp;
|
||||||
|
double temp[1200];
|
||||||
|
|
||||||
|
char *name = "db4";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
|
||||||
|
ifp = fopen("signal.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
N = 256;
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
out = (double*)malloc(sizeof(double)* N);
|
||||||
|
diff = (double*)malloc(sizeof(double)* N);
|
||||||
|
//wmean = mean(temp, N);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
inp[i] = temp[i];
|
||||||
|
//printf("%g \n",inp[i]);
|
||||||
|
}
|
||||||
|
J = 3;
|
||||||
|
|
||||||
|
wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
|
||||||
|
setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
|
||||||
|
setWTConv(wt, "direct");
|
||||||
|
|
||||||
|
dwt(wt, inp);// Perform DWT
|
||||||
|
//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
|
||||||
|
|
||||||
|
for (i = 0; i < wt->outlength; ++i) {
|
||||||
|
printf("%g ",wt->output[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
idwt(wt, out);// Perform IDWT (if needed)
|
||||||
|
// Test Reconstruction
|
||||||
|
for (i = 0; i < wt->siglength; ++i) {
|
||||||
|
diff[i] = out[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
|
||||||
|
|
||||||
|
wt_summary(wt);// Prints the full summary.
|
||||||
|
wave_free(obj);
|
||||||
|
wt_free(wt);
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(out);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/modwt2test
Executable file
BIN
dep/wavelib/test/modwt2test
Executable file
Binary file not shown.
82
dep/wavelib/test/modwt2test.c
Normal file
82
dep/wavelib/test/modwt2test.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
double generate_rnd() {
|
||||||
|
double rnd;
|
||||||
|
|
||||||
|
rnd = (double) (rand() % 100 + 1);
|
||||||
|
|
||||||
|
return rnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt2_object wt;
|
||||||
|
int i, k, J, rows, cols,N,ir,ic;
|
||||||
|
double *inp, *wavecoeffs, *oup,*cLL,*diff;
|
||||||
|
double amax;
|
||||||
|
rows = 51;
|
||||||
|
cols = 40;
|
||||||
|
N = rows*cols;
|
||||||
|
char *name = "db2";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
|
||||||
|
inp = (double*)calloc(N, sizeof(double));
|
||||||
|
oup = (double*)calloc(N, sizeof(double));
|
||||||
|
diff = (double*)calloc(N, sizeof(double));
|
||||||
|
J = 2;
|
||||||
|
|
||||||
|
wt = wt2_init(obj, "modwt", rows, cols, J);
|
||||||
|
|
||||||
|
for (i = 0; i < rows; ++i) {
|
||||||
|
for (k = 0; k < cols; ++k) {
|
||||||
|
//inp[i*cols + k] = i*cols + k;
|
||||||
|
inp[i*cols + k] = generate_rnd();
|
||||||
|
oup[i*cols + k] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wavecoeffs = modwt2(wt, inp);
|
||||||
|
|
||||||
|
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
|
||||||
|
|
||||||
|
//dispWT2Coeffs(cLL, ir, ic);
|
||||||
|
|
||||||
|
imodwt2(wt, wavecoeffs, oup);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
diff[i] = oup[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
amax = absmax(diff, N);
|
||||||
|
|
||||||
|
wt2_summary(wt);
|
||||||
|
|
||||||
|
printf("Abs Max %g \n", amax);
|
||||||
|
|
||||||
|
wave_free(obj);
|
||||||
|
wt2_free(wt);
|
||||||
|
free(inp);
|
||||||
|
free(wavecoeffs);
|
||||||
|
free(oup);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/modwtdenoisetest
Executable file
BIN
dep/wavelib/test/modwtdenoisetest
Executable file
Binary file not shown.
123
dep/wavelib/test/modwtdenoisetest.c
Normal file
123
dep/wavelib/test/modwtdenoisetest.c
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "../header/wauxlib.h"
|
||||||
|
|
||||||
|
static double rmse(int N,double *x,double *y) {
|
||||||
|
double rms;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
rms = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
rms += (x[i] - y[i]) * (x[i] - y[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
rms = sqrt(rms/(double)N);
|
||||||
|
|
||||||
|
return rms;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double corrcoef(int N,double *x,double *y) {
|
||||||
|
double cc,xm,ym,tx,ty,num,den1,den2;
|
||||||
|
int i;
|
||||||
|
xm = ym = 0.0;
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
xm += x[i];
|
||||||
|
ym += y[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
xm = xm/N;
|
||||||
|
ym = ym / N;
|
||||||
|
num = den1 = den2 = 0.0;
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
tx = x[i] - xm;
|
||||||
|
ty = y[i] - ym;
|
||||||
|
num += (tx*ty);
|
||||||
|
den1 += (tx*tx);
|
||||||
|
den2 += (ty*ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
cc = num / sqrt(den1*den2);
|
||||||
|
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// gcc -Wall -I../header -L../Bin modwtdenoisetest.c -o modwtdenoise -lwauxlib -lwavelib -lm
|
||||||
|
/*
|
||||||
|
modwtshrink can also be called from the denoise object. See denoisetest.c for more information
|
||||||
|
*/
|
||||||
|
double *sig,*inp,*oup;
|
||||||
|
int i,N,J;
|
||||||
|
FILE *ifp;
|
||||||
|
|
||||||
|
double temp[2400];
|
||||||
|
|
||||||
|
char *wname = "db5";
|
||||||
|
char *ext = "per";// The other option sym is only available with "fft" cmethod
|
||||||
|
char *thresh = "soft";
|
||||||
|
char *cmethod = "direct";// The other option is "fft"
|
||||||
|
|
||||||
|
ifp = fopen("pieceregular1024.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
N = i;
|
||||||
|
J = 4;
|
||||||
|
|
||||||
|
sig = (double*)malloc(sizeof(double)* N);
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
oup = (double*)malloc(sizeof(double)* N);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
sig[i] = temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ifp = fopen("PieceRegular10.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
for(i = 0; i < N;++i) {
|
||||||
|
inp[i] = temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
modwtshrink(sig,N,J,wname,cmethod,ext,thresh,oup);
|
||||||
|
|
||||||
|
|
||||||
|
printf("Signal - Noisy Signal Stats \n");
|
||||||
|
printf("RMSE %g\n",rmse(N,sig,inp));
|
||||||
|
printf("Corr Coeff %g\n",corrcoef(N,sig,inp));
|
||||||
|
|
||||||
|
printf("Signal - DeNoised Signal Stats \n");
|
||||||
|
printf("RMSE %g\n",rmse(N,sig,oup));
|
||||||
|
printf("Corr Coeff %g\n",corrcoef(N,sig,oup));
|
||||||
|
|
||||||
|
free(sig);
|
||||||
|
free(inp);
|
||||||
|
free(oup);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/modwttest
Executable file
BIN
dep/wavelib/test/modwttest
Executable file
Binary file not shown.
88
dep/wavelib/test/modwttest.c
Normal file
88
dep/wavelib/test/modwttest.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt_object wt;
|
||||||
|
double *inp, *out, *diff;
|
||||||
|
int N, i, J;
|
||||||
|
|
||||||
|
FILE *ifp;
|
||||||
|
double temp[1200];
|
||||||
|
|
||||||
|
char *name = "db4";
|
||||||
|
obj = wave_init(name);
|
||||||
|
wave_summary(obj);
|
||||||
|
|
||||||
|
ifp = fopen("signal.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
N = 177;
|
||||||
|
|
||||||
|
fclose(ifp);
|
||||||
|
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
out = (double*)malloc(sizeof(double)* N);
|
||||||
|
diff = (double*)malloc(sizeof(double)* N);
|
||||||
|
//wmean = mean(temp, N);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
inp[i] = temp[i];
|
||||||
|
//printf("%g \n",inp[i]);
|
||||||
|
}
|
||||||
|
J = 2;
|
||||||
|
|
||||||
|
wt = wt_init(obj, "modwt", N, J);// Initialize the wavelet transform object
|
||||||
|
|
||||||
|
modwt(wt, inp);// Perform MODWT
|
||||||
|
//MODWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
|
||||||
|
|
||||||
|
for (i = 0; i < wt->outlength; ++i) {
|
||||||
|
printf("%g ",wt->output[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
imodwt(wt, out);// Perform ISWT (if needed)
|
||||||
|
// Test Reconstruction
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < wt->siglength; ++i) {
|
||||||
|
diff[i] = out[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value.
|
||||||
|
|
||||||
|
wt_summary(wt);// Prints the full summary.
|
||||||
|
|
||||||
|
wave_free(obj);
|
||||||
|
wt_free(wt);
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(out);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
2048
dep/wavelib/test/noisybumps.txt
Normal file
2048
dep/wavelib/test/noisybumps.txt
Normal file
File diff suppressed because it is too large
Load Diff
512
dep/wavelib/test/noisyheavisine.txt
Normal file
512
dep/wavelib/test/noisyheavisine.txt
Normal file
@ -0,0 +1,512 @@
|
|||||||
|
1.0657
|
||||||
|
1.0006
|
||||||
|
0.6117
|
||||||
|
0.4044
|
||||||
|
0.7049
|
||||||
|
0.8592
|
||||||
|
0.4489
|
||||||
|
0.6764
|
||||||
|
1.4804
|
||||||
|
1.3729
|
||||||
|
1.1876
|
||||||
|
0.8359
|
||||||
|
1.0592
|
||||||
|
1.6929
|
||||||
|
1.5832
|
||||||
|
1.4987
|
||||||
|
1.9193
|
||||||
|
0.9968
|
||||||
|
2.2814
|
||||||
|
1.8615
|
||||||
|
1.8153
|
||||||
|
2.2991
|
||||||
|
2.3962
|
||||||
|
2.6282
|
||||||
|
2.6752
|
||||||
|
2.8719
|
||||||
|
2.3616
|
||||||
|
2.2559
|
||||||
|
2.3763
|
||||||
|
2.5818
|
||||||
|
3.2529
|
||||||
|
2.2118
|
||||||
|
2.7430
|
||||||
|
3.0733
|
||||||
|
3.3577
|
||||||
|
2.7022
|
||||||
|
3.1119
|
||||||
|
3.2637
|
||||||
|
3.2952
|
||||||
|
3.4738
|
||||||
|
3.3380
|
||||||
|
3.1535
|
||||||
|
3.3264
|
||||||
|
3.5341
|
||||||
|
4.1180
|
||||||
|
3.7819
|
||||||
|
3.6842
|
||||||
|
3.8126
|
||||||
|
3.9201
|
||||||
|
4.4759
|
||||||
|
3.9019
|
||||||
|
4.4292
|
||||||
|
3.9813
|
||||||
|
4.2000
|
||||||
|
4.1341
|
||||||
|
4.6312
|
||||||
|
3.5677
|
||||||
|
3.5918
|
||||||
|
4.1196
|
||||||
|
4.3429
|
||||||
|
4.0506
|
||||||
|
3.9147
|
||||||
|
4.5915
|
||||||
|
3.7525
|
||||||
|
4.3211
|
||||||
|
4.7630
|
||||||
|
4.1468
|
||||||
|
3.6378
|
||||||
|
4.9381
|
||||||
|
3.6221
|
||||||
|
4.0528
|
||||||
|
4.2498
|
||||||
|
4.3916
|
||||||
|
3.8548
|
||||||
|
4.1120
|
||||||
|
3.1226
|
||||||
|
3.8218
|
||||||
|
3.4635
|
||||||
|
3.0588
|
||||||
|
4.1349
|
||||||
|
4.2391
|
||||||
|
3.7100
|
||||||
|
3.1359
|
||||||
|
4.4892
|
||||||
|
3.3203
|
||||||
|
3.7948
|
||||||
|
3.3253
|
||||||
|
3.8491
|
||||||
|
3.3987
|
||||||
|
3.0231
|
||||||
|
3.1837
|
||||||
|
3.0502
|
||||||
|
3.5930
|
||||||
|
3.2456
|
||||||
|
3.0435
|
||||||
|
2.5884
|
||||||
|
2.4189
|
||||||
|
2.9470
|
||||||
|
3.1980
|
||||||
|
2.2149
|
||||||
|
1.9529
|
||||||
|
3.0684
|
||||||
|
2.3438
|
||||||
|
1.9030
|
||||||
|
1.6420
|
||||||
|
2.5492
|
||||||
|
2.5800
|
||||||
|
2.5930
|
||||||
|
2.0497
|
||||||
|
1.7434
|
||||||
|
2.4729
|
||||||
|
2.0337
|
||||||
|
0.7426
|
||||||
|
1.3418
|
||||||
|
2.2373
|
||||||
|
0.8947
|
||||||
|
1.1703
|
||||||
|
0.8237
|
||||||
|
1.4013
|
||||||
|
0.5204
|
||||||
|
0.7086
|
||||||
|
0.2940
|
||||||
|
0.4183
|
||||||
|
0.8239
|
||||||
|
0.3488
|
||||||
|
0.1901
|
||||||
|
-0.2755
|
||||||
|
-0.5884
|
||||||
|
0.0459
|
||||||
|
-0.0061
|
||||||
|
-0.1662
|
||||||
|
-1.1395
|
||||||
|
-0.2187
|
||||||
|
-0.4940
|
||||||
|
-0.1904
|
||||||
|
-0.7303
|
||||||
|
-0.8049
|
||||||
|
-1.2128
|
||||||
|
-1.4796
|
||||||
|
-1.2787
|
||||||
|
-0.6750
|
||||||
|
-0.6300
|
||||||
|
-1.9705
|
||||||
|
-1.3766
|
||||||
|
-1.6300
|
||||||
|
-1.6662
|
||||||
|
-1.4749
|
||||||
|
-2.2873
|
||||||
|
-2.3715
|
||||||
|
-1.9438
|
||||||
|
-2.0246
|
||||||
|
-2.3207
|
||||||
|
-2.3904
|
||||||
|
-4.0250
|
||||||
|
-4.7166
|
||||||
|
-4.6094
|
||||||
|
-4.3269
|
||||||
|
-4.5663
|
||||||
|
-4.1415
|
||||||
|
-4.8460
|
||||||
|
-4.9088
|
||||||
|
-5.1159
|
||||||
|
-5.2494
|
||||||
|
-4.7209
|
||||||
|
-5.6772
|
||||||
|
-5.3329
|
||||||
|
-6.3053
|
||||||
|
-5.0153
|
||||||
|
-5.1394
|
||||||
|
-5.0556
|
||||||
|
-5.8880
|
||||||
|
-5.5547
|
||||||
|
-5.5403
|
||||||
|
-6.3194
|
||||||
|
-6.3660
|
||||||
|
-5.9584
|
||||||
|
-5.1940
|
||||||
|
-4.9157
|
||||||
|
-5.7317
|
||||||
|
-6.5066
|
||||||
|
-5.7450
|
||||||
|
-5.7231
|
||||||
|
-5.9420
|
||||||
|
-5.8529
|
||||||
|
-6.6728
|
||||||
|
-6.5548
|
||||||
|
-5.6438
|
||||||
|
-6.0741
|
||||||
|
-6.6387
|
||||||
|
-6.1218
|
||||||
|
-6.3158
|
||||||
|
-5.7250
|
||||||
|
-6.0155
|
||||||
|
-5.8662
|
||||||
|
-5.7875
|
||||||
|
-6.3902
|
||||||
|
-5.9303
|
||||||
|
-6.0030
|
||||||
|
-5.6667
|
||||||
|
-5.1734
|
||||||
|
-5.7733
|
||||||
|
-5.9180
|
||||||
|
-5.8427
|
||||||
|
-6.0721
|
||||||
|
-6.4873
|
||||||
|
-5.5756
|
||||||
|
-5.9103
|
||||||
|
-5.5415
|
||||||
|
-5.6358
|
||||||
|
-5.8095
|
||||||
|
-5.4756
|
||||||
|
-5.2417
|
||||||
|
-5.4192
|
||||||
|
-5.3777
|
||||||
|
-5.7800
|
||||||
|
-4.8058
|
||||||
|
-4.7930
|
||||||
|
-6.2389
|
||||||
|
-5.9839
|
||||||
|
-4.9383
|
||||||
|
-5.3716
|
||||||
|
-5.4538
|
||||||
|
-3.8454
|
||||||
|
-5.1885
|
||||||
|
-5.2452
|
||||||
|
-4.5655
|
||||||
|
-4.9033
|
||||||
|
-4.9928
|
||||||
|
-5.0235
|
||||||
|
-4.6184
|
||||||
|
-4.0967
|
||||||
|
-4.8166
|
||||||
|
-4.1745
|
||||||
|
-4.0614
|
||||||
|
-4.1093
|
||||||
|
-3.4929
|
||||||
|
-3.5424
|
||||||
|
-2.5478
|
||||||
|
-4.1180
|
||||||
|
-3.4682
|
||||||
|
-3.1256
|
||||||
|
-3.5773
|
||||||
|
-3.0447
|
||||||
|
-2.4956
|
||||||
|
-2.7483
|
||||||
|
-2.6201
|
||||||
|
-2.9657
|
||||||
|
-2.6621
|
||||||
|
-2.8913
|
||||||
|
-2.6488
|
||||||
|
-2.5289
|
||||||
|
-1.9951
|
||||||
|
-2.1213
|
||||||
|
-2.2065
|
||||||
|
-2.2494
|
||||||
|
-2.0965
|
||||||
|
-2.3657
|
||||||
|
-1.5025
|
||||||
|
-1.2423
|
||||||
|
-2.0154
|
||||||
|
-0.8329
|
||||||
|
-1.6098
|
||||||
|
-1.2474
|
||||||
|
-1.0787
|
||||||
|
-1.2216
|
||||||
|
-1.0861
|
||||||
|
-1.3985
|
||||||
|
-0.8476
|
||||||
|
-0.4991
|
||||||
|
0.0904
|
||||||
|
-0.5278
|
||||||
|
0.1709
|
||||||
|
-0.5306
|
||||||
|
-0.8072
|
||||||
|
-0.4898
|
||||||
|
-0.3393
|
||||||
|
0.2191
|
||||||
|
-0.4752
|
||||||
|
0.0910
|
||||||
|
-0.2168
|
||||||
|
-0.7928
|
||||||
|
0.4831
|
||||||
|
0.1193
|
||||||
|
0.9896
|
||||||
|
0.4941
|
||||||
|
1.1458
|
||||||
|
1.1746
|
||||||
|
1.6752
|
||||||
|
0.6359
|
||||||
|
0.5090
|
||||||
|
1.4067
|
||||||
|
0.9310
|
||||||
|
1.0004
|
||||||
|
1.4047
|
||||||
|
1.4470
|
||||||
|
1.4776
|
||||||
|
1.8183
|
||||||
|
1.7719
|
||||||
|
1.0112
|
||||||
|
1.6877
|
||||||
|
1.3403
|
||||||
|
1.2260
|
||||||
|
1.7027
|
||||||
|
1.7228
|
||||||
|
1.5210
|
||||||
|
1.9816
|
||||||
|
2.0695
|
||||||
|
2.0422
|
||||||
|
1.6521
|
||||||
|
1.3538
|
||||||
|
1.6597
|
||||||
|
1.6981
|
||||||
|
1.9754
|
||||||
|
2.2320
|
||||||
|
2.8194
|
||||||
|
1.9796
|
||||||
|
1.9535
|
||||||
|
1.8937
|
||||||
|
1.6508
|
||||||
|
2.1684
|
||||||
|
1.9457
|
||||||
|
2.2100
|
||||||
|
2.3376
|
||||||
|
1.4828
|
||||||
|
2.3156
|
||||||
|
1.6363
|
||||||
|
1.6415
|
||||||
|
1.6262
|
||||||
|
1.7795
|
||||||
|
1.2742
|
||||||
|
2.1842
|
||||||
|
1.5837
|
||||||
|
2.1802
|
||||||
|
2.5516
|
||||||
|
1.8494
|
||||||
|
1.5392
|
||||||
|
1.8861
|
||||||
|
1.1615
|
||||||
|
1.5972
|
||||||
|
1.5326
|
||||||
|
1.4134
|
||||||
|
1.1573
|
||||||
|
0.9850
|
||||||
|
1.3061
|
||||||
|
1.5567
|
||||||
|
1.1001
|
||||||
|
0.5861
|
||||||
|
1.2758
|
||||||
|
1.4634
|
||||||
|
0.5481
|
||||||
|
-0.2347
|
||||||
|
1.2253
|
||||||
|
0.7886
|
||||||
|
-0.0569
|
||||||
|
0.3684
|
||||||
|
1.0031
|
||||||
|
0.2320
|
||||||
|
0.2774
|
||||||
|
0.3051
|
||||||
|
0.2066
|
||||||
|
-0.0612
|
||||||
|
-0.4045
|
||||||
|
0.2544
|
||||||
|
0.1755
|
||||||
|
0.1436
|
||||||
|
0.6782
|
||||||
|
-0.3352
|
||||||
|
-0.4587
|
||||||
|
1.8259
|
||||||
|
1.3455
|
||||||
|
1.8159
|
||||||
|
1.8610
|
||||||
|
1.4192
|
||||||
|
1.4261
|
||||||
|
1.0369
|
||||||
|
0.8564
|
||||||
|
0.4077
|
||||||
|
0.5913
|
||||||
|
0.0495
|
||||||
|
1.1516
|
||||||
|
0.2284
|
||||||
|
-0.0953
|
||||||
|
-0.2963
|
||||||
|
0.3560
|
||||||
|
0.0803
|
||||||
|
0.1577
|
||||||
|
0.1330
|
||||||
|
-0.4338
|
||||||
|
0.1264
|
||||||
|
-0.5193
|
||||||
|
-0.3638
|
||||||
|
-1.4667
|
||||||
|
-0.8071
|
||||||
|
-1.1646
|
||||||
|
-1.3581
|
||||||
|
-2.0099
|
||||||
|
-1.9754
|
||||||
|
-1.3684
|
||||||
|
-1.4739
|
||||||
|
-2.0044
|
||||||
|
-1.9212
|
||||||
|
-1.3331
|
||||||
|
-1.8712
|
||||||
|
-1.9120
|
||||||
|
-1.6113
|
||||||
|
-1.4759
|
||||||
|
-2.5851
|
||||||
|
-1.5004
|
||||||
|
-2.2432
|
||||||
|
-2.4955
|
||||||
|
-1.8040
|
||||||
|
-2.2723
|
||||||
|
-2.7506
|
||||||
|
-2.7914
|
||||||
|
-3.0147
|
||||||
|
-3.1889
|
||||||
|
-2.6117
|
||||||
|
-2.9667
|
||||||
|
-4.1494
|
||||||
|
-3.1516
|
||||||
|
-2.9235
|
||||||
|
-2.9130
|
||||||
|
-3.3368
|
||||||
|
-3.5575
|
||||||
|
-3.2338
|
||||||
|
-3.6494
|
||||||
|
-3.2499
|
||||||
|
-4.3063
|
||||||
|
-3.3651
|
||||||
|
-2.9785
|
||||||
|
-3.3652
|
||||||
|
-3.4743
|
||||||
|
-4.0558
|
||||||
|
-3.9807
|
||||||
|
-3.2774
|
||||||
|
-4.0199
|
||||||
|
-4.5528
|
||||||
|
-4.2490
|
||||||
|
-3.5356
|
||||||
|
-3.9068
|
||||||
|
-3.7764
|
||||||
|
-3.7189
|
||||||
|
-3.2039
|
||||||
|
-3.6964
|
||||||
|
-4.9097
|
||||||
|
-3.4455
|
||||||
|
-3.4451
|
||||||
|
-4.1807
|
||||||
|
-4.2489
|
||||||
|
-3.5878
|
||||||
|
-4.1839
|
||||||
|
-4.1409
|
||||||
|
-3.4127
|
||||||
|
-3.8450
|
||||||
|
-3.1923
|
||||||
|
-4.2415
|
||||||
|
-4.1260
|
||||||
|
-3.1998
|
||||||
|
-4.1118
|
||||||
|
-4.3941
|
||||||
|
-4.0991
|
||||||
|
-3.7035
|
||||||
|
-3.5813
|
||||||
|
-3.6244
|
||||||
|
-3.8968
|
||||||
|
-4.0114
|
||||||
|
-3.0996
|
||||||
|
-2.5770
|
||||||
|
-2.5784
|
||||||
|
-2.5148
|
||||||
|
-3.4869
|
||||||
|
-3.1257
|
||||||
|
-3.3178
|
||||||
|
-3.2136
|
||||||
|
-3.3256
|
||||||
|
-3.1696
|
||||||
|
-2.6366
|
||||||
|
-2.7773
|
||||||
|
-3.4404
|
||||||
|
-2.7195
|
||||||
|
-1.7045
|
||||||
|
-2.7076
|
||||||
|
-2.4246
|
||||||
|
-3.3656
|
||||||
|
-2.7804
|
||||||
|
-2.5646
|
||||||
|
-2.2261
|
||||||
|
-1.8682
|
||||||
|
-2.7736
|
||||||
|
-2.1846
|
||||||
|
-2.2518
|
||||||
|
-2.1819
|
||||||
|
-1.6506
|
||||||
|
-1.1380
|
||||||
|
-1.4379
|
||||||
|
-1.2677
|
||||||
|
-0.9920
|
||||||
|
-0.9576
|
||||||
|
-1.7788
|
||||||
|
-1.1704
|
||||||
|
-1.0133
|
||||||
|
-0.0132
|
||||||
|
-0.5174
|
||||||
|
-0.7500
|
||||||
|
-0.5398
|
||||||
|
-1.4065
|
||||||
|
-1.4180
|
||||||
|
-0.5397
|
||||||
|
0.2176
|
||||||
|
0.0255
|
||||||
|
-0.1699
|
||||||
|
-0.0142
|
1024
dep/wavelib/test/pieceregular1024.txt
Normal file
1024
dep/wavelib/test/pieceregular1024.txt
Normal file
File diff suppressed because it is too large
Load Diff
79926
dep/wavelib/test/s1.txt
Normal file
79926
dep/wavelib/test/s1.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
dep/wavelib/test/signal.txt
Normal file
1
dep/wavelib/test/signal.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
-18.3237
-18.2232
-18.0974
-17.9410
-17.7480
-17.5113
-17.2230
-16.8744
-16.4558
-15.9565
-15.3653
-14.6701
-13.8586
-12.9182
-11.8363
-10.6008
-9.2006
-7.6257
-5.8680
-3.9217
-1.7839
0.5452
3.0614
5.7562
8.6167
11.6252
14.7591
17.9909
21.2884
24.6155
27.9319
31.1947
34.3587
37.3775
40.2049
42.7957
13.2164
14.2125
15.0317
15.6595
16.0845
16.2990
16.2990
16.0845
15.6595
15.0317
14.2125
13.2164
12.0608
10.7654
9.3517
34.3587
31.1947
27.9319
24.6155
21.2884
17.9909
14.7591
11.6252
8.6167
5.7562
3.0614
0.5452
-1.7839
-3.9217
-5.8680
-7.6257
-9.2006
-10.6008
-11.8363
-12.9182
-13.8586
-14.6701
-15.3653
-15.9565
-16.4558
-16.8744
-17.2230
-17.5113
-17.7480
-17.9410
-18.0974
-18.2232
-18.3237
-18.4035
-18.0080
-17.8889
-17.7403
-17.5533
-17.3156
-17.0102
-16.6129
-16.0884
-15.3848
-14.4239
-13.0840
-11.1708
-8.3634
-4.1098
2.5833
13.6048
32.7934
28.0187
10.9660
1.0776
-4.9459
-8.7354
-11.1225
-12.4865
-12.8019
-11.2050
-3.3124
1.8995
-11.3573
-15.0684
-16.5028
-17.1937
-17.5831
-17.8288
-17.9968
-18.1185
-18.2103
-18.2818
-18.3388
-18.3849
-18.4229
-18.4545
-18.4810
-17.4642
-17.2104
-16.9033
-16.5317
-16.0822
-15.5384
-14.8804
-14.0844
-13.1214
-11.9563
-10.5467
-8.8414
-6.7782
-4.2822
-1.2624
2.3911
6.8111
12.1585
18.6280
26.4549
35.9241
35.9241
26.4549
18.6280
12.1585
6.8111
2.3911
-1.2624
-4.2822
-6.7782
-8.8414
-10.5467
-11.9563
-13.1214
-14.0844
-14.8804
-15.5384
-16.0822
-16.5317
-16.9033
-17.2104
-17.4642
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
6.3259
34.8066
34.6752
34.5285
34.3645
34.1812
33.9763
33.7474
33.4917
33.2058
32.8863
32.5294
32.1304
31.6846
31.1864
30.6296
30.0074
29.3121
28.5350
27.6667
26.6963
25.6118
24.3999
23.0456
21.5322
19.8408
17.9507
15.8385
13.4781
10.8403
7.8925
4.5982
0.9168
-3.1972
-7.7947
-12.9325
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.6741
-18.3237
|
504
dep/wavelib/test/sst_nino3.dat
Normal file
504
dep/wavelib/test/sst_nino3.dat
Normal file
@ -0,0 +1,504 @@
|
|||||||
|
-0.15
|
||||||
|
-0.30
|
||||||
|
-0.14
|
||||||
|
-0.41
|
||||||
|
-0.46
|
||||||
|
-0.66
|
||||||
|
-0.50
|
||||||
|
-0.80
|
||||||
|
-0.95
|
||||||
|
-0.72
|
||||||
|
-0.31
|
||||||
|
-0.71
|
||||||
|
-1.04
|
||||||
|
-0.77
|
||||||
|
-0.86
|
||||||
|
-0.84
|
||||||
|
-0.41
|
||||||
|
-0.49
|
||||||
|
-0.48
|
||||||
|
-0.72
|
||||||
|
-1.21
|
||||||
|
-0.80
|
||||||
|
0.16
|
||||||
|
0.46
|
||||||
|
0.40
|
||||||
|
1.00
|
||||||
|
2.17
|
||||||
|
2.50
|
||||||
|
2.34
|
||||||
|
0.80
|
||||||
|
0.14
|
||||||
|
-0.06
|
||||||
|
-0.34
|
||||||
|
-0.71
|
||||||
|
-0.34
|
||||||
|
-0.73
|
||||||
|
-0.48
|
||||||
|
-0.11
|
||||||
|
0.22
|
||||||
|
0.51
|
||||||
|
0.51
|
||||||
|
0.25
|
||||||
|
-0.10
|
||||||
|
-0.33
|
||||||
|
-0.42
|
||||||
|
-0.23
|
||||||
|
-0.53
|
||||||
|
-0.44
|
||||||
|
-0.30
|
||||||
|
0.15
|
||||||
|
0.09
|
||||||
|
0.19
|
||||||
|
-0.06
|
||||||
|
0.25
|
||||||
|
0.30
|
||||||
|
0.81
|
||||||
|
0.26
|
||||||
|
0.10
|
||||||
|
0.34
|
||||||
|
1.01
|
||||||
|
-0.31
|
||||||
|
-0.90
|
||||||
|
-0.73
|
||||||
|
-0.92
|
||||||
|
-0.73
|
||||||
|
-0.31
|
||||||
|
-0.03
|
||||||
|
0.12
|
||||||
|
0.37
|
||||||
|
0.82
|
||||||
|
1.22
|
||||||
|
1.83
|
||||||
|
1.60
|
||||||
|
0.34
|
||||||
|
-0.72
|
||||||
|
-0.87
|
||||||
|
-0.85
|
||||||
|
-0.40
|
||||||
|
-0.39
|
||||||
|
-0.65
|
||||||
|
0.07
|
||||||
|
0.67
|
||||||
|
0.39
|
||||||
|
0.03
|
||||||
|
-0.17
|
||||||
|
-0.76
|
||||||
|
-0.87
|
||||||
|
-1.36
|
||||||
|
-1.10
|
||||||
|
-0.99
|
||||||
|
-0.78
|
||||||
|
-0.93
|
||||||
|
-0.87
|
||||||
|
-0.44
|
||||||
|
-0.34
|
||||||
|
-0.50
|
||||||
|
-0.39
|
||||||
|
-0.04
|
||||||
|
0.42
|
||||||
|
0.62
|
||||||
|
0.17
|
||||||
|
0.23
|
||||||
|
1.03
|
||||||
|
1.54
|
||||||
|
1.09
|
||||||
|
0.01
|
||||||
|
0.12
|
||||||
|
-0.27
|
||||||
|
-0.47
|
||||||
|
-0.41
|
||||||
|
-0.37
|
||||||
|
-0.36
|
||||||
|
-0.39
|
||||||
|
0.43
|
||||||
|
1.05
|
||||||
|
1.58
|
||||||
|
1.25
|
||||||
|
0.86
|
||||||
|
0.60
|
||||||
|
0.21
|
||||||
|
0.19
|
||||||
|
-0.23
|
||||||
|
-0.29
|
||||||
|
0.18
|
||||||
|
0.12
|
||||||
|
0.71
|
||||||
|
1.42
|
||||||
|
1.59
|
||||||
|
0.93
|
||||||
|
-0.25
|
||||||
|
-0.66
|
||||||
|
-0.95
|
||||||
|
-0.47
|
||||||
|
0.06
|
||||||
|
0.70
|
||||||
|
0.81
|
||||||
|
0.78
|
||||||
|
1.43
|
||||||
|
1.22
|
||||||
|
1.05
|
||||||
|
0.44
|
||||||
|
-0.35
|
||||||
|
-0.67
|
||||||
|
-0.84
|
||||||
|
-0.66
|
||||||
|
-0.45
|
||||||
|
-0.12
|
||||||
|
-0.20
|
||||||
|
-0.16
|
||||||
|
-0.47
|
||||||
|
-0.52
|
||||||
|
-0.79
|
||||||
|
-0.80
|
||||||
|
-0.62
|
||||||
|
-0.86
|
||||||
|
-1.29
|
||||||
|
-1.04
|
||||||
|
-1.05
|
||||||
|
-0.75
|
||||||
|
-0.81
|
||||||
|
-0.90
|
||||||
|
-0.25
|
||||||
|
0.62
|
||||||
|
1.22
|
||||||
|
0.96
|
||||||
|
0.21
|
||||||
|
-0.11
|
||||||
|
-0.25
|
||||||
|
-0.24
|
||||||
|
-0.43
|
||||||
|
0.23
|
||||||
|
0.67
|
||||||
|
0.78
|
||||||
|
0.41
|
||||||
|
0.98
|
||||||
|
1.28
|
||||||
|
1.45
|
||||||
|
1.02
|
||||||
|
0.03
|
||||||
|
-0.59
|
||||||
|
-1.34
|
||||||
|
-0.99
|
||||||
|
-1.49
|
||||||
|
-1.74
|
||||||
|
-1.33
|
||||||
|
-0.55
|
||||||
|
-0.51
|
||||||
|
-0.36
|
||||||
|
-0.99
|
||||||
|
0.32
|
||||||
|
1.04
|
||||||
|
1.41
|
||||||
|
0.99
|
||||||
|
0.66
|
||||||
|
0.50
|
||||||
|
0.22
|
||||||
|
0.71
|
||||||
|
-0.16
|
||||||
|
0.38
|
||||||
|
0.00
|
||||||
|
-1.11
|
||||||
|
-1.04
|
||||||
|
0.05
|
||||||
|
-0.64
|
||||||
|
-0.34
|
||||||
|
-0.50
|
||||||
|
-1.85
|
||||||
|
-0.94
|
||||||
|
-0.78
|
||||||
|
0.29
|
||||||
|
0.27
|
||||||
|
0.69
|
||||||
|
-0.06
|
||||||
|
-0.83
|
||||||
|
-0.80
|
||||||
|
-1.02
|
||||||
|
-0.96
|
||||||
|
-0.09
|
||||||
|
0.62
|
||||||
|
0.87
|
||||||
|
1.03
|
||||||
|
0.70
|
||||||
|
-0.10
|
||||||
|
-0.31
|
||||||
|
0.04
|
||||||
|
-0.46
|
||||||
|
0.04
|
||||||
|
0.24
|
||||||
|
-0.08
|
||||||
|
-0.28
|
||||||
|
0.06
|
||||||
|
0.05
|
||||||
|
-0.31
|
||||||
|
0.11
|
||||||
|
0.27
|
||||||
|
0.26
|
||||||
|
0.04
|
||||||
|
0.12
|
||||||
|
1.11
|
||||||
|
1.53
|
||||||
|
1.23
|
||||||
|
0.17
|
||||||
|
-0.18
|
||||||
|
-0.56
|
||||||
|
0.05
|
||||||
|
0.41
|
||||||
|
0.22
|
||||||
|
0.04
|
||||||
|
-0.19
|
||||||
|
-0.46
|
||||||
|
-0.65
|
||||||
|
-1.06
|
||||||
|
-0.54
|
||||||
|
0.14
|
||||||
|
0.25
|
||||||
|
-0.21
|
||||||
|
-0.73
|
||||||
|
-0.43
|
||||||
|
0.48
|
||||||
|
0.26
|
||||||
|
0.05
|
||||||
|
0.11
|
||||||
|
-0.27
|
||||||
|
-0.08
|
||||||
|
-0.10
|
||||||
|
0.29
|
||||||
|
-0.15
|
||||||
|
-0.28
|
||||||
|
-0.55
|
||||||
|
-0.44
|
||||||
|
-1.40
|
||||||
|
-0.55
|
||||||
|
-0.69
|
||||||
|
0.58
|
||||||
|
0.37
|
||||||
|
0.42
|
||||||
|
1.83
|
||||||
|
1.23
|
||||||
|
0.65
|
||||||
|
0.41
|
||||||
|
1.03
|
||||||
|
0.64
|
||||||
|
-0.07
|
||||||
|
0.98
|
||||||
|
0.36
|
||||||
|
-0.30
|
||||||
|
-1.33
|
||||||
|
-1.39
|
||||||
|
-0.94
|
||||||
|
0.34
|
||||||
|
-0.00
|
||||||
|
-0.15
|
||||||
|
0.06
|
||||||
|
0.39
|
||||||
|
0.36
|
||||||
|
-0.49
|
||||||
|
-0.53
|
||||||
|
0.35
|
||||||
|
0.07
|
||||||
|
-0.24
|
||||||
|
0.20
|
||||||
|
-0.22
|
||||||
|
-0.68
|
||||||
|
-0.44
|
||||||
|
0.02
|
||||||
|
-0.22
|
||||||
|
-0.30
|
||||||
|
-0.59
|
||||||
|
0.10
|
||||||
|
-0.02
|
||||||
|
-0.27
|
||||||
|
-0.60
|
||||||
|
-0.48
|
||||||
|
-0.37
|
||||||
|
-0.53
|
||||||
|
-1.35
|
||||||
|
-1.22
|
||||||
|
-0.99
|
||||||
|
-0.34
|
||||||
|
-0.79
|
||||||
|
-0.24
|
||||||
|
0.02
|
||||||
|
0.69
|
||||||
|
0.78
|
||||||
|
0.17
|
||||||
|
-0.17
|
||||||
|
-0.29
|
||||||
|
-0.27
|
||||||
|
0.31
|
||||||
|
0.44
|
||||||
|
0.38
|
||||||
|
0.24
|
||||||
|
-0.13
|
||||||
|
-0.89
|
||||||
|
-0.76
|
||||||
|
-0.71
|
||||||
|
-0.37
|
||||||
|
-0.59
|
||||||
|
-0.63
|
||||||
|
-1.47
|
||||||
|
-0.40
|
||||||
|
-0.18
|
||||||
|
-0.37
|
||||||
|
-0.43
|
||||||
|
-0.06
|
||||||
|
0.61
|
||||||
|
1.33
|
||||||
|
1.19
|
||||||
|
1.13
|
||||||
|
0.31
|
||||||
|
0.14
|
||||||
|
0.03
|
||||||
|
0.21
|
||||||
|
0.15
|
||||||
|
-0.22
|
||||||
|
-0.02
|
||||||
|
0.03
|
||||||
|
-0.17
|
||||||
|
0.12
|
||||||
|
-0.35
|
||||||
|
-0.06
|
||||||
|
0.38
|
||||||
|
-0.45
|
||||||
|
-0.32
|
||||||
|
-0.33
|
||||||
|
-0.49
|
||||||
|
-0.14
|
||||||
|
-0.56
|
||||||
|
-0.18
|
||||||
|
0.46
|
||||||
|
1.09
|
||||||
|
1.04
|
||||||
|
0.23
|
||||||
|
-0.99
|
||||||
|
-0.59
|
||||||
|
-0.92
|
||||||
|
-0.28
|
||||||
|
0.52
|
||||||
|
1.31
|
||||||
|
1.45
|
||||||
|
0.61
|
||||||
|
-0.11
|
||||||
|
-0.18
|
||||||
|
-0.39
|
||||||
|
-0.39
|
||||||
|
-0.36
|
||||||
|
-0.50
|
||||||
|
-0.81
|
||||||
|
-1.10
|
||||||
|
-0.29
|
||||||
|
0.57
|
||||||
|
0.68
|
||||||
|
0.78
|
||||||
|
0.78
|
||||||
|
0.63
|
||||||
|
0.98
|
||||||
|
0.49
|
||||||
|
-0.42
|
||||||
|
-1.34
|
||||||
|
-1.20
|
||||||
|
-1.18
|
||||||
|
-0.65
|
||||||
|
-0.42
|
||||||
|
-0.97
|
||||||
|
-0.28
|
||||||
|
0.77
|
||||||
|
1.77
|
||||||
|
2.22
|
||||||
|
1.05
|
||||||
|
-0.67
|
||||||
|
-0.99
|
||||||
|
-1.52
|
||||||
|
-1.17
|
||||||
|
-0.22
|
||||||
|
-0.04
|
||||||
|
-0.45
|
||||||
|
-0.46
|
||||||
|
-0.75
|
||||||
|
-0.70
|
||||||
|
-1.38
|
||||||
|
-1.15
|
||||||
|
-0.01
|
||||||
|
0.97
|
||||||
|
1.10
|
||||||
|
0.68
|
||||||
|
-0.02
|
||||||
|
-0.04
|
||||||
|
0.47
|
||||||
|
0.30
|
||||||
|
-0.55
|
||||||
|
-0.51
|
||||||
|
-0.09
|
||||||
|
-0.01
|
||||||
|
0.34
|
||||||
|
0.61
|
||||||
|
0.58
|
||||||
|
0.33
|
||||||
|
0.38
|
||||||
|
0.10
|
||||||
|
0.18
|
||||||
|
-0.30
|
||||||
|
-0.06
|
||||||
|
-0.28
|
||||||
|
0.12
|
||||||
|
0.58
|
||||||
|
0.89
|
||||||
|
0.93
|
||||||
|
2.39
|
||||||
|
2.44
|
||||||
|
1.92
|
||||||
|
0.64
|
||||||
|
-0.24
|
||||||
|
0.27
|
||||||
|
-0.13
|
||||||
|
-0.16
|
||||||
|
-0.54
|
||||||
|
-0.13
|
||||||
|
-0.37
|
||||||
|
-0.78
|
||||||
|
-0.22
|
||||||
|
0.03
|
||||||
|
0.25
|
||||||
|
0.31
|
||||||
|
1.03
|
||||||
|
1.10
|
||||||
|
1.05
|
||||||
|
1.11
|
||||||
|
1.28
|
||||||
|
0.57
|
||||||
|
-0.55
|
||||||
|
-1.16
|
||||||
|
-0.99
|
||||||
|
-0.38
|
||||||
|
0.01
|
||||||
|
-0.29
|
||||||
|
0.09
|
||||||
|
0.46
|
||||||
|
0.57
|
||||||
|
0.24
|
||||||
|
0.39
|
||||||
|
0.49
|
||||||
|
0.86
|
||||||
|
0.51
|
||||||
|
0.95
|
||||||
|
1.25
|
||||||
|
1.33
|
||||||
|
-0.00
|
||||||
|
0.34
|
||||||
|
0.66
|
||||||
|
1.11
|
||||||
|
0.34
|
||||||
|
0.48
|
||||||
|
0.56
|
||||||
|
0.39
|
||||||
|
-0.17
|
||||||
|
1.04
|
||||||
|
0.77
|
||||||
|
0.12
|
||||||
|
-0.35
|
||||||
|
-0.22
|
||||||
|
0.08
|
||||||
|
-0.08
|
||||||
|
-0.18
|
||||||
|
-0.06
|
BIN
dep/wavelib/test/swt2test
Executable file
BIN
dep/wavelib/test/swt2test
Executable file
Binary file not shown.
83
dep/wavelib/test/swt2test.c
Normal file
83
dep/wavelib/test/swt2test.c
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
double generate_rnd() {
|
||||||
|
double rnd;
|
||||||
|
|
||||||
|
rnd = (double) (rand() % 100 + 1);
|
||||||
|
|
||||||
|
return rnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt2_object wt;
|
||||||
|
int i, k, J, rows, cols;
|
||||||
|
double *inp, *wavecoeffs, *oup, *cLL,*diff;
|
||||||
|
double amax;
|
||||||
|
int ir, ic, N;
|
||||||
|
rows = 64;
|
||||||
|
cols = 48;
|
||||||
|
|
||||||
|
char *name = "bior3.1";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
N = rows*cols;
|
||||||
|
inp = (double*)calloc(N, sizeof(double));
|
||||||
|
oup = (double*)calloc(N, sizeof(double));
|
||||||
|
diff = (double*)calloc(N, sizeof(double));
|
||||||
|
J = 2;
|
||||||
|
|
||||||
|
wt = wt2_init(obj, "swt", rows, cols, J);
|
||||||
|
|
||||||
|
for (i = 0; i < rows; ++i) {
|
||||||
|
for (k = 0; k < cols; ++k) {
|
||||||
|
//inp[i*cols + k] = i*cols + k;
|
||||||
|
inp[i*cols + k] = generate_rnd();
|
||||||
|
oup[i*cols + k] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wavecoeffs = swt2(wt, inp);
|
||||||
|
|
||||||
|
cLL = getWT2Coeffs(wt, wavecoeffs, J, "A", &ir, &ic);
|
||||||
|
|
||||||
|
dispWT2Coeffs(cLL, ir, ic);
|
||||||
|
|
||||||
|
iswt2(wt, wavecoeffs, oup);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
diff[i] = oup[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
amax = absmax(diff, N);
|
||||||
|
|
||||||
|
wt2_summary(wt);
|
||||||
|
|
||||||
|
printf("Abs Max %g \n", amax);
|
||||||
|
|
||||||
|
wave_free(obj);
|
||||||
|
wt2_free(wt);
|
||||||
|
free(inp);
|
||||||
|
free(wavecoeffs);
|
||||||
|
free(oup);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/swttest
Executable file
BIN
dep/wavelib/test/swttest
Executable file
Binary file not shown.
87
dep/wavelib/test/swttest.c
Normal file
87
dep/wavelib/test/swttest.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
double absmax(double *array, int N) {
|
||||||
|
double max;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
max = 0.0;
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
if (fabs(array[i]) >= max) {
|
||||||
|
max = fabs(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
wave_object obj;
|
||||||
|
wt_object wt;
|
||||||
|
double *inp, *out, *diff;
|
||||||
|
int N, i, J;
|
||||||
|
|
||||||
|
FILE *ifp;
|
||||||
|
double temp[1200];
|
||||||
|
|
||||||
|
char *name = "bior3.5";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
|
||||||
|
ifp = fopen("signal.txt", "r");
|
||||||
|
i = 0;
|
||||||
|
if (!ifp) {
|
||||||
|
printf("Cannot Open File");
|
||||||
|
exit(100);
|
||||||
|
}
|
||||||
|
while (!feof(ifp)) {
|
||||||
|
fscanf(ifp, "%lf \n", &temp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
N = 256;
|
||||||
|
fclose(ifp);
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
out = (double*)malloc(sizeof(double)* N);
|
||||||
|
diff = (double*)malloc(sizeof(double)* N);
|
||||||
|
//wmean = mean(temp, N);
|
||||||
|
|
||||||
|
for (i = 0; i < N; ++i) {
|
||||||
|
inp[i] = temp[i];
|
||||||
|
//printf("%g \n",inp[i]);
|
||||||
|
}
|
||||||
|
J = 1;
|
||||||
|
|
||||||
|
wt = wt_init(obj, "swt", N, J);// Initialize the wavelet transform object
|
||||||
|
setWTConv(wt, "direct");
|
||||||
|
|
||||||
|
|
||||||
|
swt(wt, inp);// Perform SWT
|
||||||
|
//SWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
|
||||||
|
|
||||||
|
for (i = 0; i < wt->outlength; ++i) {
|
||||||
|
printf("%g ",wt->output[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
iswt(wt, out);// Perform ISWT (if needed)
|
||||||
|
// Test Reconstruction
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < wt->siglength; ++i) {
|
||||||
|
diff[i] = out[i] - inp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value.
|
||||||
|
|
||||||
|
wt_summary(wt);// Prints the full summary.
|
||||||
|
|
||||||
|
|
||||||
|
wave_free(obj);
|
||||||
|
wt_free(wt);
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(out);
|
||||||
|
free(diff);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
dep/wavelib/test/wtreetest
Executable file
BIN
dep/wavelib/test/wtreetest
Executable file
Binary file not shown.
47
dep/wavelib/test/wtreetest.c
Normal file
47
dep/wavelib/test/wtreetest.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i, J, N, len;
|
||||||
|
int X, Y;
|
||||||
|
wave_object obj;
|
||||||
|
wtree_object wt;
|
||||||
|
double *inp, *oup;
|
||||||
|
|
||||||
|
char *name = "db3";
|
||||||
|
obj = wave_init(name);// Initialize the wavelet
|
||||||
|
N = 147;
|
||||||
|
inp = (double*)malloc(sizeof(double)* N);
|
||||||
|
for (i = 1; i < N + 1; ++i) {
|
||||||
|
inp[i - 1] = -0.25*i*i*i + 25 * i *i + 10 * i;
|
||||||
|
}
|
||||||
|
J = 3;
|
||||||
|
|
||||||
|
wt = wtree_init(obj, N, J);// Initialize the wavelet transform object
|
||||||
|
setWTREEExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
|
||||||
|
|
||||||
|
wtree(wt, inp);
|
||||||
|
wtree_summary(wt);
|
||||||
|
X = 3;
|
||||||
|
Y = 5;
|
||||||
|
len = getWTREENodelength(wt, X);
|
||||||
|
printf("\n %d", len);
|
||||||
|
printf("\n");
|
||||||
|
oup = (double*)malloc(sizeof(double)* len);
|
||||||
|
|
||||||
|
printf("Node [%d %d] Coefficients : \n",X,Y);
|
||||||
|
getWTREECoeffs(wt, X, Y, oup, len);
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
printf("%g ", oup[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
free(inp);
|
||||||
|
free(oup);
|
||||||
|
wave_free(obj);
|
||||||
|
wtree_free(wt);
|
||||||
|
return 0;
|
||||||
|
}
|
3
dep/wavelib/unitTests/CMakeLists.txt
Normal file
3
dep/wavelib/unitTests/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
add_subdirectory(wavelibBoostTests)
|
||||||
|
|
27
dep/wavelib/unitTests/wavelibBoostTests/CMakeLists.txt
Normal file
27
dep/wavelib/unitTests/wavelibBoostTests/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
set(SOURCE_FILES
|
||||||
|
tst_dwt.cpp
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(wavelibLibTests ${SOURCE_FILES} )
|
||||||
|
|
||||||
|
add_test(NAME wavelibLibTests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test COMMAND wavelibLibTests)
|
||||||
|
|
||||||
|
add_dependencies(wavelibLibTests wavelib)
|
||||||
|
target_link_libraries(wavelibLibTests wavelib)
|
||||||
|
|
||||||
|
target_include_directories(wavelibLibTests PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../header
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
install(TARGETS wavelibLibTests
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION tests
|
||||||
|
ARCHIVE DESTINATION tests
|
||||||
|
)
|
1224
dep/wavelib/unitTests/wavelibBoostTests/tst_dwt.cpp
Normal file
1224
dep/wavelib/unitTests/wavelibBoostTests/tst_dwt.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
dep/wavelib/wavelib-doc.pdf
Normal file
BIN
dep/wavelib/wavelib-doc.pdf
Normal file
Binary file not shown.
29
example/CMakeLists.txt
Normal file
29
example/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# 设置可执行文件的输出地址
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
macro(add_example name switch)
|
||||||
|
if(${switch})
|
||||||
|
# 添加可执行程序名称
|
||||||
|
add_executable(${name} ${name}.cpp)
|
||||||
|
|
||||||
|
# 设置安装后的动态库调用地址
|
||||||
|
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||||
|
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# 链接动态库
|
||||||
|
target_link_libraries(${name} PRIVATE ${GCTL_LIB})
|
||||||
|
target_link_libraries(${name} PRIVATE ${GCTL_GRAPHIC_LIB})
|
||||||
|
target_link_libraries(${name} PRIVATE gctl_mesh)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
add_example(mesh_ex1 ON)
|
||||||
|
add_example(mesh_ex2 ON)
|
||||||
|
add_example(mesh_ex3 ON)
|
||||||
|
add_example(mesh_ex4 ON)
|
||||||
|
add_example(mesh_ex5 ON)
|
||||||
|
add_example(mesh_ex6 ON)
|
||||||
|
add_example(mesh_ex7 ON)
|
||||||
|
add_example(mesh_ex8 ON)
|
||||||
|
add_example(mesh_ex9 ON)
|
||||||
|
add_example(mesh_ex10 ON)
|
57
example/mesh_ex1.cpp
Normal file
57
example/mesh_ex1.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
gctl::regular_grid rgd;
|
||||||
|
rgd.init("grid-1", "null", 4, 4, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
gctl::meshdata *data = rgd.add_data("data-1", gctl::NodeData, true, 2.5);
|
||||||
|
gctl::meshdata *data2= rgd.add_data("data-2", gctl::ElemData, false, 1.2);
|
||||||
|
gctl::meshdata *data3= rgd.add_data("data-3", gctl::NodeData, true, gctl::Scalar);
|
||||||
|
|
||||||
|
std::cout << "data name: " << data2->get_datname() << std::endl;
|
||||||
|
//gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(data2->get_name());
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) data2->get_datval_ptr();
|
||||||
|
for (int i = 0; i < data_ptr->size(); i++)
|
||||||
|
{
|
||||||
|
std::cout << data_ptr->at(i) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "data name: " << data3->get_datname() << std::endl;
|
||||||
|
gctl::array<int> *data_ptr2 = (gctl::array<int>*) rgd.get_datval(data3->get_datname());
|
||||||
|
for (int i = 0; i < data_ptr2->size(); i++)
|
||||||
|
{
|
||||||
|
std::cout << data_ptr2->at(i) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
rgd.remove_data("data-1");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
37
example/mesh_ex10.cpp
Normal file
37
example/mesh_ex10.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
gctl::regular_mesh_sph_3d rm_3ds;
|
||||||
|
rm_3ds.init("mesh-1", "null", 30.25, 30.25, 2005, 0.5, 0.5, 10, 40, 40, 50);
|
||||||
|
rm_3ds.add_data("data-1", gctl::ElemData, true, 2.5);
|
||||||
|
rm_3ds.save_gmsh("data/out/mesh_sample10", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
|
||||||
|
return 0;
|
||||||
|
}
|
65
example/mesh_ex2.cpp
Normal file
65
example/mesh_ex2.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
std::string dname = "example";
|
||||||
|
std::string dname2= "another-example";
|
||||||
|
|
||||||
|
gctl::regular_grid rgd;
|
||||||
|
rgd.init("grid-1", "null", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
rgd.add_data(dname, gctl::NodeData, true, gctl::Scalar);
|
||||||
|
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(dname);
|
||||||
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()) = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rgd.add_data(dname2, gctl::NodeData, true, gctl::Scalar);
|
||||||
|
data_ptr = (gctl::array<double>*) rgd.get_datval(dname2);
|
||||||
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()) = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable the output of data object named dname2
|
||||||
|
gctl::meshdata *data2 = rgd.get_data(dname2);
|
||||||
|
data2->set_output(false);
|
||||||
|
|
||||||
|
rgd.save_netcdf_grid("data/out/sample2-out", gctl::NodeData);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
88
example/mesh_ex3.cpp
Normal file
88
example/mesh_ex3.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string dname = "example";
|
||||||
|
std::string dname2= "another-example";
|
||||||
|
|
||||||
|
gctl::regular_grid rgd;
|
||||||
|
rgd.init("grid-1", "this is a test message.", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
rgd.add_data(dname, gctl::NodeData, true, gctl::Scalar);
|
||||||
|
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) rgd.get_datval(dname);
|
||||||
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()) = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rgd.add_data(dname2, gctl::ElemData, true, gctl::Scalar);
|
||||||
|
data_ptr = (gctl::array<double>*) rgd.get_datval(dname2);
|
||||||
|
for (int j = 0; j < rgd.get_ydim()-1; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rgd.get_xdim()-1; i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*(rgd.get_xdim()-1)) = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rgd.save_binary("data/out/sample3-out");
|
||||||
|
rgd.save_netcdf_grid("data/out/sample3-out1", dname);
|
||||||
|
rgd.save_netcdf_grid("data/out/sample3-out2", dname2);
|
||||||
|
|
||||||
|
gctl::regular_grid rgd2;
|
||||||
|
rgd2.load_binary("data/out/sample3-out");
|
||||||
|
|
||||||
|
rgd2.show_info();
|
||||||
|
|
||||||
|
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname);
|
||||||
|
for (int i = 0; i < data_ptr->size(); i++)
|
||||||
|
{
|
||||||
|
std::cout << data_ptr->at(i) << " ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
data_ptr = (gctl::array<double>*) rgd2.get_datval(dname2);
|
||||||
|
for (int i = 0; i < data_ptr->size(); i++)
|
||||||
|
{
|
||||||
|
std::cout << data_ptr->at(i) << " ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
63
example/mesh_ex4.cpp
Normal file
63
example/mesh_ex4.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string dname = "vector-data";
|
||||||
|
|
||||||
|
gctl::regular_grid rgd;
|
||||||
|
rgd.init("grid-example", "this grid can store vectors. Yeah!", 15, 10, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
rgd.add_data(dname, gctl::NodeData, true, gctl::Vector);
|
||||||
|
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) rgd.get_datval(dname);
|
||||||
|
for (int j = 0; j < rgd.get_ydim(); j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < rgd.get_xdim(); i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()).x = i;
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()).y = j;
|
||||||
|
data_ptr->at(i + j*rgd.get_xdim()).z = i+j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rgd.save_binary("data/out/sample4-out");
|
||||||
|
|
||||||
|
gctl::regular_grid rgd2;
|
||||||
|
rgd2.load_binary("data/out/sample4-out");
|
||||||
|
|
||||||
|
rgd2.show_info();
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
46
example/mesh_ex5.cpp
Normal file
46
example/mesh_ex5.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gctl::regular_grid rgd;
|
||||||
|
rgd.load_netcdf_grid("data/out/sample3-out1", gctl::ElemData, "x", "y");
|
||||||
|
|
||||||
|
rgd.show_info();
|
||||||
|
|
||||||
|
rgd.save_netcdf_grid("data/out/sample5-out", "example");
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
72
example/mesh_ex6.cpp
Normal file
72
example/mesh_ex6.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gctl::regular_mesh_2d rg_mesh;
|
||||||
|
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 0.5, 0.5, 1.0, 1.0);
|
||||||
|
|
||||||
|
int ybnum = rg_mesh.get_ybnum();
|
||||||
|
int xbnum = rg_mesh.get_xbnum();
|
||||||
|
|
||||||
|
rg_mesh.add_data("vector-data", gctl::ElemData, true, gctl::Vector);
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) rg_mesh.get_datval("vector-data");
|
||||||
|
for (int j = 0; j < ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < xbnum; i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*xbnum).x = i;
|
||||||
|
data_ptr->at(i + j*xbnum).y = j;
|
||||||
|
data_ptr->at(i + j*xbnum).z = i+j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rg_mesh.add_data("double-data", gctl::NodeData, true, gctl::Scalar);
|
||||||
|
gctl::array<double> *data_ptr2 = (gctl::array<double>*) rg_mesh.get_datval("double-data");
|
||||||
|
for (int j = 0; j < ybnum+1; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < xbnum+1; i++)
|
||||||
|
{
|
||||||
|
data_ptr2->at(i + j*(xbnum+1)) = i+j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//rg_mesh.save_gmsh("data/sample6-out", "vector-data");
|
||||||
|
//rg_mesh.save_gmsh("data/sample6-out", "double-data", Append);
|
||||||
|
|
||||||
|
rg_mesh.save_gmsh("data/out/sample6-out", gctl::ElemData, gctl::OverWrite);
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
61
example/mesh_ex7.cpp
Normal file
61
example/mesh_ex7.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gctl::regular_mesh_3d rg_mesh;
|
||||||
|
rg_mesh.init("mesh-example", "this mesh can store vectors. Yeah!", 15, 10, 10, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
int ybnum = rg_mesh.get_ybnum();
|
||||||
|
int xbnum = rg_mesh.get_xbnum();
|
||||||
|
int zbnum = rg_mesh.get_zbnum();
|
||||||
|
|
||||||
|
rg_mesh.add_data("double-data", gctl::NodeData, gctl::Packed, gctl::Scalar);
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) rg_mesh.get_datval("double-data");
|
||||||
|
for (int k = 0; k < zbnum+1; k++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < ybnum+1; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < xbnum+1; i++)
|
||||||
|
{
|
||||||
|
data_ptr->at(i + j*(xbnum+1) + k*(xbnum+1)*(ybnum+1)) = i+j+k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rg_mesh.save_gmsh("data/out/sample7-out", "double-data", gctl::OverWrite);
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
50
example/mesh_ex8.cpp
Normal file
50
example/mesh_ex8.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gctl::triangle_mesh t_mesh;
|
||||||
|
t_mesh.load_triangle("data/out/sample8", gctl::Packed);
|
||||||
|
t_mesh.add_data("example", gctl::ElemData, gctl::Packed, 1.0);
|
||||||
|
|
||||||
|
t_mesh.save_gmsh("data/out/sample8-out", "example", gctl::OverWrite, gctl::NotPacked);
|
||||||
|
t_mesh.save_binary("data/out/sample8-out");
|
||||||
|
|
||||||
|
gctl::triangle_mesh t2_mesh;
|
||||||
|
t2_mesh.load_binary("data/out/sample8-out");
|
||||||
|
t2_mesh.show_info();
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
69
example/mesh_ex9.cpp
Normal file
69
example/mesh_ex9.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "../lib/mesh.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gctl::array<double> xs(15);
|
||||||
|
for (int i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
xs[i] = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<double> ys(10);
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
ys[i] = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::linear_mesh_2d l2d_mesh;
|
||||||
|
l2d_mesh.init("mesh-example", "This is a linear mesh", 0.5, 0.5, xs, ys);
|
||||||
|
|
||||||
|
int ybnum = l2d_mesh.get_ybnum();
|
||||||
|
int xbnum = l2d_mesh.get_xbnum();
|
||||||
|
|
||||||
|
l2d_mesh.add_data("double-data", gctl::ElemData, gctl::Packed, gctl::Scalar);
|
||||||
|
gctl::array<double> *data_ptr2 = (gctl::array<double>*) l2d_mesh.get_datval("double-data");
|
||||||
|
for (int j = 0; j < ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < xbnum; i++)
|
||||||
|
{
|
||||||
|
data_ptr2->at(i + j*xbnum) = i+j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
l2d_mesh.save_gmsh("data/out/sample9-out", gctl::ElemData, gctl::OverWrite, gctl::NotPacked);
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
54
installer
Executable file
54
installer
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ $# == 0 || ${1} == "help" ]]; then
|
||||||
|
echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
|
||||||
|
echo ""
|
||||||
|
echo "School of Earth Sciences, Zhejiang University"
|
||||||
|
echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
|
||||||
|
echo ""
|
||||||
|
echo "Usage: ./config.sh [option] [Cmake options]"
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in <option>=<value>."
|
||||||
|
echo "(2) build: Build executables/libraries."
|
||||||
|
echo "(3) install: Install executables/libraries to the directory of CMAKE_INSTALL_PREFIX and sym-links them to the target address. This offers a quick and clean remove of the installed files."
|
||||||
|
echo "(4) clean: Clean build/ folder(s)."
|
||||||
|
echo "(5) uninstall: Delete the installed files and sym-links."
|
||||||
|
echo "(6) info: Print out current setups."
|
||||||
|
echo "(7) help: Show help information."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
package=gctl_mesh
|
||||||
|
address=/opt/stow
|
||||||
|
taress=/usr/local
|
||||||
|
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||||
|
|
||||||
|
if [[ $# -gt 1 ]]; then
|
||||||
|
for opt in "$@"; do
|
||||||
|
if [[ ${opt} != "configure" ]]; then
|
||||||
|
option="${option} -D${opt}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${1} == "configure" && ! -d "build/" ]]; then
|
||||||
|
mkdir build && cd build && cmake .. ${option}
|
||||||
|
elif [[ ${1} == "configure" ]]; then
|
||||||
|
cd build && rm -rf * && cmake .. ${option}
|
||||||
|
elif [[ ${1} == "build" ]]; then
|
||||||
|
cd build && make
|
||||||
|
elif [[ ${1} == "install" ]]; then
|
||||||
|
cd build && sudo make install
|
||||||
|
sudo stow --dir=${address} --target=${taress} -S ${package}
|
||||||
|
elif [[ ${1} == "clean" ]]; then
|
||||||
|
rm -rf build/
|
||||||
|
elif [[ ${1} == "uninstall" ]]; then
|
||||||
|
sudo stow --dir=${address} --target=${taress} -D ${package}
|
||||||
|
sudo rm -rf ${address}/${package}
|
||||||
|
elif [[ ${1} == "info" ]]; then
|
||||||
|
echo "package name:" ${package}
|
||||||
|
echo "stow address:" ${address}
|
||||||
|
echo "target address:" ${taress}
|
||||||
|
echo "Cmake options:" ${option}
|
||||||
|
fi
|
71
lib/CMakeLists.txt
Normal file
71
lib/CMakeLists.txt
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# 设置编译选项
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||||
|
# 设置库文件的输出地址
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||||
|
# 设定库源文件文件夹
|
||||||
|
aux_source_directory(mesh/ GCTL_MESH_SRC)
|
||||||
|
|
||||||
|
# 以下部分为库的编译
|
||||||
|
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||||
|
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||||
|
add_library(gctl_mesh SHARED ${GCTL_MESH_SRC})
|
||||||
|
# 首先添加静态库的生成命令
|
||||||
|
add_library(gctl_mesh_static STATIC ${GCTL_MESH_SRC})
|
||||||
|
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||||
|
set_target_properties(gctl_mesh_static PROPERTIES OUTPUT_NAME "gctl_mesh")
|
||||||
|
# 设置输出目标属性以同时输出动态库与静态库
|
||||||
|
set_target_properties(gctl_mesh PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
set_target_properties(gctl_mesh_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||||
|
# 设置动态库的版本号
|
||||||
|
set_target_properties(gctl_mesh PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||||
|
# 设置动态库的运行搜索地址
|
||||||
|
set_target_properties(gctl_mesh PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||||
|
set_target_properties(gctl_mesh_static PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||||
|
set_target_properties(gctl_mesh PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||||
|
set_target_properties(gctl_mesh_static PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
#连接动态库
|
||||||
|
target_link_libraries(gctl_mesh PUBLIC ${GCTL_LIB})
|
||||||
|
target_link_libraries(gctl_mesh PUBLIC ${GCTL_GRAPHIC_LIB})
|
||||||
|
target_link_libraries(gctl_mesh_static ${GCTL_LIB})
|
||||||
|
target_link_libraries(gctl_mesh_static ${GCTL_GRAPHIC_LIB})
|
||||||
|
|
||||||
|
if(GCTL_MESH_WAVELIB)
|
||||||
|
target_link_libraries(gctl_mesh PUBLIC ${WaveLib_LIB})
|
||||||
|
target_link_libraries(gctl_mesh_static ${WaveLib_LIB})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||||
|
|
||||||
|
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
|
||||||
|
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
# 库的安装命令
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS gctl_mesh DESTINATION lib)
|
||||||
|
install(TARGETS gctl_mesh_static DESTINATION lib)
|
||||||
|
else()
|
||||||
|
install(TARGETS gctl_mesh gctl_mesh_static
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib)
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
install(FILES
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
|
DESTINATION ${CONFIG_FILE_PATH})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# 头文件安装命令
|
||||||
|
file(GLOB GCTL_HEAD *.h)
|
||||||
|
file(GLOB GCTL_MESH_HEAD mesh/*.h)
|
||||||
|
|
||||||
|
install(FILES ${GCTL_HEAD} DESTINATION include/gctl)
|
||||||
|
install(FILES ${GCTL_MESH_HEAD} DESTINATION include/gctl/mesh)
|
42
lib/mesh.h
Normal file
42
lib/mesh.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MESH_H
|
||||||
|
#define _GCTL_MESH_H
|
||||||
|
|
||||||
|
#include "mesh/gctl_mesh_config.h"
|
||||||
|
#include "mesh/mesh.h"
|
||||||
|
#include "mesh/regular_grid.h"
|
||||||
|
#include "mesh/regular_mesh_2d.h"
|
||||||
|
#include "mesh/regular_mesh_3d.h"
|
||||||
|
#include "mesh/linear_mesh_2d.h"
|
||||||
|
#include "mesh/linear_mesh_3d.h"
|
||||||
|
#include "mesh/tri_mesh.h"
|
||||||
|
#include "mesh/tet_mesh.h"
|
||||||
|
#include "mesh/regular_mesh_sph_3d.h"
|
||||||
|
|
||||||
|
#endif // _GCTL_MESH_H
|
3
lib/mesh/gctl_mesh_config.h
Normal file
3
lib/mesh/gctl_mesh_config.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#define GCTL_MESH_INSTALL_PREFIX "/opt/stow/gctl_mesh"
|
||||||
|
#define GCTL_MESH_EXPRTK
|
||||||
|
#define GCTL_MESH_WAVELIB
|
295
lib/mesh/linear_mesh_2d.cpp
Normal file
295
lib/mesh/linear_mesh_2d.cpp
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "linear_mesh_2d.h"
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
||||||
|
{
|
||||||
|
if (initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
base_mesh::init(LINEAR_MESH, MESH_2D, in_name, in_info);
|
||||||
|
|
||||||
|
lm_xmin = xmin;
|
||||||
|
lm_ymin = ymin;
|
||||||
|
lm_xbnum = xsizes.size();
|
||||||
|
lm_ybnum = ysizes.size();
|
||||||
|
lm_xsizes.resize(lm_xbnum);
|
||||||
|
lm_ysizes.resize(lm_ybnum);
|
||||||
|
|
||||||
|
node_num = (lm_xbnum+1) * (lm_ybnum+1);
|
||||||
|
ele_num = lm_xbnum * lm_ybnum;
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
lm_xsizes[i] = xsizes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
lm_ysizes[i] = ysizes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.resize(node_num);
|
||||||
|
elements.resize(ele_num);
|
||||||
|
|
||||||
|
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
|
{
|
||||||
|
x_p = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (int i = 0; i < lm_xbnum+1; i++)
|
||||||
|
{
|
||||||
|
nodes[i+j*(lm_xbnum+1)].id = i+j*(lm_xbnum+1);
|
||||||
|
nodes[i+j*(lm_xbnum+1)].x = x_p;
|
||||||
|
nodes[i+j*(lm_xbnum+1)].y = y_p;
|
||||||
|
if (i < lm_xbnum) x_p += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
if (j < lm_ybnum) y_p += lm_ysizes[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < lm_ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
elements[i+j*lm_xbnum].id = i+j*lm_xbnum;
|
||||||
|
elements[i+j*lm_xbnum].vert[0] = nodes.get(i+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[1] = nodes.get(i+1+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[2] = nodes.get(i+1+(j+1)*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[3] = nodes.get(i+(j+1)*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].dl = nodes.get(i+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].ur = nodes.get(i+1+(j+1)*(lm_xbnum+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::load_binary(std::string filename)
|
||||||
|
{
|
||||||
|
if (initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is already initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile;
|
||||||
|
gctl::open_infile(infile, filename, ".2m", std::ios::in|std::ios::binary);
|
||||||
|
|
||||||
|
// 读入网格头信息
|
||||||
|
load_headinfo(infile, LINEAR_MESH, MESH_2D);
|
||||||
|
|
||||||
|
// 读入网格信息
|
||||||
|
infile.read((char*)&lm_xbnum, sizeof(int));
|
||||||
|
infile.read((char*)&lm_ybnum, sizeof(int));
|
||||||
|
infile.read((char*)&lm_xmin, sizeof(double));
|
||||||
|
infile.read((char*)&lm_ymin, sizeof(double));
|
||||||
|
|
||||||
|
lm_xsizes.resize(lm_xbnum);
|
||||||
|
lm_ysizes.resize(lm_ybnum);
|
||||||
|
node_num = (lm_xbnum+1) * (lm_ybnum+1);
|
||||||
|
ele_num = lm_xbnum * lm_ybnum;
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
infile.read((char*)lm_xsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
infile.read((char*)lm_ysizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.resize(node_num);
|
||||||
|
elements.resize(ele_num);
|
||||||
|
|
||||||
|
double x_p, y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
|
{
|
||||||
|
x_p = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (int i = 0; i < lm_xbnum+1; i++)
|
||||||
|
{
|
||||||
|
nodes[i+j*(lm_xbnum+1)].id = i+j*(lm_xbnum+1);
|
||||||
|
nodes[i+j*(lm_xbnum+1)].x = x_p;
|
||||||
|
nodes[i+j*(lm_xbnum+1)].y = y_p;
|
||||||
|
if (i < lm_xbnum) x_p += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
if (j < lm_ybnum) y_p += lm_ysizes[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < lm_ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
elements[i+j*lm_xbnum].id = i+j*lm_xbnum;
|
||||||
|
elements[i+j*lm_xbnum].vert[0] = nodes.get(i+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[1] = nodes.get(i+1+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[2] = nodes.get(i+1+(j+1)*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].vert[3] = nodes.get(i+(j+1)*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].dl = nodes.get(i+j*(lm_xbnum+1));
|
||||||
|
elements[i+j*lm_xbnum].ur = nodes.get(i+1+(j+1)*(lm_xbnum+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
// 读入模型数据单元
|
||||||
|
load_datablock(infile);
|
||||||
|
|
||||||
|
infile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::save_binary(std::string filename)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".2m", std::ios::out|std::ios::binary);
|
||||||
|
|
||||||
|
// 首先输出网格的头信息
|
||||||
|
save_headinfo(outfile);
|
||||||
|
|
||||||
|
// 输出网格信息
|
||||||
|
outfile.write((char*)&lm_xbnum, sizeof(int));
|
||||||
|
outfile.write((char*)&lm_ybnum, sizeof(int));
|
||||||
|
outfile.write((char*)&lm_xmin, sizeof(double));
|
||||||
|
outfile.write((char*)&lm_ymin, sizeof(double));
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
outfile.write((char*)lm_xsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
outfile.write((char*)lm_ysizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出的模型数据单元
|
||||||
|
save_datablock(outfile);
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::linear_mesh_2d::linear_mesh_2d() : base_mesh::base_mesh(){}
|
||||||
|
|
||||||
|
gctl::linear_mesh_2d::linear_mesh_2d(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
||||||
|
{
|
||||||
|
init(in_name, in_info, xmin, ymin, xsizes, ysizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::linear_mesh_2d::~linear_mesh_2d(){}
|
||||||
|
|
||||||
|
int gctl::linear_mesh_2d::get_xbnum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_xbnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::linear_mesh_2d::get_ybnum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_ybnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_2d::get_xmin() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_xmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_2d::get_ymin() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_ymin;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gctl::array<double> *gctl::linear_mesh_2d::get_xsizes() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lm_xsizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gctl::array<double> *gctl::linear_mesh_2d::get_ysizes() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_2d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lm_ysizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::save_gmsh(std::string filename, index_packed_e packed)
|
||||||
|
{
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh");
|
||||||
|
gctl::save2gmsh(outfile, elements, nodes, packed);
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_2d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
||||||
|
return;
|
||||||
|
}
|
79
lib/mesh/linear_mesh_2d.h
Normal file
79
lib/mesh/linear_mesh_2d.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_LINEAR_MESH_2D_H
|
||||||
|
#define _GCTL_LINEAR_MESH_2D_H
|
||||||
|
|
||||||
|
#include "mesh.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class linear_mesh_2d : public base_mesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为mesh类型的虚函数实现
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const array<double> &xsizes, const array<double> &ysizes);
|
||||||
|
|
||||||
|
void load_binary(std::string filename);
|
||||||
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为regular_mesh_2d的专有函数
|
||||||
|
*/
|
||||||
|
|
||||||
|
linear_mesh_2d();
|
||||||
|
linear_mesh_2d(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const array<double> &xsizes, const array<double> &ysizes);
|
||||||
|
virtual ~linear_mesh_2d();
|
||||||
|
|
||||||
|
int get_xbnum() const;
|
||||||
|
int get_ybnum() const;
|
||||||
|
double get_xmin() const;
|
||||||
|
double get_ymin() const;
|
||||||
|
const array<double> *get_xsizes() const;
|
||||||
|
const array<double> *get_ysizes() const;
|
||||||
|
|
||||||
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int lm_xbnum, lm_ybnum;
|
||||||
|
double lm_xmin, lm_ymin;
|
||||||
|
array<double> lm_xsizes;
|
||||||
|
array<double> lm_ysizes;
|
||||||
|
array<vertex2dc> nodes;
|
||||||
|
array<rectangle2d> elements;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_LINEAR_MESH_2D_H
|
382
lib/mesh/linear_mesh_3d.cpp
Normal file
382
lib/mesh/linear_mesh_3d.cpp
Normal file
@ -0,0 +1,382 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "linear_mesh_3d.h"
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const array<double> &xsizes, const array<double> &ysizes, const array<double> &zsizes)
|
||||||
|
{
|
||||||
|
if (initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
base_mesh::init(LINEAR_MESH, MESH_3D, in_name, in_info);
|
||||||
|
|
||||||
|
lm_xmin = xmin;
|
||||||
|
lm_ymin = ymin;
|
||||||
|
lm_zmin = zmin;
|
||||||
|
lm_xbnum = xsizes.size();
|
||||||
|
lm_ybnum = ysizes.size();
|
||||||
|
lm_zbnum = zsizes.size();
|
||||||
|
lm_xsizes.resize(lm_xbnum);
|
||||||
|
lm_ysizes.resize(lm_ybnum);
|
||||||
|
lm_zsizes.resize(lm_zbnum);
|
||||||
|
|
||||||
|
node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
||||||
|
ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
lm_xsizes[i] = xsizes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
lm_ysizes[i] = ysizes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_zbnum; i++)
|
||||||
|
{
|
||||||
|
lm_zsizes[i] = zsizes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.resize(node_num);
|
||||||
|
elements.resize(ele_num);
|
||||||
|
|
||||||
|
int tmp_index;
|
||||||
|
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
||||||
|
for (int k = 0; k < lm_zbnum+1; k++)
|
||||||
|
{
|
||||||
|
y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
|
{
|
||||||
|
x_p = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (int i = 0; i < lm_xbnum+1; i++)
|
||||||
|
{
|
||||||
|
tmp_index = i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1);
|
||||||
|
nodes[tmp_index].id = tmp_index;
|
||||||
|
nodes[tmp_index].x = x_p;
|
||||||
|
nodes[tmp_index].y = y_p;
|
||||||
|
nodes[tmp_index].z = z_p;
|
||||||
|
if (i < lm_xbnum) x_p += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
if (j < lm_ybnum) y_p += lm_ysizes[j];
|
||||||
|
}
|
||||||
|
if (k < lm_zbnum) z_p += lm_zsizes[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < lm_zbnum; k++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < lm_ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
tmp_index = i+j*lm_xbnum+k*lm_xbnum*lm_ybnum;
|
||||||
|
elements[tmp_index].id = tmp_index;
|
||||||
|
elements[tmp_index].vert[0] = nodes.get(i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[1] = nodes.get(i+1+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[2] = nodes.get(i+1+(j+1)*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[3] = nodes.get(i+(j+1)*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[4] = nodes.get(i+j*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[5] = nodes.get(i+1+j*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[6] = nodes.get(i+1+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[7] = nodes.get(i+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].dl = nodes.get(i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].ur = nodes.get(i+1+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::load_binary(std::string filename)
|
||||||
|
{
|
||||||
|
if (initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is already initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream infile;
|
||||||
|
gctl::open_infile(infile, filename, ".2m",
|
||||||
|
std::ios::in|std::ios::binary);
|
||||||
|
|
||||||
|
// 读入网格头信息
|
||||||
|
load_headinfo(infile, LINEAR_MESH, MESH_3D);
|
||||||
|
|
||||||
|
// 读入网格信息
|
||||||
|
infile.read((char*)&lm_xbnum, sizeof(int));
|
||||||
|
infile.read((char*)&lm_ybnum, sizeof(int));
|
||||||
|
infile.read((char*)&lm_zbnum, sizeof(int));
|
||||||
|
infile.read((char*)&lm_xmin, sizeof(double));
|
||||||
|
infile.read((char*)&lm_ymin, sizeof(double));
|
||||||
|
infile.read((char*)&lm_zmin, sizeof(double));
|
||||||
|
|
||||||
|
lm_xsizes.resize(lm_xbnum);
|
||||||
|
lm_ysizes.resize(lm_ybnum);
|
||||||
|
lm_zsizes.resize(lm_zbnum);
|
||||||
|
node_num = (lm_xbnum+1) * (lm_ybnum+1) * (lm_zbnum+1);
|
||||||
|
ele_num = lm_xbnum * lm_ybnum * lm_zbnum;
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
infile.read((char*)lm_xsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
infile.read((char*)lm_ysizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_zbnum; i++)
|
||||||
|
{
|
||||||
|
infile.read((char*)lm_zsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.resize(node_num);
|
||||||
|
elements.resize(ele_num);
|
||||||
|
|
||||||
|
int tmp_index;
|
||||||
|
double x_p, y_p, z_p = lm_zmin - 0.5*lm_zsizes[0];
|
||||||
|
for (int k = 0; k < lm_zbnum+1; k++)
|
||||||
|
{
|
||||||
|
y_p = lm_ymin - 0.5*lm_ysizes[0];
|
||||||
|
for (int j = 0; j < lm_ybnum+1; j++)
|
||||||
|
{
|
||||||
|
x_p = lm_xmin - 0.5*lm_xsizes[0];
|
||||||
|
for (int i = 0; i < lm_xbnum+1; i++)
|
||||||
|
{
|
||||||
|
tmp_index = i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1);
|
||||||
|
nodes[tmp_index].id = tmp_index;
|
||||||
|
nodes[tmp_index].x = x_p;
|
||||||
|
nodes[tmp_index].y = y_p;
|
||||||
|
nodes[tmp_index].z = z_p;
|
||||||
|
if (i < lm_xbnum) x_p += lm_xsizes[i];
|
||||||
|
}
|
||||||
|
if (j < lm_ybnum) y_p += lm_ysizes[j];
|
||||||
|
}
|
||||||
|
if (k < lm_zbnum) z_p += lm_zsizes[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < lm_zbnum; k++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < lm_ybnum; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
tmp_index = i+j*lm_xbnum+k*lm_xbnum*lm_ybnum;
|
||||||
|
elements[tmp_index].id = tmp_index;
|
||||||
|
elements[tmp_index].vert[0] = nodes.get(i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[1] = nodes.get(i+1+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[2] = nodes.get(i+1+(j+1)*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[3] = nodes.get(i+(j+1)*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[4] = nodes.get(i+j*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[5] = nodes.get(i+1+j*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[6] = nodes.get(i+1+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].vert[7] = nodes.get(i+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].dl = nodes.get(i+j*(lm_xbnum+1)+k*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
elements[tmp_index].ur = nodes.get(i+1+(j+1)*(lm_xbnum+1)+(k+1)*(lm_xbnum+1)*(lm_ybnum+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
// 读入模型数据单元
|
||||||
|
load_datablock(infile);
|
||||||
|
|
||||||
|
infile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::save_binary(std::string filename)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".2m",
|
||||||
|
std::ios::out|std::ios::binary);
|
||||||
|
|
||||||
|
// 首先输出网格的头信息
|
||||||
|
save_headinfo(outfile);
|
||||||
|
|
||||||
|
// 输出网格信息
|
||||||
|
outfile.write((char*)&lm_xbnum, sizeof(int));
|
||||||
|
outfile.write((char*)&lm_ybnum, sizeof(int));
|
||||||
|
outfile.write((char*)&lm_zbnum, sizeof(int));
|
||||||
|
outfile.write((char*)&lm_xmin, sizeof(double));
|
||||||
|
outfile.write((char*)&lm_ymin, sizeof(double));
|
||||||
|
outfile.write((char*)&lm_zmin, sizeof(double));
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_xbnum; i++)
|
||||||
|
{
|
||||||
|
outfile.write((char*)lm_xsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_ybnum; i++)
|
||||||
|
{
|
||||||
|
outfile.write((char*)lm_ysizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < lm_zbnum; i++)
|
||||||
|
{
|
||||||
|
outfile.write((char*)lm_zsizes.get(i), sizeof(double));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出的模型数据单元
|
||||||
|
save_datablock(outfile);
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::linear_mesh_3d::linear_mesh_3d() : base_mesh::base_mesh(){}
|
||||||
|
|
||||||
|
gctl::linear_mesh_3d::linear_mesh_3d(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
||||||
|
const gctl::array<double> &zsizes)
|
||||||
|
{
|
||||||
|
init(in_name, in_info, xmin, ymin, zmin, xsizes, ysizes, zsizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::linear_mesh_3d::~linear_mesh_3d(){}
|
||||||
|
|
||||||
|
int gctl::linear_mesh_3d::get_xbnum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_xbnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::linear_mesh_3d::get_ybnum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_ybnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::linear_mesh_3d::get_zbnum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_zbnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_xmin() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_xmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_ymin() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_ymin;
|
||||||
|
}
|
||||||
|
|
||||||
|
double gctl::linear_mesh_3d::get_zmin() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return lm_zmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gctl::array<double> *gctl::linear_mesh_3d::get_xsizes() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lm_xsizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gctl::array<double> *gctl::linear_mesh_3d::get_ysizes() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lm_ysizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gctl::array<double> *gctl::linear_mesh_3d::get_zsizes() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::linear_mesh_3d] The mesh is not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &lm_zsizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::save_gmsh(std::string filename, index_packed_e packed)
|
||||||
|
{
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh");
|
||||||
|
gctl::save2gmsh(outfile, elements, nodes, packed);
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
base_mesh::save_gmsh(filename, d_type, out_mode, packed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::linear_mesh_3d::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
base_mesh::save_gmsh(filename, datname, out_mode, packed);
|
||||||
|
return;
|
||||||
|
}
|
85
lib/mesh/linear_mesh_3d.h
Normal file
85
lib/mesh/linear_mesh_3d.h
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_LINEAR_MESH_3D_H
|
||||||
|
#define _GCTL_LINEAR_MESH_3D_H
|
||||||
|
|
||||||
|
#include "mesh.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class linear_mesh_3d : public base_mesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为mesh类型的虚函数实现
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const array<double> &xsizes, const array<double> &ysizes,
|
||||||
|
const array<double> &zsizes);
|
||||||
|
|
||||||
|
void load_binary(std::string filename);
|
||||||
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为regular_mesh_2d的专有函数
|
||||||
|
*/
|
||||||
|
|
||||||
|
linear_mesh_3d();
|
||||||
|
linear_mesh_3d(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const array<double> &xsizes, const array<double> &ysizes,
|
||||||
|
const array<double> &zsizes);
|
||||||
|
virtual ~linear_mesh_3d();
|
||||||
|
|
||||||
|
int get_xbnum() const;
|
||||||
|
int get_ybnum() const;
|
||||||
|
int get_zbnum() const;
|
||||||
|
double get_xmin() const;
|
||||||
|
double get_ymin() const;
|
||||||
|
double get_zmin() const;
|
||||||
|
const array<double> *get_xsizes() const;
|
||||||
|
const array<double> *get_ysizes() const;
|
||||||
|
const array<double> *get_zsizes() const;
|
||||||
|
|
||||||
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int lm_xbnum, lm_ybnum, lm_zbnum;
|
||||||
|
double lm_xmin, lm_ymin, lm_zmin;
|
||||||
|
array<double> lm_xsizes;
|
||||||
|
array<double> lm_ysizes;
|
||||||
|
array<double> lm_zsizes;
|
||||||
|
array<vertex3dc> nodes;
|
||||||
|
array<block> elements;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_LINEAR_MESH_3D_H
|
864
lib/mesh/mesh.cpp
Normal file
864
lib/mesh/mesh.cpp
Normal file
@ -0,0 +1,864 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "mesh.h"
|
||||||
|
|
||||||
|
gctl::base_mesh::base_mesh()
|
||||||
|
{
|
||||||
|
initialized = false;
|
||||||
|
//std::clog << "A new mesh object is created." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::base_mesh::~base_mesh()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
//std::clog << "A mesh object is destroyed." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::clear()
|
||||||
|
{
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if (!saved_data.empty())
|
||||||
|
{
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
data_ptr = *iter;
|
||||||
|
meshdata::destroy(data_ptr);
|
||||||
|
}
|
||||||
|
saved_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::base_mesh::initiated() const
|
||||||
|
{
|
||||||
|
return initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::base_mesh::saved(std::string datname) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
meshdata *data_ptr = nullptr;
|
||||||
|
// 这里我们需要使用常量迭代器
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
data_ptr = *c_iter;
|
||||||
|
if (data_ptr->get_datname() == datname)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::get_data(std::string datname) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
if (curr_data->get_datname() == datname)
|
||||||
|
{
|
||||||
|
return curr_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] No data found by the name: " + datname);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::get_all_data(array<meshdata*>& out_list) const
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int c_count = 0;
|
||||||
|
out_list.resize(saved_data.size());
|
||||||
|
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
out_list[c_count] = curr_data;
|
||||||
|
c_count++;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *gctl::base_mesh::get_datval(std::string datname) const
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(datname);
|
||||||
|
return curr_data->get_datval_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::remove_data(std::string datname)
|
||||||
|
{
|
||||||
|
if (saved_data.empty())
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] No data saved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_datname() == datname)
|
||||||
|
{
|
||||||
|
meshdata::destroy(curr_data);
|
||||||
|
iter = saved_data.erase(iter);
|
||||||
|
//std::clog << "Meshdata: " << datname << " is destroyed." << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::show_info(std::ostream &os) const
|
||||||
|
{
|
||||||
|
if (meshtype == REGULAR_MESH) os << "Mesh: Regular | ";
|
||||||
|
if (meshtype == LINEAR_MESH) os << "Mesh: Linear | ";
|
||||||
|
if (meshtype == TRI_TET_MESH) os << "Mesh: Unstructured | ";
|
||||||
|
if (meshtype == REGULAR_MESH_SPH) os << "Mesh: Regular (spherical) | ";
|
||||||
|
if (meshtype == LINEAR_MESH_SPH) os << "Mesh: Linear (spherical) | ";
|
||||||
|
if (meshtype == TRI_TET_MESH_SPH) os << "Mesh: Unstructured (spherical) | ";
|
||||||
|
if (meshtype == REGULAR_GRID) os << "Mesh: Grid | ";
|
||||||
|
|
||||||
|
if (meshdim == MESH_2D) os << "2D" << std::endl;
|
||||||
|
else if (meshdim == MESH_3D) os << "3D" << std::endl;
|
||||||
|
|
||||||
|
os << "Name: " << meshname << std::endl;
|
||||||
|
os << "Info: " << meshinfo << std::endl;
|
||||||
|
|
||||||
|
show_mesh_dimension(os);
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
std::list<meshdata*>::const_iterator c_iter;
|
||||||
|
for (c_iter = saved_data.begin(); c_iter != saved_data.end(); ++c_iter)
|
||||||
|
{
|
||||||
|
curr_data = *c_iter;
|
||||||
|
curr_data->show_info();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::rename_data(std::string oldname, std::string newname)
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(oldname);
|
||||||
|
curr_data->set_datname(newname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_type_e gctl::base_mesh::get_meshtype() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_dim_e gctl::base_mesh::get_meshdim() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshdim;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_nodenum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return node_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_elenum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ele_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gctl::base_mesh::get_datanum() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return saved_data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::base_mesh::get_meshname() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::set_meshname(std::string in_name)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_name.empty())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshname = in_name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::base_mesh::get_meshinfo() const
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::set_meshinfo(std::string in_info)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_info == "")
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] The input info. is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshinfo = in_info;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, double init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<double>* val_ptr = (array<double>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<point3dc>* val_ptr = (array<point3dc>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在一个同名 同数据类型 同赋值类型的数据 则将其数据设置为初始值
|
||||||
|
array<tensor>* val_ptr = (array<tensor>*) data_ptr->get_datval_ptr();
|
||||||
|
val_ptr->assign_all(init_val);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (in_type == ElemData || in_type == ElemData2D || in_type == ElemData3D)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata *gctl::base_mesh::add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, mesh_data_value_e val_type)
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Mesh not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshdata *data_ptr;
|
||||||
|
if(saved(in_name))
|
||||||
|
{
|
||||||
|
data_ptr = get_data(in_name);
|
||||||
|
if (data_ptr->get_valtype() != Scalar || data_ptr->get_dattype() != in_type)
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] A data object is already created with a different data or value type by the name:" + in_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val_type == Scalar && in_type == NodeData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, node_num, if_output, 0.0);
|
||||||
|
}
|
||||||
|
else if (val_type == Scalar && in_type == ElemData)
|
||||||
|
{
|
||||||
|
data_ptr = meshdata_scalar::create(in_name, in_type, ele_num, if_output, 0.0);
|
||||||
|
}
|
||||||
|
else if (val_type == Vector && in_type == NodeData)
|
||||||
|
{
|
||||||
|
point3dc init_val = {0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Vector && in_type == ElemData)
|
||||||
|
{
|
||||||
|
point3dc init_val = {0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_vector::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Tensor && in_type == NodeData)
|
||||||
|
{
|
||||||
|
tensor init_val = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, node_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
else if (val_type == Tensor && in_type == ElemData)
|
||||||
|
{
|
||||||
|
tensor init_val = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
data_ptr = meshdata_tensor::create(in_name, in_type, ele_num, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
saved_data.push_back(data_ptr);
|
||||||
|
return data_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
||||||
|
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
||||||
|
const gctl::array<double> &zsizes)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex2dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::triangle2d> &in_triangles)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex3dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::tetrahedron> &in_tets)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::show_mesh_dimension(std::ostream &os) const
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, index_packed_e packed)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
if (out_mode == OverWrite) save_gmsh(filename, packed);
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh", std::ios::out|std::ios::app);
|
||||||
|
|
||||||
|
meshdata *curr_data;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_dattype() == d_type && d_type == NodeData &&
|
||||||
|
curr_data->get_valtype() == Scalar && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
|
||||||
|
curr_data->get_valtype() == Scalar && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == NodeData &&
|
||||||
|
curr_data->get_valtype() == Vector && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == d_type && d_type == ElemData &&
|
||||||
|
curr_data->get_valtype() == Vector && curr_data->get_output())
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed)
|
||||||
|
{
|
||||||
|
meshdata *curr_data = get_data(datname);
|
||||||
|
|
||||||
|
if (!curr_data->get_output())
|
||||||
|
{
|
||||||
|
throw gctl::runtime_error("[gctl::base_mesh] Output is disabled for the data:" + datname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_mode == OverWrite) save_gmsh(filename, packed);
|
||||||
|
|
||||||
|
std::ofstream outfile;
|
||||||
|
gctl::open_outfile(outfile, filename, ".msh", std::ios::out|std::ios::app);
|
||||||
|
|
||||||
|
if (curr_data->get_valtype() == Scalar)
|
||||||
|
{
|
||||||
|
gctl::array<double> *data_ptr = (gctl::array<double>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (curr_data->get_valtype() == Vector)
|
||||||
|
{
|
||||||
|
gctl::array<gctl::point3dc> *data_ptr = (gctl::array<gctl::point3dc>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname(), *data_ptr, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (curr_data->get_valtype() == Tensor)
|
||||||
|
{
|
||||||
|
gctl::array<gctl::tensor> *data_ptr = (gctl::array<gctl::tensor>*) curr_data->get_datval_ptr();
|
||||||
|
if (curr_data->get_dattype() == NodeData)
|
||||||
|
{
|
||||||
|
array<double> v(data_ptr->size());
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][0];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txx", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txy", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txz", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyy", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyz", v, gctl::NodeData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[2][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tzz", v, gctl::NodeData, packed);
|
||||||
|
}
|
||||||
|
else if (curr_data->get_dattype() == ElemData)
|
||||||
|
{
|
||||||
|
array<double> v(data_ptr->size());
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][0];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txx", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txy", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[0][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Txz", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][1];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyy", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[1][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tyz", v, gctl::ElemData, packed);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
{
|
||||||
|
v[i] = data_ptr->at(i).val[2][2];
|
||||||
|
}
|
||||||
|
gctl::save_gmsh_data(outfile, curr_data->get_datname() + "_Tzz", v, gctl::ElemData, packed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_data_cloud(const array<point2dc> &in_posi, const array<double> &in_val,
|
||||||
|
double search_xlen, double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_data_cloud(const array<point3dc> &in_posi, const array<double> &in_val,
|
||||||
|
double search_xlen, double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_points(std::string datname, const array<point3dc> &in_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_profile(std::string datname, const point2dc &start_p, const point2dc &end_p, int size_p,
|
||||||
|
array<point2dc> &out_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::extract_profile(std::string datname, const point3dc &start_p, const point3dc &end_p, int size_p,
|
||||||
|
double dh, array<point3dc> &out_posi, array<double> &out_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, point3dc in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, tensor in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, double in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, point3dc in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::purge_data(std::string datname, tensor in_val)
|
||||||
|
{
|
||||||
|
throw runtime_error("[gctl::base_mesh] Invalid mesh type for calling this function.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下是类的私有函数,可以简单一些
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gctl::base_mesh::init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_info == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] The input info. is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
meshname = in_name;
|
||||||
|
meshinfo = in_info;
|
||||||
|
meshtype = in_type;
|
||||||
|
meshdim = in_dim;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_headinfo(std::ifstream &infile, mesh_type_e expected_type, mesh_dim_e expected_dim)
|
||||||
|
{
|
||||||
|
// 读入网格头信息
|
||||||
|
infile.read((char*)&meshtype, sizeof(int));
|
||||||
|
infile.read((char*)&meshdim, sizeof(int));
|
||||||
|
if (meshdim != expected_dim || meshtype != expected_type)
|
||||||
|
{
|
||||||
|
infile.close();
|
||||||
|
throw std::runtime_error("[gctl::base_mesh] Invalid input mesh type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int info_size;
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
meshname.resize(info_size);
|
||||||
|
infile.read((char*)meshname.c_str(), info_size);
|
||||||
|
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
meshinfo.resize(info_size);
|
||||||
|
infile.read((char*)meshinfo.c_str(), info_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::load_datablock(std::ifstream &infile)
|
||||||
|
{
|
||||||
|
meshdata *new_data;
|
||||||
|
int in_num, info_size;
|
||||||
|
mesh_data_type_e in_dattype;
|
||||||
|
mesh_data_value_e in_valtype;
|
||||||
|
std::string in_name;
|
||||||
|
|
||||||
|
infile.read((char*)&in_num, sizeof(int));
|
||||||
|
for (int i = 0; i < in_num; i++)
|
||||||
|
{
|
||||||
|
// 首先读入三个整形和数据名称
|
||||||
|
infile.read((char*)&in_dattype, sizeof(int));
|
||||||
|
infile.read((char*)&in_valtype, sizeof(int));
|
||||||
|
infile.read((char*)&info_size, sizeof(int));
|
||||||
|
|
||||||
|
in_name.resize(info_size);
|
||||||
|
infile.read((char*)in_name.c_str(), info_size);
|
||||||
|
|
||||||
|
new_data = add_data(in_name, in_dattype, true, in_valtype);
|
||||||
|
new_data->load_binary(infile);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_headinfo(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 首先输出网格的类型和维度
|
||||||
|
outfile.write((char*)&meshtype, sizeof(int));
|
||||||
|
outfile.write((char*)&meshdim, sizeof(int));
|
||||||
|
// 输出网格名称与信息
|
||||||
|
int info_size = meshname.size();
|
||||||
|
outfile.write((char*)&info_size, sizeof(int));
|
||||||
|
outfile.write((char*)meshname.c_str(), info_size);
|
||||||
|
info_size = meshinfo.size();
|
||||||
|
outfile.write((char*)&info_size, sizeof(int));
|
||||||
|
outfile.write((char*)meshinfo.c_str(), info_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::base_mesh::save_datablock(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 统计输出的模型数量
|
||||||
|
int out_num = 0;
|
||||||
|
meshdata *curr_data = nullptr;
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_output())
|
||||||
|
{
|
||||||
|
out_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outfile.write((char*)&out_num, sizeof(int));
|
||||||
|
|
||||||
|
for (iter = saved_data.begin(); iter != saved_data.end(); ++iter)
|
||||||
|
{
|
||||||
|
curr_data = *iter;
|
||||||
|
if (curr_data->get_output())
|
||||||
|
{
|
||||||
|
curr_data->save_binary(outfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
578
lib/mesh/mesh.h
Normal file
578
lib/mesh/mesh.h
Normal file
@ -0,0 +1,578 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_BASE_MESH_H
|
||||||
|
#define _GCTL_BASE_MESH_H
|
||||||
|
|
||||||
|
#include "list"
|
||||||
|
|
||||||
|
#include "meshdata.h"
|
||||||
|
#include "meshdata_scalar.h"
|
||||||
|
#include "meshdata_vector.h"
|
||||||
|
#include "meshdata_tensor.h"
|
||||||
|
|
||||||
|
#include "gctl/io.h"
|
||||||
|
#include "gctl/algorithm.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
enum mesh_type_e
|
||||||
|
{
|
||||||
|
REGULAR_MESH,
|
||||||
|
LINEAR_MESH,
|
||||||
|
TRI_TET_MESH,
|
||||||
|
REGULAR_MESH_SPH,
|
||||||
|
LINEAR_MESH_SPH,
|
||||||
|
TRI_TET_MESH_SPH,
|
||||||
|
REGULAR_GRID,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum mesh_dim_e
|
||||||
|
{
|
||||||
|
MESH_2D,
|
||||||
|
MESH_3D,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网格对象(纯虚类)。此类为所有具体网格类型的基类
|
||||||
|
*/
|
||||||
|
class base_mesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
base_mesh();
|
||||||
|
virtual ~base_mesh();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 清除所有网格数据。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查网格是否已经初始化。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool initiated() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 检查是否存在对应名称的数据。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
*/
|
||||||
|
bool saved(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回对应名称的数据对象指针。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
* @return 数据指针
|
||||||
|
*/
|
||||||
|
meshdata *get_data(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回所有数据指针。
|
||||||
|
*
|
||||||
|
* @param out_list 数据指针列表
|
||||||
|
*/
|
||||||
|
void get_all_data(array<meshdata*> &out_list) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回对应名称的数据对象的数组指针。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
* @return 数组指针(注意需要转换为对应的数组指针类型)
|
||||||
|
*/
|
||||||
|
void *get_datval(std::string datname) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 删除对应名称的数据对象。
|
||||||
|
*
|
||||||
|
* @param datname 数据名
|
||||||
|
*/
|
||||||
|
void remove_data(std::string datname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示网格与数据信息。
|
||||||
|
*
|
||||||
|
* @param os 输出流
|
||||||
|
*/
|
||||||
|
void show_info(std::ostream &os = std::clog) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 重命名数据对象。
|
||||||
|
*
|
||||||
|
* @param oldname 旧名称
|
||||||
|
* @param newname 新名称
|
||||||
|
*/
|
||||||
|
void rename_data(std::string oldname, std::string newname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格类型
|
||||||
|
*
|
||||||
|
* @return 网格类型
|
||||||
|
*/
|
||||||
|
mesh_type_e get_meshtype() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格维度类型
|
||||||
|
*
|
||||||
|
* @return 网格维度
|
||||||
|
*/
|
||||||
|
mesh_dim_e get_meshdim() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回顶点数量
|
||||||
|
*
|
||||||
|
* @return 顶点数量
|
||||||
|
*/
|
||||||
|
int get_nodenum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格单元数量
|
||||||
|
*
|
||||||
|
* @return 单元数量
|
||||||
|
*/
|
||||||
|
int get_elenum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据对象数量
|
||||||
|
*
|
||||||
|
* @return 数据对象数量
|
||||||
|
*/
|
||||||
|
int get_datanum() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格名称
|
||||||
|
*
|
||||||
|
* @return 网格名称
|
||||||
|
*/
|
||||||
|
std::string get_meshname() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置网格名称
|
||||||
|
*
|
||||||
|
* @param in_name 网格名称
|
||||||
|
*/
|
||||||
|
void set_meshname(std::string in_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回网格说明信息
|
||||||
|
*
|
||||||
|
* @return 说明信息
|
||||||
|
*/
|
||||||
|
std::string get_meshinfo() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置网格说明信息
|
||||||
|
*
|
||||||
|
* @param in_info 说明信息
|
||||||
|
*/
|
||||||
|
void set_meshinfo(std::string in_info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加标量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, double init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加适量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::point3dc init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加张量网格数据对象并赋初始值,如果对象已经存在则赋初始值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, gctl::tensor init_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 添加张量网格数据对象并初始为0值
|
||||||
|
*
|
||||||
|
* @param in_name 数据对象名称
|
||||||
|
* @param in_type 数据对象类型
|
||||||
|
* @param if_output 数据对象是否可输出
|
||||||
|
* @param init_val 初始值
|
||||||
|
* @return 新建的数据对象指针
|
||||||
|
*/
|
||||||
|
meshdata *add_data(std::string in_name, mesh_data_type_e in_type, bool if_output, mesh_data_value_e val_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类虚函数)初始化规则网格
|
||||||
|
*
|
||||||
|
* @param in_name 网格名称
|
||||||
|
* @param in_info 网格说明信息
|
||||||
|
* @param xnum 网格x轴数量
|
||||||
|
* @param ynum 网格y轴数量
|
||||||
|
* @param xmin 网格x轴最小值
|
||||||
|
* @param ymin 网格y轴最小值
|
||||||
|
* @param dx 网格x轴间隔
|
||||||
|
* @param dy 网格y轴间隔
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xbnum
|
||||||
|
* @param ybnum
|
||||||
|
* @param zbnum
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param zmin
|
||||||
|
* @param xsize
|
||||||
|
* @param ysize
|
||||||
|
* @param zsize
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, int xbnum, int ybnum, int zbnum,
|
||||||
|
double xmin, double ymin, double zmin, double xsize, double ysize, double zsize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param lon_min
|
||||||
|
* @param lat_min
|
||||||
|
* @param rad_min
|
||||||
|
* @param lon_size
|
||||||
|
* @param lat_size
|
||||||
|
* @param rad_size
|
||||||
|
* @param lon_bnum
|
||||||
|
* @param lat_bnum
|
||||||
|
* @param rad_bnum
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double lon_min, double lat_min,
|
||||||
|
double rad_min, double lon_size, double lat_size, double rad_size, int lon_bnum, int lat_bnum, int rad_bnum);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param xsizes
|
||||||
|
* @param ysizes
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
const gctl::array<double> &xsizes, const gctl::array<double> &ysizes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param xmin
|
||||||
|
* @param ymin
|
||||||
|
* @param zmin
|
||||||
|
* @param xsizes
|
||||||
|
* @param ysizes
|
||||||
|
* @param zsizes
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, double xmin, double ymin,
|
||||||
|
double zmin, const gctl::array<double> &xsizes, const gctl::array<double> &ysizes,
|
||||||
|
const gctl::array<double> &zsizes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param in_nodes
|
||||||
|
* @param in_triangles
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex2dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::triangle2d> &in_triangles);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
* @param in_nodes
|
||||||
|
* @param in_tets
|
||||||
|
*/
|
||||||
|
virtual void init(std::string in_name, std::string in_info, const gctl::array<gctl::vertex3dc> &in_nodes,
|
||||||
|
const gctl::array<gctl::tetrahedron> &in_tets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示网格的维度信息
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
virtual void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类纯虚函数)读入二进制网格文件
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
*/
|
||||||
|
virtual void load_binary(std::string filename) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类纯虚函数)写入二进制网格文件
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
*/
|
||||||
|
virtual void save_binary(std::string filename) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (基类虚函数)保存网格到Gmsh文件。
|
||||||
|
*
|
||||||
|
* @param filename 文件名
|
||||||
|
* @param packed 索引是否为紧凑(从0开始)
|
||||||
|
*/
|
||||||
|
virtual void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* @param d_type
|
||||||
|
* @param out_mode
|
||||||
|
* @param packed
|
||||||
|
*/
|
||||||
|
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param filename
|
||||||
|
* @param datname
|
||||||
|
* @param out_mode
|
||||||
|
* @param packed
|
||||||
|
*/
|
||||||
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 将输入的自由点位上的浮点数据插值为规则网络的顶点或者块体数据
|
||||||
|
*
|
||||||
|
* @param in_posi 输入的自由点位的坐标
|
||||||
|
* @param in_val 输入的自由点位的数值
|
||||||
|
* @param[in] search_xlen 插值搜索区域的x半径
|
||||||
|
* @param[in] search_ylen 插值搜索区域的y半径
|
||||||
|
* @param[in] search_deg 插值搜索区域的x半径绕x轴正方向逆时针旋转的角度(弧度)
|
||||||
|
* @param[in] datname 网格后的数据名称
|
||||||
|
* @param[in] d_type 网格后的数据类型
|
||||||
|
*/
|
||||||
|
virtual void load_data_cloud(const array<point2dc> &in_posi, const array<double> &in_val, double search_xlen,
|
||||||
|
double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type = NodeData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param in_posi
|
||||||
|
* @param in_val
|
||||||
|
* @param search_xlen
|
||||||
|
* @param search_ylen
|
||||||
|
* @param search_deg
|
||||||
|
* @param datname
|
||||||
|
* @param d_type
|
||||||
|
*/
|
||||||
|
virtual void load_data_cloud(const array<point3dc> &in_posi, const array<double> &in_val, double search_xlen,
|
||||||
|
double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type = NodeData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_points(std::string datname, const array<point3dc> &in_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param start_p
|
||||||
|
* @param end_p
|
||||||
|
* @param size_p
|
||||||
|
* @param out_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_profile(std::string datname, const point2dc &start_p, const point2dc &end_p, int size_p,
|
||||||
|
array<point2dc> &out_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param start_p
|
||||||
|
* @param end_p
|
||||||
|
* @param size_p
|
||||||
|
* @param dh
|
||||||
|
* @param out_posi
|
||||||
|
* @param out_val
|
||||||
|
*/
|
||||||
|
virtual void extract_profile(std::string datname, const point3dc &start_p, const point3dc &end_p, int size_p,
|
||||||
|
double dh, array<point3dc> &out_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, double in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, point3dc in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param p_type
|
||||||
|
* @param v_type
|
||||||
|
* @param para_str
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void edit_data(std::string datname, physical_type_e p_type, value_operator_e v_type, std::string para_str, tensor in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, double in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, point3dc in_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param datname
|
||||||
|
* @param in_val
|
||||||
|
*/
|
||||||
|
virtual void purge_data(std::string datname, tensor in_val);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mesh_type_e meshtype;
|
||||||
|
mesh_dim_e meshdim;
|
||||||
|
std::string meshname;
|
||||||
|
std::string meshinfo;
|
||||||
|
|
||||||
|
int node_num, ele_num;
|
||||||
|
bool initialized;
|
||||||
|
|
||||||
|
std::list<meshdata*> saved_data;
|
||||||
|
std::list<meshdata*>::iterator iter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为类的私有函数 只能被类的公共函数调用
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 初始化网格
|
||||||
|
*
|
||||||
|
* @param in_type
|
||||||
|
* @param in_dim
|
||||||
|
* @param in_name
|
||||||
|
* @param in_info
|
||||||
|
*/
|
||||||
|
void init(mesh_type_e in_type, mesh_dim_e in_dim, std::string in_name, std::string in_info);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读入二进制网格头信息
|
||||||
|
*
|
||||||
|
* @param infile 输入流
|
||||||
|
* @param expected_type 预期获取的网格类型
|
||||||
|
* @param expected_dim 预期获得的网格维度类型
|
||||||
|
*/
|
||||||
|
void load_headinfo(std::ifstream &infile, mesh_type_e expected_type, mesh_dim_e expected_dim);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读入二进制数据块
|
||||||
|
*
|
||||||
|
* @param infile 输入流
|
||||||
|
*/
|
||||||
|
void load_datablock(std::ifstream &infile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 写入二进制网格头信息
|
||||||
|
*
|
||||||
|
* @param outfile 输出流
|
||||||
|
*/
|
||||||
|
void save_headinfo(std::ofstream &outfile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 写入二进制数据块
|
||||||
|
*
|
||||||
|
* @param outfile 输出流
|
||||||
|
*/
|
||||||
|
void save_datablock(std::ofstream &outfile);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_BASE_MESH_H
|
94
lib/mesh/meshdata.cpp
Normal file
94
lib/mesh/meshdata.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "meshdata.h"
|
||||||
|
|
||||||
|
gctl::meshdata::meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
datname = in_name;
|
||||||
|
dattype = in_type;
|
||||||
|
output_ok = if_output;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata::~meshdata(){}
|
||||||
|
|
||||||
|
void gctl::meshdata::set_datname(std::string in_name)
|
||||||
|
{
|
||||||
|
if (in_name == "")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata] The input name is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
datname = in_name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string gctl::meshdata::get_datname()
|
||||||
|
{
|
||||||
|
return datname;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_data_type_e gctl::meshdata::get_dattype()
|
||||||
|
{
|
||||||
|
return dattype;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::mesh_data_value_e gctl::meshdata::get_valtype()
|
||||||
|
{
|
||||||
|
return valtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::set_output(bool if_output)
|
||||||
|
{
|
||||||
|
output_ok = if_output;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gctl::meshdata::get_output()
|
||||||
|
{
|
||||||
|
return output_ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata::show_info(std::ostream &os)
|
||||||
|
{
|
||||||
|
os << "Data: " << datname << " | ";
|
||||||
|
if (dattype == NodeData) os << "Type: Node data | ";
|
||||||
|
if (dattype == ElemData) os << "Type: Element data | ";
|
||||||
|
if (dattype == ElemData2D) os << "Type: 2D element data | ";
|
||||||
|
if (dattype == ElemData3D) os << "Type: 3D element data | ";
|
||||||
|
if (valtype == Scalar) os << "Value: Scalar | ";
|
||||||
|
if (valtype == Vector) os << "Value: Vector | ";
|
||||||
|
if (valtype == Tensor) os << "Value: Tensor | ";
|
||||||
|
if (output_ok) os << "Output: Yes" << std::endl;
|
||||||
|
else os<< "Output: No" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
158
lib/mesh/meshdata.h
Normal file
158
lib/mesh/meshdata.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MESHDATA_H
|
||||||
|
#define _GCTL_MESHDATA_H
|
||||||
|
|
||||||
|
#include "gctl_mesh_config.h"
|
||||||
|
#include "gctl/core.h"
|
||||||
|
#include "gctl/geometry.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief 网格数据的数值类型
|
||||||
|
*/
|
||||||
|
enum mesh_data_value_e
|
||||||
|
{
|
||||||
|
Scalar, ///< 标量数据
|
||||||
|
Vector, ///< 矢量数据
|
||||||
|
Tensor, ///< 张量数据
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 网格文件中的数据对象(纯虚类)。此类为具体类型的数据对象的基类
|
||||||
|
*/
|
||||||
|
class meshdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::string datname; // 数据的名称
|
||||||
|
mesh_data_type_e dattype; // 数据的赋值属性 顶点或是元素(设置后不可更改)
|
||||||
|
mesh_data_value_e valtype; // 数据的类型(设置后不可更改)
|
||||||
|
bool output_ok; // 是否可输出数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 构造函数
|
||||||
|
meshdata(std::string in_name, mesh_data_type_e in_type, bool if_output);
|
||||||
|
|
||||||
|
// 析构函数
|
||||||
|
virtual ~meshdata();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置数据名称
|
||||||
|
*
|
||||||
|
* @param[in] in_name 名称字符串
|
||||||
|
*/
|
||||||
|
void set_datname(std::string in_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据的名称
|
||||||
|
*
|
||||||
|
* @return 名称字符串
|
||||||
|
*/
|
||||||
|
std::string get_datname();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据的赋值类型
|
||||||
|
*
|
||||||
|
* @return 数据赋值类型的枚举
|
||||||
|
*/
|
||||||
|
mesh_data_type_e get_dattype();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据值的类型
|
||||||
|
*
|
||||||
|
* @return 数据值类型的枚举
|
||||||
|
*/
|
||||||
|
mesh_data_value_e get_valtype();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置数据对象输出状态的设置情况
|
||||||
|
*
|
||||||
|
* @param[in] if_output 是否可输出此对象
|
||||||
|
*/
|
||||||
|
void set_output(bool if_output);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据对象输出状态的设置情况
|
||||||
|
*
|
||||||
|
* @return 是否可输出此对象
|
||||||
|
*/
|
||||||
|
bool get_output();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示数据对象的头信息
|
||||||
|
*/
|
||||||
|
void show_info(std::ostream &os = std::clog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示数据统计参数
|
||||||
|
*/
|
||||||
|
virtual void show_stats(std::ostream &os = std::clog) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 返回数据块的指针 所有子类的数据块均为gctl::array类型,这是一个通用的接口。
|
||||||
|
*
|
||||||
|
* @note 注意因为具体的返回类型未知 因此需在调用后按实际数据类型转换指针
|
||||||
|
*
|
||||||
|
* @return 数据块的指针
|
||||||
|
*/
|
||||||
|
virtual void *get_datval_ptr() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 载入二进制文件
|
||||||
|
*
|
||||||
|
* @warning 不要直接调用此函数,应该在网格类型的相应函数中调用
|
||||||
|
*
|
||||||
|
* @param infile 输入文件的流(以二进制方式打开)
|
||||||
|
*/
|
||||||
|
virtual void load_binary(std::ifstream &infile) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 保存二进制文件
|
||||||
|
*
|
||||||
|
* @warning 不要直接调用此函数,应该在网格类型的相应函数中调用
|
||||||
|
*
|
||||||
|
* @param outfile 输出的文件流(以二进制方式打开)
|
||||||
|
*/
|
||||||
|
virtual void save_binary(std::ofstream &outfile) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 销毁指针的对象 可销毁此基类或子类指针指向的对象
|
||||||
|
*
|
||||||
|
* @param obj_ptr 网格数据指针
|
||||||
|
*/
|
||||||
|
static void destroy(meshdata *obj_ptr)
|
||||||
|
{
|
||||||
|
delete obj_ptr;
|
||||||
|
obj_ptr = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_MESHDATA_H
|
112
lib/mesh/meshdata_scalar.cpp
Normal file
112
lib/mesh/meshdata_scalar.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "meshdata_scalar.h"
|
||||||
|
|
||||||
|
gctl::meshdata_scalar::meshdata_scalar(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, double init_val) : meshdata::meshdata(in_name, in_type, if_output)
|
||||||
|
{
|
||||||
|
if (d_size <= 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata_scalar] Invalid data size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
nan_val = GCTL_BDL_MAX;
|
||||||
|
valtype = Scalar;
|
||||||
|
datval.resize(d_size, init_val);
|
||||||
|
|
||||||
|
//std::clog << "A new meshdata_scalar object is created." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata_scalar::~meshdata_scalar()
|
||||||
|
{
|
||||||
|
datval.clear();
|
||||||
|
|
||||||
|
//std::clog << "A meshdata_scalar object is destroyed." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<double> &gctl::meshdata_scalar::get_datval()
|
||||||
|
{
|
||||||
|
return datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_scalar::set_nan(double nan)
|
||||||
|
{
|
||||||
|
nan_val = nan;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_scalar::show_stats(std::ostream &os)
|
||||||
|
{
|
||||||
|
int vn = 0;
|
||||||
|
for (size_t i = 0; i < datval.size(); i++)
|
||||||
|
{
|
||||||
|
if (fabs(datval[i] - nan_val) > 1e-10) vn++;
|
||||||
|
}
|
||||||
|
|
||||||
|
array<double> tmp(vn);
|
||||||
|
vn = 0;
|
||||||
|
for (size_t i = 0; i < datval.size(); i++)
|
||||||
|
{
|
||||||
|
if (fabs(datval[i] - nan_val) > 1e-10)
|
||||||
|
{
|
||||||
|
tmp[vn] = datval[i];
|
||||||
|
vn++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "Mean = " << mean(tmp) << ", STD = " << std(tmp) << ", RMS = " << rms(tmp) << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *gctl::meshdata_scalar::get_datval_ptr()
|
||||||
|
{
|
||||||
|
return &datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_scalar::load_binary(std::ifstream &infile)
|
||||||
|
{
|
||||||
|
infile.read((char*) &nan_val, sizeof(double));
|
||||||
|
infile.read((char*) datval.get(), sizeof(double)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_scalar::save_binary(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 我们首先输出数据类型,赋值类型与数据长度 这三个值都是整形变量
|
||||||
|
// 我们在读入二进制文件时会在函数外先读入这三个值以新建数据对象
|
||||||
|
outfile.write((char*)&dattype, sizeof(int));
|
||||||
|
outfile.write((char*)&valtype, sizeof(int));
|
||||||
|
// 输出数据对象的名称
|
||||||
|
int name_size = datname.size();
|
||||||
|
outfile.write((char*)&name_size, sizeof(int));
|
||||||
|
outfile.write((char*)datname.c_str(), name_size);
|
||||||
|
// 输出数据
|
||||||
|
outfile.write((char*) &nan_val, sizeof(double));
|
||||||
|
outfile.write((char*) datval.get(), sizeof(double)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
62
lib/mesh/meshdata_scalar.h
Normal file
62
lib/mesh/meshdata_scalar.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MESHDATA_SCALAR_H
|
||||||
|
#define _GCTL_MESHDATA_SCALAR_H
|
||||||
|
|
||||||
|
#include "meshdata.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class meshdata_scalar : public meshdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
double nan_val;
|
||||||
|
array<double> datval;
|
||||||
|
|
||||||
|
meshdata_scalar(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, double init_val);
|
||||||
|
virtual ~meshdata_scalar();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static meshdata_scalar *create(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, double init_val)
|
||||||
|
{
|
||||||
|
return new meshdata_scalar(in_name, in_type, d_size, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<double> &get_datval();
|
||||||
|
|
||||||
|
void set_nan(double nan);
|
||||||
|
void show_stats(std::ostream &os = std::clog);
|
||||||
|
void *get_datval_ptr();
|
||||||
|
void load_binary(std::ifstream &infile);
|
||||||
|
void save_binary(std::ofstream &outfile);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_MESHDATA_SCALAR_H
|
120
lib/mesh/meshdata_tensor.cpp
Normal file
120
lib/mesh/meshdata_tensor.cpp
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "meshdata_tensor.h"
|
||||||
|
|
||||||
|
gctl::meshdata_tensor::meshdata_tensor(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, gctl::tensor init_val) : meshdata::meshdata(in_name, in_type, if_output)
|
||||||
|
{
|
||||||
|
if (d_size <= 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata_tensor] Invalid data size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
valtype = Tensor;
|
||||||
|
datval.resize(d_size, init_val);
|
||||||
|
|
||||||
|
//std::clog << "A new meshdata_tensor object is created." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata_tensor::~meshdata_tensor()
|
||||||
|
{
|
||||||
|
datval.clear();
|
||||||
|
|
||||||
|
//std::clog << "A meshdata_tensor object is destroyed." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<gctl::tensor> &gctl::meshdata_tensor::get_datval()
|
||||||
|
{
|
||||||
|
return datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_tensor::show_stats(std::ostream &os)
|
||||||
|
{
|
||||||
|
double m[9], s[9], r[9];
|
||||||
|
array<double> t(datval.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
for (size_t n = 0; n < datval.size(); n++)
|
||||||
|
{
|
||||||
|
t[n] = datval[n].at(i, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
m[j + i*3] = mean(t);
|
||||||
|
s[j + i*3] = std(t);
|
||||||
|
r[j + i*3] = rms(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "Mean = (" << m[0];
|
||||||
|
for (size_t i = 1; i < 9; i++)
|
||||||
|
{
|
||||||
|
os << "," << m[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
os << ")\nSTD = (" << s[0];
|
||||||
|
for (size_t i = 1; i < 9; i++)
|
||||||
|
{
|
||||||
|
os << "," << s[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
os << ")\nRMS = (" << r[0];
|
||||||
|
for (size_t i = 1; i < 9; i++)
|
||||||
|
{
|
||||||
|
os << "," << r[i];
|
||||||
|
}
|
||||||
|
os << ")" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *gctl::meshdata_tensor::get_datval_ptr()
|
||||||
|
{
|
||||||
|
return &datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_tensor::load_binary(std::ifstream &infile)
|
||||||
|
{
|
||||||
|
infile.read((char*) datval.get(), sizeof(gctl::tensor)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_tensor::save_binary(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 我们首先输出数据类型,赋值类型与数据长度 这三个值都是整形变量
|
||||||
|
// 我们在读入二进制文件时会在函数外先读入这三个值以新建数据对象
|
||||||
|
outfile.write((char*)&dattype, sizeof(int));
|
||||||
|
outfile.write((char*)&valtype, sizeof(int));
|
||||||
|
// 输出数据对象的名称
|
||||||
|
int name_size = datname.size();
|
||||||
|
outfile.write((char*)&name_size, sizeof(int));
|
||||||
|
outfile.write((char*)datname.c_str(), name_size);
|
||||||
|
// 输出数据
|
||||||
|
outfile.write((char*) datval.get(), sizeof(gctl::tensor)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
59
lib/mesh/meshdata_tensor.h
Normal file
59
lib/mesh/meshdata_tensor.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MESHDATA_TENSOR_H
|
||||||
|
#define _GCTL_MESHDATA_TENSOR_H
|
||||||
|
|
||||||
|
#include "meshdata.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class meshdata_tensor : public meshdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
array<tensor> datval;
|
||||||
|
|
||||||
|
meshdata_tensor(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, tensor init_val);
|
||||||
|
virtual ~meshdata_tensor();
|
||||||
|
public:
|
||||||
|
static meshdata_tensor *create(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, tensor init_val)
|
||||||
|
{
|
||||||
|
return new meshdata_tensor(in_name, in_type, d_size, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<tensor> &get_datval();
|
||||||
|
|
||||||
|
void show_stats(std::ostream &os = std::clog);
|
||||||
|
void *get_datval_ptr();
|
||||||
|
void load_binary(std::ifstream &infile);
|
||||||
|
void save_binary(std::ofstream &outfile);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_MESHDATA_TENSOR_H
|
109
lib/mesh/meshdata_vector.cpp
Normal file
109
lib/mesh/meshdata_vector.cpp
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#include "meshdata_vector.h"
|
||||||
|
|
||||||
|
gctl::meshdata_vector::meshdata_vector(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, gctl::point3dc init_val) : meshdata::meshdata(in_name, in_type, if_output)
|
||||||
|
{
|
||||||
|
if (d_size <= 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("[gctl::meshdata_vector] Invalid data size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
valtype = Vector;
|
||||||
|
datval.resize(d_size, init_val);
|
||||||
|
|
||||||
|
//std::clog << "A new meshdata_vector object is created." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::meshdata_vector::~meshdata_vector()
|
||||||
|
{
|
||||||
|
datval.clear();
|
||||||
|
|
||||||
|
//std::clog << "A meshdata_vector object is destroyed." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gctl::array<gctl::point3dc> &gctl::meshdata_vector::get_datval()
|
||||||
|
{
|
||||||
|
return datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_vector::show_stats(std::ostream &os)
|
||||||
|
{
|
||||||
|
double m[3], s[3], r[3];
|
||||||
|
array<double> t(datval.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < datval.size(); i++)
|
||||||
|
{
|
||||||
|
t[i] = datval[i].x;
|
||||||
|
}
|
||||||
|
m[0] = mean(t); s[0] = std(t); r[0] = rms(t);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < datval.size(); i++)
|
||||||
|
{
|
||||||
|
t[i] = datval[i].y;
|
||||||
|
}
|
||||||
|
m[1] = mean(t); s[1] = std(t); r[1] = rms(t);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < datval.size(); i++)
|
||||||
|
{
|
||||||
|
t[i] = datval[i].z;
|
||||||
|
}
|
||||||
|
m[2] = mean(t); s[2] = std(t); r[2] = rms(t);
|
||||||
|
|
||||||
|
os << "Mean = (" << m[0] << "," << m[1] << "," << m[2] << ")"
|
||||||
|
<< "\nSTD = (" << s[0] << "," << s[1] << "," << s[2] << ")"
|
||||||
|
<< "\nRMS = (" << r[0] << "," << r[1] << "," << r[2] << ")"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *gctl::meshdata_vector::get_datval_ptr()
|
||||||
|
{
|
||||||
|
return &datval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_vector::load_binary(std::ifstream &infile)
|
||||||
|
{
|
||||||
|
infile.read((char*) datval.get(), sizeof(gctl::point3dc)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gctl::meshdata_vector::save_binary(std::ofstream &outfile)
|
||||||
|
{
|
||||||
|
// 我们首先输出数据类型,赋值类型与数据长度 这三个值都是整形变量
|
||||||
|
// 我们在读入二进制文件时会在函数外先读入这三个值以新建数据对象
|
||||||
|
outfile.write((char*)&dattype, sizeof(int));
|
||||||
|
outfile.write((char*)&valtype, sizeof(int));
|
||||||
|
// 输出数据对象的名称
|
||||||
|
int name_size = datname.size();
|
||||||
|
outfile.write((char*)&name_size, sizeof(int));
|
||||||
|
outfile.write((char*)datname.c_str(), name_size);
|
||||||
|
// 输出数据
|
||||||
|
outfile.write((char*) datval.get(), sizeof(gctl::point3dc)*datval.size());
|
||||||
|
return;
|
||||||
|
}
|
59
lib/mesh/meshdata_vector.h
Normal file
59
lib/mesh/meshdata_vector.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_MESHDATA_VECTOR_H
|
||||||
|
#define _GCTL_MESHDATA_VECTOR_H
|
||||||
|
|
||||||
|
#include "meshdata.h"
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
class meshdata_vector : public meshdata
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
array<point3dc> datval;
|
||||||
|
|
||||||
|
meshdata_vector(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, gctl::point3dc init_val);
|
||||||
|
virtual ~meshdata_vector();
|
||||||
|
public:
|
||||||
|
static meshdata_vector *create(std::string in_name, mesh_data_type_e in_type,
|
||||||
|
int d_size, bool if_output, gctl::point3dc init_val)
|
||||||
|
{
|
||||||
|
return new meshdata_vector(in_name, in_type, d_size, if_output, init_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<point3dc> &get_datval();
|
||||||
|
|
||||||
|
void show_stats(std::ostream &os = std::clog);
|
||||||
|
void *get_datval_ptr();
|
||||||
|
void load_binary(std::ifstream &infile);
|
||||||
|
void save_binary(std::ofstream &outfile);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_MESHDATA_VECTOR_H
|
1289
lib/mesh/regular_grid.cpp
Normal file
1289
lib/mesh/regular_grid.cpp
Normal file
File diff suppressed because it is too large
Load Diff
137
lib/mesh/regular_grid.h
Normal file
137
lib/mesh/regular_grid.h
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/********************************************************
|
||||||
|
* ██████╗ ██████╗████████╗██╗
|
||||||
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||||
|
* ██║ ███╗██║ ██║ ██║
|
||||||
|
* ██║ ██║██║ ██║ ██║
|
||||||
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||||
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||||
|
* Geophysical Computational Tools & Library (GCTL)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||||
|
*
|
||||||
|
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation, either version 2
|
||||||
|
* of the License, or (at your option) any later version. You should have
|
||||||
|
* received a copy of the GNU Lesser General Public License along with this
|
||||||
|
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||||
|
* the GCTL, please consider the option to obtain a commercial license for a
|
||||||
|
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||||
|
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||||
|
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||||
|
* to include some description of your company and the realm of its activities.
|
||||||
|
* Also add information on how to contact you by electronic and paper mail.
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
#ifndef _GCTL_REGULAR_GRID_H
|
||||||
|
#define _GCTL_REGULAR_GRID_H
|
||||||
|
|
||||||
|
#include "gctl/graphic.h"
|
||||||
|
#include "mesh.h"
|
||||||
|
|
||||||
|
#ifdef GCTL_MESH_EXPRTK
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
#endif // GCTL_MESH_EXPRTK
|
||||||
|
|
||||||
|
namespace gctl
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief 规则网格对象
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class regular_grid : public base_mesh
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为mesh类型的虚函数实现
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy);
|
||||||
|
|
||||||
|
void show_mesh_dimension(std::ostream &os) const;
|
||||||
|
|
||||||
|
void load_binary(std::string filename);
|
||||||
|
void save_binary(std::string filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为regular_grid的专有函数
|
||||||
|
*/
|
||||||
|
|
||||||
|
regular_grid();
|
||||||
|
regular_grid(std::string in_name, std::string in_info, int xnum, int ynum,
|
||||||
|
double xmin, double ymin, double dx, double dy);
|
||||||
|
virtual ~regular_grid();
|
||||||
|
|
||||||
|
void clear_regular_grid();
|
||||||
|
int view(std::string datname);
|
||||||
|
void plot(std::string datname);
|
||||||
|
|
||||||
|
int get_xdim() const;
|
||||||
|
int get_ydim() const;
|
||||||
|
double get_xmin() const;
|
||||||
|
double get_ymin() const;
|
||||||
|
double get_dx() const;
|
||||||
|
double get_dy() const;
|
||||||
|
|
||||||
|
#ifdef GCTL_NETCDF
|
||||||
|
|
||||||
|
void load_netcdf_grid(std::string filename, mesh_data_type_e d_type,
|
||||||
|
std::string xname = "x", std::string yname = "y", std::string zname = "null");
|
||||||
|
void save_netcdf_grid(std::string filename, mesh_data_type_e d_type);
|
||||||
|
void save_netcdf_grid(std::string filename, std::string datname);
|
||||||
|
|
||||||
|
#endif // GCTL_NETCDF
|
||||||
|
|
||||||
|
void load_surfer_grid(std::string filename, std::string datname, mesh_data_type_e d_type, surfer_file_type_e grid_type = Surfer7Grid);
|
||||||
|
void save_surfer_grid(std::string filename, std::string datname, surfer_file_type_e grid_type = Surfer7Grid);
|
||||||
|
|
||||||
|
void save_gmsh(std::string filename, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, mesh_data_type_e d_type, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
void save_gmsh(std::string filename, std::string datname, output_type_e out_mode, index_packed_e packed = Packed);
|
||||||
|
|
||||||
|
void save_text(std::string filename, const array<std::string> &datname);
|
||||||
|
|
||||||
|
void load_data_cloud(const array<point2dc> &in_posi, const array<double> &in_val, double search_xlen,
|
||||||
|
double search_ylen, double search_deg, std::string datname, mesh_data_type_e d_type = NodeData);
|
||||||
|
|
||||||
|
void extract_points(std::string datname, const array<point2dc> &in_posi, array<double> &out_val);
|
||||||
|
void extract_profile(std::string datname, const point2dc &start_p, const point2dc &end_p, int size_p,
|
||||||
|
array<point2dc> &out_posi, array<double> &out_val);
|
||||||
|
|
||||||
|
void gradient(std::string datname, std::string gradname, gradient_type_e d_type, int order = 1);
|
||||||
|
void sum(std::string newname, std::string datname, std::string datname2);
|
||||||
|
void diff(std::string newname, std::string datname, std::string datname2);
|
||||||
|
void boolean(std::string newname, std::string datname, std::string maskname, bool reverse = false);
|
||||||
|
|
||||||
|
#ifdef GCTL_MESH_EXPRTK
|
||||||
|
void function(std::string expression_str, std::string newname, std::string x_str = "x", std::string y_str = "y", std::string f_str = "f");
|
||||||
|
void calculator(std::string expression_str, const array<std::string> &var_list, const array<std::string> &data_list);
|
||||||
|
#endif // GCTL_MESH_EXPRTK
|
||||||
|
|
||||||
|
#ifdef GCTL_MESH_WAVELIB
|
||||||
|
void wavelet(std::string datname, std::string wavename, int order, bool summary = true);
|
||||||
|
#endif // GCTL_MESH_WAVELIB
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int rg_xnum, rg_ynum;
|
||||||
|
double rg_xmin, rg_ymin;
|
||||||
|
double rg_dx, rg_dy;
|
||||||
|
|
||||||
|
#ifdef GCTL_GRAPHIC_MATHGL
|
||||||
|
mathgl_dens plt;
|
||||||
|
#endif // GCTL_GRAPHIC_MATHGL
|
||||||
|
|
||||||
|
#ifdef GCTL_GRAPHIC_GMT
|
||||||
|
gmt_JX_single pic;
|
||||||
|
#endif // GCTL_GRAPHIC_GMT
|
||||||
|
|
||||||
|
array<vertex2dc> nodes;
|
||||||
|
array<rectangle2d> elements;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_GCTL_REGULAR_GRID_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user