File indexing completed on 2025-01-18 09:12:08
0001 import acts
0002 import argparse
0003 from acts import (
0004 logging,
0005 GeometryContext,
0006 CylindricalContainerBuilder,
0007 DetectorBuilder,
0008 GeometryIdGenerator,
0009 )
0010 from acts import geomodel as gm
0011 from acts import examples
0012
0013
0014 def main():
0015 p = argparse.ArgumentParser()
0016
0017 p.add_argument("-i", "--input", type=str, default="", help="Input SQL file")
0018
0019 p.add_argument(
0020 "-o", "--output", type=str, default="GeoModel", help="Output file(s) base name"
0021 )
0022
0023 p.add_argument(
0024 "-q",
0025 "--queries",
0026 type=str,
0027 nargs="+",
0028 default="GeoModelXML",
0029 help="List of Queries for Published full phys volumes",
0030 )
0031
0032 p.add_argument(
0033 "-n",
0034 "--name-list",
0035 type=str,
0036 nargs="+",
0037 default=[],
0038 help="List of Name List for the Surface Factory",
0039 )
0040
0041 p.add_argument(
0042 "-ml",
0043 "--material-list",
0044 type=str,
0045 nargs="+",
0046 default=[],
0047 help="List of Material List for the Surface Factory",
0048 )
0049
0050 p.add_argument(
0051 "--table-name",
0052 type=str,
0053 default="ActsBlueprint",
0054 help="Name of the blueprint table",
0055 )
0056
0057 p.add_argument(
0058 "-t",
0059 "--top-node",
0060 type=str,
0061 default="",
0062 help="Name of the top node in the blueprint tree",
0063 )
0064
0065 p.add_argument(
0066 "-b",
0067 "--top-node-bounds",
0068 type=str,
0069 default="",
0070 help="Table entry string overriding the top node bounds",
0071 )
0072
0073 p.add_argument(
0074 "-m", "--map", type=str, default="", help="Input file for the material map"
0075 )
0076
0077 p.add_argument(
0078 "--convert-subvols",
0079 help="Convert the children of the top level full phys vol",
0080 action="store_true",
0081 default=False,
0082 )
0083
0084 p.add_argument(
0085 "--convert-boundingboxes",
0086 help="Convert the fpvs to bounding boxes",
0087 type=str,
0088 nargs="+",
0089 default=[],
0090 )
0091
0092 p.add_argument(
0093 "--output-svg",
0094 help="Write the surfaces to SVG files",
0095 action="store_true",
0096 default=False,
0097 )
0098
0099 p.add_argument(
0100 "--output-internals-svg",
0101 help="Write the internal navigation to SVG files",
0102 action="store_true",
0103 default=False,
0104 )
0105
0106 p.add_argument(
0107 "--output-obj",
0108 help="Write the surfaces to OBJ files",
0109 action="store_true",
0110 default=False,
0111 )
0112
0113 p.add_argument(
0114 "--output-json",
0115 help="Write the surfaces to OBJ files",
0116 action="store_true",
0117 default=False,
0118 )
0119
0120 p.add_argument(
0121 "--enable-blueprint",
0122 help="Enable the usage of the blueprint",
0123 action="store_true",
0124 default=False,
0125 )
0126
0127 args = p.parse_args()
0128
0129 gContext = acts.GeometryContext()
0130 logLevel = logging.INFO
0131
0132 materialDecorator = None
0133 if args.map != "":
0134 print("Loading a material decorator from file:", args.map)
0135 materialDecorator = acts.IMaterialDecorator.fromFile(args.map)
0136
0137
0138 gmTree = acts.geomodel.readFromDb(args.input)
0139 gmFactoryConfig = gm.GeoModelDetectorObjectFactory.Config()
0140 gmFactoryConfig.materialList = args.material_list
0141 gmFactoryConfig.nameList = args.name_list
0142 gmFactoryConfig.convertBox = args.convert_boundingboxes
0143 gmFactoryConfig.convertSubVolumes = args.convert_subvols
0144 gmFactory = gm.GeoModelDetectorObjectFactory(gmFactoryConfig, logLevel)
0145
0146 gmFactoryOptions = gm.GeoModelDetectorObjectFactory.Options()
0147 gmFactoryOptions.queries = args.queries
0148
0149 gmFactoryCache = gm.GeoModelDetectorObjectFactory.Cache()
0150 gmFactory.construct(gmFactoryCache, gContext, gmTree, gmFactoryOptions)
0151
0152
0153
0154 if args.output_obj:
0155 segments = 720
0156 gmBoxes = gmFactoryCache.boundingBoxes
0157 gmBoxSurfaces = []
0158 for gmBox in gmBoxes:
0159 gmBoxSurfaces.extend(gmBox.surfaces())
0160 gmSurfaces = [ss[1] for ss in gmFactoryCache.sensitiveSurfaces]
0161 unboundSurfaces = [item for item in gmSurfaces if item not in gmBoxSurfaces]
0162
0163 acts.examples.writeVolumesSurfacesObj(
0164 unboundSurfaces,
0165 gmBoxes,
0166 gContext,
0167 [75, 220, 100],
0168 segments,
0169 args.output + "_vols.obj",
0170 )
0171
0172
0173 if "__main__" == __name__:
0174 main()