Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim vertices #1410

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added attribute `start_vertex` to `compas.geometry.BrepTrim`.
* Added attribute `end_vertex` to `compas.geometry.BrepTrim`.
* Added attribute `vertices` to `compas.geometry.BrepTrim`.
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
* Added attribute `start_vertex` to `compas_rhino.geometry.RhinoBrepTrim`.
* Added attribute `vertices` to `compas_rhino.geometry.RhinoBrepTrim`.

### Changed

* Fixed `PluginNotInstalledError` when using `Brep.from_boolean_*` in Rhino.
* Added support for `Polyline` as input for `compas_rhino.Brep.from_extrusion`.

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/compas/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def from_extrusion(cls, curve, vector, cap_ends=True):

Parameters
----------
curve : :class:`compas.geometry.Curve`
curve : :class:`compas.geometry.Curve` or :class:`compas.geometry.Polyline`
The curve to extrude
vector : :class:`compas.geometry.Vector`
The vector to extrude the curve by
Expand Down
17 changes: 17 additions & 0 deletions src/compas/geometry/brep/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class BrepTrim(Data):
True if this trim is reversed from its associated edge curve and False otherwise.
native_trim : Any
The underlying trim object. Type is backend-dependent.
start_vertex : Any, read-only
The start vertex of this trim.
end_vertex : Any, read-only
The end vertex of this trim.
vertices : list[Any], read-only

"""

Expand All @@ -44,3 +49,15 @@ def is_reversed(self):
@property
def native_trim(self):
raise NotImplementedError

@property
def start_vertex(self):
raise NotImplementedError

@property
def end_vertex(self):
raise NotImplementedError

@property
def vertices(self):
raise NotImplementedError
10 changes: 8 additions & 2 deletions src/compas_rhino/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from compas.geometry import Frame
from compas.geometry import Plane
from compas.geometry import Point
from compas.geometry import Polyline
from compas.tolerance import TOL
from compas_rhino.conversions import box_to_rhino
from compas_rhino.conversions import curve_to_compas
Expand All @@ -19,6 +20,7 @@
from compas_rhino.conversions import mesh_to_rhino
from compas_rhino.conversions import plane_to_rhino
from compas_rhino.conversions import point_to_rhino
from compas_rhino.conversions import polyline_to_rhino_curve
from compas_rhino.conversions import sphere_to_rhino
from compas_rhino.conversions import transformation_to_rhino
from compas_rhino.conversions import vector_to_rhino
Expand Down Expand Up @@ -223,7 +225,7 @@ def from_extrusion(cls, curve, vector, cap_ends=True):

Parameters
----------
curve : :class:`~compas.geometry.Curve`
curve : :class:`~compas.geometry.Curve` or :class:`~compas.geometry.Polyline`
The curve to extrude.
vector : :class:`~compas.geometry.Vector`
The vector to extrude the curve along.
Expand All @@ -235,7 +237,11 @@ def from_extrusion(cls, curve, vector, cap_ends=True):
:class:`~compas_rhino.geometry.RhinoBrep`

"""
extrusion = Rhino.Geometry.Surface.CreateExtrusion(curve_to_rhino(curve), vector_to_rhino(vector))
if isinstance(curve, Polyline):
rhino_curve = polyline_to_rhino_curve(curve)
else:
rhino_curve = curve_to_rhino(curve)
extrusion = Rhino.Geometry.Surface.CreateExtrusion(rhino_curve, vector_to_rhino(vector))
if extrusion is None:
raise BrepError("Failed to create extrusion from curve: {} and vector: {}".format(curve, vector))
rhino_brep = extrusion.ToBrep()
Expand Down
31 changes: 28 additions & 3 deletions src/compas_rhino/geometry/brep/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from compas.geometry import BrepTrim
from compas_rhino.geometry import RhinoNurbsCurve

from .vertex import RhinoBrepVertex


class RhinoBrepTrim(BrepTrim):
"""An interface for a Brep Trim
"""Trims hold topological information about how the edges of a Brep face are are organized.

Attributes
----------
Expand All @@ -21,6 +23,12 @@ class RhinoBrepTrim(BrepTrim):
True if this trim is reversed from its associated edge curve and False otherwise.
native_trim : :class:`Rhino.Geometry.BrepTrim`
The underlying Rhino BrepTrim object.
start_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
The start vertex of this trim.
end_vertex : :class:`compas_rhino.geometry.RhinoBrepVertex`, read-only
The end vertex of this trim.
vertices : list[:class:`compas_rhino.geometry.RhinoBrepVertex`], read-only
The list of vertices which comprise this trim (start and end).

"""

Expand All @@ -30,6 +38,8 @@ def __init__(self, rhino_trim=None):
self._curve = None
self._is_reversed = None
self._iso_type = None
self._start_vertex = None
self._end_vertex = None
if rhino_trim:
self.native_trim = rhino_trim

Expand All @@ -40,7 +50,8 @@ def __init__(self, rhino_trim=None):
@property
def __data__(self):
return {
"vertex": self._trim.StartVertex.VertexIndex,
"start_vertex": self._trim.StartVertex.VertexIndex,
"end_vertex": self._trim.EndVertex.VertexIndex,
"edge": self._trim.Edge.EdgeIndex if self._trim.Edge else -1, # singular trims have no associated edge
"curve": RhinoNurbsCurve.from_rhino(self._trim.TrimCurve.ToNurbsCurve()).__data__,
"iso": str(self._trim.IsoStatus),
Expand Down Expand Up @@ -68,7 +79,7 @@ def __from_data__(cls, data, builder):
curve = RhinoNurbsCurve.__from_data__(data["curve"]).rhino_curve
iso_status = getattr(Rhino.Geometry.IsoStatus, data["iso"])
is_reversed = True if data["is_reversed"] == "true" else False
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["vertex"])
instance.native_trim = builder.add_trim(curve, data["edge"], is_reversed, iso_status, data["start_vertex"])
return instance

# ==============================================================================
Expand All @@ -79,6 +90,18 @@ def __from_data__(cls, data, builder):
def curve(self):
return self._curve

@property
def start_vertex(self):
return self._start_vertex

@property
def end_vertex(self):
return self._end_vertex

@property
def vertices(self):
return [self.start_vertex, self.end_vertex]

@property
def is_reverse(self):
return self._curve
Expand All @@ -97,3 +120,5 @@ def native_trim(self, rhino_trim):
self._curve = RhinoNurbsCurve.from_rhino(rhino_trim.TrimCurve.ToNurbsCurve())
self._is_reversed = rhino_trim.IsReversed()
self._iso_type = int(rhino_trim.IsoStatus)
self._start_vertex = RhinoBrepVertex(rhino_trim.StartVertex)
self._end_vertex = RhinoBrepVertex(rhino_trim.EndVertex)
Loading