Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions src/Draw/TKDraw/Draw/Draw_Viewer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,37 @@
#include <gp_Pnt2d.hxx>
#include <Draw_Window.hxx>
#include <Draw_Display.hxx>
#include <NCollection_Allocator.hxx>

#include <vector>

using XSegmentVectorType = std::vector<Draw_XSegment, NCollection_Allocator<Draw_XSegment>>;

#define precpers 0.95
#define ButtonPress 4
#define MotionNotify 6
static const double DRAWINFINITE = 1e50;
Standard_EXPORT bool Draw_Bounds = true;
extern bool Draw_Batch;
const int MAXSEGMENT = 1000;
Draw_XSegment segm[MAXSEGMENT];
static int nbseg = 0;
static Draw_View* curview = nullptr;
static int curviewId = 0;
static char blank[2] = "";
static double xmin, xmax, ymin, ymax;
static bool found = false;
static int xpick, ypick, precpick;
static gp_Pnt lastPickP1;
static gp_Pnt lastPickP2;
static double lastPickParam;
static Draw_Color highlightcol;
static Draw_Color currentcolor;
static bool highlight = false;
static int ps_vx, ps_vy;
static double ps_kx, ps_ky;
static int ps_px, ps_py;
static std::ostream* ps_stream;
static int ps_width[MAXCOLOR];
static double ps_gray[MAXCOLOR];
static const double DRAWINFINITE = 1e50;
Standard_EXPORT bool Draw_Bounds = true;
extern bool Draw_Batch;
static XSegmentVectorType segm(1000);
static Draw_View* curview = nullptr;
static int curviewId = 0;
static char blank[2] = "";
static double xmin, xmax, ymin, ymax;
static bool found = false;
static int xpick, ypick, precpick;
static gp_Pnt lastPickP1;
static gp_Pnt lastPickP2;
static double lastPickParam;
static Draw_Color highlightcol;
static Draw_Color currentcolor;
static bool highlight = false;
static int ps_vx, ps_vy;
static double ps_kx, ps_ky;
static int ps_px, ps_py;
static std::ostream* ps_stream;
static int ps_width[MAXCOLOR];
static double ps_gray[MAXCOLOR];

enum DrawingMode
{
Expand Down Expand Up @@ -887,7 +890,7 @@ Draw_Display Draw_Viewer::MakeDisplay(const int id) const
}
curviewId = id;
curview = myViews[id];
nbseg = 0;
segm.clear();
Draw_Color initcol(Draw_blanc);
// to force setting the color
currentcolor = Draw_Color(Draw_rouge);
Expand Down Expand Up @@ -1167,10 +1170,12 @@ void Draw_Flush()
{
if (Draw_Batch)
return;
if (segm.empty())
return;
if (highlight)
curview->SetColor(highlightcol.ID());
curview->DrawSegments(segm, nbseg);
nbseg = 0;
curview->DrawSegments(segm.data(), static_cast<int>(segm.size()));
segm.clear();
}

//=================================================================================================
Expand Down Expand Up @@ -1540,7 +1545,6 @@ void Draw_Display::DrawTo(const gp_Pnt2d& pp2)

