有誰知道如何讀取原始編碼的文件?所以難住....我想讀花車或雙打(我認爲)。我一直堅持這幾個星期。謝謝! http://www.sci.utah.edu/~gk/DTI-data/gk2/gk2-rcc-mask.raw讀取原始編碼的nrrd數據文件到雙重
說明原始編碼: 你好://teem.sourceforge.net/nrrd/format.html#encoding(其他城市招呼到http去,我想讀從
文件頁面) - 「raw」 - 根據字節值和字節順序,數據出現在磁盤上,與內存完全相同。由write()和fwrite()產生,適用於read()或fread()。
信息的文件: http://www.sci.utah.edu/~gk/DTI-data/gk2/gk2-rcc-mask.nhdr - 我認爲唯一重要的事情是大端(仍試圖理解谷歌是什麼意思)和原始編碼。
我目前的做法,不確定的,如果它是正確的:
//Function ripped off from example of c++ ifstream::read reference page
void scantensor(string filename){
ifstream tdata(filename, ifstream::binary); // not sure if I should put ifstream::binary here
// other things I tried
// ifstream tdata(filename) ifstream tdata(filename, ios::in)
if(tdata){
tdata.seekg(0, tdata.end);
int length = tdata.tellg();
tdata.seekg(0, tdata.beg);
char* buffer = new char[length];
tdata.read(buffer, length);
tdata.close();
double* d;
d = (double*) buffer;
} else cerr << "failed" << endl;
}
/* P.S. I attempted to print the first 100 elements of the array.
Then I print 100 other elements at some arbitrary array indices (i.e. 9,900 - 10,000). I actually kept increasing the number of 0's until I ran out of bound at 100,000,000 (I don't think that's how it works lol but I was just playing around to see what happens)
Here's the part that makes me suspicious: so the ifstream different has different constructors like the ones I tried above.
the first 100 values are always the same.
if I use ifstream::binary, then I get some values for the 100 arbitrary printing
if I use the other two options, then I get -6.27744e+066 for all 100 of them
So for now I am going to assume that ifstream::binary is the correct one. The thing is, I am not sure if the file I provided is how binary files actually look like. I am also unsure if these are the actual numbers that I am supposed to read in or just casting gone wrong. I do realize that my casting from char* to double* can be unsafe, and I got that from one of the threads.
*/
我真的很感激!
編輯1:現在在用上述方法正在讀取的數據顯然是「不正確」,因爲在paraview包的值是:
Dxx,Dxy,Dxz,Dyy,Dyz,Dzz
[0, 1], [-15.4006, 13.2248], [-5.32436, 5.39517], [-5.32915, 5.96026], [-17.87, 19.0954], [-6.02961, 5.24771], [-13.9861, 14.0524]
It's a 3 x 3 symmetric matrix, so 7 distinct values, 7 ranges of values.
我目前正在從文件解析彩車現在是非常大(即-4.68855e-229,-1.32351e + 120)。
也許有人知道如何從Paraview中提取花車?
我嘗試過了,它產生的效果與使用ifstream的與ifstream的二進制::。謝謝。仍然需要更多的答案來驗證,但截至目前看來似乎是正確的。 – user3298879
char的大小是1個字節。 double的大小是8個字節。這真的取決於操作系統,但您可以通過調用sizeof(char)和sizeof(double)來輕鬆檢查。所以,當你處理兩倍時,你需要考慮兩件事:1)字節排序2)在一個字節內排序的位(大端或小端)。如果您提供更具體的問題,我將能夠向您展示具體的例子。 –
所以我問了我的教授,看來這是不正確的。由於數據範圍與Paraview中的數據範圍相比非常大。我不確定我的問題具體有多特殊,因爲我不太習慣這種類型的文件。 – user3298879