bench_occ: refactor source code
This commit is contained in:
parent
58fdac010b
commit
342c382393
@ -1,17 +1,14 @@
|
|||||||
include(../../qmake.build/config.pri)
|
include(../../qmake.build/config.pri)
|
||||||
include(_local_config.pri)
|
|
||||||
include(occ.pri)
|
include(occ.pri)
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = bench_occ$$TARGET_SUFFIX
|
TARGET = bench_occ$$TARGET_SUFFIX
|
||||||
|
|
||||||
QT *= core
|
HEADERS += ../commons/bench_tools.h
|
||||||
|
|
||||||
HEADERS +=
|
SOURCES += \
|
||||||
|
../commons/bench_tools.c \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
SOURCES += main.cpp
|
LIBS *= -lTKSTL -lTKernel -lTKMath
|
||||||
|
QMAKE_RPATHDIR *= $$CASCADE_LIB_PATH
|
||||||
LIBS *= -lTKSTL -lTKernel
|
|
||||||
|
|
||||||
INCLUDEPATH += ../../src
|
|
||||||
LIBS += -L../../bin -lfougstl$$TARGET_SUFFIX
|
|
||||||
|
@ -1,90 +1,38 @@
|
|||||||
#include <QtCore/QCoreApplication>
|
extern "C" {
|
||||||
#include <QtCore/QFile>
|
#include "../commons/bench_tools.h"
|
||||||
#include <QtCore/QScopedPointer>
|
}
|
||||||
#include <QtCore/QStringList>
|
|
||||||
#include <QtCore/QTime>
|
|
||||||
|
|
||||||
#include <QtCore/QtDebug>
|
|
||||||
|
|
||||||
#include <OSD_Path.hxx>
|
#include <OSD_Path.hxx>
|
||||||
#include <RWStl.hxx>
|
#include <RWStl.hxx>
|
||||||
#include <StlMesh_Mesh.hxx>
|
#include <StlMesh_Mesh.hxx>
|
||||||
|
#include <StlAPI_Reader.hxx>
|
||||||
|
#include <TopoDS_Shape.hxx>
|
||||||
|
|
||||||
#include "streams/qt4_stream.h"
|
static void occ_RWStl_ReadBinary(const char* filepath)
|
||||||
#include "libstl/stlb.h"
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
class OccStlMeshBuilder : public foug::stl::bin::AbstractGeometryBuilder
|
|
||||||
{
|
{
|
||||||
public:
|
/*Handle_StlMesh_Mesh stlMesh = */RWStl::ReadBinary(OSD_Path(filepath));
|
||||||
void beginTriangles(foug::UInt32 count)
|
}
|
||||||
{
|
|
||||||
Q_UNUSED(count);
|
|
||||||
m_stlMesh = new StlMesh_Mesh;
|
|
||||||
m_stlMesh->AddDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
void nextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
static void occ_StlAPI_Reader(const char* filepath)
|
||||||
{
|
{
|
||||||
Q_UNUSED(attributeByteCount);
|
StlAPI_Reader reader;
|
||||||
const int uId = m_stlMesh->AddOnlyNewVertex(triangle.v1.x, triangle.v1.y, triangle.v1.z);
|
TopoDS_Shape shape;
|
||||||
const int vId = m_stlMesh->AddOnlyNewVertex(triangle.v2.x, triangle.v2.y, triangle.v2.z);
|
reader.Read(shape, filepath);
|
||||||
const int wId = m_stlMesh->AddOnlyNewVertex(triangle.v3.x, triangle.v3.y, triangle.v3.z);
|
}
|
||||||
const foug::stl::Coords& n = triangle.normal;
|
|
||||||
m_stlMesh->AddTriangle(uId, vId, wId, n.x, n.y, n.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle_StlMesh_Mesh stlMesh() const
|
|
||||||
{
|
|
||||||
return m_stlMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Handle_StlMesh_Mesh m_stlMesh;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QStringList filePaths;
|
if (argc > 1)
|
||||||
for (int i = 1; i < argc; ++i)
|
benchmark(&occ_RWStl_ReadBinary, "RWStl::ReadBinary()", argc - 1, argv + 1);
|
||||||
filePaths.append(argv[i]);
|
|
||||||
|
|
||||||
const int benchCount = 1;
|
// startTick = std::clock();
|
||||||
QTime time;
|
// std::cout << "Read with StlAPI_Reader::Read() ..." << std::endl;
|
||||||
time.start();
|
// for (int iarg = 1; iarg < argc; ++iarg) {
|
||||||
|
// StlAPI_Reader reader;
|
||||||
qDebug() << sizeof(foug::stl::Triangle);
|
// TopoDS_Shape shape;
|
||||||
|
// reader.Read(shape, argv[iarg]);
|
||||||
for (int i = 0; i < benchCount; ++i) {
|
// }
|
||||||
foreach (const QString& filePath, filePaths) {
|
// std::cout << " StlAPI_Reader::Read() read time: " << elapsed_secs(startTick) << "s" << std::endl;
|
||||||
Handle_StlMesh_Mesh stlMesh = RWStl::ReadBinary(OSD_Path(filePath.toAscii().constData()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << QString("OCC read time : %1sec").arg(time.elapsed() / 1000.);
|
|
||||||
|
|
||||||
|
|
||||||
time.restart();
|
|
||||||
|
|
||||||
internal::OccStlMeshBuilder occStlMeshBuilder;
|
|
||||||
foug::stl::bin::Io io;
|
|
||||||
io.setAutoDeleteStream(false);
|
|
||||||
for (int i = 0; i < benchCount; ++i) {
|
|
||||||
foreach (const QString& filePath, filePaths) {
|
|
||||||
QFile file(filePath);
|
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
|
||||||
foug::Qt4Stream stream(&file);
|
|
||||||
io.setStream(&stream);
|
|
||||||
io.read(&occStlMeshBuilder);
|
|
||||||
Handle_StlMesh_Mesh stlMesh = occStlMeshBuilder.stlMesh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << QString("FougSTL read time : %1sec").arg(time.elapsed() / 1000.);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
|
# Return the input path re-written using the system-dependent separator
|
||||||
|
defineReplace(sysPath) {
|
||||||
|
win*:result = $$replace(1, /, \\)
|
||||||
|
else:result = $$1
|
||||||
|
return($$result)
|
||||||
|
}
|
||||||
|
|
||||||
use_oce {
|
use_oce {
|
||||||
INCLUDEPATH += $$CASCADE_ROOT/include/oce
|
CASCADE_INC_PATH = $$CASCADE_ROOT/include/oce
|
||||||
!isEmpty(OCE_VERSION) {
|
!isEmpty(OCE_VERSION) {
|
||||||
LIBS += -L$$CASCADE_ROOT/lib/$$OCE_VERSION
|
CASCADE_LIB_PATH += -$CASCADE_ROOT/lib/$$OCE_VERSION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
INCLUDEPATH += $$CASCADE_ROOT/inc
|
CASCADE_INC_PATH = $$CASCADE_ROOT/inc
|
||||||
}
|
}
|
||||||
|
INCLUDEPATH += $$CASCADE_INC_PATH
|
||||||
|
|
||||||
linux-*:DEFINES *= HAVE_CONFIG_H \
|
linux-*:DEFINES *= HAVE_CONFIG_H \
|
||||||
HAVE_FSTREAM \
|
HAVE_FSTREAM \
|
||||||
@ -17,13 +25,22 @@ win32-*:DEFINES *= WNT
|
|||||||
linux-*:DEFINES *= LIN LININTEL OCC_CONVERT_SIGNALS
|
linux-*:DEFINES *= LIN LININTEL OCC_CONVERT_SIGNALS
|
||||||
*-64:DEFINES *= _OCC64
|
*-64:DEFINES *= _OCC64
|
||||||
|
|
||||||
linux-*:LIBS += -L$$CASCADE_ROOT/lib
|
linux-*:CASCADE_LIB_PATH += $$CASCADE_ROOT/lib
|
||||||
win32-*:LIBS += -L$$CASCADE_ROOT/win32/lib
|
CONFIG(debug, debug|release) {
|
||||||
|
win32-msvc2005:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc8/libd
|
||||||
|
win32-msvc2008:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc9/lib
|
||||||
|
win32-msvc2010:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc10/libd
|
||||||
|
} else {
|
||||||
|
win32-msvc2005:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc8/lib
|
||||||
|
win32-msvc2008:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc9/lib
|
||||||
|
win32-msvc2010:CASCADE_LIB_PATH += $$CASCADE_ROOT/win32/vc10/lib
|
||||||
|
}
|
||||||
|
LIBS += $$sysPath($$join(CASCADE_LIB_PATH, " -L", -L))
|
||||||
|
|
||||||
# There is a weird bug with qmake on windows : it fails to correctly link with
|
# There is a weird bug with qmake on windows : it fails to correctly link with TKSTEP209 due to the
|
||||||
# TKSTEP209 due to the name of library mixing characters and digits.
|
# name of library mixing characters and digits.
|
||||||
# Or maybe nmake is the problem ?
|
# Or maybe nmake is the problem ?
|
||||||
# Note : you have to rename TKSTEP209 to TKSTEP_tzn in $CASROOT/win32/lib
|
# Note : you have to rename TKSTEP209 to TKSTEP_tzn in $$CASCADE_ROOT/win32/lib
|
||||||
win32-msvc* {
|
win32-msvc* {
|
||||||
OCC_TKSTEP = TKSTEP_tzn
|
OCC_TKSTEP = TKSTEP_tzn
|
||||||
}
|
}
|
||||||
|
24
tests/commons/bench_tools.c
Normal file
24
tests/commons/bench_tools.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "bench_tools.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
float elapsed_secs(clock_t start_tick)
|
||||||
|
{
|
||||||
|
return (float)((clock() - start_tick) / (float)CLOCKS_PER_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void benchmark(void (*func)(const char*), const char* title, int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (func == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const clock_t start_tick = clock();
|
||||||
|
|
||||||
|
fprintf(stdout, "Bench %s ...\n", title);
|
||||||
|
int iarg;
|
||||||
|
for (iarg = 0; iarg < argc; ++iarg) {
|
||||||
|
fprintf(stdout, " Read file %s ...\n", argv[iarg]);
|
||||||
|
(*func)(argv[iarg]);
|
||||||
|
}
|
||||||
|
fprintf(stdout, "\n %s exec time: %.2fs\n", title, elapsed_secs(start_tick));
|
||||||
|
}
|
10
tests/commons/bench_tools.h
Normal file
10
tests/commons/bench_tools.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef BENCH_TOOLS_H
|
||||||
|
#define BENCH_TOOLS_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
float elapsed_secs(clock_t start_tick);
|
||||||
|
|
||||||
|
void benchmark(void (*func)(const char*), const char* title, int argc, char** argv);
|
||||||
|
|
||||||
|
#endif /* BENCH_TOOLS_H */
|
Loading…
Reference in New Issue
Block a user