Commit 94cbcba2c658c47219df0fb56855eac9618cc01f

Authored by Grizonnet Manuel (CNES)
2 parents b40b65b1 a0611e00
Exists in develop and in 1 other branch master

Merge branch 'hotfix/1.2.1'

Showing 2 changed files with 35 additions and 8 deletions   Show diff stats
src/CMakeLists.txt
... ... @@ -6,7 +6,7 @@ add_library( histo_utils SHARED histo_utils.cxx )
6 6 target_link_libraries(histo_utils ${OTB_LIBRARIES})
7 7 # Define the wrapper library that wraps our library
8 8 add_library( histo_utils_ext SHARED histo_utils_ext.cxx )
9   -target_link_libraries( histo_utils_ext ${Boost_LIBRARIES} histo_utils )
  9 +target_link_libraries( histo_utils_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} histo_utils )
10 10 # don't prepend wrapper library name with lib
11 11 set_target_properties( histo_utils_ext PROPERTIES PREFIX "" )
12 12  
... ...
src/histo_utils.cxx
... ... @@ -305,11 +305,38 @@ short compute_snowline_internal(const itk::VectorImage<short, 2>::Pointer compos
305 305  
306 306 histogramFilter->SetHistogramBinMinimum( lowerBound );
307 307 histogramFilter->SetHistogramBinMaximum( upperBound );
  308 +
  309 + // Handle case where Dimension 1 of the histogram is zero
  310 + // (upperBound[0]-lowerBound[0]) / dz < 1).
  311 + // In this case, the histogram can't be computed by the ImageToHistogramFilter
  312 + // filter
  313 + // Write histogram.txt file and returm zs=-1
  314 +
  315 + //FIXME Implicit cast from float to int here?
  316 + const unsigned int nbAltitudeBins = dz == 0? 0 : (upperBound[0]-lowerBound[0]) / dz;
  317 +
  318 + if ( nbAltitudeBins < 1 )
  319 + {
  320 + // Empty histogram. Write histo file and return -1 (no zs)
  321 + std::ofstream myfile;
  322 +
  323 + #if CXX11_ENABLED
  324 + myfile.open(std::string(histo_file));
  325 + #else
  326 + myfile.open(histo_file);
  327 + #endif
  328 +
  329 + myfile << "Number of bins=0" << std::endl;
  330 + myfile.close();
  331 + // Return -1 as no zs is found in this case
  332 + return -1;
  333 + }
  334 +
308 335  
309 336 typedef HistogramFilterType::HistogramSizeType SizeType;
310 337 SizeType size( 3 );
311 338  
312   - size[0] = (upperBound[0]-lowerBound[0]) / dz; // number of bins for the altitude channel
  339 + size[0] = nbAltitudeBins; // number of bins for the altitude channel
313 340 size[1] = 2; // number of bins for the snow channel
314 341 size[2] = 2; // number of bins for the cloud channel
315 342  
... ... @@ -328,12 +355,12 @@ short compute_snowline_internal(const itk::VectorImage&lt;short, 2&gt;::Pointer compos
328 355 short snowline = -1;
329 356 if(reverse)
330 357 {
331   - for (int i=histogram->GetSize()[0]-1; i>=0; i--)
332   - {
333   - snowline = get_elev_snowline_from_bin(histogram, i, fsnow_lim, offset, center_offset);
334   - if(snowline != -1)
335   - return snowline;
336   - }
  358 + for (int i=histogram->GetSize()[0]-1; i>=0; i--)
  359 + {
  360 + snowline = get_elev_snowline_from_bin(histogram, i, fsnow_lim, offset, center_offset);
  361 + if(snowline != -1)
  362 + return snowline;
  363 + }
337 364 }
338 365 else
339 366 {
... ...