Can an object be sampled to be in each of two overlapping regions?

Hi everybody,

I have a PathRegion representing the centerline of a rail track. Now I want to define a CircularRegion overlapping the centerline and sample from all points that are

  1. on the centerline
  2. within the CircularRegion

I tried this so far:

model scene_sampling.rail_model.model

param num_scenes = 1
param map_domain = 'hvle'
param simulation_start_timestamp = '2025-05-26T12:00'

mission = 1
train_model = Uniform('Single_Bogie')
sensor_set ='Development_Sensorset'
train_spot = new OrientedPoint at ego_track.follow_from(ego_track.vertices[0], 2320.21566128582)

ego = new Train with mission_profile_id mission,
      with train_model_id train_model,
      with sensor_set_id sensor_set,
      at train_spot

obstacle_area_center = new OrientedPoint following ego_track.direction from train_spot for 100.0
radius = 10.0

obstacle_region = CircularRegion(obstacle_area_center.position, radius)
new TestCube in obstacle_region, in ego_track

Which results in an error

SpecifierError: Cannot use In specifier to modify itself.

Any help appreciated.
Bruno

Interestingly,
using two different specifiers works without errors.

new TestCube in obstacle_region, on ego_track

Unfortunately this gives me a different elevation for the object.

I think what you want can be accomplished with something along the lines of:

new TestCube in obstacle_region.intersect(ego_track)

Keep in mind that in this case, the preferred orientation of the new region would be inherited from obstacle_region, so you may want to swap the order (more details here).

Also, what you’re doing in the follow up post is actually sampling the position from obstacle_region, and then projecting the base onto the ego_track, which is why you end up with a different elevation. General rule of thumb is if you’re trying to position the center you generally want on, and if you’re trying to position the base you want in.

Hope this helps, and please let me know if this doesn’t work!

Thanks for replying so quick Eric. I tried your suggestion, which results in the following error:

RejectionException: failed to generate scenario in 50 iterations

I get this from time to time in my setup. Note that the centerline is quite long, about 5km, while the circular region is only 10m. Could that have any impact?

Edit:
More verbosity in sampling brings up this for each sample:

  Rejected sample 46 because of sampling intersection of Regions (<LinearTrackRegion ego_track_1 at 0x76d0d99b4410>, CircularRegion(Vector(375965.4510185648, 5824184.398249665,
 33.49399171331255), 10.0))

Increasing iterations to up to 50000 does not change anything.

Interesting that

new TestCube in obstacle_region, on ego_track

actually finds matching samples quickly within 50 iterations.

Sorry Bruno, I think I may have misled you above! What you want is probably the following:

new TestCube in obstacle_region.footprint.intersect(ego_track)

This uses the footprint of the 2D CircularRegion, which is probably the desired behavior here. What I wrote up above actually checks the path intersecting the circle itself.

Just for context, what’s happening under the hood is that the intersection computation I first suggested above (non-footprint Circular Region and PathRegion) isn’t something Scenic knows how to do (we just haven’t added it yet since it seemed unlikely to be needed). Instead, Scenic returns an IntersectionRegion, which is essentially a region that will attempt to work around not having an explicit construction. In this case, it tries to sample by sampling a variety of points from both sub-regions and seeing if any of these points are contained in all regions. Unfortunately, since you have (presumably) a very long train track much of which does not overlap with obstacle_region, and obstacle_region is of higher dimensionality than ego_track (2D vs 1D), this procedure is not very likely to succeed. Thankfully the intersection of a PathRegion with the footprint of a PolygonalRegion is something Scenic can compute explicitly, and so hopefully this will work well for you. Please let me know if not: happy to troubleshoot further!

Thanks a lot Eric, this seems to work.
Bruno