rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
mesh.hpp File Reference

Provides all the mesh tools used for the generation of 3D grids and geometries. More...

#include <algorithm>
#include <array>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>
#include "arraystructures.hpp"
#include "warning.hpp"

Go to the source code of this file.

Classes

class  coordvec
 Handles the use and norm of a vector for which the norm and the unit value might be needed. More...
 
class  meshpart
 /Abstract class to ensure mesh interfaces are correct. More...
 
class  volu
 Class for volume cell objects in a mesh. More...
 
class  surf
 Class for surface object in a mesh. More...
 
class  edge
 Class for an edge object in a mesh. More...
 
class  vert
 Class for a vertex in a mesh. More...
 
class  ConnecRemv
 Class containing the information needed to trim objects from a mesh. More...
 
class  meshdependence
 Class for connecting meshes. More...
 
class  mesh
 Class for mesh handling. More...
 

Namespaces

 rsvs3d
 Namespace for general purpose tools of the RSVS project.
 

Typedefs

typedef ModiftrackArray< surfsurfarray
 
typedef ArrayStruct< voluvoluarray
 
typedef ModiftrackArray< edgeedgearray
 
typedef ArrayStruct< vertvertarray
 
typedef std::array< std::array< double, 2 >, 3 > grid::limits
 
typedef std::array< std::array< double, 3 >, 3 > grid::transformation
 Defines a linear transformation to the mesh where for each dimension: {new minimum, old minimum , scaling}.
 
typedef std::vector< const std::vector< double > * > grid::coordlist
 Defines a list of coordinates.
 

Functions

void ConnVertFromConnEdge (const mesh &meshin, const std::vector< int > &edgeind, std::vector< int > &vertind)
 
std::pair< int, int > OrderMatchLists (const std::vector< int > &vec1, int p1, int p2)
 
int OrderMatchLists (const std::vector< int > &vec1, const std::vector< int > &vec2, int p1, int p2)
 
void CropMeshGreedy (mesh &meshin, const std::vector< double > &lb, const std::vector< double > &ub)
 Crops a mesh to only the elements inside the cropBox. More...
 
int OrderEdgeList (std::vector< int > &edgeind, const mesh &meshin, bool warn=true, bool errout=true, const std::vector< int > *edgeIndOrigPtr=NULL, const surf *surfin=NULL)
 Orders a list of edge to be connected. More...
 
int OrderList (std::vector< int > &edgeind, const std::vector< int > &edge2Vert, bool warn=true, bool errout=true, const std::vector< int > *edgeIndOrigPtr=NULL)
 Orders a list of elements defined by pairs of indices. More...
 
void DiffPointsFromCentre (const std::vector< double > &centre, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, coordvec &normal, coordvec &temp1)
 Computes vector between vertices to then compute angles and plane normals. More...
 
void DiffPoints (const std::vector< double > &vert1, const std::vector< double > &vert2, coordvec &diffVerts)
 Computes vector between vertices to then compute angles and plane normals. More...
 
double Angle3Points (const std::vector< double > &centre, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, coordvec &vec1, coordvec &vec2)
 Calculates a plane's normal vector. More...
 
double VertexDistanceToPlane (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, const std::vector< double > &testVertex, coordvec &temp1, coordvec &temp2)
 Calculates the distance from a vertex to a plane. More...
 
std::vector< double > VerticesDistanceToPlane (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, const std::vector< double > &testVertices, coordvec &temp1, coordvec &temp2)
 Calculates the distance from a set of vertices to a plane. More...
 
double VertexDistanceToPlane (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, const std::vector< double > &testVertex)
 
std::vector< double > VerticesDistanceToPlane (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, const std::vector< double > &testVertices)
 
mesh Points2Mesh (const std::vector< double > &vecPts, int nProp=3)
 Takes in a set of points and returns a mesh of points ready for voronisation. More...
 
double PlanesDotProduct (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, const std::vector< double > &planeVert4, const std::vector< double > &planeVert5, const std::vector< double > &planeVert6, bool normalize=true)
 
void PlaneNormal (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, coordvec &normal, coordvec &temp1)
 Calculates a plane's normal vector. More...
 
double PlaneNormalAndAngle (const std::vector< double > &planeVert1, const std::vector< double > &planeVert2, const std::vector< double > &planeVert3, coordvec &normal, coordvec &temp1)
 Calculates a plane's normal vector. More...
 
