From 1e6697da3cb1b0e13417e0105fb1e944cdad3d1f Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Tue, 21 Dec 2021 21:28:45 -0800 Subject: [PATCH 1/2] Remove miniature scale from science data and fix segfault Signed-off-by: Louise Poubel --- .../src/ScienceSensorsSystem.cc | 42 +++++++--------- .../worlds/buoyant_tethys.sdf | 48 ++++++++++++------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/lrauv_ignition_plugins/src/ScienceSensorsSystem.cc b/lrauv_ignition_plugins/src/ScienceSensorsSystem.cc index da85aeb0..a3cfff44 100644 --- a/lrauv_ignition_plugins/src/ScienceSensorsSystem.cc +++ b/lrauv_ignition_plugins/src/ScienceSensorsSystem.cc @@ -296,18 +296,6 @@ class tethys::ScienceSensorsSystemPrivate /// \brief Publish a few more times for visualization plugin to get them public: int repeatPubTimes = 1; - ////////////////////////////// - // Constants for visualization - - // TODO This is a workaround pending upstream Ignition orbit tool improvements - // \brief Scale down in order to see in view - // For 2003080103_mb_l3_las_1x1km.csv - //public: const float MINIATURE_SCALE = 0.01; - // For 2003080103_mb_l3_las.csv - public: const float MINIATURE_SCALE = 0.0001; - // For simple_test.csv - //public: const float MINIATURE_SCALE = 1.0; - // TODO This is a workaround pending upstream Marker performance improvements. // \brief Performance trick. Skip depths below this z, so have memory to // visualize higher layers at higher resolution. @@ -567,11 +555,6 @@ void ScienceSensorsSystemPrivate::ReadData( // Flip sign of z, because positive depth is negative z. cart.Z() = -depth; - // Performance trick. Scale down to see in view - cart *= this->MINIATURE_SCALE; - // Revert Z to the unscaled depth - cart.Z() = -depth; - // Performance trick. Skip points beyond some distance from origin if (abs(cart.X()) > 1000 || abs(cart.Y()) > 1000) { @@ -906,7 +889,8 @@ float ScienceSensorsSystemPrivate::BarycentricInterpolate( } SortIndices(xsSorted, xsSortedInds); - int ltPSortedIdx, gtPSortedIdx; + int ltPSortedIdx{-1}; + int gtPSortedIdx{-1}; float ltPDist, gtPDist; // Get the two closest positions in _xs that _p lies between. @@ -925,6 +909,15 @@ float ScienceSensorsSystemPrivate::BarycentricInterpolate( break; } } + if (ltPSortedIdx < 0 || ltPSortedIdx >= xsSortedInds.size() || + gtPSortedIdx < 0 || gtPSortedIdx >= xsSortedInds.size()) + { + ignwarn << "Failed to find consecutive elements in sorted vector. Indices [" + << ltPSortedIdx << "] / [" << gtPSortedIdx + << "] for vector sized [" << xsSortedInds.size() + << "]. Cannot interpolate." << std::endl; + return std::numeric_limits::quiet_NaN(); + } // Normalize the distances to ratios between 0 and 1, to use as weights float ltPWeight = ltPDist / (gtPDist + ltPDist); @@ -933,6 +926,12 @@ float ScienceSensorsSystemPrivate::BarycentricInterpolate( // Retrieve indices of sorted elements in original array int ltPIdx = xsSortedInds[ltPSortedIdx]; int gtPIdx = xsSortedInds[gtPSortedIdx]; + + if (ltPIdx >= _values.size() || gtPIdx >= _values.size()) + { + ignwarn << "Bad indices. Cannot interpolate." << std::endl; + return std::numeric_limits::quiet_NaN(); + } float result = ltPWeight * _values[ltPIdx] + gtPWeight * _values[gtPIdx]; if (this->DEBUG_INTERPOLATE) @@ -975,7 +974,7 @@ void ScienceSensorsSystemPrivate::SortIndices( // Sort indexes based on comparing values in v using std::stable_sort instead // of std::sort to avoid unnecessary index re-orderings when v contains - // elements of equal values + // elements of equal values std::stable_sort(_idx.begin(), _idx.end(), [&_v](size_t _i1, size_t _i2) {return _v[_i1] < _v[_i2];}); } @@ -1396,11 +1395,6 @@ ignition::msgs::PointCloudPacked ScienceSensorsSystemPrivate::PointCloudMsg() {"xyz", ignition::msgs::PointCloudPacked::Field::FLOAT32}, }); - // TODO optimization for visualization: - // Use PCL methods to chop off points beyond some distance from sensor - // pose. Don't need to visualize beyond that. Might want to put that on a - // different topic specifically for visualization. - msg.mutable_header()->mutable_stamp()->set_sec(this->timestamps[this->timeIdx]); pcl::PCLPointCloud2 pclPC2; diff --git a/lrauv_ignition_plugins/worlds/buoyant_tethys.sdf b/lrauv_ignition_plugins/worlds/buoyant_tethys.sdf index fdd64b08..6af05bea 100644 --- a/lrauv_ignition_plugins/worlds/buoyant_tethys.sdf +++ b/lrauv_ignition_plugins/worlds/buoyant_tethys.sdf @@ -101,7 +101,17 @@ scene 0.4 0.4 0.4 0.8 0.8 0.8 + 0 6 6 0 0.5 -1.57 + + + + + + 0.1 + + 3000000 + @@ -260,10 +270,25 @@ docked_collapsed + + + Camera controls + docked_collapsed + + docked_collapsed + + + 6 + 0 + + 50000 + 0 100000 0 0 0 0.32 + 0 1 0 1 + 100 @@ -303,32 +328,23 @@ -0.5 0.1 -0.9 - - + true - - - - 0 0 1 - - - 0 0 1 - 100 100 + + 300000 300000 - - 0.8 0.8 0.8 1 - 0.8 0.8 0.8 1 - 0.8 0.8 0.8 1 - + 1.0 - --> +