blenderproc.sampler package
Module contents
- class blenderproc.sampler.Front3DPointInRoomSampler(front3d_objects, amount_of_objects_needed_per_room=2)
Bases:
object
Allows the sampling 3D Front scenes
- sample(height, max_tries=1000)
Samples a point inside one of the loaded Front3d rooms.
The points are uniformly sampled along x/y over all rooms. The z-coordinate is set based on the given height value.
- Parameters:
height (
float
) – The height above the floor to use for the z-component of the point.max_tries (
int
) – The maximum number of times sampling above the floor should be tried.
- Return type:
ndarray
- Returns:
The sampled point.
- class blenderproc.sampler.ReplicaPointInRoomSampler(room_bounding_box, replica_floor, height_list_file_path)
Bases:
object
Allows the sampling in Replica scenes
- sample(height, max_tries=1000)
Samples a point inside one of the loaded replica rooms.
The points are uniformly sampled along x/y over all rooms. The z-coordinate is set based on the given height value.
- Parameters:
height (
float
) – The height above the floor to use for the z-component of the point.max_tries (
int
) – The maximum number of times sampling above the floor should be tried.
- Return type:
ndarray
- Returns:
The sampled point.
- class blenderproc.sampler.SuncgPointInRoomSampler(suncg_objects)
Bases:
object
Allows the sampling in the SUNCG scenes
- _find_floor(suncg_objects, room_obj)
Returns the floor object of the given room object.
Goes through all children and returns the first one with type “Floor”.
- Parameters:
suncg_objects (
List
[MeshObject
]) –room_obj (
MeshObject
) – The room object.
- Return type:
Optional
[MeshObject
]- Returns:
The found floor object or None if none has been found.
- sample(height, max_tries=1000)
Samples a point inside one of the loaded suncg rooms.
The points are uniformly sampled along x/y over all rooms. The z-coordinate is set based on the given height value.
- Parameters:
height (
float
) – The height above the floor to use for the z-component of the point.max_tries (
int
) – The maximum number of times sampling above the floor should be tried.
- Return type:
Tuple
[ndarray
,int
]- Returns:
The sampled point and the id of the room it was sampled in.
- blenderproc.sampler.disk(center, radius, rotation=None, sample_from='disk', start_angle=0, end_angle=180)
- Samples a point on a 1-sphere (circle), or on a 2-ball (disk, i.e. circle + interior space), or on an arc/sector
with an inner angle less or equal than 180 degrees. Returns a 3d mathutils.Vector sampled point.
Example 1: Sample a point from a 1-sphere.
Disk.sample( center=[0, 0, 4], radius=7, sample_from="circle" )
Example 2: Sample a point from a sector.
Disk.sample( center=[0, 0, 4], radius=7, sample_from="sector", start_angle=0, end_angle=90 )
- Parameters:
center (
Union
[Vector
,ndarray
,List
[float
]]) – Center (in 3d space) of a 2d geometrical shape to sample from.radius (
float
) – The radius of the disk.rotation (
Union
[Vector
,ndarray
,List
[float
],None
]) – List of three (XYZ) Euler angles that represent the rotation of the 2d geometrical structure used for sampling in 3d space.sample_from (
str
) – Mode of sampling. Defines the geometrical structure used for sampling, i.e. the shape to sample from.start_angle (
float
) – Start angle in degrees that is used to define a sector/arc to sample from. Must be smaller than end_angle. Arc’s/sector’s inner angle (between start and end) must be less or equal than 180 degrees. Angle increases in the counterclockwise direction from the positive direction of X axis.end_angle (
float
) – End angle in degrees that is used to define a sector/arc to sample from. Must be bigger than start_angle. Arc’s/sector’s inner angle (between start and end) must be less or equal than 180 degrees. Angle increases in the counterclockwise direction from the positive direction of X axis.
- Return type:
ndarray
- Returns:
A random point sampled point on a circle/disk/arc/sector.
- blenderproc.sampler.part_sphere(center, radius, mode, dist_above_center=0.0, part_sphere_dir_vector=None)
Samples a point from the surface or from the interior of solid sphere which is split in two parts.
https://math.stackexchange.com/a/87238 https://math.stackexchange.com/a/1585996
Example 1: Sample a point from the surface of the sphere that is split by a plane with displacement of 0.5 above center and a normal of [1, 0, 0].
PartSphere.sample( center=[0, 0, 0], part_sphere_vector=[1, 0, 0], mode="SURFACE", distance_above_center=0.5 )
- Parameters:
center (
Union
[Vector
,ndarray
,List
[float
]]) – Location of the center of the sphere.radius (
float
) – The radius of the sphere.mode (
str
) – Mode of sampling. Determines the geometrical structure used for sampling. Available: SURFACE (sampling from the 2-sphere), INTERIOR (sampling from the 3-ball).dist_above_center (
float
) – The distance above the center, which should be used. Default: 0.0 (half of the sphere).part_sphere_dir_vector (
Union
[Vector
,ndarray
,List
[float
],None
]) – The direction in which the sphere should be split, the end point of the vector, will be in the middle of the sphere pointing towards the middle of the resulting surface. Default: [0, 0, 1].
- Return type:
ndarray
- Returns:
A random point lying inside or on the surface of a solid sphere.
- blenderproc.sampler.random_walk(total_length, dims, step_magnitude=1.0, window_size=1, interval=None, distribution='uniform', order=1.0)
Creates a random walk with the specified properties. Can be used to simulate camera shaking or POI drift. steps ~ step_magnitude * U[-1,1]^order
- Parameters:
total_length (
int
) – length of the random walkdims (
int
) – In how many dimensions the random walk should happenstep_magnitude (
float
) – Maximum magnitude of any coordinate in a single stepwindow_size (
int
) – Convolve the final trajectory with an average filter that smoothens the trajectory with a given filter size.interval (
Optional
[List
[ndarray
]]) – Constrain the random walk to an interval and mirror steps if they go beyond. List of arrays with dimension dims.distribution (
str
) – Distribution to sample steps from. Choose from [‘normal’, ‘uniform’].order (
float
) – Sample from higher order distribution instead of the uniform. Higher order leads to steps being less frequently close to step_magnitude and thus overall decreased variance.
- Return type:
ndarray
- Returns:
The random walk trajectory (total_length, dims)
- blenderproc.sampler.shell(center, radius_min, radius_max, elevation_min=-90, elevation_max=90, azimuth_min=-180, azimuth_max=180, uniform_volume=False)
Samples a point from the volume between two spheres (radius_min, radius_max). Optionally the spheres can be constraint by setting elevation and azimuth angles. E.g. if you only want to sample in the upper hemisphere set elevation_min = 0.
- Parameters:
center (
Union
[Vector
,ndarray
,List
[float
]]) – Center shared by both spheres.radius_min (
float
) – Radius of the smaller sphere.radius_max (
float
) – Radius of the bigger sphere.elevation_min (
float
) – Minimum angle of elevation in degrees. Range: [-90, 90].elevation_max (
float
) – Maximum angle of elevation in degrees. Range: [-90, 90].azimuth_min (
float
) – Minimum angle of azimuth in degrees. Range: [-180, 180].azimuth_max (
float
) – Maximum angle of azimuth in degrees. Range: [-180, 180].uniform_volume (
bool
) – Instead of sampling the angles and radius uniformly, sample the shell volume uniformly. As a result, there will be more samples at larger radii.
- Return type:
ndarray
- Returns:
A sampled point.
- blenderproc.sampler.sphere(center, radius, mode)
Samples a point from the surface or from the interior of solid sphere.
https://math.stackexchange.com/a/87238 https://math.stackexchange.com/a/1585996
Example 1: Sample a point from the surface of the solid sphere of a defined radius and center location.
Sphere.sample( center=Vector([0, 0, 0]), radius=2, mode="SURFACE" )
- Parameters:
center (
Union
[Vector
,ndarray
,list
]) – Location of the center of the sphere.radius (
float
) – The radius of the sphere.mode (
str
) – Mode of sampling. Determines the geometrical structure used for sampling. Available: SURFACE (sampling from the 2-sphere), INTERIOR (sampling from the 3-ball).
- Return type:
ndarray
- blenderproc.sampler.uniformSO3(around_x=True, around_y=True, around_z=True)
Uniformly samples rotations from SO(3). Allows to limit the rotation around Blender World coordinate axes.
- Parameters:
around_x (
bool
) – Whether to rotate around X-axis.around_y (
bool
) – Whether to rotate around Y-axis.around_z (
bool
) – Whether to rotate around Z-axis.
- Return type:
ndarray
- Returns:
Sampled rotation in euler angles.
- blenderproc.sampler.upper_region(objects_to_sample_on, face_sample_range=None, min_height=0.0, max_height=1.0, use_ray_trace_check=False, upper_dir=None, use_upper_dir=True)
Uniformly samples 3-dimensional value over the bounding box of the specified objects (can be just a plane) in the defined upper direction. If “use_upper_dir” is False, samples along the face normal closest to “upper_dir”. The sampling volume results in a parallelepiped. “min_height” and “max_height” define the sampling distance from the face.
Example 1: Sample a location on the surface of the given objects with height above this surface in range of [1.5, 1.8].
UpperRegionSampler.sample( objects_to_sample_on=objs, min_height=1.5, max_height=1.8 )
- Parameters:
objects_to_sample_on (
Union
[MeshObject
,List
[MeshObject
]]) – Objects, on which to sample on.face_sample_range (
Union
[Vector
,ndarray
,List
[float
],None
]) – Restricts the area on the face where objects are sampled. Specifically describes relative lengths of both face vectors between which points are sampled. Default: [0.0, 1.0]min_height (
float
) – Minimum distance to the bounding box that a point is sampled on.max_height (
float
) – Maximum distance to the bounding box that a point is sampled on.use_ray_trace_check (
bool
) – Toggles using a ray casting towards the sampled object (if the object is directly below the sampled position is the position accepted).upper_dir (
Union
[Vector
,ndarray
,List
[float
],None
]) – The ‘up’ direction of the sampling box. Default: [0.0, 0.0, 1.0].use_upper_dir (
bool
) – Toggles using a ray casting towards the sampled object (if the object is directly below the sampled position is the position accepted).
- Return type:
ndarray
- Returns:
Sampled value.