xmsgrid  1.0
2D UGrid Tutorial

2D UGrid Tutorial

Introduction

The purpose of this tutorial is to provide explanation on how to use xmsgrid to create two dimensional unstructured grids, or UGrids. A UGrid has points and cells defined using those points. There are many different kinds of cells available, but this tutorial will focus on the 2-dimensional cells, namely: triangle, polygon, pixel, quadrilateral.

Example - Defining Ugrid Cells

Supported 2D grid cells include: triangle (5), polygon (7), pixel (8), quad (9). A cell is defined with the number declaration of the shape (5, 7, 8, and 9 respectively as defined by the enumeration xms::XmUGridCellType), then the number of points, followed by the point indices. The cell definitions mirror VTK cell definitions which are available on page 9 of VTK File Formats for VTK version 4.2 at https://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf.

A triangle (5) has 3 points and the points are declared in a counter-clockwise direction. A cellstream example for a triangle is: 5, 3, 0, 1, 2.

A polygon (7) does not a have a defined number of points, but the points are still declared in a counter-clockwise direction. A cellstream example for a polygon is: 7, 5, 0, 1, 2, 3, 4.

A pixel (8) has 4 orthogonially defined points. For the direction and order of points, see the illustration in the VTK file Format pdf referenced above on page 9 for a VTK_PIXEL. A cellstream example for a pixel is: 8, 4, 0, 1, 2, 3.

A quad (9) has 4 points declared in a counter-clockwise direction. A cellstream example for a quad is: 9, 4, 0, 1, 2, 3.

The testing code for this example is xms::TEST_XmUGrid2dLinear.

VecPt3d points = { { 0, 0, 0 }, { 10, 0, 0 }, { 20, 0, 0 }, { 30, 0, 0 }, { 40, 0, 0 },
{0, 10, 0}, {10, 10, 0}, {20, 10, 0}, {40, 10, 0}, {0, 20, 0},
{10, 20, 0}, {20, 20, 0}, {30, 20, 0}, {40, 20, 0}};
// Cell type (5), number of points (3), point numbers, counterclockwise
std::vector<int> cells = {(int)XMU_QUAD, 4, 0, 1, 6, 5, // 0
(int)XMU_PIXEL, 4, 1, 2, 6, 7, // 1
(int)XMU_TRIANGLE, 3, 2, 3, 7, // 2
(int)XMU_POLYGON, 6, 3, 4, 8, 13, 12, 7, // 3
(int)XMU_POLY_LINE, 3, 7, 11, 10, // 4
(int)XMU_LINE, 2, 5, 9}; // 5

Example - Creating a New 2D UGrid With Data

This example shows how to create a new 2D UGrid with the overloaded New function which directly sets the data as it constructs the grid, using the static function xms::XmUGrid::New(const VecPt3d& a_points, const VecInt& a_cellStream). Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::testGetSetPoint.

VecPt3d points = {{0, 10, 0}, {10, 10, 10}, {20, 10, 0}, {0, 0, 0}, {10, 0, 0},
{20, 0, 0}, {0, -10, 0}, {10, -10, 0}, {20, -10, 0}};
// Cell type (9), number of points (4), point numbers, counterclockwise
VecInt cellstream = {9, 4, 0, 3, 4, 1, 9, 4, 1, 4, 5, 2, 9, 4, 3, 6, 7, 4, 9, 4, 4, 7, 8, 5};
std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cellstream);

Example - Creating a New 2D UGrid

This example shows how to create a new 2D UGrid. XmUGrid is an abstract class that cannot be instantiated. The static function xms::XmUGrid::New() is the only method to obtain a Boost Shared Pointer to an instance of XmUGrid. Points and Cellstream may be passed to New to initialize the UGrid with data but this is not required. Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::testUGridStreams.

Example - Setting the UGrid Points

This example shows how to set all of the UGrid points using xms::XmUGrid::SetLocations. The Ugrid points cannot be added or removed individually, though they can be edited individually. The SetPoints function takes one argument, a vector of 3D points. It is recomended that each point is unique to avoid unexpected behavior. Functionality is shared between 2d and 3d UGrids. The testing code for this example is the same as used for creating a new UGrid, XmUGridUnitTests::testUGridStreams.

