tataratat / splinepy

Library for prototyping spline geometries of arbitrary dimensions and degrees, and IGA
https://tataratat.github.io/splinepy
Other
45 stars 13 forks source link

Swept Surface #438

Open OberGue opened 3 months ago

OberGue commented 3 months ago

Overview

swept is a tool within the splinepy.helpme.create environment to provide sweeping a cross section along a trajectory.

Addressed issues

Showcase

In order to create a spline patch of a spaghetti pasta, we can pass a circular cross-section and an arbitrary trajectory. The result can be both a 3-dimensional volume spline or a 2-dimensional shell spline, depending on the dimension of your cross-section.

import splinepy
spaghetti = splinepy.helpme.create.swept(cross_section, trajectory)

Checklists

Summary by CodeRabbit

jzwar commented 3 months ago

Nice, can you post some screenshots?

OberGue commented 3 months ago

Nice, can you post some screenshots?

Sure! Be aware that work is still in progress.

2D_S_topfront_view 3D_questionmark_topfrontview

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent updates introduce a new example script for creating and visualizing swept surfaces and solids using spline representations in the splinepy library. Enhancements to the swept function allow for improved control over the sweeping process. The changes also involve the addition of various cross-section shapes and their visualization, along with new test cases to ensure functionality.

Changes

Files Change Summaries
examples/show_swept.py Added functionality to demonstrate the creation and visualization of swept surfaces and solids, including various cross-section shapes.
splinepy/helpme/create.py Expanded the swept function to enhance control over rotation and placement options for sweeping cross-sections along trajectories.
tests/helpme/test_create.py Introduced test functions to validate swept spline functionality and compare with extruded surfaces.
splinepy/bspline.py Minor code cleanup in the remove_knots method by removing unnecessary whitespace.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExampleScript as show_swept.py
    participant SplinePy as splinepy.create.py
    participant Visualizer as gustaf

    User->>ExampleScript: Run script
    ExampleScript->>SplinePy: Call swept(cross_section, trajectory)
    SplinePy-->>ExampleScript: Return swept_surface
    ExampleScript->>Visualizer: Visualize trajectory, cross-section, and swept_surface
    ExampleScript->>User: Display result

Poem

In the world of splines, a tale unfolds,
With trajectories swept, new wonders are told.
From cross-sections fine, surfaces arise,
Visualized with care, they dazzle the eyes.
Through math so advanced, they weave and entwine,
Splines of beauty, intricate by design.
🎨✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
OberGue commented 2 months ago

@coderabbitai generate pytest-file for the sweeping routine

coderabbitai[bot] commented 2 months ago

[!TIP] For best results, initiate chat on the files or code changes.

@OberGue, here is the pytest file for the swept function in splinepy/helpme/create.py:

import pytest
import numpy as np
from splinepy import BSpline, NURBS
from splinepy.helpme.create import swept

def test_swept_basic_functionality():
    cross_section = BSpline(
        degrees=[2],
        control_points=[[0, 0], [0.5, 1], [1, 0]],
        knot_vectors=[[0, 0, 0, 1, 1, 1]]
    )
    trajectory = BSpline(
        degrees=[3],
        control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
        knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]]
    )
    result = swept(cross_section, trajectory)
    assert result is not None
    assert result.control_points.shape[0] == cross_section.control_points.shape[0] * trajectory.control_points.shape[0]

def test_swept_with_custom_normal():
    cross_section = BSpline(
        degrees=[2],
        control_points=[[0, 0], [0.5, 1], [1, 0]],
        knot_vectors=[[0, 0, 0, 1, 1, 1]]
    )
    trajectory = BSpline(
        degrees=[3],
        control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
        knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]]
    )
    custom_normal = np.array([0, 1, 0])
    result = swept(cross_section, trajectory, cross_section_normal=custom_normal)
    assert result is not None

def test_swept_invalid_inputs():
    cross_section = BSpline(
        degrees=[2],
        control_points=[[0, 0], [0.5, 1], [1, 0]],
        knot_vectors=[[0, 0, 0, 1, 1, 1]]
    )
    invalid_trajectory = "invalid_trajectory"
    with pytest.raises(NotImplementedError):
        swept(cross_section, invalid_trajectory)

    invalid_cross_section = "invalid_cross_section"
    trajectory = BSpline(
        degrees=[3],
        control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
        knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]]
    )
    with pytest.raises(NotImplementedError):
        swept(invalid_cross_section, trajectory)

