Skip to content

Commit ac8a05c

Browse files
committed
Merge pull request #9 from fwachtel/cli-uniform
Cli uniform
2 parents bc942cd + 4c722ab commit ac8a05c

6 files changed

Lines changed: 61 additions & 59 deletions

File tree

src/main/cli.cpp

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
1313
std::string fn_bary;
1414
std::string fn_dev;
1515
std::string fn_out;
16+
unsigned int nbSample;
17+
unsigned short int seed;
1618

1719
boostPO::variables_map vm;
1820
boostPO::options_description desc("Allowed options");
@@ -23,14 +25,20 @@ int main(int argc, char** argv)
2325
boostPO::value<std::string>(&fn_rules)->required(),
2426
"REQUIRED | Subdivision rule filename")
2527
("bary,b",
26-
boostPO::value<std::string>(&fn_bary),
27-
"Barycenter offset filename (for each rule id)")
28+
boostPO::value<std::string>(&fn_bary)->required(),
29+
"REQUIRED | Barycenter offset filename (for each rule id)")
2830
("dev,d",
2931
boostPO::value<std::string>(&fn_dev),
30-
"Offset filename (for each structural indices)")
32+
"Offset LUT filename (for each structural indices)")
3133
("out,o",
3234
boostPO::value<std::string>(&fn_out),
3335
"Output filename")
36+
("nbSample,n",
37+
boostPO::value<unsigned int>(&nbSample)->default_value(1024),
38+
"Number of sample de generate")
39+
("seed,s",
40+
boostPO::value<unsigned short int>(&seed)->default_value(0),
41+
"Initial tile to use for sampling ([1-408], 0 = random)")
3442
;
3543

3644
try
@@ -55,39 +63,22 @@ int main(int argc, char** argv)
5563

5664
/* PROG ***********************************************************/
5765
Sampler sampler(fn_rules, fn_bary, fn_dev);
58-
/*
59-
WriterFilePts write(fn_out);
60-
/*/
61-
WriterEmpty write;
62-
//*/
63-
char ans;
64-
float density = 2;
65-
unsigned short int seed = 0;
66-
float spaceScale = 0.21;
67-
while(true)
68-
{
69-
std::cout << "=================================" << std::endl;
70-
std::cout << "? Generate a distribution (Y/n) ? ";
71-
if( std::cin.peek() == '\n' ) ans='y';
72-
else if( !(std::cin >> ans) ) break;
73-
std::cin.ignore();
74-
if( std::cin.fail() || ans=='n' || ans=='N') break;
75-
76-
std::cout << "? set initial seed [0-" << sampler.tiling().ruleSize()-1 << "] (" << ++seed << "): ";
77-
if( std::cin.peek() == '\n' );
78-
else if( !(std::cin >> seed) ) break;
79-
std::cin.ignore();
8066

81-
std::cout << "? set final density [0-inf] (" << density << "): ";
82-
if( std::cin.peek() == '\n' );
83-
else if( !(std::cin >> density) ) break;
84-
std::cin.ignore();
85-
86-
std::cout << "? set boundary (" << spaceScale << "): ";
87-
if( std::cin.peek() == '\n' );
88-
else if( !(std::cin >> spaceScale) ) break;
89-
std::cin.ignore();
67+
if( seed == 0 )
68+
{
69+
srand48(time(NULL));
70+
seed = std::ceil(drand48()*408);
71+
}
72+
if( vm.count("seed") ) seed = (seed-1)%408;
9073

91-
sampler.generateUniform(density, -1, write, seed, spaceScale);
74+
if( vm.count("out") )
75+
{
76+
WriterFileRaw write(fn_out);
77+
sampler.generateUniform(nbSample, -1, write, seed);
78+
}
79+
else
80+
{
81+
WriterEmpty write;
82+
sampler.generateUniform(nbSample, -1, write, seed);
9283
}
9384
}