Example - Setting the UGrid Cell Stream

This example shows how to set the entire UGrid Cellstream using xms::XmUGrid::SetCellstream. Cellstreams are formatted as a stream of integers starting with the cell type as described by the enumeration XmUGridCellType, then the number of points in the cell, followed by a series of indices to points. The SetCellstream function takes one argument, a vector of integers formatted as previously described. Functionality is shared between 2d and 3d UGrids. The testing code for this example is the same as used for creating a new UGrid, XmUGridUnitTests::testUGridStreams.

The xms::XmUGrid::IsValidCellstream function checks whether all cell types and point counts within the cellstream match up, but does not check for orientation or valid point positions. This function should not be relied on to catch all errors, but can be a basic check before setting the cellstream. The function takes one argument, a cellstream containing one or more cells. Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::SetCellstream.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// test empty UGrid
std::shared_ptr<XmUGrid> emptyUGrid = XmUGrid::New();
VecPt3d points = emptyUGrid->GetLocations();
TS_ASSERT_EQUALS(0, points.size());
VecInt cellstream = emptyUGrid->GetCellstream();
TS_ASSERT(XmUGrid::IsValidCellstream(cellstream));
TS_ASSERT_EQUALS(0, cellstream.size());
// test adding points and cell stream
// 0----1----2
// | | |
// 3----4----5
// | | |
// 6----7----8
std::shared_ptr<XmUGrid> ugrid = XmUGrid::New();
points = {{0, 10, 0}, {10, 10, 0}, {20, 10, 0}, {0, 0, 0}, {10, 0, 0},
{20, 0, 0}, {0, -10, 0}, {10, -10, 0}, {20, -10, 0}};
// Cell type (9), number of points (4), point numbers, counterclockwise
cellstream = {9, 4, 0, 3, 4, 1, 9, 4, 1, 4, 5, 2, 9, 4, 3, 6, 7, 4, 9, 4, 4, 7, 8, 5};
TS_ASSERT(!ugrid->GetModified());
ugrid->SetLocations(points);
VecPt3d pointsOut = ugrid->GetLocations();
TS_ASSERT_EQUALS(points, pointsOut);
TS_ASSERT(ugrid->GetModified());
ugrid->SetUnmodified();
TS_ASSERT(!ugrid->GetModified());
TS_ASSERT(ugrid->SetCellstream(cellstream));
VecInt cellstreamOut = ugrid->GetCellstream();
TS_ASSERT_EQUALS(cellstream, cellstreamOut);
TS_ASSERT(ugrid->GetModified());
// Test invalid cell streams
cellstream = {-1};
TS_ASSERT(!XmUGrid::IsValidCellstream(cellstream));
cellstream = {9, 4, 0, 3, 4};
TS_ASSERT(!XmUGrid::IsValidCellstream(cellstream));
cellstream = {9, 3, 0, 3, 4, 1};
TS_ASSERT(!XmUGrid::IsValidCellstream(cellstream));
// Test adding cellstream then points (should fail)
std::shared_ptr<XmUGrid> ugridBadOrder = XmUGrid::New();
TS_ASSERT(!ugridBadOrder->SetCellstream(cellstream));
} // XmUGridUnitTests::testUGridStreams

Example - Get Number Of Points

This example shows how to return the number of points contained in a UGrid. The xms::XmUGrid::GetPointCount function returns the number of points in the UGrid. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get Points (Locations)

This example shows how to get all points contained within the XmUGrid. The xms::XmUGrid::GetLocations function returns a vector of Pt3d's. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get Point Location

This example shows how to get a specific point given a point index. The xms::XmUGrid::GetPointLocation function returns the Pt3d of the point at the specified index. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Set Point Location

This example shows how to set a specific point location given a point index. The xms::XmUGrid::SetLocation function takes a point index and a Pt3d as arguments and returns whether the operation was succesful. The function will fail and return false if the change would cause any edges to cross. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get Locations of Many Points

