2015-09-01 23:01:38 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** gmio benchmarks
|
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
|
|
|
** contact@fougue.pro
|
|
|
|
**
|
|
|
|
** This software provides performance benchmarks for the gmio library
|
|
|
|
** (https://github.com/fougue/gmio)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <OSD_Path.hxx>
|
|
|
|
#include <RWStl.hxx>
|
|
|
|
#include <StlMesh_Mesh.hxx>
|
2015-09-23 21:30:17 +08:00
|
|
|
#include <Standard_Version.hxx>
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
#include <gmio_core/error.h>
|
|
|
|
#include <gmio_stl/stl_io.h>
|
2015-12-04 17:32:11 +08:00
|
|
|
#include <gmio_stl/stl_io_options.h>
|
2015-09-01 23:01:38 +08:00
|
|
|
#include <gmio_support/stl_occ.h>
|
|
|
|
|
2015-09-01 23:30:49 +08:00
|
|
|
#include "../commons/benchmark_tools.h"
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2015-09-23 21:30:17 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace BmkOcc {
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
Handle_StlMesh_Mesh stlMesh;
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void RWStl_ReadFile(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
stlMesh = RWStl::ReadFile(OSD_Path(static_cast<const char*>(filepath)));
|
2015-09-01 23:01:38 +08:00
|
|
|
if (stlMesh.IsNull())
|
|
|
|
printf("RWStl::ReadFile(): null mesh\n");
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void RWStl_WriteAscii(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
if (!RWStl::WriteAscii(stlMesh, OSD_Path(static_cast<const char*>(filepath))))
|
2015-09-01 23:01:38 +08:00
|
|
|
printf("RWStl::WriteAscii() failure\n");
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void RWStl_WriteBinary(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
if (!RWStl::WriteBinary(stlMesh, OSD_Path(static_cast<const char*>(filepath))))
|
2015-09-01 23:01:38 +08:00
|
|
|
printf("RWStl::WriteBinary() failure\n");
|
|
|
|
}
|
|
|
|
|
2015-09-23 21:30:17 +08:00
|
|
|
} // namespace BmkOcc
|
2015-09-01 23:01:38 +08:00
|
|
|
|
2015-09-23 21:30:17 +08:00
|
|
|
namespace BmkGmio {
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
Handle_StlMesh_Mesh stlMesh;
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void stl_read(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
|
|
|
stlMesh = new StlMesh_Mesh;
|
2016-02-01 23:53:45 +08:00
|
|
|
const int error = gmio_stl_read_file(
|
|
|
|
static_cast<const char*>(filepath),
|
2016-02-19 01:20:23 +08:00
|
|
|
gmio_stl_occmesh_creator(stlMesh),
|
2016-02-01 23:53:45 +08:00
|
|
|
NULL);
|
2015-09-01 23:01:38 +08:00
|
|
|
if (error != GMIO_ERROR_OK)
|
|
|
|
printf("gmio error: 0x%X\n", error);
|
|
|
|
}
|
|
|
|
|
2015-12-04 17:32:11 +08:00
|
|
|
static void stl_write(const char* filepath, gmio_stl_format format)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-02-01 23:53:45 +08:00
|
|
|
gmio_stl_write_options options = {};
|
|
|
|
options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
|
|
|
options.stla_float32_prec = 7;
|
2016-01-13 00:37:45 +08:00
|
|
|
const int error =
|
2016-02-01 23:53:45 +08:00
|
|
|
gmio_stl_write_file(
|
|
|
|
format,
|
|
|
|
static_cast<const char*>(filepath),
|
2016-02-19 01:20:23 +08:00
|
|
|
gmio_stl_occmesh(stlMesh),
|
2016-02-01 23:53:45 +08:00
|
|
|
&options);
|
2015-09-01 23:01:38 +08:00
|
|
|
if (error != GMIO_ERROR_OK)
|
|
|
|
printf("gmio error: 0x%X\n", error);
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void stla_write(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_ASCII);
|
2015-09-01 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void stlb_write_le(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_LE);
|
2015-09-01 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 00:37:45 +08:00
|
|
|
static void stlb_write_be(const void* filepath)
|
2015-09-01 23:01:38 +08:00
|
|
|
{
|
2016-01-13 00:37:45 +08:00
|
|
|
stl_write(static_cast<const char*>(filepath), GMIO_STL_FORMAT_BINARY_BE);
|
2015-09-01 23:01:38 +08:00
|
|
|
}
|
|
|
|
|
2015-09-23 21:30:17 +08:00
|
|
|
} // namespace BmkGmio
|
2015-09-01 23:01:38 +08:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc > 1) {
|
2015-09-23 21:30:17 +08:00
|
|
|
const char* filepath = argv[1];
|
|
|
|
std::cout << std::endl << "Input file: " << filepath << std::endl;
|
|
|
|
|
|
|
|
/* Declare benchmarks */
|
2015-12-04 17:32:11 +08:00
|
|
|
const benchmark_cmp_arg cmp_args[] = {
|
2015-09-23 21:30:17 +08:00
|
|
|
{ "read",
|
|
|
|
BmkGmio::stl_read, filepath,
|
|
|
|
BmkOcc::RWStl_ReadFile, filepath },
|
|
|
|
{ "write(ascii)",
|
|
|
|
BmkGmio::stla_write, "__bmk_occ_gmio.stla",
|
|
|
|
BmkOcc::RWStl_WriteAscii, "__bmk_occ.stla" },
|
|
|
|
{ "write(binary/le)",
|
|
|
|
BmkGmio::stlb_write_le, "__bmk_occ_gmio.stlb_le",
|
|
|
|
BmkOcc::RWStl_WriteBinary, "__bmk_occ.stlb_le" },
|
|
|
|
{ "write(binary/be)",
|
|
|
|
BmkGmio::stlb_write_be, "__bmk_occ_gmio.stlb_be",
|
|
|
|
NULL, NULL },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Execute benchmarks */
|
2015-12-04 17:32:11 +08:00
|
|
|
std::vector<benchmark_cmp_result> cmp_res_vec;
|
2016-01-13 19:29:44 +08:00
|
|
|
cmp_res_vec.resize(GMIO_ARRAY_SIZE(cmp_args) - 1);
|
2016-01-29 19:47:01 +08:00
|
|
|
benchmark_cmp_batch(5, cmp_args, &cmp_res_vec[0], NULL, NULL);
|
2015-09-23 21:30:17 +08:00
|
|
|
|
|
|
|
/* Print results */
|
2015-12-04 17:32:11 +08:00
|
|
|
const benchmark_cmp_result_array res_array = {
|
2015-09-23 21:30:17 +08:00
|
|
|
&cmp_res_vec.at(0), cmp_res_vec.size() };
|
2015-12-04 17:32:11 +08:00
|
|
|
const benchmark_cmp_result_header header = {
|
2015-09-23 21:30:17 +08:00
|
|
|
"gmio", "OpenCascade v"OCC_VERSION_COMPLETE };
|
|
|
|
benchmark_print_results(
|
|
|
|
BENCHMARK_PRINT_FORMAT_MARKDOWN, header, res_array);
|
2015-09-01 23:01:38 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|