-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Linearizer #1039
Merged
Merged
Linearizer #1039
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3eca5b0
Adding Linearizer class.
rolanddenis 172737e
Using Linearizer class in ImageContainerBySTLVector.
rolanddenis aff22e0
Example fix. Clean-up. Changelog update.
rolanddenis 9d06a9e
Adding test&bench for Linearizer and fixing a bug.
rolanddenis b7295b5
Forget to add the test file...
rolanddenis e6c1277
Trying to fix warnings.
rolanddenis 77f6b05
Fixing warnings with gcc (I hope)
rolanddenis 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/** | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
**/ | ||
|
||
#pragma once | ||
|
||
/** | ||
* @file Linearizer.h | ||
* @author Roland Denis (\c [email protected] ) | ||
* LAboratory of MAthematics - LAMA (CNRS, UMR 5127), University of Savoie, France | ||
* | ||
* @date 2015/06/18 | ||
* | ||
* This file is part of the DGtal library. | ||
*/ | ||
|
||
#if defined(Linearizer_RECURSES) | ||
#error Recursive header files inclusion detected in Linearizer.h | ||
#else // defined(Linearizer_RECURSES) | ||
/** Prevents recursive inclusion of headers. */ | ||
#define Linearizer_RECURSES | ||
|
||
#if !defined Linearizer_h | ||
/** Prevents repeated inclusion of headers. */ | ||
#define Linearizer_h | ||
|
||
////////////////////////////////////////////////////////////////////////////// | ||
// Inclusions | ||
#include <DGtal/kernel/domains/HyperRectDomain.h> // Only for specialization purpose. | ||
////////////////////////////////////////////////////////////////////////////// | ||
|
||
namespace DGtal | ||
{ | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
/** | ||
* @brief Tag (empty structure) specifying a row-major storage order. | ||
* | ||
* @see Linearizer | ||
*/ | ||
struct RowMajorStorage {}; | ||
|
||
/** | ||
* @brief Tag (empty structure) specifying a col-major storage order. | ||
* | ||
* @see Linearizer | ||
*/ | ||
struct ColMajorStorage {}; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* @brief Aim: Linearization and de-linearization interface for domains. | ||
* | ||
* Description of class 'Linearizer' <p> | ||
* This class is empty but there is a specialization for HyperRectDomain. | ||
* | ||
* @tparam TDomain Type of the domain. | ||
* @tparam TStorageOrder Storage Order (RowMajorStorage of ColMajorStorage). | ||
* | ||
*/ | ||
template < | ||
typename TDomain, | ||
typename TStorageOrder = ColMajorStorage | ||
> | ||
struct Linearizer; | ||
|
||
/** | ||
* @brief Aim: Linearization and de-linearization interface for HyperRectDomain. | ||
* | ||
* This is a static class that provides point linearization (point to index) and de-linearization (index to point) for storages working on HyperRectDomain. | ||
* | ||
* The storage order can be specified by template (default is colum-major ordered). | ||
* | ||
* Example: | ||
* @code | ||
* typedef SpaceND<2> Space; | ||
* tydedef HyperRectDomain<Space> Domain; | ||
* typedef typename Space::Point Point; | ||
* | ||
* const Domain domain( Point(0, 1), Point(4, 3) ); | ||
* | ||
* size_t id = Linearizer<Domain>::getIndex( Point(2, 2), domain ); // returns 7. | ||
* | ||
* Point pt = Linearizer<Domain>::getPoint( 7, domain); // returns Point(2,2). | ||
* @endcode | ||
* | ||
* @tparam TSpace Type of the space of the HyperRectDomain (auto-deduced from TDomain template, see Linearizer). | ||
* @tparam TStorageOrder Storage Order (RowMajorStorage of ColMajorStorage). | ||
*/ | ||
template < | ||
typename TSpace, | ||
typename TStorageOrder | ||
> | ||
struct Linearizer< HyperRectDomain<TSpace>, TStorageOrder > | ||
{ | ||
// Usefull typedefs | ||
typedef HyperRectDomain<TSpace> Domain; ///< The domain type. | ||
typedef typename TSpace::Point Point; ///< The point type. | ||
typedef Point Extent; ///< The domain's extent type. | ||
typedef typename TSpace::Size Size; ///< The space's size type. | ||
|
||
/** Linearized index of a point, given the domain lower-bound and extent. | ||
* | ||
* @param[in] aPoint The point to be linearized. | ||
* @param[in] aLowerBound The lower-bound of the domain. | ||
* @param[in] anExtent The extent of the domain. | ||
* @return the linearized index of the point. | ||
*/ | ||
static inline | ||
Size getIndex( Point aPoint, Point const& aLowerBound, Extent const& anExtent ); | ||
|
||
/** Linearized index of a point, given the domain extent. | ||
* | ||
* The lower-bound of the domain is defined to the origin. | ||
* | ||
* @param[in] aPoint The Point to be linearized. | ||
* @param[in] anExtent The extent of the domain. | ||
* @return the linearized index of the point. | ||
*/ | ||
static inline | ||
Size getIndex( Point aPoint, Extent const& anExtent ); | ||
|
||
/** Linearized index of a point, given a domain. | ||
* | ||
* @param[in] aPoint The Point to be linearized. | ||
* @param[in] aDomain The domain. | ||
* @return the linearized index of the point. | ||
*/ | ||
static inline | ||
Size getIndex( Point aPoint, Domain const& aDomain ); | ||
|
||
/** De-linearization of an index, given the domain lower-bound and extent. | ||
* | ||
* @param[in] anIndex The linearized index. | ||
* @param[in] aLowerBound The lower-bound of the domain. | ||
* @param[in] anExtent The domain extent. | ||
* @return the point whose linearized index is anIndex. | ||
*/ | ||
static inline | ||
Point getPoint( Size anIndex, Point const& aLowerBound, Extent const& anExtent ); | ||
|
||
/** De-linearization of an index, given the domain extent. | ||
* | ||
* The lower-bound of the domain is set to the origin. | ||
* | ||
* @param[in] anIndex The linearized index. | ||
* @param[in] anExtent The domain extent. | ||
* @return the point whose linearized index is anIndex. | ||
*/ | ||
static inline | ||
Point getPoint( Size anIndex, Extent const& anExtent ); | ||
|
||
/** De-linearization of an index, given a domain. | ||
* | ||
* @param[in] anIndex The linearized index. | ||
* @param[in] aDomain The domain. | ||
* @return the point whose linearized index is anIndex. | ||
*/ | ||
static inline | ||
Point getPoint( Size anIndex, Domain const& aDomain ); | ||
|
||
}; // end of class Linearizer | ||
|
||
} // namespace DGtal | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// Includes inline functions. | ||
#include "DGtal/kernel/domains/Linearizer.ih" | ||
|
||
// // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#endif // !defined Linearizer_h | ||
|
||
#undef Linearizer_RECURSES | ||
#endif // else defined(Linearizer_RECURSES) | ||
|
||
/* GNU coding style */ | ||
/* vim: set ts=2 sw=2 expandtab cindent cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 : */ | ||
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. cleanup these editor traces? 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. Oooops, I will clean this ! |
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.
shouldn't it be
?
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.
Right, with probably a
typename
before.