std::tuple< coordvec, double > VertexNormal (const std::vector< double > &centre, const grid::coordlist &vecPts)
 Calculates the vertex normal weighted by surface angle partitions. More...
 
template<class T , class V , class W >
double meshhelp::ProjectRay (int count, const W &&boundBox, const T &dir, const V &orig, double minDist=0.0)
 
void meshhelp::PlaceBorderVertex (const std::vector< double > &coordIn, const std::vector< double > &coordOut, const std::vector< double > &lb, const std::vector< double > &ub, std::vector< double > &coordTarg)
 
void meshhelp::SplitBorderSurfaceEdgeind (const mesh &meshin, const std::vector< bool > &edgeOut, std::vector< int > &vecconnIn, std::vector< int > &vecconnOut)
 
void meshhelp::SplitBorderVolumeSurfind (const mesh &meshin, const std::vector< bool > &edgeOut, std::vector< int > &vecconnIn, std::vector< int > &vecconnOut)
 
void meshhelp::HandleMultiSurfaceSplit (mesh &meshin, vector< int > &edgeindOld, vector< int > &edgeindNew, vector< int > &vertindNew)
 Handles case for AddBoundary where a surface more than one split. More...
 
std::vector< int > meshhelp::FindVertInFromEdgeOut (const mesh &meshin, const std::vector< bool > &vertOut, const std::vector< int > &edgeList, const std::vector< int > &edgeListCheck)
 
std::vector< int > meshhelp::FindEdgeInFromSurfOut (const mesh &meshin, const std::vector< bool > &edgeOut, std::vector< int > surfList)
 
double meshhelp::VerticesDistanceSquared (const mesh &meshin, const vector< int > &vertind)
 
double meshhelp::VerticesDistance (const mesh &meshin, const vector< int > &vertind)
 
bool meshhelp::IsVerticesDistance0 (const mesh &meshin, const vector< int > &vertind, double eps)
 
int meshhelp::VertexInVolume (const mesh &meshin, const vector< double > testCoord, bool needFlip)
 
int meshhelp::Get3PointsInSurface (const mesh &meshin, int surfCurr, std::array< int, 3 > &surfacePoints)
 Gets 3 unique points in the surface. More...
 
int meshhelp::NormalShouldFlip (const std::vector< int > orderedList, int elm1, int elm2, const std::vector< int > &voluind, bool innerComparison)
 Answers if a normal should be flipped to point towards the outside of a volume. More...
 
int Test_ArrayStructures ()
 
int Test_Volu ()
 
int Test_Surf ()
 
int Test_Vert ()
 
int Test_Edge ()
 
int Test_Mesh ()
 
int Test_Crop ()
 

Variables

static const auto rsvs3d::constants::__issetlength = [](double l) -> bool { return l >= -0.0; }
 
static const double rsvs3d::constants::__unsetlength = -1.0
 
static const int rsvs3d::constants::ordering::ordered = 0
 
static const int rsvs3d::constants::ordering::truncated = 1
 
static const int rsvs3d::constants::ordering::open = -1
 
static const int rsvs3d::constants::ordering::error = 2
 
static const auto rsvs3d::constants::ordering::__isordered = [](int l) -> bool { return l == ordered; }
 

Detailed Description

Provides all the mesh tools used for the generation of 3D grids and geometries.

This file provides the mesh class and it's associated sub-component. These can be used to robustly control changes in geometry.

Definition in file mesh.hpp.

Function Documentation

◆ Angle3Points()

double Angle3Points ( const vector< double > &  centre,
const vector< double > &  planeVert2,
const vector< double > &  planeVert3,
coordvec normal,
coordvec temp1 
)

Calculates a plane's normal vector.

Parameters
[in]planeVert1The plane vertex 1
[in]planeVert2The plane vertex 2
[in]planeVert3The plane vertex 3
normalThe normal
temp1The temporary 1
Returns
returns the angle between the two vectors defining the plane <[v2-v1] , [v3-v1]>

Definition at line 373 of file mesh.cpp.

◆ CropMeshGreedy()

void CropMeshGreedy ( mesh meshin,
const std::vector< double > &  lb,
const std::vector< double > &  ub 
)

Crops a mesh to only the elements inside the cropBox.

