diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 64097731..b8164e31 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -68,6 +68,9 @@ void createSphereInVolume(SimpleVolume& volData, float fRadius) int main(int argc, char *argv[]) { + // Show logs + setTraceStream(&(std::cout)); + //Create and show the Qt OpenGL window QApplication app(argc, argv); OpenGLWidget openGLWidget(0); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index bb28c01e..5521f1dc 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -112,6 +112,7 @@ SET(IMPL_SRC_FILES source/Impl/MarchingCubesTables.cpp source/Impl/RandomUnitVectors.cpp source/Impl/RandomVectors.cpp + source/Impl/Timer.cpp source/Impl/Utility.cpp ) @@ -127,6 +128,7 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/RandomVectors.h include/PolyVoxCore/Impl/SubArray.h include/PolyVoxCore/Impl/SubArray.inl + include/PolyVoxCore/Impl/Timer.h include/PolyVoxCore/Impl/TypeDef.h include/PolyVoxCore/Impl/Utility.h ) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 96692bdb..79f8792a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/Timer.h" + namespace PolyVox { // We try to avoid duplicate vertices by checking whether a vertex has already been added at a given position. @@ -48,6 +50,7 @@ namespace PolyVox template void CubicSurfaceExtractor::execute() { + Timer timer; m_meshCurrent->clear(); uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2; @@ -195,6 +198,10 @@ namespace PolyVox lodRecord.beginIndex = 0; lodRecord.endIndex = m_meshCurrent->getNoOfIndices(); m_meshCurrent->m_vecLodRecords.push_back(lodRecord); + + logTrace() << "Cubic surface extraction took " << timer.elapsedTimeInMilliSeconds() + << "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels() + << "x" << m_regSizeInVoxels.getDepthInVoxels() << ")"; } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index 3956858c..df347b32 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/Timer.h" + namespace PolyVox { template @@ -38,6 +40,7 @@ namespace PolyVox template void CubicSurfaceExtractorWithNormals::execute() { + Timer timer; m_meshCurrent->clear(); for(int32_t z = m_regSizeInVoxels.getLowerZ(); z < m_regSizeInVoxels.getUpperZ(); z++) @@ -126,5 +129,9 @@ namespace PolyVox lodRecord.beginIndex = 0; lodRecord.endIndex = m_meshCurrent->getNoOfIndices(); m_meshCurrent->m_vecLodRecords.push_back(lodRecord); + + logTrace() << "Cubic surface extraction took " << timer.elapsedTimeInMilliSeconds() + << "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels() + << "x" << m_regSizeInVoxels.getDepthInVoxels() << ")"; } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 22e1373d..be43387c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/Impl/Timer.h" + namespace PolyVox { template @@ -42,6 +44,7 @@ namespace PolyVox template void MarchingCubesSurfaceExtractor::execute() { + Timer timer; m_meshCurrent->clear(); const uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 1; @@ -126,6 +129,10 @@ namespace PolyVox lodRecord.beginIndex = 0; lodRecord.endIndex = m_meshCurrent->getNoOfIndices(); m_meshCurrent->m_vecLodRecords.push_back(lodRecord); + + logTrace() << "Marching cubes surface extraction took " << timer.elapsedTimeInMilliSeconds() + << "ms (Region size = " << m_regSizeInVoxels.getWidthInVoxels() << "x" << m_regSizeInVoxels.getHeightInVoxels() + << "x" << m_regSizeInVoxels.getDepthInVoxels() << ")"; } template diff --git a/library/PolyVoxCore/source/Impl/Timer.cpp b/library/PolyVoxCore/source/Impl/Timer.cpp new file mode 100644 index 00000000..d8039348 --- /dev/null +++ b/library/PolyVoxCore/source/Impl/Timer.cpp @@ -0,0 +1,92 @@ +/******************************************************************************* +Copyright (c) 2005-20013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "PolyVoxCore/Impl/Timer.h" + +#include "PolyVoxCore/Impl/ErrorHandling.h" + +#include + +namespace PolyVox +{ +#if defined(_MSC_VER) + Timer::Timer(bool bAutoStart) + :m_fPCFreq(0.0) + ,m_iStartTime(0) + { + if(bAutoStart) + { + start(); + } + } + + void Timer::start(void) + { + LARGE_INTEGER li; + if(!QueryPerformanceFrequency(&li)) + { + logWarning() << "QueryPerformanceFrequency failed!"; + m_fPCFreq = 1.0f; + } + + m_fPCFreq = double(li.QuadPart)/1000.0; + + QueryPerformanceCounter(&li); + m_iStartTime = li.QuadPart; + } + + float Timer::elapsedTimeInSeconds(void) + { + return static_cast(elapsedTimeInMilliSeconds()) / 1000.0f; + } + + uint32_t Timer::elapsedTimeInMilliSeconds(void) + { + LARGE_INTEGER li; + QueryPerformanceCounter(&li); + return static_cast(double(li.QuadPart-m_iStartTime)/m_fPCFreq); + } +#else //_MSC_VER + Timer::Timer(bool bAutoStart) + { + if(bAutoStart) + { + start(); + } + } + + void Timer::start(void) + { + } + + float Timer::elapsedTimeInSeconds(void) + { + return 0.0f + } + + uint32_t Timer::elapsedTimeInMilliSeconds(void) + { + return 0; + } +#endif //_MSC_VER +} diff --git a/library/polyvoxcore/include/PolyVoxCore/Impl/Timer.h b/library/polyvoxcore/include/PolyVoxCore/Impl/Timer.h new file mode 100644 index 00000000..6ce9c328 --- /dev/null +++ b/library/polyvoxcore/include/PolyVoxCore/Impl/Timer.h @@ -0,0 +1,64 @@ +/******************************************************************************* +Copyright (c) 2005-20013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_Timer_H__ +#define __PolyVox_Timer_H__ + +#include + +#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied. +#include +#endif //_MSC_VER + +namespace PolyVox +{ +#if defined(_MSC_VER) + class Timer + { + public: + Timer(bool bAutoStart = true); + + void start(void); + + float elapsedTimeInSeconds(void); + uint32_t elapsedTimeInMilliSeconds(void); + + private: + double m_fPCFreq; + __int64 m_iStartTime; + }; +#else //_MSC_VER + class Timer + { + public: + Timer(bool bAutoStart = true); + + void start(void); + + float elapsedTimeInSeconds(void); + uint32_t elapsedTimeInMilliSeconds(void); + }; +#endif //_MSC_VER +} + +#endif //__PolyVox_Timer_H__ \ No newline at end of file