- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为 Test 的类,它继承了 TopoDS_Face 类。已经从 This question 得到了一些提示但是...
// Test.h
class Test : public TopoDS_Face
{
public:
void operator = (const TopoDS_Face& base_)
{
TopoDS_Face::operator=(base_);
}
}
// testmain.cpp
...
int main() {
//extract faces from IGES face
for (int i = 1; i <= nbs; i++) {
TopoDS_Shape shape = myIgesReader.Shape(i);
TopoDS_Face& face = static_cast<TopoDS_Face&>(TopoDS::Face(shape));
Test *test;
// tried each of these also and did not succeed
// Test *test = dynamic_cast<Test*>(&face);
// test = &face
test->TopoDS_Face::operator=(face);
...
}
}
main 中的代码从 IGES 文件中提取面,并将每个面对象分配给 main 中创建的测试对象。编译进行得很顺利,但 valgrind 提示以下错误:
==21718== Use of uninitialised value of size 8
==21718== at 0x9B0946C: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
==21718== Use of uninitialised value of size 8
==21718== at 0x9B09431: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
==21718== Invalid read of size 4
==21718== at 0x9B0943C: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718== Address 0x75eb394801c38350 is not stack'd, malloc'd or (recently) free'd
==21718==
==21718==
==21718== Process terminating with default action of signal 11 (SIGSEGV)
==21718== General Protection Fault
==21718== at 0x9B0943C: Handle_Standard_Transient::EndScope() (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x9B09475: Handle_Standard_Transient::Assign(Standard_Transient const*) (in /usr/lib64/libTKernel.so.10.0.0)
==21718== by 0x408111: Handle_TopoDS_TShape::operator=(Handle_TopoDS_TShape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x409478: TopoDS_Shape::operator=(TopoDS_Shape const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x4094CA: TopoDS_Face::operator=(TopoDS_Face const&) (in /home/ub/Projects/C++/test/test)
==21718== by 0x407273: main (in /home/ub/Projects/C++/test/test)
==21718==
我需要帮助来解决该程序。提前致谢。
最佳答案
如果您查看TopoDS_Shape层次结构定义,您会注意到:
TopoDS_Shape 不是一个接口(interface)(没有虚拟方法或虚拟析构函数)。
TopoDS_Face、TopoDS_Shell 等提供从 TopoDS_Shape 的“虚拟”继承,无需添加任何字段或方法。
OCCT 不存储强类型 TopoDS_ shape 对象。 OCCT 集合(首先包括 TopoDS_Shape 的子形状!)按值存储 TopoDS_Shape,而不是引用。像 TopoDS::Face() 这样的方法基本上会使用内存别名来返回强类型对象,并根据 TopoDS_Shape::ShapeType() 方法返回的枚举进行运行时检查。
实际上,可共享引用以 TopoDS_Shape 类的 Handle(TopoDS_TShape) 属性的形式存储。 TopoDS_TShape是一个定义主要形状数据(几何图形)的真实类,它确实是具有真实子类的虚拟类。
TopoDS_TShape 层次结构(具有 TopoDS_TShape、TopoDS_TShell 等子类)是内部且最终的 - 没有用于在应用程序级别扩展此层次结构的接口(interface)。我想说,在 C++11 中,这些类应该被标记为 Final。
根据此描述,应该清楚的是,更改 TopoDS_Shape/TopoDS_TShape 层次结构与 OCCT 设计(对于这些特定类)相矛盾,并且无法在应用程序级别可靠地完成。假设的替代方案是使用映射(如 NCollection_DataMap<TopoDS_Shape,TopTools_ShapeMapHasher,MyShapeProperties>
)或通过文档结构(如使用 TDataStd_NamedData 和其他属性定义装配结构的 XCAF 文档)存储与形状相关的附加信息。
关于c++ - 将 TopoDS_Face 对象分配给其子对象编译时没有错误,但有 3 个 valgrind 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55852277/
除了 TopoDS_Vertex 之外,我们还可以通过以下方式获取坐标: int i=0; exp0.Init(shape, TopAbs_VERTEX); for(exp0.Init(shape,
我有一个名为 Test 的类,它继承了 TopoDS_Face 类。已经从 This question 得到了一些提示但是... // Test.h class Test : publ
我是一名优秀的程序员,十分优秀!