vtkSmartPointer<vtkCellPicker> m_cellPicker;
double* ijk = m_cellPicker->GetPickNormal();
获取的发现反向,造成这样情况的原因可能选择的面是片体(壳),需要把片体或者壳缝合或者转换为实体正常。
业务情况导入STEP,在VTK中渲染,选择面上的点法相异常,增加STEP导入后获取组合体中片体,然后缝合片体。下面方法还是有些问题的,缝合的片体可以转换为实体,但是运行后没有实体显示转换失败,没有好的方法解决。
TopoDS_Shape dmuCADReader::CreateSolidFromFaces(TopoDS_Shape theTopoDS_Shape)
{
std::vector<TopoDS_Face> faces;
TopoDS_Shape sewedShape ;
try
{
for (TopExp_Explorer explorer(theTopoDS_Shape, TopAbs_COMPOUND); explorer.More(); explorer.Next()) {
TopoDS_Shape subshape = explorer.Current();
int n = 0;
for (TopExp_Explorer explorersub(subshape, TopAbs_FACE); explorersub.More(); explorersub.Next())
{
TopoDS_Face theface = TopoDS::Face(explorersub.Current());
faces.push_back(theface);
//builder.Add(newCompound, theface);
}
}
BRep_Builder builder;
// 创建一个壳并将所有面添加到壳中
TopoDS_Shell shell;
builder.MakeShell(shell);
for (const auto& face : faces) {
builder.Add(shell, face);
}
// 使用 BRepBuilderAPI_Sewing 来缝合壳
BRepBuilderAPI_Sewing sewing;
sewing.Add(shell);
sewing.Perform();
sewedShape = sewing.SewedShape();
// 创建实体
//TopoDS_Solid solid;
//builder.MakeSolid(solid);
如果缝合的形状是有效的壳,使用它来创建实体
//if (sewedShape.ShapeType() == TopAbs_SHELL) {
// TopoDS_Shell sewedShell = TopoDS::Shell(sewedShape);
// builder.Add(solid, sewedShell);
//}
return sewedShape;
//return solid;
}
catch (const std::exception&)
{
return sewedShape;
}
}