This example shows how to convert a vector of point indices into a vector of Pt3d's. The xms::XmUGrid::GetPointsLocations function takes a vector of Point Indices as an argument and returns a vector of corresponding Pt3d's as a result. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get Extents of UGrid

This example shows how to get the extents of a UGrid. The xms::XmUGrid::GetExtents function takes two 3D points as arguments describing the minimum and maximum extent that the points of the UGrid cover. These arguments will be set by the funtion. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get Cells Adjacent to a Point

This example shows how to the cells associated with a single point. The xms::XmUGrid::GetPointAdjacentCells function takes one point index as an argument and returns a vector of cell indices. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

Example - Get the Cells that Share All of Group of Points

This example shows how to get the cells that share all of the same points or points. The xms::XmUGrid::GetPointsAdjacentCells function takes a vector of point indices as an argument and returns a vector of cell indices. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testPointFunctions.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Test GetPointCount
TS_ASSERT_EQUALS(ugrid->GetPointCount(), 9);
VecPt3d points = {{0, 10, 0}, {10, 10, 0}, {20, 10, 0}, {0, 0, 0}, {10, 0, 0},
{20, 0, 0}, {0, -10, 0}, {10, -10, 0}, {20, -10, 0}};
// Test Locations
TS_ASSERT_EQUALS(ugrid->GetLocations(), points);
for (int i = 0; i < points.size(); ++i)
{
TS_ASSERT_EQUALS(points[i], ugrid->GetPointLocation(i));
}
// Test SetPointLocation & GetPointLocation
Pt3d invalid = {100, 100, 100};
Pt3d valid = {5, 5, 5};
TS_ASSERT(!ugrid->IsValidPointChange(4, invalid));
TS_ASSERT(ugrid->SetPointLocation(4, valid));
TS_ASSERT_EQUALS(valid, ugrid->GetPointLocation(4));
VecInt pointIndices = {0, 3, 6};
VecPt3d expectedPoints = {{0, 10, 0}, {0, 0, 0}, {0, -10, 0}};
VecPt3d pointsPt3d;
// Test GetPointsLocations
pointsPt3d = ugrid->GetPointsLocations(pointIndices);
TS_ASSERT_EQUALS(expectedPoints, pointsPt3d);
// Test GetExtents
Pt3d min, max, expectedMin = {0, -10, 0}, expectedMax = {20, 10, 5};
ugrid->GetExtents(min, max);
TS_ASSERT_EQUALS(expectedMin, min);
TS_ASSERT_EQUALS(expectedMax, max);
// Test GetPointAdjacentCells
VecInt expectedCells = {0, 2};
VecInt cellsAssociated = ugrid->GetPointAdjacentCells(3);
TS_ASSERT_EQUALS(expectedCells, cellsAssociated);
// Test GetPointsAdjacentCells
VecInt expectedCommonCells = {0, 1};
VecInt pointIndex = {1};
VecInt commonCells = ugrid->GetPointsAdjacentCells(pointIndex);
TS_ASSERT_EQUALS(expectedCells, cellsAssociated);
} // XmUGridUnitTests::testPointFunctions

Example - Get the Points (or their Locations) Adjacent to Point

