Reading STEP entity id slow ?

Hello All,

I need to get the id of step entities, as this is used to reference information outside the STEP file,
e.g. the BW_123 from #33=OPEN_SHELL('BW_123',(#79)) ;

The lookup of this information takes ages compared with all other operation.

Loading my reference file containing ~10.000 faces into a document takes about 2 minutes,
creating a map containing the name and the shape about 45 minutes, doing the aktual work another 2 minutes.

The loop over the shapes itself takes less than a second, the code to access the id is taken from examples found in the forum.

Are there ideas how to speed this up a bit ?

Thank you, Carsten

 

for (TopExp_Explorer shellExplorer(shape, TopAbs_SHELL); shellExplorer.More(); shellExplorer.Next()) {
        const TopoDS_Shell& shell = TopoDS::Shell(shellExplorer.Current());

        // Get the name of the STEP Entity
        Standard_CString shapeName = "";
        Handle(Standard_Transient) anEntity =  aTransferReader->EntityFromShapeResult(shell, 1);

        if (anEntity.IsNull()) {
            // as just mapped
            anEntity = aTransferReader->EntityFromShapeResult(shell, -1);
        }

        if (anEntity.IsNull()) {
            // as anything
            anEntity = aTransferReader->EntityFromShapeResult(shell, 4);
        }

        if (anEntity.IsNull()) {
            GLOG(INFO) << "Warning: XSControl_TransferReader::EntityFromShapeResult(shapeResult) entity not found (NULL)";          
        } else {
            // use StepRepr_RepresentationItem for solids, faces and compound (geometric_set)
            Handle(StepRepr_RepresentationItem) aReprItem;
            aReprItem = Handle(StepRepr_RepresentationItem)::DownCast(anEntity);

            if (aReprItem.IsNull()) {
                GLOG(INFO) << "Warning:  XSControl_TransferReader::EntityFromShapeResult(shapeResult) : "
                    << "StepRepr_RepresentationItem Is NULL, entity type was: " << anEntity->DynamicType() << endl;

                // use StepRepr_Representation for some compounds like e.g. ManifoldSurfaceShapeRepresentation, StepShape_AdvancedBrepShapeRepresentation
                Handle(StepRepr_Representation) ent;
                ent = Handle(StepRepr_Representation)::DownCast(anEntity);
                if (ent.IsNull()) {
                    GLOG(INFO) << "Error:  XSControl_TransferReader::EntityFromShapeResult(shapeResult) : "
                        << "StepRepr_Representation also is NULL, entity type was: " << anEntity->DynamicType() << endl;
               } else {
                    shapeName = ent->Name()->ToCString();
                    id = ent->GetRefCount();
                }
            }  else {
                shapeName = aReprItem->Name()->ToCString();
                id = aReprItem->GetRefCount();
            }
        }
  

 

 

Carsten Zerbst's picture

Hello All,

just out of curiosity I tried it the other way round (from STEP Entity to TopoDS_Shape) and the speed up is tremendously.

I still have no idea, why shape -> entity is that slow, but with the code below the overall time is ok.

Bey, Carsten

    const Handle(XSControl_WorkSession) workSession = stepReader.Reader().WS();
    const Handle(Interface_InterfaceModel) model = workSession->Model();
    const Handle(XSControl_TransferReader) transferReader =
        workSession->TransferReader();
    Handle(Transfer_TransientProcess) transProc = transferReader->TransientProcess();

    Standard_Integer nb = model->NbEntities();
    for (Standard_Integer i = 1; i < nb; i++) {
        Handle(Standard_Transient) entity = model->Value(i);

        if (!entity->DynamicType()->SubType("StepShape_OpenShell")) continue;

        Handle(StepRepr_RepresentationItem) SRRI =
            Handle(StepRepr_RepresentationItem)::DownCast(entity);

        if (SRRI.IsNull()) {
            GLOG(WARNING) << "no StepRepr_RepresentationItem found in " << entity->DynamicType()->Name();
            continue;
        }

        Handle(TCollection_HAsciiString) hName = SRRI->Name();
        string shapeName = hName->ToCString();

        GLOG(INFO) << "STEP " << i << " " << entity->DynamicType()->Name() << " " << shapeName;     

        Handle(Transfer_Binder) binder;
        if (!transProc->IsBound(SRRI)) {
            GLOG(WARNING) << "found unbound entity " << shapeName;
            continue;
        }
        binder = transProc->Find(SRRI);
        TopoDS_Shape shape = TransferBRep::ShapeResult(binder);

leo lei's picture

Hi.
The SubType("StepShape_OpenShell")) is for TopoDS_Shell type. Do you know which type is used to recognize TopoDS_Solid and TopoDS_Compound?
Thank you in advance.

Benjamin Bihler's picture

I guess that EntityFromShapeResult() searches the whole model until it finds the shape. Doing that in a for loop for every shape means really a lot of effort.

Benjamin

jason jiang's picture

Hi,
in your scond part of sample code,is the stepReader instance of STEPCAFControl_Reader?how to get it?or is it can load from a step file?such as stepReader.ReadFile("D:\\test\\sample.step")?
the code:Standard_Integer nb = model->NbEntities();for (Standard_Integer i = 1; i < nb; i++);the i is not the id of an entity is a step file?
thanks
Jason

jason jiang's picture

Hi:
if open a STEP file,determined a shape by OCC,then,how to find it in Step file?such as below code:
TopExp_Explorer Ex;
for (Ex.Init(pickup, TopAbs_FACE); Ex.More(); Ex.Next())
{
TopoDS_Face face = TopoDS::Face(Ex.Current());
}
I want find face in step file,get the ID and other information.
I try to find by below code(searchshape is the TopoDS_Shape in OCC):
const Handle(XSControl_TransferReader) &aTR = aReader.Reader().WS()->TransferReader();
const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
const Interface_Graph& aGraph = aTP->Graph();
// i is internal index
for (int i = 1; i <= nb; i++)
{
const Handle(Standard_Transient)& anEntity = aModel->Value(i);
Handle(Transfer_Binder) binder;
binder = aTP->Find(anEntity);
if (binder.IsNull()) {
continue;
}
TopoDS_Shape shape = TransferBRep::ShapeResult(binder);
if (shape.IsSame(searchshape)) {
AfxMessageBox(_T("found"));
}
}
but can not find it,then,what is wrong?
could you give a right solution?
thansk
Jason.Jiang

Dmitrii Pasukhin's picture

Hi,

I think there can be a problem with location. To get pure faces from the model, please try the next code.

  TopTools_IndexedMapOfShape aSubMap;
  TopExp::MapShapes(aRes, TopAbs_FACE, aSubMap);
  for (TopTools_IndexedMapOfShape::Iterator aShapeIt(aSubMap); aShapeIt.More(); aShapeIt.Next())
  {
    const TopoDS_Shape& aShape = aShapeIt.Value();
    ...
  }

Or for test proposal clear location for toFind and toCheckShapes

  TopLoc_Location anEmptyLoc;
  searchshape.Location(anEmptyLoc);
  ...
  TopoDS_Shape aMovedShape = shape.Located(anEmptyLoc);
  // working with aMovedShape

Or checking not for the "IsSame". You can check using "IsPartner" to check only TShape. "IsEqual" - to check full equal.

Best regards, Dmitrii.

jason jiang's picture

Hi,Dmitrii:
Thanks for your reply and suggestion.
I tested serveral STEP/STP files by your suggestion,check all of code and file path carefully,but still can not find right entity from STEP file which confirmed relative TopoDS_shape object in OCC.whats wrong?or any other suggestion?
Best Regards
Jason.Jiang

Dmitrii Pasukhin's picture

You try to find shape within one session? It means you receive shape from step and then you try to find it from the model(the equal model, which was used for getting shape for search)? Or you try to find shape in the differ sessions?

Best regards, Dmitrii.

jason jiang's picture

Hi:
My test step as this:first,I import TopoDS_Shape of Step File into OCC,it can show right there.I get a sub-object such as FACE,WIRE,EDGE ect of this TopoDS_Shape showed in OCC,then,I hope to find this sub-object in the just imported STEP file,so,I can confirm which ID of this sub-object in STEP file,by this way,I can also get the other information.
but it is disappointed that I can find the right sub-object in STEP file by your suggestion.
so,a other suggestion.
Thanks
Jason

Liu Guang Yin's picture

After "STEPControl_Reader reader;reader.ReadFile("...") ;"
Please call "reader.TransferRoots();"