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

Rigid trans #869

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f31f9bc
Merge branch 'master' of https://github.com/DGtal-team/DGtal
copyme Jun 26, 2014
c8c3eb8
initial code for rigid transformations
copyme Jun 26, 2014
9fecafd
First test version.
copyme Jun 27, 2014
de88564
First version of 2D transformations
copyme Jun 28, 2014
d571b49
Checks for returned value by domain functor.
copyme Jun 28, 2014
da85428
cleanups and test for gray image
copyme Jun 28, 2014
c5a5fe3
small fixes and translation
copyme Jun 28, 2014
7fcade4
cleanups
copyme Jun 28, 2014
c6238c0
commit before merge
copyme Jun 28, 2014
8a2240e
Merge branch 'master' of https://github.com/DGtal-team/DGtal
copyme Jun 28, 2014
05d51cb
Merge branch 'master' into RigidTrans
copyme Jun 28, 2014
a29db2d
cleanups
copyme Jun 28, 2014
18474cf
example for 2D rigid transformations
copyme Jun 28, 2014
2d1cae3
example for 3D transformations and cleanups
copyme Jun 28, 2014
a26b164
Removed possible big data copying
copyme Jun 28, 2014
18c0dce
less big data copying
copyme Jun 28, 2014
be1fc00
documentation
copyme Jun 28, 2014
dc425b7
def. value
copyme Jul 1, 2014
2fe2e6d
Missing files added.
copyme Jul 2, 2014
b0124e7
fix for double comparison
copyme Jul 5, 2014
f4ec343
Merge branch 'master' of https://github.com/DGtal-team/DGtal
copyme Jul 7, 2014
af2556e
Merge branch 'master' into RigidTrans
copyme Jul 7, 2014
dc9f84c
fix for the new functor's name
copyme Jul 7, 2014
4834bd8
Fixes for 2D transformations according to comments at github.
copyme Jul 14, 2014
030fd08
Fixes for 3D
copyme Jul 14, 2014
711cdb0
Merge branch 'master' of https://github.com/DGtal-team/DGtal
copyme Jul 14, 2014
ef72ed4
Merge branch 'master' into RigidTrans
copyme Jul 14, 2014
b893387
merge
copyme Jul 14, 2014
50262da
small fixes
copyme Jul 16, 2014
8f89865
Merge branch 'master' of https://github.com/DGtal-team/DGtal
copyme Jul 17, 2014
3c85b15
Merge branch 'master' into RigidTrans
copyme Jul 17, 2014
391f5aa
fixed test
copyme Jul 17, 2014
68f6b9a
Unfinished version of documentation - first very draft
copyme Jul 17, 2014
3d4ae09
images for documentation
copyme Jul 17, 2014
8cac0ed
Indents, fix for wrong rotation axis.
copyme Jul 18, 2014
5bc39bb
documentation for 2/3D draft 2
copyme Jul 18, 2014
3f3f47c
removed debug line
copyme Jul 19, 2014
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
2 changes: 2 additions & 0 deletions examples/images/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ SET(DGTAL_EXAMPLES_SRC
extract2DImagesFrom3D
extract2DSlicesImagesFrom3D
imageBasicSubsampling
exampleRigidtransformation2d
exampleRigidtransformation3d
)

if( WITH_HDF5 )
Expand Down
100 changes: 100 additions & 0 deletions examples/images/exampleRigidtransformation2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* 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/>.
*
**/

/**
* @file rigidtransformation2d.cpp
* @ingroup Examples
* @author Kacper Pluta (\c [email protected] )
* Laboratoire d'Informatique Gaspard-Monge - LIGM, France
*
* @date 2014/06/28
*
* An example file named rigidtransformation2d.
*
* This file is part of the DGtal library.
*/

///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/io/writers/GenericWriter.h"
//! [include]
#include "DGtal/images/RigidTransformation2D.h"
//! [include]
///////////////////////////////////////////////////////////////////////////////

using namespace std;
using namespace DGtal;
using namespace functors;
using namespace Z2i;

///////////////////////////////////////////////////////////////////////////////

