bench_occ: refactor source code
This commit is contained in:
parent
58fdac010b
commit
342c382393
@ -1,17 +1,14 @@
|
||||
include(../../qmake.build/config.pri)
|
||||
include(_local_config.pri)
|
||||
include(occ.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
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
|
||||
|
||||
INCLUDEPATH += ../../src
|
||||
LIBS += -L../../bin -lfougstl$$TARGET_SUFFIX
|
||||
LIBS *= -lTKSTL -lTKernel -lTKMath
|
||||
QMAKE_RPATHDIR *= $$CASCADE_LIB_PATH
|
||||
|
@ -1,90 +1,38 @@
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QTime>
|
||||
|
||||
#include <QtCore/QtDebug>
|
||||
extern "C" {
|
||||
#include "../commons/bench_tools.h"
|
||||
}
|
||||
|
||||
#include <OSD_Path.hxx>
|
||||
#include <RWStl.hxx>
|
||||
#include <StlMesh_Mesh.hxx>
|
||||
#include <StlAPI_Reader.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
|
||||
#include "streams/qt4_stream.h"
|
||||
#include "libstl/stlb.h"
|
||||
|
||||
namespace internal {
|
||||
|
||||
class OccStlMeshBuilder : public foug::stl::bin::AbstractGeometryBuilder
|
||||
static void occ_RWStl_ReadBinary(const char* filepath)
|
||||
{
|
||||
public:
|
||||
void beginTriangles(foug::UInt32 count)
|
||||
{
|
||||
Q_UNUSED(count);
|
||||
m_stlMesh = new StlMesh_Mesh;
|
||||
m_stlMesh->AddDomain();
|
||||
}
|
||||
/*Handle_StlMesh_Mesh stlMesh = */RWStl::ReadBinary(OSD_Path(filepath));
|
||||
}
|
||||
|
||||
void nextTriangle(const foug::stl::Triangle& triangle, foug::UInt16 attributeByteCount)
|
||||
{
|
||||
Q_UNUSED(attributeByteCount);
|
||||
const int uId = m_stlMesh->AddOnlyNewVertex(triangle.v1.x, triangle.v1.y, triangle.v1.z);
|
||||
const int vId = m_stlMesh->AddOnlyNewVertex(triangle.v2.x, triangle.v2.y, triangle.v2.z);
|
||||
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
|
||||
static void occ_StlAPI_Reader(const char* filepath)
|
||||
{
|
||||
StlAPI_Reader reader;
|
||||
TopoDS_Shape shape;
|
||||
reader.Read(shape, filepath);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
QStringList filePaths;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
filePaths.append(argv[i]);
|
||||
if (argc > 1)
|
||||
benchmark(&occ_RWStl_ReadBinary, "RWStl::ReadBinary()", argc - 1, argv + 1);
|
||||
|
||||
const int benchCount = 1;
|
||||
QTime time;
|
||||
time.start();
|
||||
|
||||
qDebug() << sizeof(foug::stl::Triangle);
|
||||
|
||||
for (int i = 0; i < benchCount; ++i) {
|
||||
foreach (const QString& filePath, filePaths) {
|
||||
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.);
|
||||
// startTick = std::clock();
|
||||
// std::cout << "Read with StlAPI_Reader::Read() ..." << std::endl;
|
||||
// for (int iarg = 1; iarg < argc; ++iarg) {
|
||||
// StlAPI_Reader reader;
|
||||
// TopoDS_Shape shape;
|
||||
// reader.Read(shape, argv[iarg]);
|
||||
// }
|
||||
// std::cout << " StlAPI_Reader::Read() read time: " << elapsed_secs(startTick) << "s" << std::endl;
|
||||
|
||||
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 {
|
||||
INCLUDEPATH += $$CASCADE_ROOT/include/oce
|
||||
CASCADE_INC_PATH = $$CASCADE_ROOT/include/oce
|
||||
!isEmpty(OCE_VERSION) {
|
||||
LIBS += -L$$CASCADE_ROOT/lib/$$OCE_VERSION
|
||||
CASCADE_LIB_PATH += -$CASCADE_ROOT/lib/$$OCE_VERSION
|
||||
}
|
||||
}
|
||||
else {
|
||||
INCLUDEPATH += $$CASCADE_ROOT/inc
|
||||
CASCADE_INC_PATH = $$CASCADE_ROOT/inc
|
||||
}
|
||||
INCLUDEPATH += $$CASCADE_INC_PATH
|
||||
|
||||
linux-*:DEFINES *= HAVE_CONFIG_H \
|
||||
HAVE_FSTREAM \
|
||||
@ -17,13 +25,22 @@ win32-*:DEFINES *= WNT
|
||||
linux-*:DEFINES *= LIN LININTEL OCC_CONVERT_SIGNALS
|
||||
*-64:DEFINES *= _OCC64
|
||||
|
||||
linux-*:LIBS += -L$$CASCADE_ROOT/lib
|
||||
win32-*:LIBS += -L$$CASCADE_ROOT/win32/lib
|
||||
linux-*:CASCADE_LIB_PATH += $$CASCADE_ROOT/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
|
||||
# TKSTEP209 due to the name of library mixing characters and digits.
|
||||
# Or maybe nmake is the problem ?
|
||||
# Note : you have to rename TKSTEP209 to TKSTEP_tzn in $CASROOT/win32/lib
|
||||
# There is a weird bug with qmake on windows : it fails to correctly link with TKSTEP209 due to the
|
||||
# name of library mixing characters and digits.
|
||||
# Or maybe nmake is the problem ?
|
||||
# Note : you have to rename TKSTEP209 to TKSTEP_tzn in $$CASCADE_ROOT/win32/lib
|
||||
win32-msvc* {
|
||||
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