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

Dev #9

Merged
merged 5 commits into from May 1, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions dependencies.txt
@@ -0,0 +1,17 @@
#From package repositories
linux-headers-4.15.0-46
gcc
g++
gfortran
zlib1g-dev
wget
git
cmake
doxygen
graphviz

#From source and specific build parameters
eigen
boost
opencv
dgtal
1 change: 1 addition & 0 deletions lab/test/base/include/Shapes/testShapes.h
Expand Up @@ -18,6 +18,7 @@ namespace DIPaCUS
bool testFlower(Logger& logger);
bool testNGon(Logger& logger);
bool testBall(Logger& logger);
bool testEllipse(Logger& logger);

bool runTest(std::ostream& os, const std::string& outputFolder, bool exportObjectsFlag=false );
}
Expand Down
14 changes: 14 additions & 0 deletions lab/test/base/src/Shapes/testShapes.cpp
Expand Up @@ -67,6 +67,19 @@ namespace DIPaCUS
return t1;
}

bool Test::Shapes::testEllipse(Logger& logger)
{
logger < Logger::HeaderTwo < "Test Ellipse" < Logger::Normal;

DigitalSet ellipse = DIPaCUS::Shapes::ellipse(1.0,0,0,20,5,0);
logger < Logger::LoggableObject<DigitalSet>(ellipse,"ellipse.eps");

bool t1 = ellipse.size()==305;
logger < "Passed: " < t1 < "\n";

return t1;
}

bool Test::Shapes::runTest(std::ostream& os, const std::string& outputFolder, bool exportObjectsFlag)
{
Logger logger(os,outputFolder,exportObjectsFlag);
Expand All @@ -79,6 +92,7 @@ namespace DIPaCUS
flag = flag && testBall(logger);
flag = flag && testFlower(logger);
flag = flag && testNGon(logger);
flag = flag && testEllipse(logger);

return flag;
}
Expand Down
2 changes: 1 addition & 1 deletion lab/test/components/src/testSetOperations.cpp
Expand Up @@ -31,7 +31,7 @@ namespace DIPaCUS{ namespace Test{ namespace SetOperations{
DigitalSet intersection(ball.domain());
DIPaCUS::SetOperations::setIntersection(intersection,ball,square);

logger < Logger::LoggableObject<DigitalSet>(intersection,"ball-intersects-ball.eps");
logger < Logger::LoggableObject<DigitalSet>(intersection,"ball-intersects-square.eps");

bool t1 = intersection.size()==225;

Expand Down
21 changes: 20 additions & 1 deletion modules/base/include/DIPaCUS/base/Shapes.h
Expand Up @@ -10,6 +10,7 @@
#include <DGtal/shapes/parametric/NGon2D.h>
#include <DGtal/shapes/parametric/Ball2D.h>
#include <DGtal/shapes/parametric/AccFlower2D.h>
#include <DGtal/shapes/parametric/Ellipse2D.h>

namespace DIPaCUS
{
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace DIPaCUS
int y0,
double radius,
int sides,
double rotation);
double rotation=0);


/**
Expand Down Expand Up @@ -126,6 +127,24 @@ namespace DIPaCUS
double smallRadius=5,
int k=3,
double rotation=0);

/**
* /brief Ellipse digitization
*
* @param h Grid Step
* @param x0 Circumscribed circle center x-coordinate
* @param y0 Circumscribed circle center y-coordinate
* @param larger radius
* @param smaller radius
* @param rotation
* @return Ellipse digitization
*/
DigitalSet ellipse(double h=1.0,
int x0=0,
int y0=0,
double largerRadius=10,
double smallerRadius=5,
double rotation=0);
}
}

Expand Down
12 changes: 12 additions & 0 deletions modules/base/src/Shapes.cpp
Expand Up @@ -54,5 +54,17 @@ namespace DIPaCUS
DGtal::AccFlower2D<Space> flower(x0,y0,radius,smallRadius,k,rotation);
return digitizeShape(flower,h);
}

