00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef synaps_topology_TopSbdSurf_h
00022 #define synaps_topology_TopSbdSurf_h
00023 #include <synaps/linalg/MatrDse.h>
00024 #include <synaps/topology/Cell3d.h>
00025 #include <synaps/topology/TopSbdCurve3d.h>
00026 __BEGIN_NAMESPACE_SYNAPS
00027
00028
00029
00030 template < class C,
00031 class CELL= Cell3d<C> ,
00032 class MSLV = SbdSolver<typename CELL::coeff_t,SBDSLV_RDL> >
00033
00034 struct TopSbdSurf3d : public TopSbdCurve3d<C,CELL,MSLV>
00035 {
00036
00038
00040
00041 typedef TopSbdSurf3d<C, CELL,MSLV> self_t;
00042 typedef TopSbdCurve3d<C,CELL,MSLV> base_t;
00043
00044 typedef typename CELL::coeff_t coeff_t;
00045 typedef typename CELL::MPOL_T MPOL_T;
00046 typedef topology::box3d<coeff_t> box_t;
00047
00048 typedef CELL cell_t;
00049 typedef OCTREE::Node<cell_t*> node_t;
00050 typedef OCTREE::Octree<cell_t*> octree_t;
00051
00052 typedef topology::point<C> point_t;
00053 typedef topology::point_graph<C> pointgraph_t;
00054
00055 typedef intersection3d<coeff_t> intersection_t;
00056 typedef Seq<intersection3d<coeff_t>*> intersectionlist_t;
00057 typedef shared_object<intersection_t*> intersection_ptr;
00058 typedef Seq<intersection_ptr> intersection_ptr_list;
00059 typedef topology::point_graph<coeff_t, intersection_ptr_list> pointgraph_int_t;
00060
00061
00062
00063
00064 typedef MPolDse< coeff_t, mpoldse::bernstein<coeff_t> > mpolb_t;
00065
00066 static OCTREE::EDGE_TYPE EdgesOfFace[6][4];
00067
00068 unsigned m_min_dp, m_max_dp;
00069 MatrDse< Seq<OCTREE::NODE_TYPE> > insert_matr;
00070
00071 TopSbdSurf3d():base_t (), m_min_dp(0), m_max_dp(6) {}
00072 TopSbdSurf3d(unsigned mn, unsigned mx=6):base_t (), m_min_dp(mn), m_max_dp(mx) {}
00073 TopSbdSurf3d(coeff_t e):base_t(e), m_min_dp(0), m_max_dp(6) {}
00074 TopSbdSurf3d(coeff_t e, int d): base_t(e,d), m_min_dp(0), m_max_dp(6) {}
00075
00076
00077
00078
00080
00082
00083 bool compute_point_inside(point_t& p, cell_t* c);
00084
00085 void computeintersections(intersectionlist_t& inters, cell_t& c);
00086
00087
00088 void computeinter_face(intersectionlist_t& inters, cell_t& c, int nAxis, int nFace);
00089
00090
00091 void computeinter_face(intersectionlist_t& inters, cell_t& c,
00092 int n1Axis, int n1Face, int n2Axis, int n2Face);
00093
00094 void computeinter_edge(intersectionlist_t& inters, cell_t& c,
00095 OCTREE::EDGE_TYPE edge);
00096
00097 void computeinter_edges(intersectionlist_t& inters, cell_t& c);
00098
00099
00100
00101 bool regularity(CELL& c);
00102
00103 template<class POINTGRAPH>
00104 void build_mesh(POINTGRAPH& g, node_t* n);
00105
00106
00107 void compute_points(node_t* n);
00108
00109 template<class POINTGRAPH>
00110 void run(POINTGRAPH& g, CELL* rc);
00111
00112 protected:
00113
00114
00115
00116 void subdivide(node_t* n, std::vector<node_t*>& aNodeList);
00117
00118 void subdivide(CELL* cell, std::vector<CELL*>& subCells);
00119
00120 };
00121
00122 template< class C, class CELL, class MSLV>
00123 OCTREE::EDGE_TYPE TopSbdSurf3d<C, CELL, MSLV>::EdgesOfFace[6][4]=
00124 {{OCTREE::B_E,OCTREE::B_W,OCTREE::B_S,OCTREE::B_N},
00125 {OCTREE::F_E,OCTREE::F_W,OCTREE::F_S,OCTREE::F_N},
00126 {OCTREE::B_W,OCTREE::F_W,OCTREE::S_W,OCTREE::N_W},
00127 {OCTREE::B_E,OCTREE::F_E,OCTREE::S_E,OCTREE::N_E},
00128 {OCTREE::B_S,OCTREE::F_S,OCTREE::S_W,OCTREE::S_E},
00129 {OCTREE::B_N,OCTREE::F_N,OCTREE::N_W,OCTREE::N_E}};
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00183
00185
00186
00187
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00203
00204 template< class C, class CELL, class MSLV>
00205 void TopSbdSurf3d<C, CELL, MSLV>::subdivide(node_t* n, std::vector<node_t*>& aNodeList)
00206 {
00207 using namespace OCTREE;
00208
00209 std::vector<node_t*> aNodeNeigbrs;
00210
00211
00212 cell_t* cell = n->GetCell();
00213 std::vector<cell_t*> subCells;
00214
00215
00216 subdivide(cell,subCells);
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 aNodeList.push_back(new node_t(B_SW, n, subCells[B_SW]));
00251 aNodeList.push_back(new node_t(F_SW, n, subCells[F_SW]));
00252 aNodeList.push_back(new node_t(B_SE, n, subCells[B_SE]));
00253 aNodeList.push_back(new node_t(F_SE, n, subCells[F_SE]));
00254 aNodeList.push_back(new node_t(B_NW, n, subCells[B_NW]));
00255 aNodeList.push_back(new node_t(F_NW, n, subCells[F_NW]));
00256 aNodeList.push_back(new node_t(B_NE, n, subCells[B_NE]));
00257 aNodeList.push_back(new node_t(F_NE, n, subCells[F_NE]));
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 }
00322
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00341
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00359
00360 template < class C, class CELL, class MSLV >
00361 void TopSbdSurf3d<C, CELL, MSLV>::subdivide(CELL* cell,
00362 std::vector<CELL*>& subCells)
00363 {
00364 typedef typename CELL::intersection_t intersection_t;
00365 typedef typename CELL::intersectionlist_t intersectionlist_t;
00366 typedef typename CELL::MPOL_T MPOL_T;
00367
00368 #ifdef SYNAPS_SBD3D_RNDFACTORWHENSUBDIVISION
00369
00370 C t[] = {(C(rand())/C(RAND_MAX)-C(0.5))*C(0.095)+C(0.5),
00371 (C(rand())/C(RAND_MAX)-C(0.5))*C(0.095)+C(0.5),
00372 (C(rand())/C(RAND_MAX)-C(0.5))*C(0.095)+C(0.5)};
00373 t[0]+= (t[0]>0.5?0.005:-0.005);
00374 t[1]+= (t[1]>0.5?0.005:-0.005);
00375 t[2]+= (t[2]>0.5?0.005:-0.005);
00376 C mid[] = {cell->m_cBox.x0*(C(1)-t[0])+cell->m_cBox.x1*t[0], cell->m_cBox.y0*(C(1)-t[1])+cell->m_cBox.y1*t[1], cell->m_cBox.z0*(C(1)-t[2])+cell->m_cBox.z1*t[2]};
00377 #else
00378 C mid[] = {(cell->m_cBox.x0+cell->m_cBox.x1)/C(2), (cell->m_cBox.y0+cell->m_cBox.y1)/C(2), (cell->m_cBox.z0+cell->m_cBox.z1)/C(2)};
00379 #endif
00380 C box[] = {cell->m_cBox.x0, cell->m_cBox.x1, cell->m_cBox.y0, cell->m_cBox.y1, cell->m_cBox.z0, cell->m_cBox.z1};
00381
00382
00383 subCells.push_back(new CELL(cell->nbpol(), box[0], mid[0], box[2], mid[1], box[4], mid[2]));
00384 subCells.push_back(new CELL(cell->nbpol(), mid[0], box[1], box[2], mid[1], box[4], mid[2]));
00385 subCells.push_back(new CELL(cell->nbpol(), box[0], mid[0], mid[1], box[3], box[4], mid[2]));
00386 subCells.push_back(new CELL(cell->nbpol(), mid[0], box[1], mid[1], box[3], box[4], mid[2]));
00387 subCells.push_back(new CELL(cell->nbpol(), box[0], mid[0], box[2], mid[1], mid[2], box[5]));
00388 subCells.push_back(new CELL(cell->nbpol(), mid[0], box[1], box[2], mid[1], mid[2], box[5]));
00389 subCells.push_back(new CELL(cell->nbpol(), box[0], mid[0], mid[1], box[3], mid[2], box[5]));
00390 subCells.push_back(new CELL(cell->nbpol(), mid[0], box[1], mid[1], box[3], mid[2], box[5]));
00391
00392
00393 for (int i = 0; i < 8; i++)
00394 {
00395 subCells[i]->m_nDepth = cell->m_nDepth+1;
00396 }
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 for (int i = 0; i < cell->nbpol(); i++)
00466 {
00467 MPOL_T splited[8];
00468 int vr_idx[3] = {VARIDX(cell->m_F[i], 0), VARIDX(cell->m_F[i], 1), VARIDX(cell->m_F[i], 2)};
00469
00470 subCells[7]->m_F[i] = cell->m_F[i];
00471 #ifdef SYNAPS_SBD3D_RNDFACTORWHENSUBDIVISION
00472
00473 mpoldse::split(subCells[3]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[2], t[2]);
00474
00475
00476 mpoldse::split(subCells[1]->m_F[i].rep(), subCells[3]->m_F[i].rep(), vr_idx[1], t[1]);
00477 mpoldse::split(subCells[5]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[1], t[1]);
00478
00479
00480 mpoldse::split(subCells[0]->m_F[i].rep(), subCells[1]->m_F[i].rep(), vr_idx[0], t[0]);
00481 mpoldse::split(subCells[2]->m_F[i].rep(), subCells[3]->m_F[i].rep(), vr_idx[0], t[0]);
00482 mpoldse::split(subCells[4]->m_F[i].rep(), subCells[5]->m_F[i].rep(), vr_idx[0], t[0]);
00483 mpoldse::split(subCells[6]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[0], t[0]);
00484 #else
00485
00486 mpoldse::split(subCells[3]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[2]);
00487
00488
00489 mpoldse::split(subCells[1]->m_F[i].rep(), subCells[3]->m_F[i].rep(), vr_idx[1]);
00490 mpoldse::split(subCells[5]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[1]);
00491
00492
00493 mpoldse::split(subCells[0]->m_F[i].rep(), subCells[1]->m_F[i].rep(), vr_idx[0]);
00494 mpoldse::split(subCells[2]->m_F[i].rep(), subCells[3]->m_F[i].rep(), vr_idx[0]);
00495 mpoldse::split(subCells[4]->m_F[i].rep(), subCells[5]->m_F[i].rep(), vr_idx[0]);
00496 mpoldse::split(subCells[6]->m_F[i].rep(), subCells[7]->m_F[i].rep(), vr_idx[0]);
00497 #endif
00498 }
00499
00500 }
00501
00502 template< class C, class CELL, class MSLV>
00503 template< class POINTGRAPH>
00504 void TopSbdSurf3d<C, CELL, MSLV>::run(POINTGRAPH& g, CELL* rc)
00505 {
00506 typedef CELL cell_t;
00507 node_t* root = this->m_cOcTree.GetRoot();
00508
00509
00510
00511
00512 root->SetCell(rc);
00513
00514
00515
00516
00517 std::list<node_t*> aNodeQueue;
00518 std::list<node_t*> aNodeKept;
00519 std::vector<node_t*> aSingular;
00520 pointgraph_int_t g_tmp;
00521 int nCellProc = 0;
00522
00523 aNodeQueue.push_front(root);
00524
00525 while(aNodeQueue.size())
00526 {
00527
00528 node_t* n = *aNodeQueue.begin();
00529 aNodeQueue.pop_front();
00530
00531 bool bSubdivide = false;
00532 bool bBuildGraph = false;
00533
00534
00535 if (regularity(*n->GetCell()))
00536 {
00537 if (is_variety_in(*n->GetCell()))
00538 {
00539 if (n->GetCell()->m_nDepth < this->m_nMinSbd)
00540 {
00541
00542 bSubdivide = true;
00543 }
00544 else
00545 {
00546 bBuildGraph = true;
00547 }
00548 }
00549 else
00550 {
00551
00552 memset(n->GetCell()->m_FaceComputed, true, sizeof(bool)*6);
00553 }
00554 }
00555 else
00556 {
00557 if (n->GetCell()->m_nDepth> m_max_dp)
00558 {
00559
00560 if (is_variety_in(*n->GetCell()))
00561 {
00562 bBuildGraph = true;
00563 aSingular.push_back(n);
00564 }
00565 else
00566 memset(n->GetCell()->m_FaceComputed, true, sizeof(bool)*6);
00567 }
00568 else
00569 {
00570
00571 if (is_variety_in(*n->GetCell()))
00572 bSubdivide = true;
00573 else
00574 memset(n->GetCell()->m_FaceComputed, true, sizeof(bool)*6);
00575 }
00576 }
00577
00578
00579
00580 if (bSubdivide)
00581 {
00582
00583
00584 std::vector<node_t*> aNodeList;
00585 subdivide(n, aNodeList);
00586 for (int i = 0; i < (int)aNodeList.size(); i++)
00587 aNodeQueue.push_back(aNodeList[i]);
00588 }
00589 else if (bBuildGraph)
00590 {
00591 aNodeKept.push_front(n);
00592 }
00593
00594
00595 nCellProc++;
00596 }
00597 PRINT_DEBUG("Computing points");
00598 typedef typename std::list<node_t*>::const_iterator node_iterator_t;
00599 for(node_iterator_t it=aNodeKept.begin(); it != aNodeKept.end(); it++)
00600 {
00601 compute_points(*it);
00602 }
00603
00604 PRINT_DEBUG("Building mesh");
00605 for(node_iterator_t it=aNodeKept.begin(); it != aNodeKept.end(); it++)
00606 {
00607 build_mesh(g,(*it));
00608 }
00609
00610 std::cout << "Number of Cells : " << nCellProc << std::endl;
00611 std::cout << "Number of Sing Cells: " << aSingular.size() << std::endl;
00612 }
00613
00614
00615 template <class C, class CELL, class MSLV >
00616 bool TopSbdSurf3d<C, CELL, MSLV>::compute_point_inside(point_t& p, cell_t* cell)
00617 {
00618 using namespace OCTREE;
00619 std::vector<cell_t*> subCells;
00620 subdivide(cell,subCells);
00621
00622 intersectionlist_t L;
00623 computeinter_edge(L,*subCells[B_SW],N_E);
00624 if(L.size())
00625 {
00626 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00627 }
00628
00629 computeinter_edge(L,*subCells[B_SW],F_N);
00630 if(L.size())
00631 {
00632 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00633 }
00634
00635 computeinter_edge(L,*subCells[B_SW],F_E);
00636 if(L.size())
00637 {
00638 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00639 }
00640
00641 computeinter_edge(L,*subCells[F_NE],B_W);
00642 if(L.size())
00643 {
00644 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00645 }
00646
00647 computeinter_edge(L,*subCells[F_NE],B_S);
00648 if(L.size())
00649 {
00650 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00651 }
00652
00653 computeinter_edge(L,*subCells[F_NE],S_W);
00654 if(L.size())
00655 {
00656 for(unsigned j=0;j<3;j++) p[j]=L[0]->pnt[j]; return true;
00657 }
00658
00659 return false;
00660 }
00661
00662 template <class C, class CELL, class MSLV >
00663 void TopSbdSurf3d<C, CELL, MSLV>::computeintersections(intersectionlist_t& inters, CELL& c)
00664 {
00665
00666
00667 for (int v = 0; v < 3; v++)
00668 {
00669 for (int f = 0; f < 2; f++)
00670 {
00671 if (!c.m_FaceComputed[v*2+f])
00672 {
00673 computeinter_face(inters, c, v, f);
00674
00675 }
00676 }
00677 }
00678 }
00679
00680 template < class C, class CELL, class MSLV >
00681 void TopSbdSurf3d<C, CELL, MSLV>::computeinter_face(intersectionlist_t& inters,
00682 CELL& c,
00683 int nAxis, int nFace)
00684 {
00685 PRINT_DEBUG("Points on face "<< nAxis<<" "<<nFace);
00686 unsigned N=c.m_nT;
00687 if (N==1) return;
00688
00689
00690 std::vector<MPOL_T> facepol(N+3);
00691 std::list<MPOL_T> eqnList;
00692 unsigned sz=0;
00693 for(unsigned i=0;i<N;i++)
00694 {
00695
00696 face(facepol[i].rep(), c.m_F[i].rep(), nAxis, nFace);
00697 eqnList.push_back(facepol[i]);
00698 sz++;
00699 }
00700 MPOL_T dp[3];
00701 for (unsigned i = 0; i < 3; i++)
00702 {
00703 diff(dp[i],c.m_F[0],VARIDX(c.m_F[0], i));
00704 face(facepol[N+i].rep(), dp[i].rep(), nAxis, nFace);
00705 sz++;
00706 }
00707 PRINT_DEBUG("Solving "<<sz<<" equations");
00708
00709 MSLV solver(&facepol[0], &facepol[0]+sz, 1e-4);
00710 PRINT_DEBUG("Solving "<<sz<<" equations");
00711 std::vector<C> results;
00712 int nSol, nVar;
00713 solver.solve(results, nSol, nVar, eqnList.begin(), eqnList.end());
00714 PRINT_DEBUG("Nb of sol: "<<nSol<<" Nb of var: "<<nVar);
00715
00716
00717
00718 for (int s = 0; s < nSol; s++)
00719 {
00720 C x[3] = {(C)nFace,(C)nFace,(C)nFace};
00721
00722 switch(nAxis)
00723 {
00724 case PLANEYZ:
00725 x[1] = (C)(results[nVar*s]);
00726 x[2] = (C)(results[nVar*s+1]);
00727 break;
00728 case PLANEXZ:
00729 x[0] = (C)(results[nVar*s]);
00730 x[2] = (C)(results[nVar*s+1]);
00731 break;
00732 case PLANEXY:
00733 x[0] = (C)(results[nVar*s]);
00734 x[1] = (C)(results[nVar*s+1]);
00735 break;
00736 }
00737
00738
00739 int nMulti = 2;
00740
00741
00742
00743 if(false)
00744 {
00745 C val[3] = {-1,-1,-1};
00746 eval(val[0], c.m_F[c.m_nT], x);
00747 eval(val[1], c.m_F[c.m_nT+1], x);
00748 eval(val[2], c.m_F[c.m_nT+2], x);
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761 val[nAxis] /= sqrt(val[0]*val[0]+val[1]*val[1]+val[2]*val[2]);
00762
00763 if (_is_verysmall(std::abs(val[nAxis])))
00764 {
00765 nMulti = 2;
00766
00767 }
00768 }
00769
00770
00771
00772 point_t l(3u);
00773 l[0] = c.m_cBox.x0*((C)1-x[0]) + c.m_cBox.x1*x[0];
00774 l[1] = c.m_cBox.y0*((C)1-x[1]) + c.m_cBox.y1*x[1];
00775 l[2] = c.m_cBox.z0*((C)1-x[2]) + c.m_cBox.z1*x[2];
00776
00777
00778 intersection_t *ni = new intersection_t(l, nAxis, nMulti);
00779 inters.push_back(ni);
00780 ni->nDepth = c.m_nDepth;
00781
00782 }
00783 PRINT_DEBUG("End point on face");
00784 }
00785
00786 template < class C, class CELL, class MSLV >
00787 void TopSbdSurf3d<C, CELL, MSLV>::computeinter_face(intersectionlist_t& inters,
00788 CELL& c,
00789 int n1Axis, int n1Face,
00790 int n2Axis, int n2Face)
00791 {
00792 assert(n1Axis<n2Axis);
00793 MPOL_T pf,p[1];
00794
00795
00796
00797 face(pf.rep(), c.m_F[0].rep(),n1Axis,n1Face);
00798 face(p[0].rep(), pf.rep(),n2Axis-1,n2Face);
00799
00800
00801
00802 MSLV slv(p, p+1, 1e-4);
00803
00804 std::vector<coeff_t> sol;
00805 std::list<MPOL_T> eqnList; eqnList.push_back(p[0]);
00806 int nSol, nVar;
00807 slv.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
00808 assert(nVar==1);
00809
00810 point_t pt(3u);
00811 for(unsigned j=0;j<sol.size();j++)
00812 {
00813 for(unsigned i=0;i<3;i++)
00814 {
00815 if(i==n1Axis)
00816 switch(i)
00817 {
00818 case 0:
00819 pt[0]=(n1Face?c.m_cBox.x1:c.m_cBox.x0);
00820 case 1:
00821 pt[1]=(n1Face?c.m_cBox.y1:c.m_cBox.y0);
00822 case 2:
00823 pt[2]=(n1Face?c.m_cBox.z1:c.m_cBox.z0);
00824 }
00825 else if(i==n2Axis)
00826 switch(i)
00827 {
00828 case 0:
00829 pt[0]=(n2Face?c.m_cBox.x1:c.m_cBox.x0);
00830 case 1:
00831 pt[1]=(n2Face?c.m_cBox.y1:c.m_cBox.y0);
00832 case 2:
00833 pt[2]=(n2Face?c.m_cBox.z1:c.m_cBox.z0);
00834 }
00835 else
00836 switch(i)
00837 {
00838 case 0:
00839 pt[0]=c.m_cBox.x0*((coeff_t)1-sol[j]) + c.m_cBox.x1*sol[j];
00840 case 1:
00841 pt[1]=c.m_cBox.y0*((coeff_t)1-sol[j]) + c.m_cBox.y1*sol[j];
00842 case 2:
00843 pt[2]=c.m_cBox.z0*((coeff_t)1-sol[j]) + c.m_cBox.z1*sol[j];
00844 }
00845 }
00846 int nMulti = 1;
00847 C val;
00848 unsigned sz=p[0].rep().size()-1;
00849 if(sz>1)
00850 {
00851 C dp[sz];
00852 for(unsigned u=0;u<sz;u++) dp[u]=p[0][u+1]-p[0][u];
00853 mpoldse::decasteljau(dp,sz,sol[j]);
00854 if(_is_singular(dp[0]))
00855 {
00856
00857 PRINT_DEBUG("Multiple point: "<<pt<<" "<<dp[0]<<
00858 " ["<<c.m_cBox.x0<<" "<<c.m_cBox.x1<<" "<<c.m_cBox.y0<<" "<<c.m_cBox.y1<<" "<<c.m_cBox.z0<<" "<<c.m_cBox.z1<<"]");
00859
00860 nMulti=2;
00861 }
00862 }
00863 intersection_t *ni = new intersection_t(pt, n1Axis , nMulti);
00864 inters.push_back(ni);
00865 ni->nDepth = c.m_nDepth;
00866
00867 }
00868
00869
00870 }
00871
00872 template < class C, class CELL, class MSLV >
00873 void TopSbdSurf3d<C, CELL, MSLV>::computeinter_edge(intersectionlist_t& inters,
00874 CELL& c,
00875 OCTREE::EDGE_TYPE edge)
00876 {
00877 using namespace OCTREE;
00878 switch(edge)
00879 {
00880 case B_W:
00881 computeinter_face(inters,c,0,0,1,0);
00882 break;
00883 case B_E:
00884 computeinter_face(inters,c,0,0,1,1);
00885 break;
00886 case B_S:
00887 computeinter_face(inters,c,0,0,2,0);
00888 break;
00889 case B_N:
00890 computeinter_face(inters,c,0,0,2,1);
00891 break;
00892 case F_W:
00893 computeinter_face(inters,c,0,1,1,0);
00894 break;
00895 case F_E:
00896 computeinter_face(inters,c,0,1,1,1);
00897 break;
00898 case F_S:
00899 computeinter_face(inters,c,0,1,2,0);
00900 break;
00901 case F_N:
00902 computeinter_face(inters,c,0,1,2,1);
00903 break;
00904 case S_W:
00905 computeinter_face(inters,c,1,0,2,0);
00906 break;
00907 case N_W:
00908 computeinter_face(inters,c,1,0,2,1);
00909 break;
00910 case S_E:
00911 computeinter_face(inters,c,1,1,2,0);
00912 break;
00913 case N_E:
00914 computeinter_face(inters,c,1,1,2,1);
00915 break;
00916 }
00917 }
00918
00919 template < class C, class CELL, class MSLV >
00920 void TopSbdSurf3d<C, CELL, MSLV>::computeinter_edges(intersectionlist_t& inters,
00921 CELL& c)
00922 {
00923
00924
00925
00926
00927
00928
00929
00930 using namespace OCTREE;
00931 for(unsigned i=0;i<12;i++)
00932 computeinter_edge(inters,c,(EDGE_TYPE)i);
00933 }
00934
00935 template < class POINT, class CELL>
00936 unsigned Computeinter_edges(VectDse<Seq<POINT> >& inters,
00937 const CELL& c)
00938 {
00939
00940 typedef typename CELL::coeff_t coeff_t;
00941 typedef typename CELL::MPOL_T MPOL_T;
00942 typedef POINT point_t;
00943
00944 unsigned nbpt=0;
00945 MPOL_T lp[3],px0,px1,pz0,pz1;
00946 int nSol, nVar;
00947 point_t pt(3u);
00948
00949 PRINT_DEBUG("================================");
00950
00951 face(px0.rep(), c.m_F[0].rep(),0,0);
00952 face(px1.rep(), c.m_F[0].rep(),0,1);
00953
00954
00955 face(lp[2].rep(), px0.rep(),0,0);
00956
00957
00958
00959 SbdSolver<coeff_t,SBDSLV_RDL> slv2(lp+2, lp+3, 1e-4);
00960 std::vector<coeff_t> sol;
00961 std::list<MPOL_T> eqnList; eqnList.push_back(lp[2]);
00962 slv2.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
00963
00964 assert(nVar==1);
00965
00966
00967 pt[0]=c.m_cBox.x0;
00968 pt[1]=c.m_cBox.y0;
00969 for(unsigned j=0;j<sol.size();j++)
00970 {
00971 pt[2]= c.m_cBox.z0*((coeff_t)1-sol[j]) + c.m_cBox.z1*sol[j];
00972 inters[0].push_back(pt);
00973
00974
00975 nbpt++;
00976 }
00977
00978 face(lp[2].rep(), px0.rep(),0,1);
00979
00980
00981 (*eqnList.begin())=lp[2];
00982 slv2.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
00983
00984 pt[1]=c.m_cBox.y1;
00985 for(unsigned j=0;j<sol.size();j++)
00986 {
00987 pt[2]= c.m_cBox.z0*((coeff_t)1-sol[j]) + c.m_cBox.z1*sol[j];
00988 inters[1].push_back(pt);
00989
00990
00991 nbpt++;
00992 }
00993
00994 face(lp[2].rep(), px1.rep(),0,0);
00995
00996
00997 (*eqnList.begin())=lp[2];
00998 slv2.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
00999
01000
01001 pt[0]=c.m_cBox.x1;
01002 pt[1]=c.m_cBox.y0;
01003 for(unsigned j=0;j<sol.size();j++)
01004 {
01005 pt[2]= c.m_cBox.z0*((coeff_t)1-sol[j]) + c.m_cBox.z1*sol[j];
01006 inters[2].push_back(pt);
01007
01008 nbpt++;
01009 }
01010
01011 face(lp[2].rep(), px1.rep(),0,1);
01012
01013
01014 (*eqnList.begin())=lp[2];
01015 slv2.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01016
01017 pt[1]=c.m_cBox.y1;
01018 for(unsigned j=0;j<sol.size();j++)
01019 {
01020 pt[2]= c.m_cBox.z0*((coeff_t)1-sol[j]) + c.m_cBox.z1*sol[j];
01021 inters[3].push_back(pt);
01022
01023
01024 nbpt++;
01025 }
01026
01027 face(lp[1].rep(), px0.rep(),1,0);
01028 SbdSolver<coeff_t,SBDSLV_RDL> slv1(lp+1, lp+2, 1e-4);
01029
01030
01031
01032 (*eqnList.begin())=lp[1];
01033 slv1.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01034
01035 pt[0]=c.m_cBox.x0;
01036 pt[2]=c.m_cBox.z0;
01037 for(unsigned j=0;j<sol.size();j++)
01038 {
01039 pt[1]= c.m_cBox.y0*((coeff_t)1-sol[j]) + c.m_cBox.y1*sol[j];
01040 inters[4].push_back(pt);
01041
01042
01043 nbpt++;
01044 }
01045
01046 face(lp[1].rep(), px0.rep(),1,1);
01047
01048
01049 (*eqnList.begin())=lp[1];
01050 slv1.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01051
01052 pt[0]=c.m_cBox.x0;
01053 pt[2]=c.m_cBox.z1;
01054 for(unsigned j=0;j<sol.size();j++)
01055 {
01056 pt[1]= c.m_cBox.y0*((coeff_t)1-sol[j]) + c.m_cBox.y1*sol[j];
01057 inters[5].push_back(pt);
01058
01059
01060 nbpt++;
01061 }
01062
01063 face(lp[1].rep(), px1.rep(),1,0);
01064
01065
01066 (*eqnList.begin())=lp[1];
01067 slv1.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01068
01069 pt[0]=c.m_cBox.x1;
01070 pt[2]=c.m_cBox.z0;
01071 for(unsigned j=0;j<sol.size();j++)
01072 {
01073 pt[1]= c.m_cBox.y0*((coeff_t)1-sol[j]) + c.m_cBox.y1*sol[j];
01074 inters[6].push_back(pt);
01075
01076
01077 nbpt++;
01078 }
01079
01080 face(lp[1].rep(), px1.rep(),1,1);
01081
01082
01083 (*eqnList.begin())=lp[1];
01084 slv1.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01085
01086 pt[0]=c.m_cBox.x1;
01087 pt[2]=c.m_cBox.z1;
01088 for(unsigned j=0;j<sol.size();j++)
01089 {
01090 pt[1]= c.m_cBox.y0*((coeff_t)1-sol[j]) + c.m_cBox.y1*sol[j];
01091 inters[7].push_back(pt);
01092
01093
01094 nbpt++;
01095 }
01096
01097 face(pz0.rep(), c.m_F[0].rep(),2,0);
01098 face(pz1.rep(), c.m_F[0].rep(),2,1);
01099
01100 face(lp[0].rep(), pz0.rep(),1,0);
01101 SbdSolver<coeff_t,SBDSLV_RDL> slv0(lp, lp+1, 1e-4);
01102
01103
01104
01105 (*eqnList.begin())=lp[0];
01106 slv0.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01107
01108 pt[1]=c.m_cBox.y0;
01109 pt[2]=c.m_cBox.z0;
01110 for(unsigned j=0;j<sol.size();j++)
01111 {
01112 pt[0]= c.m_cBox.x0*((coeff_t)1-sol[j]) + c.m_cBox.x1*sol[j];
01113 inters[8].push_back(pt);
01114
01115
01116 nbpt++;
01117 }
01118
01119 face(lp[0].rep(), pz0.rep(),1,1);
01120
01121
01122 (*eqnList.begin())=lp[0];
01123 slv0.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01124
01125 pt[1]=c.m_cBox.y1;
01126 pt[2]=c.m_cBox.z0;
01127 for(unsigned j=0;j<sol.size();j++)
01128 {
01129 pt[0]= c.m_cBox.x0*((coeff_t)1-sol[j]) + c.m_cBox.x1*sol[j];
01130 inters[9].push_back(pt);
01131
01132
01133 nbpt++;
01134 }
01135
01136 face(lp[0].rep(), pz1.rep(),1,0);
01137
01138
01139 (*eqnList.begin())=lp[0];
01140 slv0.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01141
01142 pt[1]=c.m_cBox.y0;
01143 pt[2]=c.m_cBox.z1;
01144 for(unsigned j=0;j<sol.size();j++)
01145 {
01146 pt[0]= c.m_cBox.x0*((coeff_t)1-sol[j]) + c.m_cBox.x1*sol[j];
01147 inters[10].push_back(pt);
01148
01149
01150 nbpt++;
01151 }
01152
01153 face(lp[0].rep(), pz1.rep(),1,1);
01154
01155
01156 (*eqnList.begin())=lp[0];
01157 slv0.solve(sol, nSol, nVar, eqnList.begin(), eqnList.end());
01158
01159 pt[1]=c.m_cBox.y1;
01160 pt[2]=c.m_cBox.z1;
01161 for(unsigned j=0;j<sol.size();j++)
01162 {
01163 pt[0]= c.m_cBox.x0*((coeff_t)1-sol[j]) + c.m_cBox.x1*sol[j];
01164 inters[11].push_back(pt);
01165
01166
01167 nbpt++;
01168 }
01169
01170 return nbpt;
01171
01172 }
01173
01174 template <class C, class CELL, class MSLV >
01175 void TopSbdSurf3d<C, CELL, MSLV>::compute_points(node_t* n)
01176 {
01177
01178
01179
01180 std::vector<node_t*> Nbg[6];
01181 n->getAllBackNeighbors(Nbg[OCTREE::B]);
01182 n->getAllFrontNeighbors(Nbg[OCTREE::F]);
01183 n->getAllSouthNeighbors(Nbg[OCTREE::S]);
01184 n->getAllNorthNeighbors(Nbg[OCTREE::N]);
01185 n->getAllEastNeighbors(Nbg[OCTREE::E]);
01186 n->getAllWestNeighbors(Nbg[OCTREE::W]);
01187 cell_t* c=n->GetCell();
01188
01189
01190 unsigned f;
01191 for(unsigned i=0;i<6;i++)
01192 {
01193 f=i+(i%2?-1:1);
01194
01195 c->m_FaceComputed[i]=false;
01196 for(unsigned j=0;j<Nbg[i].size();j++)
01197 {
01198 if(Nbg[i][j]->GetCell()->m_FaceComputed[f])
01199 {
01200
01201 c->mergelist(c->m_FaceLstPtIdx[i], Nbg[i][j]->GetCell()->m_FaceLstPtIdx[f]);
01202 c->m_FaceComputed[i]=true;
01203 }
01204 else
01205 {
01206
01207
01208 assert(Nbg[i].size()==1);
01209
01210
01211
01212
01213 }
01214 for(unsigned e=0;e<4;e++)
01215 if(is_edge_in_face(Nbg[i][j]->GetCell(),EdgesOfFace[f][e],c,i))
01216 c->mergelist(c->m_FaceLstPtIdx[i], Nbg[i][j]->GetCell()->m_EdgeLstPtIdx[EdgesOfFace[f][e]]);
01217 }
01218 if(!c->m_FaceComputed[i])
01219 {
01220
01221 if (c->m_nRegularIdx ==-1)
01222 {
01223 computeinter_face(c->m_FaceLstPtIdx[i],*c,i/2,i%2);
01224 PRINT_DEBUG("End of face comp.");
01225 }
01226 c->m_FaceComputed[i]=true;
01227 }
01228 }
01229 for(unsigned j=0;j<12;j++)
01230 computeinter_edge(c->m_EdgeLstPtIdx[j],*c,OCTREE::EDGE_TYPE(j));
01231
01232 }
01233
01234 template <class C, class CELL, class MSLV >
01235 template < class POINTGRAPH>
01236 void TopSbdSurf3d<C, CELL, MSLV>::build_mesh(POINTGRAPH& g, node_t* n)
01237 {
01238 typedef typename CELL::coeff_t coeff_t;
01239 typedef typename CELL::MPOL_T MPOL_T;
01240 typedef intersection3d<coeff_t> intersection_t;
01241 typedef topology::point<coeff_t> point_t;
01242 typedef shared_object<intersection_t*> intersection_ptr;
01243
01244 cell_t* c= n->GetCell();
01245
01246
01247 if (c->m_nRegularIdx == -2)
01248 regularity(*c);
01249
01250 if (c->m_nRegularIdx == -1)
01251 {
01252 build_box(g,c);
01253 }
01254 else
01255 {
01256 unsigned nbp=0;
01257 point_t m(3u);
01258 m[0]=0;m[1]=0;m[2]=0;
01259 for(unsigned i=0;i<6;i++)
01260 {
01261 nbp+=c->m_FaceLstPtIdx[i].size();
01262 for(unsigned j=0;j<c->m_FaceLstPtIdx[i].size();j++)
01263 {
01264 m[0]+=c->m_FaceLstPtIdx[i][j]->pnt[0];
01265 m[1]+=c->m_FaceLstPtIdx[i][j]->pnt[1];
01266 m[2]+=c->m_FaceLstPtIdx[i][j]->pnt[2];
01267 }
01268 }
01269 for(unsigned i=0;i<12;i++)
01270 {
01271 nbp+=c->m_EdgeLstPtIdx[i].size();
01272 for(unsigned j=0;j<c->m_EdgeLstPtIdx[i].size();j++)
01273 {
01274 m[0]+=c->m_EdgeLstPtIdx[i][j]->pnt[0];
01275 m[1]+=c->m_EdgeLstPtIdx[i][j]->pnt[1];
01276 m[2]+=c->m_EdgeLstPtIdx[i][j]->pnt[2];
01277 }
01278 }
01279 if(nbp)
01280 {
01281 m[0]/= nbp;
01282 m[1]/= nbp;
01283 m[2]/= nbp;
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297 std::vector<point_t> lf[6];
01298 unsigned nbp=0;
01299 for(unsigned i=0;i<6;i++)
01300 {
01301 for(unsigned j=0;j< c->m_FaceLstPtIdx[i].size();j++)
01302 lf[i].push_back(c->m_FaceLstPtIdx[i][j]->pnt);
01303 for(unsigned e=0;e<4;e++)
01304 for(unsigned j=0;j< c->m_EdgeLstPtIdx[EdgesOfFace[i][e]].size();j++)
01305 {
01306 lf[i].push_back(c->m_EdgeLstPtIdx[EdgesOfFace[i][e]][j]->pnt);
01307 if(c->m_EdgeLstPtIdx[EdgesOfFace[i][e]][j]->nMulti==2)
01308 lf[i].push_back(c->m_EdgeLstPtIdx[EdgesOfFace[i][e]][j]->pnt);
01309 }
01310 }
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324 compute_point_inside(m,c);
01325
01326
01327
01328
01329
01330
01331
01332 int i0, i1,
01333 im=g.push_back(m);
01334
01335
01336 for(unsigned i=0;i<6;i++)
01337 {
01338 if(lf[i].size()==2)
01339 {
01340 i0=g.push_back(lf[i][0]);
01341 i1=g.push_back(lf[i][1]);
01342 g.insert_face(im,i0,i1);
01343 g.insert(im,i0);
01344 g.insert(im,i1);
01345
01346
01347 }
01348 else if(lf[i].size()>0)
01349 {
01350 int reg= c->m_nRegularIdx %3;
01351 int rf =reg;
01352
01353 if((i/2)==reg)
01354 if(i%2)
01355 rf+=c->m_nRegularIdx/9;
01356 else
01357 rf+=(c->m_nRegularIdx/3)%3;
01358 else
01359 rf+=(i/2);
01360
01361
01362 switch(rf)
01363 {
01364 case 3:
01365
01366 sort(lf[i].begin(), lf[i].end(), XPT());
01367 break;
01368 case 2:
01369
01370 sort(lf[i].begin(), lf[i].end(), YPT());
01371 break;
01372 case 1:
01373
01374 sort(lf[i].begin(), lf[i].end(), ZPT());
01375 break;
01376 }
01377
01378
01379
01380 int j=0, f=i/2;
01381
01382 i0=g.push_back(lf[i][0]);
01383 g.insert(im,i0);
01384 while(j<lf[i].size()-1)
01385 {
01386 if(same_point(lf[i][j],lf[i][j+1]))
01387 j++;
01388 else
01389 {
01390 i0=g.push_back(lf[i][j+1]);
01391 g.insert(im,i0);
01392 g.insert_face(im,i0-1,i0);
01393 if(is_on_border(lf[i][j+1],c,f))
01394 {
01395 j+=2;
01396 if(j<lf[i].size()) i0=g.push_back(lf[i][j]);
01397 g.insert(im,i0);
01398 }
01399 else
01400 j++;
01401 }
01402 }
01403 }
01404 }
01405 }
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441 }
01442 }
01443
01444 template<class C, class MP>
01445 bool is_edge_in_face(Cell3d<C,MP>* c0, unsigned e, Cell3d<C,MP>* c, unsigned f)
01446 {
01447 typedef topology::point<C> point_t;
01448 using namespace OCTREE;
01449 point_t m(3u);
01450 switch(OCTREE::EDGE_TYPE(e))
01451 {
01452 case B_E:
01453 m[0]= c0->m_cBox.x0; m[1]= c0->m_cBox.y1; m[2]= (c0->m_cBox.z0 + c0->m_cBox.z1)/2; break;
01454 case B_W:
01455 m[0]= c0->m_cBox.x0; m[1]= c0->m_cBox.y0; m[2]= (c0->m_cBox.z0 + c0->m_cBox.z1)/2; break;
01456 case B_S:
01457 m[0]= c0->m_cBox.x0; m[1]= (c0->m_cBox.y0 + c0->m_cBox.y1)/2; m[2]= c0->m_cBox.z0; break;
01458 case B_N:
01459 m[0]= c0->m_cBox.x0; m[1]= (c0->m_cBox.y0 + c0->m_cBox.y1)/2; m[2]= c0->m_cBox.z1; break;
01460
01461 case F_E:
01462 m[0]= c0->m_cBox.x1; m[1]= c0->m_cBox.y1; m[2]= (c0->m_cBox.z0 + c0->m_cBox.z1)/2; break;
01463 case F_W:
01464 m[0]= c0->m_cBox.x1; m[1]= c0->m_cBox.y0; m[2]= (c0->m_cBox.z0 + c0->m_cBox.z1)/2; break;
01465 case F_S:
01466 m[0]= c0->m_cBox.x1; m[1]= (c0->m_cBox.y0 + c0->m_cBox.y1)/2; m[2]= c0->m_cBox.z0; break;
01467 case F_N:
01468 m[0]= c0->m_cBox.x1; m[1]= (c0->m_cBox.y0 + c0->m_cBox.y1)/2; m[2]= c0->m_cBox.z1; break;
01469
01470 case S_E:
01471 m[0]= (c0->m_cBox.x0 + c0->m_cBox.x1)/2; m[1]= c0->m_cBox.y1; m[2]= c0->m_cBox.z0; break;
01472 case S_W:
01473 m[0]= (c0->m_cBox.x0 + c0->m_cBox.x1)/2; m[1]= c0->m_cBox.y0; m[2]= c0->m_cBox.z0; break;
01474 case N_E:
01475 m[0]= (c0->m_cBox.x0 + c0->m_cBox.x1)/2; m[1]= c0->m_cBox.y1; m[2]= c0->m_cBox.z1; break;
01476 case N_W:
01477 m[0]= (c0->m_cBox.x0 + c0->m_cBox.x1)/2; m[1]= c0->m_cBox.y0; m[2]= c0->m_cBox.z1; break;
01478 }
01479 switch(f)
01480 {
01481 case 0:
01482 return (m[0]== c->m_cBox.x0 && m[1]>c->m_cBox.y0 && m[1]<c->m_cBox.y1 && m[2]>c->m_cBox.z0 && m[2]<c->m_cBox.z1);
01483 case 1:
01484 return (m[0]== c->m_cBox.x1 && m[1]>c->m_cBox.y0 && m[1]<c->m_cBox.y1 && m[2]>c->m_cBox.z0 && m[2]<c->m_cBox.z1);
01485 case 2:
01486 return (m[1]== c->m_cBox.y0 && m[0]>c->m_cBox.x0 && m[0]<c->m_cBox.x1 && m[2]>c->m_cBox.z0 && m[2]<c->m_cBox.z1);
01487 case 3:
01488 return (m[1]== c->m_cBox.y1 && m[0]>c->m_cBox.x0 && m[0]<c->m_cBox.x1 && m[2]>c->m_cBox.z0 && m[2]<c->m_cBox.z1);
01489 case 4:
01490 return (m[2]== c->m_cBox.z0 && m[0]>c->m_cBox.x0 && m[0]<c->m_cBox.x1 && m[1]>c->m_cBox.y0 && m[1]<c->m_cBox.y1);
01491 case 5:
01492 return (m[2]== c->m_cBox.z1 && m[0]>c->m_cBox.x0 && m[0]<c->m_cBox.x1 && m[1]>c->m_cBox.y0 && m[1]<c->m_cBox.y1);
01493 }
01494 return false;
01495 }
01496
01497
01498 template < class C >
01499 bool is_variety_in(Cell3d<C>& c)
01500 {
01501 return c.containsVariety(0);
01502 }
01503
01504 template <class C, class CELL, class MSLV >
01505 bool TopSbdSurf3d<C, CELL, MSLV>::regularity(CELL& c)
01506 {
01507 typedef typename CELL::MPOL_T mpol_t;
01508 if(c.m_nDepth<m_min_dp)
01509 return false;
01510 else if(c.m_nDepth>m_max_dp)
01511 {
01512 c.m_nRegularIdx=-1;
01513 return false;
01514 }
01515 mpol_t dp[3];
01516 mpol_t f0,f1,df0,df1;
01517 for (int i = 0; i < 3; i++)
01518 {
01519 diff(dp[i],c.m_F[0],VARIDX(c.m_F[0], i));
01520
01521 if(!has_sign_change(dp[i]))
01522 {
01523
01524 bool b0= true, b1=true;
01525 c.m_nRegularIdx = i;
01526 for(int j=0;j <3 && (b0 ||b1) ;j++)
01527 if(j!=i)
01528 {
01529 int v=j;
01530 if(j>i) v--;
01531 if(b0)
01532 {
01533 face(f0.rep(),c.m_F[0].rep(),i,0);
01534
01535 if(!has_sign_change(f0))
01536 {
01537 c.m_nRegularIdx += 3*j;
01538
01539 b0=false;
01540
01541 }
01542 else
01543 {
01544 diff(df0, f0, v);
01545 if(!has_sign_change(df0))
01546 {
01547 c.m_nRegularIdx += 3*j;
01548
01549 b0=false;
01550
01551 }
01552 }
01553 }
01554 if(b1)
01555 {
01556 face(f1.rep(),c.m_F[0].rep(),i,1);
01557
01558 if (!has_sign_change(f1))
01559 {
01560 c.m_nRegularIdx += 9*j;
01561 b1=false;
01562
01563 }
01564 else
01565 {
01566 diff(df1, f1, v);
01567 if (!has_sign_change(df1))
01568 {
01569 c.m_nRegularIdx += 9*j;
01570 b1=false;
01571
01572 }
01573 }
01574 }
01575 }
01576 if(!(b0 || b1))
01577 {
01578
01579
01580 return true;
01581 }
01582
01583
01584 }
01585 }
01586 c.m_nRegularIdx =-1;
01587
01588 return false;
01589
01590
01591
01592 for (unsigned i = c.m_nT; i < c.nbpol(); i++)
01593 {
01594 C* coeff = c.m_F[i].begin();
01595 C lastC = coeff[0];
01596 bool bSignChange = false;
01597
01598 for (int j = 1; j < c.m_F[i].rep().env.sz() && !bSignChange; j++)
01599 {
01600 C cirC = coeff[j];
01601 if (_is_singular(cirC))
01602 {
01603 continue;
01604 }
01605 else
01606 {
01607 if (lastC*cirC < 0)
01608 {
01609 bSignChange = true;
01610 lastC = cirC;
01611 break;
01612 }
01613
01614 lastC = cirC;
01615 }
01616 }
01617
01618 if (_is_singular(lastC))
01619 continue;
01620 else if (!bSignChange)
01621 {
01622 c.m_nRegularIdx = i;
01623 PRINT_DEBUG("REG "<< c.m_nRegularIdx);
01624 return TRUE;
01625 }
01626 }
01627 c.m_nRegularIdx = -1;
01628 PRINT_DEBUG("reg "<< c.m_nRegularIdx);
01629 return FALSE;
01630 }
01631
01632 namespace topology
01633 {
01634 template<class C, class POINTGRAPH, class MPOL, class MTH>
01635 void assign(POINTGRAPH& g,
01636 const MPOL & p0,
01637 MTH mth,
01638 const C& x0, const C& x1,
01639 const C& y0, const C& y1,
01640 const C& z0, const C& z1)
01641 {
01642 typedef typename MTH::cell_t cell_t;
01643 typedef typename MTH::mpolb_t mpolb_t;
01644
01645 std::cout<<p0<<std::endl;
01646
01647
01648
01649 MPOL p1 = diff(p0,0u);
01650 MPOL p2 = diff(p0,1u);
01651
01652 MPOL d0 = diff(p1,1u)*diff(p2,2u)-diff(p1,2u)*diff(p2,1u);
01653 MPOL d1 = diff(p1,0u)*diff(p2,2u)-diff(p1,2u)*diff(p2,0u);
01654 MPOL d2 = diff(p1,0u)*diff(p2,1u)-diff(p1,1u)*diff(p2,0u);
01655 std::cout<<"Tangent field:"<<std::endl;
01656
01657 std::cout<<d0<<"\n"<<d1<<"\n"<<d2<<std::endl;
01658 mpolb_t p0dse;
01659
01660 toBernstein(p0, p0dse, x0,x1,y0,y1,z0,z1);
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726 cell_t* rc = new cell_t(p0dse,x0,x1,y0,y1,z0,z1);
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739 mth.run(g,rc);
01740 }
01741 }
01742 __END_NAMESPACE_SYNAPS
01743
01744 #endif //CELL3DCURVE_H