@@ -2374,6 +2374,151 @@ void undistortPoints(InputArray src, OutputArray dst,
23742374 InputArray R = noArray(), InputArray P = noArray(),
23752375 TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER,5 ,0.01 ));
23762376
2377+
2378+ /* * @brief Octree for 3D vision.
2379+ *
2380+ * In 3D vision filed, the Octree is used to process and accelerate the pointcloud data. The class Octree represents
2381+ * the Octree data structure. Each Octree will have a fixed depth. The depth of Octree refers to the distance from
2382+ * the root node to the leaf node.All OctreeNodes will not exceed this depth.Increasing the depth will increase
2383+ * the amount of calculation exponentially. And the small number of depth refers low resolution of Octree.
2384+ * Each node contains 8 children, which are used to divide the space cube into eight parts. Each octree node represents
2385+ * a cube. And these eight children will have a fixed order, the order is described as follows:
2386+ *
2387+ * For illustration, assume,
2388+ *
2389+ * rootNode: origin == (0, 0, 0), size == 2
2390+ *
2391+ * Then,
2392+ *
2393+ * children[0]: origin == (0, 0, 0), size == 1
2394+ *
2395+ * children[1]: origin == (1, 0, 0), size == 1, along X-axis next to child 0
2396+ *
2397+ * children[2]: origin == (0, 1, 0), size == 1, along Y-axis next to child 0
2398+ *
2399+ * children[3]: origin == (1, 1, 0), size == 1, in X-Y plane
2400+ *
2401+ * children[4]: origin == (0, 0, 1), size == 1, along Z-axis next to child 0
2402+ *
2403+ * children[5]: origin == (1, 0, 1), size == 1, in X-Z plane
2404+ *
2405+ * children[6]: origin == (0, 1, 1), size == 1, in Y-Z plane
2406+ *
2407+ * children[7]: origin == (1, 1, 1), size == 1, furthest from child 0
2408+ */
2409+
2410+ class CV_EXPORTS Octree {
2411+
2412+ public:
2413+
2414+ // ! Default constructor.
2415+ Octree ();
2416+
2417+ /* * @overload
2418+ * @brief Create an empty Octree and set the maximum depth.
2419+ *
2420+ * @param maxDepth The max depth of the Octree. The maxDepth > -1.
2421+ */
2422+ explicit Octree (int maxDepth);
2423+
2424+ /* * @overload
2425+ * @brief Create an Octree from the PointCloud data with the specific max depth.
2426+ *
2427+ * @param pointCloud Point cloud data.
2428+ * @param maxDepth The max depth of the Octree.
2429+ */
2430+ Octree (const std::vector<Point3f> &pointCloud,int maxDepth);
2431+
2432+ /* * @overload
2433+ * @brief Create an empty Octree.
2434+ *
2435+ * @param maxDepth Max depth.
2436+ * @param size Initial Cube size.
2437+ * @param origin Initial center coordinate.
2438+ */
2439+ Octree (int maxDepth,double size,const Point3f& origin);
2440+
2441+ // ! Default destructor
2442+ ~Octree ();
2443+
2444+ /* * @brief Insert a point data to a OctreeNode.
2445+ *
2446+ * @param point The point data in Point3f format.
2447+ */
2448+ void insertPoint (const Point3f& point);
2449+
2450+ /* * @brief Read point cloud data and create OctreeNode.
2451+ *
2452+ * This function is only called when the octree is being created.
2453+ * @param pointCloud PointCloud data.
2454+ * @param maxDepth The max depth of the Octree.
2455+ * @return Returns whether the creation is successful.
2456+ */
2457+ bool create (const std::vector<Point3f> &pointCloud,int maxDepth = -1 );
2458+
2459+ /* * @brief Determine whether the point is within the space range of the specific cube.
2460+ *
2461+ * @param point The point coordinates.
2462+ * @return If point is in bound, return ture. Otherwise, false.
2463+ */
2464+ bool isPointInBound (const Point3f& point)const ;
2465+
2466+ // ! Set MaxDepth for Octree.
2467+ void setMaxDepth (int maxDepth);
2468+
2469+ // ! Set Box Size for Octree.
2470+ void setSize (double size);
2471+
2472+ // ! Set Origin coordinates for Octree.
2473+ void setOrigin (const Point3f& origin);
2474+
2475+ // ! returns true if the rootnode is NULL.
2476+ bool empty ()const ;
2477+
2478+ /* * @brief Reset all octree parameter.
2479+ *
2480+ * Clear all the nodes of the octree and initialize the parameters.
2481+ */
2482+ void clear ();
2483+
2484+ /* * @brief Delete a given point from the Octree.
2485+ *
2486+ * Delete the corresponding element from the pointList in the corresponding leaf node. If the leaf node
2487+ * does not contain other points after deletion, this node will be deleted. In the same way,
2488+ * its parent node may also be deleted if its last child is deleted.
2489+ * @param point The point coordinates.
2490+ * @return return ture if the point is deleted successfully.
2491+ */
2492+ bool deletePoint (const Point3f& point);
2493+
2494+ /* * @brief Radius Nearest Neighbor Search in Octree
2495+ *
2496+ * Search all points that are less than or equal to radius.
2497+ * And return the number of searched points.
2498+ * @param query Query point.
2499+ * @param radius Retrieved radius value.
2500+ * @param pointSet Point output. Contains searched points, and output vector is not in order.
2501+ * @param squareDistSet Dist output. Contains searched squared distance, and output vector is not in order.
2502+ * @return the number of searched points.
2503+ */
2504+ int radiusNNSearch (const Point3f& query,float radius, std::vector<Point3f> &pointSet, std::vector<float > &squareDistSet)const ;
2505+
2506+ /* * @brief K Nearest Neighbor Search in Octree.
2507+ *
2508+ * Find the K nearest neighbors to the query point.
2509+ * @param query Query point.
2510+ * @param K
2511+ * @param pointSet Point output. Contains K points, arranged in order of distance from near to far.
2512+ * @param squareDistSet Dist output. Contains K squared distance, arranged in order of distance from near to far.
2513+ */
2514+ void KNNSearch (const Point3f& query,const int K, std::vector<Point3f> &pointSet, std::vector<float > &squareDistSet)const ;
2515+
2516+ protected:
2517+ struct Impl ;
2518+ Ptr<Impl> p;
2519+
2520+ };
2521+
23772522// ! @} _3d
23782523}// end namespace cv
23792524