Shapes::DigitalSet Shapes::ellipse(double h,
int x0,
int y0,
double largerRadius,
double smallerRadius,
double rotation)
{
typedef DGtal::Z2i::Space Space;
DGtal::Ellipse2D<Space> ellipse(x0,y0,largerRadius,smallerRadius,rotation);
return digitizeShape(ellipse,h);
}
}

13 changes: 13 additions & 0 deletions modules/components/include/DIPaCUS/components/SetOperations.h
Expand Up @@ -42,6 +42,19 @@ namespace DIPaCUS
void setIntersection(DigitalSet &digitalIntersection,
const DigitalSet &A,
const DigitalSet &B);


/**
* \brief Computes the intersection set between two digital sets.
* @param digitalIntersection Intersection set of A and B
* @param A First set
* @param B Second set
* @param translation Every point of A will be translated of it
*/
void setIntersection(DigitalSet &digitalIntersection,
const DigitalSet &A,
const DigitalSet &B,
const Point& p);
}
}

Expand Down
13 changes: 13 additions & 0 deletions modules/components/src/SetOperations.cpp
Expand Up @@ -38,3 +38,16 @@ void SetOperations::setIntersection(DigitalSet &digitalIntersection,
}
}

void SetOperations::setIntersection(DigitalSet &digitalIntersection,
const DigitalSet &A,
const DigitalSet &B,
const Point& translation)
{
Point tp;
for (auto it = A.begin(); it != A.end(); ++it)
{
tp = *it + translation;
if (B(tp)) digitalIntersection.insert(tp);
}
}

13 changes: 9 additions & 4 deletions modules/derivates/include/DIPaCUS/derivates/Misc.h
Expand Up @@ -93,6 +93,7 @@ namespace DIPaCUS

private:
Radius _r;
DigitalSet _ball;
const DigitalSet _ds;
const Domain _extDomain;
};
Expand Down Expand Up @@ -167,11 +168,13 @@ namespace DIPaCUS
* @param begin Curve iterator begin
* @param end Curve iterator end
* @param cOut Output curve
* @tparam TSCellIterator An iterator which value type is a SCell
*/
template<class TSCellIterator>
void invertCurve(Curve& cOut,
const KSpace& KImage,
SCellIterator begin,
SCellIterator end);
TSCellIterator begin,
TSCellIterator end);

