-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: Add polydata conversors to edges and faces #759
Draft
AlejandroFernandezLuces
wants to merge
12
commits into
main
Choose a base branch
from
feat/named-selections-plot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−18
Draft
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
94ffc46
feat: Add polydata conversors to edges and faces
AlejandroFernandezLuces b3527f6
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces dab83c9
Add return to selections
AlejandroFernandezLuces 017adfa
Merge branch 'feat/named-selections-plot' of https://github.com/ansys…
AlejandroFernandezLuces 4d9f56f
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces 88309c1
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces f6e5bca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a00e06f
feat(wip): Add circles and ellipses polydata to edges
AlejandroFernandezLuces fbac463
Merge branch 'feat/named-selections-plot' of https://github.com/ansys…
AlejandroFernandezLuces fa80782
feat(wip): Circle edges working
AlejandroFernandezLuces 1b61381
feat(wip): Ellipse edges working
AlejandroFernandezLuces 2643fd9
feat(wip): Add surface polydata
AlejandroFernandezLuces 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -25,12 +25,14 @@ | |||||
|
||||||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||||||
from ansys.api.geometry.v0.edges_pb2_grpc import EdgesStub | ||||||
from beartype.typing import TYPE_CHECKING, List | ||||||
from beartype.typing import TYPE_CHECKING, List, Union | ||||||
from pint import Quantity | ||||||
import pyvista as pv | ||||||
|
||||||
from ansys.geometry.core.connection.client import GrpcClient | ||||||
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve | ||||||
from ansys.geometry.core.errors import protect_grpc | ||||||
from ansys.geometry.core.logger import LOG | ||||||
from ansys.geometry.core.math.point import Point3D | ||||||
from ansys.geometry.core.misc.checks import ensure_design_is_active | ||||||
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS | ||||||
|
@@ -40,6 +42,8 @@ | |||||
if TYPE_CHECKING: # pragma: no cover | ||||||
from ansys.geometry.core.designer.body import Body | ||||||
from ansys.geometry.core.designer.face import Face | ||||||
from ansys.geometry.core.shapes.curves.circle import Circle | ||||||
from ansys.geometry.core.shapes.curves.ellipse import Ellipse | ||||||
|
||||||
|
||||||
@unique | ||||||
|
@@ -168,3 +172,41 @@ def faces(self) -> List["Face"]: | |||||
) | ||||||
for grpc_face in grpc_faces | ||||||
] | ||||||
|
||||||
def _to_polydata(self) -> Union[pv.PolyData, None]: | ||||||
""" | ||||||
Return the edge as polydata. | ||||||
|
||||||
This is useful to represent the edge in a PyVista plotter. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
Union[pv.PolyData, None] | ||||||
Edge as polydata | ||||||
""" | ||||||
if self._curve_type == CurveType.CURVETYPE_UNKNOWN or CurveType.CURVETYPE_LINE: | ||||||
return pv.Line(pointa=self.start_point, pointb=self.end_point) | ||||||
elif self._curve_type == CurveType.CURVETYPE_CIRCLE: | ||||||
self.shape.geometry: Circle | ||||||
point_a = self.shape.geometry.evaluate(0) | ||||||
point_b = self.shape.geometry.evaluate(1) | ||||||
half_a = pv.CircularArc( | ||||||
center=self.shape.geometry.center, | ||||||
pointa=point_a, | ||||||
pointb=point_b, | ||||||
) | ||||||
half_b = pv.CircularArc( | ||||||
center=self.shape.geometry.center, | ||||||
pointa=point_a, | ||||||
pointb=point_b, | ||||||
negative=True, | ||||||
) | ||||||
pv_circle = pv.MultiBlock([half_a, half_b]) | ||||||
return pv_circle | ||||||
|
||||||
elif self._curve_type == CurveType.CURVETYPE_ELLIPSE: | ||||||
self.shape.geometry: Ellipse | ||||||
|
||||||
else: | ||||||
LOG.warning("Non linear edges not supported.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return None |
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -28,13 +28,15 @@ | |||||
from ansys.api.geometry.v0.faces_pb2 import CreateIsoParamCurvesRequest | ||||||
from ansys.api.geometry.v0.faces_pb2_grpc import FacesStub | ||||||
from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge | ||||||
from beartype.typing import TYPE_CHECKING, List | ||||||
from beartype.typing import TYPE_CHECKING, List, Union | ||||||
from pint import Quantity | ||||||
import pyvista as pv | ||||||
|
||||||
from ansys.geometry.core.connection.client import GrpcClient | ||||||
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve, grpc_surface_to_surface | ||||||
from ansys.geometry.core.designer.edge import Edge | ||||||
from ansys.geometry.core.errors import protect_grpc | ||||||
from ansys.geometry.core.logger import LOG | ||||||
from ansys.geometry.core.math.point import Point3D | ||||||
from ansys.geometry.core.math.vector import UnitVector3D | ||||||
from ansys.geometry.core.misc.checks import ensure_design_is_active | ||||||
|
@@ -358,6 +360,34 @@ def __grpc_edges_to_edges(self, edges_grpc: List[GRPCEdge]) -> List[Edge]: | |||||
) | ||||||
return edges | ||||||
|
||||||
def _to_polydata(self) -> Union[pv.PolyData, None]: | ||||||
""" | ||||||
Return the face as polydata. | ||||||
|
||||||
This is useful to represent the face in a PyVista plotter. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Returns | ||||||
------- | ||||||
Union[pv.PolyData, None] | ||||||
Face as polydata | ||||||
""" | ||||||
if self.surface_type != SurfaceType.SURFACETYPE_PLANE: | ||||||
LOG.warning("Only planes surfaces are supported") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return None | ||||||
else: | ||||||
# get vertices from edges | ||||||
vertices = [ | ||||||
vertice | ||||||
for edge in self.edges | ||||||
for vertice in [edge.start_point.flat, edge.end_point.flat] | ||||||
] | ||||||
# TODO remove duplicate vertices | ||||||
# build the PyVista face | ||||||
vertices_order = [len(vertices)] | ||||||
vertices_order.extend(range(len(vertices))) | ||||||
|
||||||
return pv.PolyData(vertices, faces=vertices_order, n_faces=1) | ||||||
|
||||||
def create_isoparametric_curves( | ||||||
self, use_u_param: bool, parameter: float | ||||||
) -> List[TrimmedCurve]: | ||||||
|
This file contains 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
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.