Commit d2fea898 authored by Stéphane Albert's avatar Stéphane Albert

BUG: MANTIS-1179: Fixed otb::GlImageActor::UpdateResolution() algorithm.

parent c55d177a
......@@ -972,44 +972,61 @@ void GlImageActor::UpdateResolution()
double distAC = vcl_sqrt((pointA[0]-pointC[0])*(pointA[0]-pointC[0])+(pointA[1]-pointC[1])*(pointA[1]-pointC[1]));
double resolution = std::min(100/distAB,100/distAC);
// std::cout << std::endl;
// std::cout << "resolution: " << resolution << std::endl;
// Arbitrary higher than any distance we will compute here
double minDist = 50000.;
m_CurrentResolution = 0;
bool isFound = false;
// OTB always include full resolution level in available resolutions.
assert( !m_AvailableResolutions.empty() );
// Compute the diff and keep the index that minimize the distance
for (ResolutionVectorType::iterator it = m_AvailableResolutions.begin();
it != m_AvailableResolutions.end(); ++it)
// MANTIS-1179: resolution>1 <=> zooming in past 1:1 scale. So, cap
// resolution to index 0.
if( resolution<1.0 )
{
bool isFound = false;
// Compute the diff and keep the index that minimize the distance
for (ResolutionVectorType::iterator it = m_AvailableResolutions.begin();
it != m_AvailableResolutions.end(); ++it)
{
double diff = 1/((double)(1<<(*it))) - resolution;
// std::cout << "diff: " << diff << std::endl;
if( ( ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Lower &&
diff <= 0 )
||
( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Upper &&
diff >= 0 )
||
( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest ) )
&&
vcl_abs(diff) < minDist )
{
isFound = true;
minDist = vcl_abs(diff);
m_CurrentResolution = std::distance(m_AvailableResolutions.begin(),it);
// std::cout << "found: " << m_CurrentResolution << std::endl;
}
}
double diff = 1/((double)(1<<(*it))) - resolution;
if( ( ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Lower &&
diff < 0 )
||
( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Upper &&
diff > 0 )
||
( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest ) )
&&
vcl_abs(diff) < minDist )
// MANTIS-1147: Cap current-resolution.
if( !isFound )
{
isFound = true;
assert( m_AvailableResolutions.size() > 0 );
m_CurrentResolution = m_AvailableResolutions.size() - 1;
minDist = vcl_abs(diff);
m_CurrentResolution = std::distance(m_AvailableResolutions.begin(),it);
// std::cout << "not found: " << m_CurrentResolution << std::endl;
}
}
// MANTIS-1147: Cap current-resolution.
if( !isFound )
m_CurrentResolution = m_AvailableResolutions.size() - 1;
std::ostringstream extFilename;
extFilename<<m_FileName<<"?&resol="<<m_CurrentResolution;
......
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