/**
* \brief Given an oriented curve, it returns a compact set.
Expand All @@ -180,10 +183,12 @@ namespace DIPaCUS
* @param itb Curve iterator begin
* @param ite Curve iterator end
* @param ccw True if curve is oriented counterclock-wise
* @tparam TSCellIterator An iterator which value type is a SCell
*/
template<class TSCellIterator>
void compactSetFromClosedCurve(DigitalSet& dsOut,
SCellIterator itb,
SCellIterator ite,
TSCellIterator itb,
TSCellIterator ite,
bool ccw=true);

}
Expand Down
69 changes: 68 additions & 1 deletion modules/derivates/include/DIPaCUS/derivates/Misc.hpp
Expand Up @@ -14,5 +14,72 @@ namespace DIPaCUS{ namespace Misc{
std::remove_copy_if(originalDS.begin(), originalDS.end(), inserter, NP);
}

template<typename TSCellIterator>
void invertCurve(Curve& cOut,
const KSpace& KImage,
TSCellIterator begin,
TSCellIterator end)
{
std::vector<SCell> SCells;
auto it=begin;
do{
SCells.push_back(*it);
++it;
}while(it!=end);

std::vector<SCell> newSCells;
{
auto it = SCells.rbegin();
do{
SCell newLinel = KImage.sCell( *it);
KImage.sSetSign(newLinel,!KImage.sSign(*it));

newSCells.push_back(newLinel);
++it;
}while(it!=SCells.rend());
}

cOut.initFromSCellsVector(newSCells);
}

template<class TSCellIterator>
void compactSetFromClosedCurve(DigitalSet& dsOut,
TSCellIterator itb,
TSCellIterator ite,
bool ccw)
{
KSpace KImage;

//Using extended domain because IndirectIncident may access
//an invalid scell in a tight domain.
Domain extDomain( dsOut.domain().lowerBound() - Point(1,1), dsOut.domain().upperBound() + Point(1,1) );

KImage.init(extDomain.lowerBound(),extDomain.upperBound(),true);



KSpace::SCell boundaryPixel;
if(ccw)
boundaryPixel = KImage.sDirectIncident(*itb, KImage.sOrthDir(*itb));
else
boundaryPixel = KImage.sIndirectIncident(*itb, KImage.sOrthDir(*itb));

DigitalSet fakeBoundary(extDomain);
TSCellIterator it = itb;
do
{
if(ccw)
fakeBoundary.insert( KImage.sCoords( KImage.sIndirectIncident(*it,KImage.sOrthDir(*it)) ) );
else
fakeBoundary.insert( KImage.sCoords( KImage.sDirectIncident(*it,KImage.sOrthDir(*it)) ) );
++it;
}while(it!=ite);

fillInterior(dsOut,KImage.sCoords(boundaryPixel),fakeBoundary);
for(auto it=fakeBoundary.begin();it!=fakeBoundary.end();++it)
dsOut.erase(*it);
}


}}

}}
71 changes: 3 additions & 68 deletions modules/derivates/src/Misc.cpp
Expand Up @@ -20,16 +20,14 @@ namespace DIPaCUS{ namespace Misc{
DigitalBallIntersection::DigitalBallIntersection(Radius r,
const DigitalSet &intersectWith) : _r(r),
_extDomain(extendDomain(intersectWith,_r)),
_ds(extendDS(intersectWith,_r))
_ds(extendDS(intersectWith,_r)),
_ball(DIPaCUS::Shapes::ball(1.0,0,0,r))
{}

void DigitalBallIntersection::operator()(DigitalSet &intersectionSet,
Point center)
{
DigitalSet db(_extDomain);
db = DIPaCUS::Shapes::ball(1.0,center[0],center[1],_r);

DIPaCUS::SetOperations::setIntersection(intersectionSet, db, _ds);
DIPaCUS::SetOperations::setIntersection(intersectionSet, _ball, _ds, center);
}


Expand Down Expand Up @@ -119,67 +117,4 @@ namespace DIPaCUS{ namespace Misc{
DIPaCUS::Transform::eliminateLoops(boundOut,KImage,boundOut);
}

void invertCurve(Curve& cOut,
const KSpace& KImage,
SCellIterator begin,
SCellIterator end)
{
std::vector<SCell> SCells;
auto it=begin;
do{
SCells.push_back(*it);
++it;
}while(it!=end);

std::vector<SCell> newSCells;
{
auto it = SCells.rbegin();
do{
SCell newLinel = KImage.sCell( *it);
KImage.sSetSign(newLinel,!KImage.sSign(*it));

newSCells.push_back(newLinel);
++it;
}while(it!=SCells.rend());
}

cOut.initFromSCellsVector(newSCells);
}

void compactSetFromClosedCurve(DigitalSet& dsOut,
SCellIterator itb,
SCellIterator ite,
bool ccw)
{
KSpace KImage;

//Using extended domain because IndirectIncident may access
//an invalid scell in a tight domain.
Domain extDomain( dsOut.domain().lowerBound() - Point(1,1), dsOut.domain().upperBound() + Point(1,1) );

KImage.init(extDomain.lowerBound(),extDomain.upperBound(),true);



KSpace::SCell boundaryPixel;
if(ccw)
boundaryPixel = KImage.sDirectIncident(*itb, KImage.sOrthDir(*itb));
else
boundaryPixel = KImage.sIndirectIncident(*itb, KImage.sOrthDir(*itb));

DigitalSet fakeBoundary(extDomain);
SCellIterator it = itb;
do
{
if(ccw)
fakeBoundary.insert( KImage.sCoords( KImage.sIndirectIncident(*it,KImage.sOrthDir(*it)) ) );
else
fakeBoundary.insert( KImage.sCoords( KImage.sDirectIncident(*it,KImage.sOrthDir(*it)) ) );
++it;
}while(it!=ite);

fillInterior(dsOut,KImage.sCoords(boundaryPixel),fakeBoundary);
for(auto it=fakeBoundary.begin();it!=fakeBoundary.end();++it)
dsOut.erase(*it);
}
}}