This example shows how to get the Points that are adjacent to a given point. The xms::XmUGrid::GetPointAdjacentPoints functions takes a point index as an argument and returns the indices of the adjacent Points. The function xms::XmUGrid::GetPointAdjacentLocations returns instead the locations of the adjacent points. The testing code for this example is in XmUGridUnitTests::testGetPointAdjacentPoints.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// 0-----1-----2
// | 0 | 1 |
// 3-----4-----5
// | 2 | 3 |
// 6-----7-----8
std::shared_ptr<xms::XmUGrid> grid = TEST_XmUGridSimpleQuad();
VecInt attachedIdxs;
grid->GetPointAdjacentPoints(0, attachedIdxs);
VecInt expectedIdxs = {1, 3};
TS_ASSERT_EQUALS(expectedIdxs, attachedIdxs);
grid->GetPointAdjacentPoints(3, attachedIdxs);
expectedIdxs = {0, 4, 6};
TS_ASSERT_EQUALS(expectedIdxs, attachedIdxs);
grid->GetPointAdjacentPoints(4, attachedIdxs);
expectedIdxs = {1, 3, 5, 7};
TS_ASSERT_EQUALS(expectedIdxs, attachedIdxs);
VecPt3d attachedPts;
grid->GetPointAdjacentLocations(0, attachedPts);
VecPt3d expectedPts = {{10, 10, 0}, {0, 0, 0}};
TS_ASSERT_EQUALS(expectedPts, attachedPts);
grid->GetPointAdjacentLocations(3, attachedPts);
expectedPts = {{0, 10, 0}, {10, 0, 0}, {0, -10, 0}};
TS_ASSERT_EQUALS(expectedPts, attachedPts);
grid->GetPointAdjacentLocations(4, attachedPts);
expectedPts = {{10, 10, 0}, {0, 0, 0}, {20, 0, 0}, {10, -10, 0}};
TS_ASSERT_EQUALS(expectedPts, attachedPts);
} // XmUGridUnitTests::testGetPointAdjacentPoints

Example - Get the Points or Locations of a Cell

This example shows how to get the points of a cell. The xms::XmUGrid::GetCellPoints function takes one cell index and returns a vector of point indices. The xms::XmUGrid::GetCellLocations functions takes a cell index and returns a VecPt3d of the locations of those points. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellFunctions.

Example - Get the Type of a Cell

This example shows how to get the type of a cell. The xms::XmUGrid::GetCellType function takes one cell index and returns the cell type. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellFunctions.

Example - Get the Count of Cells in a UGrid of each of the possible Dimensions

This example shows how to get the count of the dimensions of cells used in a UGrid. The xms::XmUGrid::GetDimensionCounts function returns a vector with the number of cells with zero dimensions in the zero index, number of cells with one dimension in the first index, number of cells with two dimensions in the second index, and the number of cells with three dimensions in the third index. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellFunctions.

Example - Get the Dimension of a Cell

This example shows how to get the dimension of a cell. The xms::XmUGrid::GetCellDimension function takes one cell index and returns the cell dimension as an integer value. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellFunctions.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Test GetCellPoints
VecInt pointsOfCell = ugrid->GetCellPoints(0);
VecInt expectedPoints = {0, 3, 4, 1};
TS_ASSERT_EQUALS(expectedPoints, pointsOfCell);
// Test overload
ugrid->GetCellPoints(0, pointsOfCell);
TS_ASSERT_EQUALS(expectedPoints, pointsOfCell);
VecPt3d locations;
ugrid->GetCellLocations(0, locations);
VecPt3d expectedLocations = {{0, 10, 0}, {0, 0, 0}, {10, 0, 0}, {10, 10, 0}};
TS_ASSERT_EQUALS(expectedLocations, locations);
// Test GetCellExtents
Pt3d min, max;
ugrid->GetCellExtents(0, min, max);
TS_ASSERT_EQUALS(Pt3d(0, 0, 0), min);
TS_ASSERT_EQUALS(Pt3d(10, 10, 0), max);
// Test GetCellType
TS_ASSERT_EQUALS(XMU_QUAD, ugrid->GetCellType(0));
// Test GetDimensionCounts
VecInt expectedDimensions = {0, 0, 4, 0};
TS_ASSERT_EQUALS(expectedDimensions, ugrid->GetDimensionCounts());
// Test GetCellDimension
TS_ASSERT_EQUALS(2, ugrid->GetCellDimension(0));
// Test GetCellCentroid
Pt3d centroid;
TS_ASSERT(ugrid->GetCellCentroid(0, centroid));
TS_ASSERT_EQUALS(Pt3d(5, 5, 0), centroid);
} // XmUGridUnitTests::testCellFunctions

Example - Get the Cellstream of the UGrid

This example shows how to get the entire cellstream of the UGrid. The xms::XmUGrid::GetCellStream function returns a vector of integers that is the cellstream. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellstreamFunctions.

