Conscience Core
Csc3dCartographyProcessor.h
Go to the documentation of this file.
1 #ifndef Csc3dCartographyProcessor_h
2 #define Csc3dCartographyProcessor_h
3 
4 #include "CscCommon.h"
5 
6 #include <pcl/point_types.h>
7 #include <pcl/point_cloud.h>
8 #include <Eigen/Dense>
9 
10 using namespace conscience_utils::logging;
11 
12 namespace conscience_core::lidar {
14  float tx = 0.0f;
15  float ty = 0.0f;
16  float tz = 0.0f;
17 
18  float yawRad = 0.0f;
19  float pitchRad = 0.0f;
20  float rollRad = 0.0f;
21 };
22 
24  double deltaX = 0.0;
25  double deltaY = 0.0;
26  double deltaZ = 0.0;
27 
28  double deltaPitch = 0.0;
29  double deltaYaw = 0.0;
30  double deltaRoll = 0.0;
31 };
32 
51 struct FrameMetadata {
58  uint64_t frameId = 0;
59 
66  double timestamp = 0.0;
67  optional<OdometryDeltaSidecar> odometryDelta = nullopt;
69 
70  string toJsonString() const;
71 };
96  float voxelLeafSize = 5.0f;
97 
106  float finalVoxelLeafSize = 2.0f;
107 
116  double maxEdgeRmse = 30.0;
117 
125  float maxAngleDeg = 45.0f;
126 
127  bool odometryOnlyMode = false;
128 
129  double maxTranslationCorrection = 20.0f; // cm
130 
131  bool useOdometryInitialGuess = true;
132  bool fallbackToOdometryWhenGicpRejected = false;
133 
134  bool enableYawMultistart = true;
135 
136  float odometryYawClampDeg = 8.0f;
137  float odometryTranslationScale = 0.7f;
138 
139  bool accumulateStaticBootstrap = true;
140  float staticBootstrapMaxTranslationCm = 2.0f; // cm
141  float staticBootstrapMaxYawDeg = 1.0f;
142 
143  std::vector<float> yawMultistartOffsetsDeg = {
144  -20.0f,
145  -12.0f,
146  -6.0f,
147  0.0f,
148  6.0f,
149  12.0f,
150  20.0f
151  };
152 
162  int localMapWindowSize = 5;
163 
171  int lumMaxIterations = 50;
172 
180  int lumOverlapWindow = 10;
181 
190  double gicpResolution = 10.0;
191 
199  double spatialLoopDist = 500.0;
200 
208  int temporalLoopGap = 50;
209 
217  double loopClosureThreshold = 30.0;
218 
227  float dynVoxelSize = 20.0f;
228 
237  int minFrameObservations = 1;
238 
246  int ransacMaxIterations = 200;
247 
255  double ransacDistanceThreshold = 5.0;
256 
265  int ransacMinInliers = 1000;
266 
277  bool enableSpatialFilter = true;
278 
286  float maxAbsCoord = 1500.0f;
287 
295  float maxRange = 1500.0f;
296 
310  bool enableGroundLevelling = false;
311 
320  float groundMaxTiltDeg = 15.0f;
321 
330  float groundMinUpDot = 0.95f;
331 
332 
333 };
334 typedef pcl::PointXYZI PointT;
335 typedef pcl::PointCloud<PointT> PointCloudT;
336 
390 public:
391  explicit Csc3dCartographyProcessor(
392  const fs::path &inputFolderPath,
393  const fs::path &outputFilePath,
394  const CartographyConfig &config = CartographyConfig());
395 
396  ~Csc3dCartographyProcessor() = default;
397 
398  bool runPipeline();
399 
400 private:
401  Eigen::Matrix4f estimateRelativeFrameTransform(
402  int i,
403  double& rmseOut,
404  bool& acceptedOut);
405  fs::path inputFolderPath;
406  fs::path outputFilePath;
407  CartographyConfig config;
408  std::string pcdPrefix = "lidar_";
409  std::unique_ptr<CscLogger> logger;
410 
411  vector<FrameMetadata> frameMetadata;
412  vector<PointCloudT::Ptr> rawFrames;
413  vector<PointCloudT::Ptr> downsampledFrames;
414  vector<uint32_t> validFrameIds;
415 
416  Eigen::Matrix3f groundLevellingR0 = Eigen::Matrix3f::Identity();
417 
418  bool validateInputs() const;
419 
420  bool loadFrames();
421 
422  void computeInitialOdometry(vector<Eigen::Matrix4f> &poses);
423 
424  void buildAndOptimizeElchGraph(
425  const vector<Eigen::Matrix4f> &initialPoses,
426  vector<Eigen::Matrix4f> &optimizedPoses);
427 
428  PointCloudT::Ptr mergeAndFilter(const vector<Eigen::Matrix4f> &poses);
429 
430  void saveToPLY(const PointCloudT::Ptr &cloud, const fs::path &path);
431 
432  bool readJsonSidecar(const fs::path &jsonPath, FrameMetadata &out) const;
433 
434  PointCloudT::Ptr applyVoxelGridFilter(PointCloudT::Ptr input, float leafSize);
435 
436  void computeGicpAlignment(
437  PointCloudT::Ptr source,
438  PointCloudT::Ptr target,
439  Eigen::Matrix4f &transformOut,
440  double &rmseOut,
441  const Eigen::Matrix4f &initialGuess,
442  int numThreads = 0);
443 
444  string getProgressBarText(int current, int total, const std::string &prefix);
445 
446  std::vector<bool> acceptedPoseMask;
447 };
448 
449 }
450 
451 #endif
conscience_core::lidar::CartographyConfig
Definition: Csc3dCartographyProcessor.h:87
conscience_core::lidar::PointT
pcl::PointXYZI PointT
Definition: Csc3dCartographyProcessor.h:334
conscience_core::lidar::FrameMetadata
Definition: Csc3dCartographyProcessor.h:51
conscience_core::lidar
Definition: CscEntityReflexion.h:42
logger
static std::unique_ptr< CscLogger > logger
Definition: gltfHelpers.cpp:6
conscience_utils::logging
Definition: conscience_log.cpp:20
conscience_core::lidar::FrameMetadata::lidarExtrinsics
LidarExtrinsicsSidecar lidarExtrinsics
Definition: Csc3dCartographyProcessor.h:68
conscience_core::lidar::OdometryDeltaSidecar
Definition: Csc3dCartographyProcessor.h:23
CscCommon.h
conscience_core::lidar::LidarExtrinsicsSidecar
Definition: Csc3dCartographyProcessor.h:13
source
const char * source
Definition: lz4.h:807
conscience_core::lidar::Csc3dCartographyProcessor
Definition: Csc3dCartographyProcessor.h:389
conscience_core::lidar::PointCloudT
pcl::PointCloud< PointT > PointCloudT
Definition: Csc3dCartographyProcessor.h:335
i
int i
Definition: HybridAStar.cpp:191