1

除了 TopoDS_Vertex 之外,我们还可以通过以下方式获取坐标:

int i=0;
exp0.Init(shape, TopAbs_VERTEX);
for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()) {
    TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current());
    gp_Pnt pnt = BRep_Tool::Pnt(vertex);
    cout <<"Edge " << i << ": X: " << pnt.X() << " - Y:" << pnt.Y() << " - Z: " << pnt.Z();
    i++;
}

我想知道是否有类似的机制来获取 TopoDS_Face 的坐标。

编辑

在@jaba 的建议下,这就是我计算一系列点的质心的方法:

vtkSmartPointer<vtkPoints> facePoints = vtkSmartPointer<vtkPoints>::New();
int i=0;
for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next(), i++, count++) {
    facePoints->Reset();
    TopoDS_Face aFace = TopoDS::Face(exp0.Current());
    for (TopExp_Explorer Vex(aFace, TopAbs_VERTEX); Vex.More(); Vex.Next()) {
        TopoDS_Vertex vertex = TopoDS::Vertex(Vex.Current());
        gp_Pnt pnt = BRep_Tool::Pnt(vertex);
        facePoints->InsertNextPoint(p);
    }
    vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
    polydata->SetPoints(facePoints);

    // Compute the center of mass
    vtkSmartPointer<vtkCenterOfMass> centerOfMassFilter = vtkSmartPointer<vtkCenterOfMass>::New();
    centerOfMassFilter->SetInputData(polydata);
    centerOfMassFilter->SetUseScalarsAsWeights(false);
    centerOfMassFilter->Update();
    double center[3];
    centerOfMassFilter->GetCenter(center);
}
4

2 回答 2

3

计算 TopoDS_Face 质心的 Open CASCADE 方法是

TopoDS_Face face = ...;

GProp_GProps shellProps;
BRepGProp::SurfaceProperties(face, shellProps);

if (shellProps.Mass() < Precision::Confusion())
{
    throw Exception("Failed to Calculate the area of the face.", __TRACE__);
}

const gp_Pnt centerOfMass = shellProps.CentreOfMass();

这应该给出正确的结果。如果面不受凸多边形约束,其中面的顶点是多边形点,则此代码应该仍然有效,但多边形方法可能会失败。

于 2019-03-04T16:37:34.860 回答
1

您需要从面中获取顶点,因为面没有一个坐标。你所做的看起来很好,我只是添加了我的代码片段,因为你的代码不是独立的。

for (TopExp_Explorer vertexEx(face, TopAbs_VERTEX); vertexEx.More(); vertexEx.Next())
{
    TopoDS_Vertex vertex = TopoDS::Vertex(vertexEx.Current());
    gp_Pnt currentPnt = BRep_Tool::Pnt(vertex);
}

如果您只想要一个位置,您可以根据收到的顶点计算中心(请参阅计算 3D 平面多边形的质心

如果这不是您想要的,请说明您的问题。

于 2019-02-28T11:04:15.623 回答