GDAL
cpl_quad_tree.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id$
3  *
4  * Project: CPL - Common Portability Library
5  * Purpose: Implementation of quadtree building and searching functions.
6  * Derived from shapelib and mapserver implementations
7  * Author: Frank Warmerdam, warmerdam@pobox.com
8  * Even Rouault, <even dot rouault at spatialys.com>
9  *
10  ******************************************************************************
11  * Copyright (c) 1999-2008, Frank Warmerdam
12  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included
22  * in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  ****************************************************************************/
32 
33 #ifndef CPL_QUAD_TREE_H_INCLUDED
34 #define CPL_QUAD_TREE_H_INCLUDED
35 
36 #include "cpl_port.h"
37 
38 #include <stdbool.h>
39 
52 
53 /* Types */
54 
56 typedef struct {
57  double minx;
58  double miny;
59  double maxx;
60  double maxy;
61 } CPLRectObj;
62 
64 typedef struct _CPLQuadTree CPLQuadTree;
65 
67 typedef void (*CPLQuadTreeGetBoundsFunc)(const void* hFeature, CPLRectObj* pBounds);
69 typedef void (*CPLQuadTreeGetBoundsExFunc)(const void* hFeature, void* pUserData, CPLRectObj* pBounds);
71 typedef int (*CPLQuadTreeForeachFunc)(void* pElt, void* pUserData);
73 typedef void (*CPLQuadTreeDumpFeatureFunc)(const void* hFeature, int nIndentLevel, void* pUserData);
74 
75 /* Functions */
76 
77 CPLQuadTree CPL_DLL *CPLQuadTreeCreate(const CPLRectObj* pGlobalBounds,
78  CPLQuadTreeGetBoundsFunc pfnGetBounds);
79 CPLQuadTree CPL_DLL *CPLQuadTreeCreateEx(const CPLRectObj* pGlobalBounds,
80  CPLQuadTreeGetBoundsExFunc pfnGetBounds,
81  void* pUserData);
82 void CPL_DLL CPLQuadTreeDestroy(CPLQuadTree *hQuadtree);
83 
84 void CPL_DLL CPLQuadTreeSetBucketCapacity(CPLQuadTree *hQuadtree,
85  int nBucketCapacity);
86 void CPL_DLL CPLQuadTreeForceUseOfSubNodes(CPLQuadTree *hQuadTree);
87 int CPL_DLL CPLQuadTreeGetAdvisedMaxDepth(int nExpectedFeatures);
88 void CPL_DLL CPLQuadTreeSetMaxDepth(CPLQuadTree *hQuadtree,
89  int nMaxDepth);
90 
91 void CPL_DLL CPLQuadTreeInsert(CPLQuadTree *hQuadtree,
92  void* hFeature);
93 void CPL_DLL CPLQuadTreeInsertWithBounds(CPLQuadTree *hQuadtree,
94  void* hFeature,
95  const CPLRectObj* psBounds);
96 
97 void CPL_DLL CPLQuadTreeRemove(CPLQuadTree *hQuadtree,
98  void* hFeature,
99  const CPLRectObj* psBounds);
100 
101 void CPL_DLL **CPLQuadTreeSearch(const CPLQuadTree *hQuadtree,
102  const CPLRectObj* pAoi,
103  int* pnFeatureCount);
104 
105 void CPL_DLL CPLQuadTreeForeach(const CPLQuadTree *hQuadtree,
106  CPLQuadTreeForeachFunc pfnForeach,
107  void* pUserData);
108 
109 void CPL_DLL CPLQuadTreeDump(const CPLQuadTree *hQuadtree,
110  CPLQuadTreeDumpFeatureFunc pfnDumpFeatureFunc,
111  void* pUserData);
112 void CPL_DLL CPLQuadTreeGetStats(const CPLQuadTree *hQuadtree,
113  int* pnFeatureCount,
114  int* pnNodeCount,
115  int* pnMaxDepth,
116  int* pnMaxBucketCapacity);
117 
118 CPL_C_END
119 
120 #endif
CPLQuadTreeGetAdvisedMaxDepth
int CPLQuadTreeGetAdvisedMaxDepth(int nExpectedFeatures)
Returns the optimal depth of a quadtree to hold nExpectedFeatures.
Definition: cpl_quad_tree.cpp:246
CPLQuadTreeDumpFeatureFunc
void(* CPLQuadTreeDumpFeatureFunc)(const void *hFeature, int nIndentLevel, void *pUserData)
CPLQuadTreeDumpFeatureFunc.
Definition: cpl_quad_tree.h:73
CPLQuadTreeSearch
void ** CPLQuadTreeSearch(const CPLQuadTree *hQuadtree, const CPLRectObj *pAoi, int *pnFeatureCount)
Returns all the elements inserted whose bounding box intersects the provided area of interest.
Definition: cpl_quad_tree.cpp:904
CPLQuadTreeSetBucketCapacity
void CPLQuadTreeSetBucketCapacity(CPLQuadTree *hQuadtree, int nBucketCapacity)
Set the maximum capacity of a node of a quadtree.
Definition: cpl_quad_tree.cpp:312
CPLRectObj::miny
double miny
Minimum y.
Definition: cpl_quad_tree.h:58
CPLRectObj::maxy
double maxy
Maximum y.
Definition: cpl_quad_tree.h:60
CPLQuadTreeInsertWithBounds
void CPLQuadTreeInsertWithBounds(CPLQuadTree *hQuadtree, void *hFeature, const CPLRectObj *psBounds)
Insert a feature into a quadtree.
Definition: cpl_quad_tree.cpp:374
CPLQuadTree
struct _CPLQuadTree CPLQuadTree
Opaque type for a quad tree.
Definition: cpl_quad_tree.h:64
CPLQuadTreeInsert
void CPLQuadTreeInsert(CPLQuadTree *hQuadtree, void *hFeature)
Insert a feature into a quadtree.
Definition: cpl_quad_tree.cpp:346
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:304
CPLRectObj::maxx
double maxx
Maximum x.
Definition: cpl_quad_tree.h:59
CPLQuadTreeForeach
void CPLQuadTreeForeach(const CPLQuadTree *hQuadtree, CPLQuadTreeForeachFunc pfnForeach, void *pUserData)
Walk through the quadtree and runs the provided function on all the elements.
Definition: cpl_quad_tree.cpp:969
CPLQuadTreeDump
void CPLQuadTreeDump(const CPLQuadTree *hQuadtree, CPLQuadTreeDumpFeatureFunc pfnDumpFeatureFunc, void *pUserData)
Dump quad tree.
Definition: cpl_quad_tree.cpp:1034
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:306
CPLQuadTreeCreate
CPLQuadTree * CPLQuadTreeCreate(const CPLRectObj *pGlobalBounds, CPLQuadTreeGetBoundsFunc pfnGetBounds)
Create a new quadtree.
Definition: cpl_quad_tree.cpp:153
CPLRectObj
Describe a rectangle.
Definition: cpl_quad_tree.h:56
CPLQuadTreeRemove
void CPLQuadTreeRemove(CPLQuadTree *hQuadtree, void *hFeature, const CPLRectObj *psBounds)
Remove a feature from a quadtree.
Definition: cpl_quad_tree.cpp:460
CPLRectObj::minx
double minx
Minimum x.
Definition: cpl_quad_tree.h:57
CPLQuadTreeForceUseOfSubNodes
void CPLQuadTreeForceUseOfSubNodes(CPLQuadTree *hQuadTree)
Force the quadtree to insert as much as possible a feature whose bbox spread over multiple subnodes i...
Definition: cpl_quad_tree.cpp:330
cpl_port.h
CPLQuadTreeForeachFunc
int(* CPLQuadTreeForeachFunc)(void *pElt, void *pUserData)
CPLQuadTreeForeachFunc.
Definition: cpl_quad_tree.h:71
CPLQuadTreeDestroy
void CPLQuadTreeDestroy(CPLQuadTree *hQuadtree)
Destroy a quadtree.
Definition: cpl_quad_tree.cpp:516
CPLQuadTreeCreateEx
CPLQuadTree * CPLQuadTreeCreateEx(const CPLRectObj *pGlobalBounds, CPLQuadTreeGetBoundsExFunc pfnGetBounds, void *pUserData)
Create a new quadtree.
Definition: cpl_quad_tree.cpp:202
CPLQuadTreeSetMaxDepth
void CPLQuadTreeSetMaxDepth(CPLQuadTree *hQuadtree, int nMaxDepth)
Set the maximum depth of a quadtree.
Definition: cpl_quad_tree.cpp:294
CPLQuadTreeGetBoundsExFunc
void(* CPLQuadTreeGetBoundsExFunc)(const void *hFeature, void *pUserData, CPLRectObj *pBounds)
CPLQuadTreeGetBoundsExFunc.
Definition: cpl_quad_tree.h:69
CPLQuadTreeGetStats
void CPLQuadTreeGetStats(const CPLQuadTree *hQuadtree, int *pnFeatureCount, int *pnNodeCount, int *pnMaxDepth, int *pnMaxBucketCapacity)
Get stats.
Definition: cpl_quad_tree.cpp:1070
CPLQuadTreeGetBoundsFunc
void(* CPLQuadTreeGetBoundsFunc)(const void *hFeature, CPLRectObj *pBounds)
CPLQuadTreeGetBoundsFunc.
Definition: cpl_quad_tree.h:67