Anything impinging on the cropBox is deleted. Steps: 1 - Find vertices out of the box 2 - Delete those vertices 3 - Propagate the deletion to the higher level containers 4 - Propagate back to the lower level containers removing empty connectors.

Parameters
meshinInput mesh
[in]lblower bound vector
[in]ubupper bound vector

Definition at line 6264 of file mesh.cpp.

◆ DiffPoints()

void DiffPoints ( const vector< double > &  vert1,
const vector< double > &  vert2,
coordvec diffVerts 
)

Computes vector between vertices to then compute angles and plane normals.

Parameters
[in]vert1The first vertex
[in]vert2the second vertex
diffVertsThe difference : vert2 - vert1

Definition at line 296 of file mesh.cpp.

◆ DiffPointsFromCentre()

void DiffPointsFromCentre ( const vector< double > &  centre,
const vector< double > &  vert1,
const vector< double > &  vert2,
coordvec diffVert1,
coordvec diffVert2 
)

Computes vector between vertices to then compute angles and plane normals.

Parameters
[in]centreThe starting vertex for all vertices
[in]vert1The first vertex
[in]vert2the second vertex
diffVert1The difference : vert1 - centre
diffVert2The difference : vert2 - centre

Definition at line 313 of file mesh.cpp.

◆ Get3PointsInSurface()

int meshhelp::Get3PointsInSurface ( const mesh meshin,
int  surfCurr,
std::array< int, 3 > &  surfacePoints 
)

Gets 3 unique points in the surface.

These points are guaranteed to be separate

Parameters
[in]meshinThe input mesh
[in]surfCurrcurrent surface index to analyse.
[out]surfacePointsThe surface points indices.
Returns
The number of points which have been found.

Definition at line 6576 of file mesh.cpp.

◆ HandleMultiSurfaceSplit()

void meshhelp::HandleMultiSurfaceSplit ( mesh meshin,
vector< int > &  edgeindOld,
vector< int > &  edgeindNew,
vector< int > &  vertindNew 
)

Handles case for AddBoundary where a surface more than one split.

Parameters
meshinThe mesh
edgeindOldthe edgeind internal
edgeindNewthe edgeind out of the boundary (that will be split)
vertindNewthe vertex index that must be trimmed to be of size 2

Definition at line 6396 of file mesh.cpp.

◆ NormalShouldFlip()

int meshhelp::NormalShouldFlip ( const std::vector< int >  orderedList,
int  elm1,
int  elm2,
const std::vector< int > &  voluind,
bool  innerComparison 
)

Answers if a normal should be flipped to point towards the outside of a volume.

Parameters
[in]orderedListAn ordered list of elements indicating the orientation of an object.
[in]elm1The first element of a second ordered list.
[in]elm2The second element of this second ordered list, these two elements are sufficient to represent that list and are enough to represent it.
[in]voluindNormally the volume indices of a surface object. Could be any list with one 0 and one Non zero elements.
[in]innerComparisonIs this comparing two lists with an object inside the other or two outer neighbouring lists. If one is inside the other they are expected to go in the same direction otherwise they need to be contra-rotating (for no flip required).
Returns
-1 if the normal vector needs to be flipped to point outwards. 1 otherwise.

Definition at line 777 of file mesh.cpp.

◆ OrderEdgeList()

int OrderEdgeList ( vector< int > &  edgeind,
const mesh meshin,
bool  warn,
bool  errout,
const vector< int > *  edgeIndOrigPtr,
const surf surfin 
)

Orders a list of edge to be connected.

This list of edges is ordered in place. THis will not work for self crossing lists.

Parameters
edgeindThe edgeind
[in]meshinThe meshin
[in]warnThe warning
[in]erroutThe errout
Returns
the return value is a flag which can be: 0 - the edges have been ordered and closed 1 - the edges have been ordered and closed but the list was truncated. <0 - The edges are ordered but not closed. (need errout to be false) for edgeind of size -<return val>

Definition at line 3287 of file mesh.cpp.

◆ OrderList()

int OrderList ( vector< int > &  edgeind,
const vector< int > &  edge2Vert,
bool  warn,
bool  errout,
const vector< int > *  edgeIndOrigPtr 
)

Orders a list of elements defined by pairs of indices.

