Giter Site home page Giter Site logo

pythonocc-utils's Introduction

Build Status

pythonocc-utils

A python package that provides useful classes/methods for pythonocc

pythonocc-utils's People

Contributors

adamlange avatar aothms avatar dbbh avatar jf--- avatar tanneguydv avatar tnakaicode avatar tpaviot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pythonocc-utils's Issues

How to Extract center point coordinate of a solid from a STEP file

i am trying to get coordinates of the shapes i have in the STEP file ex( vertex , center point).
using the pythonocc-core library what i did was to:
1- read step file
2- read shape -> returns 1 shape
3- from that shape i want to get the solids ( from topods_Solid)
how can i get properties of the solid shape , or how to get the faces, edges in that solid in order to get its properties from step file
how can i use the pythononcc-utils to do such thing

Error with the edge class

Hi I am having issues with the new occutil. Receiving this error when I ran the Edge class project_vertex function. I realise its got to do with the curve handle function. The curve handle is not returning the curve handle.

@Property
def curve_handle(self):
if self._curve_handle is not None and not self.is_dirty:
return self._curve_handle
else:
return None
File "C:\Anaconda2\envs\envuo\lib\site-packages\OCCUtils\edge.py", line 324, in project_vertex
poc = GeomAPI_ProjectPointOnCurve(pnt_or_vertex, self.curve_handle)
File "C:\Anaconda2\envs\envuo\lib\site-packages\OCC\GeomAPI.py", line 1574, in init
_GeomAPI.GeomAPI_ProjectPointOnCurve_swiginit(self, _GeomAPI.new_GeomAPI_ProjectPointOnCurve(*args))
ValueError: invalid null reference in method 'new_GeomAPI_ProjectPointOnCurve', argument 2 of type 'Handle_Geom_Curve const &'

I am having issue when I use intersect fucntion of the Intersect class. It should work if the code is
face_curve_intersect.Next() instead of next(face_curve_intersect)

File "C:\Anaconda2\envs\envuo\lib\site-packages\OCCUtils\edge.py", line 53, in intersect
next(face_curve_intersect)
TypeError: BRepIntCurveSurface_Inter object is not an iterator

Curvature Calculation Inaccurate for B-Spline Curves in DiffGeomCurve Class

Description:

The current implementation of the curvature function in the DiffGeomCurve class from OCC.Utils.edge_py appears to provide inaccurate results when applied to B-spline curves. While the function successfully calculates curvature for circular edges, it consistently returns a value of 0 for B-spline curves, indicating inaccurate behavior.

Steps to Reproduce:

  1. Obtain the attached TXT file (sin_curve.txt) containing a B-spline representation of a sine curve.
  2. Change the file extension from .txt to .step.
  3. Load the STEP file using pythonocc.
  4. Obtain the curvature of the B-spline curve using the curvature function from the DiffGeomCurve class.

Expected Behavior:

The curvature function should accurately compute the curvature of B-spline curves, providing meaningful non-zero values consistent with the curvature of the curve at various points.

Actual Behavior:

The curvature function consistently returns 0 when applied to B-spline curves, while it correctly computes curvature for circular edges. This discrepancy indicates inaccurate behavior specific to B-spline curves.

Code Snippet:

from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_EDGE
from OCC.Core.GCPnts import GCPnts_UniformAbscissa
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.TDF import TDF_LabelSequence

from OCCUtils.edge import Edge


doc = TDocStd_Document("pythonocc-doc")
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main())

step_reader = STEPCAFControl_Reader()
step_reader.SetNameMode(True)

status = step_reader.ReadFile("sin_curve.step")
if status != IFSelect_RetDone:
    raise IOError("Failed to read STEP file")

step_reader.Transfer(doc)
labels = TDF_LabelSequence()
shape_tool.GetFreeShapes(labels)

shape = shape_tool.GetShape(labels.Value(1))

explorer = TopExp_Explorer(shape, TopAbs_EDGE)
while explorer.More():
    edge = explorer.Current()
    curve_adaptor = BRepAdaptor_Curve(edge)
    curve_edge = Edge(edge)
    curvatures = []
    _lower_bound, _upper_bound = curve_adaptor.FirstParameter(), curve_adaptor.LastParameter()

    num_eval_points = 100
    npts = GCPnts_UniformAbscissa(curve_adaptor, num_eval_points, _lower_bound, _upper_bound)
    if npts.IsDone():
        for i in range(1, npts.NbPoints() + 1):
            param = npts.Parameter(i)
            curvature = curve_edge.DiffGeom.curvature(param)
            curvatures.append(curvature)
            # Print or store the curvature value at each evaluation point
            print("Parameter:", param, "Curvature:", curvature)

    # Print all curvature values calculated for the current edge
    print("Curvatures for current edge:", curvatures)

    explorer.Next()

Geometry File:

Changed the file ending to .txt as Github doesn't allow uploads of .step files.
Attached TXT file: sin_curve.txt

Any assistance from the community in diagnosing and resolving this issue would be greatly appreciated. Thank you in advance for your help!

