Skip to content

Commit 95c4db4

Browse files
committed
create edges from trims
1 parent dac8220 commit 95c4db4

File tree

4 files changed

+32
-50
lines changed

4 files changed

+32
-50
lines changed

src/compas_rhino/geometry/brep/brep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def points(self):
103103
@property
104104
def edges(self):
105105
if self._brep:
106-
return [RhinoBrepEdge(edge) for edge in self._brep.Edges]
106+
return [RhinoBrepEdge(trim) for trim in self._brep.Trims]
107107

108108
@property
109109
def loops(self):

src/compas_rhino/geometry/brep/edge.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515

1616

1717
class RhinoBrepEdge(BrepEdge):
18-
"""A wrapper for Rhino.Geometry.BrepEdge
18+
"""A wrapper for Rhino.Geometry.BrepEdge.
19+
20+
The expected native type here is a Rhino.Geometry.BrepTrim.
21+
a BrepTrim holds a reference to its associated BrepEdge as well as its start a end vertices
22+
in a correct topological order (!).
1923
2024
Attributes
2125
----------
2226
curve : :class:`Rhino.Geometry.Curve3D`
2327
The underlying geometry of this edge.
2428
start_vertex : :class:`~compas_rhino.geometry.RhinoBrepVertex`, read-only
25-
The start vertex of this edge.
29+
The start vertex of this edge (taken from BrepTrim).
2630
end_vertex : :class:`~compas_rhino.geometry.RhinoBrepVertex`, read-only
27-
The end vertex of this edge.
31+
The end vertex of this edge (taken from BrepTrim).
2832
vertices : list[:class:`~compas_rhino.geometry.RhinoBrepVertex`], read-only
2933
The list of vertices which comprise this edge (start and end)
3034
is_circle : bool, read-only
@@ -34,22 +38,20 @@ class RhinoBrepEdge(BrepEdge):
3438
3539
"""
3640

37-
def __init__(self, rhino_edge=None):
41+
def __init__(self, rhino_trim=None):
3842
super(RhinoBrepEdge, self).__init__()
3943
self._edge = None
4044
self._curve = None
41-
self.start_vertex = None
42-
self.end_vertex = None
43-
if rhino_edge:
44-
self._set_edge(rhino_edge)
45-
46-
def _set_edge(self, native_edge):
47-
print("creating Edge object. nativ:{}".format(native_edge))
48-
self._edge = native_edge
45+
self._start_vertex = None
46+
self._end_vertex = None
47+
if rhino_trim:
48+
self._set_edge(rhino_trim)
49+
50+
def _set_edge(self, rhino_trim):
51+
self._edge = rhino_trim.Edge
4952
self._curve = self._edge.EdgeCurve
50-
# print("creating Edge object. StartVertex:{} EndVertex:{}".format(self._edge.StartVertex.Location, self._edge.EndVertex.Location))
51-
# self._curve_start = RhinoBrepVertex(self._edge.StartVertex)
52-
# self._curve_end = RhinoBrepVertex(self._edge.EndVertex)
53+
self._start_vertex = RhinoBrepVertex(rhino_trim.StartVertex)
54+
self._end_vertex = RhinoBrepVertex(rhino_trim.EndVertex)
5355

5456
# ==============================================================================
5557
# Data
@@ -91,9 +93,9 @@ def data(self, value):
9193
else:
9294
self._curve = RhinoNurbsCurve.from_data(value["value"]).rhino_curve
9395

94-
self.start_vertex, self.end_vertex = RhinoBrepVertex(), RhinoBrepVertex()
95-
self.start_vertex._point = Point.from_data(value["points"][0])
96-
self.end_vertex._point = Point.from_data(value["points"][1])
96+
self._start_vertex, self._end_vertex = RhinoBrepVertex(), RhinoBrepVertex()
97+
self._start_vertex._point = Point.from_data(value["points"][0])
98+
self._end_vertex._point = Point.from_data(value["points"][1])
9799

98100
# ==============================================================================
99101
# Properties
@@ -103,13 +105,13 @@ def data(self, value):
103105
def curve(self):
104106
return self._curve
105107

106-
# @property
107-
# def start_vertex(self):
108-
# return self._start_vertex
109-
#
110-
# @property
111-
# def end_vertex(self):
112-
# return self._end_vertex
108+
@property
109+
def start_vertex(self):
110+
return self._start_vertex
111+
112+
@property
113+
def end_vertex(self):
114+
return self._end_vertex
113115

114116
@property
115117
def vertices(self):

src/compas_rhino/geometry/brep/face.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,9 @@ def _get_surface_geometry(surface):
117117
raise NotImplementedError("Support for torus surface is not yet implemented!")
118118
return "nurbs", RhinoNurbsSurface.from_rhino(surface.ToNurbsSurface())
119119

120-
# @staticmethod
121-
# def _make_surface_from_plane_loop(plane, loop):
122-
# # TODO: replace guesswork here with an actual calculation..
123-
# u_degree, v_degree = 1, 1
124-
# u_p_count, v_p_count = 2, 2
125-
# curve_lengths = [edge.curve.GetLength() for edge in loop.edges]
126-
# max_length = max(curve_lengths)
127-
# u_interval, v_interval = (0.0, max_length), (0.0, max_length)
128-
# return RhinoNurbsSurface.from_plane(plane, u_interval, v_interval, u_degree, v_degree, u_p_count, v_p_count)
129-
130120
@staticmethod
131121
def _make_surface_from_plane_loop(plane, loop):
132-
# TODO: replace guesswork here with an actual calculation..
133-
c0 = loop.edges[0].start_vertex._point
134-
c1 = loop.edges[1].start_vertex._point
135-
c2 = loop.edges[2].start_vertex._point
136-
c3 = loop.edges[3].start_vertex._point
137-
# flipped order flips the normal of the resulting surface!
138-
surface = RhinoNurbsSurface.from_corners([c0, c1, c2, c3])
122+
# order of corners determines the normal of the resulting surface
123+
corners = [loop.edges[i].start_vertex.point for i in range(4)]
124+
surface = RhinoNurbsSurface.from_corners(corners)
139125
return surface

src/compas_rhino/geometry/brep/loop.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from compas.geometry import BrepLoop
2-
from compas_rhino.conversions import point_to_compas
32

43
import Rhino
54

@@ -56,12 +55,7 @@ def __init__(self, rhino_loop=None):
5655
def _set_loop(self, native_loop):
5756
self._loop = native_loop
5857
self._type = int(self._loop.LoopType)
59-
self._edges = []
60-
for trim in self._loop.Trims:
61-
edge = RhinoBrepEdge(trim.Edge)
62-
edge.start_vertex = RhinoBrepVertex(trim.StartVertex)
63-
edge.end_vertex = RhinoBrepVertex(trim.EndVertex)
64-
self._edges.append(edge)
58+
self._edges = [RhinoBrepEdge(trim) for trim in self._loop.Trims]
6559

6660
# ==============================================================================
6761
# Data

0 commit comments

Comments
 (0)