1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| #include <iostream> #include <memory> #include <opencv2/core/core.hpp>
enum class SegmentationMethod { Distance, Morphological };
class MapSegmentation { protected: const cv::Mat& map_seg; const double resolution; const double robot_radius;
public: MapSegmentation(const cv::Mat& map_seg, double resolution, double robot_radius) : map_seg(map_seg), resolution(resolution), robot_radius(robot_radius) {}
virtual void segmentMap() = 0; };
class DistanceSegmentation : public MapSegmentation { private: double room_upper_limit_morphological_; double room_lower_limit_morphological_;
public: DistanceSegmentation(const cv::Mat& map_seg, double resolution, double robot_radius, double room_upper_limit_morphological, double room_lower_limit_morphological) : MapSegmentation(map_seg, resolution, robot_radius), room_upper_limit_morphological_(room_upper_limit_morphological), room_lower_limit_morphological_(room_lower_limit_morphological) {}
void segmentMap() override { std::cout << "Performing distance-based map segmentation..." << std::endl; } };
class MorphologicalSegmentation : public MapSegmentation { private: double room_upper_limit_distance_; double room_lower_limit_distance_;
public: MorphologicalSegmentation(const cv::Mat& map_seg, double resolution, double robot_radius, double room_upper_limit_distance, double room_lower_limit_distance) : MapSegmentation(map_seg, resolution, robot_radius), room_upper_limit_distance_(room_upper_limit_distance), room_lower_limit_distance_(room_lower_limit_distance) {}
void segmentMap() override { std::cout << "Performing morphological-based map segmentation..." << std::endl; } };
int main() { cv::Mat map_seg; double resolution = 0.1; double robot_radius = 0.5; double room_upper_limit_distance = 1.0; double room_lower_limit_distance = 0.5; double room_upper_limit_morphological = 3.0; double room_lower_limit_morphological = 2.0; SegmentationMethod method = SegmentationMethod::Distance;
std::unique_ptr<MapSegmentation> segmentationMethod;
if (method == SegmentationMethod::Distance) { segmentationMethod = std::make_unique<DistanceSegmentation>(map_seg, resolution, robot_radius, room_upper_limit_morphological, room_lower_limit_morphological); } else if (method == SegmentationMethod::Morphological) { segmentationMethod = std::make_unique<MorphologicalSegmentation>(map_seg, resolution, robot_radius, room_upper_limit_distance, room_lower_limit_distance); }
if (segmentationMethod) { segmentationMethod->segmentMap(); }
return 0; }
|