Commit 7fe39bd8 authored by David Geistert's avatar David Geistert

[CHANGE] add debug code to simultaneously measure the time of the raw marching...

[CHANGE] add debug code to simultaneously measure the time of the raw marching cubes algorithm and the span space optimization
parent 301b0a92
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <map> #include <map>
#include <sys/time.h>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include "boost/tuple/tuple_comparison.hpp" #include "boost/tuple/tuple_comparison.hpp"
...@@ -343,6 +344,10 @@ template<typename T> boost::shared_ptr<WTriangleMesh> WMarchingCubesAlgorithm::g ...@@ -343,6 +344,10 @@ template<typename T> boost::shared_ptr<WTriangleMesh> WMarchingCubesAlgorithm::g
boost::shared_ptr< WSpanSpaceBase > spanSpace, boost::shared_ptr< WSpanSpaceBase > spanSpace,
boost::shared_ptr< WProgressCombiner > mainProgress ) boost::shared_ptr< WProgressCombiner > mainProgress )
{ {
timeval timer1, timer2;
long millis;
double activeCells = 0, allCells;
WAssert( vals, "No value set provided." ); WAssert( vals, "No value set provided." );
m_idToVertices.clear(); m_idToVertices.clear();
...@@ -358,45 +363,47 @@ template<typename T> boost::shared_ptr<WTriangleMesh> WMarchingCubesAlgorithm::g ...@@ -358,45 +363,47 @@ template<typename T> boost::shared_ptr<WTriangleMesh> WMarchingCubesAlgorithm::g
// unsigned int nX = m_nCellsX + 1; // unsigned int nX = m_nCellsX + 1;
// unsigned int nY = m_nCellsY + 1; // unsigned int nY = m_nCellsY + 1;
// unsigned int nPointsInSlice = nX * nY; // unsigned int nPointsInSlice = nX * nY;
boost::shared_ptr< WProgress > progress; boost::shared_ptr< WProgress > progress;
progress = boost::shared_ptr< WProgress >( new WProgress( "Marching Cubes" ) );
mainProgress->addSubProgress( progress );
// Generate isosurface. // calculate normal marching cubes algorithm
if( spanSpace ) gettimeofday( &timer1, NULL );
for( unsigned int z = 0; z < m_nCellsZ; z++ )
{ {
// Span Space optimized ++*progress;
progress = boost::shared_ptr< WProgress >( new WProgress( "Marching Cubes" ) ); for( unsigned int y = 0; y < m_nCellsY; y++ )
mainProgress->addSubProgress( progress );
boost::shared_ptr< WSpanSpace< T > > sstyped = boost::dynamic_pointer_cast< WSpanSpace< T > >( spanSpace );
boost::shared_ptr< WSpanSpaceBase::cellids_t > cells = spanSpace->findCells( isoValue );
for( typename WSpanSpaceBase::cellids_t::const_iterator i = cells->begin(); i < cells->end(); ++i )
{ {
calculateMarchingCube( ( *i )->m_x, ( *i )->m_y, ( *i )->m_z, vals ); for( unsigned int x = 0; x < m_nCellsX; x++ )
}
}
else
{
progress = boost::shared_ptr< WProgress >( new WProgress( "Marching Cubes", m_nCellsZ ) );
mainProgress->addSubProgress( progress );
for( unsigned int z = 0; z < m_nCellsZ; z++ )
{
++*progress;
for( unsigned int y = 0; y < m_nCellsY; y++ )
{ {
for( unsigned int x = 0; x < m_nCellsX; x++ ) // calculate
{ calculateMarchingCube( x, y, z, vals );
// calculate
calculateMarchingCube( x, y, z, vals );
}
} }
} }
} }
gettimeofday( &timer2, NULL );
millis = ( (timer2.tv_sec * 1000) + (timer2.tv_usec / 1000) ) - ( (timer1.tv_sec * 1000) + (timer1.tv_usec / 1000) );
wlog::info( "Time - MC" ) << millis;
// calculate marching cubes algorithm
gettimeofday( &timer1, NULL );
boost::shared_ptr< WSpanSpace< T > > sstyped = boost::dynamic_pointer_cast< WSpanSpace< T > >( spanSpace );
boost::shared_ptr< WSpanSpaceBase::cellids_t > cells = spanSpace->findCells( isoValue );
for( typename WSpanSpaceBase::cellids_t::const_iterator i = cells->begin(); i < cells->end(); ++i )
{
calculateMarchingCube( ( *i )->m_x, ( *i )->m_y, ( *i )->m_z, vals );
activeCells++;
}
gettimeofday( &timer2, NULL );
millis = ( (timer2.tv_sec * 1000) + (timer2.tv_usec / 1000) ) - ( (timer1.tv_sec * 1000) + (timer1.tv_usec / 1000) );
wlog::info( "Time - SS" ) << millis;
// debug - show how many cells are active
allCells = m_nCellsZ * m_nCellsY * m_nCellsX;
wlog::info( "Cells" ) << allCells << " - " << activeCells << " -> " << (activeCells / allCells ) * 100;
unsigned int nextID = 0; unsigned int nextID = 0;
boost::shared_ptr< WTriangleMesh > triMesh( new WTriangleMesh( m_idToVertices.size(), m_trivecTriangles.size() ) ); boost::shared_ptr< WTriangleMesh > triMesh( new WTriangleMesh( m_idToVertices.size(), m_trivecTriangles.size() ) );
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <tr1/functional> #include <tr1/functional>
#include <sys/time.h>
#include "../../common/WLogger.h" #include "../../common/WLogger.h"
#include "../../common/WProgressCombiner.h" #include "../../common/WProgressCombiner.h"
...@@ -341,6 +342,8 @@ template< class T > boost::shared_ptr< WSpanSpaceBase::cellids_t > WSpanSpace<T> ...@@ -341,6 +342,8 @@ template< class T > boost::shared_ptr< WSpanSpaceBase::cellids_t > WSpanSpace<T>
template< class T > WSpanSpace<T>::WSpanSpace( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ, template< class T > WSpanSpace<T>::WSpanSpace( size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ,
const std::vector< T >* vals, boost::shared_ptr< WProgressCombiner > mainProgress ) const std::vector< T >* vals, boost::shared_ptr< WProgressCombiner > mainProgress )
{ {
timeval timer1, timer2;
m_nCellsX = nbCoordsX - 1; m_nCellsX = nbCoordsX - 1;
m_nCellsY = nbCoordsY - 1; m_nCellsY = nbCoordsY - 1;
m_nCellsZ = nbCoordsZ - 1; m_nCellsZ = nbCoordsZ - 1;
...@@ -365,7 +368,12 @@ template< class T > WSpanSpace<T>::WSpanSpace( size_t nbCoordsX, size_t nbCoords ...@@ -365,7 +368,12 @@ template< class T > WSpanSpace<T>::WSpanSpace( size_t nbCoordsX, size_t nbCoords
progressSpan->finish(); progressSpan->finish();
WSpanSpaceKdTree< T > kdTree; WSpanSpaceKdTree< T > kdTree;
gettimeofday( &timer1, NULL );
m_kdTreeNode = kdTree.createTree( m_spanSpace, 0, 0, m_spanSpace.size() ); m_kdTreeNode = kdTree.createTree( m_spanSpace, 0, 0, m_spanSpace.size() );
gettimeofday( &timer2, NULL );
long millis = ( (timer2.tv_sec * 1000) + (timer2.tv_usec / 1000) ) - ( (timer1.tv_sec * 1000) + (timer1.tv_usec / 1000) );
wlog::info( "build" ) << millis;
} }
template< class T > void WSpanSpace<T>::searchKdTree( double isovalue, template< class T > void WSpanSpace<T>::searchKdTree( double isovalue,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment