iRoCS Toolbox  1.1.0
ATBNucleus.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 /*======================================================================*/
28 /*======================================================================*/
29 
30 #ifndef ATBNUCLEUS_HH
31 #define ATBNUCLEUS_HH
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.hh>
35 #endif
36 
37 #include <blitz/array.h>
38 
39 #include <map>
40 #include <vector>
41 #include <list>
42 
44 
45 #include "TypeTraits.hh"
46 #include "RuntimeError.hh"
47 
48 namespace atb
49 {
50 
51 /*======================================================================*/
58 /*======================================================================*/
59  class Nucleus
60  {
61 
62  struct NucleusId
63  {
64  NucleusId(double r, const bool m)
65  : radius(r), mitotic(m)
66  {}
67  ~NucleusId()
68  {}
69 
70  double radius;
71  bool mitotic;
72 
73  bool operator==(const NucleusId& ncId) const
74  {
75  if (radius == ncId.radius &&
76  mitotic == ncId.mitotic) return true;
77  return false;
78  }
79 
80  bool operator<(const NucleusId& ncId) const
81  {
82  if (radius < ncId.radius) return true;
83  if (radius > ncId.radius) return false;
84  if (!mitotic && ncId.mitotic) return true;
85  return false;
86  }
87  };
88 
89  public:
90 
91 /*======================================================================*/
95 /*======================================================================*/
97  : _id("marker"), _positionUm(-1.0), _label(-1), _predictedLabel(-1),
98  _manual(false), _needsFeatureUpdate(true), _features(),
99  _probabilityMap(), _qcDistanceUm(-1.0), _radialDistanceUm(-1.0),
100  _phi(-1.0), _radiusUm(-1.0), _coefficients(),
101  _value(-1.0), _confidence(-1.0), _sphase(-1.0),
102  _borderDistanceUm(-1.0), _volumeUm3(-1.0), _mitotic(false),
103  _predictedMitotic(false), _subtype(-1), _predictedSubtype(-1),
104  _cellfile(-1), _predictedCellfile(-1)
105  {}
106 
107 /*======================================================================*/
112 /*======================================================================*/
113  Nucleus(Nucleus const &nc)
114  : _id(nc._id), _positionUm(nc._positionUm), _label(nc._label),
115  _predictedLabel(nc._predictedLabel), _manual(nc._manual),
116  _needsFeatureUpdate(nc._needsFeatureUpdate),
117  _features(nc._features), _probabilityMap(nc._probabilityMap),
118  _qcDistanceUm(nc._qcDistanceUm),
119  _radialDistanceUm(nc._radialDistanceUm), _phi(nc._phi),
120  _radiusUm(nc._radiusUm), _coefficients(nc._coefficients.shape()),
121  _value(nc._value), _confidence(nc._confidence),
122  _sphase(nc._sphase), _borderDistanceUm(nc._borderDistanceUm),
123  _volumeUm3(nc._volumeUm3), _mitotic(nc._mitotic),
124  _predictedMitotic(nc._predictedMitotic), _subtype(nc._subtype),
125  _predictedSubtype(nc._predictedSubtype), _cellfile(nc._cellfile),
126  _predictedCellfile(nc._predictedCellfile)
127  {
128  _coefficients = nc._coefficients;
129  }
130 
131 /*======================================================================*/
135 /*======================================================================*/
137  {}
138 
139 /*======================================================================*/
146 /*======================================================================*/
148  {
149  _id = nc._id;
150  _positionUm = nc._positionUm;
151  _label = nc._label;
152  _predictedLabel = nc._predictedLabel;
153  _manual = nc._manual;
154  _needsFeatureUpdate = nc._needsFeatureUpdate;
155  _features = nc._features;
156  _probabilityMap = nc._probabilityMap;
157  _qcDistanceUm = nc._qcDistanceUm;
158  _radialDistanceUm = nc._radialDistanceUm;
159  _phi = nc._phi;
160  _radiusUm = nc._radiusUm;
161  _coefficients.resize(nc._coefficients.shape());
162  _coefficients = nc._coefficients;
163  _value = nc._value;
164  _confidence = nc._confidence;
165  _sphase = nc._sphase;
166  _borderDistanceUm = nc._borderDistanceUm;
167  _volumeUm3 = nc._volumeUm3;
168  _mitotic = nc._mitotic;
169  _predictedMitotic = nc._predictedMitotic;
170  _subtype = nc._subtype;
171  _predictedSubtype = nc._predictedSubtype;
172  _cellfile = nc._cellfile;
173  _predictedCellfile = nc._predictedCellfile;
174  return *this;
175  }
176 
177 /*======================================================================*/
186 /*======================================================================*/
187  std::string const &id() const
188  {
189  return _id;
190  }
191 
192 /*======================================================================*/
201 /*======================================================================*/
202  void setId(std::string const &id)
203  {
204  _id = id;
205  }
206 
207 /*======================================================================*/
213 /*======================================================================*/
214  blitz::TinyVector<double,3> const &positionUm() const
215  {
216  return _positionUm;
217  }
218 
219 /*======================================================================*/
225 /*======================================================================*/
226  void setPositionUm(blitz::TinyVector<double,3> const &positionUm)
227  {
228  _positionUm = positionUm;
229  }
230 
231 /*======================================================================*/
248 /*======================================================================*/
249  int label() const
250  {
251  return _label;
252  }
253 
254 /*======================================================================*/
271 /*======================================================================*/
272  void setLabel(int label)
273  {
274  _label = label;
275  }
276 
277 /*======================================================================*/
294 /*======================================================================*/
295  int predictedLabel() const
296  {
297  return _predictedLabel;
298  }
299 
300 /*======================================================================*/
317 /*======================================================================*/
319  {
320  _predictedLabel = predictedLabel;
321  }
322 
323 /*======================================================================*/
333 /*======================================================================*/
334  bool manual() const
335  {
336  return _manual;
337  }
338 
339 /*======================================================================*/
349 /*======================================================================*/
350  void setManual(bool manual)
351  {
352  _manual = manual;
353  }
354 
355 /*======================================================================*/
362 /*======================================================================*/
363  bool needsFeatureUpdate() const
364  {
365  return _needsFeatureUpdate;
366  }
367 
368 /*======================================================================*/
375 /*======================================================================*/
377  {
378  _needsFeatureUpdate = needsFeatureUpdate;
379  }
380 
381 /*======================================================================*/
387 /*======================================================================*/
388  std::vector<double> &features()
389  {
390  return _features;
391  }
392 
393 /*======================================================================*/
399 /*======================================================================*/
400  std::vector<double> const &features() const
401  {
402  return _features;
403  }
404 
405 /*======================================================================*/
414 /*======================================================================*/
415  std::map<int,double> &probabilityMap()
416  {
417  return _probabilityMap;
418  }
419 
420 /*======================================================================*/
429 /*======================================================================*/
430  std::map<int,double> const &probabilityMap() const
431  {
432  return _probabilityMap;
433  }
434 
435 /*======================================================================*/
444 /*======================================================================*/
445  double qcDistanceUm() const
446  {
447  return _qcDistanceUm;
448  }
449 
450 /*======================================================================*/
459 /*======================================================================*/
461  {
462  _qcDistanceUm = qcDistanceUm;
463  }
464 
465 /*======================================================================*/
472 /*======================================================================*/
473  double radialDistanceUm() const
474  {
475  return _radialDistanceUm;
476  }
477 
478 /*======================================================================*/
485 /*======================================================================*/
487  {
488  _radialDistanceUm = radialDistanceUm;
489  }
490 
491 /*======================================================================*/
498 /*======================================================================*/
499  double phi() const
500  {
501  return _phi;
502  }
503 
504 /*======================================================================*/
511 /*======================================================================*/
512  void setPhi(const double phi)
513  {
514  _phi = phi;
515  }
516 
517 /*======================================================================*/
524 /*======================================================================*/
525  double radiusUm() const
526  {
527  return _radiusUm;
528  }
529 
530 /*======================================================================*/
537 /*======================================================================*/
538  void setRadiusUm(const double radiusUm)
539  {
540  _radiusUm = radiusUm;
541  }
542 
543 /*======================================================================*/
552 /*======================================================================*/
553  blitz::Array<std::complex<double>,1> const &shCoefficients() const
554  {
555  return _coefficients;
556  }
557 
558 /*======================================================================*/
567 /*======================================================================*/
568  blitz::Array<std::complex<double>,1> &shCoefficients()
569  {
570  return _coefficients;
571  }
572 
573 /*======================================================================*/
581 /*======================================================================*/
582  double value() const
583  {
584  return _value;
585  }
586 
587 /*======================================================================*/
595 /*======================================================================*/
596  void setValue(double value)
597  {
598  _value = value;
599  }
600 
601 /*======================================================================*/
609 /*======================================================================*/
610  double confidence() const
611  {
612  return _confidence;
613  }
614 
615 /*======================================================================*/
623 /*======================================================================*/
625  {
626  _confidence = confidence;
627  }
628 
629 /*======================================================================*/
636 /*======================================================================*/
637  double sphase() const
638  {
639  return _sphase;
640  }
641 
642 /*======================================================================*/
649 /*======================================================================*/
650  void setSphase(double sphase)
651  {
652  _sphase = sphase;
653  }
654 
655 /*======================================================================*/
664 /*======================================================================*/
665  double borderDistanceUm() const
666  {
667  return _borderDistanceUm;
668  }
669 
670 /*======================================================================*/
679 /*======================================================================*/
681  {
682  _borderDistanceUm = borderDistanceUm;
683  }
684 
685 /*======================================================================*/
692 /*======================================================================*/
693  double volumeUm3() const
694  {
695  return _volumeUm3;
696  }
697 
698 /*======================================================================*/
705 /*======================================================================*/
706  void setVolumeUm3(double volumeUm3)
707  {
708  _volumeUm3 = volumeUm3;
709  }
710 
711 /*======================================================================*/
721 /*======================================================================*/
722  bool mitotic() const
723  {
724  return _mitotic;
725  }
726 
727 /*======================================================================*/
737 /*======================================================================*/
738  void setMitotic(bool mitotic)
739  {
740  _mitotic = mitotic;
741  }
742 
743 /*======================================================================*/
752 /*======================================================================*/
753  bool predictedMitotic() const
754  {
755  return _predictedMitotic;
756  }
757 
758 /*======================================================================*/
767 /*======================================================================*/
769  {
770  _predictedMitotic = predictedMitotic;
771  }
772 
773 /*======================================================================*/
784 /*======================================================================*/
785  int subtype() const
786  {
787  return _subtype;
788  }
789 
790 /*======================================================================*/
801 /*======================================================================*/
802  void setSubtype(int subType)
803  {
804  _subtype = subType;
805  }
806 
807 /*======================================================================*/
817 /*======================================================================*/
818  int predictedSubtype() const
819  {
820  return _predictedSubtype;
821  }
822 
823 /*======================================================================*/
833 /*======================================================================*/
834  void setPredictedSubtype(int subType)
835  {
836  _predictedSubtype = subType;
837  }
838 
839 /*======================================================================*/
849 /*======================================================================*/
850  int cellfile() const
851  {
852  return _cellfile;
853  }
854 
855 /*======================================================================*/
865 /*======================================================================*/
867  {
868  _cellfile = cellfile;
869  }
870 
871 /*======================================================================*/
880 /*======================================================================*/
881  int predictedCellfile() const
882  {
883  return _predictedCellfile;
884  }
885 
886 /*======================================================================*/
895 /*======================================================================*/
897  {
898  _predictedCellfile = predictedCellfile;
899  }
900 
901 /*======================================================================*/
910 /*======================================================================*/
911  bool operator<(const Nucleus& rhs) const
912  {
913  return _value < rhs.value();
914  }
915 
916 /*======================================================================*/
931 /*======================================================================*/
932  template<typename NucleusSequenceT>
933  static void saveList(
934  NucleusSequenceT const &nuclei, BlitzH5File &outFile,
935  std::string const &group);
936 
937 /*======================================================================*/
950 /*======================================================================*/
951  template<typename NucleusSequenceT>
952  static void saveList(
953  NucleusSequenceT const &nuclei, std::string const &outFileName,
954  std::string const &group);
955 
956 /*======================================================================*/
974 /*======================================================================*/
975  template<typename NucleusSequenceT>
976  static void loadList(NucleusSequenceT &nuclei,
977  BlitzH5File const &inFile, std::string const &group,
978  bool showWarnings = false);
979 
980 /*======================================================================*/
995 /*======================================================================*/
996  template<typename NucleusSequenceT>
997  static void loadList(
998  NucleusSequenceT &nuclei, std::string const &inFileName,
999  std::string const &group, bool showWarnings = false);
1000 
1001  private:
1002 
1003  static void _loadFixedSize(
1004  blitz::Array<bool,1> &buf, BlitzH5File const &inFile,
1005  std::string const &dsName, bool showWarnings = false);
1006 
1007  template<typename DataT>
1008  static void _loadFixedSize(
1009  blitz::Array<DataT,1> &buf, BlitzH5File const &inFile,
1010  std::string const &dsName, bool showWarnings = false);
1011 
1012  // General marker fields
1013  std::string _id;
1014  blitz::TinyVector<double,3> _positionUm;
1015  int _label, _predictedLabel;
1016  bool _manual, _needsFeatureUpdate;
1017  std::vector<double> _features;
1018  std::map<int,double> _probabilityMap;
1019  double _qcDistanceUm, _radialDistanceUm, _phi;
1020 
1021  // SphereMarker specific fields
1022  double _radiusUm;
1023 
1024  // SHSurface marker specific fields
1025  blitz::Array<std::complex<double>,1> _coefficients;
1026 
1027  // Nucleaus marker specific fields
1028  double _value, _confidence, _sphase, _borderDistanceUm, _volumeUm3;
1029  bool _mitotic, _predictedMitotic;
1030  int _subtype, _predictedSubtype, _cellfile, _predictedCellfile;
1031 
1032  };
1033 
1034 /*======================================================================*/
1044 /*======================================================================*/
1045  std::ostream &operator<<(std::ostream &os, Nucleus const &nc);
1046 
1047 }
1048 
1049 #include "ATBNucleus.icc"
1050 
1051 #endif
void setPredictedSubtype(int subType)
Set the predicted sub-type of this Nucleus.
Definition: ATBNucleus.hh:834
std::string const & id() const
Get the id string for this Nucleus.
Definition: ATBNucleus.hh:187
TinyMatrix< bool, NRows, NColumns > operator==(TinyMatrix< DataT, NRows, NColumns > const &lhs, TinyMatrix< DataT, NRows, NColumns > const &rhs)
Elementwise comparison for equality of two blitz::TinyMatrices.
bool needsFeatureUpdate() const
This function should return true if the feature vector needs to be recomputed prior to a classificati...
Definition: ATBNucleus.hh:363
The Nucleus class contains cell nucleus attributes and provides methods to load and save single nucle...
Definition: ATBNucleus.hh:59
void setPredictedLabel(int predictedLabel)
Set the predicted cell layer label of the nucleus.
Definition: ATBNucleus.hh:318
double sphase() const
Get the S-Phase probability of this Nucleus (if available).
Definition: ATBNucleus.hh:637
void setRadialDistanceUm(double radialDistanceUm)
Set the distance of this nucleus to the root axis in micrometers.
Definition: ATBNucleus.hh:486
std::map< int, double > & probabilityMap()
Get a random-access reference to the probability map of this Nucleus.
Definition: ATBNucleus.hh:415
~Nucleus()
Destructor.
Definition: ATBNucleus.hh:136
void setPredictedCellfile(int predictedCellfile)
Set the predicted cell file index of this nucleus.
Definition: ATBNucleus.hh:896
blitz::Array< std::complex< double >, 1 > const & shCoefficients() const
Get a read-only reference to the spherical harmonic coefficients describing the shape of this Nucleus...
Definition: ATBNucleus.hh:553
static void loadList(NucleusSequenceT &nuclei, BlitzH5File const &inFile, std::string const &group, bool showWarnings=false)
File IO Function for reading a list of Nuclei.
Exception specialization for error handling within libArrayToolbox.
std::ostream & operator<<(std::ostream &os, BasicTreeNode< KeyT, ContentT > const &n)
double qcDistanceUm() const
Get the (signed) distance between this nucleus and the root&#39;s quiescent center along the root axis in...
Definition: ATBNucleus.hh:445
int predictedCellfile() const
Get the predicted cell file index of this nucleus.
Definition: ATBNucleus.hh:881
int subtype() const
Get the sub-type of this Nucleus.
Definition: ATBNucleus.hh:785
std::map< int, double > const & probabilityMap() const
Get a read-only reference to the probability map of this Nucleus.
Definition: ATBNucleus.hh:430
std::vector< double > & features()
Get a random-access reference to the feature vector of this Nucleus.
Definition: ATBNucleus.hh:388
bool operator<(const Nucleus &rhs) const
Less than operator comparing the value field of this Nucleus and the given right-hand-side Nucleus...
Definition: ATBNucleus.hh:911
std::vector< double > const & features() const
Get a read-only reference to the feature vector of this Nucleus.
Definition: ATBNucleus.hh:400
bool predictedMitotic() const
Get the predicted mitotic state (dividing/not dividing) of this Nucleus.
Definition: ATBNucleus.hh:753
Lightweight alternative to libBlitzHDF5 providing its basic functionality.
void setPhi(const double phi)
Set the angle around the root axis of this nucleus in radians.
Definition: ATBNucleus.hh:512
int predictedSubtype() const
Get the predicted sub-type of this Nucleus.
Definition: ATBNucleus.hh:818
void setSubtype(int subType)
Set the sub-type of this Nucleus.
Definition: ATBNucleus.hh:802
void setManual(bool manual)
Set the manual flag for this Nucleus.
Definition: ATBNucleus.hh:350
void setId(std::string const &id)
Set the id string for this Nucleus.
Definition: ATBNucleus.hh:202
blitz::TinyVector< double, 3 > const & positionUm() const
Get the Nucleus position in micrometers.
Definition: ATBNucleus.hh:214
Query specific information about different data types.
void setConfidence(double confidence)
Set the content of the confidence field of this Nucleus.
Definition: ATBNucleus.hh:624
void setRadiusUm(const double radiusUm)
Set the radius of the Nucleus in micrometers.
Definition: ATBNucleus.hh:538
double value() const
Get the content of the value field of this Nucleus.
Definition: ATBNucleus.hh:582
Nucleus & operator=(Nucleus const &nc)
Copy assignment operator.
Definition: ATBNucleus.hh:147
void setMitotic(bool mitotic)
Set the mitotic state (dividing/not dividing) of this Nucleus.
Definition: ATBNucleus.hh:738
void setQcDistanceUm(double qcDistanceUm)
Set the (signed) distance between this nucleus and the root&#39;s quiescent center along the root axis in...
Definition: ATBNucleus.hh:460
double radiusUm() const
Get the radius of the Nucleus in micrometers.
Definition: ATBNucleus.hh:525
void setLabel(int label)
Set the cell layer label of the nucleus.
Definition: ATBNucleus.hh:272
Nucleus(Nucleus const &nc)
Copy constructor.
Definition: ATBNucleus.hh:113
void setValue(double value)
Set the content of the value field of this Nucleus.
Definition: ATBNucleus.hh:596
int cellfile() const
Get the cell file index of this nucleus.
Definition: ATBNucleus.hh:850
int label() const
Get the cell layer label of the nucleus.
Definition: ATBNucleus.hh:249
void setVolumeUm3(double volumeUm3)
Set the volume of this nucleus in micrometers cube.
Definition: ATBNucleus.hh:706
void setPositionUm(blitz::TinyVector< double, 3 > const &positionUm)
Set the Nucleus position in micrometers.
Definition: ATBNucleus.hh:226
bool manual() const
Get the manual flag for this Nucleus.
Definition: ATBNucleus.hh:334
bool mitotic() const
Get the mitotic state (dividing/not dividing) of this Nucleus.
Definition: ATBNucleus.hh:722
static void saveList(NucleusSequenceT const &nuclei, BlitzH5File &outFile, std::string const &group)
File IO Function for writing a list of Nuclei.
double phi() const
Get the angle around the root axis of this nucleus in radians.
Definition: ATBNucleus.hh:499
void setSphase(double sphase)
Set the S-Phase probability of this Nucleus.
Definition: ATBNucleus.hh:650
void setBorderDistanceUm(double borderDistanceUm)
Set the distance of this nucleus to the outer root boundary in micrometers.
Definition: ATBNucleus.hh:680
Nucleus()
Default constructor.
Definition: ATBNucleus.hh:96
void setPredictedMitotic(bool predictedMitotic)
Set the predicted mitotic state (dividing/not dividing) of this Nucleus.
Definition: ATBNucleus.hh:768
double radialDistanceUm() const
Get the distance of this nucleus to the root axis in micrometers.
Definition: ATBNucleus.hh:473
blitz::Array< std::complex< double >, 1 > & shCoefficients()
Get a random-access reference to the spherical harmonic coefficients describing the shape of this Nuc...
Definition: ATBNucleus.hh:568
double borderDistanceUm() const
Get the distance of this nucleus to the outer root boundary in micrometers.
Definition: ATBNucleus.hh:665
double confidence() const
Get the content of the confidence field of this Nucleus.
Definition: ATBNucleus.hh:610
void setCellfile(int cellfile)
Set the cell file index of this nucleus.
Definition: ATBNucleus.hh:866
int predictedLabel() const
Get the predicted cell layer label of the nucleus.
Definition: ATBNucleus.hh:295
void setNeedsFeatureUpdate(bool needsFeatureUpdate)
Set or reset the needsFeatureUpdate flag.
Definition: ATBNucleus.hh:376
double volumeUm3() const
Get the volume of this nucleus in micrometers cube.
Definition: ATBNucleus.hh:693