如果我正确理解了你,你想使用坐标作为std :: map键吗?
你可以只创建1只维的std ::地图,并转换XYZ坐标为1个三维坐标系:
int pos1d = z*max_x*max_y+y*max_x+x;
,然后只把那地图键。
编辑:或者你可以只使用一个结构与X,Y,Z为整数作为Space_C0wb0y表现,当然,将采取每性病::地图键3倍的内存,也注意到,比如我发现将具有最大的多维数据集大小:1625x1625x1625(如果是unsigned int),所以如果您需要更长的坐标,则使用一个结构,但请注意,使用结构必须为std :: map关键数据类型编写比较函数。
EDIT3: 我觉得这是你在找什么,因为我注意到你使用最多256个坐标值,这里是我想出了:
// NOTE: max 256x256x256 cube coordinates with this struct. change unsigned char to short or int etc if you need larger values.
// also note that if you change to something else than unsigned char, you cant use nor compare the union: v1.Pos > v2.Pos anymore.
// (unless you use unsigned short for each coordinate, and unsigned __int64 for the union Pos value)
union PosXYZ {
struct {
unsigned char x, y, z, padding; // use full 32bits for better performance
};
unsigned __int32 Pos; // assure its 32bit even on 64bit machines
PosXYZ(unsigned char x, unsigned char y, unsigned char z) : x(x), y(y), z(z), padding(0) {} // initializer list, also set padding to zero so Pos can be compared correctly.
};
inline bool operator>(const PosXYZ &v1, const PosXYZ &v2){
return v1.Pos > v2.Pos;
}
typedef map<PosXYZ, Vector3f, greater<PosXYZ> > MyMap;
void extractIS(float Threshold, MyMap &surfacePointer){
for loop over x and y {
for loop over z {
// [ ... find surface voxels and their normal vectors ... ]
Vector3f newNormalVector(x,y,z);
surfacePointer[PosXYZ(x,y,z)] = newNormalVector;
}
}
}
MyMap isoSurfaces1;
extractIS(0.45, isoSurfaces1);
另一种方式来做到这一点的std ::地图的关键结构是只使用纯整数值,您将通过自己的功能类似于产生:((X < < 16)|(Y < < 8)| Z),这将简化事情,因为你一点点不再需要std :: map的比较函数。
#define PosXYZ(x,y,z) (((x) << 16) | ((y) << 8) | (z)) // generates the std::map key for 256x256x256 max cube coords.
typedef map<unsigned __int32, Vector3f, greater<unsigned __int32> > MyMap;
void extractIS(float Threshold, MyMap &surfacePointer){
for loop over x and y {
for loop over z {
// [ ... find surface voxels and their normal vectors ... ]
Vector3f newNormalVector(x,y,z);
surfacePointer[PosXYZ(x,y,z)] = newNormalVector;
}
}
}
MyMap isoSurfaces1;
extractIS(0.45, isoSurfaces1);
您的问题描述很不清楚。你为什么不简单地将所有数据存储在一个'std :: vector'中,并使用数组算术来访问元素?你为什么想在那里使用地图? – 2011-03-30 16:48:21
花了我一些时间,但我想我明白了。当你在你的问题中说* 3D矢量*时,你的意思是像几何中的矢量,对吗?不是嵌套的'std :: vector'。那是对的吗? – 2011-03-30 16:56:09