Skip to content

Commit 2aa1ea9

Browse files
committed
Little cleanup
1 parent 0dc5559 commit 2aa1ea9

File tree

13 files changed

+153
-229
lines changed

13 files changed

+153
-229
lines changed

examples/Example_get_apr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int main(int argc, char **argv) {
5050
apr_converter.par.mask_file = options.mask_file;
5151
apr_converter.par.min_signal = options.min_signal;
5252
apr_converter.par.SNR_min = options.SNR_min;
53-
apr_converter.image_type = options.img_type;
5453

5554
//where things are
5655
apr_converter.par.input_image_name = options.input;
@@ -201,14 +200,5 @@ cmdLineOptions read_command_line_options(int argc, char **argv){
201200
result.mask_file = std::string(get_command_option(argv, argv + argc, "-mask_file"));
202201
}
203202

204-
if(command_option_exists(argv, argv + argc, "-u8bit_img"))
205-
{
206-
result.img_type = "uint8";
207-
} else if(command_option_exists(argv, argv + argc, "-float_img")){
208-
result.img_type = "float";
209-
}
210-
211-
212203
return result;
213-
214204
}

examples/Example_get_apr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ struct cmdLineOptions{
2525
float lambda = -1;
2626
float min_signal = -1;
2727
float rel_error = 0.1;
28-
29-
std::string img_type = "uint16";
30-
3128
};
3229

3330
bool command_option_exists(char **begin, char **end, const std::string &option);

src/algorithm/APRConverter.hpp

Lines changed: 67 additions & 123 deletions
Large diffs are not rendered by default.

