Initial checkin of Timer class.

This commit is contained in:
David Williams 2013-08-07 23:07:26 +02:00
parent a308102585
commit 9ad4c3fcf7
7 changed files with 182 additions and 0 deletions

View File

@ -68,6 +68,9 @@ void createSphereInVolume(SimpleVolume<uint8_t>& 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);

View File

@ -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
)

View File

@ -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<typename VolumeType, typename IsQuadNeeded>
void CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::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<typename VolumeType, typename IsQuadNeeded>

View File

@ -21,6 +21,8 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Timer.h"
namespace PolyVox
{
template<typename VolumeType, typename IsQuadNeeded>
@ -38,6 +40,7 @@ namespace PolyVox
template<typename VolumeType, typename IsQuadNeeded>
void CubicSurfaceExtractorWithNormals<VolumeType, IsQuadNeeded>::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() << ")";
}
}

View File

@ -21,6 +21,8 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxCore/Impl/Timer.h"
namespace PolyVox
{
template<typename VolumeType, typename Controller>
@ -42,6 +44,7 @@ namespace PolyVox
template<typename VolumeType, typename Controller>
void MarchingCubesSurfaceExtractor<VolumeType, Controller>::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<typename VolumeType, typename Controller>

View File

@ -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 <iostream>
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<float>(elapsedTimeInMilliSeconds()) / 1000.0f;
}
uint32_t Timer::elapsedTimeInMilliSeconds(void)
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return static_cast<uint32_t>(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
}

View File

@ -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 <cstdint>
#ifdef _MSC_VER // Don't worry about the exact version, as long as this is defied.
#include <Windows.h>
#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__