首先,我不知道如何在标题中简短地描述问题,对此感到抱歉。
我正在做网格代码。我想让代码尽可能地抽象。 网格是以某种拓扑组织的点云,形成一组多面体。 我想在最底层定义单纯形和四边形(不太确定名称)。这些还与网格无关。它仅描述这些形式的拓扑。 因此我有一个单纯形类:
template<int D> //D is the dimension of the simplex (0 is a point, 1 an edge, 2 a triangle,...)
class simplex
{
static constexpr int nb_included_simplices[4];
}
同样
template<int D> //D is the dimension of the simplex (0 is a point, 1 an edge, 2 a triangle,...)
class quadrangle
{
static constexpr int nb_included_quadrangle[4];
}
nb_included_whatever
是在编译时定义的。其他一些属性将来可能会流行。
现在困难来了。 我现在想要一个类
entity
来描述网格实体。也就是说,它可以是单纯形或四边形(我认为网格要么只包含单纯形,要么只包含四边形),并且包含所有关联实体(“接触”该实体的网格实体)。
应该是这样的(虽然我知道这是错的)
template<typename T, int D> //T is the type of the entity (simplex or quadrangle)
class entity
{
std::vector<T<0>> incident0;
std::vector<T<1>> incident1;
std::vector<T<2>> incident2;
std::vector<T<3>> incident3;
}
这个想法是精确声明实体的类型。例如,对于网格
entity<simplex,2> T
的三角形。
我不知道我该怎么做。
最终的想法是精确网格声明、实体类型,例如 mesh<simplex,3>
表示由四面体组成的 3D 网格。
做出改变对于项目的未来非常重要。
编辑及解决方案 感谢@super,我现在有了解决方案:
template<template<int> typename T, int D> //T is the type of the entity (simplex or quadrangle)
class entity
{
std::vector<T<0>> incident0;
std::vector<T<1>> incident1;
std::vector<T<2>> incident2;
std::vector<T<3>> incident3;
}
感谢@super,我现在有了解决方案:
template<template<int> typename T, int D> //T is the type of the entity (simplex or quadrangle)
class entity
{
std::vector<T<0>> incident0;
std::vector<T<1>> incident1;
std::vector<T<2>> incident2;
std::vector<T<3>> incident3;
}