70using CLHEP::perMillion;
84 for (
G4int k=0; k<4; k++) {
85 ostr <<
" " << facet.edge[k].v <<
"/" << facet.edge[k].f;
92 ostr <<
"Nverteces=" << ph.
nvert <<
", Nfacets=" << ph.
nface << std::endl;
94 for (i=1; i<=ph.
nvert; i++) {
95 ostr <<
"xyz(" << i <<
")="
96 << ph.
pV[i].
x() <<
' ' << ph.
pV[i].
y() <<
' ' << ph.
pV[i].
z()
99 for (i=1; i<=ph.
nface; i++) {
100 ostr <<
"face(" << i <<
")=" << ph.
pF[i] << std::endl;
112: nvert(0), nface(0), pV(0), pF(0)
149 for (i=0; i<4; i++) {
150 if (iNode == std::abs(pF[iFace].edge[i].v))
break;
154 <<
"HepPolyhedron::FindNeighbour: face " << iFace
155 <<
" has no node " << iNode
161 if (pF[iFace].edge[i].v == 0) i = 2;
163 return (pF[iFace].edge[i].v > 0) ? 0 : pF[iFace].edge[i].f;
177 G4int k = iFace, iOrder = 1, n = 1;
180 k = FindNeighbour(k, iNode, iOrder);
181 if (k == iFace)
break;
184 normal += GetUnitNormal(k);
186 if (iOrder < 0)
break;
191 return normal.
unit();
217 const G4int nMin = 3;
220 <<
"HepPolyhedron::SetNumberOfRotationSteps: attempt to set the\n"
221 <<
"number of steps per circle < " << nMin <<
"; forced to " << nMin
256 if (
pV != 0)
delete []
pV;
257 if (
pF != 0)
delete []
pF;
258 if (Nvert > 0 && Nface > 0) {
278 enum {DUMMY, BOTTOM, LEFT, BACK, RIGHT, FRONT, TOP};
280 pF[1] =
G4Facet(1,LEFT, 4,BACK, 3,RIGHT, 2,FRONT);
281 pF[2] =
G4Facet(5,TOP, 8,BACK, 4,BOTTOM, 1,FRONT);
282 pF[3] =
G4Facet(8,TOP, 7,RIGHT, 3,BOTTOM, 4,LEFT);
283 pF[4] =
G4Facet(7,TOP, 6,FRONT, 2,BOTTOM, 3,BACK);
284 pF[5] =
G4Facet(6,TOP, 5,LEFT, 1,BOTTOM, 2,RIGHT);
285 pF[6] =
G4Facet(5,FRONT, 6,RIGHT, 7,BACK, 8,LEFT);
310 if (r1 == 0. && r2 == 0)
return;
315 G4int ii1 = ifWholeCircle ? i1 : i1+nds;
316 G4int ii2 = ifWholeCircle ? i2 : i2+nds;
317 G4int vv = ifWholeCircle ? vEdge : 1;
321 pF[kface++] =
G4Facet(i1,0, v2*i2,0, (i2+1),0);
322 }
else if (r2 == 0.) {
323 pF[kface++] =
G4Facet(i1,0, i2,0, v1*(i1+1),0);
325 pF[kface++] =
G4Facet(i1,0, v2*i2,0, (i2+1),0, v1*(i1+1),0);
329 pF[kface++] =
G4Facet(vv*i1,0, v2*i2,0, vEdge*(i2+1),0);
330 for (i2++,i=1; i<nds-1; i2++,i++) {
331 pF[kface++] =
G4Facet(vEdge*i1,0, v2*i2,0, vEdge*(i2+1),0);
333 pF[kface++] =
G4Facet(vEdge*i1,0, v2*i2,0, vv*ii2,0);
334 }
else if (r2 == 0.) {
335 pF[kface++] =
G4Facet(vv*i1,0, vEdge*i2,0, v1*(i1+1),0);
336 for (i1++,i=1; i<nds-1; i1++,i++) {
337 pF[kface++] =
G4Facet(vEdge*i1,0, vEdge*i2,0, v1*(i1+1),0);
339 pF[kface++] =
G4Facet(vEdge*i1,0, vv*i2,0, v1*ii1,0);
341 pF[kface++] =
G4Facet(vv*i1,0, v2*i2,0, vEdge*(i2+1),0,v1*(i1+1),0);
342 for (i1++,i2++,i=1; i<nds-1; i1++,i2++,i++) {
343 pF[kface++] =
G4Facet(vEdge*i1,0, v2*i2,0, vEdge*(i2+1),0,v1*(i1+1),0);
345 pF[kface++] =
G4Facet(vEdge*i1,0, v2*i2,0, vv*ii2,0, v1*ii1,0);
370 G4int k1, k2, k3, k4;
372 if (std::abs((
G4double)(dphi-pi)) < perMillion) {
373 for (
G4int i=0; i<4; i++) {
375 k2 = (i == 3) ? ii[0] : ii[i+1];
376 if (r[k1] == 0. && r[k2] == 0.) vv[i] = -1;
380 if (ii[1] == ii[2]) {
384 pF[kface++] =
G4Facet(vv[0]*k1,0, vv[2]*k2,0, vv[3]*k3,0);
385 if (r[ii[0]] != 0.) k1 += nds;
386 if (r[ii[2]] != 0.) k2 += nds;
387 if (r[ii[3]] != 0.) k3 += nds;
388 pF[kface++] =
G4Facet(vv[2]*k3,0, vv[0]*k2,0, vv[3]*k1,0);
389 }
else if (kk[ii[0]] == kk[ii[1]]) {
393 pF[kface++] =
G4Facet(vv[1]*k1,0, vv[2]*k2,0, vv[3]*k3,0);
394 if (r[ii[0]] != 0.) k1 += nds;
395 if (r[ii[2]] != 0.) k2 += nds;
396 if (r[ii[3]] != 0.) k3 += nds;
397 pF[kface++] =
G4Facet(vv[2]*k3,0, vv[1]*k2,0, vv[3]*k1,0);
398 }
else if (kk[ii[2]] == kk[ii[3]]) {
402 pF[kface++] =
G4Facet(vv[0]*k1,0, vv[1]*k2,0, vv[3]*k3,0);
403 if (r[ii[0]] != 0.) k1 += nds;
404 if (r[ii[1]] != 0.) k2 += nds;
405 if (r[ii[2]] != 0.) k3 += nds;
406 pF[kface++] =
G4Facet(vv[1]*k3,0, vv[0]*k2,0, vv[3]*k1,0);
412 pF[kface++] =
G4Facet(vv[0]*k1,0, vv[1]*k2,0, vv[2]*k3,0, vv[3]*k4,0);
413 if (r[ii[0]] != 0.) k1 += nds;
414 if (r[ii[1]] != 0.) k2 += nds;
415 if (r[ii[2]] != 0.) k3 += nds;
416 if (r[ii[3]] != 0.) k4 += nds;
417 pF[kface++] =
G4Facet(vv[2]*k4,0, vv[1]*k3,0, vv[0]*k2,0, vv[3]*k1,0);
447 static G4double wholeCircle = twopi;
451 G4bool ifWholeCircle = (std::abs(dphi-wholeCircle) < perMillion) ?
true :
false;
452 G4double delPhi = ifWholeCircle ? wholeCircle : dphi;
453 G4int nSphi = (nstep > 0) ?
455 if (nSphi == 0) nSphi = 1;
456 G4int nVphi = ifWholeCircle ? nSphi : nSphi+1;
457 G4bool ifClosed = np1 > 0 ? false :
true;
461 G4int absNp1 = std::abs(np1);
462 G4int absNp2 = std::abs(np2);
464 G4int i1end = absNp1-1;
465 G4int i2beg = absNp1;
466 G4int i2end = absNp1+absNp2-1;
469 for(i=i1beg; i<=i2end; i++) {
470 if (std::abs(r[i]) < perMillion) r[i] = 0.;
474 for (i=i1beg; i<=i1end; i++) {
475 j += (r[i] == 0.) ? 1 : nVphi;
481 if (r[i2beg] != r[i1beg] || z[i2beg] != z[i1beg]) {
482 j += (r[i2beg] == 0.) ? 1 : nVphi;
486 for(i=i2beg+1; i<i2end; i++) {
487 j += (r[i] == 0.) ? 1 : nVphi;
490 if (r[i2end] != r[i1end] || z[i2end] != z[i1end]) {
491 if (absNp2 > 1) j += (r[i2end] == 0.) ? 1 : nVphi;
497 k = ifClosed ? absNp1*nSphi : (absNp1-1)*nSphi;
500 for(i=i2beg; i<i2end; i++) {
501 if (r[i] > 0. || r[i+1] > 0.) k += nSphi;
505 if (r[i2end] > 0. || r[i2beg] > 0.) k += nSphi;
510 if (ifSide1 && (r[i1beg] > 0. || r[i2beg] > 0.)) k += nSphi;
511 if (ifSide2 && (r[i1end] > 0. || r[i2end] > 0.)) k += nSphi;
514 if (!ifWholeCircle) {
515 k += ifClosed ? 2*absNp1 : 2*(absNp1-1);
525 kk =
new G4int[absNp1+absNp2];
528 for(i=i1beg; i<=i1end; i++) {
531 {
pV[k++] =
G4Point3D(0, 0, z[i]); }
else { k += nVphi; }
538 {
pV[k++] =
G4Point3D(0, 0, z[i]); }
else { k += nVphi; }
543 for(i=i2beg+1; i<i2end; i++) {
546 {
pV[k++] =
G4Point3D(0, 0, z[i]); }
else { k += nVphi; }
561 for(j=0; j<nVphi; j++) {
562 cosPhi = std::cos(phi+j*delPhi/nSphi);
563 sinPhi = std::sin(phi+j*delPhi/nSphi);
564 for(i=i1beg; i<=i2end; i++) {
566 pV[kk[i]+j] =
G4Point3D(r[i]*cosPhi,r[i]*sinPhi,z[i]);
575 v2 = ifClosed ? nodeVis : 1;
576 for(i=i1beg; i<i1end; i++) {
578 if (!ifClosed && i == i1end-1) {
581 v2 = (r[i] == r[i+1] && r[i+1] == r[i+2]) ? -1 : nodeVis;
583 RotateEdge(kk[i], kk[i+1], r[i], r[i+1], v1, v2,
584 edgeVis, ifWholeCircle, nSphi, k);
587 RotateEdge(kk[i1end], kk[i1beg], r[i1end],r[i1beg], nodeVis, nodeVis,
588 edgeVis, ifWholeCircle, nSphi, k);
594 v2 = ifClosed ? nodeVis : 1;
595 for(i=i2beg; i<i2end; i++) {
597 if (!ifClosed && i==i2end-1) {
600 v2 = (r[i] == r[i+1] && r[i+1] == r[i+2]) ? -1 : nodeVis;
602 RotateEdge(kk[i+1], kk[i], r[i+1], r[i], v2, v1,
603 edgeVis, ifWholeCircle, nSphi, k);
606 RotateEdge(kk[i2beg], kk[i2end], r[i2beg], r[i2end], nodeVis, nodeVis,
607 edgeVis, ifWholeCircle, nSphi, k);
615 RotateEdge(kk[i2beg], kk[i1beg], r[i2beg], r[i1beg], 1, 1,
616 -1, ifWholeCircle, nSphi, k);
619 RotateEdge(kk[i1end], kk[i2end], r[i1end], r[i2end], 1, 1,
620 -1, ifWholeCircle, nSphi, k);
626 if (!ifWholeCircle) {
631 for (i=i1beg; i<=i1end; i++) {
633 ii[3] = (i == i1end) ? i1beg : i+1;
634 ii[1] = (absNp2 == 1) ? i2beg : ii[0]+absNp1;
635 ii[2] = (absNp2 == 1) ? i2beg : ii[3]+absNp1;
643 for (i=i1beg; i<i1end; i++) {
646 ii[1] = (absNp2 == 1) ? i2beg : ii[0]+absNp1;
647 ii[2] = (absNp2 == 1) ? i2beg : ii[3]+absNp1;
648 vv[0] = (i == i1beg) ? 1 : -1;
650 vv[2] = (i == i1end-1) ? 1 : -1;
661 <<
"Polyhedron::RotateAroundZ: number of generated faces ("
662 << k-1 <<
") is not equal to the number of allocated faces ("
678 if (
nface <= 0)
return;
680 struct edgeListMember {
681 edgeListMember *next;
685 } *edgeList, *freeList, **headList;
690 edgeList =
new edgeListMember[2*
nface];
691 headList =
new edgeListMember*[
nvert];
694 for (i=0; i<
nvert; i++) {
698 for (i=0; i<2*
nface-1; i++) {
699 edgeList[i].next = &edgeList[i+1];
701 edgeList[2*
nface-1].next = 0;
705 G4int iface, iedge, nedge, i1, i2, k1, k2;
706 edgeListMember *prev, *cur;
708 for(iface=1; iface<=
nface; iface++) {
709 nedge = (
pF[iface].edge[3].v == 0) ? 3 : 4;
710 for (iedge=0; iedge<nedge; iedge++) {
712 i2 = (iedge < nedge-1) ? iedge+1 : 0;
713 i1 = std::abs(
pF[iface].edge[i1].v);
714 i2 = std::abs(
pF[iface].edge[i2].v);
715 k1 = (i1 < i2) ? i1 : i2;
716 k2 = (i1 > i2) ? i1 : i2;
721 headList[k1] = freeList;
722 freeList = freeList->next;
732 headList[k1] = cur->next;
733 cur->next = freeList;
735 pF[iface].edge[iedge].f = cur->iface;
736 pF[cur->iface].edge[cur->iedge].f = iface;
737 i1 = (
pF[iface].edge[iedge].v < 0) ? -1 : 1;
738 i2 = (
pF[cur->iface].edge[cur->iedge].v < 0) ? -1 : 1;
741 <<
"Polyhedron::SetReferences: different edge visibility "
742 << iface <<
"/" << iedge <<
"/"
743 <<
pF[iface].edge[iedge].v <<
" and "
744 << cur->iface <<
"/" << cur->iedge <<
"/"
745 <<
pF[cur->iface].edge[cur->iedge].v
756 prev->next = freeList;
757 freeList = freeList->next;
767 prev->next = cur->next;
768 cur->next = freeList;
770 pF[iface].edge[iedge].f = cur->iface;
771 pF[cur->iface].edge[cur->iedge].f = iface;
772 i1 = (
pF[iface].edge[iedge].v < 0) ? -1 : 1;
773 i2 = (
pF[cur->iface].edge[cur->iedge].v < 0) ? -1 : 1;
776 <<
"Polyhedron::SetReferences: different edge visibility "
777 << iface <<
"/" << iedge <<
"/"
778 <<
pF[iface].edge[iedge].v <<
" and "
779 << cur->iface <<
"/" << cur->iedge <<
"/"
780 <<
pF[cur->iface].edge[cur->iedge].v
791 for (i=0; i<
nvert; i++) {
792 if (headList[i] != 0) {
794 <<
"Polyhedron::SetReferences: List " << i <<
" is not empty"
815 if (
nface <= 0)
return;
816 G4int i, k, nnode, v[4],f[4];
817 for (i=1; i<=
nface; i++) {
818 nnode = (
pF[i].edge[3].v == 0) ? 3 : 4;
819 for (k=0; k<nnode; k++) {
820 v[k] = (k+1 == nnode) ?
pF[i].edge[0].v :
pF[i].edge[k+1].v;
821 if (v[k] *
pF[i].edge[k].v < 0) v[k] = -v[k];
822 f[k] =
pF[i].edge[k].f;
824 for (k=0; k<nnode; k++) {
825 pF[i].edge[nnode-1-k].v = v[k];
826 pF[i].edge[nnode-1-k].f = f[k];
866 static G4int iFace = 1;
867 static G4int iQVertex = 0;
868 G4int vIndex = pF[iFace].edge[iQVertex].v;
870 edgeFlag = (vIndex > 0) ? 1 : 0;
871 index = std::abs(vIndex);
873 if (iQVertex >= 3 || pF[iFace].edge[iQVertex+1].v == 0) {
875 if (++iFace > nface) iFace = 1;
893 if (index <= 0 || index > nvert) {
895 <<
"HepPolyhedron::GetVertex: irrelevant index " << index
916 G4bool rep = GetNextVertexIndex(index, edgeFlag);
934 static G4int iFace = 1;
935 static G4int iNode = 0;
937 if (nface == 0)
return false;
939 G4int k = pF[iFace].edge[iNode].v;
940 if (k > 0) { edgeFlag = 1; }
else { edgeFlag = -1; k = -k; }
942 normal = FindNodeNormal(iFace,k);
943 if (iNode >= 3 || pF[iFace].edge[iNode+1].v == 0) {
945 if (++iFace > nface) iFace = 1;
966 static G4int iFace = 1;
967 static G4int iQVertex = 0;
968 static G4int iOrder = 1;
969 G4int k1, k2, kflag, kface1, kface2;
971 if (iFace == 1 && iQVertex == 0) {
972 k2 = pF[nface].edge[0].v;
973 k1 = pF[nface].edge[3].v;
974 if (k1 == 0) k1 = pF[nface].edge[2].v;
975 if (std::abs(k1) > std::abs(k2)) iOrder = -1;
979 k1 = pF[iFace].edge[iQVertex].v;
983 kface2 = pF[iFace].edge[iQVertex].f;
984 if (iQVertex >= 3 || pF[iFace].edge[iQVertex+1].v == 0) {
986 k2 = std::abs(pF[iFace].edge[iQVertex].v);
990 k2 = std::abs(pF[iFace].edge[iQVertex].v);
992 }
while (iOrder*k1 > iOrder*k2);
994 i1 = k1; i2 = k2; edgeFlag = (kflag > 0) ? 1 : 0;
995 iface1 = kface1; iface2 = kface2;
998 iFace = 1; iOrder = 1;
1017 G4int kface1, kface2;
1018 return GetNextEdgeIndeces(i1, i2, edgeFlag, kface1, kface2);
1024 G4int &edgeFlag)
const
1036 G4bool rep = GetNextEdgeIndeces(i1,i2,edgeFlag);
1057 G4bool rep = GetNextEdgeIndeces(i1,i2,edgeFlag,iface1,iface2);
1074 if (iFace < 1 || iFace > nface) {
1076 <<
"HepPolyhedron::GetFacet: irrelevant index " << iFace
1081 for (i=0; i<4; i++) {
1082 k = pF[iFace].edge[i].v;
1084 if (iFaces != 0) iFaces[i] = pF[iFace].edge[i].f;
1087 if (edgeFlags != 0) edgeFlags[i] = 1;
1090 if (edgeFlags != 0) edgeFlags[i] = -1;
1109 GetFacet(index, n, iNodes, edgeFlags);
1111 for (
G4int i=0; i<n; i++) {
1112 nodes[i] = pV[iNodes[i]];
1113 if (normals != 0) normals[i] = FindNodeNormal(index,iNodes[i]);
1131 static G4int iFace = 1;
1133 if (edgeFlags == 0) {
1134 GetFacet(iFace, n, nodes);
1135 }
else if (normals == 0) {
1136 GetFacet(iFace, n, nodes, edgeFlags);
1138 GetFacet(iFace, n, nodes, edgeFlags, normals);
1141 if (++iFace > nface) {
1159 if (iFace < 1 || iFace > nface) {
1161 <<
"HepPolyhedron::GetNormal: irrelevant index " << iFace
1166 G4int i0 = std::abs(pF[iFace].edge[0].v);
1167 G4int i1 = std::abs(pF[iFace].edge[1].v);
1168 G4int i2 = std::abs(pF[iFace].edge[2].v);
1169 G4int i3 = std::abs(pF[iFace].edge[3].v);
1170 if (i3 == 0) i3 = i0;
1171 return (pV[i2] - pV[i0]).cross(pV[i3] - pV[i1]);
1184 if (iFace < 1 || iFace > nface) {
1186 <<
"HepPolyhedron::GetUnitNormal: irrelevant index " << iFace
1191 G4int i0 = std::abs(pF[iFace].edge[0].v);
1192 G4int i1 = std::abs(pF[iFace].edge[1].v);
1193 G4int i2 = std::abs(pF[iFace].edge[2].v);
1194 G4int i3 = std::abs(pF[iFace].edge[3].v);
1195 if (i3 == 0) i3 = i0;
1196 return ((pV[i2] - pV[i0]).cross(pV[i3] - pV[i1])).unit();
1210 static G4int iFace = 1;
1211 normal = GetNormal(iFace);
1212 if (++iFace > nface) {
1231 G4bool rep = GetNextNormal(normal);
1232 normal = normal.unit();
1248 G4int i0 = std::abs(
pF[iFace].edge[0].v);
1249 G4int i1 = std::abs(
pF[iFace].edge[1].v);
1250 G4int i2 = std::abs(
pF[iFace].edge[2].v);
1251 G4int i3 = std::abs(
pF[iFace].edge[3].v);
1252 if (i3 == 0) i3 = i0;
1253 srf += ((
pV[i2] -
pV[i0]).cross(
pV[i3] -
pV[i1])).mag();
1270 G4int i0 = std::abs(
pF[iFace].edge[0].v);
1271 G4int i1 = std::abs(
pF[iFace].edge[1].v);
1272 G4int i2 = std::abs(
pF[iFace].edge[2].v);
1273 G4int i3 = std::abs(
pF[iFace].edge[3].v);
1277 pt = (
pV[i0]+
pV[i1]+
pV[i2]) * (1./3.);
1279 pt = (
pV[i0]+
pV[i1]+
pV[i2]+
pV[i3]) * 0.25;
1281 v += ((
pV[i2] -
pV[i0]).cross(
pV[i3] -
pV[i1])).dot(pt);
1321 enum {DUMMY, BOTTOM,
1322 LEFT_BOTTOM, LEFT_FRONT, LEFT_TOP, LEFT_BACK,
1323 BACK_BOTTOM, BACK_LEFT, BACK_TOP, BACK_RIGHT,
1324 RIGHT_BOTTOM, RIGHT_BACK, RIGHT_TOP, RIGHT_FRONT,
1325 FRONT_BOTTOM, FRONT_RIGHT, FRONT_TOP, FRONT_LEFT,
1328 pF[ 1]=
G4Facet(1,LEFT_BOTTOM, 4,BACK_BOTTOM, 3,RIGHT_BOTTOM, 2,FRONT_BOTTOM);
1330 pF[ 2]=
G4Facet(4,BOTTOM, -1,LEFT_FRONT, -12,LEFT_BACK, 0,0);
1331 pF[ 3]=
G4Facet(1,FRONT_LEFT, -5,LEFT_TOP, -12,LEFT_BOTTOM, 0,0);
1332 pF[ 4]=
G4Facet(5,TOP, -8,LEFT_BACK, -12,LEFT_FRONT, 0,0);
1333 pF[ 5]=
G4Facet(8,BACK_LEFT, -4,LEFT_BOTTOM, -12,LEFT_TOP, 0,0);
1335 pF[ 6]=
G4Facet(3,BOTTOM, -4,BACK_LEFT, -11,BACK_RIGHT, 0,0);
1336 pF[ 7]=
G4Facet(4,LEFT_BACK, -8,BACK_TOP, -11,BACK_BOTTOM, 0,0);
1337 pF[ 8]=
G4Facet(8,TOP, -7,BACK_RIGHT, -11,BACK_LEFT, 0,0);
1338 pF[ 9]=
G4Facet(7,RIGHT_BACK, -3,BACK_BOTTOM, -11,BACK_TOP, 0,0);
1340 pF[10]=
G4Facet(2,BOTTOM, -3,RIGHT_BACK, -10,RIGHT_FRONT, 0,0);
1341 pF[11]=
G4Facet(3,BACK_RIGHT, -7,RIGHT_TOP, -10,RIGHT_BOTTOM, 0,0);
1342 pF[12]=
G4Facet(7,TOP, -6,RIGHT_FRONT, -10,RIGHT_BACK, 0,0);
1343 pF[13]=
G4Facet(6,FRONT_RIGHT,-2,RIGHT_BOTTOM,-10,RIGHT_TOP, 0,0);
1345 pF[14]=
G4Facet(1,BOTTOM, -2,FRONT_RIGHT, -9,FRONT_LEFT, 0,0);
1346 pF[15]=
G4Facet(2,RIGHT_FRONT,-6,FRONT_TOP, -9,FRONT_BOTTOM, 0,0);
1347 pF[16]=
G4Facet(6,TOP, -5,FRONT_LEFT, -9,FRONT_RIGHT, 0,0);
1348 pF[17]=
G4Facet(5,LEFT_FRONT, -1,FRONT_BOTTOM, -9,FRONT_TOP, 0,0);
1350 pF[18]=
G4Facet(5,FRONT_TOP, 6,RIGHT_TOP, 7,BACK_TOP, 8,LEFT_TOP);
1358 const G4int faces[][4])
1374 if (
nvert == 0)
return 1;
1376 for (
G4int i=0; i<Nnodes; i++) {
1377 pV[i+1] =
G4Point3D(xyz[i][0], xyz[i][1], xyz[i][2]);
1379 for (
G4int k=0; k<Nfaces; k++) {
1380 pF[k+1] =
G4Facet(faces[k][0],0,faces[k][1],0,faces[k][2],0,faces[k][3],0);
1465 G4double DzTthetaCphi = Dz*std::tan(Theta)*std::cos(Phi);
1466 G4double DzTthetaSphi = Dz*std::tan(Theta)*std::sin(Phi);
1467 G4double Dy1Talp1 = Dy1*std::tan(Alp1);
1468 G4double Dy2Talp2 = Dy2*std::tan(Alp2);
1472 pV[1] =
G4Point3D(-DzTthetaCphi-Dy1Talp1-Dx1,-DzTthetaSphi-Dy1,-Dz);
1473 pV[2] =
G4Point3D(-DzTthetaCphi-Dy1Talp1+Dx1,-DzTthetaSphi-Dy1,-Dz);
1474 pV[3] =
G4Point3D(-DzTthetaCphi+Dy1Talp1+Dx2,-DzTthetaSphi+Dy1,-Dz);
1475 pV[4] =
G4Point3D(-DzTthetaCphi+Dy1Talp1-Dx2,-DzTthetaSphi+Dy1,-Dz);
1476 pV[5] =
G4Point3D( DzTthetaCphi-Dy2Talp2-Dx3, DzTthetaSphi-Dy2, Dz);
1477 pV[6] =
G4Point3D( DzTthetaCphi-Dy2Talp2+Dx3, DzTthetaSphi-Dy2, Dz);
1478 pV[7] =
G4Point3D( DzTthetaCphi+Dy2Talp2+Dx4, DzTthetaSphi+Dy2, Dz);
1479 pV[8] =
G4Point3D( DzTthetaCphi+Dy2Talp2-Dx4, DzTthetaSphi+Dy2, Dz);
1489 :
HepPolyhedronTrap(Dz, Theta, Phi, Dy, Dx, Dx,
Alpha, Dy, Dx, Dx,
Alpha) {}
1518 if (r1 < 0. || r2 <= 0.) k = 1;
1520 if (dz <= 0.) k += 2;
1526 phi2 = sPhi; phi1 = phi2 + dPhi;
1530 phi1 = sPhi; phi2 = phi1 + wholeCircle;
1534 phi1 = sPhi; phi2 = phi1 + dPhi;
1538 if (std::abs(dphi-wholeCircle) < perMillion) dphi = wholeCircle;
1539 if (dphi > wholeCircle) k += 4;
1542 std::cerr <<
"HepPolyhedronParaboloid: error in input parameters";
1543 if ((k & 1) != 0) std::cerr <<
" (radiuses)";
1544 if ((k & 2) != 0) std::cerr <<
" (half-length)";
1545 if ((k & 4) != 0) std::cerr <<
" (angles)";
1546 std::cerr << std::endl;
1547 std::cerr <<
" r1=" << r1;
1548 std::cerr <<
" r2=" << r2;
1549 std::cerr <<
" dz=" << dz <<
" sPhi=" << sPhi <<
" dPhi=" << dPhi
1558 G4double k1 = (r2*r2 - r1*r1) / 2 / dz;
1566 for(
G4int i = 1; i < n - 1; i++)
1568 rr[i] = rr[i-1] - dl;
1569 zz[i] = (rr[i]*rr[i] - k2) / k1;
1622 if (r2 < 0. || r1 < 0. ) k = 1;
1623 if (r1 > r2 ) k = 1;
1624 if (r1 == r2) k = 1;
1626 if (halfZ <= 0.) k += 2;
1628 if (sqrtan1<0.||sqrtan2<0.) k += 4;
1632 std::cerr <<
"HepPolyhedronHype: error in input parameters";
1633 if ((k & 1) != 0) std::cerr <<
" (radiuses)";
1634 if ((k & 2) != 0) std::cerr <<
" (half-length)";
1635 if ((k & 4) != 0) std::cerr <<
" (angles)";
1636 std::cerr << std::endl;
1637 std::cerr <<
" r1=" << r1 <<
" r2=" << r2;
1638 std::cerr <<
" halfZ=" << halfZ <<
" sqrTan1=" << sqrtan1
1639 <<
" sqrTan2=" << sqrtan2
1654 rr[0] = std::sqrt(sqrtan2*halfZ*halfZ+k2);
1656 for(
G4int i = 1; i < n-1; i++)
1658 zz[i] = zz[i-1] - dz;
1659 rr[i] =std::sqrt(sqrtan2*zz[i]*zz[i]+k2);
1666 rr[n] = std::sqrt(sqrtan1*halfZ*halfZ+k1);
1668 for(
G4int i = n+1; i < n+n; i++)
1670 zz[i] = zz[i-1] - dz;
1671 rr[i] =std::sqrt(sqrtan1*zz[i]*zz[i]+k1);
1714 if (Rmn1 < 0. || Rmx1 < 0. || Rmn2 < 0. || Rmx2 < 0.) k = 1;
1715 if (Rmn1 > Rmx1 || Rmn2 > Rmx2) k = 1;
1716 if (Rmn1 == Rmx1 && Rmn2 == Rmx2) k = 1;
1718 if (Dz <= 0.) k += 2;
1722 phi2 = Phi1; phi1 = phi2 - Dphi;
1723 }
else if (Dphi == 0.) {
1724 phi1 = Phi1; phi2 = phi1 + wholeCircle;
1726 phi1 = Phi1; phi2 = phi1 + Dphi;
1729 if (std::abs(dphi-wholeCircle) < perMillion) dphi = wholeCircle;
1730 if (dphi > wholeCircle) k += 4;
1733 std::cerr <<
"HepPolyhedronCone(s)/Tube(s): error in input parameters";
1734 if ((k & 1) != 0) std::cerr <<
" (radiuses)";
1735 if ((k & 2) != 0) std::cerr <<
" (half-length)";
1736 if ((k & 4) != 0) std::cerr <<
" (angles)";
1737 std::cerr << std::endl;
1738 std::cerr <<
" Rmn1=" << Rmn1 <<
" Rmx1=" << Rmx1;
1739 std::cerr <<
" Rmn2=" << Rmn2 <<
" Rmx2=" << Rmx2;
1740 std::cerr <<
" Dz=" << Dz <<
" Phi1=" << Phi1 <<
" Dphi=" << Dphi
1811 if (dphi <= 0. || dphi > twopi) {
1813 <<
"HepPolyhedronPgon/Pcon: wrong delta phi = " << dphi
1820 <<
"HepPolyhedronPgon/Pcon: number of z-planes less than two = " << nz
1827 <<
"HepPolyhedronPgon/Pcon: error in number of phi-steps =" << npdv
1833 for (i=0; i<nz; i++) {
1834 if (rmin[i] < 0. || rmax[i] < 0. || rmin[i] > rmax[i]) {
1836 <<
"HepPolyhedronPgon: error in radiuses rmin[" << i <<
"]="
1837 << rmin[i] <<
" rmax[" << i <<
"]=" << rmax[i]
1849 if (z[0] > z[nz-1]) {
1850 for (i=0; i<nz; i++) {
1857 for (i=0; i<nz; i++) {
1859 rr[i] = rmax[nz-i-1];
1860 zz[i+nz] = z[nz-i-1];
1861 rr[i+nz] = rmin[nz-i-1];
1867 RotateAroundZ(npdv, phi, dphi, nz, nz, zz, rr, -1, (npdv == 0) ? -1 : 1);
1905 if (dphi <= 0. || dphi > twopi) {
1907 <<
"HepPolyhedronSphere: wrong delta phi = " << dphi
1912 if (the < 0. || the > pi) {
1914 <<
"HepPolyhedronSphere: wrong theta = " << the
1919 if (dthe <= 0. || dthe > pi) {
1921 <<
"HepPolyhedronSphere: wrong delta theta = " << dthe
1926 if (the+dthe > pi) {
1928 <<
"HepPolyhedronSphere: wrong theta + delta theta = "
1929 << the <<
" " << dthe
1934 if (rmin < 0. || rmin >= rmax) {
1936 <<
"HepPolyhedronSphere: error in radiuses"
1937 <<
" rmin=" << rmin <<
" rmax=" << rmax
1946 if (np1 <= 1) np1 = 2;
1947 G4int np2 = rmin < perMillion ? 1 : np1;
1955 for (
G4int i=0; i<np1; i++) {
1956 cosa = std::cos(the+i*a);
1957 sina = std::sin(the+i*a);
1961 zz[i+np1] = rmin*cosa;
1962 rr[i+np1] = rmin*sina;
2003 if (dphi <= 0. || dphi > twopi) {
2005 <<
"HepPolyhedronTorus: wrong delta phi = " << dphi
2010 if (rmin < 0. || rmin >= rmax || rmax >= rtor) {
2012 <<
"HepPolyhedronTorus: error in radiuses"
2013 <<
" rmin=" << rmin <<
" rmax=" << rmax <<
" rtorus=" << rtor
2021 G4int np2 = rmin < perMillion ? 1 : np1;
2029 for (
G4int i=0; i<np1; i++) {
2030 cosa = std::cos(i*a);
2031 sina = std::sin(i*a);
2033 rr[i] = rtor+rmax*sina;
2035 zz[i+np1] = rmin*cosa;
2036 rr[i+np1] = rtor+rmin*sina;
2076 if (zCut1 >= cz || zCut2 <= -cz || zCut1 > zCut2) {
2077 std::cerr <<
"HepPolyhedronEllipsoid: wrong zCut1 = " << zCut1
2078 <<
" zCut2 = " << zCut2
2079 <<
" for given cz = " << cz << std::endl;
2083 std::cerr <<
"HepPolyhedronEllipsoid: bad z semi-axis: cz = " << cz
2098 sthe= std::acos(zCut2/cz);
2107 dthe= std::acos(zCut1/cz)-sthe;
2115 G4int np1 =
G4int(dthe*nds/pi) + 2 + cutflag;
2122 G4Exception(
"HepPolyhedronEllipsoid::HepPolyhedronEllipsoid",
2135 for (
G4int i=0; i<np1-cutflag; i++) {
2136 cosa = std::cos(sthe+i*a);
2137 sina = std::sin(sthe+i*a);
2150 std::cerr <<
"Logic error in HepPolyhedronEllipsoid, memory corrupted!"
2155 std::cerr <<
"Warning: logic error in HepPolyhedronEllipsoid."
2175 p->
setX( p->
x() * ax/cz );
2176 p->
setY( p->
y() * by/cz );
2203 if ( (ax <= 0.) || (ay <= 0.) || (h <= 0.) || (zTopCut <= 0.) ) { k = 1; }
2206 std::cerr <<
"HepPolyhedronCone: error in input parameters";
2207 std::cerr << std::endl;
2213 zTopCut = (h >= zTopCut ? zTopCut : h);
2222 rr[0] = (h-zTopCut);
2223 rr[1] = (h+zTopCut);
2239 p->
setX( p->
x() * ax );
2240 p->
setY( p->
y() * ay );
2257#include "BooleanProcessor.src"
2271 return processor.execute(OP_UNION, *
this, p,ierr);
2286 return processor.execute(OP_INTERSECTION, *
this, p,ierr);
2301 return processor.execute(OP_SUBTRACTION, *
this, p,ierr);
2309#include "HepPolyhedronProcessor.src"
HepGeom::Normal3D< G4double > G4Normal3D
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
std::ostream & operator<<(std::ostream &ostr, const G4Facet &facet)
#define DEFAULT_NUMBER_OF_STEPS
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
virtual ~HepPolyhedronBox()
HepPolyhedronBox(G4double Dx, G4double Dy, G4double Dz)
virtual ~HepPolyhedronCone()
HepPolyhedronCone(G4double Rmn1, G4double Rmx1, G4double Rmn2, G4double Rmx2, G4double Dz)
virtual ~HepPolyhedronCons()
HepPolyhedronCons(G4double Rmn1, G4double Rmx1, G4double Rmn2, G4double Rmx2, G4double Dz, G4double Phi1, G4double Dphi)
virtual ~HepPolyhedronEllipsoid()
HepPolyhedronEllipsoid(G4double dx, G4double dy, G4double dz, G4double zcut1, G4double zcut2)
virtual ~HepPolyhedronEllipticalCone()
HepPolyhedronEllipticalCone(G4double dx, G4double dy, G4double z, G4double zcut1)
HepPolyhedronHype(G4double r1, G4double r2, G4double tan1, G4double tan2, G4double halfZ)
virtual ~HepPolyhedronHype()
virtual ~HepPolyhedronPara()
HepPolyhedronPara(G4double Dx, G4double Dy, G4double Dz, G4double Alpha, G4double Theta, G4double Phi)
virtual ~HepPolyhedronParaboloid()
HepPolyhedronParaboloid(G4double r1, G4double r2, G4double dz, G4double Phi1, G4double Dphi)
virtual ~HepPolyhedronPcon()
HepPolyhedronPcon(G4double phi, G4double dphi, G4int nz, const G4double *z, const G4double *rmin, const G4double *rmax)
virtual ~HepPolyhedronPgon()
HepPolyhedronPgon(G4double phi, G4double dphi, G4int npdv, G4int nz, const G4double *z, const G4double *rmin, const G4double *rmax)
virtual ~HepPolyhedronSphere()
HepPolyhedronSphere(G4double rmin, G4double rmax, G4double phi, G4double dphi, G4double the, G4double dthe)
HepPolyhedronTorus(G4double rmin, G4double rmax, G4double rtor, G4double phi, G4double dphi)
virtual ~HepPolyhedronTorus()
HepPolyhedronTrap(G4double Dz, G4double Theta, G4double Phi, G4double Dy1, G4double Dx1, G4double Dx2, G4double Alp1, G4double Dy2, G4double Dx3, G4double Dx4, G4double Alp2)
virtual ~HepPolyhedronTrap()
HepPolyhedronTrd1(G4double Dx1, G4double Dx2, G4double Dy, G4double Dz)
virtual ~HepPolyhedronTrd1()
virtual ~HepPolyhedronTrd2()
HepPolyhedronTrd2(G4double Dx1, G4double Dx2, G4double Dy1, G4double Dy2, G4double Dz)
virtual ~HepPolyhedronTube()
HepPolyhedronTube(G4double Rmin, G4double Rmax, G4double Dz)
HepPolyhedronTubs(G4double Rmin, G4double Rmax, G4double Dz, G4double Phi1, G4double Dphi)
virtual ~HepPolyhedronTubs()
G4bool GetNextEdgeIndeces(G4int &i1, G4int &i2, G4int &edgeFlag, G4int &iface1, G4int &iface2) const
static void SetNumberOfRotationSteps(G4int n)
void RotateAroundZ(G4int nstep, G4double phi, G4double dphi, G4int np1, G4int np2, const G4double *z, G4double *r, G4int nodeVis, G4int edgeVis)
G4Normal3D GetUnitNormal(G4int iFace) const
void GetFacet(G4int iFace, G4int &n, G4int *iNodes, G4int *edgeFlags=0, G4int *iFaces=0) const
G4int createTwistedTrap(G4double Dz, const G4double xy1[][2], const G4double xy2[][2])
static G4int fNumberOfRotationSteps
G4bool GetNextNormal(G4Normal3D &normal) const
HepPolyhedron & operator=(const HepPolyhedron &from)
G4Normal3D FindNodeNormal(G4int iFace, G4int iNode) const
static G4int GetNumberOfRotationSteps()
G4Normal3D GetNormal(G4int iFace) const
G4int FindNeighbour(G4int iFace, G4int iNode, G4int iOrder) const
G4Point3D GetVertex(G4int index) const
G4double GetSurfaceArea() const
HepPolyhedron subtract(const HepPolyhedron &p) const
G4bool GetNextVertex(G4Point3D &vertex, G4int &edgeFlag) const
G4double GetVolume() const
HepPolyhedron intersect(const HepPolyhedron &p) const
HepPolyhedron & Transform(const G4Transform3D &t)
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])
void AllocateMemory(G4int Nvert, G4int Nface)
G4bool GetNextUnitNormal(G4Normal3D &normal) const
static void ResetNumberOfRotationSteps()
void RotateEdge(G4int k1, G4int k2, G4double r1, G4double r2, G4int v1, G4int v2, G4int vEdge, G4bool ifWholeCircle, G4int ns, G4int &kface)
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
G4bool GetNextVertexIndex(G4int &index, G4int &edgeFlag) const
HepPolyhedron add(const HepPolyhedron &p) const
G4bool GetNextEdge(G4Point3D &p1, G4Point3D &p2, G4int &edgeFlag) const
void SetSideFacets(G4int ii[4], G4int vv[4], G4int *kk, G4double *r, G4double dphi, G4int ns, G4int &kface)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)