Skip to content

Commit

Permalink
point2dem: Fix support of nonspherical datums
Browse files Browse the repository at this point in the history
Apparently we were not handling datums like earth correctly. This
required fixing in Vision Workbench.
  • Loading branch information
Zachary Moratto committed Feb 20, 2012
1 parent b71738b commit a256287
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
15 changes: 10 additions & 5 deletions src/asp/Core/OrthoRasterizer.h
Expand Up @@ -42,9 +42,14 @@ namespace cartography {
typedef std::pair<BBox3, BBox2i> BBoxPair; typedef std::pair<BBox3, BBox2i> BBoxPair;
std::vector<BBoxPair > m_point_image_boundaries; std::vector<BBoxPair > m_point_image_boundaries;


// This is growing a bbox of points in point projection and Z
// values which are altitude.
struct GrowBBoxAccumulator { struct GrowBBoxAccumulator {
BBox3 bbox; BBox3 bbox;
void operator()( Vector3 const& v ) { if (v != Vector3()) bbox.grow(v); } void operator()( Vector3 const& v ) {
if ( !boost::math::isnan(v.z()) )
bbox.grow(v);
}
}; };


struct RemoveSoftInvalid : ReturnFixedType<PixelT> { struct RemoveSoftInvalid : ReturnFixedType<PixelT> {
Expand Down Expand Up @@ -199,7 +204,7 @@ namespace cartography {
for ( int32 row = 0; row < point_copy.rows()-1; ++row ) { for ( int32 row = 0; row < point_copy.rows()-1; ++row ) {
PointAcc point_ul = row_acc; PointAcc point_ul = row_acc;
for ( int32 col = 0; col < point_copy.cols()-1; ++col ) { for ( int32 col = 0; col < point_copy.cols()-1; ++col ) {
if ( *point_ul != Vector3() ) { if ( !boost::math::isnan((*point_ul).z()) ) {


PointAcc point_ur = point_ul; point_ur.next_col(); PointAcc point_ur = point_ul; point_ur.next_col();
PointAcc point_ll = point_ul; point_ll.next_row(); PointAcc point_ll = point_ul; point_ll.next_row();
Expand All @@ -208,7 +213,7 @@ namespace cartography {
// Verify the point UL and LR are in the rasterable // Verify the point UL and LR are in the rasterable
// area. Then just verify that at least one vertice is // area. Then just verify that at least one vertice is
// placed in the viewable area. // placed in the viewable area.
if ( *point_lr == Vector3() || if ( boost::math::isnan((*point_lr).z()) ||
!buf_local_3d_bbox.contains(*point_ul) || !buf_local_3d_bbox.contains(*point_ul) ||
!buf_local_3d_bbox.contains(*point_lr) || !buf_local_3d_bbox.contains(*point_lr) ||
!(local_3d_bbox.contains(*point_ul) || !(local_3d_bbox.contains(*point_ul) ||
Expand Down Expand Up @@ -237,12 +242,12 @@ namespace cartography {
intensities[4] = texture_copy(col+1,row); intensities[4] = texture_copy(col+1,row);


// triangle 1 is: LL, LR, UL // triangle 1 is: LL, LR, UL
if ( *point_ll != Vector3() && if ( !boost::math::isnan((*point_ll).z()) &&
buf_local_3d_bbox.contains(*point_lr) ) buf_local_3d_bbox.contains(*point_lr) )
renderer.DrawPolygon(0, 3); renderer.DrawPolygon(0, 3);


// triangle 2 is: UL, LR, UR // triangle 2 is: UL, LR, UR
if ( *point_ur != Vector3() && if ( !boost::math::isnan((*point_ur).z()) &&
buf_local_3d_bbox.contains(*point_ur) ) buf_local_3d_bbox.contains(*point_ur) )
renderer.DrawPolygon(2, 3); renderer.DrawPolygon(2, 3);
} }
Expand Down
35 changes: 28 additions & 7 deletions src/asp/Tools/point2dem.cc
Expand Up @@ -74,6 +74,28 @@ inline point_image_offset( ImageViewBase<ImageT> const& image, Vector3 const& of
return UnaryPerPixelView<ImageT,PointOffsetFunc>( image.impl(), PointOffsetFunc(offset) ); return UnaryPerPixelView<ImageT,PointOffsetFunc>( image.impl(), PointOffsetFunc(offset) );
} }


// Center Longitudes
class CenterLongitudeFunc : public UnaryReturnSameType {
double center;
public:
CenterLongitudeFunc(double c = 0) : center(c) {}

Vector3 operator()( Vector3 const& v ) const {
if ( v[0] < center - 180 )
return (*this)(v + Vector3(360,0,0));
else if ( v[0] > center + 180 )
return (*this)(v - Vector3(360,0,0));
return v;
}
};

template <class ImageT>
UnaryPerPixelView<ImageT, CenterLongitudeFunc>
inline recenter_longitude( ImageViewBase<ImageT> const& image, double center ) {
return UnaryPerPixelView<ImageT, CenterLongitudeFunc>(image.impl(),
CenterLongitudeFunc(center));
}

// Allows FileIO to correctly read/write these pixel types // Allows FileIO to correctly read/write these pixel types
namespace vw { namespace vw {
template<> struct PixelFormatID<Vector3> { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; }; template<> struct PixelFormatID<Vector3> { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
Expand Down Expand Up @@ -284,15 +306,14 @@ int main( int argc, char *argv[] ) {
vw_out() << "\t--> Applying offset: " << opt.x_offset vw_out() << "\t--> Applying offset: " << opt.x_offset
<< " " << opt.y_offset << " " << opt.z_offset << "\n"; << " " << opt.y_offset << " " << opt.z_offset << "\n";
point_image = point_image =
project_point_image( geodetic_to_point(point_image_offset(recenter_longitude(cartesian_to_geodetic(point_image,georef),
point_image_offset( avg_location.x() >= 0 ? 0 : 180),
xyz_to_lon_lat_radius(point_image, true, avg_location[0] >= 0 ), Vector3(opt.x_offset,
Vector3(opt.x_offset,opt.y_offset,opt.z_offset)), georef); opt.y_offset,
opt.z_offset)),georef);
} else { } else {
point_image = point_image =
project_point_image( geodetic_to_point(recenter_longitude(cartesian_to_geodetic(point_image,georef), avg_location.x() >= 0 ? 0 : 180),georef);
xyz_to_lon_lat_radius(point_image, true, avg_location[0] >= 0 ),
georef);
} }


// Rasterize the results to a temporary file on disk so as to speed // Rasterize the results to a temporary file on disk so as to speed
Expand Down

0 comments on commit a256287

Please sign in to comment.