rasterizePolygon (2D & 3D)
These functions generate discrete grid points that approximate the boundary and interior of a polygon in 2D or 3D space.
Each function returns a unique set of integer coordinates stored in a RowVector2iSet or RowVector3iSet. Neighboring offset points are also included.
Function Signatures
2D Version
RowVector2iSet rasterizePolygon2D(
const Eigen::MatrixX2d& polygonVertices,
bool needClosePolygon = true
);
-
Parameters:
polygonVertices(Eigen::MatrixX2d): Vertices of the 2D polygon.needClosePolygon(optional,bool, default =true):- If
true, the function automatically sorts the vertices counter-clockwise and ensures the polygon is closed. - If
false, the input vertices matrix must already be sorted and closed.
- If
-
Returns: A
RowVector2iSetcontaining all boundary and interior grid points, plus their four corner offsets.
3D Version
RowVector3iSet rasterizePolygon3D(
const Eigen::MatrixX3d& polygonVertices,
bool needClosePolygon = true
);
-
Parameters:
polygonVertices(Eigen::MatrixX3d): Vertices of the 3D polygon.needClosePolygon(optional,bool, default =true):- If
true, the function automatically sorts the vertices counter-clockwise and ensures the polygon is closed. - If
false, the input vertices matrix must already be sorted and closed.
- If
-
Returns: A
RowVector3iSetcontaining all boundary and interior voxels, plus their eight surrounding offsets.
Example Usage
#include "RasterizeTool.h"
int main() {
Eigen::Matrix<double, 4, 3> polygonVertices;
polygonVertices << 748694.42507040221, 2564734.3476669602, 49,
748674.41542796092, 2564734.5007915981, 49,
748674.4539194419, 2564739.5306861168, 81,
748694.4635618832, 2564739.3775614789, 81;
RowVector3iSet PointsSet = rasterizePolygon3D(polygonVertices);
return 0;
}