Commit 71eafac1 authored by Alexander Wiebel's avatar Alexander Wiebel

[FIX #342] fixed normals for lighting and made radius normalization optional

parent 616b2a8a
......@@ -47,6 +47,68 @@ WMHomeGlyphs::WMHomeGlyphs():
{
}
namespace
{
// Helper routine to estimate normals in a triangle soup in which antipodal
// vertices are subsequent
// taken from teem (glyphElf.c)
void estimateNormalsAntipodal( limnPolyData *glyph, const char normalize )
{
unsigned int faceno = glyph->indxNum/3;
unsigned int *faces = glyph->indx;
unsigned int f;
memset( glyph->norm, 0, sizeof( float )*3*glyph->xyzwNum );
for( f = 0; f < faceno/2; f++ )
{
float diff1[3];
float diff2[3];
float cross[3];
ELL_3V_SUB( diff1, glyph->xyzw+4*faces[3*f+1],
glyph->xyzw+4*faces[3*f] );
ELL_3V_SUB( diff2, glyph->xyzw+4*faces[3*f+2],
glyph->xyzw+4*faces[3*f] );
ELL_3V_CROSS( cross, diff1, diff2 );
ELL_3V_INCR( glyph->norm+3*faces[3*f], cross );
ELL_3V_INCR( glyph->norm+3*faces[3*f+1], cross );
ELL_3V_INCR( glyph->norm+3*faces[3*f+2], cross );
/* same for anti-face */
if ( faces[3*f]%2 == 0 )
{
ELL_3V_SUB( glyph->norm+3*faces[3*f]+3, glyph->norm+3*faces[3*f]+3, cross );
}
else
{
ELL_3V_SUB( glyph->norm+3*faces[3*f]-3, glyph->norm+3*faces[3*f]-3, cross );
}
if ( faces[3*f+1]%2 == 0 )
{
ELL_3V_SUB( glyph->norm+3*faces[3*f+1]+3, glyph->norm+3*faces[3*f+1]+3, cross );
}
else
{
ELL_3V_SUB( glyph->norm+3*faces[3*f+1]-3, glyph->norm+3*faces[3*f+1]-3, cross );
}
if ( faces[3*f+2]%2 == 0 )
{
ELL_3V_SUB( glyph->norm+3*faces[3*f+2]+3, glyph->norm+3*faces[3*f+2]+3, cross );
}
else
{
ELL_3V_SUB( glyph->norm+3*faces[3*f+2]-3, glyph->norm+3*faces[3*f+2]-3, cross );
}
}
if ( normalize )
{
float len;
unsigned int i;
for ( i = 0; i < glyph->normNum; i++ )
{
ELL_3V_NORM_TT( glyph->norm + 3*i, float, glyph->norm + 3*i, len );
}
}
}
}
WMHomeGlyphs::~WMHomeGlyphs()
{
// Cleanup!
......@@ -90,21 +152,22 @@ void WMHomeGlyphs::properties()
m_sliceOrientations->addItem( "x", "x-slice" );
m_sliceOrientations->addItem( "y", "y-slice" );
m_sliceOrientations->addItem( "z", "z-slice" );
m_sliceOrientationSelection = m_properties->addProperty( "Slice Orientation",
m_sliceOrientationSelection = m_properties->addProperty( "Slice orientation",
"Which slice will be shown?",
m_sliceOrientations->getSelector( 1 ),
m_recompute );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_sliceOrientationSelection );
m_glyphSizeProp = m_properties->addProperty( "Glyph Size", "Size of the displayed glyphs.", 0.5, m_recompute );
m_glyphSizeProp = m_properties->addProperty( "Glyph size", "Size of the displayed glyphs.", 0.5, m_recompute );
m_glyphSizeProp->setMin( 0 );
m_glyphSizeProp->setMax( 100. );
m_sliceIdProp = m_properties->addProperty( "Slice Id", "Number of the slice to display", 0, m_recompute );
m_sliceIdProp = m_properties->addProperty( "Slice ID", "Number of the slice to display", 0, m_recompute );
m_sliceIdProp->setMin( 0 );
m_sliceIdProp->setMax( 128 );
m_usePolarPlotProp = m_properties->addProperty( "Use Polar Plot", "Use polar plot for glyph instead of HOME?", false, m_recompute );
m_usePolarPlotProp = m_properties->addProperty( "Use polar plot", "Use polar plot for glyph instead of HOME?", true, m_recompute );
m_useNormalization = m_properties->addProperty( "Radius normalization", "Scale the radius of each glyph to be in [0,1].", true, m_recompute );
}
void WMHomeGlyphs::moduleMain()
......@@ -265,23 +328,33 @@ void WMHomeGlyphs::renderSlice( size_t sliceId )
limnPolyData *glyph = limnPolyDataNew();
limnPolyDataCopy( glyph, sphere );
double radius = 1.0; // some initialization
if( usePolar )
{
char isdef = 3; // some initialization
elfGlyphPolar( glyph, 1, ten, type, &isdef, 0, normalize, NULL, NULL );
radius = elfGlyphPolar( glyph, 1, ten, type, &isdef, 0, normalize, NULL, NULL );
WAssert( isdef != 0, "Tensor is non positive definite. Think about that." );
}
else
{
elfGlyphHOME( glyph, 1, ten, type, NULL, normalize );
radius = elfGlyphHOME( glyph, 1, ten, type, NULL, normalize );
}
// -------------------------------------------------------------------------------------------------------
// One can insert per-peak coloring here (see http://www.ci.uchicago.edu/~schultz/sphinx/home-glyph.html )
// -------------------------------------------------------------------------------------------------------
minMaxNormalization( glyph );
float scale = m_glyphSizeProp->get(); // glyph size
if( m_useNormalization->get() )
{
minMaxNormalization( glyph );
}
else
{
scale = scale / radius;
}
estimateNormalsAntipodal( glyph, normalize );
wmath::WPosition glyphPos = grid->getPosition( posId );
......@@ -292,15 +365,14 @@ void WMHomeGlyphs::renderSlice( size_t sliceId )
glyphElements->push_back( vertsUpToCurrentIteration + glyph->indx[vertId] );
}
float radius = 1.0 / m_glyphSizeProp->get(); // glyph size
for( unsigned int vertId = 0; vertId < glyph->xyzwNum; ++vertId )
{
//-------------------------------
// vertices
( *vertArray )[vertsUpToCurrentIteration+vertId][0] = glyph->xyzw[m_nbVertCoords*vertId ] / radius + glyphPos[0];
( *vertArray )[vertsUpToCurrentIteration+vertId][1] = glyph->xyzw[m_nbVertCoords*vertId+1] / radius + glyphPos[1];
( *vertArray )[vertsUpToCurrentIteration+vertId][2] = glyph->xyzw[m_nbVertCoords*vertId+2] / radius + glyphPos[2];
( *vertArray )[vertsUpToCurrentIteration+vertId][0] = glyph->xyzw[m_nbVertCoords*vertId ] * scale + glyphPos[0];
( *vertArray )[vertsUpToCurrentIteration+vertId][1] = glyph->xyzw[m_nbVertCoords*vertId+1] * scale + glyphPos[1];
( *vertArray )[vertsUpToCurrentIteration+vertId][2] = glyph->xyzw[m_nbVertCoords*vertId+2] * scale + glyphPos[2];
// ------------------------------------------------
// normals
......
......@@ -140,6 +140,7 @@ private:
boost::shared_ptr< WItemSelection > m_sliceOrientations; //!< A list of the selectable slice orientations, i.e x, y and z.
WPropSelection m_sliceOrientationSelection; //!< To choose whether to x, y or z slice.
WPropBool m_usePolarPlotProp; //!< Property indicating whether to use polar plot instead of HOME glyph
WPropBool m_useNormalization; //!< Indicates whether to us radius normalization.
WPropDouble m_glyphSizeProp; //!< Property holding the size of the displayed glyphs
WPropInt m_sliceIdProp; //!< Property holding the slice ID
......
......@@ -26,7 +26,7 @@ void main()
10.0, // shinines
1.0, // light diffuse
0.75, // light ambient
normalize( v_normal ), // normal
normalize( v_normal ), // normal
normalize( v_ray ), // view direction
normalize( v_lightSource ) // light source position
);
......
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