Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH/BUG : Update node based geometry find element family of functions #991

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ Result<> FeatureFaceCurvature::operator()()

// Make sure the Face Connectivity is created because the FindNRing algorithm needs this and will
// assert if the data is NOT in the SurfaceMesh Data Container
const IGeometry::ElementDynamicList* vertLinks = triangleGeomPtr->getElementsContainingVert();
if(nullptr == vertLinks)
{
triangleGeomPtr->findElementsContainingVert();
}
triangleGeomPtr->findElementsContainingVert(false);

int32_t maxFaceId = 0;
for(int64_t t = 0; t < numTriangles; ++t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ Result<> FindNRingNeighbors::operator()(const IFilter::MessageHandler& mesgHandl
m_NRingTriangles.clear();

// Make sure we have the proper connectivity built
const INodeGeometry1D::ElementDynamicList* node2TrianglePtr = triangleGeom->getElementsContainingVert();
if(node2TrianglePtr == nullptr)
err = triangleGeom->findElementsContainingVert(false);
if(err < 0)
{
err = triangleGeom->findElementsContainingVert();
if(err < 0)
{
return MakeErrorResult(err, "Failed to find elements containing vert");
}
node2TrianglePtr = triangleGeom->getElementsContainingVert();
return MakeErrorResult(err, "Failed to find elements containing vert");
}
const INodeGeometry1D::ElementDynamicList* node2TrianglePtr = triangleGeom->getElementsContainingVert();

// Figure out these boolean values for a sanity check
bool check0 = faceLabels[triangleId * 2] == m_InputValues->RegionId0 && faceLabels[triangleId * 2 + 1] == m_InputValues->RegionId1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Result<> LabelTriangleGeometry::operator()()
{
usize numTris = triangle.getNumberOfFaces();

auto check = triangle.findElementNeighbors(); // use auto since return time is a class declared typename
auto check = triangle.findElementNeighbors(false); // use auto since return time is a class declared typename
if(check < 0)
{
return MakeErrorResult(check, fmt::format("Error finding element neighbors for {} geometry", triangle.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ Result<> LaplacianSmoothing::edgeBasedSmoothing()
std::vector<float> lambdas = generateLambdaArray();

// Generate the Unique Edges
if(nullptr == surfaceMesh.getEdges())
{
err = surfaceMesh.findEdges();
}
err = surfaceMesh.findEdges(false);
if(err < 0)
{
return MakeErrorResult(-560, "Error retrieving the shared edge list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ Result<> ComputeFeatureSizesFilter::executeImpl(DataStructure& dataStructure, co

if(saveElementSizes)
{
if(!imageGeom->getElementSizes())
int32 err = imageGeom->findElementSizes(false);
if(err < 0)
{
int32 err = imageGeom->findElementSizes();
if(err < 0)
{
std::string ss = fmt::format("Error computing Element sizes for Geometry type {}", imageGeom->getTypeName());
return {nonstd::make_unexpected(std::vector<Error>{Error{err, ss}})};
}
std::string ss = fmt::format("Error computing Element sizes for Geometry type {}", imageGeom->getTypeName());
return {nonstd::make_unexpected(std::vector<Error>{Error{err, ss}})};
}
}
}
Expand All @@ -255,14 +252,11 @@ Result<> ComputeFeatureSizesFilter::executeImpl(DataStructure& dataStructure, co

usize numfeatures = volumes.getNumberOfTuples();

if(!geom->getElementSizes())
int32_t err = geom->findElementSizes(false);
if(err < 0)
{
int32_t err = geom->findElementSizes();
if(err < 0)
{
std::string ss = fmt::format("Error computing Element sizes for Geometry type {}", geom->getTypeName());
return {nonstd::make_unexpected(std::vector<Error>{Error{err, ss}})};
}
std::string ss = fmt::format("Error computing Element sizes for Geometry type {}", geom->getTypeName());
return {nonstd::make_unexpected(std::vector<Error>{Error{err, ss}})};
}

const Float32Array* elemSizes = geom->getElementSizes();
Expand Down
80 changes: 54 additions & 26 deletions src/simplnx/DataStructure/Geometry/EdgeGeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,21 @@ std::shared_ptr<DataObject> EdgeGeom::deepCopy(const DataPath& copyPath)
return nullptr;
}

IGeometry::StatusCode EdgeGeom::findElementSizes()
IGeometry::StatusCode EdgeGeom::findElementSizes(bool recalculate)
{
auto dataStore = std::make_unique<DataStore<float32>>(getNumberOfCells(), 0.0f);
auto* sizes = DataArray<float32>::Create(*getDataStructure(), k_VoxelSizes, std::move(dataStore), getId());
auto* sizes = getDataStructureRef().getDataAs<Float32Array>(m_ElementSizesId);
if(sizes != nullptr && !recalculate)
{
return 0;
}
if(sizes == nullptr)
{
auto dataStore = std::make_unique<DataStore<float32>>(getNumberOfCells(), 0.0f);
sizes = DataArray<float32>::Create(*getDataStructure(), k_VoxelSizes, std::move(dataStore), getId());
}
if(sizes == nullptr)
{
m_ElementSizesId.reset();
return -1;
}
m_ElementSizesId = sizes->getId();
Expand All @@ -163,59 +172,78 @@ IGeometry::StatusCode EdgeGeom::findElementSizes()
return 1;
}

IGeometry::StatusCode EdgeGeom::findElementsContainingVert()
IGeometry::StatusCode EdgeGeom::findElementsContainingVert(bool recalculate)
{
auto* containsVert = ElementDynamicList::Create(*getDataStructure(), k_EltsContainingVert, getId());
auto* containsVert = getDataStructureRef().getDataAs<ElementDynamicList>(m_CellContainingVertDataArrayId);
if(containsVert != nullptr && !recalculate)
{
return 0;
}
if(containsVert == nullptr)
{
return -1;
containsVert = ElementDynamicList::Create(*getDataStructure(), k_EltsContainingVert, getId());
}
GeometryHelpers::Connectivity::FindElementsContainingVert<uint16, MeshIndexType>(getEdges(), containsVert, getNumberOfVertices());
if(containsVert == nullptr)
{
m_CellContainingVertDataArrayId.reset();
return -1;
}
GeometryHelpers::Connectivity::FindElementsContainingVert<uint16, MeshIndexType>(getEdges(), containsVert, getNumberOfVertices());
m_CellContainingVertDataArrayId = containsVert->getId();
return 1;
}

IGeometry::StatusCode EdgeGeom::findElementNeighbors()
IGeometry::StatusCode EdgeGeom::findElementNeighbors(bool recalculate)
{
StatusCode err = 0;
if(getElementsContainingVert() == nullptr)
auto* edgeNeighbors = getDataStructureRef().getDataAs<ElementDynamicList>(m_CellNeighborsDataArrayId);
if(edgeNeighbors != nullptr && !recalculate)
{
err = findElementsContainingVert();
if(err < 0)
{
return err;
}
return 0;
}
auto* edgeNeighbors = ElementDynamicList::Create(*getDataStructure(), k_EltNeighbors, getId());
if(edgeNeighbors == nullptr)

StatusCode err = findElementsContainingVert(recalculate);
if(err < 0)
{
err = -1;
m_CellNeighborsDataArrayId.reset();
return err;
}
if(edgeNeighbors == nullptr)
{
edgeNeighbors = ElementDynamicList::Create(*getDataStructure(), k_EltNeighbors, getId());
}
if(edgeNeighbors == nullptr)
{
m_CellNeighborsDataArrayId.reset();
return -1;
}
m_CellNeighborsDataArrayId = edgeNeighbors->getId();
err = GeometryHelpers::Connectivity::FindElementNeighbors<uint16, MeshIndexType>(getEdges(), getElementsContainingVert(), edgeNeighbors, IGeometry::Type::Edge);
if(getElementNeighbors() == nullptr)
if(edgeNeighbors == nullptr)
{
m_CellNeighborsDataArrayId.reset();
err = -1;
return -1;
}
return err;
return 1;
}

IGeometry::StatusCode EdgeGeom::findElementCentroids()
IGeometry::StatusCode EdgeGeom::findElementCentroids(bool recalculate)
{
auto dataStore = std::make_unique<DataStore<float32>>(std::vector<usize>{getNumberOfCells()}, std::vector<usize>{3}, 0.0f);
auto* edgeCentroids = DataArray<float32>::Create(*getDataStructure(), k_EltCentroids, std::move(dataStore), getId());
GeometryHelpers::Topology::FindElementCentroids(getEdges(), getVertices(), edgeCentroids);
if(getElementCentroids() == nullptr)
auto* edgeCentroids = getDataStructureRef().getDataAs<Float32Array>(m_CellCentroidsDataArrayId);
if(edgeCentroids != nullptr && !recalculate)
{
return 0;
}
if(edgeCentroids == nullptr)
{
auto dataStore = std::make_unique<DataStore<float32>>(std::vector<usize>{getNumberOfCells()}, std::vector<usize>{3}, 0.0f);
edgeCentroids = DataArray<float32>::Create(*getDataStructure(), k_EltCentroids, std::move(dataStore), getId());
}
if(edgeCentroids == nullptr)
{
m_CellCentroidsDataArrayId.reset();
return -1;
}
GeometryHelpers::Topology::FindElementCentroids(getEdges(), getVertices(), edgeCentroids);
m_CellCentroidsDataArrayId = edgeCentroids->getId();
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/DataStructure/Geometry/EdgeGeom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ class SIMPLNX_EXPORT EdgeGeom : public INodeGeometry1D
* @brief
* @return StatusCode
*/
StatusCode findElementSizes() override;
StatusCode findElementSizes(bool recalculate) override;

/**
* @brief
* @return StatusCode
*/
StatusCode findElementsContainingVert() override;
StatusCode findElementsContainingVert(bool recalculate) override;

/**
* @brief
* @return StatusCode
*/
StatusCode findElementNeighbors() override;
StatusCode findElementNeighbors(bool recalculate) override;

/**
* @brief
* @return StatusCode
*/
StatusCode findElementCentroids() override;
StatusCode findElementCentroids(bool recalculate) override;

/**
* @brief
Expand Down
Loading
Loading