29 const float slicer_action::EPS = float(1e-13);
33 slicer_none& slicer_none::static_instance() {
38 slicer_boundary::slicer_boundary(
const mesh& m, slicer_action &sA,
39 const mesh_region& cvflst) : A(&sA) {
43 slicer_boundary::slicer_boundary(
const mesh& m, slicer_action &sA) : A(&sA) {
46 build_from(m,cvflist);
49 void slicer_boundary::build_from(
const mesh& m,
const mesh_region& cvflst) {
50 if (m.convex_index().card()==0)
return;
51 convex_faces.resize(m.convex_index().last()+1, slice_node::faces_ct(0L));
52 for (mr_visitor i(cvflst); !i.finished(); ++i)
53 if (i.is_face()) convex_faces[i.cv()][i.f()]=1;
54 else convex_faces[i.cv()].set();
57 for (dal::bv_visitor cv(m.convex_index()); !cv.finished(); ++cv) {
58 for (
short_type f=m.structure_of_convex(cv)->nb_faces(); f < convex_faces[cv].size(); ++f)
59 convex_faces[cv][f]=1;
63 bool slicer_boundary::test_bound(
const slice_simplex& s, slice_node::faces_ct& fmask,
const mesh_slicer::cs_nodes_ct& nodes)
const {
64 slice_node::faces_ct f; f.set();
66 f &= nodes[s.inodes[i]].faces;
72 void slicer_boundary::exec(mesh_slicer& ms) {
74 if (ms.splx_in.card() == 0)
return;
75 slice_node::faces_ct fmask(ms.cv < convex_faces.size() ? convex_faces[ms.cv] : 0);
77 if (!convex_faces[ms.cv].any()) { ms.splx_in.clear();
return; }
79 for (dal::bv_visitor_c cnt(ms.splx_in); !cnt.finished(); ++cnt) {
80 const slice_simplex& s = ms.simplexes[cnt];
81 if (s.dim() < ms.nodes[0].pt.size()) {
82 if (!test_bound(s, fmask, ms.nodes)) ms.splx_in.sup(cnt);
83 }
else if (s.dim() == 2) {
88 static unsigned ord[][2] = {{0,1},{1,2},{2,0}};
89 for (
size_type k=0; k < 2; ++k) { s2.inodes[k] = ms.simplexes[cnt].inodes[ord[j][k]]; }
90 if (test_bound(s2, fmask, ms.nodes)) {
91 ms.add_simplex(s2,
true);
94 }
else if (s.dim() == 3) {
100 static unsigned ord[][3] = {{0,2,1},{1,2,3},{1,3,0},{0,3,2}};
101 for (
size_type k=0; k < 3; ++k) { s2.inodes[k] = ms.simplexes[cnt].inodes[ord[j][k]]; }
104 if (test_bound(s2, fmask, ms.nodes)) {
105 ms.add_simplex(s2,
true);
110 ms.update_nodes_index();
114 void slicer_apply_deformation::exec(mesh_slicer& ms) {
117 bool ref_pts_changed =
false;
118 if (ms.cvr != ms.prev_cvr
119 || defdata->pmf->fem_of_element(ms.cv) != pf) {
120 pf = defdata->pmf->fem_of_element(ms.cv);
122 bgeot::vectors_to_base_matrix
123 (G, defdata->pmf->linked_mesh().points_of_convex(ms.cv));
127 std::vector<base_node> ref_pts2; ref_pts2.reserve(ms.nodes_index.card());
128 for (dal::bv_visitor i(ms.nodes_index); !i.finished(); ++i) {
129 ref_pts2.push_back(ms.nodes[i].pt_ref);
130 if (ref_pts2.size() > ref_pts.size()
131 || gmm::vect_dist2_sqr(ref_pts2[i],ref_pts[i])>1e-20)
132 ref_pts_changed =
true;
134 if (ref_pts2.size() != ref_pts.size()) ref_pts_changed =
true;
135 if (ref_pts_changed) {
136 ref_pts.swap(ref_pts2);
139 bgeot::pstored_point_tab pspt = store_point_tab(ref_pts);
140 pfem_precomp pfp = fprecomp(pf, pspt);
141 defdata->copy(ms.cv, coeff);
143 base_vector val(ms.m.dim());
145 fem_interpolation_context ctx(ms.pgt, pfp, 0, G, ms.cv,
short_type(-1));
146 for (dal::bv_visitor i(ms.nodes_index); !i.finished(); ++i, ++cnt) {
147 ms.nodes[i].pt.resize(defdata->pmf->get_qdim());
149 pf->interpolation(ctx, coeff, val, defdata->pmf->get_qdim());
150 gmm::add(val, ms.nodes[cnt].pt);
184 void slicer_volume::split_simplex(mesh_slicer& ms,
186 std::bitset<32> spin, std::bitset<32> spbin) {
188 bool intersection =
false;
189 static int level = 0;
199 for (iA=0; iA < s.dim(); ++iA) {
200 if (spbin[iA])
continue;
201 for (iB=iA+1; iB < s.dim()+1; ++iB) {
202 if (!spbin[iB] && spin[iA] != spin[iB]) {
204 if (alpha >= 1e-8 && alpha <= 1-1e-8) { intersection =
true;
break; }
207 if (intersection)
break;
211 const slice_node& A = ms.nodes[s.inodes[iA]];
212 const slice_node& B = ms.nodes[s.inodes[iB]];
213 slice_node n(A.pt + alpha*(B.pt-A.pt), A.pt_ref + alpha*(B.pt_ref-A.pt_ref));
214 n.faces = A.faces & B.faces;
216 ms.nodes.push_back(n);
217 pt_bin.add(nn); pt_in.add(nn);
219 std::bitset<32> spin2(spin), spbin2(spbin);
220 std::swap(s.inodes[iA],nn);
221 spin2.set(iA); spbin2.set(iA);
222 split_simplex(ms, s, sstart, spin2, spbin2);
224 std::swap(s.inodes[iA],nn); std::swap(s.inodes[iB],nn);
225 spin2 = spin; spbin2 = spbin; spin2.set(iB); spbin2.set(iB);
226 split_simplex(ms, s, sstart, spin2, spbin2);
231 for (
size_type i=0; i < s.dim()+1; ++i)
if (!spin[i]) { all_in =
false;
break; }
235 ms.add_simplex(s,(all_in &&
orient != VOLBOUND) ||
orient == VOLSPLIT);
237 slice_simplex face(s.dim());
238 for (
size_type f=0; f < s.dim()+1; ++f) {
242 if (!spbin[p]) { all_in =
false;
break; }
243 else face.inodes[i] = s.inodes[p];
247 std::sort(face.inodes.begin(), face.inodes.end());
248 if (std::find(ms.simplexes.begin()+sstart, ms.simplexes.end(), face) == ms.simplexes.end()) {
249 ms.add_simplex(face,
true);
264 void slicer_volume::exec(mesh_slicer& ms) {
266 if (ms.splx_in.card() == 0)
return;
267 prepare(ms.cv,ms.nodes,ms.nodes_index);
268 for (dal::bv_visitor_c cnt(ms.splx_in); !cnt.finished(); ++cnt) {
269 slice_simplex& s = ms.simplexes[cnt];
276 std::bitset<32> spin, spbin;
277 for (
size_type i=0; i < s.dim()+1; ++i) {
278 if (pt_in.is_in(s.inodes[i])) { ++in_cnt; spin.set(i); }
279 if (pt_bin.is_in(s.inodes[i])) { ++in_bcnt; spbin.set(i); }
283 if (
orient != VOLSPLIT) ms.splx_in.sup(cnt);
284 }
else if (in_cnt != s.dim()+1 ||
orient==VOLBOUND) {
286 split_simplex(ms, s, ms.simplexes.size(), spin, spbin);
292 GMM_ASSERT1(ms.fcnt != dim_type(-1),
293 "too much {faces}/{slices faces} in the convex " << ms.cv
294 <<
" (nbfaces=" << ms.fcnt <<
")");
295 for (dal::bv_visitor cnt(pt_bin); !cnt.finished(); ++cnt) {
296 ms.nodes[cnt].faces.set(ms.fcnt);
300 ms.update_nodes_index();
303 slicer_mesh_with_mesh::slicer_mesh_with_mesh(
const mesh& slm_) : slm(slm_) {
305 for (dal::bv_visitor cv(slm.convex_index()); !cv.finished(); ++cv) {
306 bgeot::bounding_box(min,max,slm.points_of_convex(cv),slm.trans_of_convex(cv));
307 tree.add_box(min, max, cv);
312 void slicer_mesh_with_mesh::exec(mesh_slicer &ms) {
314 base_node min(ms.nodes[0].pt),max(ms.nodes[0].pt);
315 for (
size_type i=1; i < ms.nodes.size(); ++i) {
316 for (
size_type k=0; k < min.size(); ++k) {
317 min[k] = std::min(min[k], ms.nodes[i].pt[k]);
318 max[k] = std::max(max[k], ms.nodes[i].pt[k]);
321 std::vector<size_type> slmcvs;
322 tree.find_intersecting_boxes(min, max, slmcvs);
324 mesh_slicer::cs_simplexes_ct simplexes_final(ms.simplexes);
325 dal::bit_vector splx_in_save(ms.splx_in),
326 simplex_index_save(ms.simplex_index), nodes_index_save(ms.nodes_index);
330 for (
size_type i=0; i < slmcvs.size(); ++i) {
332 dim_type fcnt_save = dim_type(ms.fcnt);
333 ms.simplexes.resize(scnt0);
334 ms.splx_in = splx_in_save; ms.simplex_index = simplex_index_save; ms.nodes_index = nodes_index_save;
343 base_node G = gmm::mean_value(slm.points_of_convex(slmcv).begin(),slm.points_of_convex(slmcv).end());
345 n[0] = A[1]*B[2] - A[2]*B[1];
346 n[1] = A[2]*B[0] - A[0]*B[2];
347 n[2] = A[0]*B[1] - A[1]*B[0];
348 if (gmm::vect_sp(n,G-x0) > 0) n *= -1.;
354 slicer_half_space slf(x0,n,slicer_volume::VOLIN);
356 if (ms.splx_in.card() == 0)
break;
358 if (ms.splx_in.card()) intersection_callback(ms, slmcv);
359 for (dal::bv_visitor is(ms.splx_in); !is.finished(); ++is) {
360 simplexes_final.push_back(ms.simplexes[is]);
364 ms.splx_in.clear(); ms.splx_in.add(scnt0, simplexes_final.size()-scnt0);
365 ms.simplexes.swap(simplexes_final);
366 ms.simplex_index = ms.splx_in;
367 ms.update_nodes_index();
374 void slicer_isovalues::prepare(
size_type cv,
375 const mesh_slicer::cs_nodes_ct& nodes,
376 const dal::bit_vector& nodes_index) {
377 pt_in.clear(); pt_bin.clear();
378 std::vector<base_node> refpts(nodes.size());
379 Uval.resize(nodes.size());
382 pfem pf = mfU->pmf->fem_of_element(cv);
384 fem_precomp_pool fprecomp;
386 bgeot::vectors_to_base_matrix
387 (G,mfU->pmf->linked_mesh().points_of_convex(cv));
388 for (
size_type i=0; i < nodes.size(); ++i) refpts[i] = nodes[i].pt_ref;
389 pfem_precomp pfp = fprecomp(pf, store_point_tab(refpts));
390 mfU->copy(cv, coeff);
393 fem_interpolation_context ctx(mfU->pmf->linked_mesh().trans_of_convex(cv),
395 for (dal::bv_visitor i(nodes_index); !i.finished(); ++i) {
398 pf->interpolation(ctx, coeff, v, mfU->pmf->get_qdim());
401 pt_bin[i] = (gmm::abs(Uval[i] - val) < EPS * val_scaling);
402 pt_in[i] = (Uval[i] - val < 0);
if (
orient>0) pt_in[i] = !pt_in[i];
403 pt_in[i] = pt_in[i] || pt_bin[i];
411 void slicer_union::exec(mesh_slicer &ms) {
412 dal::bit_vector splx_in_base = ms.splx_in;
414 dim_type fcnt_0 = dim_type(ms.fcnt);
416 dal::bit_vector splx_inA(ms.splx_in);
417 dim_type fcnt_1 = dim_type(ms.fcnt);
419 dal::bit_vector splx_inB = splx_in_base;
420 splx_inB.add(c, ms.simplexes.size()-c);
421 splx_inB.setminus(splx_inA);
422 for (dal::bv_visitor_c i(splx_inB); !i.finished(); ++i) {
423 if (!ms.simplex_index[i]) splx_inB.sup(i);
426 ms.splx_in = splx_inB;
427 B->exec(ms); splx_inB = ms.splx_in;
428 ms.splx_in |= splx_inA;
434 for (
unsigned f=fcnt_0; f < fcnt_1; ++f) {
435 for (dal::bv_visitor i(splx_inB); !i.finished(); ++i) {
436 for (
unsigned j=0; j < ms.simplexes[i].dim()+1; ++j) {
437 bool face_boundA =
true;
438 for (
unsigned k=0; k < ms.simplexes[i].dim()+1; ++k) {
439 if (j != k && !ms.nodes[ms.simplexes[i].inodes[k]].faces[f]) {
440 face_boundA =
false;
break;
448 for (
unsigned k=0; k < ms.simplexes[i].dim()+1; ++k)
449 if (j != k) ms.nodes[ms.simplexes[i].inodes[k]].faces[f] =
false;
454 ms.update_nodes_index();
457 void slicer_intersect::exec(mesh_slicer& ms) {
462 void slicer_complementary::exec(mesh_slicer& ms) {
463 dal::bit_vector splx_inA = ms.splx_in;
465 A->exec(ms); splx_inA.swap(ms.splx_in);
466 ms.splx_in &= ms.simplex_index;
467 dal::bit_vector bv = ms.splx_in; bv.add(sz, ms.simplexes.size()-sz); bv &= ms.simplex_index;
468 for (dal::bv_visitor_c i(bv); !i.finished(); ++i) {
472 ms.splx_in[i] = !splx_inA.is_in(i);
476 void slicer_compute_area::exec(mesh_slicer &ms) {
477 for (dal::bv_visitor is(ms.splx_in); !is.finished(); ++is) {
478 const slice_simplex& s = ms.simplexes[is];
479 base_matrix M(s.dim(),s.dim());
482 M(i,j) = ms.nodes[s.inodes[i+1]].pt[j] - ms.nodes[s.inodes[0]].pt[j];
483 scalar_type v = bgeot::lu_det(&(*(M.begin())), s.dim());
484 for (
size_type d=2; d <= s.dim(); ++d) v /= scalar_type(d);
489 void slicer_build_edges_mesh::exec(mesh_slicer &ms) {
490 for (dal::bv_visitor is(ms.splx_in); !is.finished(); ++is) {
491 const slice_simplex& s = ms.simplexes[is];
493 for (
size_type j=i+1; j <= s.dim(); ++j) {
494 const slice_node& A = ms.nodes[s.inodes[i]];
495 const slice_node& B = ms.nodes[s.inodes[j]];
498 if ((A.faces & B.faces).count() >=
unsigned(ms.cv_dim-1)) {
499 slice_node::faces_ct fmask((1 << ms.cv_nbfaces)-1); fmask.flip();
501 if (pslice_edges && (((A.faces & B.faces) & fmask).any())) pslice_edges->add(e);
508 void slicer_build_mesh::exec(mesh_slicer &ms) {
509 std::vector<size_type> pid(ms.nodes_index.last_true()+1);
510 for (dal::bv_visitor i(ms.nodes_index); !i.finished(); ++i)
511 pid[i] = m.add_point(ms.nodes[i].pt);
512 for (dal::bv_visitor i(ms.splx_in); !i.finished(); ++i) {
513 for (
unsigned j=0; j < ms.simplexes.at(i).inodes.size(); ++j) {
514 assert(m.points_index().is_in(pid.at(ms.simplexes.at(i).inodes[j])));
516 m.add_convex(bgeot::simplex_geotrans(ms.simplexes[i].dim(),1),
517 gmm::index_ref_iterator(pid.begin(),
518 ms.simplexes[i].inodes.begin()));
522 void slicer_explode::exec(mesh_slicer &ms) {
523 if (ms.nodes_index.card() == 0)
return;
526 if (ms.face < dim_type(-1))
527 G = gmm::mean_value(ms.m.points_of_face_of_convex(ms.cv, ms.face).begin(),
528 ms.m.points_of_face_of_convex(ms.cv, ms.face).end());
530 G = gmm::mean_value(ms.m.points_of_convex(ms.cv).begin(),
531 ms.m.points_of_convex(ms.cv).end());
532 for (dal::bv_visitor i(ms.nodes_index); !i.finished(); ++i)
533 ms.nodes[i].pt = G + coef*(ms.nodes[i].pt - G);
535 for (dal::bv_visitor cnt(ms.splx_in); !cnt.finished(); ++cnt) {
536 const slice_simplex& s = ms.simplexes[cnt];
542 static unsigned ord[][3] = {{0,2,1},{1,2,3},{1,3,0},{0,3,2}};
543 for (
size_type k=0; k < 3; ++k) { s2.inodes[k] = ms.simplexes[cnt].inodes[ord[j][k]]; }
545 slice_node::faces_ct f; f.set();
546 for (
size_type i=0; i < s2.dim()+1; ++i) {
547 f &= ms.nodes[s2.inodes[i]].faces;
550 ms.add_simplex(s2,
true);
560 m(mls_.linked_mesh()), mls(&mls_), pgt(0), cvr(0) {}
562 m(m_), mls(0), pgt(0), cvr(0) {}
564 void mesh_slicer::using_mesh_level_set(
const mesh_level_set &mls_) {
566 GMM_ASSERT1(&m == &mls->
linked_mesh(),
"different meshes");
569 void mesh_slicer::pack() {
570 std::vector<size_type> new_id(nodes.size());
572 for (dal::bv_visitor i(nodes_index); !i.finished(); ++i) {
574 nodes[i].swap(nodes[ncnt]);
580 for (dal::bv_visitor j(simplex_index); !j.finished(); ++j) {
581 if (j != scnt) { simplexes[scnt] = simplexes[j]; }
582 for (std::vector<size_type>::iterator it = simplexes[scnt].inodes.begin();
583 it != simplexes[scnt].inodes.end(); ++it) {
587 simplexes.resize(scnt);
590 void mesh_slicer::update_nodes_index() {
592 for (dal::bv_visitor j(simplex_index); !j.finished(); ++j) {
593 assert(j < simplexes.size());
594 for (std::vector<size_type>::iterator it = simplexes[j].inodes.begin();
595 it != simplexes[j].inodes.end(); ++it) {
596 assert(*it < nodes.size());
597 nodes_index.add(*it);
602 static void flag_points_on_faces(
const bgeot::pconvex_ref& cvr,
603 const std::vector<base_node>& pts,
604 std::vector<slice_node::faces_ct>& faces) {
605 GMM_ASSERT1(cvr->structure()->nb_faces() <= 32,
606 "won't work for convexes with more than 32 faces "
607 "(hardcoded limit)");
608 faces.resize(pts.size());
609 for (
size_type i=0; i < pts.size(); ++i) {
611 for (
short_type f=0; f < cvr->structure()->nb_faces(); ++f)
612 faces[i][f] = (gmm::abs(cvr->is_in_face(f, pts[i])) < 1e-10);
619 pgt = m.trans_of_convex(cv);
620 prev_cvr = cvr; cvr = pgt->convex_ref();
621 cv_dim = cvr->structure()->dim();
622 cv_nbfaces = cvr->structure()->nb_faces();
623 fcnt = cvr->structure()->nb_faces();
624 discont = (mls && mls->is_convex_cut(cv));
627 void mesh_slicer::apply_slicers() {
628 simplex_index.clear(); simplex_index.add(0, simplexes.size());
629 splx_in = simplex_index;
630 nodes_index.clear(); nodes_index.add(0, nodes.size());
631 for (
size_type i=0; i < action.size(); ++i) {
632 action[i]->exec(*
this);
634 assert(simplex_index.contains(splx_in));
638 void mesh_slicer::simplex_orientation(slice_simplex& s) {
643 base_small_vector d = nodes[s.inodes[i]].pt - nodes[s.inodes[0]].pt;
644 gmm::copy_n(d.const_begin(), N, M.begin() + (i-1)*N);
646 scalar_type J = bgeot::lu_det(&(*(M.begin())), N);
649 std::swap(s.inodes[1],s.inodes[0]);
661 exec_(&nrefine[0], 1, cvlst);
666 if (pgt->dim() == m.dim() && m.dim()>=2) {
668 base_matrix G; bgeot::vectors_to_base_matrix(G,m.points_of_convex(cv));
669 base_node g(pgt->dim()); g.fill(.5);
670 base_matrix pc; pgt->poly_vector_grad(g,pc);
671 base_matrix K(pgt->dim(),pgt->dim());
673 scalar_type J = bgeot::lu_det(&(*(K.begin())), pgt->dim());
676 if (J < 0)
return true;
683 void mesh_slicer::exec_(
const short_type *pnrefine,
int nref_stride,
684 const mesh_region& cvlst) {
685 std::vector<base_node> cvm_pts;
686 const bgeot::basic_mesh *cvm = 0;
689 bgeot::pgeotrans_precomp pgp = 0;
690 std::vector<slice_node::faces_ct> points_on_faces;
694 for (mr_visitor it(cvlst); !it.finished(); ++it) {
695 size_type nrefine = pnrefine[it.cv()*nref_stride];
696 update_cv_data(it.cv(),it.f());
697 bool revert_orientation = check_orient(cv, pgt,m);
700 if (prev_cvr != cvr || nrefine != prev_nrefine) {
702 cvm_pts.resize(cvm->points().card());
703 std::copy(cvm->points().begin(), cvm->points().end(), cvm_pts.begin());
704 pgp = gppool(pgt, store_point_tab(cvm_pts));
705 flag_points_on_faces(cvr, cvm_pts, points_on_faces);
706 prev_nrefine = nrefine;
708 if (face < dim_type(-1))
714 std::vector<size_type> ptsid(cvm_pts.size()); std::fill(ptsid.begin(), ptsid.end(),
size_type(-1));
722 if (revert_orientation) std::swap(simplexes[snum].inodes[0],simplexes[snum].inodes[1]);
724 for (std::vector<size_type>::iterator itp = simplexes[snum].inodes.begin();
725 itp != simplexes[snum].inodes.end(); ++itp) {
727 ptsid[*itp] = nodes.size();
728 nodes.push_back(slice_node());
729 nodes.back().pt_ref = cvm_pts[*itp];
730 nodes.back().faces = points_on_faces[*itp];
731 nodes.back().pt.resize(m.dim()); nodes.back().pt.fill(0.);
732 pgp->transform(m.points_of_convex(cv), *itp, nodes.back().pt);
739 cout <<
"check orient cv " << cv <<
", snum=" << snum <<
"/" << cvms->
nb_convex();
741 simplex_orientation(simplexes[snum]);
747 #endif // OLD_MESH_SLICER
749 template <
typename CONT>
752 unsigned N = pgt->dim();
753 std::vector<base_node> v; v.reserve(N+1);
754 for (
unsigned i=0; i < pgt->nb_points(); ++i) {
755 const base_node P = pgt->convex_ref()->points()[i];
757 for (
unsigned j=0; j < N; ++j) {
758 s += P[j];
if (P[j] == 1) { v.push_back(pts[i]);
break; }
760 if (s == 0) v.push_back(pts[i]);
762 assert(v.size() == N+1);
763 base_node G = gmm::mean_value(v);
766 m.add_convex_by_points(bgeot::simplex_geotrans(N,1), v.begin());
769 const mesh& mesh_slicer::refined_simplex_mesh_for_convex_cut_by_level_set
770 (
const mesh &cvm,
unsigned nrefine) {
771 mesh mm; mm.copy_from(cvm);
772 while (nrefine > 1) {
773 mm.Bank_refine(mm.convex_index());
777 std::vector<size_type> idx;
780 for (dal::bv_visitor_c ic(mm.convex_index()); !ic.finished(); ++ic) {
781 add_degree1_convex(mm.trans_of_convex(ic), mm.points_of_convex(ic), tmp_mesh);
789 mesh_slicer::refined_simplex_mesh_for_convex_faces_cut_by_level_set
791 mesh &cvm = tmp_mesh;
792 tmp_mesh_struct.
clear();
793 unsigned N = cvm.dim();
795 dal::bit_vector pt_in_face; pt_in_face.sup(0, cvm.points().index().last_true()+1);
796 for (dal::bv_visitor ip(cvm.points().index()); !ip.finished(); ++ip)
797 if (gmm::abs(cvr->is_in_face(
short_type(f), cvm.points()[ip]))) pt_in_face.add(ip);
799 for (dal::bv_visitor_c ic(cvm.convex_index()); !ic.finished(); ++ic) {
800 for (
short_type ff=0; ff < cvm.nb_faces_of_convex(ic); ++ff) {
802 for (
unsigned i=0; i < N; ++i) {
803 if (!pt_in_face.is_in(cvm.ind_points_of_face_of_convex(ic,ff)[i])) {
804 face_ok =
false;
break;
809 cvm.ind_points_of_face_of_convex(ic, ff).begin());
813 return tmp_mesh_struct;
816 void mesh_slicer::exec_(
const short_type *pnrefine,
818 const mesh_region& cvlst) {
819 std::vector<base_node> cvm_pts;
820 const bgeot::basic_mesh *cvm = 0;
823 bgeot::pgeotrans_precomp pgp = 0;
824 std::vector<slice_node::faces_ct> points_on_faces;
825 bool prev_discont =
true;
830 for (mr_visitor it(cvlst); !it.finished(); ++it) {
831 size_type nrefine = pnrefine[it.cv()*nref_stride];
832 update_cv_data(it.cv(),it.f());
833 bool revert_orientation = check_orient(cv, pgt,m);
837 if (prev_cvr != cvr || nrefine != prev_nrefine
838 || discont || prev_discont) {
840 cvm = &refined_simplex_mesh_for_convex_cut_by_level_set
841 (mls->mesh_of_convex(cv),
unsigned(nrefine));
845 cvm_pts.resize(cvm->points().card());
846 std::copy(cvm->points().begin(), cvm->points().end(), cvm_pts.begin());
847 pgp = gppool(pgt, store_point_tab(cvm_pts));
848 flag_points_on_faces(cvr, cvm_pts, points_on_faces);
849 prev_nrefine = nrefine;
851 if (face < dim_type(-1)) {
856 cvms = &refined_simplex_mesh_for_convex_faces_cut_by_level_set(face);
863 std::vector<size_type> ptsid(cvm_pts.size()); std::fill(ptsid.begin(), ptsid.end(),
size_type(-1));
873 if (revert_orientation) std::swap(simplexes[snum].inodes[0],simplexes[snum].inodes[1]);
876 G.resize(m.dim()); G.fill(0.);
877 for (std::vector<size_type>::iterator itp =
878 simplexes[snum].inodes.begin();
879 itp != simplexes[snum].inodes.end(); ++itp) {
882 G /= scalar_type(simplexes[snum].inodes.size());
885 for (std::vector<size_type>::iterator itp =
886 simplexes[snum].inodes.begin();
887 itp != simplexes[snum].inodes.end(); ++itp) {
888 if (discont || ptsid[*itp] ==
size_type(-1)) {
889 ptsid[*itp] = nodes.size();
890 nodes.push_back(slice_node());
892 nodes.back().pt_ref = cvm_pts[*itp];
898 nodes.back().pt_ref = cvm_pts[*itp] + 0.01*(G - cvm_pts[*itp]);
900 nodes.back().faces = points_on_faces[*itp];
901 nodes.back().pt.resize(m.dim()); nodes.back().pt.fill(0.);
902 pgp->transform(m.points_of_convex(cv), *itp, nodes.back().pt);
913 prev_discont = discont;
919 exec(nrefine,mesh_region(m.convex_index()));
924 GMM_ASSERT1(&sl.
linked_mesh() == &m,
"wrong mesh");
925 for (stored_mesh_slice::cvlst_ct::const_iterator it = sl.cvlst.begin(); it != sl.cvlst.end(); ++it) {
926 update_cv_data((*it).cv_num);
928 simplexes = (*it).simplexes;
939 for (dal::bv_visitor ic(m.convex_index()); !ic.finished(); ++ic) {
943 nodes.resize(0); simplexes.resize(0);
947 nodes.push_back(slice_node(pts[itab[i]],ptab[i])); nodes.back().faces=0;
948 slice_simplex s(1); s.inodes[0] = nodes.size()-1;
949 simplexes.push_back(s);