Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. CAD Modeling
  4. Avoid solid

Avoid solid

Scheduled Pinned Locked Moved CAD Modeling
6 Posts 2 Posters 568 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mkn
    wrote on last edited by
    #1

    Hi,

    I am modeling some neural pathways and portions of it go along the muscle layer in the human body model. Is it possible to avoid solid intersection?

    I came across something like this in the IMSafe toolbox:

    9c6d609c-e0ec-448b-9b55-5d871d290f5e-image.png

    So I'm wondering if it is possible to do this using Python.

    Thanks!

    1 Reply Last reply
    0
    • brynB Offline
      brynB Offline
      bryn
      ZMT
      wrote on last edited by
      #2

      The algorithm/evaluator is called:

      s4l_v1.analysis.em_evaluators.ImplantSafety
      
      1 Reply Last reply
      0
      • brynB Offline
        brynB Offline
        bryn
        ZMT
        wrote on last edited by
        #3

        Here is a script I found. Not sure it still runs, but I guess it should help you get started:

        import tempfile
        import os
        
        import s4l_v1.model as model
        from s4l_v1.model import Vec3, Unit
        
        import s4l_v1.simulation as simulators
        import s4l_v1.simulation.emfdtd as emfdtd
        
        # Preamble ---------------
        import s4l_v1.document as doc
        
        sim = doc.AllSimulations[0]
        
        # assumptions
        sphere = model.AllEntities()["Sphere 1"]
        assert sphere
        assert isinstance(sim, emfdtd.Simulation)
        
        sim_xtor = sim.Results()  # pin this variable, otherwise wrapped members are deleted
        efield_port = sim_xtor["Overall Field"]["EM E(x,y,z,f0)"]
        hfield_port = sim_xtor["Overall Field"]["EM H(x,y,z,f0)"]
        
        # Demo ---------------------------------------------------
        from s4l_v1.analysis.em_evaluators import ImplantSafety
        from s4l_v1.analysis import RegisterAlgorithm
        
        
        # Creates ImSafe algorithm
        imsafe = ImplantSafety() # 0. create algorithm and connect to e-field port
        imsafe.SetInputConnection(0, hfield_port)
        
        # Disks options
        base_line = model.CreateSpline([Vec3(52.0, 0.0, 0.0), Vec3(0, 32, 0), Vec3(-9, 70, 0)])
        imsafe.SetBaseLine(base_line)  # 1. define baseline
        total_len = imsafe.EvalBaseLineLength()
        
        imsafe.ModelUnits = Unit.MilliMeter
        imsafe.SetDisks(
            position=[0, 0.1, 1], radii=[10.0] * 3
        )  # 2. define disks along baseline
        centers, normals, radii = imsafe.GetDisks()
        print("centers", centers, imsafe.ModelUnits)
        print("normals", normals, imsafe.ModelUnits)
        print("radii", radii, imsafe.ModelUnits)
        
        # Line generation options #3. setup line options
        imsafe.NumberOfLinesProp.Value = 5
        imsafe.LengthDeviationProp.Value = 10  # %
        imsafe.NormalToEndDisksProp.Value = True
        imsafe.MinSplineResolutionProp.Value = 0.01 * total_len  # or
        # imsafe.MinSplineResolutionProp.SetValueAs(0.05, Unit.Meter)
        
        imsafe.EnableConstraintsProp.Value = False  # 4. setup obstacles
        imsafe.SetAsObstacles([sphere])
        
        RegisterAlgorithm(imsafe)
        assert imsafe.UpdateAttributes(), "Guarantees output ports are updated"
        
        imsafe.ClearOutputLines()
        assert imsafe.Update(0)
        
        filepath = os.path.join(tempfile.mkdtemp(), "line.txt")
        print("Exporting to", filepath)
        imsafe.ExportLines(filepath, snapshot_index=0)
        
        imsafe.ClearOutputLines()
        imsafe.ImportLines(filepath)
        
        
        # Creates viewer
        import s4l_v1.analysis.viewers as viewers
        
        dv = viewers.SurfaceViewer()
        dv.SetInputConnection(0, imsafe.GetOutputPort(2))
        
        RegisterAlgorithm(dv)
        
        1 Reply Last reply
        0
        • brynB Offline
          brynB Offline
          bryn
          ZMT
          wrote on last edited by
          #4
          • it simply takes the first simulation. Note, the evaluator needs an existing simulation because it tests if the splines pass through voxels of the "Entities to Avoid" list
          • the entities to avoid are set via SetAsObstacles(entity_list). the script assumes this entity is called "Sphere `"
          • the script creates a spline as baseline, but you could also create the baseline in the GUI, and get it via base_line = model.AllEntities()["My Baseline"]
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mkn
            wrote on last edited by
            #5

            Thanks for the scrip @bryn. I am actually curious if it is possible to set an obstacle to avoid in the modelling window when drawing an object, outside of IMSafe.

            1 Reply Last reply
            0
            • brynB Offline
              brynB Offline
              bryn
              ZMT
              wrote on last edited by
              #6

              Only by snapping to objects. One strategy can be to use planar cuts to snap inside solids/surfaces

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Search