Skip to content

Commit

Permalink
#757 box_connectivity, supplemental;
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenHilferink committed Aug 2, 2024
1 parent 6b46836 commit 7734b19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
25 changes: 18 additions & 7 deletions geo/dll/src/BoostPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ CommonOperGroup cogBC("box_connectivity", oper_policy::better_not_in_meta_script

class AbstrBoxConnectivityOperator : public BinaryOperator
{
protected:
using ResultingDomainType = UInt32;

AbstrBoxConnectivityOperator(const DataItemClass* polyAttrClass)
Expand Down Expand Up @@ -1462,9 +1463,10 @@ class BoxConnectivityOperator : public AbstrBoxConnectivityOperator
{
using PointType = P;
using ScalarType = scalar_of_t<P>;
using RectType = Range<P>;
using RectTypePtr = RectType*;
using RectType = Range<PointType>;
using RectTypeCPtr = const RectType*;
using Arg1Type = DataArray<PointType>;
using SpatialIndexType = SpatialIndex<ScalarType, RectTypeCPtr>;

public:
BoxConnectivityOperator()
Expand All @@ -1481,20 +1483,25 @@ class BoxConnectivityOperator : public AbstrBoxConnectivityOperator
lowerBoundData = {};
upperBoundData = {};

auto spatialIndex = SpatialIndex<ScalarType, RectTypePtr>(begin_ptr( rects ), end_ptr( rects ));
auto rects_begin = begin_ptr(rects);
auto rects_beyond = end_ptr(rects);
auto spatialIndex = SpatialIndexType(rects_begin, rects_beyond);

// counting
SizeT nrEdges = 0;
for (const auto& rect : rects)
{
SizeT index = &rect - begin_ptr(rects);
for (auto iter = spatialIndex.begin(rect); iter; ++iter)
if (Intersects(*((*iter)->get_ptr()), rect))
{
auto currRectPtr = (*iter)->get_ptr();
if (IsIntersecting(*currRectPtr, rect))
{
SizeT index2 = (*iter)->get_ptr() - beginPtr(rects);
SizeT index2 = currRectPtr - rects_begin;
if (index < index2)
++nrEdges;
}
}
}
res->SetCount(ThrowingConvert<ResultingDomainType>(nrEdges));
DataWriteLock resF1Lock(resF1);
Expand All @@ -1508,9 +1515,11 @@ class BoxConnectivityOperator : public AbstrBoxConnectivityOperator
{
SizeT index = &rect - begin_ptr(rects);
for (auto iter = spatialIndex.begin(rect); iter; ++iter)
if (Intersects(*((*iter)->get_ptr()), rect))
{
auto currRectPtr = (*iter)->get_ptr();
if (IsIntersecting(*currRectPtr, rect))
{
SizeT index2 = (*iter)->get_ptr() - beginPtr(rects);
SizeT index2 = currRectPtr - rects_begin;
if (index < index2)
{
assert(e < nrEdges);
Expand All @@ -1519,6 +1528,7 @@ class BoxConnectivityOperator : public AbstrBoxConnectivityOperator
++e;
}
}
}
}
indexAssigner1.Store();
indexAssigner2.Store();
Expand Down Expand Up @@ -1675,6 +1685,7 @@ namespace
tl_oper::inst_tuple_templ<typelists::points, CGAL_OverlayOperator, AbstrOperGroup&> cgalOverlayOperators(grCGALOverlayPolygon);

tl_oper::inst_tuple_templ<typelists::sint_points, PolygonConnectivityOperator> polygonConnectivityOperators;
tl_oper::inst_tuple_templ<typelists::points, BoxConnectivityOperator> boxConnectivityOperators;

PolyOperatorGroupss simple("", PolygonFlags());
BpPolyOperatorGroupss bp_simple;
Expand Down
27 changes: 23 additions & 4 deletions rtc/dll/src/geo/SpatialIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __RTC_GEO_SPATIALINDEX_H

#include "geo/Pair.h"
#include "geo/SequenceArray.h"
#include "utl/IncrementalLock.h"

template <typename SpatialIndexType> struct neighbour_iter;
Expand All @@ -29,6 +30,13 @@ Point<T> _FirstElem(const Point<T>& p)
return p;
}

template<typename PointType>
Range<PointType>
RangeFromPtr(const Range<PointType>* rect)
{
return *rect;
}

template<typename PointType>
Range<PointType>
RangeFromPtr(typename sequence_traits<PointType>::cseq_t::const_iterator point)
Expand Down Expand Up @@ -149,14 +157,25 @@ struct PolyLeaf: LeafBase<PointType, ObjectPtr, PolyLeaf<PointType, ObjectPtr>>
extents_type m_Bounds;
};

template <typename PointType, typename ObjectPtr> struct LeafTypeGetter;
template <typename PointType, typename ObjectPtr> struct LeafTypeGetter
{
using type = PolyLeaf<PointType, ObjectPtr>;
};

template <typename PointType> struct LeafTypeGetter<PointType, const PointType*>
{
using type = PointLeaf<PointType>;
};


template <typename PointType> struct LeafTypeGetter<PointType, const PointType*> { typedef PointLeaf<PointType> type; };
/*
template <typename PointType> struct LeafTypeGetter<PointType, const Range<PointType>*> { typedef PolyLeaf<PointType, const Range<PointType>*> type; };
template <typename PointType> struct LeafTypeGetter<PointType, const std::vector<PointType>*> { typedef PolyLeaf <PointType, const std::vector<PointType>*> type; };
template <typename PointType> struct LeafTypeGetter<PointType, SA_ConstIterator<PointType> > { typedef PolyLeaf <PointType, SA_ConstIterator<PointType> > type; };
template <typename PointType> struct LeafTypeGetter<PointType, sequence_array_index<PointType> > { typedef PolyLeaf <PointType, sequence_array_index<PointType> > type; };
*/

template <typename PointType, typename ObjectPtr> using LeafTypeGetter_t = LeafTypeGetter<PointType, ObjectPtr>::type;
template <typename PointType, typename ObjectPtr> using LeafTypeGetter_t = typename LeafTypeGetter<PointType, ObjectPtr>::type;


template <typename PointType, typename LeafType>
Expand Down Expand Up @@ -362,7 +381,7 @@ struct SpatialIndex
friend struct iterator<PointType>;
friend struct iterator<RangeType>;

SpatialIndex(ObjectPtr first, ObjectPtr last, SizeT maxNrFutureInserts)
SpatialIndex(ObjectPtr first, ObjectPtr last, SizeT maxNrFutureInserts = 0)
{
MG_CHECK(first != last || !maxNrFutureInserts); // future inserts must be within the current determinable boundingbox
m_Leafs.reserve((last-first) + maxNrFutureInserts);
Expand Down

0 comments on commit 7734b19

Please sign in to comment.