Reputation: 20130
All
have file from CAD (SW) in STEP format and was able to read it via Python OCC binding:
importer = aocxchange.step.StepImporter(fname)
shapes = importer.shapes
shape = shapes[0]
# promote up
if (shape.ShapeType() == OCC.TopAbs.TopAbs_SOLID):
sol = OCC.TopoDS.topods.Solid(shape)
I could display it, poke at it, check flags etc
t = OCC.BRepCheck.BRepCheck_Analyzer(sol)
print(t.IsValid())
print(sol.Checked())
print(sol.Closed())
print(sol.Convex())
print(sol.Free())
print(sol.Infinite())
So far so good. It really looks like small tube bent along some complex path.
Question: how I could extract geometry features from what I have? I really need tube parameters and path it follows. Any good example in Python and/or C++ would be great
Upvotes: 4
Views: 2641
Reputation: 535
In OpenCASCADE there's a separation between topology and geometry. So, usually your first contact will be the topological entities (i.e.: TopoDS_Wire or a TopoDS_Edge), that can give you access to the geometry (take a look here for more details).
In your case, after reading the STEP file you ended up with a TopoDS_Shape. This is the highest level topological entity and most probably is formed by one or more sub-shapes.
Assuming that your shape is formed by a bspline curve (it seems to be!), you could explore the shape, looking for TopoDS_Edge objects (they are the topological entities that map to geometric curves):
TopExp_Explorer myEdgeExplorer(shape, TopAbs_EDGE);
while (myEdgeExplorer.More())
{
double u0, u1;
auto edge = TopoDS::Edge(myEdgeExplorer.Current());
auto curve = BRep_Tool::Curve(edge, u0, u1);
// now you have access to the curve ...
// to get a point lying on it, check
// the method curve->Value(u);
myEdgeExplorer.Next();
}
Upvotes: 6