コード例 #1
0
ファイル: CTiglFusePlane.cpp プロジェクト: DLR-SC/tigl
/**
 * @todo: it would be nice if this algorithm would support
 * some progress bar interface
 */
void CTiglFusePlane::Perform()
{
    if (_hasPerformed) {
        return;
    }

    CTiglUIDManager& uidManager = _myconfig.GetUIDManager();
    CTiglAbstractPhysicalComponent* rootComponent = uidManager.GetRootComponent();
    if (!rootComponent) {
        LOG(ERROR) << "Root component of plane not found. Cannot create fused plane.";
        return;
    }

    _result = FuseWithChilds(rootComponent);

    CCPACSFarField& farfield = _myconfig.GetFarField();
    if (farfield.GetFieldType() != NONE && (_mymode == FULL_PLANE_TRIMMED_FF || _mymode == HALF_PLANE_TRIMMED_FF)) {
        PNamedShape ff = farfield.GetLoft();

        BOPCol_ListOfShape aLS;
        aLS.Append(_result->Shape());
        aLS.Append(ff->Shape());

        BOPAlgo_PaveFiller dsfill;
        dsfill.SetArguments(aLS);
        dsfill.Perform();
        CTrimShape trim1(_result, ff, dsfill, INCLUDE);
        PNamedShape resulttrimmed = trim1.NamedShape();

        CTrimShape trim2(ff, _result, dsfill, EXCLUDE);
        _farfield = trim2.NamedShape();

        _result = resulttrimmed;

        // trim intersections with far field
        ListPNamedShape::iterator intIt = _intersections.begin();
        ListPNamedShape newInts;
        for (; intIt != _intersections.end(); ++intIt) {
            PNamedShape inters = *intIt;
            if (!inters) {
                continue;
            }

            TopoDS_Shape sh = inters->Shape();
            sh = BRepAlgoAPI_Common(sh, ff->Shape());
            if (! sh.IsNull()) {
                inters->SetShape(sh);
                newInts.push_back(inters);
            }
        }
        _intersections = newInts;
    }

    if (_result) {
        _result->SetName(_myconfig.GetUID().c_str());
        _result->SetShortName("AIRCRAFT");
    }
    _hasPerformed = true;

}
コード例 #2
0
ファイル: CTiglExportBrep.cpp プロジェクト: gstariarch/tigl
bool CTiglExportBrep::Write(const std::string& filename) const
{
    if (filename.empty()) {
       LOG(ERROR) << "Error: Empty filename in CTiglExportBrep::Write.";
       return false;
    }
    
    if (_shapes.size() > 1) {
        TopoDS_Compound c;
        BRep_Builder b;
        b.MakeCompound(c);
        
        for (ListPNamedShape::const_iterator it = _shapes.begin(); it != _shapes.end(); ++it) {
            PNamedShape shape = *it;
            if (shape) {
                b.Add(c, shape->Shape());
            }
        }
        
        // write the file
        return BRepTools::Write(c, filename.c_str());
    }
    else if ( _shapes.size() == 1) {
        PNamedShape shape = _shapes[0];
        return BRepTools::Write(shape->Shape(), filename.c_str());
    }
    else {
        LOG(WARNING) << "No shapes defined in BRep export. Abort!";
        return false;
    }
}
コード例 #3
0
ファイル: CGroupShapes.cpp プロジェクト: DLR-SC/tigl
CGroupShapes::CGroupShapes(const ListPNamedShape& list)
{
    if (list.size() == 1) {
        _result = list[0];
        return;
    }

    BRep_Builder b;
    TopoDS_Compound c;
    b.MakeCompound(c);

    for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) {
        PNamedShape shape = *it;
        if (!shape) {
            continue;
        }

        b.Add(c, shape->Shape());
    }

    _result = PNamedShape(new CNamedShape(c, "ShapeGroup"));

    // apply face names from the shapes
    for (ListPNamedShape::const_iterator it=list.begin(); it != list.end(); ++it) {
        PNamedShape shape = *it;
        if (!shape) {
            continue;
        }

        CBooleanOperTools::AppendNamesToShape(shape, _result);
    }
}
コード例 #4
0
ファイル: CCPACSWingSegment.cpp プロジェクト: gstariarch/tigl
    // Set the face traits
    void SetFaceTraits (PNamedShape loft) 
    { 
        // designated names of the faces
        std::vector<std::string> names(5);
        names[0]="Bottom";
        names[1]="Top";
        names[2]="TrailingEdge";
        names[3]="Inside";
        names[4]="Outside";

        // map of faces
        TopTools_IndexedMapOfShape map;
        TopExp::MapShapes(loft->Shape(),   TopAbs_FACE, map);

        // check if number of faces is correct (only valid for ruled surfaces lofts)
        if (map.Extent() != 5 && map.Extent() != 4) {
            LOG(ERROR) << "CCPACSWingSegment: Unable to determine face names in ruled surface loft";
            return;
        }
        // remove trailing edge name if there is no trailing edge
        if (map.Extent() == 4) {
            names.erase(names.begin()+2);
        }
        // set face trait names
        for (int i = 0; i < map.Extent(); i++) {
            CFaceTraits traits = loft->GetFaceTraits(i);
            traits.SetName(names[i].c_str());
            loft->SetFaceTraits(i, traits);
        }
    }