Example - Get a the Cellstream for Single Cell

This example shows how to get the cellstream for one cell. The xms::XmUGrid::GetCellCellstream function takes a cell index and a vector of integers that is the cellstream for the specified cell passed in by reference. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellstreamFunctions.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Test GetCellstream
VecInt cellstream = ugrid->GetCellstream();
VecInt expectedCellstream = {XMU_QUAD, 4, 0, 3, 4, 1, XMU_QUAD, 4, 1, 4, 5, 2,
XMU_QUAD, 4, 3, 6, 7, 4, XMU_QUAD, 4, 4, 7, 8, 5};
TS_ASSERT_EQUALS(expectedCellstream, cellstream);
// Test GetCellCellstream
ugrid->GetCellCellstream(0, cellstream);
expectedCellstream = {XMU_QUAD, 4, 0, 3, 4, 1};
TS_ASSERT_EQUALS(expectedCellstream, cellstream);
} // XmUGridUnitTests::testCellstreamFunctions

Example - Get the Cells Adjacent to a Given Cell

This example shows how to get the cells adjacent to a given cell. Cells are adjacent if they share at least one point. The xms::XmUGrid::GetCellAdjacentCells function takes a cell index and returns a vector of cell indices. Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::testGetCellAdjacentCells.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// 0-----1-----2
// | 0 | 1 |
// 3-----4-----5
// | 2 | 3 |
// 6-----7-----8
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
VecInt expectedCells;
VecInt retrievedCells;
retrievedCells = ugrid->GetCellAdjacentCells(-1);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
retrievedCells = ugrid->GetCellAdjacentCells(0);
expectedCells = {2, 1, 3};
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells.clear();
retrievedCells = ugrid->GetCellAdjacentCells(4);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells.clear();
retrievedCells = ugrid->GetCellAdjacentCells(5);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells.clear();
retrievedCells.clear();
// 2D Shapes
std::shared_ptr<XmUGrid> ugrid2d = TEST_XmUGrid2dLinear();
expectedCells = {1, 5};
retrievedCells = ugrid2d->GetCellAdjacentCells(0);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {0, 2, 3, 4};
retrievedCells = ugrid2d->GetCellAdjacentCells(1);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {1, 3, 4};
retrievedCells = ugrid2d->GetCellAdjacentCells(2);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {2, 1, 4};
retrievedCells = ugrid2d->GetCellAdjacentCells(3);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {1, 2, 3};
retrievedCells = ugrid2d->GetCellAdjacentCells(4);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {0};
retrievedCells = ugrid2d->GetCellAdjacentCells(5);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
// 3D Shapes
std::shared_ptr<XmUGrid> ugrid3d = TEST_XmUGrid3dLinear();
expectedCells = {1, 5};
retrievedCells = ugrid3d->GetCellAdjacentCells(0);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {0, 2, 5};
retrievedCells = ugrid3d->GetCellAdjacentCells(1);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {1, 4, 3};
retrievedCells = ugrid3d->GetCellAdjacentCells(2);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {4, 2};
retrievedCells = ugrid3d->GetCellAdjacentCells(3);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {2, 3};
retrievedCells = ugrid3d->GetCellAdjacentCells(4);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
expectedCells = {0, 1};
retrievedCells = ugrid3d->GetCellAdjacentCells(5);
TS_ASSERT_EQUALS(expectedCells, retrievedCells);
} // XmUGridUnitTests::testGetCellAdjacentCells

Example - Get a Plan View Polygon