case DRAW: {

#if 1
int x0, y0, x1, y1;
curview->GetFrame(x0, y0, x1, y1);

Expand All @@ -1555,23 +1559,12 @@ void Draw_Display::DrawTo(const gp_Pnt2d& pp2)

if (Trim(PI1, PI2, x0, y0, x1, y1))
{
segm[nbseg].Init(static_cast<int>(PI1.X() + curview->GetDx()),
static_cast<int>(-PI1.Y() - curview->GetDy()),
static_cast<int>(PI2.X() + curview->GetDx()),
static_cast<int>(-PI2.Y() - curview->GetDy()));
++nbseg;
}
#else
segm[nbseg].Init(static_cast<int>(p1.X() + curview->GetDx()),
static_cast<int>(-p1.Y() - curview->GetDy()),
static_cast<int>(p2.X() + curview->GetDx()),
static_cast<int>(-p2.Y() - curview->GetDy()));
nbseg++;
#endif
if (nbseg == MAXSEGMENT)
{
Draw_Flush();
segm.emplace_back(static_cast<short>(PI1.X() + curview->GetDx()),
static_cast<short>(-PI1.Y() - curview->GetDy()),
static_cast<short>(PI2.X() + curview->GetDx()),
static_cast<short>(-PI2.Y() - curview->GetDy()));
}

if (Draw_Bounds)
{
if (p2.X() > xmax)
Expand Down
8 changes: 8 additions & 0 deletions src/Draw/TKDraw/Draw/Draw_Window.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ struct Draw_XSegment
{
NCollection_Vec2<short> Points[2]; // same as XSegment

Draw_XSegment() = default;

Draw_XSegment(short theXStart, short theYStart, short theXEnd, short theYEnd)
: Points{NCollection_Vec2<short>(theXStart, theYStart),
NCollection_Vec2<short>(theXEnd, theYEnd)}
{
}

NCollection_Vec2<short>& operator[](int theIndex) { return Points[theIndex]; }

const NCollection_Vec2<short>& operator[](int theIndex) const { return Points[theIndex]; }
Expand Down
36 changes: 27 additions & 9 deletions src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_BuilderSolid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
static bool IsGrowthShell(const TopoDS_Shape&,
const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>&);
static bool IsHole(const TopoDS_Shape&, occ::handle<IntTools_Context>&);
static bool IsInside(const TopoDS_Shape&, const TopoDS_Shape&, occ::handle<IntTools_Context>&);
static bool IsInside(const TopoDS_Shape&,
const TopoDS_Shape&,
const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>&,
occ::handle<IntTools_Context>&);
static void MakeInternalShells(const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>&,
NCollection_List<TopoDS_Shape>&);

Expand Down Expand Up @@ -478,6 +481,19 @@ void BOPAlgo_BuilderSolid::PerformAreas(const Message_ProgressRange& theRange)
// Find outer growth shell that is most close to each hole shell
NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> aHoleSolidMap;

// Pre-compute edge bounds for each solid to avoid redundant TopExp::MapShapes
// calls when the same solid is checked against multiple holes.
NCollection_DataMap<TopoDS_Shape,
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>,
TopTools_ShapeMapHasher>
aSolidEdgesCache;
for (NCollection_List<TopoDS_Shape>::Iterator aIt(aNewSolids); aIt.More(); aIt.Next())
{
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> anEdges;
TopExp::MapShapes(aIt.Value(), TopAbs_EDGE, anEdges);
aSolidEdgesCache.Bind(aIt.Value(), anEdges);
}

Message_ProgressScope aPSH(aMainScope.Next(4), "Adding holes", aNewSolids.Size());
NCollection_List<TopoDS_Shape>::Iterator aItLS(aNewSolids);
for (; aItLS.More(); aItLS.Next(), aPSH.Next())
Expand All @@ -499,21 +515,24 @@ void BOPAlgo_BuilderSolid::PerformAreas(const Message_ProgressRange& theRange)
aSelector.SetBVHSet(&aBBTree);
aSelector.Select();

const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& aSolidEdges =
aSolidEdgesCache.Find(aSolid);

const NCollection_List<int>& aLI = aSelector.Indices();
NCollection_List<int>::Iterator aItLI(aLI);
for (; aItLI.More(); aItLI.Next())
{
int k = aItLI.Value();
const TopoDS_Shape& aHole = aHoleShells(k);
// Check if it is inside
if (!IsInside(aHole, aSolid, myContext))
if (!IsInside(aHole, aSolid, aSolidEdges, myContext))
continue;

// Save the relation
TopoDS_Shape* pSolidWas = aHoleSolidMap.ChangeSeek(aHole);
if (pSolidWas)
{
if (IsInside(aSolid, *pSolidWas, myContext))
if (IsInside(aSolid, *pSolidWas, aSolidEdgesCache.Find(*pSolidWas), myContext))
{
*pSolidWas = aSolid;
}
Expand Down Expand Up @@ -808,9 +827,10 @@ bool IsHole(const TopoDS_Shape& theS2, occ::handle<IntTools_Context>& theContext

//=================================================================================================

bool IsInside(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
occ::handle<IntTools_Context>& theContext)
bool IsInside(const TopoDS_Shape& theS1,
const TopoDS_Shape& theS2,
const NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>& theSolidEdges,
occ::handle<IntTools_Context>& theContext)
{
TopExp_Explorer aExp;
TopAbs_State aState;
Expand All @@ -826,11 +846,9 @@ bool IsInside(const TopoDS_Shape& theS1,
}
else
{
NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aBounds;
TopExp::MapShapes(*pS2, TopAbs_EDGE, aBounds);
const TopoDS_Face& aF = (*(TopoDS_Face*)(&aExp.Current()));
aState =
BOPTools_AlgoTools::ComputeState(aF, *pS2, Precision::Confusion(), aBounds, theContext);
BOPTools_AlgoTools::ComputeState(aF, *pS2, Precision::Confusion(), theSolidEdges, theContext);
}
return (aState == TopAbs_IN);
}
Expand Down
38 changes: 34 additions & 4 deletions src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_6.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,38 @@ void BOPAlgo_PaveFiller::PerformFF(const Message_ProgressRange& theRange)
BRep_Tool::Triangulation(aF2, aLocation2);
const bool anIsPlane2 = IsPlaneFF(aSurface2);

// Pre-compute edge closedness for each face to avoid redundant IsClosedFF calls
// in the inner loop (O(N1*N2) -> O(N1+N2) + O(1) lookups).
NCollection_DataMap<int, bool> aClosedMap1, aClosedMap2;
for (TopoDS_Iterator aItW(aF1); aItW.More(); aItW.Next())
{
for (TopoDS_Iterator aItE(aItW.Value()); aItE.More(); aItE.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(aItE.Value());
const int anEdgeIdx = myDS->Index(anEdge);
if (!aClosedMap1.IsBound(anEdgeIdx))
{
aClosedMap1.Bind(
anEdgeIdx,
IsClosedFF(anEdge, aSurface1, aTriangulation1, aLocation1, anIsPlane1));
}
}
}
for (TopoDS_Iterator aItW(aF2); aItW.More(); aItW.Next())
{
for (TopoDS_Iterator aItE(aItW.Value()); aItE.More(); aItE.Next())
{
const TopoDS_Edge& anEdge = TopoDS::Edge(aItE.Value());
const int anEdgeIdx = myDS->Index(anEdge);
if (!aClosedMap2.IsBound(anEdgeIdx))
{
aClosedMap2.Bind(
anEdgeIdx,
IsClosedFF(anEdge, aSurface2, aTriangulation2, aLocation2, anIsPlane2));
}
}
}

bool anIsFound = false;
for (TopoDS_Iterator aItW1(aF1); !anIsFound && aItW1.More(); aItW1.Next())
{
Expand All @@ -430,10 +462,8 @@ void BOPAlgo_PaveFiller::PerformFF(const Message_ProgressRange& theRange)
const TopoDS_Edge& anEdge2 = TopoDS::Edge(aItE2.Value());
const int anEdgeIndex2 = myDS->Index(anEdge2);

const bool anIsClosed1 =
IsClosedFF(anEdge1, aSurface1, aTriangulation1, aLocation1, anIsPlane1);
const bool anIsClosed2 =
IsClosedFF(anEdge2, aSurface2, aTriangulation2, aLocation2, anIsPlane2);
const bool anIsClosed1 = aClosedMap1.Find(anEdgeIndex1);
const bool anIsClosed2 = aClosedMap2.Find(anEdgeIndex2);
if (!anIsClosed1 && !anIsClosed2)
{
continue;
Expand Down
3 changes: 3 additions & 0 deletions tests/boolean/bopcommon_complex/D1
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ bopcommon result

checkprops result -s 152908
checkview -display result -2d -otherwise { sh_2 sh_1 } -s -path ${imagedir}/${test_image}.png

# test boolean bopcommon_complex D1 -echo

Loading