src/sampler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class Sampler
2929
public:
3030
const Tiling& tiling() const { return m_tiling; };
3131
template <class WRITER>
32-
unsigned int generateUniform(const float& density, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.235, const bool& crop=true);
32+
unsigned int generateUniform(const float& density, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.21, const bool& crop=true);
3333
template <class WRITER>
34-
unsigned int generateUniform(const unsigned short int& finalLvl, const unsigned short int& finalRank, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.235, const bool& crop=true);
34+
unsigned int generateUniform(const unsigned short int& finalLvl, const unsigned short int& finalRank, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.21, const bool& crop=true);
3535
template <class WRITER>
36-
unsigned int generateAdaptive(float (*func)(const Point&), const float& white_density, const float& black_density, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.235, const bool& interpolate=true, const bool& dither=true);
36+
unsigned int generateAdaptive(float (*func)(const Point&), const float& white_density, const float& black_density, const short int& ilut, WRITER& writer, const unsigned short int& seed=0, const float& spaceSize=0.21, const bool& interpolate=true, const bool& dither=true);
3737

3838
};
3939

src/writerEmpty.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class WriterEmpty
1010
{
1111
public:
12-
inline void sample(const Point& sample, const TileState& tilestate) const {}
12+
inline void sample(const Point& sample, const TileState& tilestate) {}
1313
inline void clear(const float& a=1.) const {}
1414
};
1515

src/writerFilePts.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88
#include <fstream>
99

10+
#include "tileState.hpp"
1011
#include "vector.hpp"
1112

1213

@@ -20,15 +21,16 @@ class WriterFilePts
2021
WriterFilePts(const std::string& fn);
2122
~WriterFilePts();
2223

24+
void open(const float& spaceSize=1.);
25+
void header(const float& spaceSize=1.);
26+
2327
public:
24-
inline void sample(const Point& sample)
28+
inline void sample(const Point& sample, const TileState& tilestate)
2529
{
2630
m_file << sample.x() << "\t" << sample.y() << std::endl;
2731
}
2832

2933
void clear(const float& spaceSize=1.);
30-
void open(const float& spaceSize=1.);
31-
void header(const float& spaceSize=1.);
3234
};
3335

3436
#endif

src/writerFileRaw.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,28 @@ WriterFileRaw::WriterFileRaw(const std::string& fn)
55
: m_filename(fn)
66
{
77
m_file.open(m_filename.c_str());
8-
if(!m_file.is_open())
9-
{
10-
ERR( "Cannot open output file : " << m_filename );
11-
std::exit(EXIT_FAILURE);
12-
}
8+
open();
139
}
1410

1511
WriterFileRaw::~WriterFileRaw()
1612
{
1713
m_file.close();
1814
}
15+
16+
17+
void WriterFileRaw::clear(const float& spaceSize)
18+
{
19+
m_file.close();
20+
open(spaceSize);
21+
}
22+
23+
void WriterFileRaw::open(const float& spaceSize)
24+
{
25+
m_spaceSize = 2*spaceSize;
26+
m_file.open(m_filename.c_str());
27+
if(!m_file.is_open())
28+
{
29+
ERR( "Cannot open output file : " << m_filename );
30+
std::exit(EXIT_FAILURE);
31+
}
32+
}

src/writerFileRaw.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88
#include <fstream>
99

10+
#include "tileState.hpp"
1011
#include "vector.hpp"
1112

1213

@@ -15,27 +16,21 @@ class WriterFileRaw
1516
private:
1617
std::string m_filename;
1718
std::ofstream m_file;
19+
float m_spaceSize;
1820

1921
public:
2022
WriterFileRaw(const std::string& fn);
2123
~WriterFileRaw();
2224

25+
void open(const float& spaceSize=1.);
26+
2327
public:
24-
inline void sample(const Point& sample)
28+
inline void sample(const Point& sample, const TileState& tilestate)
2529
{
26-
m_file << sample.x() << "\t" << sample.y() << std::endl;
30+
m_file << sample.x()/m_spaceSize+0.5 << "\t" << sample.y()/m_spaceSize+0.5 << std::endl;
2731
}
2832

29-
inline void clear()
30-
{
31-
m_file.close();
32-
m_file.open(m_filename.c_str());
33-
if(!m_file.is_open())
34-
{
35-
std::cerr << "<<! Cannot open output file : " << m_filename << std::endl;
36-
exit(EXIT_FAILURE);
37-
}
38-
}
33+
void clear(const float& spaceSize=1.);
3934
};
4035

4136
#endif

0 commit comments

Comments
 (0)