如果我正確理解了你,你想使用座標作爲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