38 #ifndef BGEOT_GEOMETRIC_TRANSFORMATION_H__
39 #define BGEOT_GEOMETRIC_TRANSFORMATION_H__
110 std::vector<size_type> vertices_;
115 void fill_standard_vertices();
119 dim_type
dim()
const {
return cvr->structure()->dim(); }
132 virtual void poly_vector_val(
const base_node &pt, base_vector &val)
const = 0;
134 virtual void poly_vector_val(
const base_node &pt,
const convex_ind_ct &ind_ct,
135 base_vector &val)
const = 0;
137 virtual void poly_vector_grad(
const base_node &pt, base_matrix &val)
const = 0;
139 virtual void poly_vector_grad(
const base_node &pt,
const convex_ind_ct &ind_ct,
140 base_matrix &val)
const = 0;
142 virtual void poly_vector_hess(
const base_node &pt, base_matrix &val)
const = 0;
144 virtual void compute_K_matrix(
const base_matrix &G,
const base_matrix &pc, base_matrix &K)
const;
148 const std::vector<size_type> &
vertices()
const {
return vertices_; }
151 {
return cvr->points(); }
154 {
return cvr->pspt(); }
156 const std::vector<base_small_vector> &
normals()
const
157 {
return cvr->normals(); }
161 const CONT &PTAB)
const;
163 void set_name(
const std::string &name){name_ = name;}
164 const std::string& debug_name()
const {
return name_;}
165 virtual void project_into_reference_convex(base_node &pt)
const
166 { cvr->project_into(pt); }
167 size_type complexity()
const {
return complexity_; }
168 virtual ~geometric_trans()
169 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Geometric transformation"); }
171 { DAL_STORED_OBJECT_DEBUG_CREATED(
this,
"Geometric transformation"); }
176 const CONT &ptab)
const {
181 for (
size_type l = 0; l < k; ++l) gmm::add(gmm::scaled(ptab[l], val[l]),P);
192 typename CONT::const_iterator it = ptab.begin();
193 min = max = *it;
size_type P = min.size();
194 base_node::iterator itmin = min.begin(), itmax = max.begin();
195 for ( ++it; it != ptab.end(); ++it) {
199 base_node::const_iterator it2 = pt.begin();
201 itmin[i] = std::min(itmin[i], it2[i]);
202 itmax[i] = std::max(itmax[i], it2[i]);
206 if (pgt && !pgt->is_linear())
208 scalar_type e = (itmax[i]-itmin[i]) * 0.2;
209 itmin[i] -= e; itmax[i] += e;
230 pyramid_geotrans(
short_type k) {
return pyramid_QK_geotrans(k); }
268 base_small_vector APIDECL
284 class geotrans_precomp_;
285 typedef std::shared_ptr<const geotrans_precomp_> pgeotrans_precomp;
296 pstored_point_tab pspt;
297 mutable std::vector<base_vector> c;
299 mutable std::vector<base_matrix> pc;
301 mutable std::vector<base_matrix> hpc;
304 inline const base_vector &val(
size_type i)
const
305 {
if (c.empty()) init_val();
return c[i]; }
306 inline const base_matrix &grad(
size_type i)
const
307 {
if (pc.empty()) init_grad();
return pc[i]; }
308 inline const base_matrix &hessian(
size_type i)
const
309 {
if (hpc.empty()) init_hess();
return hpc[i]; }
319 template <
typename CONT>
320 void transform(
const CONT& G,
322 template <
typename CONT,
typename VEC>
323 void transform(
const CONT& G,
size_type ii, VEC& pt)
const;
328 inline pstored_point_tab get_ppoint_tab()
const {
return pspt; }
331 { DAL_STORED_OBJECT_DEBUG_DESTROYED(
this,
"Geotrans precomp"); }
334 void init_val()
const;
335 void init_grad()
const;
336 void init_hess()
const;
342 friend pgeotrans_precomp
344 dal::pstatic_stored_object dep);
351 dal::pstatic_stored_object dep);
353 template <
typename CONT,
typename VEC>
358 if (c.empty()) init_val();
359 for (
typename CONT::const_iterator itk = G.begin();
360 itk != G.end(); ++itk, ++k)
361 gmm::add(gmm::scaled(*itk, c[j][k]), pt);
362 GMM_ASSERT1(k == pgt->nb_points(),
363 "Wrong number of points in transformation");
366 template <
typename CONT>
369 if (c.empty()) init_val();
370 pt_tab.clear(); pt_tab.resize(c.size(),
base_node(G[0].size()));
371 for (
size_type j = 0; j < c.size(); ++j) {
376 void APIDECL delete_geotrans_precomp(pgeotrans_precomp pgp);
384 std::set<pgeotrans_precomp> precomps;
389 pstored_point_tab pspt) {
390 pgeotrans_precomp p = geotrans_precomp(pg, pspt, 0);
395 for (std::set<pgeotrans_precomp>::iterator it = precomps.begin();
396 it != precomps.end(); ++it)
397 delete_geotrans_precomp(*it);
415 const base_matrix *
G_;
417 mutable base_matrix
K_, B_, B3_, B32_;
419 pgeotrans_precomp pgp_;
420 pstored_point_tab pspt_;
422 mutable scalar_type
J_, J__;
423 mutable base_matrix
PC, B_factors;
424 mutable base_vector aux1, aux2;
425 mutable std::vector<long> ipvt;
426 mutable bool have_J_, have_B_, have_B3_, have_B32_, have_K_, have_cv_center_;
427 void compute_J()
const;
429 bool have_xref()
const {
return !xref_.empty(); }
430 bool have_xreal()
const {
return !xreal_.empty(); }
431 bool have_G()
const {
return G_ != 0; }
432 bool have_K()
const {
return have_K_; }
433 bool have_B()
const {
return have_B_; }
434 bool have_B3()
const {
return have_B3_; }
435 bool have_B32()
const {
return have_B32_; }
436 bool have_pgt()
const {
return pgt_ != 0; }
437 bool have_pgp()
const {
return pgp_ != 0; }
439 const base_node& xref()
const;
441 const base_node& xreal()
const;
443 const base_node& cv_center()
const;
445 const base_matrix& K()
const;
446 const base_matrix& B()
const;
447 const base_matrix& B3()
const;
448 const base_matrix& B32()
const;
451 const base_matrix&
G()
const {
return *G_; }
453 scalar_type
J()
const {
if (!have_J_) compute_J();
return J_; }
455 if (have_G())
return G().nrows();
456 else if (have_xreal())
return xreal_.size();
457 else GMM_ASSERT2(
false,
"cannot get N");
461 bgeot::pgeotrans_precomp pgp()
const {
return pgp_; }
465 if (pgt_ && !pgt()->is_linear())
466 { have_K_ = have_B_ = have_B3_ = have_B32_ = have_J_ =
false; }
467 xref_.resize(0); xreal_.resize(0);
473 void change(bgeot::pgeotrans_precomp pgp__,
475 const base_matrix& G__) {
476 G_ = &G__; pgt_ = pgp__->get_trans(); pgp_ = pgp__;
477 pspt_ = pgp__->get_ppoint_tab(); ii_ = ii__;
478 have_J_ = have_B_ = have_B3_ = have_B32_ = have_K_ =
false;
479 have_cv_center_ =
false;
480 xref_.resize(0); xreal_.resize(0); cv_center_.resize(0);
483 bgeot::pstored_point_tab pspt__,
485 const base_matrix& G__) {
486 G_ = &G__; pgt_ = pgt__; pgp_ = 0; pspt_ = pspt__; ii_ = ii__;
487 have_J_ = have_B_ = have_B3_ = have_B32_ = have_K_ =
false;
488 have_cv_center_ =
false;
489 xref_.resize(0); xreal_.resize(0); cv_center_.resize(0);
492 const base_node& xref__,
493 const base_matrix& G__) {
494 xref_ = xref__; G_ = &G__; pgt_ = pgt__; pgp_ = 0; pspt_ = 0;
496 have_J_ = have_B_ = have_B3_ = have_B32_ = have_K_ =
false;
497 have_cv_center_ =
false;
498 xreal_.resize(0); cv_center_.resize(0);
501 geotrans_interpolation_context()
502 : G_(0), pgt_(0), pgp_(0), pspt_(0), ii_(
size_type(-1)),
503 have_J_(false), have_B_(false), have_B3_(false), have_B32_(false),
504 have_K_(false), have_cv_center_(false) {}
505 geotrans_interpolation_context(bgeot::pgeotrans_precomp pgp__,
507 const base_matrix& G__)
508 : G_(&G__), pgt_(pgp__->get_trans()), pgp_(pgp__),
509 pspt_(pgp__->get_ppoint_tab()), ii_(ii__), have_J_(false), have_B_(false),
510 have_B3_(false), have_B32_(false), have_K_(false), have_cv_center_(false) {}
512 bgeot::pstored_point_tab pspt__,
514 const base_matrix& G__)
515 : G_(&G__), pgt_(pgt__), pgp_(0),
516 pspt_(pspt__), ii_(ii__), have_J_(false), have_B_(false), have_B3_(false),
517 have_B32_(false), have_K_(false), have_cv_center_(false) {}
519 const base_node& xref__,
520 const base_matrix& G__)
521 : xref_(xref__), G_(&G__), pgt_(pgt__), pgp_(0), pspt_(0),
522 ii_(
size_type(-1)),have_J_(false), have_B_(false), have_B3_(false),
523 have_B32_(false), have_K_(false), have_cv_center_(false) {}
529 typedef dal::naming_system<geometric_trans>::param_list gt_param_list;
531 void APIDECL add_geometric_trans_name
536 scalar_type lu_det(
const scalar_type *A,
size_type N);
537 scalar_type lu_inverse(scalar_type *A,
size_type N,
bool doassert =
true);
538 inline scalar_type lu_det(
const base_matrix &A)
539 {
return lu_det(&(*(A.begin())), A.nrows()); }
540 inline scalar_type lu_inverse(base_matrix &A,
bool doassert =
true)
541 {
return lu_inverse(&(*(A.begin())), A.nrows(), doassert); }
544 void mat_mult(
const scalar_type *A,
const scalar_type *B, scalar_type *C,
549 void mat_tmult(
const scalar_type *A,
const scalar_type *B, scalar_type *C,