def test_swept_rational_splines():
    cross_section = NURBS(
        degrees=[2],
        control_points=[[0, 0], [0.5, 1], [1, 0]],
        weights=[1, 0.5, 1],
        knot_vectors=[[0, 0, 0, 1, 1, 1]]
    )
    trajectory = NURBS(
        degrees=[3],
        control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
        weights=[1, 0.5, 0.5, 1],
        knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]]
    )
    result = swept(cross_section, trajectory)
    assert result is not None
    assert result.is_rational

This test suite includes:

Feel free to run these tests and let me know if any adjustments are needed!

Analysis chain --- ---
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Search for the `swept` function in `splinepy/helpme/create.py` ast-grep --lang python --pattern $'def swept($_, $_, $_):' splinepy/helpme/create.py ``` Length of output: 85 --- --- Script: ```shell #!/bin/bash # Search for all function definitions in `splinepy/helpme/create.py` ast-grep --lang python --pattern $'def $_($_):' splinepy/helpme/create.py ``` Length of output: 74 --- --- Script: ```shell #!/bin/bash # List the contents of the `splinepy/helpme/` directory to verify `create.py` exists ls splinepy/helpme/ # Display the contents of `create.py` if it exists if [ -f splinepy/helpme/create.py ]; then cat splinepy/helpme/create.py fi ``` Length of output: 41109
OberGue commented 1 week ago

@coderabbitai update the sequence diagram

coderabbitai[bot] commented 1 week ago

[!TIP] For best results, initiate chat on the files or code changes.

@OberGue, here is the updated sequence diagram for the swept function:

sequenceDiagram
    participant User
    participant SweptFunction as swept()
    participant Spline as Spline
    participant Numpy as np
    participant Log as log

    User->>SweptFunction: Call swept(cross_section, trajectory, ...)
    SweptFunction->>Spline: Validate cross_section and trajectory
    SweptFunction->>Numpy: Set default cross_section_normal if None
    SweptFunction->>SweptFunction: Initialize transformation matrices
    SweptFunction->>Spline: Calculate tangent vectors and B-vectors
    SweptFunction->>SweptFunction: Calculate rotation matrix for cross_section
    SweptFunction->>SweptFunction: Perform sweeping process
    SweptFunction->>Spline: Handle rational splines if applicable
    SweptFunction->>User: Return swept_spline

This diagram captures the key steps and interactions within the swept function. Let me know if any further adjustments are needed!

Analysis chain
Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Extract the implementation of the `swept` function from `splinepy/helpme/create.py` ast-grep --lang python --pattern $'def swept($_, $_, $_, $_, $_):\n $$$' splinepy/helpme/create.py ``` Length of output: 19056
OberGue commented 1 week ago

Tip

For best results, initiate chat on the files or code changes.

@OberGue, here is the updated sequence diagram for the swept function:

sequenceDiagram
    participant User
    participant SweptFunction as swept()
    participant Spline as Spline
    participant Numpy as np
    participant Log as log

    User->>SweptFunction: Call swept(cross_section, trajectory, ...)
    SweptFunction->>Spline: Validate cross_section and trajectory
    SweptFunction->>Numpy: Set default cross_section_normal if None
    SweptFunction->>SweptFunction: Initialize transformation matrices
    SweptFunction->>Spline: Calculate tangent vectors and B-vectors
    SweptFunction->>SweptFunction: Calculate rotation matrix for cross_section
    SweptFunction->>SweptFunction: Perform sweeping process
    SweptFunction->>Spline: Handle rational splines if applicable
    SweptFunction->>User: Return swept_spline

This diagram captures the key steps and interactions within the swept function. Let me know if any further adjustments are needed! Analysis chain Scripts executed

@coderabbitai Please be more superficial. Additionally, I only want the columns "user", "show_swept" and "create-file"

coderabbitai[bot] commented 1 week ago

[!TIP] For best results, initiate chat on the files or code changes.

@OberGue, I've simplified the sequence diagram as requested, focusing only on the interactions between the "user", "show_swept", and "create-file" columns:

sequenceDiagram
    participant User
    participant ShowSwept as show_swept.py
    participant CreateFile as create.py

    User->>ShowSwept: Call show_swept.py
    ShowSwept->>CreateFile: Call swept() from create.py
    CreateFile->>ShowSwept: Return swept_spline
    ShowSwept->>User: Display results

This diagram now captures the key interactions between the user, the show_swept.py file, and the create.py file where the swept function is defined. Let me know if any further adjustments are needed!

j042 commented 3 hours ago

Good progress! If you are done with comments, can you please resolve the conversations? Feel free to leave a note if needed