九韶内核的拓扑和几何不带附加属性的,为了支持给 TopoShape 挂载属性,应用框架引入 AMCAX::Label。其上关联一个 TopoShape 和一组属性。此外,提供一组 WithAttr 模板类,这组类是对内核建模接口的封装,其上提供了 GetResultLabel,用于获取结果 Label。
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
Get all face labels on the label
需要注意的是,带属性布尔接口提供的 GetResultLabel 接口可传递一个布尔参数表示是否需要进行级联追踪,当传递 true 上代表需要,此时更改 arguments 或者 tools上属性或拓扑时,布尔结果会自动更新。布尔结果的属性保留策略,由 AMCAX::AttributePolicy 定义,当前定义了以下三种策略:
用户可通过 WithAttr 的 SetPolicy 接口定义指定属性类型的属性策略,也可以使用默认属性策略,当调用了 SetPolicy 接口时,它会覆盖默认属性策略。
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 (commonFacelabel.FindAttribute("guid", foundAttr)) {
std::cout << foundAttr.
GetValue<Int16Attribute>() << std::endl;
}
}
The Attribute class is used to represent an attribute in the system.
定义 Attribute.hpp:24
AMCAX_API R GetValue()
Get the attribute value
定义 Attribute.hpp:53
The class of ColorAttribute
定义 ColorAttribute.hpp:20
static const std::string & GetId()
Defining a id to identify an attribute.
定义 ColorAttribute.hpp:71
static const std::string & GetId()
Defining a id to identify an attribute.
定义 FixedIntAttribute.hpp:109
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.);
common.SetPolicy(AttributeType::INT16_ATTRIBUTE, AttributePolicy::ATTRIBUTE_POLICY_KEEP_TOOL);
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 (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 (commonFacelabel.FindAttribute("guid", foundAttr)) {
std::cout << foundAttr.
GetValue<Int16Attribute>() << std::endl;
}
}
return 0;
}
The class of WithAttrBase, WithAttr.