Skip to content

Commit ce879c7

Browse files
committed
factorize code for adding columns to tables
1 parent f62d70b commit ce879c7

3 files changed

Lines changed: 59 additions & 53 deletions

File tree

‎src/main/java/inra/ijpb/measure/region2d/MorphometricFeatures2D.java‎

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import inra.ijpb.geometry.OrientedBox2D;
4646
import inra.ijpb.geometry.PointPair2D;
4747
import inra.ijpb.label.LabelImages;
48+
import inra.ijpb.util.Tables;
4849

4950
/**
5051
* An analyzer class that aggregates the computation of several morphometric features
@@ -348,7 +349,7 @@ else if (contains(CENTROID))
348349
calib);
349350
}
350351

351-
if (contains(ORIENTED_BOX))
352+
if (containsAny(ORIENTED_BOX, ORIENTED_BOX_ELONGATION))
352353
{
353354
this.fireStatusChanged(this, "Oriented Bounding Boxes");
354355
OrientedBoundingBox2D algo = new OrientedBoundingBox2D();
@@ -417,37 +418,37 @@ private ResultsTable populateTable(Results results)
417418
{
418419
case PIXEL_COUNT:
419420
{
420-
addColumnToTable(table, "PixelCount", results.pixelCounts);
421+
Tables.addColumnToTable(table, "PixelCount", results.pixelCounts);
421422
break;
422423
}
423424
case AREA:
424425
{
425426
double[] areas = Stream.of(results.intrinsicVolumes)
426427
.mapToDouble(res -> res.area)
427428
.toArray();
428-
addColumnToTable(table, "Area", areas);
429+
Tables.addColumnToTable(table, "Area", areas);
429430
break;
430431
}
431432
case PERIMETER:
432433
{
433434
double[] perimeters = Stream.of(results.intrinsicVolumes)
434435
.mapToDouble(res -> res.perimeter)
435436
.toArray();
436-
addColumnToTable(table, "Perimeter", perimeters);
437+
Tables.addColumnToTable(table, "Perimeter", perimeters);
437438
break;
438439
}
439440
case CIRCULARITY:
440441
{
441442
double[] circularities = IntrinsicVolumes2DUtils.computeCircularities(results.intrinsicVolumes);
442-
addColumnToTable(table, "Circularity", circularities);
443+
Tables.addColumnToTable(table, "Circularity", circularities);
443444
break;
444445
}
445446
case EULER_NUMBER:
446447
{
447448
double[] eulerNumbers = Stream.of(results.intrinsicVolumes)
448449
.mapToDouble(res -> res.eulerNumber)
449450
.toArray();
450-
addColumnToTable(table, "EulerNumber", eulerNumbers);
451+
Tables.addColumnToTable(table, "EulerNumber", eulerNumbers);
451452
break;
452453
}
453454
case BOUNDING_BOX:
@@ -494,7 +495,7 @@ private ResultsTable populateTable(Results results)
494495
Ellipse elli = results.ellipses[i];
495496
elong[i] = elli.radius1() / elli.radius2();
496497
}
497-
addColumnToTable(table, "Ellipse.Elong", elong);
498+
Tables.addColumnToTable(table, "Ellipse.Elong", elong);
498499
break;
499500
}
500501
case CONVEXITY:
@@ -534,15 +535,15 @@ private ResultsTable populateTable(Results results)
534535
double[] elongations = Stream.of(results.orientedBoxes)
535536
.mapToDouble(obox -> obox.length() / obox.width())
536537
.toArray();
537-
addColumnToTable(table, "OBox.Elongation", elongations);
538+
Tables.addColumnToTable(table, "OBox.Elongation", elongations);
538539
break;
539540
}
540541
case GEODESIC_DIAMETER:
541542
{
542543
double[] diameter = Stream.of(results.geodDiams)
543544
.mapToDouble(gdData -> gdData.diameter)
544545
.toArray();
545-
addColumnToTable(table, "GeodesicDiameter", diameter);
546+
Tables.addColumnToTable(table, "GeodesicDiameter", diameter);
546547
break;
547548
}
548549
case TORTUOSITY:
@@ -552,7 +553,7 @@ private ResultsTable populateTable(Results results)
552553
{
553554
tortuosity[i] = results.geodDiams[i].diameter / results.maxFeretDiams[i].diameter();
554555
}
555-
addColumnToTable(table, "Tortuosity", tortuosity);
556+
Tables.addColumnToTable(table, "Tortuosity", tortuosity);
556557
break;
557558
}
558559
case MAX_INSCRIBED_DISK:
@@ -582,7 +583,7 @@ private ResultsTable populateTable(Results results)
582583
{
583584
elong[i] = results.geodDiams[i].diameter / (results.inscrDiscs[i].getRadius() * 2);
584585
}
585-
addColumnToTable(table, "GeodesicElongation", elong);
586+
Tables.addColumnToTable(table, "GeodesicElongation", elong);
586587
break;
587588
}
588589
default:
@@ -596,24 +597,6 @@ private ResultsTable populateTable(Results results)
596597
return table;
597598
}
598599

599-
private static final void addColumnToTable(ResultsTable table,
600-
String colName, double[] values)
601-
{
602-
for (int i = 0; i < values.length; i++)
603-
{
604-
table.setValue(colName, i, values[i]);
605-
}
606-
}
607-
608-
private static final void addColumnToTable(ResultsTable table,
609-
String colName, int[] values)
610-
{
611-
for (int i = 0; i < values.length; i++)
612-
{
613-
table.setValue(colName, i, values[i]);
614-
}
615-
}
616-
617600

618601
/**
619602
* Concatenates the results of the analyzes.

‎src/main/java/inra/ijpb/measure/region3d/MorphometricFeatures3D.java‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import inra.ijpb.geometry.Point3D;
4444
import inra.ijpb.geometry.Sphere;
4545
import inra.ijpb.label.LabelImages;
46+
import inra.ijpb.util.Tables;
4647

4748
/**
4849
* An analyzer class that aggregates the computation of several morphometric features
@@ -419,39 +420,39 @@ private ResultsTable populateTable(Results results)
419420
{
420421
case VOXEL_COUNT:
421422
{
422-
addColumnToTable(table, "VoxelCount", results.voxelCounts);
423+
Tables.addColumnToTable(table, "VoxelCount", results.voxelCounts);
423424
break;
424425
}
425426
case VOLUME:
426427
{
427428
double[] volumes = Stream.of(results.intrinsicVolumes)
428429
.mapToDouble(res -> res.volume)
429430
.toArray();
430-
addColumnToTable(table, "Volume", volumes);
431+
Tables.addColumnToTable(table, "Volume", volumes);
431432
break;
432433
}
433434
case SURFACE_AREA:
434435
{
435436
double[] surfaces = Stream.of(results.intrinsicVolumes)
436437
.mapToDouble(res -> res.surfaceArea)
437438
.toArray();
438-
addColumnToTable(table, "SurfaceArea", surfaces);
439+
Tables.addColumnToTable(table, "SurfaceArea", surfaces);
439440
break;
440441
}
441442
case MEAN_BREADTH:
442443
{
443444
double[] meanBreadths = Stream.of(results.intrinsicVolumes)
444445
.mapToDouble(res -> res.meanBreadth)
445446
.toArray();
446-
addColumnToTable(table, "MeanBreadth", meanBreadths);
447+
Tables.addColumnToTable(table, "MeanBreadth", meanBreadths);
447448
break;
448449
}
449450
case SPHERICITY:
450451
{
451452
double[] sphericites = Stream.of(results.intrinsicVolumes)
452453
.mapToDouble(res -> res.sphericity())
453454
.toArray();
454-
addColumnToTable(table, "Sphericity", sphericites);
455+
Tables.addColumnToTable(table, "Sphericity", sphericites);
455456
break;
456457
}
457458
case BOUNDING_BOX:
@@ -525,7 +526,7 @@ private ResultsTable populateTable(Results results)
525526
double[] eulerNumbers = Stream.of(results.intrinsicVolumes)
526527
.mapToDouble(res -> res.eulerNumber)
527528
.toArray();
528-
addColumnToTable(table, "EulerNumber", eulerNumbers);
529+
Tables.addColumnToTable(table, "EulerNumber", eulerNumbers);
529530
break;
530531
}
531532
default:
@@ -539,24 +540,6 @@ private ResultsTable populateTable(Results results)
539540
return table;
540541
}
541542

542-
private static final void addColumnToTable(ResultsTable table,
543-
String colName, double[] values)
544-
{
545-
for (int i = 0; i < values.length; i++)
546-
{
547-
table.setValue(colName, i, values[i]);
548-
}
549-
}
550-
551-
private static final void addColumnToTable(ResultsTable table,
552-
String colName, int[] values)
553-
{
554-
for (int i = 0; i < values.length; i++)
555-
{
556-
table.setValue(colName, i, values[i]);
557-
}
558-
}
559-
560543

561544
/**
562545
* Concatenates the results of the analyzes.

‎src/main/java/inra/ijpb/util/Tables.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,46 @@ public static final ResultsTable appendColumns(ResultsTable refTable, ResultsTab
5151
return refTable;
5252
}
5353

54+
/**
55+
* Adds a numeric column given by an array of double values to the specified
56+
* table. If the column already exists within the table, its values are
57+
* updated.
58+
*
59+
* @param table
60+
* The instance of ResultsTable to update
61+
* @param colName
62+
* the name of the column.
63+
* @param values
64+
* the values contained within the column.
65+
*/
66+
public static final void addColumnToTable(ResultsTable table, String colName, double[] values)
67+
{
68+
for (int i = 0; i < values.length; i++)
69+
{
70+
table.setValue(colName, i, values[i]);
71+
}
72+
}
73+
74+
/**
75+
* Adds a numeric column given by an array of integer values to the specified
76+
* table. If the column already exists within the table, its values are
77+
* updated.
78+
*
79+
* @param table
80+
* The instance of ResultsTable to update
81+
* @param colName
82+
* the name of the column.
83+
* @param values
84+
* the values contained within the column.
85+
*/
86+
public static final void addColumnToTable(ResultsTable table, String colName, int[] values)
87+
{
88+
for (int i = 0; i < values.length; i++)
89+
{
90+
table.setValue(colName, i, values[i]);
91+
}
92+
}
93+
5494
/**
5595
* Private constructor to prevent instantiation.
5696
*/

0 commit comments

Comments
 (0)