52 #ifndef BGEOT_GEOTRANS_INV_H__ 53 #define BGEOT_GEOTRANS_INV_H__ 60 class geotrans_inv_convex;
62 struct nonlinear_storage_struct {
66 bool project_into_element;
68 struct linearised_structure {
70 const convex_ind_ct &direct_points_indices,
71 const stored_point_tab &reference_nodes,
72 const std::vector<base_node> &real_nodes);
73 void invert(
const base_node &x_real, base_node &x_ref,
74 scalar_type IN_EPS)
const;
76 base_matrix K_ref_linear;
79 base_node P_ref_linear;
80 mutable base_node diff;
81 mutable base_node diff_ref;
84 std::shared_ptr<linearised_structure> plinearised_structure =
nullptr;
91 base_matrix G, pc, K, B, CS;
94 nonlinear_storage_struct nonlinear_storage;
97 const base_matrix &get_G()
const {
return G; }
99 N(0), P(0), pgt(0), EPS(e)
100 { this->nonlinear_storage.project_into_element = project_into_element; }
104 scalar_type e=10e-12,
105 bool project_into_element =
false)
106 : N(0), P(0), pgt(0), EPS(e) {
107 this->nonlinear_storage.project_into_element = project_into_element;
108 init(cv.points(),pgt_);
113 scalar_type e=10e-12,
114 bool project_into_element =
false)
115 : N(0), P(0), pgt(0), EPS(e) {
116 this->nonlinear_storage.project_into_element = project_into_element;
120 void set_projection_into_element(
bool activate);
140 scalar_type IN_EPS=1e-12);
161 scalar_type IN_EPS=1e-12);
165 scalar_type IN_EPS,
bool &converged,
bool throw_except);
168 friend class geotrans_inv_convex_bfgs;
173 bool geotrans_changed = (pgt != pgt_);
if (geotrans_changed) pgt = pgt_;
174 GMM_ASSERT3(!nodes.empty(),
"empty points!");
175 if (N != nodes[0].size())
176 { N = nodes[0].size(); geotrans_changed =
true; }
177 if (geotrans_changed) {
178 P = pgt->structure()->dim();
179 pc.resize(pgt->nb_points() , P);
180 K.resize(N,P); B.resize(N,P); CS.resize(P,P);
181 G.resize(N, pgt->nb_points());
183 vectors_to_base_matrix(G, nodes);
184 if (pgt->is_linear()) {
185 if (geotrans_changed) {
187 pgt->poly_vector_grad(Dummy, pc);
192 this->nonlinear_storage.diff.resize(N);
193 this->nonlinear_storage.x_real.resize(N);
194 this->nonlinear_storage.x_ref.resize(P);
196 if (pgt->complexity() > 1) {
197 std::vector<base_node> real_nodes(nodes.begin(), nodes.end());
198 this->nonlinear_storage.plinearised_structure
199 = std::make_shared<nonlinear_storage_struct::linearised_structure>
200 (pgt->structure()->ind_dir_points(), pgt->geometric_nodes(),
218 void clear(
void) { tree.
clear(); }
221 tree.reserve(std::distance(c.begin(),c.end()));
222 typename CONT::const_iterator it = c.begin(), ite = c.end();
223 for (; it != ite; ++it) tree.
add_point(*it);
237 tree.points_in_box(ipts, min, max);
263 template<
class TAB,
class CONT1,
class CONT2>
266 CONT1 &pftab, CONT2 &itab,
267 bool bruteforce=
false);
274 template<
class TAB,
class CONT1,
class CONT2>
277 CONT1 &pftab, CONT2 &itab,
282 bounding_box(min, max, cv.points(), pgt);
283 for (
size_type k=0; k < min.size(); ++k) { min[k] -= EPS; max[k] += EPS; }
284 gic.init(cv.points(),pgt);
286 if (!bruteforce) points_in_box(boxpts, min, max);
287 else boxpts = tree.points();
290 for (
size_type l = 0; l < boxpts.size(); ++l) {
292 if (gic.invert(boxpts[l].n, pftab[nbpt], EPS)) {
293 itab[nbpt++] = boxpts[l].i;
void add_points(const CONT &c)
Add the points contained in c to the list of points.
Geometric transformations on convexes.
size_type points_in_box(kdtree_tab_type &ipts, const base_node &min, const base_node &max) const
Find all the points present in the box between min and max.
size_type add_point(base_node p)
Add point p to the list of points.
does the inversion of the geometric transformation for a given convex
handles the geometric inversion for a given (supposedly quite large) set of points ...
generic definition of a convex ( bgeot::convex_structure + vertices coordinates ) ...
Balanced tree over a set of points.
size_t size_type
used as the common size type in the library
size_type points_in_convex(const convex< base_node, TAB > &cv, pgeometric_trans pgt, CONT1 &pftab, CONT2 &itab, bool bruteforce=false)
Search all the points in the convex cv, which is the transformation of the convex cref via the geomet...
size_type nb_points(void) const
Number of points.
void add_point_with_id(const base_node &n, size_type i)
insert a new point, with an associated number.
void clear()
reset the tree, remove all points
size_type add_point(const base_node &n)
insert a new point
Simple implementation of a KD-tree.
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
std::vector< index_node_pair > kdtree_tab_type
store a set of points with associated indexes.