30 #if defined(ROTATIONTABLES_RECURSES)
31 #error Recursive header files inclusion detected in Rotationtables.h
34 #define ROTATIONTABLES_RECURSES
36 #if !defined ROTATIONTABLES_h
38 #define ROTATIONTABLES_h
57 template<
typename TSpace,
typename TInputValue =
typename TSpace::Po
int>
58 std::vector<std::vector<int>>
loadOTCTable(
const std::string& tableFolderPath,
const int rwidth) {
59 std::ostringstream ot;
60 ot << tableFolderPath <<
"OT-" << rwidth <<
"-circles-l2.txt";
61 std::string tname = ot.str();
62 std::vector< int> Csize;
63 std::vector< std::vector< int > > table;
64 std::ifstream tinput( tname.c_str() );
66 std::cerr <<
"OTC file not found" <<std::endl;
68 bool size_mode =
true;
71 while ( ! tinput.eof() )
76 std::getline( tinput, str );
79 if ( str.empty() || str[ 0 ] ==
'#' )
continue;
81 std::istringstream is( str );
82 while ( is >> t ) Csize.push_back( t );
86 std::istringstream is( str );
87 std::vector< int > mapping;
89 int ra = int( round( alpha*180.0/M_PI ) );
90 if ( a == ra ) nb_ok += 1;
91 mapping.push_back( 0 );
92 while ( is >> t ) mapping.push_back( t );
94 table.push_back( mapping );
105 template<
typename TSpace,
typename TInputValue =
typename TSpace::Po
int>
107 std::vector<std::string> substrings;
108 std::istringstream iss(coordinatesStr);
110 std::string substring;
111 while(std::getline(iss,substring,delimiter)) {
112 std::cout <<
"substring="<<substring<<std::endl;
113 substrings.push_back(substring);
120 template<
typename TSpace,
typename TInputValue =
typename TSpace::Po
int>
123 std::istringstream iss(coordinatesStr);
125 std::vector<GAVector<TSpace>> gavecs;
129 while (iss >> x >> delim >> y) {
132 if (iss.peek() ==
',' || iss.peek() ==
')') {
133 iss >> delim >> delim>> delim;
141 template<
typename TSpace,
typename TInputValue =
typename TSpace::Po
int>
142 std::vector<std::tuple<std::vector<GAVector<TSpace>>,double,
double>>
loadFastCBDRTable(std::string fileStr) {
143 const char* filename =fileStr.c_str();
144 std::cout <<
"filename="<<filename<<std::endl;
146 int fileDesc = open(filename, O_RDONLY);
147 if (fileDesc == -1) {
148 std::cerr <<
"Fast table : Error opening file: " << strerror(errno) << std::endl;
149 std::cerr <<
"Fast table : Error file name= " << filename << std::endl;
153 struct stat fileInfo;
154 if (fstat(fileDesc, &fileInfo) == -1) {
155 std::cerr <<
"file information error : " << strerror(errno) << std::endl;
160 char* fileData =
static_cast<char*
>(mmap(NULL, fileInfo.st_size, PROT_READ, MAP_PRIVATE, fileDesc, 0));
161 if (fileData == MAP_FAILED) {
162 std::cerr <<
"Error mapping file to memory: " << strerror(errno) << std::endl;
170 std::vector<std::tuple<std::vector<GAVector<TSpace>>,double,
double>> vecCompositionBijective_With_Errors;
171 std::cout <<
"file info size="<<fileInfo.st_size<<std::endl;
172 for (
size_t i = 0; i < fileInfo.st_size; ++i) {
173 std::string linebefore(fileData + start, i - start + 1);
174 std::cout <<
"line before="<<linebefore<<std::endl;
175 if (fileData[i] ==
'\n' || i == fileInfo.st_size - 1) {
177 std::string line(fileData + start, i - start + 1);
178 std::cout <<
"line="<<line<<std::endl;
179 auto vectorsAndLinfLcont = parselineWithSeparator<TSpace,TInputValue>(line,
';');
180 std::cout <<
"1="<<vectorsAndLinfLcont[0]<<std::endl;
181 std::cout <<
"2="<<vectorsAndLinfLcont[1]<<std::endl;
182 std::cout <<
"3="<<vectorsAndLinfLcont[2]<<std::endl;
184 std::vector<GAVector<TSpace>> coordinates;
187 std::string coordinateStr;
188 coordinates = functions::parseCoordinates<TSpace>(vectorsAndLinfLcont[0]);
189 std::cout <<
"fast : coord=";
190 for(
auto gavec : coordinates)
191 std::cout <<gavec.my_gavec <<
" ";
192 std::cout <<std::endl;
193 std::cout <<
"fast two"<<vectorsAndLinfLcont[1]<<std::endl;
194 std::cout <<
"fast three"<<vectorsAndLinfLcont[2]<<std::endl;
195 vecCompositionBijective_With_Errors.push_back(std::make_tuple(coordinates,std::stod(vectorsAndLinfLcont[1]),std::stod(vectorsAndLinfLcont[2])));
200 munmap(fileData, fileInfo.st_size);
202 std::cout <<
"load done .."<<std::endl;
204 return vecCompositionBijective_With_Errors;
208 template<
typename TSpace,
typename TInputValue =
typename TSpace::Po
int>
211 const char* filename =fileStr.c_str();
214 int fileDesc = open(filename, O_RDONLY);
215 if (fileDesc == -1) {
216 std::cerr <<
"Error opening file: " << strerror(errno) << std::endl;
221 struct stat fileInfo;
222 if (fstat(fileDesc, &fileInfo) == -1) {
223 std::cerr <<
"file information error : " << strerror(errno) << std::endl;
229 char* fileData =
static_cast<char*
>(mmap(NULL, fileInfo.st_size, PROT_READ, MAP_PRIVATE, fileDesc, 0));
230 if (fileData == MAP_FAILED) {
231 std::cerr <<
"Error mapping file to memory: " << strerror(errno) << std::endl;
238 bool isFirstLine =
true;
241 std::vector<std::pair<std::vector<GAVector<TSpace>>,
GAVector<TSpace>>> vecCompositionBijective;
242 for (
size_t i = 0; i < fileInfo.st_size; ++i) {
243 if (fileData[i] ==
'\n' || i == fileInfo.st_size - 1) {
245 std::string line(fileData + start, i - start + 1);
247 size_t pos = line.find(
"kmax=");
248 if (pos != std::string::npos) {
249 if (sscanf(line.c_str() + pos + 5,
"%d", &kmaxFile) == 1) {
250 std::cout <<
"kmax: " << kmaxFile << std::endl;
255 std::vector<GAVector<TSpace>> coordinates;
258 std::string coordinateStr;
259 coordinates = functions::parseCoordinates<TSpace>(line);
262 coordinates.pop_back();
263 vecCompositionBijective.push_back(std::make_pair(coordinates,last));
269 munmap(fileData, fileInfo.st_size);
271 std::cout <<
"load done .."<<std::endl;
272 return vecCompositionBijective;
281 #undef ROTATIONTABLES_RECURSES
std::vector< std::pair< std::vector< GAVector< TSpace > >, GAVector< TSpace > > > loadBijectiveRotationTable(std::string fileStr, const size_t n, const size_t kmax)
std::vector< std::tuple< std::vector< GAVector< TSpace > >, double, double > > loadFastCBDRTable(std::string fileStr)
std::vector< GAVector< TSpace > > parseCoordinates(const std::string &coordinatesStr)
parse line of CBDR tables
std::vector< std::vector< int > > loadOTCTable(const std::string &tableFolderPath, const int rwidth)
Rotation table loading : for OTC and RBDR.
std::vector< std::string > parselineWithSeparator(const std::string &coordinatesStr, const char delimiter)
DGtal is the top-level namespace which contains all DGtal functions and types.