Skip to content

Commit

Permalink
#604: bg_intersection added
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenHilferink committed Jun 28, 2024
1 parent e0d96b7 commit ab71348
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 57 deletions.
5 changes: 2 additions & 3 deletions clc/dll/include/OperAttrBin.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ struct AbstrBinaryAttrOper : BinaryOperator
}

virtual SharedPtr<const AbstrDataObject> CreateFutureTileFunctor(SharedPtr<AbstrDataItem>, bool lazy, const AbstrUnit* valuesUnitA, const AbstrDataItem* arg1A, const AbstrDataItem* arg2A, ArgFlags af MG_DEBUG_ALLOCATOR_SRC_ARG) const = 0;
virtual void Calculate(AbstrDataObject* borrowedDataHandle, const AbstrDataItem* arg1A, const AbstrDataItem* arg2A, ArgFlags af, tile_id t
) const=0;
virtual void Calculate(AbstrDataObject* borrowedDataHandle, const AbstrDataItem* arg1A, const AbstrDataItem* arg2A, ArgFlags af, tile_id t) const=0;

private:
UnitCreatorPtr m_UnitCreatorPtr;
Expand All @@ -110,7 +109,7 @@ struct BinaryAttrOper : AbstrBinaryAttrOper
using ResultType = DataArray<ResultValueType>;

