Creates user defined polyhedron. This function allows to the user to define arbitrary polyhedron. The faces of the polyhedron should be either triangles or planar quadrilateral. Nodes of a face are defined by indexes pointing to the elements in the xyz array. Numeration of the elements in the array starts from 1 (like in fortran). The indexes can be positive or negative. Negative sign means that the corresponding edge is invisible. The normal of the face should be directed to exterior of the polyhedron.
892{
893
894
895
897 {
904 }
905 else
906 {
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929 const G4int numSide =
935 double3* xyz;
936 typedef G4int int4[4];
937 int4* faces_vec;
939 {
940
941
942
943 std::vector<G4bool> chopped(
numCorner,
false);
944 std::vector<G4int*> triQuads;
947 while (remaining >= 3)
948 {
949
950
951 G4int A = -1, B = -1, C = -1;
952 G4int iStepper = iStarter;
953 do
954 {
955 if (A < 0) { A = iStepper; }
956 else if (B < 0) { B = iStepper; }
957 else if (C < 0) { C = iStepper; }
958 do
959 {
960 if (++iStepper >=
numCorner) { iStepper = 0; }
961 }
962 while (chopped[iStepper]);
963 }
964 while (C < 0 && iStepper != iStarter);
965
966
967
968
974 {
976 tq[0] = A + 1;
977 tq[1] = B + 1;
978 tq[2] = C + 1;
979 triQuads.push_back(tq);
980 chopped[B] = true;
981 --remaining;
982 }
983 else
984 {
985 do
986 {
987 if (++iStarter >=
numCorner) { iStarter = 0; }
988 }
989 while (chopped[iStarter]);
990 }
991 }
992
993
995 nFaces = numSide *
numCorner + 2 * triQuads.size();
996 faces_vec = new int4[nFaces];
1000 for (
G4int iEnd = 0; iEnd < 2; ++iEnd)
1001 {
1002 for (size_t i = 0; i < triQuads.size(); ++i)
1003 {
1004
1005
1007 if (iEnd == 0)
1008 {
1009 a = triQuads[i][0];
1010 b = triQuads[i][1];
1011 c = triQuads[i][2];
1012 }
1013 else
1014 {
1015 a = triQuads[i][0] + addition;
1016 b = triQuads[i][2] + addition;
1017 c = triQuads[i][1] + addition;
1018 }
1019 G4int ab = std::abs(b - a);
1020 G4int bc = std::abs(c - b);
1021 G4int ca = std::abs(a - c);
1022 faces_vec[iface][0] = (ab == 1 || ab == d)? a: -a;
1023 faces_vec[iface][1] = (bc == 1 || bc == d)? b: -b;
1024 faces_vec[iface][2] = (ca == 1 || ca == d)? c: -c;
1025 faces_vec[iface][3] = 0;
1026 ++iface;
1027 }
1028 }
1029
1030
1031
1032 xyz = new double3[nNodes];
1036 for (
G4int iSide = 0; iSide < numSide; ++iSide)
1037 {
1039 {
1040 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1041 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1043 if (iSide == 0)
1044 {
1046 {
1047 faces_vec[iface][0] = ixyz + 1;
1048 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1049 faces_vec[iface][2] = ixyz +
numCorner + 2;
1050 faces_vec[iface][3] = ixyz + 2;
1051 }
1052 else
1053 {
1054 faces_vec[iface][0] = ixyz + 1;
1055 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1056 faces_vec[iface][2] = ixyz + 2;
1057 faces_vec[iface][3] = ixyz -
numCorner + 2;
1058 }
1059 }
1060 else if (iSide == numSide - 1)
1061 {
1063 {
1064 faces_vec[iface][0] = ixyz + 1;
1065 faces_vec[iface][1] = ixyz +
numCorner + 1;
1066 faces_vec[iface][2] = ixyz +
numCorner + 2;
1067 faces_vec[iface][3] = -(ixyz + 2);
1068 }
1069 else
1070 {
1071 faces_vec[iface][0] = ixyz + 1;
1072 faces_vec[iface][1] = ixyz +
numCorner + 1;
1073 faces_vec[iface][2] = ixyz + 2;
1074 faces_vec[iface][3] = -(ixyz -
numCorner + 2);
1075 }
1076 }
1077 else
1078 {
1080 {
1081 faces_vec[iface][0] = ixyz + 1;
1082 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1083 faces_vec[iface][2] = ixyz +
numCorner + 2;
1084 faces_vec[iface][3] = -(ixyz + 2);
1085 }
1086 else
1087 {
1088 faces_vec[iface][0] = ixyz + 1;
1089 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1090 faces_vec[iface][2] = ixyz + 2;
1091 faces_vec[iface][3] = -(ixyz -
numCorner + 2);
1092 }
1093 }
1094 ++iface;
1095 ++ixyz;
1096 }
1097 phi += dPhi;
1098 }
1099
1100
1101
1103 {
1104 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1105 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1107 ++ixyz;
1108 }
1109 }
1110 else
1111 {
1114 xyz = new double3[nNodes];
1115 faces_vec = new int4[nFaces];
1118 G4int ixyz = 0, iface = 0;
1119 for (
G4int iSide = 0; iSide < numSide; ++iSide)
1120 {
1122 {
1123 xyz[ixyz][0] =
corners[iCorner].
r * std::cos(phi);
1124 xyz[ixyz][1] =
corners[iCorner].
r * std::sin(phi);
1126
1127 if (iSide < numSide - 1)
1128 {
1130 {
1131 faces_vec[iface][0] = ixyz + 1;
1132 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1133 faces_vec[iface][2] = ixyz +
numCorner + 2;
1134 faces_vec[iface][3] = -(ixyz + 2);
1135 }
1136 else
1137 {
1138 faces_vec[iface][0] = ixyz + 1;
1139 faces_vec[iface][1] = -(ixyz +
numCorner + 1);
1140 faces_vec[iface][2] = ixyz + 2;
1141 faces_vec[iface][3] = -(ixyz -
numCorner + 2);
1142 }
1143 }
1144 else
1145 {
1147 {
1148 faces_vec[iface][0] = ixyz + 1;
1149 faces_vec[iface][1] = -(ixyz +
numCorner - nFaces + 1);
1150 faces_vec[iface][2] = ixyz +
numCorner - nFaces + 2;
1151 faces_vec[iface][3] = -(ixyz + 2);
1152 }
1153 else
1154 {
1155 faces_vec[iface][0] = ixyz + 1;
1156 faces_vec[iface][1] = -(ixyz - nFaces +
numCorner + 1);
1157 faces_vec[iface][2] = ixyz - nFaces + 2;
1158 faces_vec[iface][3] = -(ixyz -
numCorner + 2);
1159 }
1160 }
1161 ++ixyz;
1162 ++iface;
1163 }
1164 phi += dPhi;
1165 }
1166 }
1169 delete [] faces_vec;
1170 delete [] xyz;
1171 if (problem)
1172 {
1173 std::ostringstream message;
1174 message <<
"Problem creating G4Polyhedron for: " <<
GetName();
1175 G4Exception(
"G4Polycone::CreatePolyhedron()",
"GeomSolids1002",
1177 delete polyhedron;
1178 return 0;
1179 }
1180 else
1181 {
1182 return polyhedron;
1183 }
1184 }
1185}
static G4int GetNumberOfRotationSteps()
G4int createPolyhedron(G4int Nnodes, G4int Nfaces, const G4double xyz[][3], const G4int faces[][4])