Changeset 875

Show
Ignore:
Timestamp:
01/29/08 23:14:48
Author:
robert
Message:

Fixed bug in height field access

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/vpb/HeightFieldMapper.cpp

    r850 r875  
    719719    double ry = cy-fy; 
    720720     
    721     double h00 = _hf.getHeight(c,r); 
    722     double h01 = ((r+1) < (int) _hf.getNumRows()) ? _hf.getHeight(c,r+1) : h00; 
    723     double h10 = ((c) < (int) _hf.getNumColumns()) ? _hf.getHeight(c+1,r) : h00; 
    724     double h11 = ((c+1) < (int) _hf.getNumColumns() && (r+1) < (int) _hf.getNumRows()) ? _hf.getHeight(c+1,r+1) : h00; 
    725  
    726     double z = _hf.getOrigin().z() +  
    727                 h00*(1.0-rx)*(1.0-ry) +  
    728                 h01*(1.0-rx)*(ry) +  
    729                 h10*(rx)*(1.0-ry) +  
    730                 h11*(rx)*(ry); 
    731      
    732     return z; 
     721    double total_ratio = 0.0; 
     722    double total_height = 0.0; 
     723     
     724    if ((c>=0 && c<_hf.getNumColumns()) && (r>=0 && r<_hf.getNumRows()))  
     725    {   
     726        total_ratio = (1.0-rx)*(1.0-ry); 
     727        total_height = _hf.getHeight(c,r); 
     728    } 
     729     
     730    if (((c+1)>=0 && (c+1)<_hf.getNumColumns()) && (r>=0 && r<_hf.getNumRows())) 
     731    {   
     732        total_ratio = rx*(1.0-ry); 
     733        total_height = _hf.getHeight(c+1,r); 
     734    } 
     735 
     736    if ((c>=0 && c<_hf.getNumColumns()) && ((r+1)>=0 && (r+1)<_hf.getNumRows())) 
     737    {   
     738        total_ratio = (1.0-rx)*ry; 
     739        total_height = _hf.getHeight(c,r+1); 
     740    } 
     741 
     742    if (((c+1)>=0 && (c+1)<_hf.getNumColumns()) && ((r+1)>=0 && (r+1)<_hf.getNumRows())) 
     743    {   
     744        total_ratio = rx*ry; 
     745        total_height = _hf.getHeight(c+1,r+1); 
     746    } 
     747 
     748    if (total_ratio>0.0) return _hf.getOrigin().z() + total_height/total_ratio; 
     749    else return _hf.getOrigin().z(); 
    733750} 
    734751