概述
九韶内核的拓扑和几何不带附加属性的,为了支持给 TopoShape 挂载属性,应用框架引入 AMCAX::Label。其上关联一个 TopoShape 和一组属性。此外,提供一组 WithAttr 模板类,这组类是对内核建模接口的封装,其上提供了 GetResultLabel,用于获取结果 Label。
命名空间
为了示例代码清晰,使用命名空间。
AMCAX 内核提供的所有接口所在的命名空间。
定义 misc.docu:8
附加属性示例一
通过 AMCAX::WithAttr 获取 Label
通过 WithAttr 获取 Label,并为 Label 附加属性。WithAttr 使用上存在两种形式,一种形式是通过 AMCAX 内核构建一个 TopoShape,并通过 WithAttr<TopoShape> 进行构建,另一种形式是使用参数化建模,所支持的带属性参数化建模接口的详细列表参见 API 列表。
Label boxLabel = shapeWithAttr.GetResultLabel();
Label cylinderLabel = cylinder.GetResultLabel();
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15
WithAttr 的模板类
定义 WithAttrBase.hpp:186
为面挂载属性
Label 上提供了获取面上 Label 的接口 GetFaceLabels,用于获取 Label上所有的 Face Labels。AttributeTool 提供了更新/设置Label上属性的工具函数。注意,同一个 Label 上属性 ID 一样的属性只能存在一份,若想给一个 Label 挂载相同类型的不同属性对象,需要指定不同的属性ID。下面给出在 Label 上挂载属性的例子:
std::vector<Label> cylinderFaceLabels = cylinder.GetAllFaceLabel();
Label boxFace_1 = boxFaceLabels.front();
Label boxFace_3 = boxFaceLabels[2];
Label cylinderFace_1 = cylinderFaceLabels.front();
auto color = std::make_tuple(1., 0., 0., 1.);
color = std::make_tuple(1., 1., 1., 1.);
color = std::make_tuple(0., 1., 0., 1.);
AMCAX_API std::vector< Label > GetFaceLabels() const
获取标签上的所有面标签
布尔操作
WithAttr 对内核的布尔操作进行带属性封装,提供了:
- WithAttr<BoolBRepFuse>
- WithAttr<BoolBRepCommon>
- WithAttr<BoolBRepCut>
- WithAttr<BoolBRepSplitter>
需要注意的是,带属性布尔接口提供的 GetResultLabel 接口可传递一个布尔参数表示是否需要进行级联追踪,当传递 true 上代表需要,此时更改 arguments 或者 tools上属性或拓扑时,布尔结果会自动更新。布尔结果的属性保留策略,由 AMCAX::AttributePolicy 定义,当前定义了以下三种策略:
};
AttributePolicy
用于解决属性发生冲突时的策略枚举
定义 AttributePolicy.hpp:11
@ ATTRIBUTE_POLICY_KEEP_ARGUMENT
当发生属性冲突时,保留第一个参数的属性
定义 AttributePolicy.hpp:15
@ ATTRIBUTE_POLICY_DROP
当发生属性冲突时,丢弃所有属性
定义 AttributePolicy.hpp:13
@ ATTRIBUTE_POLICY_KEEP_TOOL
当发生属性冲突时,保留第一个工具的属性
定义 AttributePolicy.hpp:17
用户可通过 WithAttr 的 SetPolicy 接口定义指定属性类型的属性策略,也可以使用默认属性策略,当调用了 SetPolicy 接口时,它会覆盖默认属性策略。
Label commonLabel = common.GetResultLabel(
true);
virtual AMCAX_API void Build()
执行建模
属性的查找与获取
Label 提供 FindAttribute 接口用于属性的查找,属性上提供 GetValue 接口用于获取属性的值。
std::vector<Label> commonFaceLabels = common.GetAllFaceLabel();
for (auto commonFacelabel : commonFaceLabels) {
std::cout << "r = " << r << ", g = " << g << ", b = " << b << ", a = " << a << std::endl;
}
std::cout << foundAttr->
GetValue<Int8Attribute>() << std::endl;
}
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
if (auto foundAttr = commonFacelabel.FindAttribute("guid"); foundAttr) {
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
}
所有属性的基类
定义 Attribute.hpp:38
R GetValue()
获取属性值
定义 Attribute.hpp:99
颜色属性类
定义 ColorAttribute.hpp:19
static AMCAX_API const std::string & GetId()
获取属性的默认 id
static const std::string & GetId()
定义 FixedIntAttribute.hpp:115
点击这里example01可获得附加属性示例一完整源码,大家根据学习需要自行下载。
附录
下面列出了此示例的完整代码:
#include<iostream>
int main()
{
Label boxLabel = shapeWithAttr.GetResultLabel();
Label cylinderLabel = cylinder.GetResultLabel();
std::vector<Label> cylinderFaceLabels = cylinder.GetAllFaceLabel();
Label boxFace_1 = boxFaceLabels.front();
Label boxFace_3 = boxFaceLabels[2];
Label cylinderFace_1 = cylinderFaceLabels.front();
auto color = std::make_tuple(1., 0., 0., 1.);
color = std::make_tuple(1., 1., 1., 1.);
color = std::make_tuple(0., 1., 0., 1.);
Label commonLabel = common.GetResultLabel(
true);
std::vector<Label> commonFaceLabels = common.GetAllFaceLabel();
for (auto commonFacelabel : commonFaceLabels) {
std::cout << "r = " << r << ", g = " << g << ", b = " << b << ", a = " << a << std::endl;
}
std::cout << foundAttr->
GetValue<Int8Attribute>() << std::endl;
}
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
if (auto foundAttr = commonFacelabel.FindAttribute("guid"); foundAttr) {
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
}
color = std::make_tuple(0., 1., 1., 1.);
for (auto commonFacelabel : commonFaceLabels) {
std::cout << "r = " << r << ", g = " << g << ", b = " << b << ", a = " << a << std::endl;
}
std::cout << foundAttr->
GetValue<Int8Attribute>() << std::endl;
}
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
if (auto foundAttr = commonFacelabel.FindAttribute("guid"); foundAttr) {
std::cout << foundAttr->
GetValue<Int16Attribute>() << std::endl;
}
}
return 0;
}
WithAttr<BoolOperation> 及其派生类
附加属性示例二
属性冲突是指:操作结果的拓扑从多个面 modified 过来,id 一样的属性,参与操作且发生变化。当属性冲突时才会采用下述策略,否则,属性继承自 modified 过来或者保留的拓扑。
准备工作
创建两个带属性的 Box 和 一个带属性的 Cylinder,并为它们的面挂上字符串属性。
auto box = boxWithAttr.GetResultLabel();
auto boxFaces = box.GetFaceLabels();
uint64_t cnt = 1;
for (auto boxFace: boxFaces) {
}
auto box_ = boxWithAttr_.GetResultLabel();
auto boxFaces_ = box_.GetFaceLabels();
cnt = 1;
for (auto boxFace: boxFaces_) {
}
auto cylnder = cylinderWithAttr.GetResultLabel();
auto cylinderFaces = cylnder.GetFaceLabels();
cnt = 1;
for (auto cylFace: cylinderFaces) {
}
执行布尔操作,属性策略为 KEEP_TOOL
auto fuseLabel = fuse.GetResultLabel(true);
auto fuseFaces = fuseLabel.GetFaceLabels();
auto boxFace1 = boxFaces[0];
auto cylFace2 = cylinderFaces[1];
auto fuseFace_1 = fuseFaces[0];
}
}
字符串属性类
定义 StringAttribute.hpp:16
static AMCAX_API const std::string & GetId()
获取属性的默认 id
点击这里example02可获得附加属性示例二完整源码,大家根据学习需要自行下载。
附录
#include <iostream>
int main() {
auto box = boxWithAttr.GetResultLabel();
auto boxFaces = box.GetFaceLabels();
uint64_t cnt = 1;
for (auto boxFace: boxFaces) {
}
auto box_ = boxWithAttr_.GetResultLabel();
auto boxFaces_ = box_.GetFaceLabels();
cnt = 1;
for (auto boxFace: boxFaces_) {
}
auto cylnder = cylinderWithAttr.GetResultLabel();
auto cylinderFaces = cylnder.GetFaceLabels();
cnt = 1;
for (auto cylFace: cylinderFaces) {
}
auto fuseLabel = fuseKeepTool.GetResultLabel(true);
auto fuseFaces = fuseLabel.GetFaceLabels();
auto boxFace1 = boxFaces[0];
auto cylFace2 = cylinderFaces[1];
auto fuseFace_1 = fuseFaces[0];
}
}
return 0;
}
附加属性示例三
应用框架提供了内核建模接口的带属性封装,下面给出两个示例。
WithAttr<MakeEdge> 示例
Point3 p1{0.,0.,0.}, p2{1.,0.,0.}, p{0.,0.,0.};
auto labelV2 = v2.GetResultLabel();
uint64_t cnt = 0;
auto attrs = iter.Value().FindAllAttributes();
}
用于遍历标签中子标签的类
定义 LabelIterator.hpp:18
AMCAX_API bool More()
检查是否还有更多子标签未遍历
创建顶点的类
定义 MakeVertex.hpp:18
virtual AMCAX_API Label & GetResultLabel(bool keepTrack=false)
获取由 WithAttr 构造而来的标签
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459
WithAttr<TransformShape> 示例
auto boxVertex02 = boxFace01.GetVertexLabels()[1];
transShape.Perform(boxLabel);
auto transBoxVertex02 = transBoxFace01.GetVertexLabels()[1];
AMCAX_API std::string & GetValue() noexcept
获取字符串属性的值
TransformationT< double, 3 > Transformation3
三维变换
定义 TransformationT.hpp:1116
VectorT< double, 3 > Vector3
三维向量
定义 VectorT.hpp:707
点击这里example03可获得附加属性示例三完整源码,大家根据学习需要自行下载。
附录
#include <iostream>
int main() {
Point3 p1{ 0.,0.,0. }, p2{ 1.,0.,0. }, p{ 0.,0.,0. };
auto labelV2 = v2.GetResultLabel();
uint64_t cnt = 0;
auto attrs = iter.Value().FindAllAttributes();
}
auto boxVertex02 = boxFace01.GetVertexLabels()[1];
transShape.Perform(boxLabel);
auto transBoxVertex02 = transBoxFace01.GetVertexLabels()[1];
}