28 #if defined(CBDR_RECURSES)
29 #error Recursive header files inclusion detected in CBDR.h
41 #include "CBDRSolver.h"
42 #include "CBDRFastSolver.h"
44 #include "Rotationtables.h"
45 #include "NBijectiveReflectionGenerator.h"
56 template<
typename TSpace,
typename TInputValue =
typename TSpace::RealPo
int,
typename TOutputValue =
typename TSpace::Po
int>
80 const bool precompute=
true,
const bool fast =
true ):
nbijectiveGen(km),
my_domain(typename TSpace::
Point(0,0),typename TSpace::
Point(100,100)),
my_angle(theta),
my_center(
center),
nbReflections(nbreflect),
kmax(km),
my_policy(policy),
90 std::cout <<
"use fast table"<<std::endl;
91 std::string fastTableName=(
"CBDROptimisedTable_"+std::to_string(
nbReflections)+
"_"+std::to_string(
kmax)+
".txt");
102 return std::make_shared<CBDR_naiverotation<TSpace>>(cbdrFastSolver.
solve());
116 my_cbdr=std::make_shared<CBDR_naiverotation<TSpace>>(cbdrFastSolver.
solve());
135 template<
typename TImage>
137 return my_cbdr->rotateImage(img);
161 std::shared_ptr<CBDR_naiverotation<TSpace>>
my_cbdr;
168 std::vector<CBDR_naiverotation<TSpace, TInputValue>>
loadFastOptimisedTable(
const std::string& fastTableName);
177 template<
typename TSpace,
typename TInputValue,
typename TOutputValue>
179 auto vecTable = DGtal::functions::loadFastCBDRTable<DGtal::SpaceND< 2, DGtal::int32_t >>(fastTableName);
180 std::vector<CBDR_naiverotation<TSpace, TInputValue>> fastCBDRtab(vecTable.size());
182 return DGtal::CBDR_naiverotation<DGtal::SpaceND< 2, DGtal::int32_t >>(std::get<0>(x));
187 template<
typename TSpace,
typename TInputValue,
typename TOutputValue>
190 for(
size_t nbReflec = 2 ; nbReflec <= nbReflections ; nbReflec+=2) {
192 std::string tableName(
"CBDRTable_"+std::to_string(nbReflec)+
"_"+std::to_string(kmax)+
".txt");
194 if(usePrecomputedTable ) {
196 bool exists = (stat (tableName.c_str(), &buffer) == 0);
198 usePrecomputedTable=
false;
202 if(usePrecomputedTable){
203 std::cout <<
"loading precomputed table ..."<<std::endl;
204 vecBijNormals = functions::loadBijectiveRotationTable<TSpace,TInputValue>(tableName,nbReflec,kmax);
206 std::cout <<
"does not use precomputed table"<<std::endl;
207 auto tableIntVecBijNormals = nbijectiveGen.n_bijectiveReflections_get_NormalVectorsAngles(nbReflec);
208 nbijectiveGen.writeBijectiveVectors(
"CBDRTable_"+std::to_string(nbReflec)+
"_"+std::to_string(kmax)+
".txt",tableIntVecBijNormals );
209 vecBijNormals = nbijectiveGen.vecBijNormals_index_2_GAVector(tableIntVecBijNormals);
211 vecBijectiveSearchTree.push_back(vecBijNormals);
216 template<
typename TSpace,
typename TInputValue,
typename TOutputValue>
219 std::vector<BijectiveSearchTree> &vecBijectiveSearchTree) {
220 std::vector<CBDR_naiverotation<TSpace, TInputValue>> fastCBDRtab;
224 std::string tablefilename =
"CBDROptimisedTable_"+std::to_string(nbReflections)+
"_"+std::to_string(kmax)+
".txt";
225 std::ofstream file(tablefilename);
226 for(
int alpha = 0 ; alpha < 91; ++alpha) {
227 double currentAngle = (alpha * M_PI) / 180.0;
229 std::vector<Reflection<TSpace>> bestReflections =cbdrsolv.
solve(points,nbijectiveVectors,
230 vecBijectiveSearchTree,*my_policy);
233 fastCBDRtab.push_back(currentRotation);
236 for(
size_t i = 0 ; i<bestReflections.size() ; ++i) {
237 if(i<bestReflections.size()-1)
238 file << bestReflections[i].normalVector.my_gavec <<
",";
240 file << bestReflections[i].normalVector.my_gavec;
242 file <<
";"<<Linf->evaluate(points,currentRotation,currentAngle,my_center);
243 file <<
";"<<LContinuity->evaluate(points,currentRotation,currentAngle,my_center);
248 std::cout <<
"table written !"<<std::endl;
BijectiveReflections solve()
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: CBDR solver, use a policy to choose the composition of digitized reflections that minimises an e...
std::vector< Reflection< TSpace > > solve(const TDomain &points, NBijectiveGenerator< TSpace > &nbijectiveVectors, std::vector< BijectiveSearchTree > &vecBijectiveSearchTree, const Policy< TSpace, TDomain, BijectiveReflections > &policy)
vec since the parameters are the vectors of digitized reflections
CBDR : Composition of Bijective Digitized Reflections,.
TImage rotateImage(TImage img) const
TOutputValue operator()(const TInputValue &aInput) const
TOutputValue center() const
void setPolicy(const std::shared_ptr< Policy< TSpace, HyperRectDomain< TSpace >, CBDR_naiverotation< TSpace >>> &newPolicy)
std::vector< CBDR_naiverotation< TSpace, TInputValue > > fastCBDRTable
std::string tostring() const
std::shared_ptr< CBDR_naiverotation< TSpace > > initCBDRVec()
BOOST_STATIC_ASSERT((TOutputValue::dimension==2))
std::vector< std::pair< std::vector< GAVector< TSpace > >, GAVector< TSpace > > > BijectiveSearchTree
HyperRectDomain< TSpace > my_domain
std::vector< BijectiveSearchTree > vecBijectiveSearchTree
void set_angle(const double newAngle)
void initcbdr_loadBijectiveReflectionSearchTree(const HyperRectDomain< TSpace > &my_domain)
std::vector< CBDR_naiverotation< TSpace, TInputValue > > initFastPrecomputationTable(const HyperRectDomain< TSpace > &points, NBijectiveGenerator< TSpace > &nbijectiveVectors, std::vector< BijectiveSearchTree > &vecBijectiveSearchTree)
NBijectiveGenerator< TSpace, TInputValue > nbijectiveGen
std::shared_ptr< CBDR_naiverotation< TSpace > > my_cbdr
BOOST_STATIC_ASSERT((TSpace::dimension==2))
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
std::vector< CBDR_naiverotation< TSpace, TInputValue > > loadFastOptimisedTable(const std::string &fastTableName)
load fast optimised table in case the table is found
double my_angle
number of sample rotation angle
std::shared_ptr< Policy< TSpace, HyperRectDomain< TSpace >, CBDR_naiverotation< TSpace > > > my_policy
BOOST_STATIC_ASSERT((TInputValue::dimension==2))
CBDR(const double theta, const typename TSpace::Point center, const size_t nbreflect, const size_t km, std::shared_ptr< Policy< TSpace, HyperRectDomain< TSpace >, CBDR_naiverotation< TSpace >>> policy, const bool precompute=true, const bool fast=true)
Reflection< TSpace, TInputValue > DigitizedReflection
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.