-
Notifications
You must be signed in to change notification settings - Fork 8
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
GRIDEDIT-1407 add mkernel_mesh2d_get_property api #368
Merged
lucacarniato
merged 5 commits into
master
from
feature/GRIDEDIT-1407_api_for_edge_length
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dfa2220
GRIDEDIT-1407 add mkernel_mesh2d_get_property api
lucacarniato a44f47b
Merge branch 'master' into feature/GRIDEDIT-1407_api_for_edge_length
lucacarniato 8dd2c90
Fix clang formatting
lucacarniato 7482e7c
Fix uniot test for getting the properties
lucacarniato 2db8627
GRIDEDIT-1407: remove commented out code
lucacarniato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1460,6 +1460,98 @@ namespace meshkernelapi | |
return lastExitCode; | ||
} | ||
|
||
MKERNEL_API int mkernel_mesh2d_get_property(int meshKernelId, int propertyValue, const GeometryList& geometryList) | ||
{ | ||
lastExitCode = meshkernel::ExitCode::Success; | ||
try | ||
{ | ||
if (!meshKernelState.contains(meshKernelId)) | ||
{ | ||
throw meshkernel::MeshKernelError("The selected mesh kernel id does not exist."); | ||
} | ||
|
||
const auto& mesh2d = meshKernelState.at(meshKernelId).m_mesh2d; | ||
|
||
if (!mesh2d || mesh2d->GetNumNodes() <= 0) | ||
{ | ||
return lastExitCode; | ||
} | ||
|
||
const auto propertyValueEnum = static_cast<meshkernel::Mesh2D::Property>(propertyValue); | ||
switch (propertyValueEnum) | ||
{ | ||
case meshkernel::Mesh2D::Property::Orthogonality: | ||
{ | ||
std::vector<double> values = mesh2d->GetOrthogonality(); | ||
if (static_cast<size_t>(geometryList.num_coordinates) < values.size()) | ||
{ | ||
throw meshkernel::MeshKernelError("GeometryList with wrong dimensions"); | ||
} | ||
std::copy(values.begin(), values.end(), geometryList.values); | ||
Comment on lines
+1486
to
+1490
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this snippet common to both cases? |
||
} | ||
break; | ||
case meshkernel::Mesh2D::Property::EdgeLength: | ||
{ | ||
mesh2d->ComputeEdgesLengths(); | ||
std::vector<double> values = mesh2d->m_edgeLengths; | ||
if (static_cast<size_t>(geometryList.num_coordinates) < values.size()) | ||
{ | ||
throw meshkernel::MeshKernelError("GeometryList with wrong dimensions"); | ||
} | ||
std::copy(values.begin(), values.end(), geometryList.values); | ||
} | ||
break; | ||
default: | ||
throw meshkernel::MeshKernelError("Property not supported"); | ||
} | ||
} | ||
catch (...) | ||
{ | ||
lastExitCode = HandleException(); | ||
} | ||
return lastExitCode; | ||
} | ||
|
||
MKERNEL_API int mkernel_mesh2d_get_property_dimension(int meshKernelId, int propertyValue, int& dimension) | ||
{ | ||
lastExitCode = meshkernel::ExitCode::Success; | ||
try | ||
{ | ||
if (!meshKernelState.contains(meshKernelId)) | ||
{ | ||
throw meshkernel::MeshKernelError("The selected mesh kernel id does not exist."); | ||
} | ||
|
||
const auto& mesh2d = meshKernelState.at(meshKernelId).m_mesh2d; | ||
|
||
if (!mesh2d || mesh2d->GetNumNodes() <= 0) | ||
{ | ||
return lastExitCode; | ||
} | ||
|
||
const auto propertyValueEnum = static_cast<meshkernel::Mesh2D::Property>(propertyValue); | ||
dimension = -1; | ||
switch (propertyValueEnum) | ||
{ | ||
case meshkernel::Mesh2D::Property::Orthogonality: | ||
dimension = static_cast<int>(mesh2d->GetOrthogonality().size()); | ||
break; | ||
|
||
case meshkernel::Mesh2D::Property::EdgeLength: | ||
mesh2d->ComputeEdgesLengths(); | ||
dimension = static_cast<int>(mesh2d->m_edgeLengths.size()); | ||
break; | ||
default: | ||
throw meshkernel::MeshKernelError("Property not supported"); | ||
} | ||
} | ||
catch (...) | ||
{ | ||
lastExitCode = HandleException(); | ||
} | ||
return lastExitCode; | ||
} | ||
|
||
MKERNEL_API int mkernel_mesh2d_get_smoothness(int meshKernelId, GeometryList& geometryList) | ||
{ | ||
lastExitCode = meshkernel::ExitCode::Success; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dimension should be an out parameter