37 namespace extensions {
74 gsTrimData(
unsigned level,std::vector<index_t>& AABBBox,std::vector<std::vector<std::vector<T> > >polylines)
75 : m_level(level),m_AABBBox(AABBBox),m_Polylines(polylines)
78 gsTrimData() : m_level(0),m_AABBBox(),m_Polylines()
83 std::vector<index_t> m_AABBBox;
84 std::vector<std::vector<std::vector<T> > > m_Polylines;
88 void makeValidGeometry(
const gsTHBSpline<2>& surface,
89 gsTensorBSpline<2, real_t>& bspline);
91 void getInterval(
const bool directionU,
94 const real_t paramConst,
95 const gsTensorBSpline<2, real_t>& bspline,
96 const PK_CURVE_t line,
97 PK_INTERVAL_t& result);
99 bool validMultiplicities(
const std::vector<index_t>& mult,
103 bool exportCheck(
const gsTHBSpline<2, T>& surface);
106 bool exportTHBsurface(
const gsTHBSpline<2, T>& surface,
107 gsTHBSplineBasis<2>::TrimmingCurves trimCurves,
108 gsTHBSplineBasis<2>::AxisAlignedBoundingBox boundaryAABB,
109 PK_ASSEMBLY_t& body );
112 void getTrimCurvesAndBoundingBoxes(
const gsTHBSpline<2, T>& surface,
113 std::vector<index_t>& boxes,
114 gsTHBSplineBasis<2>::TrimmingCurves& trimCurves,
115 gsTHBSplineBasis<2>::AxisAlignedBoundingBox& boundaryAABB);
118 bool gsWriteParasolid(
const gsMultiPatch<T> & gssurfs, std::string
const & filename )
120 std::cout <<
"write parasolid mulitpatch" << std::endl;
124 PK_GEOM_t geo[ gssurfs.nPatches() ];
127 gsPKSession::start();
131 PK_LOGICAL_t checks(0);
132 PK_SESSION_set_check_continuity(checks);
133 PK_SESSION_set_check_self_int(checks);
137 for (
typename gsMultiPatch<T>::const_iterator
138 it = gssurfs.begin(); it != gssurfs.end(); ++it)
140 createPK_GEOM(**it, geo[count++] );
151 PK_BODY_t parts[count];
152 for (
int i = 0; i!= count; ++i )
155 PK_ERROR_code_t err = PK_SURF_ask_uvbox(geo[i], &uvbox);
156 PARASOLID_ERROR(PK_SURF_ask_uvbox, err);
158 PK_SURF_make_sheet_body(geo[i], uvbox, &part);
159 PARASOLID_ERROR(PK_SURF_make_sheet_body, err);
165 PK_PART_transmit_o_t transmit_options;
166 PK_PART_transmit_o_m(transmit_options);
167 transmit_options.transmit_format = PK_transmit_format_text_c;
168 err = PK_PART_transmit(count, parts, filename.c_str(), &transmit_options);
169 PARASOLID_ERROR(PK_PART_transmit, err);
178 bool gsWriteParasolid(
const gsGeometry<T> & ggeo, std::string
const & filename )
185 gsPKSession::start();
188 PK_LOGICAL_t checks(0);
189 PK_SESSION_set_check_continuity(checks);
190 PK_SESSION_set_check_self_int(checks);
193 createPK_GEOM(ggeo, pgeo);
196 PK_ASSEMBLY_create_empty(&part);
197 err = PK_PART_add_geoms(part, 1, &pgeo);
198 PARASOLID_ERROR(PK_PART_add_geoms, err);
201 PK_PART_transmit_o_t transmit_options;
202 PK_PART_transmit_o_m(transmit_options);
203 transmit_options.transmit_format = PK_transmit_format_text_c;
204 err = PK_PART_transmit(1, &part, filename.c_str(), &transmit_options);
205 PARASOLID_ERROR(PK_PART_transmit, err);
215 bool gsWriteParasolid(
const gsMesh<T>& mesh,
const std::string & filename)
217 gsPKSession::start();
219 PK_LOGICAL_t checks(0);
220 PK_SESSION_set_check_continuity(checks);
221 PK_SESSION_set_check_self_int(checks);
223 PK_ASSEMBLY_t assembly;
224 exportMesh(mesh, assembly);
226 PK_PART_transmit_o_t transmit_options;
227 PK_PART_transmit_o_m(transmit_options);
228 transmit_options.transmit_format = PK_transmit_format_text_c;
230 PK_ERROR_code_t err = PK_PART_transmit(1, &assembly, filename.c_str(), &transmit_options);
231 PARASOLID_ERROR(PK_PART_transmit, err);
240 bool gsWriteParasolid(
const gsTHBSpline<2, T>& thb,
const std::string& filename)
242 gsPKSession::start();
243 PK_LOGICAL_t checks(0);
244 PK_SESSION_set_check_continuity(checks);
245 PK_SESSION_set_check_self_int(checks);
247 PK_ASSEMBLY_t assembly;
248 exportTHBsurface<T>(thb, assembly);
250 PK_PART_transmit_o_t transmit_options;
251 PK_PART_transmit_o_m(transmit_options);
252 transmit_options.transmit_format = PK_transmit_format_text_c;
254 PK_ERROR_code_t err = PK_PART_transmit(1, &assembly, filename.c_str(), &transmit_options);
255 PARASOLID_ERROR(PK_PART_transmit, err);
263 bool gsWriteParasolid(
const gsTHBSpline<2, T>& thb,
const std::vector<T>& par_boxes,
const std::string& filename )
265 gsPKSession::start();
266 PK_LOGICAL_t checks(0);
267 PK_SESSION_set_check_continuity(checks);
268 PK_SESSION_set_check_self_int(checks);
270 PK_ASSEMBLY_t assembly;
271 exportTHBsurface<T>(thb,par_boxes,assembly);
273 PK_PART_transmit_o_t transmit_options;
274 PK_PART_transmit_o_m(transmit_options);
275 transmit_options.transmit_format = PK_transmit_format_text_c;
277 PK_ERROR_code_t err = PK_PART_transmit(1, &assembly, filename.c_str(), &transmit_options);
278 PARASOLID_ERROR(PK_PART_transmit, err);
284 bool gsWritePK_SHEET(
const gsTensorBSpline<2, T>& tp,
const std::string& filename)
286 gsPKSession::start();
287 PK_LOGICAL_t checks(0);
288 PK_SESSION_set_check_continuity(checks);
289 PK_SESSION_set_check_self_int(checks);
294 createPK_BSURF<T>(tp, bsurf,
false,
false);
296 gsMatrix<T> domain = tp.parameterRange();
299 uv_box.param[0] = domain(0, 0);
300 uv_box.param[1] = domain(1, 0);
301 uv_box.param[2] = domain(0, 1);
302 uv_box.param[3] = domain(1, 1);
304 err = PK_SURF_make_sheet_body(bsurf, uv_box, &body);
305 PARASOLID_ERROR(PK_SURF_make_sheet_body, err);
312 PK_PART_transmit_o_t transmit_options;
313 PK_PART_transmit_o_m(transmit_options);
314 transmit_options.transmit_format = PK_transmit_format_text_c;
316 err = PK_PART_transmit(1, &body, filename.c_str(), &transmit_options);
317 PARASOLID_ERROR(PK_PART_transmit, err);
326 bool createPK_GEOM(
const gsGeometry<T> & ggeo,
330 if (
const gsTensorBSpline<2,T> * tbsp =
331 dynamic_cast<const gsTensorBSpline<2,T> *
>(&ggeo) )
333 return createPK_BSURF(*tbsp, pgeo);
337 else if (
const gsBSpline<>* bspl =
338 dynamic_cast< const gsBSpline<>*
>(&ggeo) )
340 return createPK_BCURVE(*bspl, pgeo);
344 gsInfo <<
"Cannot write "<<ggeo<<
" to parasolid file.\n";
351 bool createPK_BSURF(
const gsTensorBSpline< 2, T> & bsp,
356 typedef typename gsKnotVector<T>::mult_t mult_t;
357 std::vector<mult_t> mult;
361 for (
index_t dim = 0; dim != 2; dim++)
363 const int deg = bsp.basis().degree(dim);
364 mult = bsp.basis().knots(dim).multiplicities();
366 if (!validMultiplicities(mult, deg))
377 sform.u_degree = bsp.basis().degree(1);
378 sform.v_degree = bsp.basis().degree(0);
381 std::vector<T> gknot0 = bsp.basis().knots(1).unique();
382 std::vector<mult_t> gmult0 = bsp.basis().knots(1).multiplicities();
383 sform.n_u_knots = gknot0.size();
384 sform.u_knot = gknot0.data();
385 sform.u_knot_mult = gmult0.data();
388 std::vector<T> gknot1 = bsp.basis().knots(0).unique();
389 std::vector<mult_t> gmult1 = bsp.basis().knots(0).multiplicities();
390 sform.n_v_knots = gknot1.size();
391 sform.v_knot = gknot1.data();
392 sform.v_knot_mult = gmult1.data();
395 sform.n_u_vertices = bsp.basis().size(1);
396 sform.n_v_vertices = bsp.basis().size(0);
397 gsMatrix<T> coefs = bsp.coefs();
398 const int n = bsp.geoDim();
401 coefs.conservativeResize(gsEigen::NoChange, 3);
402 coefs.rightCols(3-n).setZero();
404 coefs.transposeInPlace();
405 coefs.resize(3*bsp.basis().size(), 1);
406 sform.vertex_dim = 3;
407 sform.vertex = coefs.data();
410 sform.is_rational = PK_LOGICAL_false;
411 sform.form = PK_BSURF_form_unset_c;
412 sform.u_knot_type = PK_knot_unset_c;
413 sform.v_knot_type = PK_knot_unset_c;
414 sform.is_u_periodic = PK_LOGICAL_false;
415 sform.is_v_periodic = PK_LOGICAL_false;
416 sform.is_u_closed = PK_LOGICAL_false;
417 sform.is_v_closed = PK_LOGICAL_false;
421 sform.is_v_closed = PK_LOGICAL_true;
426 sform.is_u_closed = PK_LOGICAL_true;
429 sform.self_intersecting = PK_self_intersect_unset_c;
430 sform.convexity = PK_convexity_unset_c;
433 PK_ERROR_code_t err = PK_BSURF_create(&sform, &bsurf);
434 PARASOLID_ERROR(PK_BSURF_create, err);
437 PK_BSURF_reparameterise_o_t options;
438 PK_BSURF_reparameterise_o_m(options);
439 options.transpose = PK_LOGICAL_true;
441 err = PK_BSURF_reparameterise(bsurf,&options);
442 PARASOLID_ERROR(PK_BSURF_reparameterise, err);
448 bool createPK_BCURVE(
const gsBSpline<T>& curve,
451 typedef typename gsKnotVector<T>::mult_t mult_t;
453 PK_BCURVE_sf_t sform;
456 sform.degree = curve.degree();
459 std::vector<T> knots = curve.basis().knots().unique();
460 std::vector<mult_t> mult = curve.basis().knots().multiplicities();
461 sform.n_knots = knots.size();
462 sform.knot = knots.data();
463 sform.knot_mult = mult.data();
467 sform.n_vertices = curve.basis().size();
468 gsMatrix<T> coefs = curve.coefs();
469 const int n = curve.geoDim();
472 coefs.conservativeResize(gsEigen::NoChange, 3);
473 coefs.rightCols(3 - n).setZero();
475 coefs.transposeInPlace();
476 coefs.resize(3 * curve.basis().size(), 1);
477 sform.vertex_dim = 3;
478 sform.vertex = coefs.data();
481 sform.is_rational = PK_LOGICAL_false;
482 sform.form = PK_BCURVE_form_unset_c;
483 sform.knot_type = PK_knot_unset_c;
484 sform.is_periodic = PK_LOGICAL_false;
485 sform.is_closed = PK_LOGICAL_false;
486 sform.self_intersecting = PK_self_intersect_unset_c;
488 PK_ERROR_code_t err = PK_BCURVE_create(&sform, &bcurve);
489 PARASOLID_ERROR(PK_BCURVE_create, err);
495 bool exportMesh(
const gsMesh<T>& mesh,
496 PK_ASSEMBLY_t& assembly)
505 PK_ERROR_t err = PK_ASSEMBLY_create_empty(&assembly);
506 PARASOLID_ERROR(PK_ASSEMBLY_create_empty, err);
508 gsKnotVector<T> kv(0, 1, 0, 2);
509 gsMatrix<T> coefs(2, 3);
510 gsBSpline<T> bspl(kv, coefs);
512 gsMatrix<T> newCoefs(2, 3);
513 for (
size_t i = 0; i != mesh.numEdges(); ++i)
515 newCoefs.row(0) = mesh.edges()[i].source->transpose();
516 newCoefs.row(1) = mesh.edges()[i].target->transpose();
518 if ((newCoefs.row(0) - newCoefs.row(1)).norm() < 1e-6)
523 bspl.setCoefs(newCoefs);
526 createPK_BCURVE(bspl, bcurve);
528 err = PK_PART_add_geoms(assembly, 1, &bcurve);
529 PARASOLID_ERROR(PK_PART_add_geoms, err);
537 bool exportTHBsurface(
const gsTHBSpline<2, T>& surface,
538 PK_ASSEMBLY_t& assembly)
540 if(!exportCheck(surface))
543 gsTHBSplineBasis<2>::AxisAlignedBoundingBox boundaryAABB;
544 gsTHBSplineBasis<2>::TrimmingCurves trimCurves;
546 const gsTHBSplineBasis<2>& basis= surface.basis();
548 basis.decomposeDomain(boundaryAABB, trimCurves);
550 std::vector<gsTrimData<T> > trimData;
552 bool success = getTrimDataFromBoundaryTrimCurves(boundaryAABB,trimCurves,trimData);
557 return exportTHBsurface(surface,trimData,assembly);
561 bool exportTHBsurface(
const gsTHBSpline<2, T>& surface,
562 const std::vector<T>& par_boxes,
563 PK_ASSEMBLY_t& assembly)
565 if(par_boxes.size()==0)
566 return exportTHBsurface(surface,assembly);
568 if(!exportCheck(surface))
571 std::vector<gsTrimData<T> > trimData;
573 bool success = getTrimCurvesAndBoundingBoxes<T>(surface,par_boxes,trimData);
578 return exportTHBsurface(surface,trimData,assembly);
587 bool validMultiplicities(
const std::vector<index_t>& mult,
590 for (
size_t i = 1; i != mult.size() - 1; i++)
592 if (mult[i] == deg + 1)
595 "Only B-Splines with (inner) multiplicity less (<) "
596 "than degree + 1 are supported. \n"
597 "Parasolid restriction."
613 void getInterval(
const bool directionU,
616 const real_t paramConst,
617 const gsTensorBSpline<2, real_t>& bspline,
618 const PK_CURVE_t line,
619 PK_INTERVAL_t& result)
621 gsMatrix<> param(2, 2);
624 param(0, 0) = param1;
625 param(1, 0) = paramConst;
627 param(0, 1) = param2;
628 param(1, 1) = paramConst;
632 param(0, 0) = paramConst;
633 param(1, 0) = param1;
635 param(0, 1) = paramConst;
636 param(1, 1) = param2;
640 bspline.eval_into(param, points);
643 for (
index_t i = 0; i != 2; i++)
645 PK_VECTOR_t position;
646 position.coord[0] = 0;
647 position.coord[1] = 0;
648 position.coord[2] = 0;
650 for (
index_t row = 0; row != points.rows(); row++)
652 position.coord[row] = points(row, i);
657 PK_ERROR_t err = PK_CURVE_parameterise_vector(line, position, &p);
658 PARASOLID_ERROR(PK_CURVE_parameterise_vector, err);
664 if( param1!=param2 && result.value[0]==result.value[1] )
666 result.value[0]=param1;
667 result.value[1]=param2;
687 makeValidGeometry(
const gsTHBSpline<2>& surface,
688 gsTensorBSpline<2, real_t>& bspline)
692 gsMatrix<>& coefs = bspline.coefs();
693 gsVector<int> globalToLocal(coefs.rows());
694 globalToLocal.setConstant(-1);
697 for (
index_t row = 0; row != coefs.rows(); row++)
700 for (
index_t col = 0; col != coefs.cols(); col++)
702 if (coefs(row, col) != 0.0)
711 globalToLocal(row) = numZeroRows;
726 bspline.basis().anchors_into(anchors);
728 gsMatrix<> params(2, coefs.rows());
729 gsVector<> localToGlobal(coefs.rows());
732 gsMatrix<> support = bspline.basis().support();
734 for (
index_t fun = 0; fun != globalToLocal.rows(); fun++)
736 if (globalToLocal(fun) != -1)
738 params.col(counter) = anchors.col(fun);
739 localToGlobal(counter) = fun;
740 for (
index_t row = 0; row != support.rows(); row++)
742 if (params(row, counter) < support(row, 0))
744 params(row, counter) = support(row, 0);
747 if (support(row, 1) < params(row, counter))
749 params(row, counter) = support(row, 1);
756 params.conservativeResize(2, counter);
757 localToGlobal.conservativeResize(counter);
760 surface.eval_into(params, points);
764 gsSparseMatrix<> A(localToGlobal.rows(), localToGlobal.rows());
766 gsMatrix<> B(localToGlobal.rows(), surface.geoDim());
770 gsMatrix<index_t> actives;
772 for (
index_t k = 0; k != params.cols(); k++)
774 const gsMatrix<>& curr_param = params.col(k);
776 bspline.basis().eval_into(curr_param, value);
777 bspline.basis().active_into(curr_param, actives);
778 const index_t numActive = actives.rows();
780 for (
index_t i = 0; i != numActive; i++)
782 const int I = globalToLocal(actives(i, 0));
785 B.row(I) += value(i, 0) * points.col(k);
787 for (
index_t j = 0; j != numActive; j++)
789 const int J = globalToLocal(actives(j, 0));
792 A(I, J) += value(i, 0) * value(j, 0);
800 gsSparseSolver<real_t>::BiCGSTABILUT solver(A);
803 gsWarn<<
"The preconditioner failed. Aborting.\n";
807 gsMatrix<> x = solver.solve(B);
809 for (
index_t row = 0; row != x.rows(); row++)
811 coefs.row(localToGlobal(row)) = x.row(row);
816 bool exportCheck(
const gsTHBSpline<2, T>& surface)
818 typedef typename gsKnotVector<T>::mult_t mult_t;
820 for (
index_t dim = 0; dim != 2; dim++)
822 typedef std::vector< gsTensorBSplineBasis< 2, real_t>* > Bases;
823 const Bases& bases = surface.basis().getBases();
824 const int deg = (bases[0])->degree(dim);
825 std::vector<mult_t> mult = (bases[0])->knots(dim).multiplicities();
827 if (!validMultiplicities(mult, deg))
837 bool exportTHBsurface(
const gsTHBSpline<2, T>& surface,
838 std::vector<gsTrimData<T> >& trimData,
839 PK_ASSEMBLY_t& assembly )
841 const gsTHBSplineBasis<2>& basis= surface.basis();
843 PK_ERROR_t err = PK_SESSION_set_check_continuity(PK_LOGICAL_false);
844 PARASOLID_ERROR(PK_SESSION_set_check_continuity, err);
846 err = PK_ASSEMBLY_create_empty(&assembly);
847 PARASOLID_ERROR(PK_ASSEMBLY_create_empty, err);
849 for (
size_t box = 0;box<trimData.size();++box)
851 unsigned level = trimData[box].m_level;
852 std::vector<index_t> AABBBox = trimData[box].m_AABBBox;
853 std::vector<std::vector<std::vector<T> > > polylines = trimData[box].m_Polylines;
855 gsTensorBSpline<2, T> bspline =
856 basis.getBSplinePatch(AABBBox, level, surface.coefs());
860 makeValidGeometry(surface, bspline);
865 createPK_BSURF<T>(bspline, bsurf);
867 std::vector<PK_CURVE_t> curves;
868 std::vector<PK_INTERVAL_t> intervals;
869 std::vector<int> trim_loop;
870 std::vector<int> trim_set;
872 for (
unsigned loop = 0; loop != polylines.size(); loop++)
874 for (
unsigned seg = 0; seg != polylines[loop].size(); seg++)
876 real_t y1 = polylines[loop][seg][0];
877 real_t x1 = polylines[loop][seg][1];
878 real_t y2 = polylines[loop][seg][2];
879 real_t x2 = polylines[loop][seg][3];
882 PK_INTERVAL_t intervalDummy;
883 PK_INTERVAL_t interval;
885 PK_SURF_make_curve_isoparam_o_t options;
886 PK_SURF_make_curve_isoparam_o_m(options);
890 err = PK_SURF_make_curve_isoparam(bsurf, x1, PK_PARAM_direction_v_c,
891 &options, &line, &intervalDummy);
892 PARASOLID_ERROR(PK_SURF_make_curve_isoparam, err);
894 getInterval(
true, y1, y2, x1, bspline, line, interval);
898 err = PK_SURF_make_curve_isoparam(bsurf, y1, PK_PARAM_direction_u_c,
899 &options, &line, &intervalDummy);
900 PARASOLID_ERROR(PK_SURF_make_curve_isoparam, err);
902 getInterval(
false, x1, x2, y1, bspline, line, interval);
905 curves.push_back(line);
906 intervals.push_back(interval);
907 trim_loop.push_back(loop);
908 trim_set.push_back(0);
989 PK_SURF_trim_data_t trim_data;
990 trim_data.n_spcurves =
static_cast<int>(curves.size());
991 trim_data.spcurves = curves.data();
992 trim_data.intervals = intervals.data();
993 trim_data.trim_loop = trim_loop.data();
994 trim_data.trim_set = trim_set.data();
996 PK_SURF_make_sheet_trimmed_o_t options;
997 PK_SURF_make_sheet_trimmed_o_m(options);
998 options.check_loops = PK_LOGICAL_true;
1000 PK_BODY_t trimSurface;
1001 PK_check_state_t state;
1002 err = PK_SURF_make_sheet_trimmed(bsurf, trim_data, 1e-8, &options,
1003 &trimSurface, &state);
1004 PARASOLID_ERROR(PK_SURF_make_sheet_trimmed, err);
1008 PK_ATTRIB_t attribut;
1009 PK_ATTDEF_find(
"SDL/TYSA_NAME",&attdef);
1010 if(attdef == PK_ENTITY_null)
1011 std::cout<<
"entity null for tysa name" <<std::endl;
1012 PK_ERROR_code_t err2 = PK_ATTRIB_create_empty(trimSurface,attdef,&attribut);
1013 if(err2 == PK_ERROR_existing_attrib || err2 == PK_ERROR_wrong_entity)
1014 std::cout<<
"attribute already exists" <<std::endl;
1015 PK_ATTRIB_set_string(attribut,0,name.c_str());
1016 if (state != PK_BODY_state_ok_c)
1018 std::cout <<
"Something went wrong. state(" << state <<
")" << std::endl;
1021 PK_INSTANCE_sf_t sform;
1022 sform.assembly = assembly;
1023 sform.transf = PK_ENTITY_null;
1024 sform.part = trimSurface;
1026 PK_INSTANCE_t instance;
1027 err = PK_INSTANCE_create(&sform, &instance);
1028 PARASOLID_ERROR(PK_INSTANCE_create, err);
1032 err = PK_SESSION_set_check_continuity(PK_LOGICAL_true);
1033 PARASOLID_ERROR(PK_SESSION_set_check_continuity, err);
1039 bool getParBoxAsIndexBoxInLevel(
const gsTHBSplineBasis<2, T>& basis,
unsigned lvl,
const std::vector<real_t>& par_box,
1040 std::vector<index_t>& index_box)
1046 unsigned lowerIndexU,upperIndexU,lowerIndexV,upperIndexV;
1047 const typename gsBSplineTraits<2,T>::Basis & tBasis = *(basis.getBases()[lvl]);
1048 const gsKnotVector<T> & tKvU = tBasis.component(0).knots();
1049 if( !( *(tKvU.begin())<=lowU && lowU<=upU &&
1050 upU<=tKvU.get().end()[-tKvU.degree()-1]) )
1054 std::cout <<
"Error in the box." << std::endl;
1057 std::cout<<
"Box in u is not in Range, it will be cut at domain boundary."<<std::endl;
1058 if( !( *(tKvU.begin())<=lowU) )
1059 lowU=*(tKvU.begin());
1060 if( !(upU<=tKvU.get().end()[-tKvU.degree()-1]) )
1061 upU=tKvU.get().end()[-tKvU.degree()-1];
1063 lowerIndexU=(tKvU.uFind(lowU)-tKvU.uFind(0));
1064 upperIndexU=(tKvU.uFind(upU)-tKvU.uFind(0))+1;
1066 const gsKnotVector<T> & tKvV = tBasis.component(1).knots();
1067 if( !( *(tKvV.begin())<=lowV && lowV<=upV &&
1068 upV<=tKvV.get().end()[-tKvV.degree()-1]) )
1072 std::cout <<
"Error in the box." << std::endl;
1075 std::cout<<
"Box in v is not in Range, it will be cut at domain boundary."<<std::endl;
1076 if( !( *(tKvV.begin())<=lowV) )
1077 lowV=*(tKvV.begin());
1078 if( !(upV<=tKvV.get().end()[-tKvV.degree()-1]) )
1079 upV=tKvV.get().end()[-tKvV.degree()-1];
1081 lowerIndexV=(tKvV.uFind(lowV)-tKvV.uFind(0));
1082 upperIndexV=(tKvV.uFind(upV)-tKvV.uFind(0))+1;
1084 index_box.push_back(lvl);
1085 index_box.push_back(lowerIndexU);
1086 index_box.push_back(lowerIndexV);
1087 index_box.push_back(upperIndexU);
1088 index_box.push_back(upperIndexV);
1093 bool parBoxesIntersect(
const std::vector<T>& par_boxes)
1095 T lowerUi,lowerVi,upperUi,upperVi,lowerUj,lowerVj,upperUj,upperVj;
1097 unsigned boxSize=2*d;
1098 for(
unsigned i = 0;i<par_boxes.size();i+=boxSize)
1100 lowerUi=par_boxes[i];
1101 lowerVi=par_boxes[i+1];
1102 upperUi=par_boxes[i+2];
1103 upperVi=par_boxes[i+3];
1104 for(
unsigned j = 0;j<i;j+=boxSize)
1106 lowerUj=par_boxes[j];
1107 lowerVj=par_boxes[j+1];
1108 upperUj=par_boxes[j+2];
1109 upperVj=par_boxes[j+3];
1111 if(upperUi>lowerUj&&lowerUi<upperUj&&
1112 upperVi>lowerVj&&lowerVi<upperVj)
1120 bool getTrimDataFromBoundaryTrimCurves(gsTHBSplineBasis<2>::AxisAlignedBoundingBox boundaryAABB,
1121 gsTHBSplineBasis<2>::TrimmingCurves trimCurves,std::vector<gsTrimData<T> >& trimdata)
1124 for(
unsigned level = 0;level<trimCurves.size();++level)
1126 for(
unsigned component=0;component<trimCurves[level].size();++component)
1128 gsTrimData<T> td(level,boundaryAABB[level][component],trimCurves[level][component]);
1129 trimdata.push_back(td);
1136 bool getTrimCurvesAndBoundingBoxes(
const gsTHBSpline<2, T>& surface,
1137 const std::vector<T>& par_boxes,
1138 std::vector<gsTrimData<T> >& trimdata)
1140 if(parBoxesIntersect(par_boxes))
1142 std::cout<<
"Given boxes have intersections."<<std::endl;
1146 const gsTHBSplineBasis<2, T>* basis =
static_cast< const gsTHBSplineBasis<2,T>*
> (&surface.basis());
1147 unsigned maxLevel = basis->tree().getMaxInsLevel();
1149 std::vector<std::vector<index_t> >aabbBoxesForCheck;
1150 std::vector<T> par_box;
1151 std::vector<index_t> index_box;
1153 unsigned boxSize=2*d;
1156 for(
unsigned i = 0;i<par_boxes.size();i=i+boxSize)
1159 par_box.push_back(par_boxes[i]);
1160 par_box.push_back(par_boxes[i+1]);
1161 par_box.push_back(par_boxes[i+2]);
1162 par_box.push_back(par_boxes[i+3]);
1163 success=getParBoxAsIndexBoxInLevel(*basis,maxLevel,par_box,index_box);
1168 gsVector<index_t,2>lower;
1169 lower << index_box[1],index_box[2];
1170 gsVector<index_t,2>upper;
1171 upper << index_box[3],index_box[4];
1172 lvl=basis->tree().query4(lower, upper, index_box[0]);
1174 success=getParBoxAsIndexBoxInLevel(*basis,lvl,par_box,index_box);
1182 std::vector<index_t> aabb_box;
1183 aabb_box.push_back(index_box[1]<<(maxLevel-lvl));
1184 aabb_box.push_back(index_box[2]<<(maxLevel-lvl));
1185 aabb_box.push_back(index_box[3]<<(maxLevel-lvl));
1186 aabb_box.push_back(index_box[4]<<(maxLevel-lvl));
1188 std::vector<std::vector<std::vector<T> > > trimCurveComp;
1189 std::vector<std::vector<T> >trimCurveBox;
1190 std::vector<T> trimCurve;
1191 trimCurve.push_back(par_box[0]);
1192 trimCurve.push_back(par_box[1]);
1193 trimCurve.push_back(par_box[0]);
1194 trimCurve.push_back(par_box[3]);
1195 trimCurveBox.push_back(trimCurve);
1197 trimCurve.push_back(par_box[0]);
1198 trimCurve.push_back(par_box[3]);
1199 trimCurve.push_back(par_box[2]);
1200 trimCurve.push_back(par_box[3]);
1201 trimCurveBox.push_back(trimCurve);
1203 trimCurve.push_back(par_box[2]);
1204 trimCurve.push_back(par_box[1]);
1205 trimCurve.push_back(par_box[2]);
1206 trimCurve.push_back(par_box[3]);
1207 trimCurveBox.push_back(trimCurve);
1209 trimCurve.push_back(par_box[0]);
1210 trimCurve.push_back(par_box[1]);
1211 trimCurve.push_back(par_box[2]);
1212 trimCurve.push_back(par_box[1]);
1213 trimCurveBox.push_back(trimCurve);
1214 trimCurveComp.push_back(trimCurveBox);
1216 gsTrimData<T> td(lvl,aabb_box,trimCurveComp);
1217 trimdata.push_back(td);
1219 aabbBoxesForCheck.push_back(aabb_box);
1230 #undef PARASOLID_ERROR
Knot vector for B-splines.
Manages starting and stopping Parasolid session.
Provides declaration of Surface abstract interface.
Provides declaration of THBSplineBasis class.
Represents a tensor-product B-spline patch.
#define index_t
Definition: gsConfig.h:32
Provides declaration of gsReadParasolid functions.
Provides declaration of functions writing Paraview files.
Provides declaration of THBSplineBasis class.
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
#define gsWarn
Definition: gsDebug.h:50
Provides declaration of BSplineBasis class.
Provides declaration of the MultiPatch class.
#define gsInfo
Definition: gsDebug.h:43
Provides declaration of the Mesh class.
Defines the Parasolud frustrim.
Represents a B-spline curve/function with one parameter.