Skip to content

Commit

Permalink
This changes an observer to use Progress instead
Browse files Browse the repository at this point in the history
  • Loading branch information
azundel authored and gagelarsen committed Nov 6, 2018
1 parent 971e790 commit bbf27a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 50 deletions.
55 changes: 14 additions & 41 deletions xmsinterp/triangulate/TrBreaklineAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// 4. External library headers

// 5. Shared code headers
#include <xmscore/misc/Progress.h>
#include <xmscore/stl/set.h>
#include <xmscore/stl/vector.h>
#include <xmsinterp/geometry/geoms.h>
Expand Down Expand Up @@ -181,18 +182,9 @@ void TrBreaklineAdderImpl::SetTin(BSHP<TrTin> a_tin, double a_tol /*-1*/)
void TrBreaklineAdderImpl::AddBreakline(const VecInt& a_breakline)
{
XM_ENSURE_TRUE_T_NO_ASSERT(m_tin, std::runtime_error("No tin set in TrBreaklineAdder."));

bool progressStarted = false;
if (m_observer)
{
if (m_totNumSegs < 1)
{
m_observer->BeginOperationString("Adding Breaklines");
progressStarted = true;
m_totNumSegs = a_breakline.size() - 1;
m_segCount = 0;
}
}
Progress prog("Adding Breaklines");
double totNumSegs = static_cast<double>(a_breakline.size() - 1);
double segCount(0.0);

for (size_t pt = 1; pt < a_breakline.size(); ++pt)
{
Expand All @@ -202,18 +194,9 @@ void TrBreaklineAdderImpl::AddBreakline(const VecInt& a_breakline)
{
ProcessSegmentBySwapping(pt1, pt2);
}
if (m_observer)
{
m_observer->ProgressStatus(m_segCount / (double)m_totNumSegs);
m_segCount++;
}
}

if (m_observer && progressStarted)
{
m_observer->EndOperation();
segCount += 1.0;
prog.ProgressStatus(std::min(1.0, segCount / totNumSegs));
}

} // TrBreaklineAdderImpl::AddBreakline
//------------------------------------------------------------------------------
/// \brief Add breaklines by swapping. Compare to bkProcessScatBySwapping.
Expand All @@ -224,29 +207,19 @@ void TrBreaklineAdderImpl::AddBreakline(const VecInt& a_breakline)
void TrBreaklineAdderImpl::AddBreaklines(const VecInt2d& a_breaklines)
{
XM_ENSURE_TRUE_T_NO_ASSERT(m_tin, std::runtime_error("No tin set in TrBreaklineAdder."));

if (m_observer)
Progress prog("Adding Breaklines");
size_t segCount(0);
size_t totNumSegs(0);
for (size_t i = 0; i < a_breaklines.size(); ++i)
{
m_observer->BeginOperationString("Adding Breaklines");
m_segCount = 0;
m_totNumSegs = 0;
for (size_t i = 0; i < a_breaklines.size(); ++i)
{
m_totNumSegs += a_breaklines[i].size() - 1;
}
totNumSegs += a_breaklines[i].size() - 1;
}

double total = static_cast<double>(totNumSegs);
for (size_t i = 0; i < a_breaklines.size(); ++i)
{
segCount += a_breaklines[i].size() - 1;
AddBreakline(a_breaklines[i]);
}

m_segCount = 0;
m_totNumSegs = 0;

if (m_observer)
{
m_observer->EndOperation();
prog.ProgressStatus(static_cast<double>(segCount) / total);
}
} // TrBreaklineAdderImpl::AddBreaklines
//------------------------------------------------------------------------------
Expand Down
9 changes: 0 additions & 9 deletions xmsinterp/triangulate/TrTriangulatorPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ void TrTriangulatorPoints::IncrementPoint()
//------------------------------------------------------------------------------
void TrTriangulatorPoints::PrepareToReceiveTriangles()
{
if (m_observer)
m_observer->BeginOperationString("Triangulating Points");
if (m_trisAdjToPts)
{
m_trisAdjToPts->resize(m_pts.size(), VecInt());
Expand All @@ -159,8 +157,6 @@ void TrTriangulatorPoints::PrepareToReceiveTriangles()
//------------------------------------------------------------------------------
void TrTriangulatorPoints::FinalizeTriangulation()
{
if (m_observer)
m_observer->EndOperation();
stShrinkCapacity(m_tris);
if (m_trisAdjToPts)
{
Expand Down Expand Up @@ -193,11 +189,6 @@ void TrTriangulatorPoints::ReceiveTriangle(int a_id1, int a_id2, int a_id3)
(*m_trisAdjToPts)[a_id2 - 1].push_back(triIdx);
(*m_trisAdjToPts)[a_id3 - 1].push_back(triIdx);
}
if (m_observer)
{
double prog = std::min(m_tris.size() / (double)(m_pts.size() * 2), 1.0);
m_observer->ProgressStatus(prog);
}
} // TrTriangulatorPoints::ReceiveTriangle
//------------------------------------------------------------------------------
/// \brief calculates the area tolerance
Expand Down
6 changes: 6 additions & 0 deletions xmsinterp/triangulate/detail/triangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// 4. External library headers

// 5. Shared code headers
#include <xmscore/misc/Progress.h>
#include <xmscore/misc/XmLog.h> // XM_LOG
#include <xmsinterp/triangulate/TrTriangulator.h>

Expand Down Expand Up @@ -921,8 +922,11 @@ static void triFillTriList(TrTriangulator& a_Client, TriVars& t)
Tedge triangleloop;
Tpt p1, p2, p3;

Progress prog("Triangulating Points");
// prepare to recieve trianlges
a_Client.PrepareToReceiveTriangles();
double triCount(0.0);
double total = static_cast<double>(a_Client.GetNPoints());

triTraversalInit(&t.m_triangles);
triangleloop.tri = triTriangleTraverse(t);
Expand All @@ -939,6 +943,8 @@ static void triFillTriList(TrTriangulator& a_Client, TriVars& t)

// recieve the triangle
a_Client.ReceiveTriangle(id1, id2, id3);
triCount += 2.0;
prog.ProgressStatus(std::min(1.0, triCount / total));

triangleloop.tri = triTriangleTraverse(t);
}
Expand Down

0 comments on commit bbf27a9

Please sign in to comment.