{"id":5011,"date":"2021-01-31T12:54:31","date_gmt":"2021-01-31T04:54:31","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=5011"},"modified":"2021-01-31T12:54:31","modified_gmt":"2021-01-31T04:54:31","slug":"%e5%9b%9b%e5%8f%89%e6%a0%91%e7%a9%ba%e9%97%b4%e7%b4%a2%e5%bc%95%e5%8e%9f%e7%90%86%e5%8f%8a%e5%85%b6%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5011","title":{"rendered":"\u56db\u53c9\u6811\u7a7a\u95f4\u7d22\u5f15\u539f\u7406\u53ca\u5176\u5b9e\u73b0"},"content":{"rendered":"<h1 style=\"font-weight: 600;\"><a href=\"https:\/\/blog.csdn.net\/zhouxuguang236\/article\/details\/12312099\">\u539f\u6587\u5730\u5740<\/a><\/h1>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/blog.csdn.net\/zhouxuguang236\">\u5468\u65ed\u5149<\/a>\u00a02013-10-05 15:59:19\u00a0\u00a086366\u00a0\u00a0\u6536\u85cf\u00a044<\/p>\n<p>\u5206\u7c7b\u4e13\u680f\uff1a\u00a0<a href=\"https:\/\/blog.csdn.net\/zhouxuguang236\/category_1273506.html\">GIS\u5e95\u5c42\u5f00\u53d1<\/a>\u00a0<a href=\"https:\/\/blog.csdn.net\/zhouxuguang236\/category_9261716.html\">GIS\u5e95\u5c42\u5f00\u53d1<\/a><\/p>\n<p>\u7248\u6743<\/p>\n<p style=\"font-weight: 400;\">\u4eca\u5929\u4f9d\u7136\u5728\u653e\u5047\u4e2d\uff0c\u5728\u6b64\u5c06\u4ee5\u524d\u5728\u5b66\u6821\u5199\u7684\u56db\u53c9\u6811\u7684\u4e1c\u897f\u62ff\u51fa\u6765\u548c\u5927\u5bb6\u5206\u4eab\u3002<\/p>\n<p style=\"font-weight: 400;\">\u56db\u53c9\u6811\u7d22\u5f15\u7684\u57fa\u672c\u601d\u60f3\u662f\u5c06\u5730\u7406\u7a7a\u95f4\u9012\u5f52\u5212\u5206\u4e3a\u4e0d\u540c\u5c42\u6b21\u7684\u6811\u7ed3\u6784\u3002\u5b83\u5c06\u5df2\u77e5\u8303\u56f4\u7684\u7a7a\u95f4\u7b49\u5206\u6210\u56db\u4e2a\u76f8\u7b49\u7684\u5b50\u7a7a\u95f4\uff0c\u5982\u6b64\u9012\u5f52\u4e0b\u53bb\uff0c\u76f4\u81f3\u6811\u7684\u5c42\u6b21\u8fbe\u5230\u4e00\u5b9a\u6df1\u5ea6\u6216\u8005\u6ee1\u8db3\u67d0\u79cd\u8981\u6c42\u540e\u505c\u6b62\u5206\u5272\u3002\u56db\u53c9\u6811\u7684\u7ed3\u6784\u6bd4\u8f83\u7b80\u5355\uff0c\u5e76\u4e14\u5f53\u7a7a\u95f4\u6570\u636e\u5bf9\u8c61\u5206\u5e03\u6bd4\u8f83\u5747\u5300\u65f6\uff0c\u5177\u6709\u6bd4\u8f83\u9ad8\u7684\u7a7a\u95f4\u6570\u636e\u63d2\u5165\u548c\u67e5\u8be2\u6548\u7387\uff0c\u56e0\u6b64\u56db\u53c9\u6811\u662f<i>GIS<\/i>\u4e2d\u5e38\u7528\u7684\u7a7a\u95f4\u7d22\u5f15\u4e4b\u4e00\u3002\u5e38\u89c4\u56db\u53c9\u6811\u7684\u7ed3\u6784\u5982\u56fe\u6240\u793a\uff0c\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u90fd\u5b58\u50a8\u5728\u53f6\u5b50\u8282\u70b9\u4e0a\uff0c\u4e2d\u95f4\u8282\u70b9\u4ee5\u53ca\u6839\u8282\u70b9\u4e0d\u5b58\u50a8\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0<\/i><\/p>\n<p style=\"font-weight: 400;\">\u56db\u53c9\u6811\u793a\u610f\u56fe<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0<\/i><\/p>\n<p style=\"font-weight: 400;\">\u56db\u53c9\u6811\u5bf9\u4e8e\u533a\u57df\u67e5\u8be2\uff0c\u6548\u7387\u6bd4\u8f83\u9ad8\u3002\u4f46\u5982\u679c\u7a7a\u95f4\u5bf9\u8c61\u5206\u5e03\u4e0d\u5747\u5300\uff0c\u968f\u7740\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u7684\u4e0d\u65ad\u63d2\u5165\uff0c\u56db\u53c9\u6811\u7684\u5c42\u6b21\u4f1a\u4e0d\u65ad\u5730\u52a0\u6df1\uff0c\u5c06\u5f62\u6210\u4e00\u68f5\u4e25\u91cd\u4e0d\u5e73\u8861\u7684\u56db\u53c9\u6811\uff0c\u90a3\u4e48\u6bcf\u6b21\u67e5\u8be2\u7684\u6df1\u5ea6\u5c06\u5927\u5927\u7684\u589e\u591a\uff0c\u4ece\u800c\u5bfc\u81f4\u67e5\u8be2\u6548\u7387\u7684\u6025\u5267\u4e0b\u964d\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0<\/i><\/p>\n<p style=\"font-weight: 400;\">\u672c\u8282\u5c06\u4ecb\u7ecd\u4e00\u79cd\u6539\u8fdb\u7684\u56db\u53c9\u6811\u7d22\u5f15\u7ed3\u6784\u3002\u56db\u53c9\u6811\u7ed3\u6784\u662f\u81ea\u9876\u5411\u4e0b\u9010\u6b65\u5212\u5206\u7684\u4e00\u79cd\u6811\u72b6\u7684\u5c42\u6b21\u7ed3\u6784\u3002\u4f20\u7edf\u7684\u56db\u53c9\u6811\u7d22\u5f15\u5b58\u5728\u7740\u4ee5\u4e0b\u51e0\u4e2a\u7f3a\u70b9\uff1a<\/p>\n<p style=\"font-weight: 400;\"><i>(1)<\/i>\u7a7a\u95f4\u5b9e\u4f53\u53ea\u80fd\u5b58\u50a8\u5728\u53f6\u5b50\u8282\u70b9\u4e2d\uff0c\u4e2d\u95f4\u8282\u70b9\u4ee5\u53ca\u6839\u8282\u70b9\u4e0d\u80fd\u5b58\u50a8\u7a7a\u95f4\u5b9e\u4f53\u4fe1\u606f\uff0c\u968f\u7740\u7a7a\u95f4\u5bf9\u8c61\u7684\u4e0d\u65ad\u63d2\u5165\uff0c\u6700\u7ec8\u4f1a\u5bfc\u81f4\u56db\u53c9\u6811\u6811\u7684\u5c42\u6b21\u6bd4\u8f83\u6df1\uff0c\u5728\u8fdb\u884c\u7a7a\u95f4\u6570\u636e\u7a97\u53e3\u67e5\u8be2\u7684\u65f6\u5019\u6548\u7387\u4f1a\u6bd4\u8f83\u4f4e\u4e0b\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>(2)<\/i>\u540c\u4e00\u4e2a\u5730\u7406\u5b9e\u4f53\u5728\u56db\u53c9\u6811\u7684\u5206\u88c2\u8fc7\u7a0b\u4e2d\u6781\u6709\u53ef\u80fd\u5b58\u50a8\u5728\u591a\u4e2a\u8282\u70b9\u4e2d\uff0c\u8fd9\u6837\u5c31\u5bfc\u81f4\u4e86\u7d22\u5f15\u5b58\u50a8\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>(3)<\/i>\u7531\u4e8e\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u53ef\u80fd\u5206\u5e03\u4e0d\u5747\u8861\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u5e38\u89c4\u56db\u53c9\u6811\u751f\u6210\u4e00\u68f5\u6781\u4e3a\u4e0d\u5e73\u8861\u7684\u6811\uff0c\u8fd9\u6837\u4e5f\u4f1a\u9020\u6210\u6811\u7ed3\u6784\u7684\u4e0d\u5e73\u8861\u4ee5\u53ca\u5b58\u50a8\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002<\/p>\n<p style=\"font-weight: 400;\">\u76f8\u5e94\u7684\u6539\u8fdb\u65b9\u6cd5\uff0c\u5c06\u5730\u7406\u5b9e\u4f53\u4fe1\u606f\u5b58\u50a8\u5728\u5b8c\u5168\u5305\u542b\u5b83\u7684\u6700\u5c0f\u77e9\u5f62\u8282\u70b9\u4e2d\uff0c\u4e0d\u5b58\u50a8\u5728\u5b83\u7684\u7236\u8282\u70b9\u4e2d\uff0c\u6bcf\u4e2a\u5730\u7406\u5b9e\u4f53\u53ea\u5728\u6811\u4e2d\u5b58\u50a8\u4e00\u6b21\uff0c\u907f\u514d\u5b58\u50a8\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002\u9996\u5148\u751f\u6210\u6ee1\u56db\u53c9\u6811\uff0c\u907f\u514d\u5728\u5730\u7406\u5b9e\u4f53\u63d2\u5165\u65f6\u9700\u8981\u91cd\u65b0\u5206\u914d\u5185\u5b58\uff0c\u52a0\u5feb\u63d2\u5165\u7684\u901f\u5ea6\uff0c\u6700\u540e\u5c06\u7a7a\u7684\u8282\u70b9\u6240\u5360\u5185\u5b58\u7a7a\u95f4\u91ca\u653e\u6389\u3002\u6539\u8fdb\u540e\u7684\u56db\u53c9\u6811\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\u3002\u56db\u53c9\u6811\u7684\u6df1\u5ea6\u4e00\u822c\u53d6\u7ecf\u9a8c\u503c<i>4-7<\/i>\u4e4b\u95f4\u4e3a\u6700\u4f73\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0<\/i><\/p>\n<p style=\"font-weight: 400;\">\u56fe\u6539\u8fdb\u7684\u56db\u53c9\u6811\u7ed3\u6784<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0<\/i><\/p>\n<p style=\"font-weight: 400;\">\u4e3a\u4e86\u7ef4\u62a4\u7a7a\u95f4\u7d22\u5f15\u4e0e\u5bf9\u5b58\u50a8\u5728\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u7684\u7a7a\u95f4\u6570\u636e\u7684\u4e00\u81f4\u6027\uff0c\u4f5c\u8005\u8bbe\u8ba1\u4e86\u5982\u4e0b\u7684\u6570\u636e\u7ed3\u6784\u652f\u6301\u56db\u53c9\u6811\u7684\u64cd\u4f5c\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>(1)<\/i>\u56db\u5206\u533a\u57df\u6807\u8bc6<\/p>\n<p style=\"font-weight: 400;\">\u5206\u522b\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5e73\u9762\u533a\u57df\u7684\u56db\u4e2a\u5b50\u533a\u57df\u7d22\u5f15\u53f7\uff0c\u53f3\u4e0a\u4e3a\u7b2c\u4e00\u8c61\u9650<i>0<\/i>\uff0c\u5de6\u4e0a\u4e3a\u7b2c\u4e8c\u8c61\u9650<i>1<\/i>\uff0c\u5de6\u4e0b\u4e3a\u7b2c\u4e09\u8c61\u9650<i>2<\/i>\uff0c\u53f3\u4e0b\u4e3a\u7b2c\u56db\u8c61\u9650<i>3<\/i>\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>typedef enum<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>{<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0UR = 0,\/\/ UR<\/i>\u7b2c\u4e00\u8c61\u9650<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0UL = 1,\u00a0\/\/ UL<\/i>\u4e3a\u7b2c\u4e8c\u8c61\u9650<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LL = 2,\u00a0\/\/ LL<\/i>\u4e3a\u7b2c\u4e09\u8c61\u9650<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LR = 3\u00a0\u00a0\/\/ LR<\/i>\u4e3a\u7b2c\u56db\u8c61\u9650<\/p>\n<p style=\"font-weight: 400;\"><i>}QuadrantEnum;<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>(2)<\/i>\u7a7a\u95f4\u5bf9\u8c61\u6570\u636e\u7ed3\u6784<\/p>\n<p style=\"font-weight: 400;\">\u7a7a\u95f4\u5bf9\u8c61\u6570\u636e\u7ed3\u6784\u662f\u5bf9\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u7684\u8fd1\u4f3c\uff0c\u5728\u7a7a\u95f4\u7d22\u5f15\u4e2d\uff0c\u76f8\u5f53\u4e00\u90e8\u5206\u90fd\u662f\u91c7\u7528<i>MBR<\/i>\u4f5c\u4e3a\u8fd1\u4f3c\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>\/*<\/i>\u7a7a\u95f4\u5bf9\u8c61<i>MBR<\/i>\u4fe1\u606f<i>*\/<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>typedef struct SHPMBRInfo<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>{<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int nID;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u7a7a\u95f4\u5bf9\u8c61<i>ID<\/i>\u53f7<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MapRect Box;\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u7a7a\u95f4\u5bf9\u8c61<i>MBR<\/i>\u8303\u56f4\u5750\u6807<\/p>\n<p style=\"font-weight: 400;\"><i>}SHPMBRInfo;<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>nID<\/i>\u662f\u7a7a\u95f4\u5bf9\u8c61\u7684\u6807\u8bc6\u53f7\uff0c<i>Box<\/i>\u662f\u7a7a\u95f4\u5bf9\u8c61\u7684\u6700\u5c0f\u5916\u5305\u77e9\u5f62\uff08<i>MBR<\/i>\uff09\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>(3)<\/i>\u56db\u53c9\u6811\u8282\u70b9\u6570\u636e\u7ed3\u6784<\/p>\n<p style=\"font-weight: 400;\">\u56db\u53c9\u6811\u8282\u70b9\u662f\u56db\u53c9\u6811\u7ed3\u6784\u7684\u4e3b\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u4e3b\u8981\u7528\u4e8e\u5b58\u50a8\u7a7a\u95f4\u5bf9\u8c61\u7684\u6807\u8bc6\u53f7\u548c<i>MBR<\/i>\uff0c\u4e5f\u662f\u56db\u53c9\u6811\u7b97\u6cd5\u64cd\u4f5c\u7684\u4e3b\u8981\u90e8\u5206\u3002<\/p>\n<p style=\"font-weight: 400;\"><i>\/*<\/i>\u56db\u53c9\u6811\u8282\u70b9\u7c7b\u578b\u7ed3\u6784<i>*\/<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>typedef struct QuadNode<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>{<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0MapRect\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Box;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u8282\u70b9\u6240\u4ee3\u8868\u7684\u77e9\u5f62\u533a\u57df<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nShpCount;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u8282\u70b9\u6240\u5305\u542b\u7684\u6240\u6709\u7a7a\u95f4\u5bf9\u8c61\u4e2a\u6570<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SHPMBRInfo* pShapeObj;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u7a7a\u95f4\u5bf9\u8c61\u6307\u9488\u6570\u7ec4<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0nChildCount;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u5b50\u8282\u70b9\u4e2a\u6570<\/p>\n<p style=\"font-weight: 400;\"><i>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0QuadNode\u00a0*children[4];\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/<\/i>\u6307\u5411\u8282\u70b9\u7684\u56db\u4e2a\u5b69\u5b50<\/p>\n<p style=\"font-weight: 400;\"><i>}QuadNode;<\/i><\/p>\n<p style=\"font-weight: 400;\"><i>Box<\/i>\u662f\u4ee3\u8868\u56db\u53c9\u6811\u5bf9\u5e94\u533a\u57df\u7684\u6700\u5c0f\u5916\u5305\u77e9\u5f62\uff0c\u4e0a\u4e00\u5c42\u7684\u8282\u70b9\u7684\u6700\u5c0f\u5916\u5305\u77e9\u5f62\u5305\u542b\u4e0b\u4e00\u5c42\u6700\u5c0f\u5916\u5305\u77e9\u5f62\u533a\u57df\uff1b<i>nShpCount<\/i>\u4ee3\u8868\u672c\u8282\u70b9\u5305\u542b\u7684\u7a7a\u95f4\u5bf9\u8c61\u7684\u4e2a\u6570\uff1b<i>pShapeObj<\/i>\u4ee3\u8868\u6307\u5411\u7a7a\u95f4\u5bf9\u8c61\u5b58\u50a8\u5730\u5740\u7684\u9996\u5730\u5740\uff0c\u540c\u4e00\u4e2a\u8282\u70b9\u7684\u7a7a\u95f4\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u8fde\u7eed\u5b58\u50a8\uff1b<i>nChildCount<\/i>\u4ee3\u8868\u8282\u70b9\u62e5\u6709\u7684\u5b50\u8282\u70b9\u7684\u6570\u76ee\uff1b<i>children<\/i>\u662f\u6307\u5411\u5b69\u5b50\u8282\u70b9\u6307\u9488\u7684\u6570\u7ec4\u3002<\/p>\n<p style=\"font-weight: 400;\">\u4e0a\u8ff0\u7406\u8bba\u90e8\u5206\u90fd\u90fd\u8bb2\u7684\u5dee\u4e0d\u591a\u4e86\uff0c\u4e0b\u9762\u5c31\u8d34\u4e0a\u6211\u7684C\u8bed\u8a00\u5b9e\u73b0\u7248\u672c\u4ee3\u7801\u3002<\/p>\n<p style=\"font-weight: 400;\">\u5934\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>#ifndef __QUADTREE_H_59CAE94A_E937_42AD_AA27_794E467715BB__<\/li>\n<li>#define __QUADTREE_H_59CAE94A_E937_42AD_AA27_794E467715BB__<\/li>\n<li><i>\/* \u4e00\u4e2a\u77e9\u5f62\u533a\u57df\u7684\u8c61\u9650\u5212\u5206\uff1a:<\/i><\/li>\n<li><i>UL(1) | UR(0)<\/i><\/li>\n<li><i>&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;&#8211;<\/i><\/li>\n<li><i>LL(2) | LR(3)<\/i><\/li>\n<li><i>\u4ee5\u4e0b\u5bf9\u8be5\u8c61\u9650\u7c7b\u578b\u7684\u679a\u4e3e<\/i><\/li>\n<li><i>*\/<\/i><\/li>\n<li>typedef enum<\/li>\n<li>{<\/li>\n<li>UR = 0,<\/li>\n<li>UL = 1,<\/li>\n<li>LL = 2,<\/li>\n<li>LR = 3<\/li>\n<li>}QuadrantEnum;<\/li>\n<li><i>\/*\u7a7a\u95f4\u5bf9\u8c61MBR\u4fe1\u606f*\/<\/i><\/li>\n<li>typedef struct SHPMBRInfo<\/li>\n<li>{<\/li>\n<li>int nID; <i>\/\/\u7a7a\u95f4\u5bf9\u8c61ID\u53f7<\/i><\/li>\n<li>MapRect Box; <i>\/\/\u7a7a\u95f4\u5bf9\u8c61MBR\u8303\u56f4\u5750\u6807<\/i><\/li>\n<li>}SHPMBRInfo;<\/li>\n<li><i>\/* \u56db\u53c9\u6811\u8282\u70b9\u7c7b\u578b\u7ed3\u6784 *\/<\/i><\/li>\n<li>typedef struct QuadNode<\/li>\n<li>{<\/li>\n<li>MapRect Box; <i>\/\/\u8282\u70b9\u6240\u4ee3\u8868\u7684\u77e9\u5f62\u533a\u57df<\/i><\/li>\n<li>int nShpCount; <i>\/\/\u8282\u70b9\u6240\u5305\u542b\u7684\u6240\u6709\u7a7a\u95f4\u5bf9\u8c61\u4e2a\u6570<\/i><\/li>\n<li>SHPMBRInfo* pShapeObj; <i>\/\/\u7a7a\u95f4\u5bf9\u8c61\u6307\u9488\u6570\u7ec4<\/i><\/li>\n<li>int nChildCount; <i>\/\/\u5b50\u8282\u70b9\u4e2a\u6570<\/i><\/li>\n<li>QuadNode *children[4]; <i>\/\/\u6307\u5411\u8282\u70b9\u7684\u56db\u4e2a\u5b69\u5b50 <\/i><\/li>\n<li>}QuadNode;<\/li>\n<li><i>\/* \u56db\u53c9\u6811\u7c7b\u578b\u7ed3\u6784 *\/<\/i><\/li>\n<li>typedef struct quadtree_t<\/li>\n<li>{<\/li>\n<li>QuadNode *root;<\/li>\n<li>int depth; <i>\/\/ \u56db\u53c9\u6811\u7684\u6df1\u5ea6 <\/i><\/li>\n<li>}QuadTree;<\/li>\n<li><i>\/\/\u521d\u59cb\u5316\u56db\u53c9\u6811\u8282\u70b9<\/i><\/li>\n<li>QuadNode *InitQuadNode();<\/li>\n<li><i>\/\/\u5c42\u6b21\u521b\u5efa\u56db\u53c9\u6811\u65b9\u6cd5\uff08\u6ee1\u56db\u53c9\u6811\uff09<\/i><\/li>\n<li>void CreateQuadTree(int depth,GeoLayer *poLayer,QuadTree* pQuadTree);<\/li>\n<li><i>\/\/\u521b\u5efa\u5404\u4e2a\u5206\u652f<\/i><\/li>\n<li>void CreateQuadBranch(int depth,MapRect &amp;rect,QuadNode** node);<\/li>\n<li><i>\/\/\u6784\u5efa\u56db\u53c9\u6811\u7a7a\u95f4\u7d22\u5f15<\/i><\/li>\n<li>void BuildQuadTree(GeoLayer*poLayer,QuadTree* pQuadTree);<\/li>\n<li><i>\/\/\u56db\u53c9\u6811\u7d22\u5f15\u67e5\u8be2(\u77e9\u5f62\u67e5\u8be2)<\/i><\/li>\n<li>void SearchQuadTree(QuadNode* node,MapRect &amp;queryRect,vector&lt;int&gt;&amp; ItemSearched);<\/li>\n<li><i>\/\/\u56db\u53c9\u6811\u7d22\u5f15\u67e5\u8be2(\u77e9\u5f62\u67e5\u8be2)\u5e76\u884c\u67e5\u8be2<\/i><\/li>\n<li>void SearchQuadTreePara(vector&lt;QuadNode*&gt; resNodes,MapRect &amp;queryRect,vector&lt;int&gt;&amp; ItemSearched);<\/li>\n<li><i>\/\/\u56db\u53c9\u6811\u7684\u67e5\u8be2\uff08\u70b9\u67e5\u8be2\uff09<\/i><\/li>\n<li>void PtSearchQTree(QuadNode* node,double cx,double cy,vector&lt;int&gt;&amp; ItemSearched);<\/li>\n<li><i>\/\/\u5c06\u6307\u5b9a\u7684\u7a7a\u95f4\u5bf9\u8c61\u63d2\u5165\u5230\u56db\u53c9\u6811\u4e2d<\/i><\/li>\n<li>void Insert(long key,MapRect &amp;itemRect,QuadNode* pNode);<\/li>\n<li><i>\/\/\u5c06\u6307\u5b9a\u7684\u7a7a\u95f4\u5bf9\u8c61\u63d2\u5165\u5230\u56db\u53c9\u6811\u4e2d<\/i><\/li>\n<li>void InsertQuad(long key,MapRect &amp;itemRect,QuadNode* pNode);<\/li>\n<li><i>\/\/\u5c06\u6307\u5b9a\u7684\u7a7a\u95f4\u5bf9\u8c61\u63d2\u5165\u5230\u56db\u53c9\u6811\u4e2d<\/i><\/li>\n<li>void InsertQuad2(long key,MapRect &amp;itemRect,QuadNode* pNode);<\/li>\n<li><i>\/\/\u5224\u65ad\u4e00\u4e2a\u8282\u70b9\u662f\u5426\u662f\u53f6\u5b50\u8282\u70b9<\/i><\/li>\n<li>bool IsQuadLeaf(QuadNode* node);<\/li>\n<li><i>\/\/\u5220\u9664\u591a\u4f59\u7684\u8282\u70b9<\/i><\/li>\n<li>bool DelFalseNode(QuadNode* node);<\/li>\n<li><i>\/\/\u56db\u53c9\u6811\u904d\u5386(\u6240\u6709\u8981\u7d20)<\/i><\/li>\n<li>void TraversalQuadTree(QuadNode* quadTree,vector&lt;int&gt;&amp; resVec);<\/li>\n<li><i>\/\/\u56db\u53c9\u6811\u904d\u5386\uff08\u6240\u6709\u8282\u70b9\uff09<\/i><\/li>\n<li>void TraversalQuadTree(QuadNode* quadTree,vector&lt;QuadNode*&gt;&amp; arrNode);<\/li>\n<li><i>\/\/\u91ca\u653e\u6811\u7684\u5185\u5b58\u7a7a\u95f4<\/i><\/li>\n<li>void ReleaseQuadTree(QuadNode** quadTree);<\/li>\n<li><i>\/\/\u8ba1\u7b97\u56db\u53c9\u6811\u6240\u5360\u7684\u5b57\u8282\u7684\u5927\u5c0f<\/i><\/li>\n<li>long CalByteQuadTree(QuadNode* quadTree,long&amp; nSize);<\/li>\n<li>#endif<\/li>\n<\/ol>\n<p style=\"font-weight: 400;\">\n\u6e90\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>#include &#8220;QuadTree.h&#8221;<\/li>\n<li>QuadNode *InitQuadNode()<\/li>\n<li>{<\/li>\n<li>QuadNode *node = new QuadNode;<\/li>\n<li>node-&gt;Box.maxX = 0;<\/li>\n<li>node-&gt;Box.maxY = 0;<\/li>\n<li>node-&gt;Box.minX = 0;<\/li>\n<li>node-&gt;Box.minY = 0;<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>node-&gt;children[i] = NULL;<\/li>\n<li>}<\/li>\n<li>node-&gt;nChildCount = 0;<\/li>\n<li>node-&gt;nShpCount = 0;<\/li>\n<li>node-&gt;pShapeObj = NULL;<\/li>\n<li>return node;<\/li>\n<li>}<\/li>\n<li>void CreateQuadTree(int depth,GeoLayer *poLayer,QuadTree* pQuadTree)<\/li>\n<li>{<\/li>\n<li>pQuadTree-&gt;depth = depth;<\/li>\n<li>GeoEnvelope env; <i>\/\/\u6574\u4e2a\u56fe\u5c42\u7684MBR<\/i><\/li>\n<li>poLayer-&gt;GetExtent(&amp;env);<\/li>\n<li>MapRect rect;<\/li>\n<li>rect.minX = env.MinX;<\/li>\n<li>rect.minY = env.MinY;<\/li>\n<li>rect.maxX = env.MaxX;<\/li>\n<li>rect.maxY = env.MaxY;<\/li>\n<li><i>\/\/\u521b\u5efa\u5404\u4e2a\u5206\u652f<\/i><\/li>\n<li>CreateQuadBranch(depth,rect,&amp;(pQuadTree-&gt;root));<\/li>\n<li>int nCount = poLayer-&gt;GetFeatureCount();<\/li>\n<li>GeoFeature **pFeatureClass = new GeoFeature*[nCount];<\/li>\n<li>for (int i = 0; i &lt; poLayer-&gt;GetFeatureCount(); i ++)<\/li>\n<li>{<\/li>\n<li>pFeatureClass[i] = poLayer-&gt;GetFeature(i);<\/li>\n<li>}<\/li>\n<li><i>\/\/\u63d2\u5165\u5404\u4e2a\u8981\u7d20<\/i><\/li>\n<li>GeoEnvelope envObj; <i>\/\/\u7a7a\u95f4\u5bf9\u8c61\u7684MBR<\/i><\/li>\n<li><i>\/\/#pragma omp parallel for<\/i><\/li>\n<li>for (int i = 0; i &lt; nCount; i ++)<\/li>\n<li>{<\/li>\n<li>pFeatureClass[i]-&gt;GetGeometry()-&gt;getEnvelope(&amp;envObj);<\/li>\n<li>rect.minX = envObj.MinX;<\/li>\n<li>rect.minY = envObj.MinY;<\/li>\n<li>rect.maxX = envObj.MaxX;<\/li>\n<li>rect.maxY = envObj.MaxY;<\/li>\n<li>InsertQuad(i,rect,pQuadTree-&gt;root);<\/li>\n<li>}<\/li>\n<li><i>\/\/DelFalseNode(pQuadTree-&gt;root);<\/i><\/li>\n<li>}<\/li>\n<li>void CreateQuadBranch(int depth,MapRect &amp;rect,QuadNode** node)<\/li>\n<li>{<\/li>\n<li>if (depth != 0)<\/li>\n<li>{<\/li>\n<li>*node = InitQuadNode(); <i>\/\/\u521b\u5efa\u6811\u6839<\/i><\/li>\n<li>QuadNode *pNode = *node;<\/li>\n<li>pNode-&gt;Box = rect;<\/li>\n<li>pNode-&gt;nChildCount = 4;<\/li>\n<li>MapRect boxs[4];<\/li>\n<li>pNode-&gt;Box.Split(boxs,boxs+1,boxs+2,boxs+3);<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u521b\u5efa\u56db\u4e2a\u8282\u70b9\u5e76\u63d2\u5165\u76f8\u5e94\u7684MBR<\/i><\/li>\n<li>pNode-&gt;children[i] = InitQuadNode();<\/li>\n<li>pNode-&gt;children[i]-&gt;Box = boxs[i];<\/li>\n<li>CreateQuadBranch(depth-1,boxs[i],&amp;(pNode-&gt;children[i]));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>void BuildQuadTree(GeoLayer *poLayer,QuadTree* pQuadTree)<\/li>\n<li>{<\/li>\n<li>assert(poLayer);<\/li>\n<li>GeoEnvelope env; <i>\/\/\u6574\u4e2a\u56fe\u5c42\u7684MBR<\/i><\/li>\n<li>poLayer-&gt;GetExtent(&amp;env);<\/li>\n<li>pQuadTree-&gt;root = InitQuadNode();<\/li>\n<li>QuadNode* rootNode = pQuadTree-&gt;root;<\/li>\n<li>rootNode-&gt;Box.minX = env.MinX;<\/li>\n<li>rootNode-&gt;Box.minY = env.MinY;<\/li>\n<li>rootNode-&gt;Box.maxX = env.MaxX;<\/li>\n<li>rootNode-&gt;Box.maxY = env.MaxY;<\/li>\n<li><i>\/\/\u8bbe\u7f6e\u6811\u7684\u6df1\u5ea6( \u6839\u636e\u7b49\u6bd4\u6570\u5217\u7684\u6c42\u548c\u516c\u5f0f)<\/i><\/li>\n<li><i>\/\/pQuadTree-&gt;depth = log(poLayer-&gt;GetFeatureCount()*3\/8.0+1)\/log(4.0);<\/i><\/li>\n<li>int nCount = poLayer-&gt;GetFeatureCount();<\/li>\n<li>MapRect rect;<\/li>\n<li>GeoEnvelope envObj; <i>\/\/\u7a7a\u95f4\u5bf9\u8c61\u7684MBR<\/i><\/li>\n<li>for (int i = 0; i &lt; nCount; i ++)<\/li>\n<li>{<\/li>\n<li>poLayer-&gt;GetFeature(i)-&gt;GetGeometry()-&gt;getEnvelope(&amp;envObj);<\/li>\n<li>rect.minX = envObj.MinX;<\/li>\n<li>rect.minY = envObj.MinY;<\/li>\n<li>rect.maxX = envObj.MaxX;<\/li>\n<li>rect.maxY = envObj.MaxY;<\/li>\n<li>InsertQuad2(i,rect,rootNode);<\/li>\n<li>}<\/li>\n<li>DelFalseNode(pQuadTree-&gt;root);<\/li>\n<li>}<\/li>\n<li>void SearchQuadTree(QuadNode* node,MapRect &amp;queryRect,vector&lt;int&gt;&amp; ItemSearched)<\/li>\n<li>{<\/li>\n<li>assert(node);<\/li>\n<li><i>\/\/int coreNum = omp_get_num_procs();<\/i><\/li>\n<li><i>\/\/vector&lt;int&gt; * pResArr = new vector&lt;int&gt;[coreNum];<\/i><\/li>\n<li>if (NULL != node)<\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; node-&gt;nShpCount; i ++)<\/li>\n<li>{<\/li>\n<li>if (queryRect.Contains(node-&gt;pShapeObj[i].Box)<\/li>\n<li>|| queryRect.Intersects(node-&gt;pShapeObj[i].Box))<\/li>\n<li>{<\/li>\n<li>ItemSearched.push_back(node-&gt;pShapeObj[i].nID);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5e76\u884c\u641c\u7d22\u56db\u4e2a\u5b69\u5b50\u8282\u70b9<\/i><\/li>\n<li><i>\/*#pragma omp parallel sections<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> #pragma omp section<\/i><\/li>\n<li><i> if ((node-&gt;children[0] != NULL) &amp;&amp; <\/i><\/li>\n<li><i> (node-&gt;children[0]-&gt;Box.Contains(queryRect)<\/i><\/li>\n<li><i> || node-&gt;children[0]-&gt;Box.Intersects(queryRect)))<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> int tid = omp_get_thread_num();<\/i><\/li>\n<li><i> SearchQuadTree(node-&gt;children[0],queryRect,pResArr[tid]);<\/i><\/li>\n<li><i> }<\/i><\/li>\n<li><i> #pragma omp section<\/i><\/li>\n<li><i> if ((node-&gt;children[1] != NULL) &amp;&amp; <\/i><\/li>\n<li><i> (node-&gt;children[1]-&gt;Box.Contains(queryRect)<\/i><\/li>\n<li><i> || node-&gt;children[1]-&gt;Box.Intersects(queryRect)))<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> int tid = omp_get_thread_num();<\/i><\/li>\n<li><i> SearchQuadTree(node-&gt;children[1],queryRect,pResArr[tid]);<\/i><\/li>\n<li><i> }<\/i><\/li>\n<li><i> #pragma omp section<\/i><\/li>\n<li><i> if ((node-&gt;children[2] != NULL) &amp;&amp; <\/i><\/li>\n<li><i> (node-&gt;children[2]-&gt;Box.Contains(queryRect)<\/i><\/li>\n<li><i> || node-&gt;children[2]-&gt;Box.Intersects(queryRect)))<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> int tid = omp_get_thread_num();<\/i><\/li>\n<li><i> SearchQuadTree(node-&gt;children[2],queryRect,pResArr[tid]);<\/i><\/li>\n<li><i> }<\/i><\/li>\n<li><i> #pragma omp section<\/i><\/li>\n<li><i> if ((node-&gt;children[3] != NULL) &amp;&amp; <\/i><\/li>\n<li><i> (node-&gt;children[3]-&gt;Box.Contains(queryRect)<\/i><\/li>\n<li><i> || node-&gt;children[3]-&gt;Box.Intersects(queryRect)))<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> int tid = omp_get_thread_num();<\/i><\/li>\n<li><i> SearchQuadTree(node-&gt;children[3],queryRect,pResArr[tid]);<\/i><\/li>\n<li><i> }<\/i><\/li>\n<li><i> }*\/<\/i><\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if ((node-&gt;children[i] != NULL) &amp;&amp;<\/li>\n<li>(node-&gt;children[i]-&gt;Box.Contains(queryRect)<\/li>\n<li>|| node-&gt;children[i]-&gt;Box.Intersects(queryRect)))<\/li>\n<li>{<\/li>\n<li>SearchQuadTree(node-&gt;children[i],queryRect,ItemSearched);<\/li>\n<li><i>\/\/node = node-&gt;children[i]; \/\/\u975e\u9012\u5f52<\/i><\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/*for (int i = 0 ; i &lt; coreNum; i ++)<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> ItemSearched.insert(ItemSearched.end(),pResArr[i].begin(),pResArr[i].end());<\/i><\/li>\n<li><i> }*\/<\/i><\/li>\n<li>}<\/li>\n<li>void SearchQuadTreePara(vector&lt;QuadNode*&gt; resNodes,MapRect &amp;queryRect,vector&lt;int&gt;&amp; ItemSearched)<\/li>\n<li>{<\/li>\n<li>int coreNum = omp_get_num_procs();<\/li>\n<li>omp_set_num_threads(coreNum);<\/li>\n<li>vector&lt;int&gt;* searchArrs = new vector&lt;int&gt;[coreNum];<\/li>\n<li>for (int i = 0; i &lt; coreNum; i ++)<\/li>\n<li>{<\/li>\n<li>searchArrs[i].clear();<\/li>\n<li>}<\/li>\n<li>#pragma omp parallel for<\/li>\n<li>for (int i = 0; i &lt; resNodes.size(); i ++)<\/li>\n<li>{<\/li>\n<li>int tid = omp_get_thread_num();<\/li>\n<li>for (int j = 0; j &lt; resNodes[i]-&gt;nShpCount; j ++)<\/li>\n<li>{<\/li>\n<li>if (queryRect.Contains(resNodes[i]-&gt;pShapeObj[j].Box)<\/li>\n<li>|| queryRect.Intersects(resNodes[i]-&gt;pShapeObj[j].Box))<\/li>\n<li>{<\/li>\n<li>searchArrs[tid].push_back(resNodes[i]-&gt;pShapeObj[j].nID);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>for (int i = 0; i &lt; coreNum; i ++)<\/li>\n<li>{<\/li>\n<li>ItemSearched.insert(ItemSearched.end(),<\/li>\n<li>searchArrs[i].begin(),searchArrs[i].end());<\/li>\n<li>}<\/li>\n<li>delete [] searchArrs;<\/li>\n<li>searchArrs = NULL;<\/li>\n<li>}<\/li>\n<li>void PtSearchQTree(QuadNode* node,double cx,double cy,vector&lt;int&gt;&amp; ItemSearched)<\/li>\n<li>{<\/li>\n<li>assert(node);<\/li>\n<li>if (node-&gt;nShpCount &gt;0) <i>\/\/\u8282\u70b9 <\/i><\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; node-&gt;nShpCount; i ++)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;pShapeObj[i].Box.IsPointInRect(cx,cy))<\/li>\n<li>{<\/li>\n<li>ItemSearched.push_back(node-&gt;pShapeObj[i].nID);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>else if (node-&gt;nChildCount &gt;0) <i>\/\/\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;children[i]-&gt;Box.IsPointInRect(cx,cy))<\/li>\n<li>{<\/li>\n<li>PtSearchQTree(node-&gt;children[i],cx,cy,ItemSearched);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u627e\u51fa\u91cd\u590d\u5143\u7d20\u7684\u4f4d\u7f6e<\/i><\/li>\n<li>sort(ItemSearched.begin(),ItemSearched.end()); <i>\/\/\u5148\u6392\u5e8f,\u9ed8\u8ba4\u5347\u5e8f<\/i><\/li>\n<li>vector&lt;int&gt;::iterator unique_iter =<\/li>\n<li>unique(ItemSearched.begin(),ItemSearched.end());<\/li>\n<li>ItemSearched.erase(unique_iter,ItemSearched.end());<\/li>\n<li>}<\/li>\n<li>void Insert(long key, MapRect &amp;itemRect,QuadNode* pNode)<\/li>\n<li>{<\/li>\n<li>QuadNode *node = pNode; <i>\/\/\u4fdd\u7559\u6839\u8282\u70b9\u526f\u672c<\/i><\/li>\n<li>SHPMBRInfo pShpInfo;<\/li>\n<li><i>\/\/\u8282\u70b9\u6709\u5b69\u5b50<\/i><\/li>\n<li>if (0 &lt; node-&gt;nChildCount)<\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5982\u679c\u5305\u542b\u6216\u76f8\u4ea4\uff0c\u5219\u5c06\u8282\u70b9\u63d2\u5165\u5230\u6b64\u8282\u70b9<\/i><\/li>\n<li>if (node-&gt;children[i]-&gt;Box.Contains(itemRect)<\/li>\n<li>|| node-&gt;children[i]-&gt;Box.Intersects(itemRect))<\/li>\n<li>{<\/li>\n<li><i>\/\/node = node-&gt;children[i];<\/i><\/li>\n<li>Insert(key,itemRect,node-&gt;children[i]);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u4e00\u4e2a\u5b50\u8282\u70b9\u65f6<\/i><\/li>\n<li>else if (1 == node-&gt;nShpCount)<\/li>\n<li>{<\/li>\n<li>MapRect boxs[4];<\/li>\n<li>node-&gt;Box.Split(boxs,boxs+1,boxs+2,boxs+3);<\/li>\n<li><i>\/\/\u521b\u5efa\u56db\u4e2a\u8282\u70b9\u5e76\u63d2\u5165\u76f8\u5e94\u7684MBR<\/i><\/li>\n<li>node-&gt;children[UR] = InitQuadNode();<\/li>\n<li>node-&gt;children[UL] = InitQuadNode();<\/li>\n<li>node-&gt;children[LL] = InitQuadNode();<\/li>\n<li>node-&gt;children[LR] = InitQuadNode();<\/li>\n<li>node-&gt;children[UR]-&gt;Box = boxs[0];<\/li>\n<li>node-&gt;children[UL]-&gt;Box = boxs[1];<\/li>\n<li>node-&gt;children[LL]-&gt;Box = boxs[2];<\/li>\n<li>node-&gt;children[LR]-&gt;Box = boxs[3];<\/li>\n<li>node-&gt;nChildCount = 4;<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5c06\u5f53\u524d\u8282\u70b9\u4e2d\u7684\u8981\u7d20\u79fb\u52a8\u5230\u76f8\u5e94\u7684\u5b50\u8282\u70b9\u4e2d<\/i><\/li>\n<li>for (int j = 0; j &lt; node-&gt;nShpCount; j ++)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;children[i]-&gt;Box.Contains(node-&gt;pShapeObj[j].Box)<\/li>\n<li>|| node-&gt;children[i]-&gt;Box.Intersects(node-&gt;pShapeObj[j].Box))<\/li>\n<li>{<\/li>\n<li>node-&gt;children[i]-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;children[i]-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(node-&gt;children[i]-&gt;nShpCount*sizeof(SHPMBRInfo));<\/li>\n<li>memcpy(node-&gt;children[i]-&gt;pShapeObj,&amp;(node-&gt;pShapeObj[j]),sizeof(SHPMBRInfo));<\/li>\n<li>free(node-&gt;pShapeObj);<\/li>\n<li>node-&gt;pShapeObj = NULL;<\/li>\n<li>node-&gt;nShpCount = 0;<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5982\u679c\u5305\u542b\u6216\u76f8\u4ea4\uff0c\u5219\u5c06\u8282\u70b9\u63d2\u5165\u5230\u6b64\u8282\u70b9<\/i><\/li>\n<li>if (node-&gt;children[i]-&gt;Box.Contains(itemRect)<\/li>\n<li>|| node-&gt;children[i]-&gt;Box.Intersects(itemRect))<\/li>\n<li>{<\/li>\n<li>if (node-&gt;children[i]-&gt;nShpCount == 0) <i>\/\/\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>node-&gt;children[i]-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*node-&gt;children[i]-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>else if (node-&gt;children[i]-&gt;nShpCount &gt; 0)<\/li>\n<li>{<\/li>\n<li>node-&gt;children[i]-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;children[i]-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo *)realloc(node-&gt;children[i]-&gt;pShapeObj,<\/li>\n<li>sizeof(SHPMBRInfo)*node-&gt;children[i]-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>pShpInfo.Box = itemRect;<\/li>\n<li>pShpInfo.nID = key;<\/li>\n<li>memcpy(node-&gt;children[i]-&gt;pShapeObj,<\/li>\n<li>&amp;pShpInfo,sizeof(SHPMBRInfo));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5f53\u524d\u8282\u70b9\u6ca1\u6709\u7a7a\u95f4\u5bf9\u8c61<\/i><\/li>\n<li>else if (0 == node-&gt;nShpCount)<\/li>\n<li>{<\/li>\n<li>node-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*node-&gt;nShpCount);<\/li>\n<li>pShpInfo.Box = itemRect;<\/li>\n<li>pShpInfo.nID = key;<\/li>\n<li>memcpy(node-&gt;pShapeObj,&amp;pShpInfo,sizeof(SHPMBRInfo));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>void InsertQuad(long key,MapRect &amp;itemRect,QuadNode* pNode)<\/li>\n<li>{<\/li>\n<li>assert(pNode != NULL);<\/li>\n<li>if (!IsQuadLeaf(pNode)) <i>\/\/\u975e\u53f6\u5b50\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>int nCorver = 0; <i>\/\/\u8de8\u8d8a\u7684\u5b50\u8282\u70b9\u4e2a\u6570<\/i><\/li>\n<li>int iIndex = -1; <i>\/\/\u88ab\u54ea\u4e2a\u5b50\u8282\u70b9\u5b8c\u5168\u5305\u542b\u7684\u7d22\u5f15\u53f7<\/i><\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if (pNode-&gt;children[i]-&gt;Box.Contains(itemRect)<\/li>\n<li>&amp;&amp; pNode-&gt;Box.Contains(itemRect))<\/li>\n<li>{<\/li>\n<li>nCorver += 1;<\/li>\n<li>iIndex = i;<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u88ab\u67d0\u4e00\u4e2a\u5b50\u8282\u70b9\u5305\u542b\uff0c\u5219\u8fdb\u5165\u8be5\u5b50\u8282\u70b9<\/i><\/li>\n<li>if (<i>\/*pNode-&gt;Box.Contains(itemRect) || <\/i><\/li>\n<li><i> pNode-&gt;Box.Intersects(itemRect)*\/<\/i>1 &lt;= nCorver)<\/li>\n<li>{<\/li>\n<li>InsertQuad(key,itemRect,pNode-&gt;children[iIndex]);<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u8de8\u8d8a\u4e86\u591a\u4e2a\u5b50\u8282\u70b9\uff0c\u76f4\u63a5\u653e\u5728\u8fd9\u4e2a\u8282\u70b9\u4e2d<\/i><\/li>\n<li>else if (nCorver == 0)<\/li>\n<li>{<\/li>\n<li>if (pNode-&gt;nShpCount == 0) <i>\/\/\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>pNode-&gt;nShpCount += 1;<\/li>\n<li>pNode-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*pNode-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>else<\/li>\n<li>{<\/li>\n<li>pNode-&gt;nShpCount += 1;<\/li>\n<li>pNode-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo *)realloc(pNode-&gt;pShapeObj,sizeof(SHPMBRInfo)*pNode-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>SHPMBRInfo pShpInfo;<\/li>\n<li>pShpInfo.Box = itemRect;<\/li>\n<li>pShpInfo.nID = key;<\/li>\n<li>memcpy(pNode-&gt;pShapeObj+pNode-&gt;nShpCount-1,&amp;pShpInfo,sizeof(SHPMBRInfo));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u662f\u53f6\u5b50\u8282\u70b9\uff0c\u76f4\u63a5\u653e\u8fdb\u53bb<\/i><\/li>\n<li>else if (IsQuadLeaf(pNode))<\/li>\n<li>{<\/li>\n<li>if (pNode-&gt;nShpCount == 0) <i>\/\/\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>pNode-&gt;nShpCount += 1;<\/li>\n<li>pNode-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*pNode-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>else<\/li>\n<li>{<\/li>\n<li>pNode-&gt;nShpCount += 1;<\/li>\n<li>pNode-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo *)realloc(pNode-&gt;pShapeObj,sizeof(SHPMBRInfo)*pNode-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>SHPMBRInfo pShpInfo;<\/li>\n<li>pShpInfo.Box = itemRect;<\/li>\n<li>pShpInfo.nID = key;<\/li>\n<li>memcpy(pNode-&gt;pShapeObj+pNode-&gt;nShpCount-1,&amp;pShpInfo,sizeof(SHPMBRInfo));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>void InsertQuad2(long key,MapRect &amp;itemRect,QuadNode* pNode)<\/li>\n<li>{<\/li>\n<li>QuadNode *node = pNode; <i>\/\/\u4fdd\u7559\u6839\u8282\u70b9\u526f\u672c<\/i><\/li>\n<li>SHPMBRInfo pShpInfo;<\/li>\n<li><i>\/\/\u8282\u70b9\u6709\u5b69\u5b50<\/i><\/li>\n<li>if (0 &lt; node-&gt;nChildCount)<\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5982\u679c\u5305\u542b\u6216\u76f8\u4ea4\uff0c\u5219\u5c06\u8282\u70b9\u63d2\u5165\u5230\u6b64\u8282\u70b9<\/i><\/li>\n<li>if (node-&gt;children[i]-&gt;Box.Contains(itemRect)<\/li>\n<li>|| node-&gt;children[i]-&gt;Box.Intersects(itemRect))<\/li>\n<li>{<\/li>\n<li><i>\/\/node = node-&gt;children[i];<\/i><\/li>\n<li>Insert(key,itemRect,node-&gt;children[i]);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u4e00\u4e2a\u5b50\u8282\u70b9\u65f6<\/i><\/li>\n<li>else if (0 == node-&gt;nChildCount)<\/li>\n<li>{<\/li>\n<li>MapRect boxs[4];<\/li>\n<li>node-&gt;Box.Split(boxs,boxs+1,boxs+2,boxs+3);<\/li>\n<li>int cnt = -1;<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5982\u679c\u5305\u542b\u6216\u76f8\u4ea4\uff0c\u5219\u5c06\u8282\u70b9\u63d2\u5165\u5230\u6b64\u8282\u70b9<\/i><\/li>\n<li>if (boxs[i].Contains(itemRect))<\/li>\n<li>{<\/li>\n<li>cnt = i;<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u6709\u4e00\u4e2a\u77e9\u5f62\u5305\u542b\u6b64\u5bf9\u8c61\uff0c\u5219\u521b\u5efa\u56db\u4e2a\u5b69\u5b50\u8282\u70b9<\/i><\/li>\n<li>if (cnt &gt; -1)<\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u521b\u5efa\u56db\u4e2a\u8282\u70b9\u5e76\u63d2\u5165\u76f8\u5e94\u7684MBR<\/i><\/li>\n<li>node-&gt;children[i] = InitQuadNode();<\/li>\n<li>node-&gt;children[i]-&gt;Box = boxs[i];<\/li>\n<li>}<\/li>\n<li>node-&gt;nChildCount = 4;<\/li>\n<li>InsertQuad2(key,itemRect,node-&gt;children[cnt]); <i>\/\/\u9012\u5f52<\/i><\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u90fd\u4e0d\u5305\u542b\uff0c\u5219\u76f4\u63a5\u5c06\u5bf9\u8c61\u63d2\u5165\u6b64\u8282\u70b9<\/i><\/li>\n<li>if (cnt == -1)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;nShpCount == 0) <i>\/\/\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u8282\u70b9<\/i><\/li>\n<li>{<\/li>\n<li>node-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*node-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>else if (node-&gt;nShpCount &gt; 0)<\/li>\n<li>{<\/li>\n<li>node-&gt;nShpCount += 1;<\/li>\n<li>node-&gt;pShapeObj =<\/li>\n<li>(SHPMBRInfo *)realloc(node-&gt;pShapeObj,<\/li>\n<li>sizeof(SHPMBRInfo)*node-&gt;nShpCount);<\/li>\n<li>}<\/li>\n<li>pShpInfo.Box = itemRect;<\/li>\n<li>pShpInfo.nID = key;<\/li>\n<li>memcpy(node-&gt;pShapeObj,<\/li>\n<li>&amp;pShpInfo,sizeof(SHPMBRInfo));<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5f53\u524d\u8282\u70b9\u6ca1\u6709\u7a7a\u95f4\u5bf9\u8c61<\/i><\/li>\n<li><i>\/*else if (0 == node-&gt;nShpCount)<\/i><\/li>\n<li><i> {<\/i><\/li>\n<li><i> node-&gt;nShpCount += 1;<\/i><\/li>\n<li><i> node-&gt;pShapeObj = <\/i><\/li>\n<li><i> (SHPMBRInfo*)malloc(sizeof(SHPMBRInfo)*node-&gt;nShpCount);<\/i><\/li>\n<li><i> pShpInfo.Box = itemRect;<\/i><\/li>\n<li><i> pShpInfo.nID = key;<\/i><\/li>\n<li><i> memcpy(node-&gt;pShapeObj,&amp;pShpInfo,sizeof(SHPMBRInfo));<\/i><\/li>\n<li><i> }*\/<\/i><\/li>\n<li>}<\/li>\n<li>bool IsQuadLeaf(QuadNode* node)<\/li>\n<li>{<\/li>\n<li>if (NULL == node)<\/li>\n<li>{<\/li>\n<li>return 1;<\/li>\n<li>}<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;children[i] != NULL)<\/li>\n<li>{<\/li>\n<li>return 0;<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>return 1;<\/li>\n<li>}<\/li>\n<li>bool DelFalseNode(QuadNode* node)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5982\u679c\u6ca1\u6709\u5b50\u8282\u70b9\u4e14\u6ca1\u6709\u8981\u7d20<\/i><\/li>\n<li>if (node-&gt;nChildCount ==0 &amp;&amp; node-&gt;nShpCount == 0)<\/li>\n<li>{<\/li>\n<li>ReleaseQuadTree(&amp;node);<\/li>\n<li>}<\/li>\n<li><i>\/\/\u5982\u679c\u6709\u5b50\u8282\u70b9<\/i><\/li>\n<li>else if (node-&gt;nChildCount &gt; 0)<\/li>\n<li>{<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>DelFalseNode(node-&gt;children[i]);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>return 1;<\/li>\n<li>}<\/li>\n<li>void TraversalQuadTree(QuadNode* quadTree,vector&lt;int&gt;&amp; resVec)<\/li>\n<li>{<\/li>\n<li>QuadNode *node = quadTree;<\/li>\n<li>int i = 0;<\/li>\n<li>if (NULL != node)<\/li>\n<li>{<\/li>\n<li><i>\/\/\u5c06\u672c\u8282\u70b9\u4e2d\u7684\u7a7a\u95f4\u5bf9\u8c61\u5b58\u50a8\u6570\u7ec4\u4e2d<\/i><\/li>\n<li>for (i = 0; i &lt; node-&gt;nShpCount; i ++)<\/li>\n<li>{<\/li>\n<li>resVec.push_back((node-&gt;pShapeObj+i)-&gt;nID);<\/li>\n<li>}<\/li>\n<li><i>\/\/\u904d\u5386\u5b69\u5b50\u8282\u70b9<\/i><\/li>\n<li>for (i = 0; i &lt; node-&gt;nChildCount; i ++)<\/li>\n<li>{<\/li>\n<li>if (node-&gt;children[i] != NULL)<\/li>\n<li>{<\/li>\n<li>TraversalQuadTree(node-&gt;children[i],resVec);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>void TraversalQuadTree(QuadNode* quadTree,vector&lt;QuadNode*&gt;&amp; arrNode)<\/li>\n<li>{<\/li>\n<li>deque&lt;QuadNode*&gt; nodeQueue;<\/li>\n<li>if (quadTree != NULL)<\/li>\n<li>{<\/li>\n<li>nodeQueue.push_back(quadTree);<\/li>\n<li>while (!nodeQueue.empty())<\/li>\n<li>{<\/li>\n<li>QuadNode* queueHead = nodeQueue.at(0); <i>\/\/\u53d6\u961f\u5217\u5934\u7ed3\u70b9<\/i><\/li>\n<li>arrNode.push_back(queueHead);<\/li>\n<li>nodeQueue.pop_front();<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if (queueHead-&gt;children[i] != NULL)<\/li>\n<li>{<\/li>\n<li>nodeQueue.push_back(queueHead-&gt;children[i]);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>void ReleaseQuadTree(QuadNode** quadTree)<\/li>\n<li>{<\/li>\n<li>int i = 0;<\/li>\n<li>QuadNode* node = *quadTree;<\/li>\n<li>if (NULL == node)<\/li>\n<li>{<\/li>\n<li>return;<\/li>\n<li>}<\/li>\n<li>else<\/li>\n<li>{<\/li>\n<li>for (i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>ReleaseQuadTree(&amp;node-&gt;children[i]);<\/li>\n<li>}<\/li>\n<li>free(node);<\/li>\n<li>node = NULL;<\/li>\n<li>}<\/li>\n<li>node = NULL;<\/li>\n<li>}<\/li>\n<li>long CalByteQuadTree(QuadNode* quadTree,long&amp; nSize)<\/li>\n<li>{<\/li>\n<li>if (quadTree != NULL)<\/li>\n<li>{<\/li>\n<li>nSize += sizeof(QuadNode)+quadTree-&gt;nChildCount*sizeof(SHPMBRInfo);<\/li>\n<li>for (int i = 0; i &lt; 4; i ++)<\/li>\n<li>{<\/li>\n<li>if (quadTree-&gt;children[i] != NULL)<\/li>\n<li>{<\/li>\n<li>nSize += CalByteQuadTree(quadTree-&gt;children[i],nSize);<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<li>return 1;<\/li>\n<li>}<\/li>\n<\/ol>\n<p style=\"font-weight: 400;\">\n\u4ee3\u7801\u6709\u70b9\u957f\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u501f\u9274\u5e76\u81ea\u5df1\u4f18\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u5468\u65ed\u5149\u00a02013<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-5011","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5011"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5011\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}