inc
Mesh
-
class Mesh2d
Constructs a triangular mesh from a geometry image.
Given a segmented geometry image, and the colours that correspond to compartments in the image, the compartment boundaries are identified and simplified to a set of connected straight lines, and the resulting PLSG is triangulated to give a triangular mesh.
The mesh is provided as an image, in GMSH format, and as flat arrays of indices and vertices for SBML.
The number of points used for each boundary line and the maximum triangle area allowed for each compartment can then be adjusted.
Public Functions
-
Mesh2d()
-
explicit Mesh2d(const QImage &image, std::vector<std::size_t> maxPoints = {}, std::vector<std::size_t> maxTriangleArea = {}, const common::VolumeF &voxelSize = {1.0, 1.0, 1.0}, const common::VoxelF &originPoint = {0.0, 0.0, 0.0}, const std::vector<QRgb> &compartmentColours = {}, std::size_t boundarySimplificationType = 0)
Constructs a mesh from the supplied image.
- Parameters:
image – [in] the segmented geometry image
maxPoints – [in] the max points allowed for each boundary line
maxTriangleArea – [in] the max triangle area allowed for each compartment
voxelSize – [in] the physical size of a pixel
originPoint – [in] the physical location of the
(0,0)
pixelcompartmentColours – [in] the colours of compartments in the image
-
~Mesh2d()
-
void constructMesh()
Constructs (or re-constructs) the mesh.
-
bool isValid() const
Returns true if the mesh is valid.
-
const std::string &getErrorMessage() const
Returns an error message if the mesh is invalid.
-
std::size_t getNumBoundaries() const
The number of boundary lines in the mesh.
-
std::size_t getBoundarySimplificationType() const
Get the type of boundary simplification.
-
void setBoundarySimplificationType(std::size_t boundarySimplificationType)
Set the type of boundary simplification.
-
void setBoundaryMaxPoints(std::size_t boundaryIndex, std::size_t maxPoints)
Set the maximum number of allowed points.
If the boundary simplification type is one where each boundary line can be independently simplified, maxPoints applies only to the specified boundary line, and only this boundary line is potentially altered by this method.
If the boundary simplification type is a topology-preserving type that simplifies all boundaries simultaneously, maxPoints is the total number of allowed points summed over all boundaries, and all boundary lines can potentially be altered by this method.
- Parameters:
boundaryIndex – [in] the index of the boundary
maxPoints – [in] the maximum number of points allowed
-
std::size_t getBoundaryMaxPoints(std::size_t boundaryIndex) const
Get the maximum number of allowed points for a given boundary.
- Parameters:
boundaryIndex – [in] the index of the boundary
-
std::vector<std::size_t> getBoundaryMaxPoints() const
The maximum allowed points for each boundary in the mesh.
-
void setCompartmentMaxTriangleArea(std::size_t compartmentIndex, std::size_t maxTriangleArea)
Set the maximum allowed triangle area for a given compartment.
- Parameters:
compartmentIndex – [in] the index of the compartment
maxTriangleArea – [in] the maximum allowed triangle area
-
std::size_t getCompartmentMaxTriangleArea(std::size_t compartmentIndex) const
Get the maximum allowed triangle area for a given compartment.
- Parameters:
compartmentIndex – [in] the index of the compartment
-
const std::vector<std::size_t> &getCompartmentMaxTriangleArea() const
The maximum allowed triangle areas for each compartment in the mesh.
-
const std::vector<std::vector<QPointF>> &getCompartmentInteriorPoints() const
The interior points for each compartment in the mesh.
Each interior point is chosen to be as far as possible from the edge of the region, to reduce the chance that it ends up outside the meshed approximation to the region as the boundary lines are simplified.
Note
There may be multiple interior points for a single compartment, for example if that compartment has two disconnected regions
-
void setPhysicalGeometry(const common::VolumeF &voxelSize, const common::VoxelF &originPoint = {0.0, 0.0, 0.0})
The physical volume and origin to use.
The boundary lines and mesh use pixel units internally, and are rescaled to physical values using the supplied physical origin and pixel width.
- Parameters:
voxelSize – [in] the physical size of a voxel
originPoint – [in] the physical location of the
(0,0,0)
voxel
-
std::vector<double> getVerticesAsFlatArray() const
The physical mesh vertices as a flat array of doubles.
For saving to the SBML document.
-
std::vector<int> getTriangleIndicesAsFlatArray(std::size_t compartmentIndex) const
The mesh triangle indices as a flat array of ints.
For saving to the SBML document.
-
const std::vector<std::vector<TriangulateTriangleIndex>> &getTriangleIndices() const
The mesh triangle indices.
The indices of the triangles used in the mesh for each compartment
-
std::pair<common::ImageStack, common::ImageStack> getBoundariesImages(const QSize &size, std::size_t boldBoundaryIndex) const
An image of the compartment boundary lines.
A pair of images are returned, the first is the image of the boundary lines, and the second is a map from each pixel to the corresponding boundary index, which can be used to identify which boundary was clicked on by the user.
- Parameters:
size – [in] the desired size of the image
boldBoundaryIndex – [in] the boundary line to emphasize in the image
-
std::pair<common::ImageStack, common::ImageStack> getMeshImages(const QSize &size, std::size_t compartmentIndex) const
An image of the mesh.
A pair of images are returned, the first is the image of the mesh, and the second is a map from each pixel to the corresponding compartment index, which can be used to identify which compartment was clicked on by the user.
- Parameters:
size – [in] the desired size of the image
compartmentIndex – [in] the compartment to emphasize in the image
- Returns:
a pair of images: mesh, compartment index
-
QString getGMSH() const
The mesh in GMSH format.
- Returns:
the mesh in GMSH format
Public Static Attributes
-
static constexpr std::size_t dim = 2
-
Mesh2d()
-
class Mesh3d
Public Functions
-
Mesh3d()
-
explicit Mesh3d(const sme::common::ImageStack &imageStack, std::vector<std::size_t> maxCellVolume = {}, const common::VolumeF &voxelSize = {1.0, 1.0, 1.0}, const common::VoxelF &originPoint = {0.0, 0.0, 0.0}, std::vector<QRgb> compartmentColours = {})
Constructs a 3d mesh from the supplied ImageStack.
- Parameters:
imageStack – [in] the segmented geometry ImageStack
maxCellVolume – [in] the max volume (in voxels) of a cell for each compartment
voxelSize – [in] the physical size of a voxel
originPoint – [in] the physical location of the
(0,0,0)
voxelcompartmentColours – [in] the colours of compartments in the image
-
~Mesh3d()
-
bool isValid() const
Returns true if the mesh is valid.
-
const std::string &getErrorMessage() const
Returns an error message if the mesh is invalid.
-
void setCompartmentMaxCellVolume(std::size_t compartmentIndex, std::size_t maxCellVolume)
Set the maximum allowed cell volume in voxels for a given compartment.
- Parameters:
compartmentIndex – [in] the index of the compartment
maxTriangleArea – [in] the maximum allowed cell volume in voxels
-
std::size_t getCompartmentMaxCellVolume(std::size_t compartmentIndex) const
Get the maximum allowed cell volume for a given compartment.
- Parameters:
compartmentIndex – [in] the index of the compartment
-
const std::vector<std::size_t> &getCompartmentMaxCellVolume() const
The maximum allowed cell volume in voxels for each compartment in the mesh.
-
void setPhysicalGeometry(const common::VolumeF &voxelSize, const common::VoxelF &originPoint = {0.0, 0.0, 0.0})
The physical volume and origin to use.
The boundary lines and mesh use pixel units internally, and are rescaled to physical values using the supplied physical origin and pixel width.
- Parameters:
voxelSize – [in] the physical size of a voxel
originPoint – [in] the physical location of the
(0,0,0)
voxel
-
const std::vector<sme::common::VoxelF> &getVertices() const
The physical mesh vertices as a vector of VoxelF.
-
std::vector<double> getVerticesAsFlatArray() const
The physical mesh vertices as a flat array of doubles.
For saving to the SBML document.
-
std::size_t getNumberOfCompartments() const
- Returns:
number of compartments available.
-
std::vector<int> getTetrahedronIndicesAsFlatArray(std::size_t compartmentIndex) const
The mesh tetrahedron indices as a flat array of ints.
For saving to the SBML document.
-
const std::vector<std::vector<TetrahedronVertexIndices>> &getTetrahedronIndices() const
The mesh tetrahedron indices.
The indices of the vertices of each tetrahedron used in the mesh for each compartment
-
QString getGMSH() const
The mesh in GMSH format.
- Returns:
the mesh in GMSH format
-
const std::vector<QRgb> &getColors() const
Get the colors of the compartments.
-
void setColors(std::vector<QRgb> colors)
Set the colors of the compartments.
Public Static Attributes
-
static constexpr std::size_t dim = 3
-
Mesh3d()