Commit 1cf0d972 authored by Alexander Wiebel's avatar Alexander Wiebel

[CHANGE #366] hopefully made it better suited for multi threading. Still it

seems that more threads do not accelerate it
parent d9525be9
......@@ -24,6 +24,7 @@
#include <teem/elf.h>
#include <sstream>
#include <string>
#include <osg/LightModel>
......@@ -41,8 +42,6 @@
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMHomeGlyphs )
const size_t WMHomeGlyphs::m_nbVertCoords = 4;
WMHomeGlyphs::WMHomeGlyphs():
WModule(),
m_recompute( boost::shared_ptr< WCondition >( new WCondition() ) )
......@@ -265,13 +264,15 @@ void WMHomeGlyphs::activate()
WModule::activate();
}
void WMHomeGlyphs::GlyphGeneration::minMaxNormalization( limnPolyData *glyph )
void WMHomeGlyphs::GlyphGeneration::minMaxNormalization( limnPolyData *glyph, const size_t& nbVertCoords )
{
double min = wlimits::MAX_DOUBLE;
double max = -wlimits::MAX_DOUBLE;
for( size_t i = 0; i < glyph->xyzwNum; ++i )
// double min = wlimits::MAX_DOUBLE;
// double max = -wlimits::MAX_DOUBLE;
double min = 1e15;
double max = -1e15;
for( size_t vertID = 0; vertID < glyph->xyzwNum; ++vertID )
{
wmath::WPosition pos( glyph->xyzw[m_nbVertCoords*i], glyph->xyzw[m_nbVertCoords*i+1], glyph->xyzw[m_nbVertCoords*i+2] );
wmath::WPosition pos( glyph->xyzw[nbVertCoords*vertID], glyph->xyzw[nbVertCoords*vertID+1], glyph->xyzw[nbVertCoords*vertID+2] );
double norm = pos.norm();
if( norm < min )
{
......@@ -288,15 +289,19 @@ void WMHomeGlyphs::GlyphGeneration::minMaxNormalization( limnPolyData *glyph )
{
WAssert( dist > 0, "Max has to be larger than min." );
for( size_t i = 0; i < glyph->xyzwNum; ++i )
{
wmath::WPosition pos( glyph->xyzw[m_nbVertCoords*i], glyph->xyzw[m_nbVertCoords*i+1], glyph->xyzw[m_nbVertCoords*i+2] );
double norm = pos.norm();
wmath::WPosition newPos = ( ( norm - min ) / dist ) * pos.normalized();
glyph->xyzw[m_nbVertCoords*i] = newPos[0];
glyph->xyzw[m_nbVertCoords*i+1] = newPos[1];
glyph->xyzw[m_nbVertCoords*i+2] = newPos[2];
}
for( size_t i = 0; i < glyph->xyzwNum; ++i )
{
size_t coordIdBase = nbVertCoords * i;
wmath::WPosition pos( glyph->xyzw[coordIdBase], glyph->xyzw[coordIdBase+1], glyph->xyzw[coordIdBase+2] );
double norm = pos.norm();
const double epsilon = 1e-9;
wmath::WPosition newPos;
// newPos = ( ( ( norm - min ) / dist ) + epsilon ) * pos.normalized();
newPos = ( ( ( norm - min ) / dist ) + epsilon ) * pos / norm;
glyph->xyzw[coordIdBase] = newPos[0];
glyph->xyzw[coordIdBase+1] = newPos[1];
glyph->xyzw[coordIdBase+2] = newPos[2];
}
}
// else do nothing because all values are equal.
}
......@@ -381,6 +386,9 @@ WMHomeGlyphs::GlyphGeneration::~GlyphGeneration()
void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WBoolFlag& /*b*/ )
{
const size_t nbVertCoords = 4; //The teem limn data structure has 4 values for a coordinate: x, y, z, w.
limnPolyData *localSphere = limnPolyDataNew();
limnPolyDataCopy( localSphere, m_sphere );
enum sliceTypeEnum
{
xSlice = 0,
......@@ -400,16 +408,19 @@ void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WB
float* res = new float[type->num];
float* esh = new float[type->num];
size_t chunkSize = m_nA;
if( numThreads > 1 )
{
chunkSize = m_nA / ( numThreads - 1 );
}
size_t chunkSize = m_nA / numThreads;
size_t first = id * chunkSize;
size_t last = ( id + 1 ) * chunkSize - 1;
//std::cout << "I am still running " << id << "/" << numThreads << " (" << first << " ... " << last << ")" << chunkSize << std::endl;
if( id == numThreads - 1 )
{
last = m_nA - 1;
}
std::stringstream ss;
ss << id << "/" << numThreads <<" (" << first << " ... " << last << ")[" << chunkSize << "/" << m_nA << "]" << std::endl;
WLogger::getLogger()->addLogMessage( ss.str(), "______", LL_DEBUG );
for( size_t aId = first; aId <= last && aId < m_nA; ++aId )
for( size_t aId = first; aId <= last; ++aId )
{
for( size_t bId = 0; bId < m_nB; ++bId )
{
......@@ -447,14 +458,14 @@ void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WB
tijk_refine_rankk_parm *parm = tijk_refine_rankk_parm_new();
parm->pos = 1;
int ret = tijk_approx_rankk_3d_f( NULL, NULL, res, ten, type, 6, parm );
WAssert( ret == 0, "Error condition in call." );
WAssert( ret == 0, "Error condition in call to tijk_approx_rankk_3d_f." );
parm = tijk_refine_rankk_parm_nix( parm );
tijk_sub_f( ten, ten, res, type );
const char normalize = 0;
limnPolyData *glyph = limnPolyDataNew();
limnPolyDataCopy( glyph, m_sphere );
limnPolyDataCopy( glyph, localSphere );
double radius = 1.0; // some initialization
if( m_usePolar )
......@@ -475,13 +486,14 @@ void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WB
if( m_useNormalization )
{
minMaxNormalization( glyph );
minMaxNormalization( glyph, nbVertCoords );
}
else
{
m_scale = m_scale / radius;
}
estimateNormalsAntipodal( glyph, normalize );
wmath::WPosition glyphPos = m_grid->getPosition( posId );
//-------------------------------
......@@ -497,9 +509,9 @@ void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WB
size_t globalVertexId = vertsUpToCurrentIteration + vertId;
//-------------------------------
// vertices
( *m_vertArray )[globalVertexId][0] = glyph->xyzw[m_nbVertCoords*vertId ] * m_scale + glyphPos[0];
( *m_vertArray )[globalVertexId][1] = glyph->xyzw[m_nbVertCoords*vertId+1] * m_scale + glyphPos[1];
( *m_vertArray )[globalVertexId][2] = glyph->xyzw[m_nbVertCoords*vertId+2] * m_scale + glyphPos[2];
( *m_vertArray )[globalVertexId][0] = glyph->xyzw[nbVertCoords*vertId ] * m_scale + glyphPos[0];
( *m_vertArray )[globalVertexId][1] = glyph->xyzw[nbVertCoords*vertId+1] * m_scale + glyphPos[1];
( *m_vertArray )[globalVertexId][2] = glyph->xyzw[nbVertCoords*vertId+2] * m_scale + glyphPos[2];
// ------------------------------------------------
// normals
......@@ -521,6 +533,10 @@ void WMHomeGlyphs::GlyphGeneration::operator()( size_t id, size_t numThreads, WB
glyph = limnPolyDataNix( glyph );
}
}
// free memory
localSphere = limnPolyDataNix( localSphere );
delete[] ten;
delete[] res;
delete[] esh;
......
......@@ -138,7 +138,6 @@ private:
osg::ref_ptr< osg::Geode > m_glyphsGeode; //!< Pointer to geode containing the glyphs.
osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node.
static const size_t m_nbVertCoords; //!< The teem limn data structure has 4 values for a coordinate: x, y, z, w.
/**
* This class actually generated the glyph geometry. This class has () operator that the work.
......@@ -186,9 +185,10 @@ private:
/**
* Makes the radii of the glyph be distributed between [0,1]
* \param glyph The glyph thta will be normalized given as teem's limnPolyData.
* \param glyph The glyph that will be normalized given as teem's limnPolyData.
* \param nbVertCoords Number of coords per vertex for the glyph polydata
*/
void minMaxNormalization( limnPolyData *glyph );
void minMaxNormalization( limnPolyData *glyph, const size_t& nbVertCoords );
size_t m_nA; //!< Internal variable holding the number of glyphs in the first direction of the slice.
size_t m_nB; //!< Internal variable holding the number of glyphs in the second direction of the slice.
......
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