bool CSketch::FilletAtPoint(const gp_Pnt& p, double rad) { std::list<TopoDS_Shape> faces; bool fillet_done = false; if(ConvertSketchToFaceOrWire(this, faces, true)) { for(std::list<TopoDS_Shape>::iterator It2 = faces.begin(); It2 != faces.end(); It2++) { TopoDS_Shape& shape = *It2; if(shape.ShapeType() != TopAbs_FACE)continue; const TopoDS_Face& face = TopoDS::Face(shape); BRepFilletAPI_MakeFillet2d fillet(face); TopoDS_Vertex Vertex; if(!FindClosestVertex(p, face, Vertex))continue; fillet.AddFillet(Vertex, rad); if(fillet.Status() != ChFi2d_IsDone)continue; const TopoDS_Shape& new_shape = fillet.Shape(); if(new_shape.ShapeType() != TopAbs_FACE)continue; const TopoDS_Face& new_face = TopoDS::Face(new_shape); HeeksObj* new_object = new CSketch(); if(ConvertFaceToSketch2(new_face, new_object, FaceToSketchTool::deviation)) { *this = *((CSketch*)new_object); delete new_object; fillet_done = true; } } } return fillet_done; }
// Input: // poly - general polygon // threshold - smaller threshold, smaller grid // Output: // mesh - result mesh void Triangulation(CP_GeneralPolygon2D &poly, bool isClockwise, CP_Mesh3D &mesh) { CP_MeshTriangle3D *pTriangle = NULL; vector<CP_MeshVertex3D*> candidateVertexArray; int numOfEdge = poly.GetEdgeSize(); if (numOfEdge == 0) return; for (int i = 0; i < poly.GetVertSize(); ++i) mesh.AddVert(poly.GetVert(i)); while (numOfEdge > 3) { GenEdge *edge0 = poly.GetEdge(0); CP_MeshVertex3D *L11 = edge0->m_pStart; CP_MeshVertex3D *L12 = edge0->m_pEnd; for (int k = 1; k < numOfEdge; ++k) { GenEdge *edgeK = poly.GetEdge(k); CP_MeshVertex3D *Lk2 = edgeK->m_pEnd; // Test if Lk2 in the left side of v_L11_L12 if (!isClockwise && !IsLk2LeftOfL11L12(L11, L12, Lk2) || isClockwise && !IsLk2RightOfL11L12(L11, L12, Lk2)) continue; // Test if any edge in polygon intersect with line_L11_Lk2 or line_L12_Lk2 CP_LineSegment3D line_L11_Lk2(L11->m_point, Lk2->m_point); CP_LineSegment3D line_L12_Lk2(L12->m_point, Lk2->m_point); CP_LineSegment3D lineJ; int j = 1; for (; j < numOfEdge; ++j) { GenEdge *edgeJ = poly.GetEdge(j); lineJ.m_startPt = edgeJ->m_pStart->m_point; lineJ.m_endPt = edgeJ->m_pEnd->m_point; if (!curve_basic::IsLinesegOverlap(&lineJ, &line_L11_Lk2) && !curve_basic::IsLinesegOverlap(&lineJ, &line_L12_Lk2)) { if (curve_basic::IsLinesegIntersect(&lineJ, &line_L11_Lk2) || curve_basic::IsLinesegIntersect(&lineJ, &line_L12_Lk2)) break; } } if (j != numOfEdge) continue; candidateVertexArray.push_back(Lk2); // Add Lk2 into candidate points when condition satisfied } // Find closest vertex if (candidateVertexArray.size() == 0) { Anticlockwise(poly); continue; } int index = FindClosestVertex(L11, L12, candidateVertexArray); CP_MeshVertex3D *L02 = candidateVertexArray[index]; candidateVertexArray.clear(); // Create triangle and add to array pTriangle = new CP_MeshTriangle3D(L11, L12, L02); mesh.AddTriangle(pTriangle); // Reshape ReshapePoly(poly, L11, L12, L02); numOfEdge = poly.GetEdgeSize(); // return; } // Add the last triangle into array pTriangle = new CP_MeshTriangle3D(poly.GetEdge(0), poly.GetEdge(1)); mesh.AddTriangle(pTriangle); // Optimize // m_optimizedStructure.mf_optimize(&m_triangleArray, &m_vertexArray, threshold); }