int main( int , char** )
{
typedef ImageSelector<Domain, unsigned char >::Type Image;
//! [def]
typedef ForwardRigidTransformation2D < Space > ForwardTrans;
typedef BackwardRigidTransformation2D < Space > BackwardTrans;
typedef ConstImageAdapter<Image, Domain, BackwardTrans, Image::Value, Identity > MyImageBackwardAdapter;
typedef DomainRigidTransformation2D < Domain, ForwardTrans > MyDomainTransformer;
typedef MyDomainTransformer::Bounds Bounds;
//! [def]
trace.beginBlock ( "Example rigidtransformation2d" );
//! [trans]
ForwardTrans forwardTrans( RealPoint ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) );
BackwardTrans backwardTrans( RealPoint ( 5, 5 ), M_PI_4, RealVector( 3, -3 ) );
//! [trans]
//![init_domain_helper]
MyDomainTransformer domainTransformer ( forwardTrans );
//![init_domain_helper]
Identity idD;

Image image = PGMReader<Image>::importPGM ( examplesPath + "samples/church.pgm" );
//! [domain]
Bounds bounds = domainTransformer ( image.domain() );
Domain transformedDomain ( bounds.first, bounds.second );
//! [domain]

trace.beginBlock ( "Backward - Eulerian model" );
//! [backward]
MyImageBackwardAdapter backwardImageAdapter ( image, transformedDomain , backwardTrans, idD );
//! [backward]
backwardImageAdapter >> "backward_transform.pgm";
trace.endBlock();

trace.beginBlock( "Forward - Lagrangian model" );
Image forwardTransformedImage ( transformedDomain );
//! [forward]
for ( Domain::ConstIterator it = image.domain().begin(); it != image.domain().end(); ++it )
{
forwardTransformedImage.setValue ( forwardTrans ( *it ), image ( *it ) );
}
//! [forward]
forwardTransformedImage >> "forward_transform.pgm";
trace.endBlock();
trace.endBlock();
return 0;
}
// //
///////////////////////////////////////////////////////////////////////////////
99 changes: 99 additions & 0 deletions examples/images/exampleRigidtransformation3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* 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/>.
*
**/

/**
* @file rigidtransformation3d.cpp
* @ingroup Examples
* @author Kacper Pluta (\c [email protected] )
* Laboratoire d'Informatique Gaspard-Monge - LIGM, France
*
* @date 2014/06/28
*
* An example file named rigidtransformation3d.
*
* This file is part of the DGtal library.
*/

///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/GenericWriter.h"
//! [include]
#include "DGtal/images/RigidTransformation3D.h"
//! [include]
///////////////////////////////////////////////////////////////////////////////

using namespace std;
using namespace DGtal;
using namespace functors;
using namespace Z3i;

///////////////////////////////////////////////////////////////////////////////

int main( int , char** )
{
typedef ImageSelector<Domain, unsigned char >::Type Image;
//! [def]
typedef ForwardRigidTransformation3D < Space > ForwardTrans;
typedef BackwardRigidTransformation3D < Space > BackwardTrans;
typedef ConstImageAdapter<Image, Domain, BackwardTrans, Image::Value, Identity > MyImageBackwardAdapter;
typedef DomainRigidTransformation3D < Domain, ForwardTrans > MyTransformedDomain;
typedef MyTransformedDomain::Bounds Bounds;
//! [def]
trace.beginBlock ( "Example rigidtransformation3d" );
//! [trans]
ForwardTrans forwardTrans( Point ( 5, 5, 5 ), RealVector ( 1, 0, 1 ), M_PI_4, RealVector( 3, -3, 3 ) );
BackwardTrans backwardTrans( Point ( 5, 5, 5 ), RealVector ( 1, 0, 1 ), M_PI_4, RealVector( 3, -3, 3 ) );
//! [trans]
//![init_domain_helper]
MyTransformedDomain domainForwardTrans ( forwardTrans );
//![init_domain_helper]
Identity idD;

Image image = VolReader<Image>::importVol ( examplesPath + "samples/cat10.vol" );
//! [domain]
Bounds bounds = domainForwardTrans ( image.domain() );
Domain transformedDomain ( bounds.first, bounds.second );
//! [domain]
trace.beginBlock ( "Backward - Eulerian model" );
//! [backward]
MyImageBackwardAdapter adapter ( image, transformedDomain, backwardTrans, idD );
//! [backward]
adapter >> "backward_transform.pgm3d";
trace.endBlock();

trace.beginBlock( "Forward - Lagrangian model" );
Image transformed ( transformedDomain );
//! [forward]
for ( Domain::ConstIterator it = image.domain().begin(); it != image.domain().end(); ++it )
{
transformed.setValue ( forwardTrans ( *it ), image ( *it ) );
}
//! [forward]
transformed >> "forward_transform.pgm3d";
trace.endBlock();
trace.endBlock();
return 0;
}
// //
///////////////////////////////////////////////////////////////////////////////
33 changes: 30 additions & 3 deletions src/DGtal/images/ConstImageAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ConstImageAdapter
ConstImageAdapter(const ImageContainer &anImage, const Domain &aDomain, const TFunctorD &aFD, const TFunctorV &aFV):
myImagePtr(&anImage), mySubDomainPtr(&aDomain), myFD(&aFD), myFV(&aFV)
{
defaultValue = 0;
#ifdef DEBUG_VERBOSE
trace.warning() << "ConstImageAdapter Ctor fromRef " << std::endl;
#endif
Expand All @@ -154,6 +155,7 @@ class ConstImageAdapter
mySubDomainPtr = other.mySubDomainPtr;
myFD = other.myFD;
myFV = other.myFV;
defaultValue = other.defaultValue;
}
return *this;
}
Expand Down Expand Up @@ -206,11 +208,15 @@ class ConstImageAdapter
Value operator()(const Point & aPoint) const
{
ASSERT(this->domain().isInside(aPoint));

return myFV->operator()(myImagePtr->operator()(myFD->operator()(aPoint)));

typename TImageContainer::Point point = myFD->operator()(aPoint);
if (myImagePtr->domain().isInside(point))
return myFV->operator()(myImagePtr->operator()(point));
else
return defaultValue;
}


