Commit 57ad80c3 authored by Alexander Wiebel's avatar Alexander Wiebel

[REFAC] extracted function evaluating transfer function

parent 14bd6de0
......@@ -526,77 +526,77 @@ std::vector< std::pair< double, WPosition > > WMPickingDVR::sampleIntensityAlong
return result;
}
WPosition WMPickingDVR::getPickedDVRPosition( std::string pickingMode, bool* pickingSuccess )
double WMPickingDVR::getTFAlpha( const double scalar ) const
{
std::vector< std::pair< double, WPosition > > samples( 0 );
samples = sampleIntensityAlongRay();
if( samples.size() == 0 )
{
*pickingSuccess = false;
}
WPosition posPicking = m_posStart;
double max = 0.0;
double min = 0.0;
double accAlpha = 0.0;
double accAlphaOld = 0.0;
double pickedAlpha = 0.0;
double maxValue = 0.0;
// Get transferfunction data
boost::shared_ptr< WDataSetSingle > transferFunctionData = m_transferFunction->getData();
if(!transferFunctionData)
if( !transferFunctionData )
{
errorLog()<< "[Invalid transferfunction data]";
*pickingSuccess = false;
return WPosition();
WAssert( false, "Invalid transferfunction data" );
}
// Get transferfunction values
boost::shared_ptr< WValueSetBase > transferFunctionValues = transferFunctionData->getValueSet();
// Get scalar field
boost::shared_ptr< WDataSetScalar > scalarData = m_scalarIC->getData();
if(!scalarData)
{
errorLog()<< "[Invalid scalar field]";
return WPosition();
WAssert( false, "Invalid scalar field" );
}
max = scalarData->getMax();
min = scalarData->getMin();
maxValue = min;
const double max = scalarData->getMax();
const double min = scalarData->getMin();
std::vector<double> vecAlphaAcc;
// Classification variables
const double nominator = scalar - min;
double denominator = max - min;
// Sampling loop
for( unsigned int i = 0; i < samples.size(); i++ )
if( denominator == 0.0 )
{
// Classification variables
double nominator = samples[i].first - min;
double denominator = max - min;
denominator = 0.0001;
}
if( denominator == 0.0 )
{
denominator = 0.0001;
}
// Classification: Convert scalar to color
double scalarPercentage = nominator / denominator;
int colorIdx = scalarPercentage * transferFunctionValues->size();
WMPickingColor<double> color;
// Classification: Convert scalar to color
double scalarPercentage = nominator / denominator;
int colorIdx = scalarPercentage * transferFunctionValues->size();
// Get color from transferfunction
color.setRed( transferFunctionData->getSingleRawValue( colorIdx * 4 + 0 ) );
color.setGreen( transferFunctionData->getSingleRawValue( colorIdx * 4 + 1 ) );
color.setBlue( transferFunctionData->getSingleRawValue( colorIdx * 4 + 2 ) );
color.setAlpha( transferFunctionData->getSingleRawValue( colorIdx * 4 + 3 ) );
color.normalize();
WMPickingColor<double> color;
return color.getAlpha();
}
// Get color from transferfunction
color.setRed( transferFunctionData->getSingleRawValue( colorIdx * 4 + 0 ) );
color.setGreen( transferFunctionData->getSingleRawValue( colorIdx * 4 + 1 ) );
color.setBlue( transferFunctionData->getSingleRawValue( colorIdx * 4 + 2 ) );
color.setAlpha( transferFunctionData->getSingleRawValue( colorIdx * 4 + 3 ) );
color.normalize();
double currentAlpha = color.getAlpha();
WPosition WMPickingDVR::getPickedDVRPosition( std::string pickingMode, bool* pickingSuccess )
{
std::vector< std::pair< double, WPosition > > samples( 0 );
samples = sampleIntensityAlongRay();
if( samples.size() == 0 )
{
*pickingSuccess = false;
return WPosition();
}
WPosition posPicking = m_posStart;
double accAlpha = 0.0;
double accAlphaOld = 0.0;
double pickedAlpha = 0.0;
double maxValue = -1 * std::numeric_limits< double >::max();;
std::vector<double> vecAlphaAcc;
for( unsigned int i = 0; i < samples.size(); i++ )
{
const double currentAlpha = getTFAlpha( samples[i].first );
double currentAlphaCorrected;
if( m_opacityCorrectionEnabled->get( true ) )
......
......@@ -151,6 +151,15 @@ private:
*/
std::vector< std::pair< double, WPosition > > sampleIntensityAlongRay();
/**
* Evaluate transfer function.
*
* \param scalar Evaluate transfer function for this value.
*
* \returnOpacity obtained from transfer function.
*/
double getTFAlpha( const double scalar ) const;
/**
* Compute the position picked in the DVR
*
......
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