@@ -143,6 +143,10 @@ class GmTriSearchImpl : public GmTriSearch
143
143
virtual bool InterpWeights (const Pt3d& a_pt,
144
144
std::vector<int >& a_idxs,
145
145
std::vector<double >& a_wts) override ;
146
+ virtual bool InterpWeightsTriangleIdx (const Pt3d& a_pt,
147
+ int & a_triangleIdx,
148
+ std::vector<int >& a_idxs,
149
+ std::vector<double >& a_wts) override ;
146
150
147
151
virtual std::string ToString () const override ;
148
152
@@ -419,11 +423,28 @@ void GmTriSearchImpl::TriEnvelopesOverlap(const Pt3d& a_pMin, const Pt3d& a_pMax
419
423
// / \return false if a_pt is not inside of any triangle
420
424
// ------------------------------------------------------------------------------
421
425
bool GmTriSearchImpl::InterpWeights (const Pt3d& a_pt, VecInt& a_idxs, VecDbl& a_wts)
426
+ {
427
+ int triangleIdx;
428
+ bool result = InterpWeightsTriangleIdx (a_pt, triangleIdx, a_idxs, a_wts);
429
+ return result;
430
+ } // GmTriSearchImpl::InterpWeights
431
+ // ------------------------------------------------------------------------------
432
+ // / \brief Use the stored triangles to get interpolation weights for a point.
433
+ // / Returns false if the point is outside the triangles.
434
+ // / \param a_pt Location that is interpolated to.
435
+ // / \param a_triangleIdx Found triangles index in triangle array
436
+ // / (zero based count*3).
437
+ // / \param a_idxs Vector of triangle point indices filled in by this method.
438
+ // / \param a_wts Vector of triangle point weights filled in by this method.
439
+ // / \return false if a_pt is not inside of any triangle
440
+ // ------------------------------------------------------------------------------
441
+ bool GmTriSearchImpl::InterpWeightsTriangleIdx (const Pt3d& a_pt, int & a_triangleIdx,
442
+ VecInt& a_idxs, VecDbl& a_wts)
422
443
{
423
444
int ix[3 ];
424
445
Pt3d weights;
425
- int idx = FindTriangle (a_pt, ix, weights);
426
- if (idx != XM_NONE)
446
+ a_triangleIdx = FindTriangle (a_pt, ix, weights);
447
+ if (a_triangleIdx != XM_NONE)
427
448
{
428
449
a_wts.resize (0 );
429
450
a_wts.push_back (weights.x );
@@ -432,8 +453,13 @@ bool GmTriSearchImpl::InterpWeights(const Pt3d& a_pt, VecInt& a_idxs, VecDbl& a_
432
453
a_idxs.assign (ix, ix + 3 );
433
454
return true ;
434
455
}
456
+ else
457
+ {
458
+ a_idxs.clear ();
459
+ a_wts.clear ();
460
+ }
435
461
return false ;
436
- } // GmTriSearchImpl::InterpWeights
462
+ } // GmTriSearchImpl::InterpWeightsTriangleIdx
437
463
// ------------------------------------------------------------------------------
438
464
// / \brief Write the internals to a string.
439
465
// / \return The string.
@@ -635,11 +661,24 @@ void TriSearchUnitTests::testInterpWeights()
635
661
std::vector<int > idxs, baseIdx;
636
662
std::vector<double > wt, baseWt;
637
663
Pt3d pt (.5 , .2 , 0 );
638
- tris->InterpWeights (pt, idxs, wt);
664
+ TS_ASSERT ( tris->InterpWeights (pt, idxs, wt) );
639
665
baseIdx = {0 , 2 , 1 };
640
666
baseWt = {.5 , .3 , .2 };
641
667
TS_ASSERT_EQUALS_VEC (baseIdx, idxs);
642
668
TS_ASSERT_DELTA_VEC (baseWt, wt, 1e-7 );
669
+
670
+ int triangleIdx;
671
+ TS_ASSERT (tris->InterpWeightsTriangleIdx ({.25 , .75 , 0 }, triangleIdx, idxs, wt));
672
+ TS_ASSERT_EQUALS (3 , triangleIdx);
673
+ baseIdx = {0 , 1 , 3 };
674
+ TS_ASSERT_EQUALS_VEC (baseIdx, idxs);
675
+ baseWt = {.25 , .25 , .5 };
676
+ TS_ASSERT_DELTA_VEC (baseWt, wt, 1e-7 );
677
+
678
+ TS_ASSERT (!tris->InterpWeightsTriangleIdx ({0 , 1.25 , 0 }, triangleIdx, idxs, wt));
679
+ TS_ASSERT_EQUALS (XM_NONE, triangleIdx);
680
+ TS_ASSERT_EQUALS_VEC (VecInt (), idxs);
681
+ TS_ASSERT_DELTA_VEC (VecDbl (), wt, 1e-7 );
643
682
} // TriSearchUnitTests::testInterpWeights
644
683
// ------------------------------------------------------------------------------
645
684
// / \brief tests setting the point activity
0 commit comments