Hello Benjamin, I hope my comments help. Fredric Dorothy
On Thu, Jun 30, 2011 at 3:57 PM, Benjamin Turner <[email protected]> wrote: > Hello, > > I've asked before but I'm still having some trouble understanding the nature > of edges in PythonOCC and OCC in general. I am trying to discretize all of > the edges in an IGES model and generate (x, y, z) values for each curve. > I'd then like to print this to a file. Basically, I want to discretize > every single edge of 3D object. I had written a script a few months ago to generate a triangle mesh from all faces of an IGES file and write out an STL file. The script used the StdMeshers_* classes in SMESH (some vaguely-related documentation here from the Salome project: http://docs.salome-platform.org/salome_6_3_0/smesh/tui/SMESH/namespaceStdMeshers.html). I assume that you could take out the 2D hypothesis in this script to generate only points along the edges, although I haven't tried that myself yet. import sys from OCC.ShapeFix import * from OCC.SMESH import * from OCC.StdMeshers import * from OCC.IGESControl import * def load_iges(filename): """ Loads an IGES file and returns a shape. """ i = IGESControl_Controller() i.Init() iges_reader = IGESControl_Reader() iges_reader.ReadFile(filename) iges_reader.TransferRoots() return iges_reader.OneShape() def smesh_triangulate(shape): """ Triangulates a shape using the SMESH module. """ meshGen = SMESH_Gen() mesh = meshGen.CreateMesh(0,True) # 1D hypo1d = StdMeshers_AutomaticLength(0,0,meshGen) # best-guess length spacing algo1d = StdMeshers_Regular_1D(1,0,meshGen) # interpolation # 2D hypo2d = StdMeshers_TrianglePreference(2,0,meshGen) #define the boundary algo2d = StdMeshers_MEFISTO_2D(3,0,meshGen) # the 2D mesh #Calculate mesh mesh.ShapeToMesh(shape) #Assign hyptothesis to mesh mesh.AddHypothesis(shape,0) mesh.AddHypothesis(shape,1) mesh.AddHypothesis(shape,2) mesh.AddHypothesis(shape,3) #Compute the data meshGen.Compute(mesh,mesh.GetShapeToMesh()) return mesh if __name__ == '__main__': shape = load_iges(sys.argv[1]) mesh = smesh_triangulate(shape) mesh.ExportSTL(sys.argv[2], True) > > I have looked at: http://www.opencascade.org/org/forum/thread_9874/ and I > have looked at BRepAdaptor_Curve, BRepAdaptor_CompCurve, > CPnts_UniformDeflection and CPnts_AbscissaPoint. I found another post too at > http://www.opencascade.org/org/forum/thread_20706/ which seems to be almost > exactly what I want to do. Check out the StdMeshers_* classes in the script above. They worked fine for me. > > I'm assuming for curves (splines, circles, arcs, etc.) I'd want to use > CPnts_UniformDeflection, but I'm guessing this will fail on things that do > not have any deflections, such as lines. What is the ultimate goal? If you just need a rough discretization of the IGES curves then the AutomaticLength 1-D hypothesis will do an OK job. > > Right now I'm converting the IGES file into one giant shape with > OneShape(). Can I still do it this way, or do I need to discretize the > edges before I make it a single shape? I don't believe there is anything wrong with using OneShape(). OneShape() usually just bundles up the individual shapes into a compound shape, so all the shapes are still accessible if you need to work with them individually. > > One last (probably really stupid) question: What is the difference in > OpenCASCADE between a wire and an edge? A wire is a collection of edges. > > Thank you very much for any help. > > Regards, > > Benjamin P. L. Turner > [email protected] > > _______________________________________________ > Pythonocc-users mailing list > [email protected] > https://mail.gna.org/listinfo/pythonocc-users > > _______________________________________________ Pythonocc-users mailing list [email protected] https://mail.gna.org/listinfo/pythonocc-users
