GEOUNED-org / GEOUNED

A tool to convert CAD to CSG & CSG to CAD for Monte Carlo transport codes
European Union Public License 1.2
45 stars 27 forks source link

[BUG] - Issues when using simplify - "full" #203

Closed KBGrammer closed 3 weeks ago

KBGrammer commented 4 weeks ago

Describe the bug

Simplification fails when using the option "full" with the error below. It appers to be a missing second option for calls to get_box() and build_c_table_from_solids().

To Reproduce

  1. use option "simplify": "full"
  2. See errors

Expected behavior

Should process the simplification of the geometry, but it crashes with a number of errors.

Error message

This is the error for get_box:

Traceback (most recent call last):
  File "~/test_convert.py", line 233, in <module>
    test_cad_to_csg_from_json_with_defaults("config_complete_defaults.json")
  File "~/test_convert.py", line 134, in test_cad_to_csg_from_json_with_defaults
    my_cad_to_csg = geouned.CadToCsg.from_json(input_json_file)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 252, in from_json
    cad_to_csg.start()
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 642, in start
    Box = UF.get_box(c)
TypeError: get_box() missing 1 required positional argument: 'options'

This is the error for build_c_table_from_solids:

Traceback (most recent call last):
  File "~/test_convert.py", line 233, in <module>
    test_cad_to_csg_from_json_with_defaults("config_complete_defaults.json")
  File "~/test_convert.py", line 134, in test_cad_to_csg_from_json_with_defaults
    my_cad_to_csg = geouned.CadToCsg.from_json(input_json_file)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 252, in from_json
    cad_to_csg.start()
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 643, in start
    CT = build_c_table_from_solids(Box, (c.Surfaces, Surfs), option="full")
TypeError: build_c_table_from_solids() missing 1 required positional argument: 'options'

This is the error from the point_inside function:

Traceback (most recent call last):
  File "~/test_convert.py", line 233, in <module>
    test_cad_to_csg_from_json_with_defaults("config_complete_defaults.json")
  File "~/test_convert.py", line 134, in test_cad_to_csg_from_json_with_defaults
    my_cad_to_csg = geouned.CadToCsg.from_json(input_json_file)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 252, in from_json
    cad_to_csg.start()
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/core.py", line 643, in start
    CT = build_c_table_from_solids(Box, (c.Surfaces, Surfs), option="full",options=self.options)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/utils/boolean_solids.py", line 269, in build_c_table_from_solids
    res, splitRegions = split_solid_fast(Box, surfaces[s1], True, options)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/utils/boolean_solids.py", line 404, in split_solid_fast
    sgn = check_sign(s, surf)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/utils/boolean_solids.py", line 552, in check_sign
    point = point_inside(solid)
  File "~/GEOUNED-1.1.0/src/geouned/GEOUNED/utils/boolean_solids.py", line 463, in point_inside
    boxes, centers = cut_box(box)
TypeError: 'int' object is not callable

Please complete the following information):

Additional context

If I had only posted the first error, I wouldn't have found the second. I'm working through these and resolving them as I go.

Errors 1 and 2 seem to be resolved by changing the following lines in core.py:

Box = UF.get_box(c)
CT = build_c_table_from_solids(Box, (c.Surfaces, Surfs), option="full")

to this:

Box = UF.get_box(c,self.options)
CT = build_c_table_from_solids(Box, (c.Surfaces, Surfs), option="full",options=self.options)

Error 3 is because an integer "cut_box" is defined in the function point_inside() as well as being defined as a callable function. Changing the integer to something else resolves it. Affects two lines in utils/boolean_solids.py, with cut_box replaced as "cbox".

    cbox = 2
        if n == cbox:
KBGrammer commented 3 weeks ago

This bug has been resolved.

KBGrammer commented 3 weeks ago

The parameter passed down to get_box should be "self.options" because it is treated as options in get_box. Additionally, there's a call to get_box that was also missing the required second parameter in conversion/cell_definition.py

def get_box(comp, options):
    bb = FreeCAD.BoundBox(comp.BoundBox)
    bb.enlarge(options.enlargeBox)