8000 Add numpy support to OCC array types; fixes in Qt backend by jnwalther · Pull Request #1381 · tpaviot/pythonocc-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add numpy support to OCC array types; fixes in Qt backend #1381

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 4 commits into from
Nov 9, 2024

Conversation

jnwalther
Copy link
Contributor
@jnwalther jnwalther commented Nov 7, 2024

This PR adds support to convert selcted OCC array types to numpy and vice versa. Array types covered are found on the Poly, TColgp, TColStd and TShort modules in OCC.Core. The interface is implenented via the from_numpy_array and to_numpy_array methods. Additionally, fast evaluation of Geom[2d]_Curve and Geom_Surface objects using numpy is provided, via the eval_numpy_array method.

Tests for the numpy interfaces are provided in test/test_core_numpy.py.

Furthermore, two minor fixes to the Qt backend are supplied related to #1363 and a side-effect where the global log level is inadvertently changed.

Tests are provided in test/test_display_sideeffects.py.

Summary by Sourcery

Introduce numpy support for selected OCC array types and enhance Geom[2d]_Curve and Geom_Surface evaluation with numpy. Fix minor issues in the Qt backend and add corresponding tests.

New Features:

  • Add support for converting selected OCC array types to and from numpy arrays, covering modules such as Poly, TColgp, TColStd, and TShort in OCC.Core.
  • Implement fast evaluation of Geom[2d]_Curve and Geom_Surface objects using numpy via the eval_numpy_array method.

Bug Fixes:

  • Fix issues in the Qt backend related to global log level changes and other minor bugs.

Tests:

  • Add tests for the new numpy interfaces in test/test_core_numpy.py.
  • Include tests for the Qt backend fixes in test/test_display_sideeffects.py.

Copy link
sourcery-ai bot commented Nov 7, 2024

Reviewer's Guide by Sourcery

This PR implements numpy array support for OCC array types and adds fast evaluation methods for geometric objects. The implementation is done through SWIG interface files and includes comprehensive test coverage. Additionally, it fixes two issues in the Qt backend related to logging and application instance handling.

Class diagram for updated OCC array types with numpy support

classDiagram
    class NCollection_Array1 {
        +int Lower()
        +int Upper()
        +int Length()
        +T Value(int index)
        +void SetValue(int index, T value)
        +void AddDataFromNumpyArray(array_dtype* numpyArray1, int nRows1)
        +void BuildNumpyArray(array_dtype* numpyArray1Argout, int nRows1Argout)
        +from_numpy_array(cls, arr)
        +to_numpy_array()
    }
    class NCollection_Array2 {
        +void AddDataFromNumpyArray(array_dtype* numpyArray2, int nRows2, int nCols2)
        +void BuildNumpyArray(array_dtype* numpyArray2Argout, int aSizeArgout, int nRows2Argout, int nCols2Argout)
        +from_numpy_array(cls, arr)
        +to_numpy_array()
    }
    class Geom_Curve {
        +void evalNumpy(double* numpyArrayU, int nRowsU, double* numpyArrayResultArgout, int aSizeArgout, int nDimsResult)
        +void evalDerivativeNumpy(double* numpyArrayU, int nRowsU, double* numpyArrayResultArgout, int aSizeArgout, int nDimsResult, int nU)
        +eval_numpy_array(u_arr)
        +eval_derivative_numpy_array(u_arr, n_u)
    }
    class Geom_Surface {
        +void evalNumpy(double* numpyArrayUV, int nRowsUV, int nColUV, double* numpyArrayResultArgout, int aSizeArgout, int nDimsResult)
        +void evalDerivativeNumpy(double* numpyArrayUV, int nRowsUV, int nColUV, double* numpyArrayResultArgout, int aSizeArgout, int nDimsResult, int nU, int nV)
        +eval_numpy_array(u_arr)
        +eval_derivative_numpy_array(u_arr, n_u)
    }
    NCollection_Array1 <|-- NCollection_Array2
    Geom_Curve <|-- Geom_Surface
Loading

Class diagram for Qt backend fixes

classDiagram
    class QApplication {
        +instance()
        +QApplication(sys.argv)
    }
    class MainWindow {
        +resize(int width, int height)
        +show()
    }
    class Logger {
        +setLevel(logging.DEBUG)
    }
    QApplication <|-- MainWindow
    Logger <|-- QApplication
Loading

File-Level Changes

Change Details Files
Added numpy array conversion support for OCC array types
  • Implemented from_numpy_array and to_numpy_array methods for array conversion
  • Added support for 1D and 2D array types
  • Created array macros for different data types (2D/3D points, vectors, etc.)
  • Added numpy array support for standard types (Integer, Real, ShortReal)
src/SWIG_files/wrapper/TColgp.i
src/SWIG_files/wrapper/TColStd.i
src/SWIG_files/wrapper/TShort.i
src/SWIG_files/wrapper/Poly.i
src/SWIG_files/common/ArrayMacros.i
Implemented fast evaluation methods using numpy arrays
  • Added eval_numpy_array method for curves and surfaces
  • Added eval_derivative_numpy_array for derivative evaluation
  • Implemented array evaluation for both 2D and 3D geometries
src/SWIG_files/wrapper/Geom.i
src/SWIG_files/wrapper/Geom2d.i
Fixed Qt backend issues
  • Prevented inadvertent global log level changes
  • Fixed application instance handling for Qt backend
  • Added tests to verify display functionality
src/Display/SimpleGui.py
src/Display/qtDisplay.py
test/test_display_sideeffects.py
Added comprehensive test coverage
  • Created tests for numpy array conversion
  • Added tests for geometric evaluation methods
  • Implemented tests for Qt backend fixes
test/test_core_numpy.py
test/test_display_sideeffects.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jnwalther - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jf---
Copy link
Contributor
jf--- commented Nov 7, 2024

wonderful contribution @jnwalther!!

@jnwalther
Copy link
Contributor Author
jnwalther commented Nov 7, 2024

Thanks @jf---. I hope everything will work out. I'm slightly concerned about the issues reported by codacy. As far as I'm aware assert statements are common practice in pytest-style tests.

@jnwalther
Copy link
Contributor Author

Ok, so it seems there is an issue with the new display tests on the Ubuntu machines. I tried to reproduce the error running on my personal Linux laptop (not Ubuntu but Arch), but I couldn't, so I doubt it's a general Linux issue. From the error message I gather that it has something to do with the way Qt is set up on the system.

My suggestion would be to simply skip the tests for linux platform. I couldn't find any indication that the previously existing core_display_* unittests were running, so I'm not even sure if the tests would have worked in the first place. What do you guys think?

To fix the assert topic this looks promising.

@tpaviot
Copy link
Owner
tpaviot commented Nov 8, 2024

Thank you for this huge work @jnwalther I need time to review your contribution and add it as a rule to the pythonocc-generator

@jnwalther
Copy link
Contributor Author

Thank you @tpaviot, please take your time. Let me know if you have any questions.

@tpaviot tpaviot merged commit 6e079c5 into tpaviot:master Nov 9, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0