installing pythonocc-utils in pythonocc conda environment: "no module named Common"

Hello, I have pythonocc-core installed in an anaconda environment and it is a pleasure to use (though with a very steep learning curve as I had never manipulated CAD files/drawing before and am few months old in python).
conda create -n pythonocc -c pythonocc -c dlr-sc pythonocc-core==0.17.2 python=3
In my activated pythonocc environment
source activate pythonocc
I've cloned pythonocc-utils, navigated to its root directory and:
pip install ./pythonocc-utils
I can verify that OCCutils is correctly in my current conda environment:
conda list
does show me this line
OCCUtils-0.1 dev <pip>
But in a python console,
>>> import OCCUtils
returns

  File "<stdin>", line 1, in <module>
  File "~/Python/DataVisualization/CADRelated/pythonocc-utils-master/OCCUtils/__init__.py", line 1, in <module>
    from Common import get_boundingbox
ImportError: No module named 'Common'

same if I try import Common.
So I've uninstalled OCCutils
pip uninstall OCCutils
and tried
python setup.py install
but with the same outcome (both installation methods seem to be equivalent).
It's much more likely that I'm not correctly installing the module rather than an issue with the module itself, but could you please help or comment on my issue?

Runtime error in edge.py

I get a runtime error calling the is_line function in Utils' edge.py

b = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
t = Topo(b)
ed = next(t.edges())
my_e = Edge(ed)
print(my_e.is_line())

return self.adaptor.NbKnots()
RuntimeError: Standard_NoSuchObject
GeomAdaptor_Curve::NbKnots
wrapper details:

  • symname: Adaptor3d_Curve_NbKnots
  • wrapname: _wrap_Adaptor3d_Curve_NbKnots
  • fulldecl: Standard_Integer Adaptor3d_Curve::NbKnots()

OCCUtils, Common, point_in_solid Function Issue

Hello everyone, and hope for your well-being.

I faced a problem when I tried to use the point_in_solid function from OCCUtils.
Actually, sometimes when I use this function with a shape (indeed it is an IfcSpace) and a point (which I know is inside the shape), it returns "False" (as the point is not in the shape!!).

Does anyone know what the problem is? Actually, I test this function with several points and several shapes and I do not know why it returns erroneous values.
One more thing; what is the geometry data that defines a TopoDS_Shape?! Is that a Mesh that surrounds the shape?
Thank you.

import ifcopenshell
import ifcopenshell.geom
import OCC.Core
from OCCUtils.Common import point_in_solid
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Trsf

ifc_file = ifcopenshell.open(r'C:\Users\PATH\MyProject3.ifc')
space = ifc_file.by_guid('1YaheuayH6kBI6D9$zc5YL')

settings = ifcopenshell.geom.settings()
settings.set(settings.USE_PYTHON_OPENCASCADE, True)

product = ifcopenshell.geom.create_shape(settings, space)
aShape = OCC.Core.TopoDS.TopoDS_Shape(product.geometry)

thePoint = gp_Pnt(2.6644,-0.5839,15)

print(point_in_solid(aShape, thePoint))      ### Should return True, but returns False!

Here is the out put of the code:
Capture

Error in Common/smooth_pnts function

def smooth_pnts(pnts):
    smooth = [pnts[0]]
    for i in range(1, len(pnts)-1):
        prev = pnts[i-1]
        this = pnts[i]
        next_pnt = pnts[i+1]
        pt = (prev+this+next_pnt) / 3.0
        smooth.append(pt)
    smooth.append(pnts[-1])
    return smooth

This function is from pythonocc-utils/Common.py. The line:
pt = (prev+this+next_pnt) / 3.0

throws this error:
TypeError: unsupported operand type(s) for /: 'gp_Pnt' and 'float'.

It seems to be trying to divide a sum of points by a float? Not sure what is suppose to be happening here. Any help is appreciated!

No packaged version available

I'm trying to install this, and it appears no packaged version is available, either in anaconda or pypi.

It'd be nice if there was a way to install without needing to manually clone and install it.

issues when running the example occutils_geomplate.py

With occutils properly installed, the option "solve radius" in the drop down menu ("geom plate") returns:
AttributeError: 'RadiusConstrainedSurface' object has no attribute 'curr_radius'
And the option "build curve network" exits with a segmentation core failing to build the geom plate surface, when, upon importing IGES data, "At least one shape in IGES cannot be transfered".
In order for occutils_geomplate.py to properly execute "solve_radius", change the following:

  • uncomment line 263 (reason for the AttributeError)
  • change line 236 from if isinstance(z, types.FloatType): to if isinstance(z, float):
  • change line 243 from radius = radius_at_uv(self.plate, uv.X(), uv.Y()) to radius = radius_at_uv(self.plate, uv[0], uv[1])

There's an example core_geometry_geomplate.py in pythonocc-core-master/examples with what seems to be identical functions, does it mean that the whole pythonocc-utils module have been included into pythonocc-core?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.