-
-
Notifications
You must be signed in to change notification settings - Fork 123
Parallel II Estimator #1842
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
Open
BDoignies
wants to merge
14
commits into
main
Choose a base branch
from
parallelII
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Parallel II Estimator #1842
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3b3501e
WIP ParallelIIEstimator
BDoignies 0b9242b
Forgot .h file
BDoignies 04e562a
Ordered evaluation for ParallelIIEstimator
BDoignies beebcf8
Few more comments
BDoignies 3e9680d
Merge branch 'main' into parallelII
dcoeurjo 1121654
Merge branch 'main' into parallelII
dcoeurjo 933395b
Merge branch 'main' into parallelII
dcoeurjo f5e2d01
Pre commit fixes
BDoignies 7021794
cmake edit to make sure that DGTAL_WITH_OPENMP has been set
dcoeurjo 07c6535
WIP testing the splitter
dcoeurjo efee3cb
Adding Axis splitter and concept check
dcoeurjo 57b6f43
Merge branch 'main' into parallelII
dcoeurjo 4fee775
Removing traces.
dcoeurjo b1650b1
t push
dcoeurjo 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
135 changes: 135 additions & 0 deletions
135
src/DGtal/geometry/surfaces/estimation/DomainSplitter.h
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #pragma once | ||
|
|
||
| #include "DGtal/kernel/domains/CDomain.h" | ||
| #include <vector> | ||
|
|
||
| namespace DGtal | ||
| { | ||
| /** | ||
| * @brief Data structure returned by Domain splitters | ||
| * | ||
| * This class offers the ability for the splitter to give information | ||
| * about the surfaces or object within the splits. | ||
| * For example, the hintVoxelCount field may allow to pre-allocate buffers. | ||
| */ | ||
| template<typename Domain> | ||
| struct SplitInfo | ||
| { | ||
| BOOST_CONCEPT_ASSERT(( concepts::CDomain< Domain > )); | ||
|
|
||
| Domain domain; //< The actual split domain | ||
| uint32_t hintVoxelCount = 0; //< An expected guess for the number of voxel | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Splits a domain evenly along all dimensions | ||
| * | ||
| * @tparam The model of domain to split | ||
| */ | ||
| template<typename Domain> | ||
| struct RegularDomainSplitter | ||
| { | ||
| BOOST_CONCEPT_ASSERT(( concepts::CDomain< Domain > )); | ||
|
|
||
| //Output spllitted domain type | ||
| typedef std::vector<SplitInfo<Domain>> SplitDomainsInfo; | ||
|
|
||
| /** | ||
| * @brief Splits a domain | ||
| * | ||
| * This functions may split the domain in fewer part than wanted to ensure | ||
| * even subdomains. | ||
| * | ||
| * @param d The domain to split | ||
| * @param splitHint The targeted number of splits | ||
| */ | ||
| SplitDomainsInfo operator()(const Domain& d, uint32_t splitHint) const | ||
| { | ||
| // Find best match possible for even splitting | ||
| const uint32_t splitCount = std::floor(std::log(splitHint) / std::log(Domain::dimension)); | ||
| const uint32_t totalSplits = std::pow(splitCount, Domain::dimension); | ||
|
|
||
| if (splitCount == 0) | ||
| return { SplitInfo{d, 0} }; | ||
|
|
||
| auto splitSize = (d.upperBound() - d.lowerBound()) / (int32_t)splitCount; | ||
| SplitDomainsInfo result; | ||
| result.reserve(totalSplits); | ||
|
|
||
| for (uint32_t i = 0; i < totalSplits; ++i) | ||
| { | ||
| auto start = d.lowerBound(); | ||
| auto idx = i; | ||
| for (uint32_t j = 0; j < Domain::dimension; ++j) | ||
| { | ||
| auto k = idx % splitCount; | ||
| start[j] += k * splitSize[j] + k; // +k ensure no overlap between domains | ||
| idx /= splitCount; | ||
| } | ||
|
|
||
| // Make correction to ensure it remains within the domain | ||
| auto end = start + splitSize; | ||
| for (uint32_t j = 0; j < Domain::dimension; ++j) | ||
| end[j] = std::clamp(end[j], d.lowerBound()[j], d.upperBound()[j]); | ||
|
|
||
| result.emplace_back(Domain(start, end), 0); | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @brief Splits a domain along one of the domain grid axis. | ||
| * | ||
| * @tparam The model of domain to split | ||
| */ | ||
| template<typename Domain> | ||
| struct AxisDomainSplitter | ||
| { | ||
|
|
||
| BOOST_CONCEPT_ASSERT(( concepts::CDomain< Domain > )); | ||
|
|
||
| //Output spllitted domain type | ||
| typedef std::vector<SplitInfo<Domain>> SplitDomainsInfo; | ||
|
|
||
| /** | ||
| * @brief Regularly splits a domain along one axis | ||
| * | ||
| * @param d The domain to split | ||
| * @param splitHint The targeted number of splits (clamped to the width of the domain) | ||
| * @param dim the split axis | ||
| */ | ||
| SplitDomainsInfo operator()(const Domain& d, uint32_t splitHint, typename Domain::Dimension dim) const | ||
| { | ||
| SplitDomainsInfo result; | ||
| if (splitHint == 0) | ||
| return result; | ||
|
|
||
| auto lower = d.lowerBound(); | ||
| auto upper = d.upperBound(); | ||
| auto length = upper[dim] - lower[dim] + 1; | ||
| uint32_t splitCount = splitHint; | ||
| if (splitCount > length) | ||
| splitCount = length; | ||
|
|
||
| result.reserve(splitCount); | ||
| auto base = length / splitCount; | ||
| auto rem = length % splitCount; | ||
|
|
||
| auto start = lower; | ||
| for (uint32_t i = 0; i < splitCount; ++i) | ||
| { | ||
| auto size = base + (i < rem ? 1 : 0); | ||
| auto end = upper; | ||
| end[dim] = start[dim] + size - 1; | ||
| result.emplace_back(Domain(start, end), 0); | ||
| start[dim] = end[dim] + 1; | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
| }; | ||
|
|
||
| } | ||
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.
gel header here