This example shows how to get a plan view polygon. The xms::XmUGrid::GetCellPlanViewPolygon function takes a cell index and a vector of Pt3d which is the points of the 2D cell and returns whether the operation was succesful. The testing code for this example is XmUGridUnitTests::testGetCellPlanViewPolygon.

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// 2d
std::shared_ptr<xms::XmUGrid> grid2d = TEST_XmUGrid2dLinear();
VecPt3d2d expectedPolygons{
{{0, 0, 0}, {10, 0, 0}, {10, 10, 0}, {0, 10, 0}},
{{10, 0, 0}, {20, 0, 0}, {20, 10, 0}, {10, 10, 0}},
{{20, 0, 0}, {30, 0, 0}, {20, 10, 0}},
{{30, 0, 0}, {40, 0, 0}, {40, 10, 0}, {40, 20, 0}, {30, 20, 0}, {20, 10, 0}},
{},
{}};
VecPt3d viewPolygon;
VecPt3d empty;
// Bounds testing
TS_ASSERT(!grid2d->GetCellPlanViewPolygon(-1, viewPolygon));
TS_ASSERT_EQUALS(empty, viewPolygon);
TS_ASSERT(!grid2d->GetCellPlanViewPolygon(grid2d->GetCellCount(), viewPolygon));
TS_ASSERT_EQUALS(empty, viewPolygon);
// Regular testing
for (int i = 0; i < grid2d->GetCellCount(); ++i)
{
// Should return true for the first 4 cells, and false for the last 2
TS_ASSERT(grid2d->GetCellPlanViewPolygon(i, viewPolygon) != i >= 4);
TS_ASSERT_EQUALS(expectedPolygons[i], viewPolygon);
}
// 3d
std::shared_ptr<XmUGrid> ugrid3d = TEST_XmUGrid3dLinear();
expectedPolygons = {{{0, 0, 0}, {10, 0, 0}, {0, 10, 0}},
{{20, 0, 0}, {20, 10, 0}, {10, 10, 0}, {10, 0, 0}},
{{30, 0, 0}, {30, 10, 0}, {20, 10, 0}, {20, 0, 0}},
{{40, 10, 0}, {40, 20, 0}, {30, 20, 0}, {30, 10, 0}},
{{30, 0, 0}, {40, 0, 0}, {40, 10, 0}, {30, 10, 0}},
{{0, 10, 0}, {10, 10, 0}, {10, 20, 0}, {0, 20, 0}}};
for (int i = 0; i < ugrid3d->GetCellCount(); ++i)
{
TS_ASSERT(ugrid3d->GetCellPlanViewPolygon(i, viewPolygon));
TS_ASSERT_EQUALS(expectedPolygons[i], viewPolygon);
}
std::shared_ptr<xms::XmUGrid> chevronUgrid = TEST_XmUBuild3DChevronUgrid();
TS_REQUIRE_NOT_NULL(chevronUgrid);
expectedPolygons = {{{0.0, 0.0, 0.0}, {20.0, 10.0, 0.0}, {40.0, 0.0, 0.0}, {20.0, 50.0, 0.0}}};
TS_ASSERT(chevronUgrid->GetCellPlanViewPolygon(0, viewPolygon));
TS_ASSERT_EQUALS(expectedPolygons[0], viewPolygon);
} // XmUGridUnitTests::testGetCellPlanViewPolygon

Example - Get Number of Cell Edges

This example shows how to get the number of cell edges in a cell. The xms::XmUGrid::GetCellEdgeCount function takes a cell index and returns the number of edges as an int. Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::testCellEdgeAdjacentCellFunctions

Example - Get Cell Edge from Edge Index

This example shows how to get the cell edge from a given cell and edge index. The xms::XmUGrid::GetCellEdge function takes a cell index and an edge index and returns a XmEdge containing the point indices of the edge. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellEdgeAdjacentCellFunctions

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// 0-----1-----2
// | 0 | 1 |
// 3-----4-----5
// | 2 | 3 |
// 6-----7-----8
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Get Adjacent Cells from cell and edge
VecInt2d expectedCells = {{}, {2}, {1}, {}};
VecInt expected2dCells = {-1, 2, 1, -1};
int adjacentCell;
VecInt adjacentCells;
for (int i(0); i < ugrid->GetCellEdgeCount(0); i++)
{
adjacentCells = ugrid->GetCellEdgeAdjacentCells(0, i);
TS_ASSERT_EQUALS(expectedCells[i], adjacentCells);
// For 2D cells only
adjacentCell = ugrid->GetCell2dEdgeAdjacentCell(0, i);
TS_ASSERT_EQUALS(expected2dCells[i], adjacentCell);
}
// Get Adjacent cells from given Edge
VecInt2d expectedCellsFromEdge = {{0, 1}, {0, 2}, {0}};
std::vector<XmEdge> edges = {{1, 4}, {3, 4}, {0, 3}};
adjacentCells = ugrid->GetEdgeAdjacentCells(XmEdge(-1, -1));
for (int i(0); i < edges.size(); i++)
{
adjacentCells = ugrid->GetEdgeAdjacentCells(edges[i]);
TS_ASSERT_EQUALS(expectedCellsFromEdge[i], adjacentCells);
}
} // XmUGridUnitTests::testCellAdjacentCellFunctions

