Mesh: remove problematic method MeshGrid::Rebuild(unsigned long, unsigned long)
and MeshGrid::CalculateGridLength(unsigned long, unsigned long) For almost flat meshes CalculateGridLength may compute a grid with a huge amount of cells that allocates the whole RAM of the system while for an exactly flat mesh a grid with a sensible number of cells is computed. Use the overloaded methods of MeshGrid::Rebuild(unsigned long) and MeshGrid::CalculateGridLength(unsigned long) instead
This commit is contained in:
@@ -177,11 +177,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void CalculateGridLength(unsigned long /*ulCtGrid*/, unsigned long /*ulMaxGrids*/) override
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CalculateGridLength(int /*iCtGridPerAxis*/) override
|
||||
{
|
||||
// do nothing
|
||||
|
||||
@@ -83,13 +83,6 @@ void MeshGrid::Rebuild(unsigned long ulX, unsigned long ulY, unsigned long ulZ)
|
||||
RebuildGrid();
|
||||
}
|
||||
|
||||
void MeshGrid::Rebuild(unsigned long ulPerGrid, unsigned long ulMaxGrid)
|
||||
{
|
||||
_ulCtElements = HasElements();
|
||||
CalculateGridLength(ulPerGrid, ulMaxGrid);
|
||||
RebuildGrid();
|
||||
}
|
||||
|
||||
void MeshGrid::Rebuild(int iCtGridPerAxis)
|
||||
{
|
||||
_ulCtElements = HasElements();
|
||||
@@ -104,7 +97,7 @@ void MeshGrid::InitGrid()
|
||||
// Calculate grid length if not initialised
|
||||
//
|
||||
if ((_ulCtGridsX == 0) || (_ulCtGridsY == 0) || (_ulCtGridsZ == 0)) {
|
||||
CalculateGridLength(MESH_CT_GRID, MESH_MAX_GRIDS);
|
||||
CalculateGridLength(MESH_CT_GRID_PER_AXIS);
|
||||
}
|
||||
|
||||
// Determine grid length and offset
|
||||
@@ -286,66 +279,8 @@ void MeshGrid::Position(const Base::Vector3f& rclPoint,
|
||||
}
|
||||
}
|
||||
|
||||
void MeshGrid::CalculateGridLength(unsigned long ulCtGrid, unsigned long ulMaxGrids)
|
||||
{
|
||||
// Calculate grid lengths or number of grids per dimension
|
||||
// There should be about 10 (?!?!) facets per grid
|
||||
// respectively max grids should not exceed 10000
|
||||
Base::BoundBox3f clBBMeshEnlarged = _pclMesh->GetBoundBox();
|
||||
float fGridLen = 0;
|
||||
|
||||
float fLenX = clBBMeshEnlarged.LengthX();
|
||||
float fLenY = clBBMeshEnlarged.LengthY();
|
||||
float fLenZ = clBBMeshEnlarged.LengthZ();
|
||||
|
||||
float fVolume = fLenX * fLenY * fLenZ;
|
||||
if (fVolume > 0.0f) {
|
||||
float fVolElem {};
|
||||
if (_ulCtElements > (ulMaxGrids * ulCtGrid)) {
|
||||
fVolElem = (fLenX * fLenY * fLenZ) / float(ulMaxGrids * ulCtGrid);
|
||||
}
|
||||
else {
|
||||
fVolElem = (fLenX * fLenY * fLenZ) / float(_ulCtElements);
|
||||
}
|
||||
|
||||
float fVol = fVolElem * float(ulCtGrid);
|
||||
fGridLen = float(pow(fVol, 1.0f / 3.0f));
|
||||
}
|
||||
else {
|
||||
// Planar bounding box
|
||||
float fArea = fLenX * fLenY + fLenX * fLenZ + fLenY * fLenZ;
|
||||
float fAreaElem {};
|
||||
if (_ulCtElements > (ulMaxGrids * ulCtGrid)) {
|
||||
fAreaElem = fArea / float(ulMaxGrids * ulCtGrid);
|
||||
}
|
||||
else {
|
||||
fAreaElem = fArea / float(_ulCtElements);
|
||||
}
|
||||
|
||||
float fRepresentativeArea = fAreaElem * static_cast<float>(ulCtGrid);
|
||||
fGridLen = sqrt(fRepresentativeArea);
|
||||
}
|
||||
|
||||
if (fGridLen > 0) {
|
||||
_ulCtGridsX = std::max<unsigned long>(static_cast<unsigned long>(fLenX / fGridLen), 1);
|
||||
_ulCtGridsY = std::max<unsigned long>(static_cast<unsigned long>(fLenY / fGridLen), 1);
|
||||
_ulCtGridsZ = std::max<unsigned long>(static_cast<unsigned long>(fLenZ / fGridLen), 1);
|
||||
}
|
||||
else {
|
||||
// Degenerated grid
|
||||
_ulCtGridsX = 1;
|
||||
_ulCtGridsY = 1;
|
||||
_ulCtGridsZ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void MeshGrid::CalculateGridLength(int iCtGridPerAxis)
|
||||
{
|
||||
if (iCtGridPerAxis <= 0) {
|
||||
CalculateGridLength(MESH_CT_GRID, MESH_MAX_GRIDS);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate grid lengths or number of grids per dimension
|
||||
// There should be about 10 (?!?!) facets per grid
|
||||
// respectively max grids should not exceed 10000
|
||||
@@ -405,12 +340,9 @@ void MeshGrid::CalculateGridLength(int iCtGridPerAxis)
|
||||
|
||||
float fLengthGrid = pow(fVolumenGrid, 1.0f / 3.0f);
|
||||
|
||||
_ulCtGridsX =
|
||||
std::max<unsigned long>(static_cast<unsigned long>(fLenghtX / fLengthGrid), 1);
|
||||
_ulCtGridsY =
|
||||
std::max<unsigned long>(static_cast<unsigned long>(fLenghtY / fLengthGrid), 1);
|
||||
_ulCtGridsZ =
|
||||
std::max<unsigned long>(static_cast<unsigned long>(fLenghtZ / fLengthGrid), 1);
|
||||
_ulCtGridsX = std::max(static_cast<unsigned long>(fLenghtX / fLengthGrid), 1UL);
|
||||
_ulCtGridsY = std::max(static_cast<unsigned long>(fLenghtY / fLengthGrid), 1UL);
|
||||
_ulCtGridsZ = std::max(static_cast<unsigned long>(fLenghtZ / fLengthGrid), 1UL);
|
||||
|
||||
} break;
|
||||
case 1: {
|
||||
|
||||
@@ -76,9 +76,6 @@ public:
|
||||
* rebuilt automatically. */
|
||||
virtual void Attach(const MeshKernel& rclM);
|
||||
/** Rebuilds the grid structure. */
|
||||
virtual void Rebuild(unsigned long ulPerGrid = MESH_CT_GRID,
|
||||
unsigned long ulMaxGrid = MESH_MAX_GRIDS);
|
||||
/** Rebuilds the grid structure. */
|
||||
virtual void Rebuild(int iCtGridPerAxis = MESH_CT_GRID_PER_AXIS);
|
||||
/** Rebuilds the grid structure. */
|
||||
virtual void Rebuild(unsigned long ulX, unsigned long ulY, unsigned long ulZ);
|
||||
@@ -189,8 +186,6 @@ protected:
|
||||
virtual void InitGrid();
|
||||
/** Deletes the grid structure. */
|
||||
virtual void Clear();
|
||||
/** Calculates the grid length dependent on maximum number of grids. */
|
||||
virtual void CalculateGridLength(unsigned long ulCtGrid, unsigned long ulMaxGrids);
|
||||
/** Calculates the grid length dependent on the number of grids per axis. */
|
||||
virtual void CalculateGridLength(int iCtGridPerAxis);
|
||||
/** Rebuilds the grid structure. Must be implemented in sub-classes. */
|
||||
|
||||
Reference in New Issue
Block a user