CVB++ 15.0
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
12Cvb::Plane3D CutAqs12RoofAndCalculateNormal(const Cvb::PointCloud& cloud, double zRangeRoof, double xRangeRoofPlane, double yRangeRoofPlane);
13
14int main()
15{
16 try
17 {
18 auto path = Cvb::InstallPath();
19
20 // create calibrated 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(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
40Cvb::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<Cvb::DensePointCloud>(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 // calculate and return plane
58 return roof->FitPlane();
59}
Angle Max(Angle a, Angle b) noexcept
Returns the bigger of two angles.
Definition: angle.hpp:504
void SetZRange(ValueRange< double > zRange) noexcept
Set the range regarding the z-axis.
Definition: cuboid.hpp:101
A dense Cartesian 3D point cloud object.
Definition: decl_dense_point_cloud.hpp:31
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition: detail_image.hpp:32
A plane in 3D space in Hessian normal form.
Definition: plane_3d.hpp:19
static PointCloudPtr Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image.
Definition: point_cloud_factory.hpp:87
A point cloud object.
Definition: decl_point_cloud.hpp:49
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
Cuboid CalculateBoundingBox() const
Calculates the minimum and maximum extent of the point cloud.
Definition: decl_point_cloud.hpp:224
Point3D< double > CalculateCenterOfGravity() const
Calculates the center of gravity of the point cloud.
Definition: decl_point_cloud.hpp:239