src/algorithm/ComputeGradient.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ void ComputeGradient::mask_gradient(MeshData<T>& grad_ds,MeshData<S>& temp_ds,Me
7575

7676
TiffUtils::getMesh(file_name, temp_full);
7777

78-
down_sample(temp_ds,temp_full,
79-
[](const T &x, const T &y) -> T { return std::max(x,y); },
80-
[](const T &x) -> T { return x; });
78+
downsample(temp_ds, temp_full,
79+
[](const T &x, const T &y) -> T { return std::max(x, y); },
80+
[](const T &x) -> T { return x; });
8181

8282
#ifdef HAVE_OPENMP
8383
#pragma omp parallel for default(shared)

src/algorithm/PullingScheme.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ void PullingScheme::initialize_particle_cell_tree(APR<T>& apr) {
8888
particle_cell_tree.resize(l_max + 1);
8989

9090
for (int l = l_min; l < (l_max + 1) ;l ++){
91-
particle_cell_tree[l].initialize(ceil((1.0*apr.apr_access.org_dims[0])/pow(2.0,1.0*l_max - l + 1)),
92-
ceil((1.0*apr.apr_access.org_dims[1])/pow(2.0,1.0*l_max - l + 1)),
93-
ceil((1.0*apr.apr_access.org_dims[2])/pow(2.0,1.0*l_max - l + 1)), EMPTY);
91+
particle_cell_tree[l].init(ceil((1.0 * apr.apr_access.org_dims[0]) / pow(2.0, 1.0 * l_max - l + 1)),
92+
ceil((1.0 * apr.apr_access.org_dims[1]) / pow(2.0, 1.0 * l_max - l + 1)),
93+
ceil((1.0 * apr.apr_access.org_dims[2]) / pow(2.0, 1.0 * l_max - l + 1)), EMPTY);
9494
}
9595
}
9696

src/data_structures/APR/APR.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
template<typename ImageType>
1919
class APR {
2020

21-
template<typename S> friend class APRConverter;
21+
template<typename> friend class APRConverter;
22+
template<typename> friend class APRIterator;
2223
friend class APRWriter;
2324
friend class PullingScheme;
24-
template<typename S> friend class APRIterator;
2525

2626
APRWriter apr_writer;
2727
APRReconstruction apr_recon;
28-
APRAccess apr_access;
2928

3029
public:
30+
APRAccess apr_access;
3131

3232
ExtraParticleData<ImageType> particles_intensities;
3333
std::string name;
@@ -151,7 +151,7 @@ class APR {
151151
for (uint64_t particle_number = 0; particle_number < apr_iterator.total_number_particles(); ++particle_number) {
152152
//needed step for any parallel loop (update to the next part)
153153
apr_iterator.set_iterator_to_particle_by_number(particle_number);
154-
parts[apr_iterator] = img_by_level[apr_iterator.level()].access_no_protection(apr_iterator.y(),apr_iterator.x(),apr_iterator.z());
154+
parts[apr_iterator] = img_by_level[apr_iterator.level()].at(apr_iterator.y(),apr_iterator.x(),apr_iterator.z());
155155
}
156156
}
157157
};

src/data_structures/APR/APRAccess.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ class APRAccess {
418418
else {
419419
current = 0;
420420
if (previous == 1) {
421-
if (y == 0) {std::cout << "y==0 but we want to use (y-1) as unsigned value!" << std::endl;}
422421
(y_begin.data[i][offset_pc_data][counter]).second.y_end = (y-1);
423422
counter++;
424423
}
@@ -462,7 +461,7 @@ class APRAccess {
462461

463462
for (size_t y_ = 0; y_ < y_num_; ++y_) {
464463
uint8_t status = p_map[i][offset_part_map + y_];
465-
if (status ==SEED_TYPE) {
464+
if (status == SEED_TYPE) {
466465
current = 1;
467466
if (previous == 0) {
468467
y_begin.data[i+1][offset_pc_data1].push_back({2*y_,gap});
@@ -471,7 +470,6 @@ class APRAccess {
471470
else {
472471
current = 0;
473472
if (previous == 1) {
474-
if (y_ == 0) {std::cout << "y==0 but we want to use (y-1) as unsigned value! (2)" << std::endl;}
475473
y_begin.data[i+1][offset_pc_data1][counter].second.y_end = std::min((uint16_t)(2*(y_-1)+1),(uint16_t)(y_num_us-1));
476474
counter++;
477475
}
@@ -569,11 +567,9 @@ class APRAccess {
569567
total_number_particles = cumsum;
570568
apr_timer.stop_timer();
571569

572-
573570
//set minimum level now to the first non-empty level.
574571
level_min = min_level_find;
575572
level_max = max_level_find;
576-
577573
total_number_non_empty_rows=0;
578574

579575
allocate_map_insert(apr,y_begin);
@@ -582,13 +578,11 @@ class APRAccess {
582578
particle_cell_type.data.resize(global_index_by_level_end[level_max-1]+1,0);
583579

584580
for (size_t level = apr_iterator.level_min(); level < apr_iterator.level_max(); ++level) {
585-
std::cout << "level: " << level << " PART NUM: " << apr_iterator.particles_level_begin(level) << " " << apr_iterator.particles_level_end(level) << std::endl;
586581
#ifdef HAVE_OPENMP
587582
#pragma omp parallel for schedule(static) firstprivate(apr_iterator)
588583
#endif
589584
for (size_t particle_number = apr_iterator.particles_level_begin(level); particle_number < apr_iterator.particles_level_end(level); ++particle_number) {
590-
std::cout << "PN:" << particle_number << std::endl;
591-
std::cout << apr_iterator.set_iterator_to_particle_by_number(particle_number) << std::endl;
585+
apr_iterator.set_iterator_to_particle_by_number(particle_number);
592586
const size_t offset_part_map = apr_iterator.x() * apr_iterator.spatial_index_y_max(apr_iterator.level()) + apr_iterator.z() * apr_iterator.spatial_index_y_max(apr_iterator.level()) * apr_iterator.spatial_index_x_max(apr_iterator.level());
593587
particle_cell_type[apr_iterator] = p_map[apr_iterator.level()][offset_part_map + apr_iterator.y()];
594588
}

src/data_structures/Mesh/MeshData.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public :
8383
/**
8484
* Constructor - initialize mesh with size of 0,0,0
8585
*/
86-
MeshData() { initialize(0, 0, 0); }
86+
MeshData() { init(0, 0, 0); }
8787

8888
/**
8989
* Constructor - initialize initial size of mesh to provided values
9090
* @param aSizeOfY
9191
* @param aSizeOfX
9292
* @param aSizeOfZ
9393
*/
94-
MeshData(int aSizeOfY, int aSizeOfX, int aSizeOfZ) { initialize(aSizeOfY, aSizeOfX, aSizeOfZ); }
94+
MeshData(int aSizeOfY, int aSizeOfX, int aSizeOfZ) { init(aSizeOfY, aSizeOfX, aSizeOfZ); }
9595

9696
/**
9797
* Constructor - creates mesh with provided dimentions initialized to aInitVal
@@ -100,7 +100,7 @@ public :
100100
* @param aSizeOfZ
101101
* @param aInitVal - initial value of all elements
102102
*/
103-
MeshData(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) { initialize(aSizeOfY, aSizeOfX, aSizeOfZ, aInitVal); }
103+
MeshData(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) { init(aSizeOfY, aSizeOfX, aSizeOfZ, aInitVal); }
104104

105105
/**
106106
* Move constructor
@@ -133,7 +133,7 @@ public :
133133
*/
134134
template<typename U>
135135
MeshData(const MeshData<U> &aMesh, bool aShouldCopyData) {
136-
initialize(aMesh.y_num, aMesh.x_num, aMesh.z_num);
136+
init(aMesh.y_num, aMesh.x_num, aMesh.z_num);
137137
if (aShouldCopyData) std::copy(aMesh.mesh.begin(), aMesh.mesh.end(), mesh.begin());
138138
}
139139

@@ -143,7 +143,7 @@ public :
143143
* @return created object by value
144144
*/
145145
template <typename U>
146-
MeshData<U> to_type() const {
146+
MeshData<U> toType() const {
147147
MeshData<U> new_value(y_num, x_num, z_num);
148148
std::copy(mesh.begin(), mesh.end(), new_value.mesh.begin());
149149
return new_value;
@@ -171,7 +171,7 @@ public :
171171
* @param z
172172
* @return element @(y, x, z)
173173
*/
174-
T& access_no_protection(size_t y, size_t x, size_t z) {
174+
T& at(size_t y, size_t x, size_t z) {
175175
size_t idx = z * x_num * y_num + x * y_num + y;
176176
return mesh[idx];
177177
}
@@ -184,7 +184,7 @@ public :
184184
* @param aNumberOfBlocks in how many chunks copy will be done
185185
*/
186186
template<typename U>
187-
void block_copy_data(const MeshData<U> &aInputMesh, unsigned int aNumberOfBlocks = 8) {
187+
void copyFromMesh(const MeshData<U> &aInputMesh, unsigned int aNumberOfBlocks = 8) {
188188
aNumberOfBlocks = std::min((unsigned int)z_num, aNumberOfBlocks);
189189
unsigned int numOfElementsPerBlock = z_num/aNumberOfBlocks;
190190

@@ -213,7 +213,7 @@ public :
213213
* @param aInitVal
214214
* NOTE: If mesh was already created only added elements (new size > old size) will be initialize with aInitVal
215215
*/
216-
void initialize(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) {
216+
void init(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) {
217217
y_num = aSizeOfY;
218218
x_num = aSizeOfX;
219219
z_num = aSizeOfZ;
@@ -246,8 +246,8 @@ public :
246246
* @param aInputMesh
247247
*/
248248
template<typename S>
249-
void initialize(const MeshData<S>& aInputMesh) {
250-
initialize(aInputMesh.y_num, aInputMesh.x_num, aInputMesh.z_num);
249+
void init(const MeshData<S> &aInputMesh) {
250+
init(aInputMesh.y_num, aInputMesh.x_num, aInputMesh.z_num);
251251
}
252252

253253
/**
@@ -256,7 +256,7 @@ public :
256256
* @param aSizeOfX
257257
* @param aSizeOfZ
258258
*/
259-
void initialize(int aSizeOfY, int aSizeOfX, int aSizeOfZ) {
259+
void init(int aSizeOfY, int aSizeOfX, int aSizeOfZ) {
260260
y_num = aSizeOfY;
261261
x_num = aSizeOfX;
262262
z_num = aSizeOfZ;
@@ -272,12 +272,12 @@ public :
272272
* @param aSizeOfX
273273
* @param aSizeOfZ
274274
*/
275-
void preallocate(int aSizeOfY, int aSizeOfX, int aSizeOfZ) {
275+
void initDownsampled(int aSizeOfY, int aSizeOfX, int aSizeOfZ) {
276276
const int z_num_ds = ceil(1.0*aSizeOfZ/2.0);
277277
const int x_num_ds = ceil(1.0*aSizeOfX/2.0);
278278
const int y_num_ds = ceil(1.0*aSizeOfY/2.0);
279279

280-
initialize(y_num_ds, x_num_ds, z_num_ds);
280+
init(y_num_ds, x_num_ds, z_num_ds);
281281
}
282282

283283
/**
@@ -287,12 +287,12 @@ public :
287287
* @param aSizeOfZ
288288
* @param aInitVal
289289
*/
290-
void preallocate(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) {
290+
void initDownsampled(int aSizeOfY, int aSizeOfX, int aSizeOfZ, T aInitVal) {
291291
const int z_num_ds = ceil(1.0*aSizeOfZ/2.0);
292292
const int x_num_ds = ceil(1.0*aSizeOfX/2.0);
293293
const int y_num_ds = ceil(1.0*aSizeOfY/2.0);
294294

295-
initialize(y_num_ds, x_num_ds, z_num_ds, aInitVal);
295+
init(y_num_ds, x_num_ds, z_num_ds, aInitVal);
296296
}
297297

298298
/**
@@ -316,7 +316,7 @@ public :
316316
* @param aNumberOfBlocks - in how many chunks copy will be done
317317
*/
318318
template<typename U, typename R>
319-
void initWithUnaryOp(const MeshData<U> &aInputMesh, R aOp, size_t aNumberOfBlocks = 10) {
319+
void copyFromMeshWithUnaryOp(const MeshData<U> &aInputMesh, R aOp, size_t aNumberOfBlocks = 10) {
320320
aNumberOfBlocks = std::min(aInputMesh.z_num, (size_t)aNumberOfBlocks);
321321
size_t numOfElementsPerBlock = aInputMesh.z_num/aNumberOfBlocks;
322322

@@ -345,13 +345,13 @@ public :
345345
* @param aIdx
346346
* @return
347347
*/
348-
std::string getIdx(uint64_t aIdx) const {
348+
std::string getStrIndex(size_t aIdx) const {
349349
if (aIdx < 0 || aIdx >= mesh.size()) return "(ErrIdx)";
350-
uint64_t z = aIdx / (x_num * y_num);
350+
size_t z = aIdx / (x_num * y_num);
351351
aIdx -= z * (x_num * y_num);
352-
uint64_t x = aIdx / y_num;
352+
size_t x = aIdx / y_num;
353353
aIdx -= x * y_num;
354-
uint64_t y = aIdx;
354+
size_t y = aIdx;
355355
std::ostringstream outputStr;
356356
outputStr << "(" << y << ", " << x << ", " << z << ")";
357357
return outputStr.str();
@@ -371,31 +371,31 @@ public :
371371

372372

373373
template<typename T, typename S, typename R, typename C>
374-
void down_sample(const MeshData<T>& aInput, MeshData<S>& aOutput, R reduce, C constant_operator, bool aInitializeOutput = false) {
375-
const int64_t z_num = aInput.z_num;
376-
const int64_t x_num = aInput.x_num;
377-
const int64_t y_num = aInput.y_num;
374+
void downsample(const MeshData<T> &aInput, MeshData<S> &aOutput, R reduce, C constant_operator, bool aInitializeOutput = false) {
375+
const size_t z_num = aInput.z_num;
376+
const size_t x_num = aInput.x_num;
377+
const size_t y_num = aInput.y_num;
378378

379379
// downsampled dimensions twice smaller (rounded up)
380-
const int64_t z_num_ds = (int64_t) ceil(z_num/2.0);
381-
const int64_t x_num_ds = (int64_t) ceil(x_num/2.0);
382-
const int64_t y_num_ds = (int64_t) ceil(y_num/2.0);
380+
const size_t z_num_ds = ceil(z_num/2.0);
381+
const size_t x_num_ds = ceil(x_num/2.0);
382+
const size_t y_num_ds = ceil(y_num/2.0);
383383

384384
APRTimer timer;
385385
timer.verbose_flag = false;
386386

387387
if (aInitializeOutput) {
388388
timer.start_timer("downsample_initalize");
389-
aOutput.initialize(y_num_ds, x_num_ds, z_num_ds);
389+
aOutput.init(y_num_ds, x_num_ds, z_num_ds);
390390
timer.stop_timer();
391391
}
392392

393393
timer.start_timer("downsample_loop");
394394
#ifdef HAVE_OPENMP
395395
#pragma omp parallel for default(shared)
396396
#endif
397-
for (int64_t z = 0; z < z_num_ds; ++z) {
398-
for (int64_t x = 0; x < x_num_ds; ++x) {
397+
for (size_t z = 0; z < z_num_ds; ++z) {
398+
for (size_t x = 0; x < x_num_ds; ++x) {
399399

400400
// shifted +1 in original inMesh space
401401
const int64_t shx = std::min(2*x + 1, x_num - 1);
@@ -404,7 +404,7 @@ void down_sample(const MeshData<T>& aInput, MeshData<S>& aOutput, R reduce, C co
404404
const ArrayWrapper<T> &inMesh = aInput.mesh;
405405
ArrayWrapper<S> &outMesh = aOutput.mesh;
406406

407-
for (int64_t y = 0; y < y_num_ds; ++y) {
407+
for (size_t y = 0; y < y_num_ds; ++y) {
408408
const int64_t shy = std::min(2*y + 1, y_num - 1);
409409
const int64_t idx = z * x_num_ds * y_num_ds + x * y_num_ds + y;
410410
outMesh[idx] = constant_operator(
@@ -425,15 +425,15 @@ void down_sample(const MeshData<T>& aInput, MeshData<S>& aOutput, R reduce, C co
425425
}
426426

427427
template<typename T>
428-
void downsample_pyrmaid(MeshData<T> &original_image, std::vector<MeshData<T>> &downsampled, size_t l_max, size_t l_min) {
428+
void downsamplePyrmaid(MeshData<T> &original_image, std::vector<MeshData<T>> &downsampled, size_t l_max, size_t l_min) {
429429
downsampled.resize(l_max + 1); // each level is kept at same index
430430
downsampled.back().swap(original_image); // put original image at l_max index
431431

432432
// calculate downsampled in range (l_max, l_min]
433433
auto sum = [](const float x, const float y) -> float { return x + y; };
434434
auto divide_by_8 = [](const float x) -> float { return x/8.0; };
435435
for (int level = l_max; level > l_min; --level) {
436-
down_sample(downsampled[level], downsampled[level - 1], sum, divide_by_8, true);
436+
downsample(downsampled[level], downsampled[level - 1], sum, divide_by_8, true);
437437
}
438438
}
439439

0 commit comments

Comments
 (0)