/////////////////// API //////////////////

/**
Expand Down Expand Up @@ -243,6 +249,21 @@ class ConstImageAdapter
{
return myImagePtr;
}

/**
* Allows to define a default value returned when point
* transformed by domain functor does not belongs to
* image domain.
*/
void setDefaultValue ( Value aValue )
{
defaultValue = aValue;
}

Value getDefaultValue () const
{
return defaultValue;
}

// ------------------------- Protected Datas ------------------------------
private:
Expand Down Expand Up @@ -275,6 +296,12 @@ class ConstImageAdapter
* Aliasing pointer on the underlying Value functor
*/
const TFunctorV* myFV;

/**
* Default value returned when point transformed by image functor does not belongs to image.
* Initial value is 0.
*/
Value defaultValue;

private:

Expand Down
34 changes: 31 additions & 3 deletions src/DGtal/images/ImageAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ImageAdapter
ImageAdapter(ImageContainer &anImage, const Domain &aDomain, const TFunctorD &aFD, const TFunctorV &aFV, const TFunctorVm1 &aFVm1):
myImagePtr(&anImage), mySubDomainPtr(&aDomain), myFD(&aFD), myFV(&aFV), myFVm1(&aFVm1)
{
defaultValue = 0;
#ifdef DEBUG_VERBOSE
trace.warning() << "ImageAdapter Ctor fromRef " << std::endl;
#endif
Expand All @@ -160,6 +161,7 @@ class ImageAdapter
myFD = other.myFD;
myFV = other.myFV;
myFVm1 = other.myFVm1;
defaultValue = other.defaultValue;
}
return *this;
}
Expand Down Expand Up @@ -222,10 +224,15 @@ class ImageAdapter
*/
Value operator()(const Point & aPoint) const
{
ASSERT(this->domain().isInside(aPoint));

return myFV->operator()(myImagePtr->operator()(myFD->operator()(aPoint)));
ASSERT(this->domain().isInside(aPoint));

typename TImageContainer::Point point = myFD->operator()(aPoint);
if (myImagePtr->domain().isInside(point))
return myFV->operator()(myImagePtr->operator()(point));
else
return defaultValue;
}



/////////////////// Set values //////////////////
Expand Down Expand Up @@ -273,6 +280,21 @@ class ImageAdapter
{
return myImagePtr;
}

/**
* Allows to define a default value returned when point
* transformed by domain functor does not belongs to
* image domain.
*/
void setDefaultValue ( Value aValue )
{
defaultValue = aValue;
}

Value getDefaultValue () const
{
return defaultValue;
}

// ------------------------- Protected Datas ------------------------------
private:
Expand Down Expand Up @@ -310,6 +332,12 @@ class ImageAdapter
* Aliasing pointer on the underlying "m-1" Value functor
*/
const TFunctorVm1* myFVm1;

/**
* Default value returned when point transformed by image functor does not belongs to image.
* Initial value is 0.
*/
Value defaultValue;


private:
Expand Down
Loading