Skip to content

Commit

Permalink
Merge pull request #288 from kerautret/SDPTBDC
Browse files Browse the repository at this point in the history
add sdp as input for tangentBC
  • Loading branch information
kerautret authored Feb 12, 2017
2 parents 528e53d + fe1fda9 commit c57ebe0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
- *estimators*:
- 2dlocalEstimators: add an option to export the generated contour.
(Bertrand Kerautret, [#285](https://github.com/DGtal-team/DGtalTools/pull/285))

- tangentBC: add an option to read sdp points as input.
(Bertrand Kerautret, [#285](https://github.com/DGtal-team/DGtalTools/pull/288))


# DGtalTools 0.9.2
Expand Down
46 changes: 30 additions & 16 deletions estimators/tangentBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/PointListReader.h"

//Grid curve
#include "DGtal/geometry/curves/FreemanChain.h"
Expand All @@ -65,7 +66,7 @@ namespace po = boost::program_options;
@b Allowed @b options @b are :
@code
-h [ --help ] display this message
-i [ --input ] arg input FreemanChain file name
-i [ --input ] arg input file name: FreemanChain (.fc) or a sequence of discrete points (.sdp).
-s [ --GridStep ] arg (=1) Grid step
@endcode
Expand Down Expand Up @@ -105,7 +106,7 @@ int main( int argc, char** argv )
po::options_description general_opt("Allowed options are: ");
general_opt.add_options()
("help,h", "display this message")
("input,i", po::value<std::string>(), "input FreemanChain file name")
("input,i", po::value<std::string>(), "input file name: FreemanChain (.fc) or a sequence of discrete points (.sdp).")
("GridStep,step", po::value<double>()->default_value(1.0), "Grid step");


Expand Down Expand Up @@ -135,7 +136,8 @@ int main( int argc, char** argv )

if(vm.count("input")){
std::string fileName = vm["input"].as<std::string>();

std::string extension = fileName.substr( fileName.find_last_of(".") + 1 );
bool isSDP = extension == "sdp";
typedef Z2i::Space Space;
typedef Space::Point Point;
typedef PointVector<2, double> RealPoint;
Expand All @@ -144,18 +146,30 @@ int main( int argc, char** argv )
typedef std::vector< Point > Storage;
typedef Storage::const_iterator ConstIteratorOnPoints;

std::vector< FreemanChain > vectFcs =
PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);

for(unsigned int i=0; i<vectFcs.size(); i++){

bool isClosed = vectFcs.at(i).isClosed();
std::cout << "# grid curve " << i << "/" << vectFcs.size() << " "
<< ( (isClosed)?"closed":"open" ) << std::endl;

std::vector< FreemanChain > vectFcs;
if(!isSDP)
{
vectFcs =
PointListReader< Point >:: getFreemanChainsFromFile<Integer> (fileName);
}
for(unsigned int i=0; i<vectFcs.size() || (i==0 && isSDP); i++){
Storage vectPts;
FreemanChain::getContourPoints( vectFcs.at(i), vectPts );

bool isClosed;
if(!isSDP)
{
isClosed = vectFcs.at(i).isClosed();
std::cout << "# grid curve " << i << "/" << vectFcs.size() << " "
<< ( (isClosed)?"closed":"open" ) << std::endl;
FreemanChain::getContourPoints( vectFcs.at(i), vectPts );
}
else
{
vectPts = PointListReader<Z2i::Point>::getPointsFromFile(fileName);
Z2i::Point pf =vectPts[0];
Z2i::Point pl =vectPts[vectPts.size()-1];
isClosed = (pf[0]-pl[0])+(pf[1]-pl[1]) <= 1;
}

// Binomial
std::cout << "# Curvature estimation from binomial convolution" << std::endl;
typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
Expand All @@ -174,7 +188,7 @@ int main( int argc, char** argv )
tangents.begin() );

// Output
std::cout << "# id tangent.x tangent.y angle(atan2(y,x))" << std::endl;
std::cout << "# id tangent.x tangent.y angle(atan2(y,x)) x y" << std::endl;
unsigned int j = 0;
for ( ConstIteratorOnPoints
it = vectPts.begin(), it_end = vectPts.end();
Expand All @@ -184,7 +198,7 @@ int main( int argc, char** argv )
double y = tangents[ j ][ 1 ];
std::cout << j << std::setprecision( 15 )
<< " " << x << " " << y
<< " " << atan2( y, x )
<< " " << atan2( y, x ) << " " << (*it)[0] << " " << (*it)[1]
<< std::endl;
}

Expand Down

0 comments on commit c57ebe0

Please sign in to comment.