xmsextractor  1.0
XmUGrid2dDataExtractor.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
6 //------------------------------------------------------------------------------
7 
8 //----- Included files ---------------------------------------------------------
9 
10 // 1. Precompiled header
11 
12 // 2. My own header
14 
15 // 3. Standard library headers
16 #include <sstream>
17 
18 // 4. External library headers
19 
20 // 5. Shared code headers
21 #include <xmscore/misc/XmError.h>
22 #include <xmscore/misc/XmLog.h>
23 #include <xmscore/misc/xmstype.h>
25 #include <xmsgrid/ugrid/XmUGrid.h>
26 #include <xmsgrid/geometry/geoms.h>
27 #include <xmsgrid/geometry/GmTriSearch.h>
28 #include <xmsinterp/interpolate/InterpUtil.h>
29 
30 // 6. Non-shared code headers
32 
33 //----- Forward declarations ---------------------------------------------------
34 
35 //----- External globals -------------------------------------------------------
36 
37 //----- Namespace declaration --------------------------------------------------
38 
40 namespace xms
41 {
42 //----- Constants / Enumerations -----------------------------------------------
43 
44 //----- Classes / Structs ------------------------------------------------------
45 
46 //----- Internal functions -----------------------------------------------------
47 
48 //----- Class / Function definitions -------------------------------------------
49 
53 {
54 public:
55  XmUGrid2dDataExtractorImpl(std::shared_ptr<XmUGrid> a_ugrid);
56  XmUGrid2dDataExtractorImpl(BSHP<XmUGrid2dDataExtractorImpl> a_extractor);
57 
58  virtual void SetGridPointScalars(const VecFlt& a_pointScalars,
59  const DynBitset& a_activity,
60  DataLocationEnum a_activityLocation) override;
61  virtual void SetGridCellScalars(const VecFlt& a_cellScalars,
62  const DynBitset& a_activity,
63  DataLocationEnum a_activityLocation) override;
64 
65  virtual void SetExtractLocations(const VecPt3d& a_locations) override;
66  virtual void ExtractData(VecFlt& a_outData) override;
67  virtual float ExtractAtLocation(const Pt3d& a_location) override;
68 
69  virtual void SetUseIdwForPointData(bool a_) override;
70  virtual void SetNoDataValue(float a_value) override;
71 
72  virtual void BuildTriangles(DataLocationEnum a_location) override;
73  virtual const BSHP<XmUGridTriangles2d> GetUGridTriangles() const override;
74 
77  virtual const VecFlt& GetScalars() const override { return m_pointScalars; }
80  virtual DataLocationEnum GetScalarLocation() const override { return m_triangleType; }
83  virtual const VecPt3d& GetExtractLocations() const override { return m_extractLocations; }
86  virtual const VecInt& GetCellIndexes() const { return m_cellIdxs; }
89  virtual bool GetUseIdwForPointData() const override { return m_useIdwForPointData; }
92  virtual float GetNoDataValue() const override { return m_noDataValue; }
93 
94 private:
95  void ApplyActivity(const DynBitset& a_activity,
96  DataLocationEnum a_location,
97  DynBitset& a_cellActivity);
98  void SetGridPointActivity(const DynBitset& a_pointActivity, DynBitset& a_cellActivity);
99  void SetGridCellActivity(const DynBitset& a_cellActivity);
100  void PushPointDataToCentroids(const DynBitset& a_cellActivity);
101  void PushCellDataToTrianglePoints(const VecFlt& a_cellScalars, const DynBitset& a_cellActivity);
102  float CalculatePointByAverage(const VecInt& a_cellIdxs,
103  const VecFlt& a_cellScalars,
104  const DynBitset& a_cellActivity);
105  float CalculatePointByIdw(int a_pointIdx,
106  const VecInt& a_cellIdxs,
107  const VecFlt& a_cellScalars,
108  const DynBitset& a_cellActivity);
109 
110  std::shared_ptr<XmUGrid> m_ugrid;
112  BSHP<XmUGridTriangles2d>
115  VecFlt m_pointScalars;
116  VecInt m_cellIdxs;
119 };
120 
126 //------------------------------------------------------------------------------
129 //------------------------------------------------------------------------------
131 : m_ugrid(a_ugrid)
132 , m_triangleType(LOC_UNKNOWN)
134 , m_extractLocations()
135 , m_pointScalars()
136 , m_cellIdxs()
137 , m_useIdwForPointData(false)
138 , m_noDataValue(XM_NODATA)
139 {
140 } // XmUGrid2dDataExtractorImpl::XmUGrid2dDataExtractorImpl
141 //------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------
147 XmUGrid2dDataExtractorImpl::XmUGrid2dDataExtractorImpl(BSHP<XmUGrid2dDataExtractorImpl> a_extractor)
148 : m_ugrid(a_extractor->m_ugrid)
149 , m_triangleType(a_extractor->m_triangleType)
150 , m_triangles(a_extractor->m_triangles)
151 , m_extractLocations()
152 , m_pointScalars()
153 , m_cellIdxs()
154 , m_useIdwForPointData(a_extractor->m_useIdwForPointData)
155 , m_noDataValue(a_extractor->m_noDataValue)
156 {
157 } // XmUGrid2dDataExtractorImpl::XmUGrid2dDataExtractorImpl
158 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 void XmUGrid2dDataExtractorImpl::SetGridPointScalars(const VecFlt& a_pointScalars,
166  const DynBitset& a_activity,
167  DataLocationEnum a_activityLocation)
168 {
169  if (a_pointScalars.size() != m_ugrid->GetPointCount())
170  {
171  XM_LOG(xmlog::debug, "Invalid point scalar size in 2D data extractor.");
172  }
173 
174  BuildTriangles(LOC_POINTS);
175 
176  DynBitset cellActivity;
177  ApplyActivity(a_activity, a_activityLocation, cellActivity);
178 
179  m_pointScalars = a_pointScalars;
180  PushPointDataToCentroids(cellActivity);
181 } // XmUGrid2dDataExtractorImpl::SetGridPointScalars
182 //------------------------------------------------------------------------------
188 //------------------------------------------------------------------------------
189 void XmUGrid2dDataExtractorImpl::SetGridCellScalars(const VecFlt& a_cellScalars,
190  const DynBitset& a_activity,
191  DataLocationEnum a_activityLocation)
192 {
193  if ((int)a_cellScalars.size() != m_ugrid->GetCellCount())
194  {
195  XM_LOG(xmlog::debug, "Invalid cell scalar size in 2D data extractor.");
196  }
197 
198  BuildTriangles(LOC_CELLS);
199 
200  DynBitset cellActivity;
201  ApplyActivity(a_activity, a_activityLocation, cellActivity);
202 
203  PushCellDataToTrianglePoints(a_cellScalars, cellActivity);
204 } // XmUGrid2dDataExtractorImpl::SetGridCellScalars
205 //------------------------------------------------------------------------------
208 //------------------------------------------------------------------------------
209 void XmUGrid2dDataExtractorImpl::SetExtractLocations(const VecPt3d& a_locations)
210 {
211  m_extractLocations = a_locations;
212 } // XmUGrid2dDataExtractorImpl::SetExtractLocations
213 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
218 {
219  a_outData.clear();
220 
221  a_outData.reserve(m_extractLocations.size());
222  m_cellIdxs.assign(m_extractLocations.size(), -1);
223  int cnt(0);
224  VecInt interpIdxs;
225  VecDbl interpWeights;
226  for (const auto& pt : m_extractLocations)
227  {
228  int cellIdx = m_triangles->GetIntersectedCell(pt, interpIdxs, interpWeights);
229  m_cellIdxs[cnt] = cellIdx;
230  cnt++;
231  if (cellIdx >= 0)
232  {
233  double interpValue = 0.0;
234  for (size_t i = 0; i < interpIdxs.size(); ++i)
235  {
236  int ptIdx = interpIdxs[i];
237  double weight = interpWeights[i];
238  float scalar = m_pointScalars[ptIdx];
239  interpValue += scalar * weight;
240  }
241  a_outData.push_back(static_cast<float>(interpValue));
242  }
243  else
244  {
245  a_outData.push_back(m_noDataValue);
246  }
247  }
248 } // XmUGrid2dDataExtractorImpl::ExtractData
249 //------------------------------------------------------------------------------
253 //------------------------------------------------------------------------------
255 {
256  VecPt3d locations(1, a_location);
257  SetExtractLocations(locations);
258  VecFlt values;
259  ExtractData(values);
260  return values[0];
261 } // XmUGrid2dDataExtractorImpl::ExtractAtLocation
262 //------------------------------------------------------------------------------
265 //------------------------------------------------------------------------------
267 {
268  m_useIdwForPointData = a_useIdw;
269 } // XmUGrid2dDataExtractorImpl::SetUseIdwForPointData
270 //------------------------------------------------------------------------------
274 //------------------------------------------------------------------------------
276 {
277  m_noDataValue = a_value;
278 } // XmUGrid2dDataExtractorImpl::SetNoDataValue
279 //------------------------------------------------------------------------------
284 //------------------------------------------------------------------------------
285 void XmUGrid2dDataExtractorImpl::ApplyActivity(const DynBitset& a_activity,
286  DataLocationEnum a_location,
287  DynBitset& a_cellActivity)
288 {
289  if (a_activity.empty())
290  {
291  // when empty, everything gets enabled on the cells
292  a_cellActivity = a_activity;
293  SetGridCellActivity(a_cellActivity);
294  }
295  else
296  {
297  if (a_location == LOC_POINTS)
298  {
299  SetGridPointActivity(a_activity, a_cellActivity);
300  }
301  else if (a_location == LOC_CELLS)
302  {
303  SetGridCellActivity(a_activity);
304  a_cellActivity = a_activity;
305  }
306  }
307 } // XmUGrid2dDataExtractorImpl::ApplyActivity
308 //------------------------------------------------------------------------------
313 //------------------------------------------------------------------------------
314 void XmUGrid2dDataExtractorImpl::SetGridPointActivity(const DynBitset& a_pointActivity,
315  DynBitset& a_cellActivity)
316 {
317  if (a_pointActivity.size() != m_ugrid->GetPointCount() && !a_pointActivity.empty())
318  {
319  XM_LOG(xmlog::debug, "Invalid point activity size in 2D data extractor.");
320  }
321 
322  if (a_pointActivity.empty())
323  {
324  a_cellActivity = a_pointActivity;
325  m_triangles->SetCellActivity(a_cellActivity);
326  return;
327  }
328 
329  a_cellActivity.reset();
330  a_cellActivity.resize(m_ugrid->GetCellCount(), true);
331  VecInt attachedCells;
332  int numPoints = m_ugrid->GetPointCount();
333  for (int pointIdx = 0; pointIdx < numPoints; ++pointIdx)
334  {
335  if (pointIdx < a_pointActivity.size() && !a_pointActivity[pointIdx])
336  {
337  m_ugrid->GetPointAdjacentCells(pointIdx, attachedCells);
338  for (auto cellIdx : attachedCells)
339  {
340  a_cellActivity[cellIdx] = false;
341  }
342  }
343  }
344  m_triangles->SetCellActivity(a_cellActivity);
345 } // XmUGrid2dDataExtractorImpl::SetGridPointActivity
346 //------------------------------------------------------------------------------
349 //------------------------------------------------------------------------------
350 void XmUGrid2dDataExtractorImpl::SetGridCellActivity(const DynBitset& a_cellActivity)
351 {
352  if (a_cellActivity.size() != m_ugrid->GetCellCount() && !a_cellActivity.empty())
353  {
354  XM_LOG(xmlog::debug, "Invalid cell activity size in 2D data extractor.");
355  }
356  m_triangles->SetCellActivity(a_cellActivity);
357 } // XmUGrid2dDataExtractorImpl::SetGridCellActivity
358 //------------------------------------------------------------------------------
361 //------------------------------------------------------------------------------
362 void XmUGrid2dDataExtractorImpl::PushPointDataToCentroids(const DynBitset& a_cellActivity)
363 {
364  // default any missing scalar values to zero
365  m_pointScalars.resize(m_triangles->GetPoints().size(), 0.0);
366 
367  VecInt cellPoints;
368  int numCells = m_ugrid->GetCellCount();
369  for (int cellIdx = 0; cellIdx < numCells; ++cellIdx)
370  {
371  if (a_cellActivity.empty() || a_cellActivity[cellIdx])
372  {
373  int centroidIdx = m_triangles->GetCellCentroid(cellIdx);
374  if (centroidIdx >= 0)
375  {
376  m_ugrid->GetCellPoints(cellIdx, cellPoints);
377  double sum = 0.0;
378  for (auto ptIdx : cellPoints)
379  sum += m_pointScalars[ptIdx];
380  double average = sum / cellPoints.size();
381  m_pointScalars[centroidIdx] = static_cast<float>(average);
382  }
383  }
384  }
385 } // XmUGrid2dDataExtractorImpl::PushPointDataToCentroids
386 //------------------------------------------------------------------------------
391 //------------------------------------------------------------------------------
393  const DynBitset& a_cellActivity)
394 {
395  m_pointScalars.resize(m_triangles->GetPoints().size());
396  VecInt cellIdxs;
397  int numPoints = m_ugrid->GetPointCount();
398  for (int pointIdx = 0; pointIdx < numPoints; ++pointIdx)
399  {
400  m_ugrid->GetPointAdjacentCells(pointIdx, cellIdxs);
402  {
403  m_pointScalars[pointIdx] =
404  CalculatePointByIdw(pointIdx, cellIdxs, a_cellScalars, a_cellActivity);
405  }
406  else
407  {
408  m_pointScalars[pointIdx] = CalculatePointByAverage(cellIdxs, a_cellScalars, a_cellActivity);
409  }
410  }
411 
412  int numCells = m_ugrid->GetCellCount();
413  for (int cellIdx = 0; cellIdx < numCells; ++cellIdx)
414  {
415  int pointIdx = m_triangles->GetCellCentroid(cellIdx);
416  if (pointIdx >= 0)
417  m_pointScalars[pointIdx] = cellIdx >= a_cellScalars.size() ? 0.0f : a_cellScalars[cellIdx];
418  }
419 } // XmUGrid2dDataExtractorImpl::PushCellDataToTrianglePoints
420 //------------------------------------------------------------------------------
426 //------------------------------------------------------------------------------
428  const VecFlt& a_cellScalars,
429  const DynBitset& a_cellActivity)
430 {
431  double sum = 0.0;
432  int sumCount = 0;
433  for (auto cellIdx : a_cellIdxs)
434  {
435  if (cellIdx >= a_cellActivity.size() || a_cellActivity[cellIdx])
436  {
437  sum += cellIdx >= a_cellScalars.size() ? 0.0 : a_cellScalars[cellIdx];
438  ++sumCount;
439  }
440  }
441  double average;
442  if (sumCount)
443  average = sum / sumCount;
444  else
445  average = m_noDataValue;
446  return static_cast<float>(average);
447 } // XmUGrid2dDataExtractorImpl::CalculatePointByAverage
448 //------------------------------------------------------------------------------
455 //------------------------------------------------------------------------------
457  const VecInt& a_cellIdxs,
458  const VecFlt& a_cellScalars,
459  const DynBitset& a_cellActivity)
460 {
461  Pt3d pt = m_ugrid->GetPointLocation(a_pointIdx);
462  VecInt cellCentroids;
463  for (auto cellIdx : a_cellIdxs)
464  {
465  int centroidIdx = m_triangles->GetCellCentroid(cellIdx);
466  if (0 <= centroidIdx && a_cellActivity[cellIdx])
467  {
468  cellCentroids.push_back(centroidIdx);
469  }
470  }
471  if (!cellCentroids.empty())
472  {
473  VecDbl d2;
474  VecDbl weights;
475  inDistanceSquared(pt, cellCentroids, m_triangles->GetPoints(), true, d2);
476  inIdwWeights(d2, 2, false, weights);
477 
478  double interpValue = 0.0;
479  for (size_t cellIdx = 0; cellIdx < cellCentroids.size(); ++cellIdx)
480  {
481  int ptIdx = cellCentroids[cellIdx];
482  double weight = weights[cellIdx];
483  interpValue += a_cellScalars[cellIdx] * weight;
484  }
485  return static_cast<float>(interpValue);
486  }
487  else
488  {
489  return CalculatePointByAverage(a_cellIdxs, a_cellScalars, a_cellActivity);
490  }
491 } // XmUGrid2dDataExtractorImpl::CalculatePointByIdw
492 //------------------------------------------------------------------------------
495 //------------------------------------------------------------------------------
497 {
498  if (m_triangleType != a_location)
499  {
500  bool triangleCentroids = a_location == LOC_CELLS;
501  m_triangles->BuildTriangles(*m_ugrid, triangleCentroids);
502  m_triangleType = a_location;
503  }
504 } // XmUGrid2dDataExtractorImpl::BuildTriangles
505 //------------------------------------------------------------------------------
508 //------------------------------------------------------------------------------
509 const BSHP<XmUGridTriangles2d> XmUGrid2dDataExtractorImpl::GetUGridTriangles() const
510 {
511  return m_triangles;
512 } // XmUGrid2dDataExtractorImpl::GetUGridTriangles
513 
519 //------------------------------------------------------------------------------
523 //------------------------------------------------------------------------------
524 BSHP<XmUGrid2dDataExtractor> XmUGrid2dDataExtractor::New(std::shared_ptr<XmUGrid> a_ugrid)
525 {
526  BSHP<XmUGrid2dDataExtractor> extractor(new XmUGrid2dDataExtractorImpl(a_ugrid));
527  return extractor;
528 } // XmUGrid2dDataExtractor::New
529 //------------------------------------------------------------------------------
534 //------------------------------------------------------------------------------
535 BSHP<XmUGrid2dDataExtractor> XmUGrid2dDataExtractor::New(BSHP<XmUGrid2dDataExtractor> a_extractor)
536 {
537  BSHP<XmUGrid2dDataExtractorImpl> copied = BDPC<XmUGrid2dDataExtractorImpl>(a_extractor);
538  if (copied)
539  {
540  BSHP<XmUGrid2dDataExtractor> extractor(new XmUGrid2dDataExtractorImpl(copied));
541  return extractor;
542  }
543 
544  XM_ASSERT(0);
545  return nullptr;
546 } // XmUGrid2dDataExtractor::New
547 //------------------------------------------------------------------------------
549 //------------------------------------------------------------------------------
551 {
552 } // XmUGrid2dDataExtractor::XmUGrid2dDataExtractor
553 //------------------------------------------------------------------------------
555 //------------------------------------------------------------------------------
557 {
558 } // XmUGrid2dDataExtractor::~XmUGrid2dDataExtractor
559 
560 } // namespace xms
561 
562 #ifdef CXX_TEST
563 //------------------------------------------------------------------------------
564 // Unit Tests
565 //------------------------------------------------------------------------------
566 using namespace xms;
568 
569 #include <xmscore/testing/TestTools.h>
570 
575 //------------------------------------------------------------------------------
577 //------------------------------------------------------------------------------
579 {
580  // 3----2
581  // | 1 /|
582  // | / |
583  // | / |
584  // |/ 0 |
585  // 0----1
586  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
587  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
588  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
589  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
590  TS_ASSERT(extractor);
591  extractor->SetNoDataValue(-999.0);
592 
593  VecFlt pointScalars = {1, 2, 3, 2};
594  extractor->SetGridPointScalars(pointScalars, DynBitset(), LOC_POINTS);
595  VecPt3d extractLocations = {
596  {0.0, 0.0, 0.0}, {0.25, 0.75, 100.0}, {0.5, 0.5, 0.0}, {0.75, 0.25, -100.0}, {-1.0, -1.0, 0.0}};
597  extractor->SetExtractLocations(extractLocations);
598 
599  VecFlt interpValues;
600  extractor->ExtractData(interpValues);
601  VecFlt expected = {1.0, 2.0, 2.0, 2.0, -999.0};
602  TS_ASSERT_EQUALS(expected, interpValues);
603 } // XmUGrid2dDataExtractorUnitTests::testScalarsOnly
604 //------------------------------------------------------------------------------
606 //------------------------------------------------------------------------------
608 {
609  // 3----2
610  // | 1 /|
611  // | / |
612  // | / |
613  // |/ 0 |
614  // 0----1
615  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
616  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
617  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
618  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
619  TS_ASSERT(extractor);
620 
621  VecFlt pointScalars = {1, 2, 3, 2};
622  DynBitset cellActivity;
623  cellActivity.push_back(true);
624  cellActivity.push_back(false);
625  extractor->SetGridPointScalars(pointScalars, cellActivity, LOC_CELLS);
626  extractor->SetExtractLocations({{0.25, 0.75, 100.0}, {0.75, 0.25, -100.0}, {-1.0, -1.0, 0.0}});
627 
628  VecFlt interpValues;
629  extractor->ExtractData(interpValues);
630  VecFlt expected = {XM_NODATA, 2.0, XM_NODATA};
631  TS_ASSERT_EQUALS(expected, interpValues);
632 } // XmUGrid2dDataExtractorUnitTests::testPointScalarCellActivity
633 //------------------------------------------------------------------------------
635 //------------------------------------------------------------------------------
637 {
638  // clang-format off
651  VecPt3d points = {
652  {0, 0, 0}, {1, 0, 0}, {3, 0, 0}, // row 1 of points
653  {0, 1, 0}, {2, 1, 0}, {3, 1, 0}, // row 2 of points
654  {0, 2, 0}, {1, 2, 0}, {3, 2, 0}}; // row 3 of points
655  VecInt cells = {
656  XMU_TRIANGLE, 3, 0, 1, 3, // row 1 of triangles
657  XMU_TRIANGLE, 3, 1, 4, 3,
658  XMU_TRIANGLE, 3, 1, 2, 4,
659  XMU_TRIANGLE, 3, 2, 5, 4,
660 
661  XMU_TRIANGLE, 3, 3, 7, 6, // row 2 of triangles
662  XMU_TRIANGLE, 3, 3, 4, 7,
663  XMU_TRIANGLE, 3, 4, 8, 7,
664  XMU_TRIANGLE, 3, 4, 5, 8};
665 
666  VecFlt pointScalars = {
667  0, 0, 0, // row 1
668  1, 1, 1, // row 2
669  2, 2, 2}; // row 3
670 
671  // extract value for each cell
672  VecPt3d extractLocations = {
673  {0.25, 0.25, 0}, // cell 0
674  {1.00, 0.25, 0}, // cell 1
675  {2.00, 0.50, 0}, // cell 2
676  {2.75, 0.75, 0}, // cell 3
677  {0.25, 1.75, 0}, // cell 4
678  {1.00, 1.25, 0}, // cell 5
679  {1.50, 1.75, 0}, // cell 6
680  {2.75, 1.25, 0} // cell 7
681  };
682 
683  // expected results with point 4 inactive
684  VecFlt expectedPerCell = {
685  0.25, XM_NODATA, XM_NODATA, XM_NODATA,
686  1.75, XM_NODATA, XM_NODATA, XM_NODATA };
687  // clang-format on
688 
689  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
690  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
691  TS_ASSERT(extractor);
692 
693  // set point 4 inactive
694  // should cause all cells connected to point 4 to return XM_NODATA
695  DynBitset pointActivity;
696  pointActivity.resize(9, true);
697  pointActivity[4] = false;
698  extractor->SetGridPointScalars(pointScalars, pointActivity, LOC_POINTS);
699 
700  // extract interpolated scalar for each cell
701  extractor->SetExtractLocations(extractLocations);
702 
703  VecFlt interpValues;
704  extractor->ExtractData(interpValues);
705  TS_ASSERT_EQUALS(expectedPerCell, interpValues);
706 } // XmUGrid2dDataExtractorUnitTests::testPointScalarPointActivity
707 //------------------------------------------------------------------------------
709 //------------------------------------------------------------------------------
711 {
712  // 3----2
713  // | 1 /|
714  // | / |
715  // | / |
716  // |/ 0 |
717  // 0----1
718  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
719  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
720  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
721  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
722  TS_ASSERT(extractor);
723 
724  VecFlt pointScalars = {1, 2, 3};
725  DynBitset activity;
726  activity.push_back(true);
727  activity.push_back(false);
728  extractor->SetGridPointScalars(pointScalars, activity, LOC_POINTS);
729 
730  VecPt3d extractLocations = {{0.25, 0.75, 100.0}, {0.75, 0.25, 0.0}};
731  extractor->SetExtractLocations(extractLocations);
732 
733  VecFlt interpValues;
734  extractor->ExtractData(interpValues);
735  VecFlt expected = {1.0, XM_NODATA};
736  TS_ASSERT_EQUALS(expected, interpValues);
737 } // XmUGrid2dDataExtractorUnitTests::testInvalidPointScalarsAndActivitySize
738 //------------------------------------------------------------------------------
748 //------------------------------------------------------------------------------
751 {
752  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
753  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
754  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
755 
756  // Step 1. Create an extractor for an existing XmUGrid (call xms::XmUGrid2dDataExtractor).
757  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
758  TS_ASSERT(extractor);
759 
760  // Step 2. Set scalar and activity values (call xms::XmUGrid2dDataExtractor::SetGridCellScalars or
761  // XmUGrid2dDataExtractor::SetPointCellScalars).
762  VecFlt cellScalars = {1, 2};
763  extractor->SetGridCellScalars(cellScalars, DynBitset(), LOC_CELLS);
764 
765  // Step 3. Set extract locations (call XmUGrid2dDataExtractor::SetExtractLocations).
766  extractor->SetExtractLocations({{0.0, 0.0, 0.0},
767  {0.25, 0.75, 100.0},
768  {0.5, 0.5, 0.0},
769  {0.75, 0.25, -100.0},
770  {-0.1, -0.1, 0.0}});
771 
772  // Step 4. Extract the data (call xms::XmUGrid2dDataExtractor::ExtractData).
773  VecFlt interpValues;
774  extractor->ExtractData(interpValues);
775  VecFlt expected = {1.5, 2.0, 1.5, 1.0, XM_NODATA};
776  TS_ASSERT_EQUALS(expected, interpValues);
777 } // XmUGrid2dDataExtractorUnitTests::testCellScalarsOnly
779 //------------------------------------------------------------------------------
781 //------------------------------------------------------------------------------
783 {
784  // clang-format off
785  // 6----7---------8 point row 3
786  // | 4 / \ /|
787  // | / \ 6 / |
788  // | / 5 \ / |
789  // |/ \ / 7 |
790  // 3---------4----5 point row 2
791  // |\ / \ 3 |
792  // | \ 1 / \ |
793  // | \ / \ |
794  // | 0 \ / 2 \|
795  // 0----1---------2 point row 1
796  //
797  VecPt3d points = {
798  {0, 0, 0}, {1, 0, 0}, {3, 0, 0}, // row 1 of points
799  {0, 1, 0}, {2, 1, 0}, {3, 1, 0}, // row 2 of points
800  {0, 2, 0}, {1, 2, 0}, {3, 2, 0}}; // row 3 of points
801  VecInt cells = {
802  XMU_TRIANGLE, 3, 0, 1, 3, // row 1 of triangles
803  XMU_TRIANGLE, 3, 1, 4, 3,
804  XMU_TRIANGLE, 3, 1, 2, 4,
805  XMU_TRIANGLE, 3, 2, 5, 4,
806 
807  XMU_TRIANGLE, 3, 3, 7, 6, // row 2 of triangles
808  XMU_TRIANGLE, 3, 3, 4, 7,
809  XMU_TRIANGLE, 3, 4, 8, 7,
810  XMU_TRIANGLE, 3, 4, 5, 8};
811 
812  VecFlt cellScalars = {
813  2, 4, 6, 8, // row 1
814  4, 6, 8, 10 // row 2
815  };
816 
817  // extract value for each cell
818  VecPt3d extractLocations = {
819  {0.25, 0.25, 0}, // cell 0
820  {1.00, 0.25, 0}, // cell 1
821  {2.00, 0.50, 0}, // cell 2
822  {2.75, 0.75, 0}, // cell 3
823  {0.25, 1.75, 0}, // cell 4
824  {1.00, 1.25, 0}, // cell 5
825  {1.50, 1.75, 0}, // cell 6
826  {2.75, 1.25, 0} // cell 7
827  };
828 
829  // expected results with point 4 inactive
830  VecFlt expectedPerCell = {
831  XM_NODATA, 4.0000, XM_NODATA, 8.2500, // row 1 cells
832  XM_NODATA, 6.0000, XM_NODATA, 9.750 // row 2 cells
833  };
834  // clang-format on
835 
836  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
837  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
838  TS_ASSERT(extractor);
839 
840  // set point 4 inactive
841  // should cause all cells connected to point 4 to return XM_NODATA
842  DynBitset cellActivity;
843  cellActivity.resize(8, true);
844  cellActivity[0] = false;
845  cellActivity[2] = false;
846  cellActivity[4] = false;
847  cellActivity[6] = false;
848  extractor->SetGridCellScalars(cellScalars, cellActivity, LOC_CELLS);
849 
850  // extract interpolated scalar for each cell
851  extractor->SetExtractLocations(extractLocations);
852 
853  VecFlt interpValues;
854  extractor->ExtractData(interpValues);
855  TS_ASSERT_EQUALS(expectedPerCell, interpValues);
856 } // XmUGrid2dDataExtractorUnitTests::testCellScalarCellActivity
857 //------------------------------------------------------------------------------
859 //------------------------------------------------------------------------------
861 {
862  // clang-format off
863  // 6----7---------8 point row 3
864  // | 4 / \ /|
865  // | / \ 6 / |
866  // | / 5 \ / |
867  // |/ \ / 7 |
868  // 3---------4----5 point row 2
869  // |\ / \ 3 |
870  // | \ 1 / \ |
871  // | \ / \ |
872  // | 0 \ / 2 \|
873  // 0----1---------2 point row 1
874  //
875  VecPt3d points = {
876  {0, 0, 0}, {1, 0, 0}, {3, 0, 0}, // row 1 of points
877  {0, 1, 0}, {2, 1, 0}, {3, 1, 0}, // row 2 of points
878  {0, 2, 0}, {1, 2, 0}, {3, 2, 0}}; // row 3 of points
879  VecInt cells = {
880  XMU_TRIANGLE, 3, 0, 1, 3, // row 1 of triangles
881  XMU_TRIANGLE, 3, 1, 4, 3,
882  XMU_TRIANGLE, 3, 1, 2, 4,
883  XMU_TRIANGLE, 3, 2, 5, 4,
884 
885  XMU_TRIANGLE, 3, 3, 7, 6, // row 2 of triangles
886  XMU_TRIANGLE, 3, 3, 4, 7,
887  XMU_TRIANGLE, 3, 4, 8, 7,
888  XMU_TRIANGLE, 3, 4, 5, 8};
889 
890  VecFlt cellScalars = {
891  2, 4, 6, 8, // row 1
892  4, 6, 8, 10 // row 2
893  };
894 
895  // extract value for each cell
896  VecPt3d extractLocations = {
897  {0.25, 0.25, 0}, // cell 0
898  {1.00, 0.25, 0}, // cell 1
899  {2.00, 0.50, 0}, // cell 2
900  {2.75, 0.75, 0}, // cell 3
901  {0.25, 1.75, 0}, // cell 4
902  {1.00, 1.25, 0}, // cell 5
903  {1.50, 1.75, 0}, // cell 6
904  {2.75, 1.25, 0} // cell 7
905  };
906 
907  // expected results with point 4 inactive
908  VecFlt expectedPerCell = {
909  2.0f, 3.4444f, XM_NODATA, 6.75f, // row 1 cells
910  3.5f, 5.7303f, 5.4652f, 8.25f // row 2 cells
911  };
912  // clang-format on
913 
914  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
915  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
916  TS_ASSERT(extractor);
917  extractor->SetUseIdwForPointData(true);
918 
919  // set point 4 inactive
920  // should cause all cells connected to point 4 to return XM_NODATA
921  DynBitset cellActivity;
922  cellActivity.resize(8, true);
923  cellActivity[2] = false;
924  extractor->SetGridCellScalars(cellScalars, cellActivity, LOC_CELLS);
925 
926  // extract interpolated scalar for each cell
927  extractor->SetExtractLocations(extractLocations);
928 
929  VecFlt interpValues;
930  extractor->ExtractData(interpValues);
931  TS_ASSERT_DELTA_VEC(expectedPerCell, interpValues, 0.001);
932 } // XmUGrid2dDataExtractorUnitTests::testCellScalarCellActivityIdw
933 //------------------------------------------------------------------------------
935 //------------------------------------------------------------------------------
937 {
938  // 3----2
939  // | 1 /|
940  // | / |
941  // | / |
942  // |/ 0 |
943  // 0----1
944  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
945  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
946  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
947  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
948  TS_ASSERT(extractor);
949 
950  DynBitset pointActivity;
951  pointActivity.resize(4, true);
952  pointActivity[1] = false;
953  VecFlt cellScalars = {1, 2};
954  extractor->SetGridCellScalars(cellScalars, pointActivity, LOC_POINTS);
955  extractor->SetExtractLocations({{0.0, 0.0, 0.0},
956  {0.25, 0.75, 100.0},
957  {0.5, 0.5, 0.0},
958  {0.75, 0.25, -100.0},
959  {-1.0, -1.0, 0.0}});
960 
961  VecFlt interpValues;
962  extractor->ExtractData(interpValues);
963  VecFlt expected = {2.0, 2.0, 2.0, XM_NODATA, XM_NODATA};
964  TS_ASSERT_EQUALS(expected, interpValues);
965 } // XmUGrid2dDataExtractorUnitTests::testCellScalarPointActivity
966 //------------------------------------------------------------------------------
968 //------------------------------------------------------------------------------
970 {
971  // 3----2
972  // | 1 /|
973  // | / |
974  // | / |
975  // |/ 0 |
976  // 0----1
977  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
978  VecInt cells = {XMU_TRIANGLE, 3, 0, 1, 2, XMU_TRIANGLE, 3, 2, 3, 0};
979  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
980  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
981  TS_ASSERT(extractor);
982 
983  VecFlt cellScalars = {1};
984  DynBitset activity;
985  activity.push_back(false);
986  extractor->SetGridCellScalars(cellScalars, activity, LOC_CELLS);
987  VecPt3d extractLocations = {{0.25, 0.75, 100.0}, {0.75, 0.25, 0.0}};
988  extractor->SetExtractLocations(extractLocations);
989 
990  VecFlt interpValues;
991  extractor->ExtractData(interpValues);
992  VecFlt expected = {0.0, XM_NODATA};
993  TS_ASSERT_EQUALS(expected, interpValues);
994 } // XmUGrid2dDataExtractorUnitTests::testInvalidCellScalarsAndActivitySize
995 //------------------------------------------------------------------------------
997 //------------------------------------------------------------------------------
999 {
1000  // build a grid with 3 cells in a row
1001  VecPt3d points = {{0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {3, 1, 0},
1002  {0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 0}};
1003  VecInt cells = {
1004  XMU_QUAD, 4, 0, 4, 5, 1, // cell 0
1005  XMU_QUAD, 4, 1, 5, 6, 2, // cell 1
1006  XMU_QUAD, 4, 2, 6, 7, 3 // cell 2
1007  };
1008 
1009  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
1010  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
1011  TS_ASSERT(extractor);
1012 
1013  VecFlt scalars;
1014  DynBitset activity;
1015  VecPt3d extractLocations = {
1016  {0.75, 0.25, 0.0}, // cell 0
1017  {1.5, 0.5, 0.0}, // cell 1
1018  {2.25, 0.75, 0.0} // cell 3
1019  };
1020 
1021  // timestep 1
1022  scalars = {1, 2, 3};
1023  // empty activity means all are enabled
1024  extractor->SetGridCellScalars(scalars, activity, LOC_CELLS);
1025  extractor->SetExtractLocations(extractLocations);
1026 
1027  VecFlt extractedValues;
1028  extractor->ExtractData(extractedValues);
1029  VecFlt expectedValues = {1.25, 2.0, 2.75};
1030  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1031 
1032  // timestep 2
1033  scalars = {2, 3, 4};
1034  activity.resize(3, true);
1035  activity[1] = false;
1036  extractor->SetGridCellScalars(scalars, activity, LOC_CELLS);
1037  extractor->SetExtractLocations(extractLocations);
1038 
1039  extractor->ExtractData(extractedValues);
1040  expectedValues = {2, XM_NODATA, 4};
1041  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1042 
1043  // timestep 3
1044  scalars = {3, 4, 5};
1045  activity.clear();
1046  extractor->SetGridCellScalars(scalars, activity, LOC_CELLS);
1047  extractor->SetExtractLocations(extractLocations);
1048 
1049  extractor->ExtractData(extractedValues);
1050  expectedValues = {3.25, 4.0, 4.75};
1051  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1052 
1053  // change to point data
1054  // timestep 1
1055  scalars = {1, 2, 3, 4, 2, 3, 4, 5};
1056  // empty activity means all are enabled
1057  extractor->SetGridPointScalars(scalars, activity, LOC_POINTS);
1058  extractor->SetExtractLocations(extractLocations);
1059 
1060  extractor->ExtractData(extractedValues);
1061  expectedValues = {2.5, 3.0, 3.5};
1062  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1063 
1064  // timestep 2
1065  scalars = {2, 3, 4, 5, 3, 4, 5, 6};
1066  activity.resize(8, true);
1067  activity[0] = false;
1068  extractor->SetGridPointScalars(scalars, activity, LOC_POINTS);
1069  extractor->SetExtractLocations(extractLocations);
1070 
1071  extractor->ExtractData(extractedValues);
1072  expectedValues = {XM_NODATA, 4.0, 4.5};
1073  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1074 
1075  // timestep 3
1076  scalars = {3, 4, 5, 6, 4, 5, 6, 7};
1077  activity.resize(8, true);
1078  activity[1] = false;
1079  extractor->SetGridPointScalars(scalars, activity, LOC_POINTS);
1080  extractor->SetExtractLocations(extractLocations);
1081 
1082  extractor->ExtractData(extractedValues);
1083  expectedValues = {XM_NODATA, XM_NODATA, 5.5};
1084  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1085 
1086  // timestep 4
1087  activity.clear();
1088  extractor->SetGridPointScalars(scalars, activity, LOC_POINTS);
1089  extractor->SetExtractLocations(extractLocations);
1090 
1091  extractor->ExtractData(extractedValues);
1092  expectedValues = {4.5, 5, 5.5};
1093  TS_ASSERT_EQUALS(expectedValues, extractedValues);
1094 } // XmUGrid2dDataExtractorUnitTests::testChangingScalarsAndActivity
1095 //------------------------------------------------------------------------------
1097 //------------------------------------------------------------------------------
1099 {
1100  // 3----2
1101  // | 1 /|
1102  // | / |
1103  // | / |
1104  // |/ 0 |
1105  // 0----1
1106  VecPt3d points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
1107  VecInt cells = {XMU_QUAD, 4, 0, 1, 2, 3};
1108  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
1109  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
1110  TS_ASSERT(extractor);
1111 
1112  VecFlt pointScalars = {1, 2, 3, 4};
1113  extractor->SetGridPointScalars(pointScalars, DynBitset(), LOC_POINTS);
1114  extractor->SetExtractLocations({{0.5, 0.5, 0.0}});
1115  VecFlt interpValues;
1116  extractor->ExtractData(interpValues);
1117  VecFlt expected = {2.0};
1118  TS_ASSERT_EQUALS(expected, interpValues);
1119 
1120  BSHP<XmUGrid2dDataExtractor> extractor2 = XmUGrid2dDataExtractor::New(extractor);
1121  extractor2->SetGridPointScalars(pointScalars, DynBitset(), LOC_POINTS);
1122  extractor2->SetExtractLocations({{0.5, 0.5, 0.0}});
1123  extractor2->ExtractData(interpValues);
1124  TS_ASSERT_EQUALS(expected, interpValues);
1125 } // XmUGrid2dDataExtractorUnitTests::testCopiedExtractor
1126 //------------------------------------------------------------------------------
1128 //------------------------------------------------------------------------------
1131 {
1132  // build 2x3 grid
1133  VecPt3d points = {{288050, 3907770, 0}, {294050, 3907770, 0}, {300050, 3907770, 0},
1134  {306050, 3907770, 0}, {288050, 3901770, 0}, {294050, 3901770, 0},
1135  {300050, 3901770, 0}, {306050, 3901770, 0}, {288050, 3895770, 0},
1136  {294050, 3895770, 0}, {300050, 3895770, 0}, {306050, 3895770, 0}};
1137  VecInt cells = {XMU_QUAD, 4, 0, 4, 5, 1, XMU_QUAD, 4, 1, 5, 6, 2, XMU_QUAD, 4, 2, 6, 7, 3,
1138  XMU_QUAD, 4, 4, 8, 9, 5, XMU_QUAD, 4, 5, 9, 10, 6, XMU_QUAD, 4, 6, 10, 11, 7};
1139  std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
1140  // Step 1. Create an extractor for an XmUGrid (call XmUGrid2dDataExtractor::New).
1141  BSHP<XmUGrid2dDataExtractor> extractor = XmUGrid2dDataExtractor::New(ugrid);
1142 
1143  // Step 2. Set extract locations (call XmUGrid2dDataExtractor::SetExtractLocations).
1144  VecPt3d extractLocations = {{289780, 3906220, 0}, {293780, 3899460, 0}, {298900, 3900780, 0},
1145  {301170, 3904960, 0}, {296330, 3906180, 0}, {307395, 3901463, 0}};
1146  extractor->SetExtractLocations(extractLocations);
1147  VecFlt extractedData;
1148  VecPt3d retrievedLocations = extractor->GetExtractLocations();
1149  TS_ASSERT_EQUALS(extractLocations, retrievedLocations);
1150 
1151  // Step 3. Optionally set the "no data" value for output interpolated values
1152  // (XmUGrid2dDataExtractor::SetNoDataValue).
1153  extractor->SetNoDataValue(-999.0);
1154 
1155  // time step 1
1156  // Step 4. Set the point scalars for the first time step
1157  // (XmUGrid2dDataExtractor::SetGridPointScalars).
1158  VecFlt pointScalars = {730.787f, 1214.54f, 1057.145f, 629.2069f, 351.1153f, 631.6649f,
1159  1244.366f, 449.9133f, 64.04247f, 240.9716f, 680.0491f, 294.9547f};
1160  extractor->SetGridPointScalars(pointScalars, DynBitset(), LOC_CELLS);
1161  // Step 5. Extract the data (call xms::XmUGrid2dDataExtractor::ExtractData).
1162  extractor->ExtractData(extractedData);
1163 
1164  VecFlt expectedData = {719.6f, 468.6f, 1033.8f, 996.5f, 1204.3f, -999.0f};
1165  TS_ASSERT_DELTA_VEC(expectedData, extractedData, 0.2);
1166 
1167  // time step 2
1168  // Step 6. Continue using steps 4 and 5 for remaining time steps.
1169  pointScalars = {-999.0f, 1220.5f, 1057.1f, 613.2f, 380.1f, 625.6f,
1170  722.2f, 449.9f, 51.0f, 240.9f, 609.0f, 294.9f};
1171  DynBitset cellActivity;
1172  cellActivity.resize(ugrid->GetCellCount(), true);
1173  cellActivity[0] = false;
1174  extractor->SetGridPointScalars(pointScalars, cellActivity, LOC_CELLS);
1175  // Step 7. Extract the data (call xms::XmUGrid2dDataExtractor::ExtractData).
1176  extractor->ExtractData(extractedData);
1177 
1178  expectedData = {-999.0f, 466.4f, 685.0f, 849.4f, 1069.6f, -999.0f};
1179  TS_ASSERT_DELTA_VEC(expectedData, extractedData, 0.2);
1180 } // XmUGrid2dDataExtractorUnitTests::testTutorial
1182 
1183 #endif
static BSHP< XmUGrid2dDataExtractor > New(std::shared_ptr< XmUGrid > a_ugrid)
Create a new XmUGrid2dDataExtractor.
virtual ~XmUGrid2dDataExtractor()
Destructor.
virtual void SetNoDataValue(float a_value) override
Set value to use when extracted value is in inactive cell or doesn&#39;t intersect with the grid...
virtual bool GetUseIdwForPointData() const override
Gets the option for using IDW for point data.
virtual float ExtractAtLocation(const Pt3d &a_location) override
Extract interpolated data for the previously set locations.
Implementation for XmUGrid2dDataExtractor.
virtual const BSHP< XmUGridTriangles2d > GetUGridTriangles() const override
Get the UGrid triangles.
bool m_useIdwForPointData
use IDW to calculate point data from cell data
DataLocationEnum m_triangleType
if triangles been generated for points or cells
float CalculatePointByIdw(int a_pointIdx, const VecInt &a_cellIdxs, const VecFlt &a_cellScalars, const DynBitset &a_cellActivity)
Calculate the point value by IDW method from surrounding cells.
virtual const VecFlt & GetScalars() const override
Gets the scalars.
void testChangingScalarsAndActivity()
Test extractor going through time steps with cell and point scalars.
virtual void SetUseIdwForPointData(bool a_) override
Set to use IDW to calculate point scalar values from cell scalars.
Class to store XmUGrid triangles. Tracks where midpoints and triangles came from. ...
void testCellScalarsOnly()
Test extractor with cell scalars only.
virtual const VecInt & GetCellIndexes() const
Gets cell indexes associated with the extract location points.
void SetGridPointActivity(const DynBitset &a_pointActivity, DynBitset &a_cellActivity)
Set point activity. Turns off each cell attached to an inactive point.
void SetGridCellActivity(const DynBitset &a_cellActivity)
Set activity on cells.
virtual void ExtractData(VecFlt &a_outData) override
Extract interpolated data for the previously set locations.
std::shared_ptr< XmUGrid > m_ugrid
UGrid for dataset.
void PushCellDataToTrianglePoints(const VecFlt &a_cellScalars, const DynBitset &a_cellActivity)
Push cell scalar data to triangle points using cells connected to a point with average or IDW...
void testCellScalarPointActivity()
Test extractor when using point scalars and point activity.
void testInvalidCellScalarsAndActivitySize()
Test extractor with cell scalars only.
void PushPointDataToCentroids(const DynBitset &a_cellActivity)
Push point scalar data to cell centroids using average.
virtual void BuildTriangles(DataLocationEnum a_location) override
Build triangles for UGrid for either point or cell scalars.
BSHP< VecInt > m_triangles
Triangles for the UGrid.
DataLocationEnum
The location at which the data will be stored.
void testPointScalarPointActivity()
Test extractor when using point scalars and point activity.
Contains the XmUGrid2dDataExtractor Class and supporting data types.
void testCellScalarCellActivityIdw()
Test extractor when using cell scalars and cell activity.
void testCopiedExtractor()
Test extractor built by copying triangles.
VecFlt m_pointScalars
scalars to interpolate from
void testCellScalarCellActivity()
[snip_test_Example_SimpleLocationExtractor]
void testTutorial()
Test XmUGrid2dDataExtractor for tutorial.
XMS Namespace.
virtual void SetGridPointScalars(const VecFlt &a_pointScalars, const DynBitset &a_activity, DataLocationEnum a_activityLocation) override
Setup point scalars to be used to extract interpolated data.
virtual void SetExtractLocations(const VecPt3d &a_locations) override
Sets locations of points to extract interpolated scalar data from.
void testPointScalarCellActivity()
Test extractor when using point scalars and cell activity.
virtual void SetGridCellScalars(const VecFlt &a_cellScalars, const DynBitset &a_activity, DataLocationEnum a_activityLocation) override
Setup cell scalars to be used to extract interpolated data.
float CalculatePointByAverage(const VecInt &a_cellIdxs, const VecFlt &a_cellScalars, const DynBitset &a_cellActivity)
Calculate the average of the cell values connected to a point.
void testInvalidPointScalarsAndActivitySize()
Test when scalar and activity arrays are sized incorrectly.
float m_noDataValue
value to use for inactive result
virtual DataLocationEnum GetScalarLocation() const override
Gets the location of the scalars (points or cells)
void testPointScalarsOnly()
Test extractor with point scalars only.
VecPt3d m_extractLocations
output locations for interpolated values
void ApplyActivity(const DynBitset &a_activity, DataLocationEnum a_location, DynBitset &a_cellActivity)
Apply point or cell activity to triangles.
Contains the XmUGrid Class and supporting data types.
XmUGrid2dDataExtractorImpl(std::shared_ptr< XmUGrid > a_ugrid)
Construct from a UGrid.
BSHP< XmUGridTriangles2d > m_triangles
triangles generated from UGrid to use for data extraction
Contains the XmUGrid2dPolylineDataExtractor Class and supporting data types.
virtual float GetNoDataValue() const override
Gets the no data value.
virtual const VecPt3d & GetExtractLocations() const override
Gets locations of points to extract interpolated scalar data from.
Provides ability to interpolate and extract the scalar values points and along arcs for an unstructur...