public:
BinaryAttrOper(AbstrOperGroup* gr, UnitCreatorPtr ucp, ValueComposition vc, ArgFlags possibleArgFlags)
BinaryAttrOper(AbstrOperGroup* gr, UnitCreatorPtr ucp, ValueComposition vc)
: AbstrBinaryAttrOper(gr
, ResultType::GetStaticClass(), Arg1Type::GetStaticClass(), Arg2Type::GetStaticClass()
, ucp, vc, ArgFlags(AF1_HASUNDEFINED | AF2_HASUNDEFINED)
Expand Down
10 changes: 5 additions & 5 deletions clc/dll/src/OperAttrBin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using tile_future = std::function<TileCRef>;
struct StrConcatOperator : BinaryAttrOper<SharedStr, SharedStr, SharedStr>
{
StrConcatOperator(AbstrOperGroup* gr)
: BinaryAttrOper(gr, compatible_simple_values_unit_creator, COMPOSITION(SharedStr), ArgFlags())
: BinaryAttrOper(gr, compatible_simple_values_unit_creator, COMPOSITION(SharedStr))
{}

// Override BinaryAttrOper
Expand Down Expand Up @@ -89,7 +89,7 @@ template <typename SubTerFunc>
struct Str2Operator : BinaryAttrOper<SharedStr, SharedStr, strpos_t>
{
Str2Operator(AbstrOperGroup& aog, SubTerFunc&& sf)
: BinaryAttrOper(&aog, arg1_values_unit, COMPOSITION(SharedStr), ArgFlags())
: BinaryAttrOper(&aog, arg1_values_unit, COMPOSITION(SharedStr))
, m_SubFunc(std::move(sf))
{}

Expand Down Expand Up @@ -152,7 +152,7 @@ struct String2Operator : BinaryAttrOper<SharedStr, TA, decpos_t>
{

String2Operator()
: BinaryAttrOper<SharedStr, TA, decpos_t>(GetUnitGroup<SharedStr>(), default_unit_creator<SharedStr>, ValueComposition::Single, ArgFlags())
: BinaryAttrOper<SharedStr, TA, decpos_t>(GetUnitGroup<SharedStr>(), default_unit_creator<SharedStr>, ValueComposition::Single)
{}

// Override BinaryAttrOper
Expand Down Expand Up @@ -203,7 +203,7 @@ void Repeat(StringRef& res, const StringCRef& arg, strpos_t count)
struct RepeatOperator : BinaryAttrOper<SharedStr, SharedStr, strpos_t>
{
RepeatOperator()
: BinaryAttrOper(&cog_repeat, default_unit_creator<SharedStr>, ValueComposition::Single, ArgFlags())
: BinaryAttrOper(&cog_repeat, default_unit_creator<SharedStr>, ValueComposition::Single)
{}

// Override BinaryAttrOper
Expand Down Expand Up @@ -390,7 +390,7 @@ template <typename BinOper>
struct BinaryAttrFuncOper : BinaryAttrOper<typename BinOper::res_type, typename BinOper::arg1_type, typename BinOper::arg2_type>
{
BinaryAttrFuncOper(AbstrOperGroup* gr)
: BinaryAttrOper<typename BinOper::res_type, typename BinOper::arg1_type, typename BinOper::arg2_type>(gr, BinOper::unit_creator, composition_of<typename BinOper::res_type>::value, ArgFlags(AF1_HASUNDEFINED | AF2_HASUNDEFINED))
: BinaryAttrOper<typename BinOper::res_type, typename BinOper::arg1_type, typename BinOper::arg2_type>(gr, BinOper::unit_creator, composition_of<typename BinOper::res_type>::value)
{}

void CalcTile(sequence_traits<typename BinOper::res_type>::seq_t resData, sequence_traits<typename BinOper::arg1_type>::cseq_t arg1Data, sequence_traits<typename BinOper::arg2_type>::cseq_t arg2Data, ArgFlags af MG_DEBUG_ALLOCATOR_SRC_ARG) const override
Expand Down
78 changes: 74 additions & 4 deletions geo/dll/src/BoostGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@

#include "RtcTypeLists.h"
#include "RtcGeneratedVersion.h"
#include "VersionComponent.h"

#include "mci/ValueClass.h"
#include "mci/ValueWrap.h"
#include "utl/TypeListOper.h"
#include "xct/DmsException.h"

#include "ParallelTiles.h"

#include "Unit.h"
#include "UnitClass.h"

#include "OperAttrBin.h"
#include "RemoveAdjacentsAndSpikes.h"

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/within.hpp>
#include <boost/geometry/geometries/multi_linestring.hpp>

#include "ipolygon/polygon.hpp"
#include "geo/BoostPolygon.h"
#include "RemoveAdjacentsAndSpikes.h"

#include "VersionComponent.h"
static VersionComponent s_BoostGeometry("boost::geometry " BOOST_STRINGIZE(BOOST_GEOMETRY_VERSION));

using bg_multi_point_t = boost::geometry::model::multi_point<DPoint>;
Expand Down Expand Up @@ -398,7 +399,7 @@ void store_multi_polygon(SA_Reference<DmsPointType> resDataElem, bg_multi_polygo
}

// *****************************************************************************
// simplify
// operation groups
// *****************************************************************************


Expand Down Expand Up @@ -430,6 +431,66 @@ static Obsolete<CommonOperGroup> grOuter_multi_polygon("use bg_outer_multi_polyg
static CommonOperGroup grBgOuter_single_polygon("bg_outer_single_polygon", oper_policy::better_not_in_meta_scripting);
static CommonOperGroup grBgOuter_multi_polygon("bg_outer_multi_polygon", oper_policy::better_not_in_meta_scripting);

// *****************************************************************************
// map algebraic operations
// *****************************************************************************

template <typename P> using sequence_t = std::vector<P>;
template <typename P> using BinaryMapAlgebraicOperator = BinaryAttrOper<sequence_t<P>, sequence_t<P>, sequence_t<P>>;

template <typename P>
struct BgIntersectMultiPolygonOperator : BinaryMapAlgebraicOperator<P>
{
using PointType = P;
using PolygonType = std::vector<PointType>;
using ArgType = DataArray<PolygonType>;

BgIntersectMultiPolygonOperator()
: BinaryMapAlgebraicOperator<P>(&grBgIntersect, compatible_simple_values_unit_creator, ValueComposition::Polygon)
{}
using st = sequence_traits<PolygonType>;
using seq_t = typename st::seq_t;
using cseq_t = typename st::cseq_t;

void CalcTile(seq_t resData, cseq_t arg1Data, cseq_t arg2Data, ArgFlags af MG_DEBUG_ALLOCATOR_SRC_ARG) const override
{
tile_offset n1 = arg1Data.size();
tile_offset n2 = arg2Data.size();
tile_offset n = std::max(n1, n2);
assert(n1 == n || (af & AF1_ISPARAM));
assert(n2 == n || (af & AF2_ISPARAM));
assert(resData.size() == n);


bg_ring_t helperRing;
bg_polygon_t helperPolygon;
bg_multi_polygon_t currMP1, currMP2, resMP;
std::vector<DPoint> helperPointArray;

bool domain1IsVoid = (af & AF1_ISPARAM);
bool domain2IsVoid = (af & AF2_ISPARAM);
if (domain1IsVoid)
assign_multi_polygon(currMP1, arg1Data[0], true, helperPolygon, helperRing);
if (domain2IsVoid)
assign_multi_polygon(currMP2, arg2Data[0], true, helperPolygon, helperRing);

for (SizeT i = 0; i != n; ++i)
{
if (!domain1IsVoid)
assign_multi_polygon(currMP1, arg1Data[i], true, helperPolygon, helperRing);
if (!domain2IsVoid)
assign_multi_polygon(currMP2, arg2Data[i], true, helperPolygon, helperRing);
resMP.clear();
boost::geometry::intersection(currMP1, currMP2, resMP);
store_multi_polygon(resData[i], resMP, helperPointArray);
}
}
};

// *****************************************************************************
// simplify
// *****************************************************************************

class AbstrSimplifyOperator : public BinaryOperator
{
protected:
Expand Down Expand Up @@ -664,6 +725,10 @@ struct SimplifyLinestringOperator : public AbstrSimplifyOperator
}
};

// *****************************************************************************
// buffer
// *****************************************************************************

class AbstrBufferOperator : public TernaryOperator
{
protected:
Expand Down Expand Up @@ -1069,6 +1134,10 @@ struct BufferSinglePolygonOperator : public AbstrBufferOperator
}
};

// *****************************************************************************
// outer
// *****************************************************************************

class AbstrOuterOperator : public UnaryOperator
{
protected:
Expand Down Expand Up @@ -1195,6 +1264,7 @@ namespace
tl_oper::inst_tuple_templ<typelists::points, BufferPointOperator> bufferPointOperators;
tl_oper::inst_tuple_templ<typelists::points, BufferMultiPointOperator> bufferMultiPointOperators;
tl_oper::inst_tuple_templ<typelists::points, BufferLineStringOperator> bufferLineStringOperators;
tl_oper::inst_tuple_templ<typelists::points, BgIntersectMultiPolygonOperator> bgIntersectMultiPolygonOperators;

#if DMS_VERSION_MAJOR < 15
tl_oper::inst_tuple_templ<typelists::points, BufferSinglePolygonOperator, AbstrOperGroup&> bg_bufferPolygonOperators(grBgBuffer_polygon);
Expand Down
41 changes: 9 additions & 32 deletions geo/dll/src/PolyOper.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
//<HEADER>
/*
Data & Model Server (DMS) is a server written in H++ for DSS applications.
Version: see srv/dms/rtc/dll/src/RtcVersion.h for version info.
Copyright (C) 1998-2004 YUSE GSO Object Vision BV.
Documentation on using the Data & Model Server software can be found at:
http://www.ObjectVision.nl/DMS/
See additional guidelines and notes in srv/dms/Readme-srv.txt
This library is free software; you can use, redistribute, and/or
modify it under the terms of the GNU General Public License version 2
(the License) as published by the Free Software Foundation,
provided that this entire header notice and readme-srv.txt is preserved.
See LICENSE.TXT for terms of distribution or look at our web site:
http://www.objectvision.nl/DMS/License.txt
or alternatively at: http://www.gnu.org/copyleft/gpl.html
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details. However, specific warranties might be
granted by an additional written contract for support, assistance and/or development
*/
//</HEADER>
// Copyright (C) 1998-2024 Object Vision b.v.
// License: GNU GPL 3
/////////////////////////////////////////////////////////////////////////////

#if defined(_MSC_VER)
#pragma once
#endif

#if !defined(DMS_GEO_POLYOPER_H)
#define DMS_GEO_POLYOPER_H
Expand Down Expand Up @@ -124,7 +101,7 @@ void do_binary_poly_assign(

if (e1IsVoid)
{
dms_assert(arg1Data.size() == 1);
assert(arg1Data.size() == 1);

if (!IsDefined(arg1Data[0]))
fast_undefine(resData.begin(), resData.end());
Expand All @@ -148,11 +125,11 @@ void do_binary_poly_assign(
return;
}

dms_assert(arg1Data.size() == resData.size());
assert(arg1Data.size() == resData.size());

if (e2IsVoid)
{
dms_assert(arg2Data.size() == 1);
assert(arg2Data.size() == 1);

if (!IsDefined(arg2Data[0]))
fast_undefine(resData.begin(), resData.end());
Expand Down Expand Up @@ -204,7 +181,7 @@ struct BinaryPolyAttrAssignOper : BinaryAttrOper< typename PolyAttrOper::assigne
{
BinaryPolyAttrAssignOper(AbstrOperGroup* gr)
: BinaryAttrOper<typename PolyAttrOper::assignee_type, typename PolyAttrOper::arg1_type, typename PolyAttrOper::arg2_type>(gr
, &PolyAttrOper::unit_creator, composition_of_v<typename PolyAttrOper::assignee_type>, ArgFlags()
, &PolyAttrOper::unit_creator, composition_of_v<typename PolyAttrOper::assignee_type>
)
{}

Expand Down
24 changes: 11 additions & 13 deletions tic/dll/src/TreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2471,21 +2471,19 @@ void TreeItem::UpdateMetaInfoImpl2() const
m_UsingCache->GetNrUsings();
}
SetMetaInfoReady();
if (WasFailed(FR_MetaInfo))
return;

// Update Meta Info according to storage manager
const TreeItem* storageParent = GetStorageParent(false);
if (storageParent)
if (!WasFailed(FR_MetaInfo))
{
auto sm = storageParent->GetStorageManager();
sm->UpdateTree(storageParent, const_cast<TreeItem*>(this));
}
// validate units with refObject if it wasn't copied by the parent

// if (mc_RefItem && !GetTSF(TSF_InheritedRef) && !mc_Expr.empty())
// Unify(mc_RefItem);
// NotifyStateChange(this, NC2_MetaReady);
// Update Meta Info according to storage manager
const TreeItem* storageParent = GetStorageParent(false);
if (storageParent)
{
auto sm = storageParent->GetStorageManager();
sm->UpdateTree(storageParent, const_cast<TreeItem*>(this));
}
// validate units with refObject if it wasn't copied by the parent
}
ProcessMainThreadOpers();
}
catch (...)
{
Expand Down

0 comments on commit ab71348

Please sign in to comment.