| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef _JMIA_H_ |
| 22 |
#define _JMIA_H_ |
| 23 |
|
| 24 |
#include <vector> |
| 25 |
#include <queue> |
| 26 |
#include <limits> |
| 27 |
#include "Jim.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
void set_seq_shift(long int nx, long int ny, long int nz, long int graph, long int *shift); |
| 32 |
|
| 33 |
template<typename T> void Jim::d_jlframebox_t(std::vector<int> box, T val, std::size_t band){ |
| 34 |
if(box.size()!=6){ |
| 35 |
std::ostringstream s; |
| 36 |
s << "Error: box should be of size 6"; |
| 37 |
throw(s.str()); |
| 38 |
} |
| 39 |
long int nx = nrOfCol(); |
| 40 |
long int ny = nrOfRow(); |
| 41 |
long int nz = nrOfPlane(); |
| 42 |
long int l1,l2; |
| 43 |
|
| 44 |
if (box[0] > nx || box[1] > nx || |
| 45 |
box[2] > ny || box[3] > ny || |
| 46 |
box[4] > nz || box[5] > nz){ |
| 47 |
std::ostringstream s; |
| 48 |
s << "Error: box parameters out of bounds"; |
| 49 |
throw(s.str()); |
| 50 |
} |
| 51 |
|
| 52 |
T *p; |
| 53 |
T* pdata=static_cast<T*>(getDataPointer(static_cast<int>(band))); |
| 54 |
|
| 55 |
long int x; |
| 56 |
long int y; |
| 57 |
long int z; |
| 58 |
|
| 59 |
l1 = box[0]; l2 = box[1]; |
| 60 |
for (z = 0; z < nz; z++){ |
| 61 |
for (y = 0; y < ny; y++){ |
| 62 |
p = pdata + z * nx * ny + y * nx; |
| 63 |
for (x = 0; x < l1; x++) |
| 64 |
*p++ = val; |
| 65 |
p = pdata + z * nx * ny + y * nx + nx - l2; |
| 66 |
for (x = 0; x < l2; x++) |
| 67 |
*p++ = val; |
| 68 |
} |
| 69 |
} |
| 70 |
l1 = box[2] * nx; l2 = box[3] * nx; |
| 71 |
for (z = 0; z < nz; z++){ |
| 72 |
p = pdata + z * nx * ny; |
| 73 |
for (x = 0; x < l1; x++) |
| 74 |
*p++ = val; |
| 75 |
p = pdata + z * nx * ny + nx * (ny - box[3]); |
| 76 |
for (x = 0; x < l2; x++) |
| 77 |
*p++ = val; |
| 78 |
} |
| 79 |
|
| 80 |
l1 = box[4] * nx * ny; l2 = box[5] * nx * ny; |
| 81 |
p = pdata; |
| 82 |
for (x = 0; x < l1; x++) |
| 83 |
*p++ = val; |
| 84 |
p = pdata + nx * ny * (nz - box[5]); |
| 85 |
for (x = 0; x < l2; x++) |
| 86 |
*p++ = val; |
| 87 |
} |
| 88 |
|
| 89 |
template<typename T> void Jim::d_jldistanceGeodesic_t(Jim& reference, std::size_t graph, std::size_t band){ |
| 90 |
long int nx = nrOfCol(); |
| 91 |
long int ny = nrOfRow(); |
| 92 |
long int nz = nrOfPlane(); |
| 93 |
long int shft[27]; |
| 94 |
|
| 95 |
T* pm; |
| 96 |
unsigned char* pr; |
| 97 |
long int i, k; |
| 98 |
std::queue<std::intptr_t> stlq; |
| 99 |
|
| 100 |
std::vector<int> box(6,1); |
| 101 |
if(nrOfPlane()==1){ |
| 102 |
box[4]=0; |
| 103 |
box[5]=0; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
set_seq_shift(nx, ny, nz, graph, shft); |
| 108 |
|
| 109 |
if(reference.getDataType()!=GDT_Byte){ |
| 110 |
std::ostringstream s; |
| 111 |
s << "Error: data type of reference should be GDT_Byte"; |
| 112 |
throw(s.str()); |
| 113 |
} |
| 114 |
pm=static_cast<T*>(getDataPointer(static_cast<int>(band))); |
| 115 |
pr=static_cast<unsigned char*>(reference.getDataPointer(static_cast<int>(band))); |
| 116 |
|
| 117 |
for (i=0; i < nx*ny*nz; ++i){ |
| 118 |
if(pm){ |
| 119 |
*pm ^= (T)(*pr); |
| 120 |
if (*pm) |
| 121 |
*pm = std::numeric_limits<T>::max(); |
| 122 |
} |
| 123 |
pm++; |
| 124 |
pr++; |
| 125 |
} |
| 126 |
|
| 127 |
d_jlframebox_t<T>(box,static_cast<T>(0),band); |
| 128 |
|
| 129 |
pm=static_cast<T*>(getDataPointer(static_cast<int>(band))); |
| 130 |
pr=static_cast<unsigned char*>(reference.getDataPointer(static_cast<int>(band))); |
| 131 |
|
| 132 |
for (i=0; i < nx*ny*nz; ++i){ |
| 133 |
if (*pr){ |
| 134 |
for (k = 0; k < graph; k++){ |
| 135 |
if(i+shft[k]>=0 && i+shft[k]<nx*ny*nz){ |
| 136 |
if (*(pm + shft[k]) == std::numeric_limits<T>::max()){ |
| 137 |
*(pm + shft[k]) = std::numeric_limits<T>::max()-1; |
| 138 |
stlq.push(reinterpret_cast<std::intptr_t>(pm+shft[k])); |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
pm++; |
| 144 |
pr++; |
| 145 |
} |
| 146 |
|
| 147 |
T dcrt = 0; |
| 148 |
bool init=true; |
| 149 |
while(!stlq.empty()){ |
| 150 |
if(init){ |
| 151 |
stlq.push(1L); |
| 152 |
dcrt++; |
| 153 |
init=false; |
| 154 |
} |
| 155 |
if(stlq.front()==1L){ |
| 156 |
stlq.pop(); |
| 157 |
init=true; |
| 158 |
continue; |
| 159 |
} |
| 160 |
pm=(T*)(stlq.front()); |
| 161 |
stlq.pop(); |
| 162 |
*pm = dcrt; |
| 163 |
for (k=0; k < graph; ++k){ |
| 164 |
if(pm + shft[k]){ |
| 165 |
if (*(pm + shft[k]) == std::numeric_limits<T>::max()){ |
| 166 |
*(pm + shft[k]) = std::numeric_limits<T>::max()- 1; |
| 167 |
stlq.push(reinterpret_cast<std::intptr_t>(pm + shft[k])); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
#endif |