inc

Mesh

class sme::mesh::Mesh

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

Mesh()
explicit Mesh(const QImage &image, std::vector<std::size_t> maxPoints = {}, std::vector<std::size_t> maxTriangleArea = {}, double pixelWidth = 1.0, const QPointF &originPoint = QPointF(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

  • pixelWidth[in] the physical width of a pixel

  • originPoint[in] the physical location of the (0,0) pixel

  • compartmentColours[in] the colours of compartments in the image

~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(double pixelWidth, const QPointF &originPoint = QPointF(0, 0))

The physical size 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
  • pixelWidth[in] the physical width of a pixel

  • originPoint[in] the physical location of the (0,0) pixel

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<QImage, QImage> 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<QImage, QImage> 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