GEOS  3.10.3
FacetSequenceTreeBuilder.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2016 Daniel Baston
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: operation/distance/FacetSequenceTreeBuilder.java (f6187ee2 JTS-1.14)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_OPERATION_DISTANCE_FACETSEQUENCETREEBUILDER_H
20 #define GEOS_OPERATION_DISTANCE_FACETSEQUENCETREEBUILDER_H
21 
22 #include <geos/index/ItemVisitor.h>
23 #include <geos/index/strtree/TemplateSTRtree.h>
24 #include <geos/geom/Geometry.h>
25 #include <geos/geom/CoordinateSequence.h>
26 #include <geos/operation/distance/FacetSequence.h>
27 
28 namespace geos {
29 namespace operation {
30 namespace distance {
31 class GEOS_DLL FacetSequenceTreeBuilder {
32 private:
33  // 6 seems to be a good facet sequence size
34  static const int FACET_SEQUENCE_SIZE = 6;
35 
36  // Seems to be better to use a minimum node capacity
37  static const int STR_TREE_NODE_CAPACITY = 4;
38 
39  static void addFacetSequences(const geom::Geometry* geom,
40  const geom::CoordinateSequence* pts,
41  std::vector<FacetSequence> & sections);
42  static std::vector<FacetSequence> computeFacetSequences(const geom::Geometry* g);
43 
44  class FacetSequenceTree : public geos::index::strtree::TemplateSTRtree<const FacetSequence*> {
45  public:
46  // TODO support TemplateSTRtree<std::unique_ptr<FacetSequence>> and dispense with holding vector.
47  FacetSequenceTree(std::vector<FacetSequence> &&seq) :
48  TemplateSTRtree(STR_TREE_NODE_CAPACITY, seq.size()), sequences(seq) {
49  for (auto& fs : sequences) {
50  TemplateSTRtree::insert(fs.getEnvelope(), &fs);
51  }
52  }
53 
54  private:
55  std::vector<FacetSequence> sequences;
56  };
57 
58 public:
65  static std::unique_ptr<geos::index::strtree::TemplateSTRtree<const FacetSequence*>> build(const geom::Geometry* g);
66 };
67 }
68 }
69 }
70 
71 #endif //GEOS_FACETSEQUENCETREEBUILDER_H
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26