Each element is defined by 1 index in edgeind and 2 indices in edge2Vert. The two indices are then matched to the next element chaining equal indices together.

Parameters
edgeindThe edgeind
[in]edge2VertThe edge 2 vertical
[in]warnThe warning
[in]erroutThe errout
[in]edgeIndOrigPtrThe edge ind original pointer
Returns
the return value is one of the globals defined in namespace: rsvs3d::constants::ordering::(currently:<ordered,truncated, open, error>)

Definition at line 3449 of file mesh.cpp.

◆ PlaneNormal()

void PlaneNormal ( const vector< double > &  planeVert1,
const vector< double > &  planeVert2,
const vector< double > &  planeVert3,
coordvec normal,
coordvec temp1 
)

Calculates a plane's normal vector.

Parameters
[in]planeVert1The plane vertex 1
[in]planeVert2The plane vertex 2
[in]planeVert3The plane vertex 3
normalThe normal
temp1The temporary 1

Definition at line 333 of file mesh.cpp.

◆ PlaneNormalAndAngle()

double PlaneNormalAndAngle ( const vector< double > &  planeVert1,
const vector< double > &  planeVert2,
const vector< double > &  planeVert3,
coordvec normal,
coordvec temp1 
)

Calculates a plane's normal vector.

Parameters
[in]planeVert1The plane vertex 1
[in]planeVert2The plane vertex 2
[in]planeVert3The plane vertex 3
normalThe normal
temp1The temporary 1
Returns
returns the angle between the two vectors defining the plane <[v2-v1] , [v3-v1]>

Definition at line 352 of file mesh.cpp.

◆ Points2Mesh()

mesh Points2Mesh ( const std::vector< double > &  vecPts,
int  nProp 
)

Takes in a set of points and returns a mesh of points ready for voronisation.

Parameters
[in]vecPtsThe vector of points
[in]nPropnumber of properties per point
Returns
The points in the mesh format

Definition at line 6293 of file mesh.cpp.

◆ VertexDistanceToPlane()

double VertexDistanceToPlane ( const vector< double > &  planeVert1,
const vector< double > &  planeVert2,
const vector< double > &  planeVert3,
const vector< double > &  testVertex,
coordvec temp1,
coordvec temp2 
)

Calculates the distance from a vertex to a plane.

calculates the distance from a plane to a vertex, with the plane defined by three vertices.

Two optional arguments can be provided to avoid the need for memory allocation if this is called in a loop. For max speedup if testing a surface multiple times against many vertices temp2 can be reused

Parameters
[in]planeVert1The plane vertex 1
[in]planeVert2The plane vertex 2
[in]planeVert3The plane vertex 3
[in]testVertexThe test vertex
[in|out]temp1 The temporary array 1
[in|out]temp2 The temporary array 2
Returns
the distance from the plane to the vertex

Definition at line 400 of file mesh.cpp.

◆ VertexNormal()

std::tuple<coordvec, double> VertexNormal ( const std::vector< double > &  centre,
const grid::coordlist vecPts 
)

Calculates the vertex normal weighted by surface angle partitions.

Parameters
[in]centreThe coordinate at which the normal needs to be evaluated.
[in]vecPtsThe points used to compute the normal.
Returns
A tuple with the normal vector and the total angle between the surfaces. This angle is a measure of the local curvature.

Definition at line 747 of file mesh.cpp.

◆ VerticesDistanceToPlane()

std::vector<double> VerticesDistanceToPlane ( const vector< double > &  planeVert1,
const vector< double > &  planeVert2,
const vector< double > &  planeVert3,
const vector< double > &  testVertices,
coordvec temp1,
coordvec temp2 
)

Calculates the distance from a set of vertices to a plane.

Calculates the distance from a plane to a vertex, with the plane defined by three vertices.

Two optional arguments can be provided to avoid the need for memory allocation if this is called in a loop. For max speedup if testing a surface multiple times against many vertices temp2 is reused internally allowing surface properties to only be calculated once.

Parameters
[in]planeVert1The plane vertex 1
[in]planeVert2The plane vertex 2
[in]planeVert3The plane vertex 3
[in]testVerticesThe test vertices
[in|out]temp1 The temporary array 1
[in|out]temp2 The temporary array 2
Returns
the distance from the plane to the vertex

Definition at line 438 of file mesh.cpp.