-
Notifications
You must be signed in to change notification settings - Fork 114
Geometry brep #1057
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
Merged
Merged
Geometry brep #1057
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7e1d7e6
WIP: start of a compas.core.Brep implementation
a062549
added basic implementations for edge, face, vertex and loop
ab65dc7
formatted with black
9027829
BRep->Brep, fixed pluging signatures, fixed call to default constructor
f937532
added interfaces for Brep components in compas.geometry
96b0e1a
fixed serialization
19b5dd6
WIP: reconstructing brep
4075a41
solved invalid geometry
84d356b
valid brep reconstruction
c2b3724
tidying of brep reconstruction
ad9ccda
added error handling to brep reconstruction
82c53f5
added circle and nurbs curves to possible edge geometries
1d6dd82
cleanup, linting and formatting
c86095d
updated CHANGELOG
6536d35
fixed ambiguous variable names
86519a3
updated some comments
d67a810
implemented Geometry interface in Brep, removed None syntax error
cc3a022
added documentation, started Brep json schema
89d4d53
added trim operation to brep
62e9f1c
updated tutorial
81dc3cf
fixed indentation errors in tutorial
ddc6cb9
removed already implemented methods
f636dc8
added docstrings
64fa58b
fixed weird trimming bug on de-serialized brep
550099d
dtype hack for backend agnostic de-serialization of brep
713141b
added turorial screenshots
66c3335
removed unused import
chenkasirer 0b92fdb
Merge branch 'main' into geometry_brep
chenkasirer a40516d
completed missing docstrings
chenkasirer c529ec1
formatted with black
chenkasirer 877fed9
new classes inherit from object
chenkasirer a2e2fce
fixed brep docstrings
chenkasirer 48d9a9e
standardized docstrings in brep modules
chenkasirer 7879313
remove property docstrings
chenkasirer 2042d25
standardized docstrings in compas_rhino
chenkasirer 937da8e
small docstring corrections
chenkasirer b273650
removed unused module attribute
chenkasirer d2540f7
Brep.trim takes cutting plane also as Plane
chenkasirer 0e62739
black formatting
chenkasirer 84b8dfd
fixed typo in conf.py
chenkasirer 4d5d249
minor docs fixes
chenkasirer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| *********************** | ||
| Boundary Representation | ||
| *********************** | ||
|
|
||
| .. rst-class:: lead | ||
|
|
||
| Boundary representation (Brep) support is realized in COMPAS using its `plugin` system. | ||
| The expected interface for Brep related classes is defined in the :mod:`compas.geometry.brep` module | ||
| whereas the actual implementation is context dependent and implemented using plugins. | ||
|
|
||
| .. currentmodule:: compas.geometry | ||
|
|
||
| .. highlight:: python | ||
|
|
||
| Brep Basics | ||
| =========== | ||
| Brep is a data structure used to describe a shape by means of recording topological and geometrical information of the shape's boundaries. | ||
| Some topological properties are associated with an underlying geometry, while others are purely topological. | ||
|
|
||
| A Brep is comprised of the following: | ||
|
|
||
| .. rst-class:: table table-bordered | ||
|
|
||
| .. list-table:: | ||
| :widths: auto | ||
| :header-rows: 1 | ||
|
|
||
| * - Topology | ||
| - Geometry | ||
| - Description | ||
| * - Vertex | ||
| - 3D Point | ||
| - The most basic element of a Brep, geometrically described as a point in 3D space. | ||
| * - Edge | ||
| - 3D Curve | ||
| - An edge has a start vertex and an end vertex. The underlying 3D curve describes the geometry of the edge (Line, Circle etc.). Closed edges feature start_vertex == end_vertex. | ||
| * - Loop | ||
| - None | ||
| - A collection of trims which define the inner or outer boundary of a face. | ||
| * - Face | ||
| - Surface | ||
| - Defines the geometry of one of the shape's faces using a surface. Associated with at least one loop which describes the trimmed outer boundary of the surface. Inner loops are referred to as holes in the face. | ||
| * - Trim | ||
| - 2D Curve | ||
| - A 2D curve which trims a face. Trims are associated with a corresponding edge. | ||
|
|
||
|
|
||
| Getting Started with COMPAS Brep | ||
| ================================ | ||
|
|
||
| To create an empty `Brep` | ||
|
|
||
| .. code-block:: | ||
|
|
||
| >>> from compas.geometry import Brep | ||
| >>> brep = Brep() | ||
|
|
||
|
|
||
| Notice that the type of the actual instance created by `Brep()` will differ depending on the currently available backend. | ||
| For example, when in Rhino | ||
|
|
||
| .. code-block:: | ||
|
|
||
| >>> type(brep) | ||
| compas_rhino.geometry.RhinoBrep | ||
|
|
||
| Every backend is expected to implement some alternative constructors | ||
|
|
||
| .. code-block:: | ||
|
|
||
| >>> from compas.geometry import Box | ||
| >>> from compas.geometry import Brep | ||
| >>> ... | ||
| >>> box = Box.from_width_height_depth(5., 5., 5.) | ||
| >>> brep_box = Brep.from_box(box) | ||
|
|
||
|
|
||
| `Brep` can also be instantiated from an instance of a backend native `Brep` | ||
|
|
||
| .. code-block:: | ||
|
|
||
| >>> import Rhino | ||
| >>> from compas.geometry import Brep | ||
| >>> ... | ||
| >>> Brep.from_brep(Rhino.Geometry.Brep()) | ||
|
|
||
| Brep operations | ||
| =============== | ||
|
|
||
| Trimming a Brep in Grasshopper | ||
|
|
||
| .. code-block:: | ||
|
|
||
| from compas.geometry import Frame | ||
| from compas.geometry import Point | ||
| from compas.geometry import Brep | ||
|
|
||
| box = Box.from_width_height_depth(5, 5, 10) | ||
|
|
||
| brep = Brep.from_box(box) | ||
| cutting_plane = Frame(Point(0, 2.5, 0), [1, 0, 0], [0, 1, 1.5]) | ||
|
|
||
| brep.trim(cutting_plane) | ||
|
|
||
| |pic1| |pic2| | ||
|
|
||
| .. |pic1| image:: files/box_w_plane.png | ||
| :width: 48% | ||
|
|
||
| .. |pic2| image:: files/trimmed_box.png | ||
| :width: 48% | ||
|
|
||
|
|
||
| Implementing a new backend | ||
| ========================== | ||
|
|
||
| If you wish to create an additional backend to `Brep` in your package, this can be done using the plugin system of COMPAS. | ||
|
|
||
| Create a Brep type in your package which inherits from :class:`compas.geometry.Brep` and override the `__new__` dundle as follows: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| from compas.geometry import Brep | ||
|
|
||
| class OccBrep(Brep): | ||
|
|
||
| def __new__(cls, *args, **kwargs): | ||
| # This breaks the endless recursion when calling `compas.geometry.Brep()` and allows | ||
| # having Brep here as the parent class. Otherwise OccBrep() calls Brep.__new__() | ||
| # which calls OccBrep() and so on... | ||
| return object.__new__(cls, *args, **kwargs) | ||
|
|
||
| Whenever instantiating `compas.geometry.Brep`, the actual instantiation is delegated to the available factory plugin | ||
|
|
||
| .. code-block:: | ||
|
|
||
| @plugin(category="factories", requires=["OCC"]) | ||
| def new_brep(*args, **kwargs): | ||
| # Note: this is called inside Brep.__new__, thus Brep.__init__ will be ran by the interpreter | ||
| # upon returning from __new__. This means any fully initialized instance returned here will be overwritten! | ||
| return object.__new__(OccBrep, *args, **kwargs) | ||
|
|
||
| Now, a call to `compas.geometry.Brep()` will result in an instance of `your.package.OccBrep`, given that the plugin is available and loaded. | ||
| `OccBrep` encapsulates the native Brep object available by the underlying implementation. If necessary, it can be accessed using `occ_brep_instance.native_brep`. | ||
|
|
||
| Implementing the `compas.data.Data` interface | ||
| --------------------------------------------- | ||
| A powerful feature of this approach is to be able to serialize a Brep created in one backend and de-serialize it using another. | ||
| For that, it is required that `your.package.OccBrep` implements the :class:`compas.data.Data` interface and follows the unified serialization protocol. | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$id": "brep.json", | ||
| "$compas": "1.16.0", | ||
| "type": "object", | ||
| "properties": { | ||
| "faces": { | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "items": {} | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from .brep import Brep | ||
| from .brep import BrepOrientation | ||
| from .brep import BrepType | ||
| from .edge import BrepEdge | ||
| from .loop import BrepLoop | ||
| from .face import BrepFace | ||
| from .vertex import BrepVertex | ||
|
|
||
|
|
||
| class BrepError(Exception): | ||
| """Represents a generic error in the Brep context""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class BrepInvalidError(BrepError): | ||
| """Raised when the process of re-constructing a Brep has resulted in an invalid Brep""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class BrepTrimmingError(BrepError): | ||
| """Raised when a trimming operation has failed or had not result""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "Brep", | ||
| "BrepEdge", | ||
| "BrepLoop", | ||
| "BrepFace", | ||
| "BrepVertex", | ||
| "BrepOrientation", | ||
| "BrepType", | ||
| "BrepError", | ||
| "BrepInvalidError", | ||
| "BrepTrimmingError", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will need to expose vertex, edge, loop, and face as well...