Cvb/CppPointCloudCreateCalibrated
1 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 
6 #include <iostream>
7 
8 #include "cvb/point_cloud_factory.hpp"
9 #include "cvb/point_cloud.hpp"
10 #include "cvb/calibrator_3d.hpp"
11 
12 Cvb::Plane3D CutAqs12RoofAndCalculateNormal(const Cvb::PointCloud& cloud, double zRangeRoof, double xRangeRoofPlane, double yRangeRoofPlane);
13 
14 int main()
15 {
16  try
17  {
18  auto path = Cvb::InstallPath();
19 
20  // create calibrated (dense) point cloud
21  Cvb::ImagePtr rangemap = Cvb::Image::Load(path + CVB_LIT("tutorial/Metric/Images/RangeMapCalibrationPattern.tif"));
22  auto calibrator = Cvb::Calibrator3D::Load<Cvb::Calibrator3D>(path + CVB_LIT("tutorial/Metric/Images/SICalibration.json"));
23  calibrator->SetRangeMapIgnoreValue(0.0);
24  auto cloudAqs12 = Cvb::PointCloudFactory::Create<Cvb::DensePointCloud>(rangemap->Plane(0), *calibrator,
26 
27  // do something, e.g.
28  // cut roof part of AQS12 and calculate its normal
29  auto plane = CutAqs12RoofAndCalculateNormal(*cloudAqs12, 10.0, 50.0, 1000.0);
30 
31  }
32  catch (const std::exception & error)
33  {
34  std::cout << error.what() << std::endl;
35  }
36 
37  return 0;
38 }
39 
40 Cvb::Plane3D CutAqs12RoofAndCalculateNormal(const Cvb::PointCloud &cloud, double zRangeRoof, double xRangeRoofPlane, double yRangeRoofPlane)
41 {
42  auto dx = xRangeRoofPlane / 2;
43  auto dy = yRangeRoofPlane / 2;
44 
45  // crop roof roughly
46  auto bbRoof = cloud.CalculateBoundingBox();
47  bbRoof.SetZRange({ bbRoof.ZRange().Max() - zRangeRoof, bbRoof.ZRange().Max() + 1 });
48  auto roof = cloud.Crop(bbRoof);
49 
50  // use only midmost part of roof
51  auto cog = roof->CalculateCenterOfGravity();
52  auto bbRoofPlane = roof->CalculateBoundingBox();
53  bbRoofPlane.SetXRange({ cog.X() - dx, cog.X() + dx });
54  bbRoofPlane.SetYRange({ cog.Y() - dy, cog.Y() + dy });
55  auto roofPlane = roof->Crop(bbRoofPlane);
56 
57  // calcluate and return plane
58  return roof->FitPlane();
59 }
std::shared_ptr< T > Crop(const Cuboid &clipBox) const
Creates a new point cloud which only consists of the points inside the clip box.
Definition: decl_point_cloud.hpp:301
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition: detail_image.hpp:32
A point cloud object.
Definition: decl_point_cloud.hpp:48
void SetZRange(ValueRange< double > zRange) noexcept
Set the range regarding the z-axis.
Definition: cuboid.hpp:101
STL class.
A plane in 3D space in Hessian normal form.
Definition: plane_3d.hpp:17
Cuboid CalculateBoundingBox() const
Calculates the minimum and maximum extent of the point cloud.
Definition: decl_point_cloud.hpp:224