109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
/********************************************************
|
|
* ██████╗ ██████╗████████╗██╗
|
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
|
* ██║ ███╗██║ ██║ ██║
|
|
* ██║ ██║██║ ██║ ██║
|
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
|
* 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;
|
|
} |