Changeset 1140 for trunk/source/graphics_reps/src
- Timestamp:
- Nov 3, 2009, 11:17:28 AM (16 years ago)
- Location:
- trunk/source/graphics_reps/src
- Files:
-
- 2 edited
-
BooleanProcessor.src (modified) (70 diffs)
-
HepPolyhedron.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/graphics_reps/src/BooleanProcessor.src
r830 r1140 9 9 ***********************************************************************/ 10 10 11 //G.Barrand : begin 12 #define BP_GEANT4 13 14 #ifdef BP_GEANT4 //G.Barrand 15 11 16 #include <CLHEP/Geometry/Plane3D.h> 12 13 using namespace HepGeom; 17 #include <CLHEP/Geometry/Plane3D.h> 18 typedef HepGeom::Plane3D<double> HVPlane3D; 19 typedef HepGeom::Point3D<double> HVPoint3D; 20 typedef HepGeom::Normal3D<double> HVNormal3D; 21 22 #else //BP_HEPVIS 23 24 #define ExtNode HEPVis_ExtNode 25 #define ExtEdge HEPVis_ExtEdge 26 #define ExtFace HEPVis_ExtFace 27 #define FaceList HEPVis_FaceList 28 #define ExtPolyhedron HEPVis_ExtPolyhedron 29 #define BooleanProcessor HEPVis_BooleanProcessor 30 31 #define HepPolyhedron SbPolyhedron 32 #define G4Facet SbFacet 33 34 #include <HEPVis/SbPlane.h> 35 typedef HEPVis::SbPlane HVPlane3D; 36 37 #endif 38 39 //using namespace HepGeom; 40 41 //#define BP_DEBUG 42 43 //G.Barrand : end 14 44 15 45 #define INITIAL_SIZE 200 16 #define CRAZY_POINT Point3D<double>(-10.e+6, -10.e+6, -10.e+6) 17 #define GRANULARITY 10.e+5; 46 #define CRAZY_POINT HVPoint3D(-10.e+6, -10.e+6, -10.e+6) 47 //#define GRANULARITY 10.e+5; 48 #define GRANULARITY 10.e+5 //G.Barrand : rm the trailing ; 18 49 19 50 #define SWAP(A,B) w = A; A = B; B = w … … 36 67 37 68 // -------------------------------------------- Simplified STL vector --- 69 //G.Barrand : begin 70 #include <vector> 71 using namespace std; 72 /* 38 73 template<class T> 39 74 class vector { … … 68 103 } 69 104 }; 105 */ 106 //G.Barrand : end 70 107 71 108 // ---------------------------------------------------- Extended node --- 72 109 class ExtNode { 73 110 public: 74 Point3D<double>v;111 HVPoint3D v; 75 112 int s; 76 113 77 114 public: 78 ExtNode( Point3D<double> vertex=Point3D<double>(), int status=0)115 ExtNode(HVPoint3D vertex=HVPoint3D(), int status=0) 79 116 : v(vertex), s(status) {} 80 117 ~ExtNode() {} … … 126 163 // ---------------------------------------------------- Extended face --- 127 164 class ExtFace { 165 private: 166 std::vector<ExtEdge>& edges; //G.Barrand 128 167 public: 129 168 int iedges[4]; // indices of original edges 130 Plane3D<double>plane; // face plane169 HVPlane3D plane; // face plane 131 170 double rmin[3], rmax[3]; // bounding box 132 171 int iold; // head of the list of the original edges … … 136 175 137 176 public: 138 ExtFace(int iedge=0) : iold(iedge), inew(0), iprev(iprev), inext(0) {} 177 //G.Barrand : ExtFace(int iedge=0) : iold(iedge), inew(0), iprev(iprev), inext(0) {} 178 ExtFace(std::vector<ExtEdge>& a_edges,int iedge) 179 : edges(a_edges), iold(iedge), inew(0), iprev(0), inext(0) { 180 //G.Barrand : initialize arrays to quiet valgrind. 181 {for (int i=0; i<4; i++) { iedges[i] = 0; }} 182 {for (int i=0; i<3; i++) { rmin[i] = 0; rmax[i] = 0; }} 183 } 139 184 ~ExtFace() {} 140 185 141 186 ExtFace(const ExtFace & face) : 187 edges(face.edges), //G.Barrand 142 188 plane(face.plane), iold(face.iold), inew(face.inew), 143 189 iprev(face.iprev), inext(face.inext) … … 149 195 150 196 ExtFace & operator=(const ExtFace & face) { 197 //FIXME : edges(face.edges) ???? //G.Barrand 151 198 int i; 152 199 for (i=0; i<4; i++) { iedges[i] = face.iedges[i]; } … … 164 211 165 212 // ---------------------------------------------------- Global arrays --- 166 static vector<ExtNode> nodes; // vector of nodes 167 static vector<ExtEdge> edges; // vector of edges 168 static vector<ExtFace> faces; // vector of faces 213 //G.Barrand : MacIntel : crash with g++-4.0.1 with -O on some subtract. 214 // Anyway static of objects is proved to be not safe. 215 // We put the below vector as members of BooleanProcessor. 216 //GB static std::vector<ExtNode> nodes; // vector of nodes 217 //GB static std::vector<ExtEdge> edges; // vector of edges 218 //GB static std::vector<ExtFace> faces; // vector of faces 169 219 170 220 // ---------------------------------------------------- List of faces --- 171 221 class FaceList { 172 222 private: 223 std::vector<ExtFace>& faces; //G.Barrad : end 224 private: 173 225 int ihead; 174 226 int ilast; 175 227 176 228 public: 177 FaceList() : ihead(0), ilast(0) {} 229 //G.Barrand : FaceList() : ihead(0), ilast(0) {} 230 FaceList(std::vector<ExtFace>& a_faces) : faces(a_faces),ihead(0),ilast(0) {} 178 231 ~FaceList() {} 179 232 … … 183 236 void push_back(int i) { 184 237 if (ilast == 0) { ihead = i; } else { faces[ilast].inext = i; } 185 faces[i].iprev = ilast; 186 faces[i].inext = 0; 238 ExtFace& face = faces[i]; //G.Barrand : optimize. 239 face.iprev = ilast; 240 face.inext = 0; 187 241 ilast = i; 188 242 } 189 243 190 244 void remove(int i) { 245 ExtFace& face = faces[i]; //G.Barrand : optimize. 191 246 if (ihead == i) { 192 ihead = face s[i].inext;247 ihead = face.inext; 193 248 }else{ 194 faces[face s[i].iprev].inext = faces[i].inext;249 faces[face.iprev].inext = face.inext; 195 250 } 196 251 if (ilast == i) { 197 ilast = face s[i].iprev;252 ilast = face.iprev; 198 253 }else{ 199 faces[face s[i].inext].iprev = faces[i].iprev;200 } 201 face s[i].iprev = 0;202 face s[i].inext = 0;254 faces[face.inext].iprev = face.iprev; 255 } 256 face.iprev = 0; 257 face.inext = 0; 203 258 } 204 259 }; … … 215 270 // ----------------------------------------- Boolean processor class --- 216 271 class BooleanProcessor { 272 private: 273 static int ishift; //G.Barrand 274 std::vector<ExtNode> nodes; // vector of nodes //G.Barrand 275 std::vector<ExtEdge> edges; // vector of edges //G.Barrand 276 std::vector<ExtFace> faces; // vector of faces //G.Barrand 217 277 private: 218 278 int processor_error; // is set in case of error … … 264 324 265 325 public: 266 BooleanProcessor() {} 326 //G.Barrand : BooleanProcessor() {} 327 BooleanProcessor() //G.Barrand 328 :result_faces(faces) 329 ,suitable_faces(faces) 330 ,unsuitable_faces(faces) 331 ,unknown_faces(faces) 332 { 333 } 334 267 335 ~BooleanProcessor() {} 268 336 269 337 HepPolyhedron execute(int op, 270 338 const HepPolyhedron &a, 271 const HepPolyhedron &b); 339 const HepPolyhedron &b, 340 int& err); 272 341 273 342 void draw(); … … 278 347 void print_edge(int); 279 348 int get_processor_error() const {return processor_error;} 349 350 void dump(); //G.Barrand 351 static int get_shift(); //G.Barrand 352 static void set_shift(int); //G.Barrand 353 static int get_num_shift(); //G.Barrand 280 354 }; 281 355 … … 294 368 iEprev = 0; iEcur = iold; 295 369 while (iEcur > 0) { 296 edges[iEcur].invert(); 297 iEnext = edges[iEcur].inext; 298 edges[iEcur].inext = iEprev; 370 ExtEdge& edge = edges[iEcur]; //G.Barrand : optimize. 371 edge.invert(); 372 iEnext = edge.inext; 373 edge.inext = iEprev; 299 374 iEprev = iEcur; 300 375 iEcur = iEnext; … … 304 379 iEprev = 0; iEcur = inew; 305 380 while (iEcur > 0) { 306 edges[iEcur].invert(); 307 iEnext = edges[iEcur].inext; 308 edges[iEcur].inext = iEprev; 381 ExtEdge& edge = edges[iEcur]; //G.Barrand : optimize. 382 edge.invert(); 383 iEnext = edge.inext; 384 edge.inext = iEprev; 309 385 iEprev = iEcur; 310 386 iEcur = iEnext; … … 312 388 if (inew > 0) inew = iEprev; 313 389 314 plane = Plane3D<double>(-plane.a(), -plane.b(), -plane.c(), -plane.d()); 390 #ifdef BP_GEANT4 //G.Barrand 391 plane = HVPlane3D(-plane.a(), -plane.b(), -plane.c(), -plane.d()); 392 #else 393 plane = HVPlane3D(-plane.getNormal(), -plane.getDistanceFromOrigin()); 394 #endif 315 395 } 316 396 … … 336 416 // } 337 417 338 Point3D<double>ppp;418 HVPoint3D ppp; 339 419 for (i=1; i <= p.GetNoVertices(); i++) { 420 #ifdef BP_GEANT4 //G.Barrand 340 421 ppp = p.GetVertex(i); 341 422 ppp.setX(ppp.x()+dx); 342 423 ppp.setY(ppp.y()+dy); 343 424 ppp.setZ(ppp.z()+dz); 425 #else 426 ppp = p.GetVertexFast(i); 427 ppp += HVPoint3D(dx,dy,dz); 428 #endif 344 429 nodes.push_back(ExtNode(ppp)); 345 430 } … … 348 433 349 434 for (int iface=1; iface <= p.GetNoFacets(); iface++) { 350 faces.push_back(ExtFace(edges .size()));435 faces.push_back(ExtFace(edges,edges.size())); 351 436 352 437 // S E T F A C E N O D E S … … 354 439 p.GetFacet(iface, nnode, iNodes, iVis, iFaces); 355 440 for (i=0; i<nnode; i++) { 356 if (iNodes[i] < 1 || iNodes[i] > p.GetNoVertices()) processor_error = 1; 357 if (iFaces[i] < 1 || iFaces[i] > p.GetNoFacets()) processor_error = 1; 441 //if (iNodes[i] < 1 || iNodes[i] > p.GetNoVertices()) processor_error = 1; 442 //if (iFaces[i] < 1 || iFaces[i] > p.GetNoFacets()) processor_error = 1; 443 444 if (iNodes[i] < 1 || iNodes[i] > p.GetNoVertices()) { //G.Barrand 445 processor_error = 1; 446 #ifdef BP_DEBUG 447 std::cerr 448 << "BooleanProcessor::takePolyhedron : problem 1." 449 << std::endl; 450 #endif 451 } 452 if (iFaces[i] < 1 || iFaces[i] > p.GetNoFacets()) { //G.Barrand 453 processor_error = 1; 454 #ifdef BP_DEBUG 455 std::cerr 456 << "BooleanProcessor::takePolyhedron : problem 2." 457 << std::endl; 458 #endif 459 } 358 460 iNodes[i] += dnode; 359 461 iFaces[i] += dface; … … 374 476 // S E T F A C E M I N - M A X 375 477 478 ExtFace& face = faces.back(); //G.Barrand : optimize. 376 479 for (i=0; i<3; i++) { 377 face s.back().rmin[i] = nodes[iNodes[0]].v[i];378 face s.back().rmax[i] = nodes[iNodes[0]].v[i];480 face.rmin[i] = nodes[iNodes[0]].v[i]; 481 face.rmax[i] = nodes[iNodes[0]].v[i]; 379 482 } 380 483 for (i=1; i<nnode; i++) { 484 ExtNode& node = nodes[iNodes[i]]; //G.Barrand : optimize. 381 485 for (k=0; k<3; k++) { 382 if (face s.back().rmin[k] > nodes[iNodes[i]].v[k])383 face s.back().rmin[k] = nodes[iNodes[i]].v[k];384 if (face s.back().rmax[k] < nodes[iNodes[i]].v[k])385 face s.back().rmax[k] = nodes[iNodes[i]].v[k];486 if (face.rmin[k] > node.v[k]) 487 face.rmin[k] = node.v[k]; 488 if (face.rmax[k] < node.v[k]) 489 face.rmax[k] = node.v[k]; 386 490 } 387 491 } … … 389 493 // S E T F A C E P L A N E 390 494 391 Normal3D<double>n = (nodes[iNodes[2]].v-nodes[iNodes[0]].v).cross495 HVNormal3D n = (nodes[iNodes[2]].v-nodes[iNodes[0]].v).cross 392 496 (nodes[iNodes[3]].v-nodes[iNodes[1]].v); 393 Point3D<double>p(0,0,0);497 HVPoint3D p(0,0,0); 394 498 395 499 for (i=0; i<nnode; i++) { p += nodes[iNodes[i]].v; } 396 500 p *= (1./nnode); 397 faces.back().plane = Plane3D<double>(n.unit(), p); 501 //G.Barrand : faces.back().plane = HVPlane3D(n.unit(), p); 502 faces.back().plane = HVPlane3D(n, p); //G.Barrand 398 503 399 504 // S E T R E F E R E N C E T O T H E N E X T F A C E … … 431 536 iface = faces[ifaces1].inext; 432 537 while(iface > 0) { 538 ExtFace& face = faces[iface]; //G.Barrand 433 539 for (i=0; i<3; i++) { 434 if (rmin1[i] > face s[iface].rmin[i]) rmin1[i] = faces[iface].rmin[i];435 if (rmax1[i] < face s[iface].rmax[i]) rmax1[i] = faces[iface].rmax[i];436 } 437 iface = face s[iface].inext;540 if (rmin1[i] > face.rmin[i]) rmin1[i] = face.rmin[i]; 541 if (rmax1[i] < face.rmax[i]) rmax1[i] = face.rmax[i]; 542 } 543 iface = face.inext; 438 544 } 439 545 440 546 iface = faces[ifaces2].inext; 441 547 while(iface > 0) { 548 ExtFace& face = faces[iface]; //G.Barrand 442 549 for (i=0; i<3; i++) { 443 if (rmin2[i] > face s[iface].rmin[i]) rmin2[i] = faces[iface].rmin[i];444 if (rmax2[i] < face s[iface].rmax[i]) rmax2[i] = faces[iface].rmax[i];445 } 446 iface = face s[iface].inext;550 if (rmin2[i] > face.rmin[i]) rmin2[i] = face.rmin[i]; 551 if (rmax2[i] < face.rmax[i]) rmax2[i] = face.rmax[i]; 552 } 553 iface = face.inext; 447 554 } 448 555 … … 476 583 { 477 584 int i, outflag, iface = ifaces, *prev; 478 Point3D<double> mmbox[8] = { Point3D<double>(rmin[0],rmin[1],rmin[2]),479 Point3D<double>(rmax[0],rmin[1],rmin[2]),480 Point3D<double>(rmin[0],rmax[1],rmin[2]),481 Point3D<double>(rmax[0],rmax[1],rmin[2]),482 Point3D<double>(rmin[0],rmin[1],rmax[2]),483 Point3D<double>(rmax[0],rmin[1],rmax[2]),484 Point3D<double>(rmin[0],rmax[1],rmax[2]),485 Point3D<double>(rmax[0],rmax[1],rmax[2]) };585 HVPoint3D mmbox[8] = { HVPoint3D(rmin[0],rmin[1],rmin[2]), 586 HVPoint3D(rmax[0],rmin[1],rmin[2]), 587 HVPoint3D(rmin[0],rmax[1],rmin[2]), 588 HVPoint3D(rmax[0],rmax[1],rmin[2]), 589 HVPoint3D(rmin[0],rmin[1],rmax[2]), 590 HVPoint3D(rmax[0],rmin[1],rmax[2]), 591 HVPoint3D(rmin[0],rmax[1],rmax[2]), 592 HVPoint3D(rmax[0],rmax[1],rmax[2]) }; 486 593 prev = &ifaces; 487 594 while (iface > 0) { … … 490 597 491 598 outflag = 0; 599 ExtFace& face = faces[iface]; //G.Barrand : optimize. 492 600 for (i=0; i<3; i++) { 493 if (face s[iface].rmin[i] > rmax[i] + del) { outflag = 1; break; }494 if (face s[iface].rmax[i] < rmin[i] - del) { outflag = 1; break; }601 if (face.rmin[i] > rmax[i] + del) { outflag = 1; break; } 602 if (face.rmax[i] < rmin[i] - del) { outflag = 1; break; } 495 603 } 496 604 … … 501 609 double d; 502 610 for (i=0; i<8; i++) { 503 d = face s[iface].plane.distance(mmbox[i]);611 d = face.plane.distance(mmbox[i]); //G.Barrand : optimize 504 612 if (d > +del) npos++; 505 613 if (d < -del) nneg++; … … 511 619 512 620 if (outflag == 1) { 513 *prev = face s[iface].inext;514 face s[iface].inext = iout;621 *prev = face.inext; 622 face.inext = iout; 515 623 iout = iface; 516 624 }else{ 517 prev = &faces[iface].inext; 518 } 625 prev = &face.inext; 626 } 627 519 628 iface = *prev; 520 629 } … … 532 641 { 533 642 int iface = edge.iface1; 534 Plane3D<double>plane = faces[edge.iface2].plane;643 HVPlane3D plane = faces[edge.iface2].plane; 535 644 int i, nnode, npos = 0, nneg = 0, nzer = 0; 536 645 double dd[5]; … … 599 708 i1 = edges[iedge].i1; 600 709 i2 = edges[iedge].i2; 710 601 711 d1 = plane.distance(nodes[i1].v); 602 712 d2 = plane.distance(nodes[i2].v); … … 610 720 iedge = edges[iedge].inext; 611 721 } 612 if (ii[i] == nodes.size()) {722 if (ii[i] == (int)nodes.size()) { 613 723 dd = d2-d1; d1 = d1/dd; d2 = d2/dd; 614 724 nodes.push_back(ExtNode(d2*nodes[i1].v-d1*nodes[i2].v, iedge)); … … 795 905 { 796 906 processor_error = 1; 907 #ifdef BP_DEBUG 797 908 std::cout 798 909 << "BooleanProcessor::caseIE : unimplemented case" 799 910 << std::endl; 911 #endif 800 912 } 801 913 … … 811 923 { 812 924 processor_error = 1; 925 #ifdef BP_DEBUG 813 926 std::cout 814 927 << "BooleanProcessor::caseEE : unimplemented case" 815 928 << std::endl; 929 #endif 816 930 } 817 931 … … 831 945 // M I N - M A X 832 946 947 {const ExtFace& face_1 = faces[iface1]; //G.Barrand : optimize 948 const ExtFace& face_2 = faces[iface2]; 833 949 for (int i=0; i<3; i++) { 834 if (face s[iface1].rmin[i] > faces[iface2].rmax[i] + del) return;835 if (face s[iface1].rmax[i] < faces[iface2].rmin[i] - del) return;836 } 950 if (face_1.rmin[i] > face_2.rmax[i] + del) return; 951 if (face_1.rmax[i] < face_2.rmin[i] - del) return; 952 }} 837 953 838 954 // F A C E - 1 vs P L A N E - 2 … … 929 1045 *ilink = A; ilink = &edges[A].inext; *ilink = 0 930 1046 1047 ExtFace& face = faces[iface]; //G.Barrand : optimize. 931 1048 ilink = &ihead; 932 1049 for(;;) { 933 if (face s[iface].inew == 0) break;1050 if (face.inew == 0) break; 934 1051 935 1052 // S T A R T N E W C O N T O U R 936 1053 937 icur = face s[iface].inew;938 face s[iface].inew = edges[icur].inext;1054 icur = face.inew; 1055 face.inew = edges[icur].inext; 939 1056 INSERT_EDGE_TO_THE_LIST(icur); 940 1057 ifirst = edges[icur].i1; … … 943 1060 944 1061 for (;;) { 945 i = &faces[iface].inew; 1062 i = &face.inew; 1063 ExtEdge& edge_cur = edges[icur]; 946 1064 while(*i > 0) { 947 if (edges[*i].i1 == edges[icur].i2) break; 948 i = &edges[*i].inext; 1065 ExtEdge& edge_i = edges[*i]; 1066 if (edge_i.i1 == edge_cur.i2) break; 1067 i = &edge_i.inext; 949 1068 } 950 1069 if (*i == 0) { 951 i = &faces[iface].iold; 952 while(*i > 0) { 953 if (edges[*i].i1 == edges[icur].i2) ioldflag = 1; 954 if (edges[*i].i1 == edges[icur].i2) break; 955 i = &edges[*i].inext; 1070 i = &face.iold; 1071 while(*i > 0) { 1072 ExtEdge& edge_i = edges[*i]; 1073 if (edge_i.i1 == edge_cur.i2) { 1074 ioldflag = 1; 1075 break; 1076 } 1077 i = &edge_i.inext; 956 1078 } 957 1079 } … … 963 1085 }else{ 964 1086 processor_error = 1; 1087 #ifdef BP_DEBUG 965 1088 std::cerr 966 1089 << "BooleanProcessor::assembleFace(" << iface << ") : " 967 1090 << "could not find next edge of the contour" 968 1091 << std::endl; 969 faces[iface].inew = DEFECTIVE_FACE; 1092 #endif 1093 face.inew = DEFECTIVE_FACE; 970 1094 return; 971 1095 } … … 976 1100 977 1101 int iedge; 978 iedge = face s[iface].iold;1102 iedge = face.iold; 979 1103 if (what == 0 && ioldflag == 0 && iedge > 0) { 980 1104 for (;;) { … … 986 1110 } 987 1111 }else{ 988 if (edges[iedge].i2 == edges[face s[iface].iold].i1) {1112 if (edges[iedge].i2 == edges[face.iold].i1) { 989 1113 edges[iedge].inext = ihead; // set new face 990 1114 return; … … 999 1123 1000 1124 int iface2; 1001 iedge = face s[iface].iold;1125 iedge = face.iold; 1002 1126 while(iedge > 0) { 1003 1127 iface2 = edges[iedge].iface2; … … 1005 1129 iedge = edges[iedge].inext; 1006 1130 } 1007 face s[iface].iold = ihead; // set new face1131 face.iold = ihead; // set new face 1008 1132 } 1009 1133 … … 1186 1310 unsuitable_faces.remove(i); 1187 1311 } 1312 1313 //G.Barrand : begin 1314 /* From S.Ponce 1315 At last, there is a problem in the assemblePolyhedra method. At least, I 1316 think it is there. The problem deals with boolean operations on solids, 1317 when one of the two contains entirely the other one. It has no sense for 1318 intersection and union but still has sense for subtraction. In this 1319 case, faces from the inner solid are stored in the unknown_faces 1320 FaceList. And an error occurs in the execute method. This may be correct 1321 for intersection and union but in the case of subtraction, one should do 1322 that in assemblePolyhedra : 1323 */ 1324 // Unknown faces are actually suitable face !!! 1325 iface = unknown_faces.front(); 1326 while(iface > 0) { 1327 i = iface; 1328 faces[i].inew = ORIGINAL_FACE; 1329 iface = faces[i].inext; 1330 unknown_faces.remove(i); 1331 result_faces.push_back(i); 1332 } 1333 /* 1334 Otherwise, the inner hole that the second solid was building in the 1335 first one does not exist. I'm not very clear on what to do for unions 1336 and intersections. I think this kind of situation should be detected and 1337 one of the solid should simply be ignored. 1338 */ 1339 //G.Barrand : end 1188 1340 } 1189 1341 … … 1203 1355 a = y1 - y2; 1204 1356 b = x2 - x1; 1205 w = std::abs(a)+std::abs(b); 1357 //G.Barrand : w = std::abs(a)+std::abs(b); 1358 w = ::fabs(a)+::fabs(b); //G.Barrand 1206 1359 a /= w; 1207 1360 b /= w; … … 1268 1421 int icontour, iedge, k1, k2; 1269 1422 double x3, y3, x4, y4, a2, b2, c2, d1, d2; 1270 for(icontour=0; icontour< external_contours.size(); icontour++) {1423 for(icontour=0; icontour<(int)external_contours.size(); icontour++) { 1271 1424 iedge = external_contours[icontour]; 1272 1425 while(iedge > 0) { … … 1296 1449 // L O O P A L O N G E X T E R N A L C O N T O U R S 1297 1450 1298 for(icontour=0; icontour< internal_contours.size(); icontour++) {1451 for(icontour=0; icontour<(int)internal_contours.size(); icontour++) { 1299 1452 iedge = internal_contours[icontour]; 1300 1453 while(iedge > 0) { … … 1478 1631 // L O O P A L O N G C O N T O U R 1479 1632 1633 //std::cerr << "debug : contour : begin : =================" << std::endl; 1634 //dump();//debug 1635 1480 1636 int iedge1, iedge2, iedge3, istart = 0; 1481 1637 for (;;) { 1482 1638 iedge1 = edges[ipnext].inext; 1483 1639 iedge2 = edges[iedge1].inext; 1640 /* 1641 std::cerr << "debug :" 1642 << " ipnext " << ipnext 1643 << " iedge1 " << iedge1 1644 << " iedge2 " << iedge2 1645 << " : istart " << istart 1646 << std::endl; 1647 */ 1484 1648 if (istart == 0) { 1485 1649 istart = iedge1; … … 1490 1654 edges[iedge3].iface1 = faces.size(); 1491 1655 edges[iedge3].inext = 0; 1492 faces.push_back(ExtFace( ));1656 faces.push_back(ExtFace(edges,0)); //G.Barrand : ok ? 1493 1657 faces.back().iold = iedge1; 1494 1658 faces.back().inew = ORIGINAL_FACE; … … 1500 1664 }else if (istart == iedge1) { 1501 1665 processor_error = 1; 1666 #ifdef BP_DEBUG 1502 1667 std::cerr 1503 1668 << "BooleanProcessor::triangulateContour : " 1504 1669 << "could not generate a triangle (infinite loop)" 1505 1670 << std::endl; 1671 #endif 1506 1672 break; 1507 1673 } … … 1529 1695 edges[iedge2].inext = edges.size(); 1530 1696 edges.push_back(ExtEdge(i3, i1, iface2, -(edges.size()-1), -1)); 1531 faces.push_back(ExtFace( ));1697 faces.push_back(ExtFace(edges,0)); //G.Barrand : ok ? 1532 1698 faces.back().iold = iedge1; 1533 1699 faces.back().inew = ORIGINAL_FACE; … … 1562 1728 } 1563 1729 processor_error = 1; 1730 #ifdef BP_DEBUG 1564 1731 std::cerr 1565 1732 << "BooleanProcessor::modifyReference : could not find the edge, " 1566 1733 << "iface=" << iface << ", i1,i2=" << i1 << "," << i2 << ", iref=" << iref 1567 1734 << std::endl; 1735 #endif 1568 1736 } 1569 1737 … … 1582 1750 // S E T IX, IY, IZ 1583 1751 1584 Normal3D<double> normal = faces[iface].plane.normal(); 1752 #ifdef BP_GEANT4 //G.Barrand 1753 HVNormal3D normal = faces[iface].plane.normal(); 1754 #else 1755 const HVNormal3D& normal = faces[iface].plane.getNormal(); 1756 #endif 1585 1757 int ix, iy, iz = 0; 1586 if (std::abs(normal[1]) > std::abs(normal[iz])) iz = 1; 1587 if (std::abs(normal[2]) > std::abs(normal[iz])) iz = 2; 1758 //G.Barrand : if (std::abs(normal[1]) > std::abs(normal[iz])) iz = 1; 1759 //G.Barrand : if (std::abs(normal[2]) > std::abs(normal[iz])) iz = 2; 1760 if (::fabs(normal[1]) > ::fabs(normal[iz])) iz = 1; //G.Barrand 1761 if (::fabs(normal[2]) > ::fabs(normal[iz])) iz = 2; //G.Barrand 1588 1762 if (normal[iz] > 0) { 1589 1763 ix = (iz+1)%3; iy = (ix+1)%3; … … 1606 1780 i1 = edges[iedge].i1; 1607 1781 i2 = edges[iedge].i2; 1608 z += nodes[i1].v[ix]*nodes[i2].v[iy]-nodes[i2].v[ix]*nodes[i1].v[iy]; 1782 ExtNode& node_1 = nodes[i1]; 1783 ExtNode& node_2 = nodes[i2]; 1784 z += node_1.v[ix]*node_2.v[iy]-node_2.v[ix]*node_1.v[iy]; 1609 1785 if (ifirst != i2) { 1610 1786 iedge = edges[iedge].inext; … … 1617 1793 }else{ 1618 1794 processor_error = 1; 1795 #ifdef BP_DEBUG 1619 1796 std::cerr 1620 1797 << "BooleanProcessor::triangulateFace : too small contour" 1621 1798 << std::endl; 1799 #endif 1622 1800 } 1623 1801 icontour = edges[iedge].inext; … … 1627 1805 }else{ 1628 1806 processor_error = 1; 1807 #ifdef BP_DEBUG 1629 1808 std::cerr 1630 1809 << "BooleanProcessor::triangulateFace : broken contour" 1631 1810 << std::endl; 1811 #endif 1632 1812 icontour = 0; 1633 1813 break; … … 1639 1819 1640 1820 int kint, kext; 1641 for (kint=0; kint < internal_contours.size(); kint++) {1642 for (kext=0; kext < external_contours.size(); kext++) {1821 for (kint=0; kint < (int)internal_contours.size(); kint++) { 1822 for (kext=0; kext < (int)external_contours.size(); kext++) { 1643 1823 mergeContours(ix, iy, kext, kint); 1644 1824 if (internal_contours[kint] == 0) break; 1645 1825 } 1646 if (kext == external_contours.size()) {1826 if (kext == (int)external_contours.size()) { 1647 1827 processor_error = 1; 1828 #ifdef BP_DEBUG 1648 1829 std::cerr 1649 1830 << "BooleanProcessor::triangulateFace : " 1650 1831 << "could not merge internal contour " << kint 1651 1832 << std::endl; 1833 #endif 1652 1834 } 1653 1835 } … … 1656 1838 1657 1839 int nface = faces.size(); 1658 for (kext=0; kext < external_contours.size(); kext++) {1840 for (kext=0; kext < (int)external_contours.size(); kext++) { 1659 1841 triangulateContour(ix, iy, external_contours[kext]); 1842 #ifdef BP_DEBUG 1843 if(processor_error) { //G.Barrand 1844 std::cerr 1845 << "BooleanProcessor::triangulateFace : " 1846 << "triangulateContour failed." 1847 << std::endl; 1848 break; //G.Barrand : ok ? 1849 } 1850 #endif 1660 1851 } 1661 1852 faces[iface].inew = UNSUITABLE_FACE; … … 1663 1854 // M O D I F Y R E F E R E N C E S 1664 1855 1665 for (int ifa=nface; ifa< faces.size(); ifa++) {1856 for (int ifa=nface; ifa<(int)faces.size(); ifa++) { 1666 1857 iedge = faces[ifa].iold; 1667 1858 while (iedge > 0) { 1668 1859 if (edges[iedge].iface1 != ifa) { 1669 1860 processor_error = 1; 1861 #ifdef BP_DEBUG 1670 1862 std::cerr 1671 1863 << "BooleanProcessor::triangulateFace : wrong reference to itself, " 1672 1864 << "iface=" << ifa << ", iface1=" << edges[iedge].iface1 1673 1865 << std::endl; 1866 #endif 1674 1867 }else if (edges[iedge].iface2 > 0) { 1675 1868 modifyReference(edges[iedge].iface2, … … 1697 1890 // R E N U M E R A T E N O D E S A N D F A C E S 1698 1891 1699 for (i=1; i< nodes.size(); i++) nodes[i].s = 0;1700 1701 for (i=1; i< faces.size(); i++) {1892 for (i=1; i<(int)nodes.size(); i++) nodes[i].s = 0; 1893 1894 for (i=1; i<(int)faces.size(); i++) { 1702 1895 if (faces[i].inew == ORIGINAL_FACE) { 1703 1896 faces[i].inew = ++nface; … … 1712 1905 } 1713 1906 1714 for (i=1; i< nodes.size(); i++) {1907 for (i=1; i<(int)nodes.size(); i++) { 1715 1908 if (nodes[i].s == 1) nodes[i].s = ++nnode; 1716 1909 } … … 1724 1917 // S E T N O D E S 1725 1918 1726 for (i=1; i< nodes.size(); i++) {1919 for (i=1; i<(int)nodes.size(); i++) { 1727 1920 if (nodes[i].s != 0) polyhedron.pV[nodes[i].s] = nodes[i].v; 1728 1921 } … … 1731 1924 1732 1925 int k, v[4], f[4]; 1733 for (i=1; i< faces.size(); i++) {1926 for (i=1; i<(int)faces.size(); i++) { 1734 1927 if (faces[i].inew == 0) continue; 1735 1928 v[3] = f[3] = k = 0; … … 1755 1948 } 1756 1949 polyhedron.pF[faces[i].inew] = 1757 G4Facet(v[0],f[0], v[1],f[1], v[2],f[2], v[3],f[3]); 1950 G4Facet(v[0],f[0], v[1],f[1], v[2],f[2], v[3],f[3]); 1758 1951 } 1759 1952 return polyhedron; 1760 1953 } 1954 1955 int BooleanProcessor::ishift = 0; //G.Barrand 1956 int BooleanProcessor::get_shift() { return ishift;} //G.Barrand 1957 void BooleanProcessor::set_shift(int a_shift) { ishift = a_shift;} //G.Barrand 1958 #define NUM_SHIFT 8 1959 int BooleanProcessor::get_num_shift() { return NUM_SHIFT;} //G.Barrand 1761 1960 1762 1961 HepPolyhedron BooleanProcessor::execute(int op, 1763 1962 const HepPolyhedron & a, 1764 const HepPolyhedron & b) 1963 const HepPolyhedron & b, 1964 int& err) //G.Barrand 1765 1965 /*********************************************************************** 1766 1966 * * … … 1772 1972 ***********************************************************************/ 1773 1973 { 1774 static int ishift = 0; 1775 static double shift[8][3] = { 1974 //static int ishift = 0; //G.Barrand 1975 //static double shift[8][3] = { 1976 static double shift[NUM_SHIFT][3] = { //G.Barrand 1776 1977 { 31, 23, 17}, 1777 1978 { -31, -23, -17}, … … 1784 1985 }; 1785 1986 1987 /* 1988 std::cerr << "BooleanProcessor::execute : ++++++++++++++++++++++" 1989 << a.getName().getString() 1990 << b.getName().getString() 1991 << std::endl; 1992 */ 1993 1786 1994 // I N I T I A T E P R O C E S S O R 1787 1995 … … 1790 1998 nodes.clear(); nodes.push_back(CRAZY_POINT); 1791 1999 edges.clear(); edges.push_back(ExtEdge()); 1792 faces.clear(); faces.push_back(ExtFace( ));2000 faces.clear(); faces.push_back(ExtFace(edges,0)); //G.Barrand : ok ? 1793 2001 1794 2002 // T A K E P O L Y H E D R A … … 1801 2009 << "BooleanProcessor: corrapted input polyhedron" 1802 2010 << std::endl; 2011 err = processor_error; //G.Barrand 1803 2012 return HepPolyhedron(); 1804 2013 } 1805 2014 if (ifaces1 == ifaces2) { // a is empty 2015 err = processor_error; //G.Barrand 1806 2016 switch (operation) { 1807 2017 case OP_UNION: … … 1819 2029 } 1820 2030 } 1821 if (ifaces2 == faces.size()) { // b is empty 2031 if (ifaces2 == (int)faces.size()) { // b is empty 2032 err = processor_error; //G.Barrand 1822 2033 switch (operation) { 1823 2034 case OP_UNION: … … 1839 2050 // W O R K A R O U N D T O A V O I D I E A N D E E 1840 2051 2052 /* 2053 #define PROCESSOR_ERROR(a_what) \ 2054 std::cerr << "BooleanProcessor: boolean operation problem (" << a_what \ 2055 << "). Try again with other shifts."\ 2056 << std::endl; 2057 */ 2058 #define PROCESSOR_ERROR(a_what) 2059 2060 unsigned int try_count = 1; 2061 while(true) { //G.Barrand 2062 1841 2063 double ddxx = del*shift[ishift][0]; 1842 2064 double ddyy = del*shift[ishift][1]; 1843 2065 double ddzz = del*shift[ishift][2]; 1844 ishift++; if (ishift == 8) ishift = 0; 1845 2066 ishift++; if (ishift == get_num_shift()) ishift = 0; 2067 2068 processor_error = 0; //G.Barrand 1846 2069 operation = op; 1847 2070 nodes.clear(); nodes.push_back(CRAZY_POINT); 1848 2071 edges.clear(); edges.push_back(ExtEdge()); 1849 faces.clear(); faces.push_back(ExtFace( ));2072 faces.clear(); faces.push_back(ExtFace(edges,0)); //G.Barrand : ok ? 1850 2073 1851 2074 ifaces1 = faces.size(); takePolyhedron(a,0,0,0); 1852 2075 ifaces2 = faces.size(); takePolyhedron(b,ddxx,ddyy,ddzz); 2076 2077 if (processor_error) { PROCESSOR_ERROR(1) } //G.Barrand 1853 2078 1854 2079 del = findMinMax(); … … 1859 2084 selectOutsideFaces(ifaces1, iout1); 1860 2085 selectOutsideFaces(ifaces2, iout2); 2086 2087 if (processor_error) { PROCESSOR_ERROR(2) } //G.Barrand 1861 2088 1862 2089 // P R E S E L E C T N O I N T E R S E C T I O N F A C E S … … 1875 2102 } 1876 2103 1877 #define PROCESSOR_ERROR \ 1878 std::cerr << "BooleanProcessor: boolean operation failed" << std::endl;\ 1879 return a; 2104 if (processor_error) { PROCESSOR_ERROR(3) } //G.Barrand 1880 2105 1881 2106 // F I N D N E W E D G E S … … 1892 2117 } 1893 2118 } 1894 if (processor_error) { PROCESSOR_ERROR }2119 if (processor_error) { PROCESSOR_ERROR(4) } //G.Barrand 1895 2120 1896 2121 // C O N S T R U C T N E W F A C E S 1897 2122 1898 2123 assembleNewFaces((operation == OP_INTERSECTION) ? 1 : 0, ifaces1); 1899 if (processor_error) { PROCESSOR_ERROR }2124 if (processor_error) { PROCESSOR_ERROR(5) } //G.Barrand 1900 2125 assembleNewFaces((operation == OP_UNION) ? 0 : 1, ifaces2); 1901 if (processor_error) { PROCESSOR_ERROR }2126 if (processor_error) { PROCESSOR_ERROR(6) } //G.Barrand 1902 2127 1903 2128 // A S S E M B L E S U I T A B L E F A C E S … … 1908 2133 if (unknown_faces.front() != 0) { 1909 2134 processor_error = 1; 2135 #ifdef BP_DEBUG 1910 2136 std::cerr 1911 2137 << "BooleanProcessor::execute : unknown faces !!!" 1912 2138 << std::endl; 2139 #endif 1913 2140 } 1914 2141 break; 1915 2142 } 1916 if (processor_error) { PROCESSOR_ERROR }2143 if (processor_error) { PROCESSOR_ERROR(7) } //G.Barrand 1917 2144 1918 2145 // T R I A N G U L A T E A C C E P T E D F A C E S … … 1923 2150 ifa1 = faces[ifa2].inext; 1924 2151 if (faces[ifa2].inew == NEW_FACE) triangulateFace(ifa2); 1925 if (processor_error) { PROCESSOR_ERROR } 1926 } 2152 if (processor_error) { 2153 PROCESSOR_ERROR(8) //G.Barrand 2154 break; //G.Barrand 2155 } 2156 } 2157 2158 if(!processor_error) { 2159 #ifdef BP_DEBUG 2160 if(try_count!=1) { 2161 std::cerr 2162 << "BooleanProcessor::execute : had converged." 2163 << std::endl; 2164 } 2165 #endif 2166 break; 2167 } 2168 2169 if((int)try_count>get_num_shift()) { 2170 #ifdef BP_DEBUG 2171 std::cerr << "BooleanProcessor: " 2172 << " all shifts tried. Boolean operation (" << op << ") failure." 2173 << " a name \"" << a.getName().getString() << "\"" 2174 << " b name \"" << b.getName().getString() << "\"" 2175 << std::endl; 2176 #endif 2177 err = processor_error; 2178 return a; 2179 } 2180 2181 #ifdef BP_DEBUG 2182 std::cerr 2183 << "BooleanProcessor::execute : try another tilt..." 2184 << std::endl; 2185 #endif 2186 2187 try_count++; 2188 2189 } //G.Barrand : end while shift. 2190 #undef PROCESSOR_ERROR //G.Barrand 1927 2191 1928 2192 // C R E A T E P O L Y H E D R O N 1929 2193 2194 err = processor_error; 1930 2195 return createPolyhedron(); 1931 2196 } … … 2149 2414 } 2150 2415 */ 2416 2417 void BooleanProcessor::dump() {//G.Barrand 2418 unsigned int number = nodes.size(); 2419 std::cout << "nodes : " << number << endl; 2420 for(unsigned int index=0;index<number;index++) { 2421 const ExtNode& node = nodes[index]; 2422 std::cout << " " << index 2423 << " x = " << node.v[0] 2424 << " y = " << node.v[1] 2425 << " z = " << node.v[2] 2426 << std::endl; 2427 } 2428 } -
trunk/source/graphics_reps/src/HepPolyhedron.cc
r1058 r1140 25 25 // 26 26 // 27 // $Id: HepPolyhedron.cc,v 1.3 2 2008/11/13 09:05:27 gcosmoExp $28 // GEANT4 tag $Name: geant4-09-02-ref-02$27 // $Id: HepPolyhedron.cc,v 1.34 2009/10/28 13:36:32 allison Exp $ 28 // GEANT4 tag $Name: $ 29 29 // 30 30 // … … 2255 2255 2256 2256 #include "BooleanProcessor.src" 2257 static BooleanProcessor processor;2258 2257 2259 2258 HepPolyhedron HepPolyhedron::add(const HepPolyhedron & p) const … … 2267 2266 ***********************************************************************/ 2268 2267 { 2269 return processor.execute(OP_UNION, *this, p); 2268 int ierr; 2269 BooleanProcessor processor; 2270 return processor.execute(OP_UNION, *this, p,ierr); 2270 2271 } 2271 2272 … … 2280 2281 ***********************************************************************/ 2281 2282 { 2282 return processor.execute(OP_INTERSECTION, *this, p); 2283 int ierr; 2284 BooleanProcessor processor; 2285 return processor.execute(OP_INTERSECTION, *this, p,ierr); 2283 2286 } 2284 2287 … … 2293 2296 ***********************************************************************/ 2294 2297 { 2295 return processor.execute(OP_SUBTRACTION, *this, p); 2296 } 2297 2298 bool HepPolyhedron::IsErrorBooleanProcess() const { 2299 return processor.get_processor_error(); 2300 } 2298 int ierr; 2299 BooleanProcessor processor; 2300 return processor.execute(OP_SUBTRACTION, *this, p,ierr); 2301 } 2302 2303 //NOTE : include the code of HepPolyhedronProcessor here 2304 // since there is no BooleanProcessor.h 2305 2306 #undef INTERSECTION 2307 2308 #include "HepPolyhedronProcessor.src" 2309
Note:
See TracChangeset
for help on using the changeset viewer.