Example Get Cells Adjacent to an Edge of a Cell

This example shows how to get all cells which share the specified edge with a cell. The xms::XmUGrid::GetCellEdgeAdjacentCells function takes a cell index and an edge index and returns a vector of cell indices. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellEdgeAdjacentCellFunctions

Example 2D Get the Other Cell Adjacent to a particular Cell Edge

This example shows how to get a 2D cell which is adjacent to another given 2D cell with a given edge index. The xms::XmUGrid::GetCell2dEdgeAdjacentCell function takes a cell index and an edge index and returns a cell index, since no more than one cell may legally share an edge in this manner. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellEdgeAdjacentCellFunctions

Example Get Cells Adjacent to a Given Edge

This example shows how to get all cells which contain a given edge. The xms::XmUGrid::GetEdgeAdjacentCells function takes two point indices describing an edge and returns a vector of cell indices. There is also an overload which takes a pair of point indices describing an edge. Functionality is shared between 2d and 3d UGrids. The testing code for this example is shared with other examples, XmUGridUnitTests::testCellEdgeAdjacentCellFunctions

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
// 0-----1-----2
// | 0 | 1 |
// 3-----4-----5
// | 2 | 3 |
// 6-----7-----8
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Get Adjacent Cells from cell and edge
VecInt2d expectedCells = {{}, {2}, {1}, {}};
VecInt expected2dCells = {-1, 2, 1, -1};
int adjacentCell;
VecInt adjacentCells;
for (int i(0); i < ugrid->GetCellEdgeCount(0); i++)
{
adjacentCells = ugrid->GetCellEdgeAdjacentCells(0, i);
TS_ASSERT_EQUALS(expectedCells[i], adjacentCells);
// For 2D cells only
adjacentCell = ugrid->GetCell2dEdgeAdjacentCell(0, i);
TS_ASSERT_EQUALS(expected2dCells[i], adjacentCell);
}
// Get Adjacent cells from given Edge
VecInt2d expectedCellsFromEdge = {{0, 1}, {0, 2}, {0}};
std::vector<XmEdge> edges = {{1, 4}, {3, 4}, {0, 3}};
adjacentCells = ugrid->GetEdgeAdjacentCells(XmEdge(-1, -1));
for (int i(0); i < edges.size(); i++)
{
adjacentCells = ugrid->GetEdgeAdjacentCells(edges[i]);
TS_ASSERT_EQUALS(expectedCellsFromEdge[i], adjacentCells);
}
} // XmUGridUnitTests::testCellAdjacentCellFunctions

Example Get Edges of a Cell

This example shows how to get edges associated with a cell. The xms::XmUGrid::GetCellEdges function takes a cell index and returns a vector of XmEdge (each of which has a pair of integers which are point indices of the Edge). Functionality is shared between 2d and 3d UGrids. The testing code for this example is XmUGridUnitTests::testCellEdges

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
{
std::shared_ptr<XmUGrid> ugrid = TEST_XmUGridSimpleQuad();
// Test GetCellEdges
std::vector<XmEdge> edges = ugrid->GetCellEdges(0);
std::vector<XmEdge> expectededges = {{0, 3}, {3, 4}, {4, 1}, {1, 0}};
TS_ASSERT_EQUALS(expectededges, edges);
} // XmUGridUnitTests::testCellEdges