ShapeBuilder.polyline - skip creating segments if they are not needed

This commit is contained in:
Andrej730
2023-07-05 13:02:05 +05:00
parent 1533283822
commit 9fbcb3900f
3 changed files with 214 additions and 208 deletions
File diff suppressed because it is too large Load Diff
@@ -258,11 +258,7 @@ class FilledOpeningGenerator:
unioned_boundaries = shapely.union_all(shapely.GeometryCollection(boundary_lines)) unioned_boundaries = shapely.union_all(shapely.GeometryCollection(boundary_lines))
closed_polygons = shapely.polygonize(boundary_lines) closed_polygons = shapely.polygonize(boundary_lines)
polygon = max(closed_polygons.geoms, key=lambda polygon: polygon.area) polygon = max(closed_polygons.geoms, key=lambda polygon: polygon.area)
return shape_builder.polyline(list(polygon.exterior.coords))
if tool.Ifc.get_schema() == "IFC2X3":
return shape_builder.polyline(list(polygon.exterior.coords))
points = tool.Ifc.get().createIfcCartesianPointList2D(list(polygon.exterior.coords))
return tool.Ifc.get().createIfcIndexedPolyCurve(points)
extrusion = shape_builder.extrude( extrusion = shape_builder.extrude(
get_curve_2d_from_3d(profile), get_curve_2d_from_3d(profile),
@@ -42,6 +42,28 @@ class ShapeBuilder:
if arc_points and self.file.schema == "IFC2X3": if arc_points and self.file.schema == "IFC2X3":
raise Exception("Arcs are not supported for IFC2X3.") raise Exception("Arcs are not supported for IFC2X3.")
if position_offset:
points = [Vector(p) + position_offset for p in points]
if self.file.schema == "IFC2X3":
points = [self.file.createIfcCartesianPoint(p) for p in points]
if closed:
points.append(points[0])
ifc_curve = self.file.createIfcPolyline(Points=points)
return ifc_curve
dimensions = len(points[0])
if dimensions == 2:
ifc_points = self.file.createIfcCartesianPointList2D(points)
elif dimensions == 3:
ifc_points = self.file.createIfcCartesianPointList3D(points)
if not closed and not arc_points:
ifc_curve = self.file.createIfcIndexedPolyCurve(Points=ifc_points)
return ifc_curve
# if curve is closed or we have arc points
# then we do need to create segments
segments = [] segments = []
cur_i = 0 cur_i = 0
while cur_i < len(points) - 1: while cur_i < len(points) - 1:
@@ -55,38 +77,26 @@ class ShapeBuilder:
if closed: if closed:
segments.append((len(points), 1)) segments.append((len(points), 1))
if position_offset:
points = [Vector(p) + position_offset for p in points]
if self.file.schema == "IFC2X3": ifc_segments = []
points = [self.file.createIfcCartesianPoint(p) for p in points] # because IfcLineIndex support 2+ points
ifc_curve = self.file.createIfcPolyline(Points=points) # we merge neighbor line segments into one
else: current_line_segment = []
dimensions = len(points[0]) last_segment = len(segments) - 1
if dimensions == 2: for seg_i, segment in enumerate(segments):
ifc_points = self.file.createIfcCartesianPointList2D(points) if len(segment) == 2:
elif dimensions == 3: # check if `current_line_segment` is empty to avoid duplicated indices like `IfcLineIndex((1,2,2,3,3,4,4,1))`
ifc_points = self.file.createIfcCartesianPointList3D(points) current_line_segment += segment if not current_line_segment else segment[1:]
ifc_segments = [] if current_line_segment and (len(segment) == 3 or seg_i == last_segment):
# because IfcLineIndex support 2+ points ifc_segments.append(self.file.createIfcLineIndex(current_line_segment))
# we merge neighbor line segments into one current_line_segment = []
current_line_segment = []
last_segment = len(segments) - 1
for seg_i, segment in enumerate(segments):
if len(segment) == 2:
# check if `current_line_segment` is empty to avoid duplicated indices like `IfcLineIndex((1,2,2,3,3,4,4,1))`
current_line_segment += segment if not current_line_segment else segment[1:]
if current_line_segment and (len(segment) == 3 or seg_i == last_segment): if len(segment) == 3:
ifc_segments.append(self.file.createIfcLineIndex(current_line_segment)) ifc_segments.append(self.file.createIfcArcIndex(segment))
current_line_segment = []
if len(segment) == 3: # NOTE: IfcIndexPolyCurve support only consequtive segments
ifc_segments.append(self.file.createIfcArcIndex(segment)) ifc_curve = self.file.createIfcIndexedPolyCurve(Points=ifc_points, Segments=ifc_segments)
# NOTE: IfcIndexPolyCurve support only consequtive segments
ifc_curve = self.file.createIfcIndexedPolyCurve(Points=ifc_points, Segments=ifc_segments)
return ifc_curve return ifc_curve
def get_rectangle_coords(self, size: Vector = Vector((1.0, 1.0)).freeze(), position: Vector = None): def get_rectangle_coords(self, size: Vector = Vector((1.0, 1.0)).freeze(), position: Vector = None):