bool IfcGeom::profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Face& face) {
	TopoDS_Vertex* vertices = new TopoDS_Vertex[numVerts];
	
	for ( int i = 0; i < numVerts; i ++ ) {
		gp_XY xy (verts[2*i],verts[2*i+1]);
		trsf.Transforms(xy);
		vertices[i] = BRepBuilderAPI_MakeVertex(gp_Pnt(xy.X(),xy.Y(),0.0f));
	}

	BRepBuilderAPI_MakeWire w;
	for ( int i = 0; i < numVerts; i ++ )
		w.Add(BRepBuilderAPI_MakeEdge(vertices[i],vertices[(i+1)%numVerts]));

	IfcGeom::convert_wire_to_face(w.Wire(),face);

	if ( numFillets && *std::max_element(filletRadii, filletRadii + numFillets) > 1e-7 ) {
		BRepFilletAPI_MakeFillet2d fillet (face);
		for ( int i = 0; i < numFillets; i ++ ) {
			const double radius = filletRadii[i];
			if ( radius <= 1e-7 ) continue;
			fillet.AddFillet(vertices[filletIndices[i]],radius);
		}
		fillet.Build();
		if (fillet.IsDone()) {
			face = TopoDS::Face(fillet.Shape());
		} else {
			Logger::Message(Logger::LOG_WARNING, "Failed to process profile fillets");
		}
	}

	delete[] vertices;
	return true;
}
Example #2
0
int OCCWire::fillet(std::vector<OCCVertex *> vertices, std::vector<double> radius) {
    int vertices_size = vertices.size();
    int radius_size = radius.size();
    
    BRepFilletAPI_MakeFillet2d MF;
    try {
        if (this->getShape().IsNull()) {
            StdFail_NotDone::Raise("Shapes is Null");
        }
        
        MF.Init(BRepBuilderAPI_MakeFace(this->getWire()));
        
        for (unsigned i=0; i<vertices.size(); i++) {
            OCCVertex *vertex = vertices[i];
            
            if (radius_size == 1) {
                // single radius
                MF.AddFillet(vertex->getVertex(), radius[0]);
            } else if (radius_size == vertices_size) {
                // radius given for each vertex
                MF.AddFillet(vertex->getVertex(), radius[i]);
            } else {
                StdFail_NotDone::Raise("radius argument has wrong size");
            }
        }
        
        if(MF.Status() != ChFi2d_IsDone)
            StdFail_NotDone::Raise("fillet not completed");
        
        BRepBuilderAPI_MakeWire wire;
        TopTools_IndexedMapOfShape aMap;
        BRepTools_WireExplorer Ex;
        
        TopExp::MapShapes(MF.Shape(), TopAbs_WIRE, aMap);
        if(aMap.Extent() != 1)
            StdFail_NotDone::Raise("Fillet operation did not result in single wire");
        
        //add edges to the wire
        Ex.Clear();
        for(Ex.Init(TopoDS::Wire(aMap(1))); Ex.More(); Ex.Next())
        {
            wire.Add(Ex.Current());
        }
          
        this->setShape(wire);
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to fillet wire");
        }
        return 0;
    }
    return 1;
}