コード例 #5
0
ファイル: CTiglExportIges.cpp プロジェクト: hyper123/tigl
/**
 * @briefAdds a shape to the IGES file. All faces are named according to their face
 * traits. If there are no faces, the wires are named according to the shape name.
 * 
 * The level parameter defines the iges layer/level, which is another way of grouping faces.
 */
void CTiglExportIges::AddToIges(PNamedShape shape, IGESControl_Writer& writer, int level) const 
{
    if (!shape) {
        return;
    }
    
    std::string shapeName = shape->Name();
    std::string shapeShortName = shape->ShortName();
    Handle(Transfer_FinderProcess) FP = writer.TransferProcess();
    TopTools_IndexedMapOfShape faceMap;
    TopExp::MapShapes(shape->Shape(),   TopAbs_FACE, faceMap);
    // any faces?
    if (faceMap.Extent() > 0) {
        int ret = writer.AddShape(shape->Shape());
        if (ret > IFSelect_RetDone) {
            throw CTiglError("Error: Export to IGES file failed in CTiglExportStep. Could not translate shape " 
                             + shapeName + " to iges entity,", TIGL_ERROR);
        }
        WriteIgesNames(FP, shape, level);
    }
    else {
        // no faces, export edges as wires
        Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape();
        TopExp_Explorer myEdgeExplorer (shape->Shape(), TopAbs_EDGE);
        while (myEdgeExplorer.More()) {
            Edges->Append(TopoDS::Edge(myEdgeExplorer.Current()));
            myEdgeExplorer.Next();
        }
        ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges, 1e-7, false, Edges);
        for (int iwire = 1; iwire <= Edges->Length(); ++iwire) {
            int ret = writer.AddShape(Edges->Value(iwire));
            if (ret > IFSelect_RetDone) {
                throw CTiglError("Error: Export to IGES file failed in CTiglExportIges. Could not translate shape " 
                                 + shapeName + " to iges entity,", TIGL_ERROR);
            }
            PNamedShape theWire(new CNamedShape(Edges->Value(iwire),shapeName.c_str()));
            theWire->SetShortName(shapeShortName.c_str());
            WriteIGESShapeNames(FP, theWire, level);
            WriteIgesWireName(FP, theWire);
        }
    }
}
コード例 #6
0
ファイル: CTiglExportIges.cpp プロジェクト: hyper123/tigl
// Save a sequence of shapes in IGES Format
void CTiglExportIges::ExportShapes(const ListPNamedShape& shapes, const std::string& filename) const
{
    IGESControl_Controller::Init();

    if ( filename.empty()) {
       LOG(ERROR) << "Error: Empty filename in ExportShapes.";
       return;
    }

    ListPNamedShape::const_iterator it;
    // scale all shapes to mm
    ListPNamedShape shapeScaled;
    for (it = shapes.begin(); it != shapes.end(); ++it) {
        PNamedShape pshape = *it;
        if (pshape) {
            CTiglTransformation trafo;
            trafo.AddScaling(1000,1000,1000);
            PNamedShape pScaledShape(new CNamedShape(*pshape));
            pScaledShape->SetShape(trafo.Transform(pshape->Shape()));
            shapeScaled.push_back(pScaledShape);
        }
    }
    
    ListPNamedShape list;
    for (it = shapeScaled.begin(); it != shapeScaled.end(); ++it) {
        ListPNamedShape templist = GroupFaces(*it, _groupMode);
        for (ListPNamedShape::iterator it2 = templist.begin(); it2 != templist.end(); ++it2) {
            list.push_back(*it2);
        }
    }
    
    SetTranslationParameters();

    IGESControl_Writer igesWriter("MM", 0);
    igesWriter.Model()->ApplyStatic();

    int level = 0;
    for (it = list.begin(); it != list.end(); ++it) {
        PNamedShape pshape = *it;
        AddToIges(pshape, igesWriter, level++);
    }

    igesWriter.ComputeModel();

    if (igesWriter.Write(const_cast<char*>(filename.c_str())) != Standard_True) {
        throw CTiglError("Error: Export of shapes to IGES file failed in CCPACSImportExport::SaveIGES", TIGL_ERROR);
    }
}
コード例 #7
0
PNamedShape CCPACSControlSurfaceDevice::getTransformedFlapShape()
{
    PNamedShape deviceShape = getFlapShape()->DeepCopy();
    gp_Trsf T = GetFlapTransform();
    BRepBuilderAPI_Transform form(deviceShape->Shape(), T);
    deviceShape->SetShape(form.Shape());
    
    // store the transformation property. Required e.g. for VTK metadata
    gp_GTrsf gT(T);
    CTiglTransformation tiglTrafo(gT);
    unsigned int nFaces = deviceShape->GetFaceCount();
    for (unsigned int iFace = 0; iFace < nFaces; ++iFace) {
        CFaceTraits ft = deviceShape->GetFaceTraits(iFace);
        ft.SetTransformation(tiglTrafo);
        deviceShape->SetFaceTraits(iFace, ft);
    }
    
    return deviceShape;
}
コード例 #8
0
ファイル: CFuseShapes.cpp プロジェクト: Felipeasg/tigl
/// This is the actual fusing
void CFuseShapes::DoFuse()
{
    if (!_parent) {
        throw tigl::CTiglError("Null pointer for parent shape in CFuseShapes", TIGL_NULL_POINTER);
    }

    BRepBuilderAPI_Sewing shellMaker;

    _trimmedChilds.clear();
    ListPNamedShape::const_iterator childIter;

    TrimOperation childTrim  = EXCLUDE;
    TrimOperation parentTrim = EXCLUDE;

    // trim the childs with the parent and vice versa
    _trimmedParent = _parent->DeepCopy();
    for (childIter = _childs.begin(); childIter != _childs.end(); ++childIter) {
        const PNamedShape child = *childIter;
        if (!child) {
            continue;
        }

#ifdef DEBUG_BOP
        clock_t start, stop;
        start = clock();
#endif
        BOPCol_ListOfShape aLS;
        aLS.Append(_trimmedParent->Shape());
        aLS.Append(child->Shape());
        BOPAlgo_PaveFiller DSFill;
        DSFill.SetArguments(aLS);
        DSFill.Perform();
#ifdef DEBUG_BOP
        stop = clock();
        printf("dsfiller [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        // calculate intersection
        // Todo: make a new BOP out of this
        TopoDS_Shape intersection = BRepAlgoAPI_Section(_trimmedParent->Shape(), child->Shape(), DSFill);
        PNamedShape intersectionShape(new CNamedShape(intersection, std::string("INT" + std::string(_parent->Name()) + child->Name()).c_str()));
        intersectionShape->SetShortName(std::string("INT" + std::string(_parent->ShortName()) + child->ShortName()).c_str());
        _intersections.push_back(intersectionShape);

#ifdef DEBUG_BOP
        stop = clock();
        printf("intersection [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        _trimmedParent = CTrimShape(_trimmedParent, child, DSFill, parentTrim);

#ifdef DEBUG_BOP
        stop = clock();
        printf("parent split [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);

        start = clock();
#endif
        PNamedShape trimmedChild = CTrimShape(child, _parent, DSFill, childTrim);
        _trimmedChilds.push_back(trimmedChild);

#ifdef DEBUG_BOP
        stop = clock();
        printf("child split [ms]: %f\n", (stop-start)/(double)CLOCKS_PER_SEC * 1000.);
#endif
    } // trimming

    // add trimmed child faces to result
    for (childIter = _trimmedChilds.begin(); childIter != _trimmedChilds.end(); ++childIter) {
        shellMaker.Add((*childIter)->Shape());
    }

    // add trimmed parent faces to result
    shellMaker.Add(_trimmedParent->Shape());
    shellMaker.Perform();

    // make a solid out of the face collection
    TopoDS_Shape shell = shellMaker.SewedShape();


    BRepSewingToBRepBuilderShapeAdapter sewerAdapter(shellMaker);

    // map names to shell
    PNamedShape resultShell(new CNamedShape(shell, "BOP_FUSE"));
    for (childIter = _trimmedChilds.begin(); childIter != _trimmedChilds.end(); ++childIter) {
        const PNamedShape child = *childIter;
        PNamedShape tmpshape(new CNamedShape(*child));
        tmpshape->SetShape(shellMaker.ModifiedSubShape(child->Shape()));
        CBooleanOperTools::MapFaceNamesAfterBOP(sewerAdapter, tmpshape, resultShell);
    }
    PNamedShape tmpshape(new CNamedShape(*_trimmedParent));
    tmpshape->SetShape(shellMaker.ModifiedSubShape(_trimmedParent->Shape()));
    CBooleanOperTools::MapFaceNamesAfterBOP(sewerAdapter, tmpshape, resultShell);

    // map names to solid
    BRepBuilderAPI_MakeSolid solidmaker;
    TopTools_IndexedMapOfShape shellMap;
    TopExp::MapShapes(resultShell->Shape(), TopAbs_SHELL, shellMap);
    for (int ishell = 1; ishell <= shellMap.Extent(); ++ishell) {
        const TopoDS_Shell& shell = TopoDS::Shell(shellMap(ishell));
        solidmaker.Add(shell);
    }

    PNamedShape result(new CNamedShape(solidmaker.Solid(), resultShell->Name()));
    CBooleanOperTools::MapFaceNamesAfterBOP(solidmaker, resultShell, result);

    _resultshape = result;
}
コード例 #9
0
ListPNamedShape GroupFaces(const PNamedShape shape, tigl::ShapeGroupMode groupType)
{
    ListPNamedShape shapeList;
    if (!shape) {
        return shapeList;
    }

    if (groupType == tigl::NAMED_COMPOUNDS) {
        BRep_Builder b;
        TopTools_IndexedMapOfShape faceMap;
        std::map<PNamedShape, TopoDS_Shape> map;
        TopExp::MapShapes(shape->Shape(),   TopAbs_FACE, faceMap);
        if (faceMap.Extent() == 0) {
            // return the shape as is
            shapeList.push_back(shape);
            return shapeList;
        }
        
        for (int iface = 1; iface <= faceMap.Extent(); ++iface) {
            TopoDS_Face face = TopoDS::Face(faceMap(iface));
            PNamedShape origin = shape->GetFaceTraits(iface-1).Origin();

            std::map<PNamedShape, TopoDS_Shape>::iterator it = map.find(origin);
            if (it == map.end()) {
                TopoDS_Compound c;
                b.MakeCompound(c);
                b.Add(c, face);
                map[origin] = c;
            }
            else {
                TopoDS_Shape& c = it->second;
                b.Add(c, face);
            }
        }

        // create Named Shapes
        std::map<PNamedShape, TopoDS_Shape>::iterator it;
        for (it = map.begin(); it != map.end(); ++it) {
            PNamedShape  origin     = it->first;
            TopoDS_Shape toposhape  = it->second;
            PNamedShape curshape;
            if (origin) {
                curshape = PNamedShape(new CNamedShape(toposhape, origin->Name()));
                curshape->SetShortName(origin->ShortName());
            }
            else {
                curshape = PNamedShape(new CNamedShape(toposhape, shape->Name()));
                curshape->SetShortName(shape->ShortName());
            }
            // set the original face traits
            CBooleanOperTools::AppendNamesToShape(shape, curshape);

            // make shells
            curshape = CBooleanOperTools::Shellify(curshape);
            shapeList.push_back(curshape);
        }
    }
    else if (groupType == tigl::WHOLE_SHAPE) {
        shapeList.push_back(shape);
    }
    else if (groupType == tigl::FACES) {
        // store each face as an own shape
        TopTools_IndexedMapOfShape faceMap;
        TopExp::MapShapes(shape->Shape(), TopAbs_FACE, faceMap);
        if (faceMap.Extent() == 0) {
            // return the shape as is
            shapeList.push_back(shape);
            return shapeList;
        }
        
        for (int iface = 1; iface <= faceMap.Extent(); ++iface) {
            TopoDS_Face face = TopoDS::Face(faceMap(iface));
            const CFaceTraits& traits = shape->GetFaceTraits(iface-1);

            PNamedShape faceShape;
            if (traits.Origin()) {
                faceShape = PNamedShape(new CNamedShape(face, traits.Origin()->Name()));
                faceShape->SetShortName(traits.Origin()->ShortName());
            }
            else {
                faceShape = PNamedShape(new CNamedShape(face, shape->Name()));
                faceShape->SetShortName(shape->ShortName());
            }
            faceShape->SetFaceTraits(0, shape->GetFaceTraits(iface-1));
            shapeList.push_back(faceShape);
        }
        
    }
    return shapeList;
}
コード例 #10
0
ファイル: CTiglFusePlane.cpp プロジェクト: DLR-SC/tigl
PNamedShape CTiglFusePlane::FuseWithChilds(CTiglAbstractPhysicalComponent* parent)
{
    assert(parent != NULL);
    
    PNamedShape parentShape (parent->GetLoft());
    if (parentShape) {
        if (_mymode == FULL_PLANE || _mymode == FULL_PLANE_TRIMMED_FF) {
            PNamedShape rootShapeMirr = parent->GetMirroredLoft();
            parentShape = CMergeShapes(parentShape, rootShapeMirr);
        }
    }

    CTiglAbstractPhysicalComponent::ChildContainerType childs = parent->GetChildren(false);
    CTiglAbstractPhysicalComponent::ChildContainerType::iterator childIt;
    
    if (childs.size() == 0) {
        return parentShape;
    }

    ListPNamedShape childShapes;
    for (childIt = childs.begin(); childIt != childs.end(); ++childIt) {
        CTiglAbstractPhysicalComponent* child = *childIt;
        if (!child) {
            continue;
        }

        PNamedShape childShape = FuseWithChilds(child);
        childShapes.push_back(childShape);
    }
    CFuseShapes fuser(parentShape, childShapes);
    PNamedShape result = fuser.NamedShape();

    // trim previous intersections
    ListPNamedShape::iterator intIt = _intersections.begin();
    ListPNamedShape newInts;
    for (; intIt != _intersections.end(); ++intIt) {
        PNamedShape inters = *intIt;
        if (!inters) {
            continue;
        }

        TopoDS_Shape sh = inters->Shape();
        if (parentShape) {
            sh = BRepAlgoAPI_Cut(sh, parentShape->Shape());
        }
        if (!sh.IsNull()) {
            inters->SetShape(sh);
            newInts.push_back(inters);
        }
    }
    _intersections = newInts;

    // insert intersections
    ListPNamedShape::const_iterator it = fuser.Intersections().begin();
    for (; it != fuser.Intersections().end(); it++) {
        if (*it) {
            _intersections.push_back(*it);
        }
    }
    
    return result;
}