Commit 64c582bb5763f1c57e1025184804e9f38ecc5591

Authored by David Mayerich
2 parents 3fc1d461 3b972fb3

Merge branch 'fastread'

Merging David's general binary::getSlice() function into the main branch.
Showing 1 changed file with 30 additions and 3 deletions   Show diff stats
envi/binary.h
... ... @@ -89,12 +89,39 @@ public:
89 89 return false;
90 90 }
91 91  
92   - file.seekg(R[1] * R[0] * page * sizeof(T), ios::beg); //write into memory from the binary file
  92 + file.seekg(R[1] * R[0] * page * sizeof(T), std::ios::beg); //write into memory from the binary file
93 93 file.read((char *)p, R[0] * R[1] * sizeof(T));
94 94  
95 95 return true;
96 96 }
97 97  
  98 + //saves a hyperplane orthogonal to dimension d at intersection n
  99 + bool getSlice(T * dest, unsigned int d, unsigned int n){
  100 +
  101 + //reset the file pointer back to the beginning of the file
  102 + file.seekg(0, std::ios::beg);
  103 +
  104 + //compute the contiguous size C for each readable block
  105 + unsigned int C = 1;
  106 + for(unsigned int i = 0; i < d; i++) //for each dimension less than d
  107 + C *= R[i]; //compute the product
  108 +
  109 + //compute the non-contiguous size NC for each readable block
  110 + unsigned int NC = 1;
  111 + for(unsigned int i = d + 1; i < D; i++)
  112 + NC *= R[i];
  113 +
  114 + //for all noncontiguous blocks, read each contiguous block that makes up the hyper-plane
  115 + for(unsigned int nc = 0; nc < NC; nc++){
  116 + file.seekg(n * C * sizeof(T), std::ios::cur); //skip n contiguous blocks
  117 + file.read( (char*)&dest[nc * C], C * sizeof(T)); //read one contiguous block
  118 + file.seekg( (R[d] - n - 1) * C * sizeof(T), std::ios::cur); //skip R[d] - n contiguous blocks
  119 + }
  120 +
  121 + return true;
  122 +
  123 + }
  124 +
98 125 //save one pixel of the file into the memory, and return the pointer
99 126 bool saveXY(T * p, unsigned x, unsigned y){
100 127  
... ... @@ -105,11 +132,11 @@ public:
105 132 return false;
106 133 }
107 134  
108   - file.seekg((x + y * R[0]) * sizeof(T), ios::beg); //point to the certain sample and line
  135 + file.seekg((x + y * R[0]) * sizeof(T), std::ios::beg); //point to the certain sample and line
109 136 for (i = 0; i < R[2]; i++)
110 137 {
111 138 file.read((char *)(p + i), sizeof(T));
112   - file.seekg((R[1] * R[0] - 1) * sizeof(T), ios::cur); //go to the next band
  139 + file.seekg((R[1] * R[0] - 1) * sizeof(T), std::ios::cur); //go to the next band
113 140 }
114 141  
115 142 return true;
... ...