GEOS  3.3.9
MCIndexSegmentSetMutualIntersector.h
00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.refractions.net
00005  *
00006  * Copyright (C) 2006 Refractions Research Inc.
00007  *
00008  * This is free software; you can redistribute and/or modify it under
00009  * the terms of the GNU Lesser General Public Licence as published
00010  * by the Free Software Foundation. 
00011  * See the COPYING file for more information.
00012  *
00013  *
00014  **********************************************************************
00015  *
00016  * Last port: noding/MCIndexSegmentSetMutualIntersector.java r388 (JTS-1.12)
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
00021 #define GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
00022 
00023 #include <geos/noding/SegmentSetMutualIntersector.h> // inherited
00024 #include <geos/index/chain/MonotoneChainOverlapAction.h> // inherited
00025 
00026 namespace geos {
00027         namespace index {
00028                 class SpatialIndex;
00029 
00030                 namespace chain {
00031                         class MonotoneChain;
00032                 }
00033                 namespace strtree {
00034                         //class STRtree;
00035                 }
00036         }
00037         namespace noding {
00038                 class SegmentString;
00039                 class SegmentIntersector;
00040         }
00041 }
00042 
00043 //using namespace geos::index::strtree;
00044 
00045 namespace geos {
00046 namespace noding { // geos::noding
00047 
00054 class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector 
00055 {
00056 public:
00057 
00058         MCIndexSegmentSetMutualIntersector();
00059 
00060         ~MCIndexSegmentSetMutualIntersector();
00061 
00062         /* Returns a reference to a vector of MonotoneChain objects owned
00063          * by this class and destroyed on next call to ::process.
00064          * Copy them if you need them alive for longer.
00065          */
00066         std::vector<index::chain::MonotoneChain *>& getMonotoneChains() 
00067         { 
00068                 return monoChains; 
00069         }
00070 
00071         index::SpatialIndex* getIndex() 
00072         { 
00073                 return index; 
00074         }
00075 
00076         void setBaseSegments(SegmentString::ConstVect* segStrings);
00077   
00078         // NOTE: re-populates the MonotoneChain vector with newly created chains
00079         void process(SegmentString::ConstVect* segStrings);
00080 
00081     class SegmentOverlapAction : public index::chain::MonotoneChainOverlapAction
00082     {
00083     private:
00084         SegmentIntersector & si;
00085 
00086         // Declare type as noncopyable
00087         SegmentOverlapAction(const SegmentOverlapAction& other);
00088         SegmentOverlapAction& operator=(const SegmentOverlapAction& rhs);
00089 
00090     public:
00091         SegmentOverlapAction(SegmentIntersector & si) :
00092           index::chain::MonotoneChainOverlapAction(), si(si)
00093           {}
00094 
00095           void overlap(index::chain::MonotoneChain& mc1, std::size_t start1,
00096               index::chain::MonotoneChain& mc2, std::size_t start2);
00097     };
00098 
00099 private:
00100 
00101         typedef std::vector<index::chain::MonotoneChain *> MonoChains;
00102         MonoChains monoChains;
00103 
00104         /*
00105          * The {@link SpatialIndex} used should be something that supports
00106          * envelope (range) queries efficiently (such as a {@link Quadtree}
00107          * or {@link STRtree}.
00108          */
00109         index::SpatialIndex * index;
00110         int indexCounter;
00111         int processCounter;
00112         // statistics
00113         int nOverlaps;
00114         
00115         /* memory management helper, holds MonotoneChain objects used
00116          * in the SpatialIndex. It's cleared when the SpatialIndex is
00117          */
00118         MonoChains chainStore;
00119       
00120         void addToIndex( SegmentString * segStr);
00121 
00122         void intersectChains();
00123 
00124         void addToMonoChains( SegmentString * segStr);
00125 
00126 };
00127 
00128 } // namespace geos::noding
00129 } // namespace geos
00130 
00131 #endif // GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
00132 /**********************************************************************
00133  * $Log$
00134  **********************************************************************/
00135