iRoCS Toolbox  1.1.0
Marker.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * This file belongs to the iRoCS Toolbox.
4  *
5  * Copyright (C) 2015 Thorsten Falk
6  *
7  * Image Analysis Lab, University of Freiburg, Germany
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  **************************************************************************/
24 
25 #ifndef MARKER_HH
26 #define MARKER_HH
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.hh>
30 #endif
31 
32 #include <QtCore/QObject>
33 
34 #include <blitz/array.h>
36 
38 
39 #include <map>
40 
41 class MarkerPresetWidget;
43 
44 class OrthoViewWidget;
46 class MarkerRenderer;
47 class ViewWidget;
48 
49 /*======================================================================*/
55 /*======================================================================*/
56 class Marker : public QObject
57 {
58 
59  Q_OBJECT
60 
61 public:
62 
63 /*======================================================================*/
72 /*======================================================================*/
73  enum MarkerType {
74  Point = 0x0000,
75  Sphere = 0x0001,
76  Nucleus = 0x0002,
77  Cylinder = 0x0003,
78  SHSurface = 0x0004,
79  Surface = 0x005,
80  Cell = 0x006
81  };
82 
83 /*======================================================================*/
96 /*======================================================================*/
97  static QStringList supportedMarkerTypes();
98 
99 /*======================================================================*/
109 /*======================================================================*/
110  static MarkerType markerTypeFromString(QString const &name);
111 
112 /*======================================================================*/
120 /*======================================================================*/
121  static QString markerTypeToString(Marker::MarkerType m);
122 
123 /*======================================================================*/
134 /*======================================================================*/
136 
137 /*======================================================================*/
149 /*======================================================================*/
150  Marker(blitz::TinyVector<double,3> const &positionUm,
152 
153 /*======================================================================*/
161 /*======================================================================*/
162  Marker(Marker const &marker);
163 
164 /*======================================================================*/
168 /*======================================================================*/
169  virtual ~Marker();
170 
171 /*======================================================================*/
180 /*======================================================================*/
181  Marker &operator=(Marker const &marker);
182 
183 /*======================================================================*/
190 /*======================================================================*/
191  virtual MarkerType markerType() const = 0;
192 
193 /*======================================================================*/
201 /*======================================================================*/
202  virtual bool inherits(MarkerType type) const = 0;
203 
204 /*======================================================================*/
212 /*======================================================================*/
214 
215 /*======================================================================*/
222 /*======================================================================*/
224 
225 /*======================================================================*/
240 /*======================================================================*/
241  virtual MarkerRenderer *addRenderer(ViewWidget *view) = 0;
242 
243 /*======================================================================*/
249 /*======================================================================*/
250  void removeRenderer(ViewWidget *view);
251 
252 /*======================================================================*/
260 /*======================================================================*/
261  MarkerRenderer *renderer(ViewWidget *view) const;
262 
263 /*======================================================================*/
270 /*======================================================================*/
271  const std::map<ViewWidget*, MarkerRenderer*> &renderers() const;
272 
273 /*======================================================================*/
283 /*======================================================================*/
284  std::string id() const;
285 
286 /*======================================================================*/
293 /*======================================================================*/
294  void setId(const std::string& id);
295 
296 /*======================================================================*/
305 /*======================================================================*/
306  blitz::TinyVector<double,3> positionUm() const;
307 
308 /*======================================================================*/
316 /*======================================================================*/
317  void setPositionUm(const blitz::TinyVector<double,3>& positionUm);
318 
319 /*======================================================================*/
326 /*======================================================================*/
327  blitz::TinyVector<double,3> relativePositionUm() const;
328 
329 /*======================================================================*/
336 /*======================================================================*/
337  void setRelativePositionUm(const blitz::TinyVector<double,3>& positionUm);
338 
339  bool manual() const;
340  void setManual(const bool manual);
341 
342  bool needsFeatureUpdate() const;
344 
345  int label() const;
346  void setLabel(const int label);
347 
348  int predictedLabel() const;
349  void setPredictedLabel(const int label);
350 
351  const std::vector<double>& features() const;
352  double& feature(size_t index);
353  std::vector<double>::iterator featuresBegin();
354  std::vector<double>::iterator featuresEnd();
355 
356  const std::map<int,double>& probabilityMap() const;
357  std::map<int,double>::iterator probabilityMapFind(int key);
358  std::map<int,double>::iterator probabilityMapBegin();
359  std::map<int,double>::iterator probabilityMapEnd();
360 
361  double qcDistanceUm() const;
362  void setQcDistanceUm(const double qcDistanceUm);
363 
364  double radialDistanceUm() const;
365  void setRadialDistanceUm(const double radialDistanceUm);
366 
367  double phi() const;
368  void setPhi(const double phi);
369 
370 /*======================================================================*/
377 /*======================================================================*/
378  blitz::TinyVector<float,3> const &randomColor() const;
379 
380  static void save(
382  BlitzH5File &outFile, std::string const &group,
383  iRoCS::ProgressReporter *pr = NULL);
384  static void load(
386  std::string const &group, iRoCS::ProgressReporter *pr = NULL);
387 
388  virtual void writeCSVHeader(std::ofstream &out) const;
389  virtual void saveCSV(std::ofstream &out) const;
390  virtual void loadFromMap(std::map<std::string,std::string> const &values);
391 
392  void setSelected(bool selected);
393  bool selected() const;
394 
395 /*======================================================================*/
407 /*======================================================================*/
408  virtual bool occupiesPositionUm(
409  blitz::TinyVector<double,3> const &positionUm) const = 0;
410 
411 /*======================================================================*/
417 /*======================================================================*/
418  blitz::TinyVector<double,3> boundingBoxLowerBoundUm() const;
419 
420 /*======================================================================*/
426 /*======================================================================*/
427  blitz::TinyVector<double,3> boundingBoxUpperBoundUm() const;
428 
429 /*======================================================================*/
435 /*======================================================================*/
436  bool updatesEnabled() const;
437 
438  virtual void copyToATBNucleus(atb::Nucleus &nc) const;
439  virtual void copyFromATBNucleus(atb::Nucleus const &nc);
440 
441 public slots:
442 
443 /*======================================================================*/
452 /*======================================================================*/
453  void setUpdatesEnabled(bool enable);
454 
455 /*======================================================================*/
462 /*======================================================================*/
463  void update();
464 
465 protected:
466 
467  void setFeatures(const std::vector<double>& features);
468  void setProbabilityMap(const std::map<int,double>& probabilityMap);
469 
470  static void _loadFixedSize(
471  blitz::Array<bool,1> &buf, BlitzH5File const &inFile,
472  std::string const &dsName, bool showWarnings = false);
473 
474  template<typename DataT>
475  static void _loadFixedSize(
476  blitz::Array<DataT,1> &buf, BlitzH5File const &inFile,
477  std::string const &dsName, bool showWarnings = false)
478  {
479  size_t targetSize = buf.size();
480  try
481  {
482  inFile.readDataset(buf, dsName);
483  }
484  catch (BlitzH5Error &)
485  {
486  buf.resize(0);
487  if (showWarnings)
488  std::cerr << "'" << dsName << "' not found. Setting it to -1"
489  << std::endl;
490  }
491  size_t readSize = buf.size();
492  buf.resizeAndPreserve(targetSize);
493  if (readSize < targetSize)
494  buf(blitz::Range(readSize, targetSize - 1)) = DataT(-1);
495  }
496 
497  virtual void _updateBoundingBox() const = 0;
498 
500  std::map<ViewWidget*, MarkerRenderer*> _renderers;
501 
502  std::string _id;
503  blitz::TinyVector<double,3> _positionUm;
506  std::vector<double> _features;
507  std::map<int,double> _probabilityMap;
509 
510  blitz::TinyVector<float,3> _randomColor;
511 
512 /*======================================================================*/
517 /*======================================================================*/
518  mutable bool _boundingBoxUpToDate;
519 
520 /*======================================================================*/
525 /*======================================================================*/
526  mutable blitz::TinyVector<double,3> _boundingBoxLowerBoundUm;
527 
528 /*======================================================================*/
533 /*======================================================================*/
534  mutable blitz::TinyVector<double,3> _boundingBoxUpperBoundUm;
535 
536  friend class MarkerControlWidget;
538 
539 private:
540 
541  bool _updatesEnabled;
542 
543 };
544 
545 #endif
static MarkerType markerTypeFromString(QString const &name)
Get the MarkerType corresponding to the given string representation.
double radialDistanceUm() const
const std::map< ViewWidget *, MarkerRenderer * > & renderers() const
Get a map containing all ViewWidgets this Marker is currently drawn in and the corresponding MarkerRe...
void setRadialDistanceUm(const double radialDistanceUm)
static void _loadFixedSize(blitz::Array< bool, 1 > &buf, BlitzH5File const &inFile, std::string const &dsName, bool showWarnings=false)
The Nucleus class contains cell nucleus attributes and provides methods to load and save single nucle...
Definition: ATBNucleus.hh:59
bool updatesEnabled() const
Check whether cache updates for this marker are enabled.
std::map< int, double >::iterator probabilityMapFind(int key)
std::string id() const
Get the marker id.
void setManual(const bool manual)
blitz::TinyVector< double, 3 > boundingBoxUpperBoundUm() const
Get the upper bound of the marker&#39;s bounding box for all dimensions.
blitz::TinyVector< double, 3 > relativePositionUm() const
Get the marker position relative to the group transformation.
virtual void copyToATBNucleus(atb::Nucleus &nc) const
double _qcDistance
Definition: Marker.hh:508
Marker(AnnotationChannelSpecs *channel=NULL)
Constructor.
void setSelected(bool selected)
double qcDistanceUm() const
void setPredictedLabel(const int label)
The Marker class specifies the properties of an abstract Marker that can be contained in an Annotatio...
Definition: Marker.hh:56
virtual void copyFromATBNucleus(atb::Nucleus const &nc)
virtual void _updateBoundingBox() const =0
MarkerRenderer * renderer(ViewWidget *view) const
Get the rendering engine for this Marker and the given view.
std::vector< double > _features
Definition: Marker.hh:506
std::string _id
Definition: Marker.hh:502
virtual ~Marker()
Destructor.
void setFeatures(const std::vector< double > &features)
double phi() const
blitz::TinyVector< double, 3 > positionUm() const
Get the absolute marker world position in micrometers.
double _phi
Definition: Marker.hh:508
virtual void loadFromMap(std::map< std::string, std::string > const &values)
virtual void writeCSVHeader(std::ofstream &out) const
bool manual() const
void setUpdatesEnabled(bool enable)
Enables/Disables cache updates for this marker.
int _predictedLabel
Definition: Marker.hh:504
virtual bool inherits(MarkerType type) const =0
Checks whether this marker is of the given MarkerType or derives from it.
The main error class for the BlitzHDF5 interface.
virtual void saveCSV(std::ofstream &out) const
virtual bool occupiesPositionUm(blitz::TinyVector< double, 3 > const &positionUm) const =0
This methods checks whether the given micrometer world position is within the marker volume and is ma...
blitz::TinyVector< float, 3 > const & randomColor() const
If the view type is set to random use this color to obtain the marker color to use.
virtual MarkerRenderer * addRenderer(ViewWidget *view)=0
Add a rendering engine for the given view to this marker.
Lightweight alternative to libBlitzHDF5 providing its basic functionality.
blitz::TinyVector< double, 3 > _boundingBoxLowerBoundUm
This variable contains the lower bound of this marker in micrometers relative to its world position i...
Definition: Marker.hh:526
void setChannel(AnnotationChannelSpecs *channel)
Add this marker to the given channel.
bool needsFeatureUpdate() const
int _label
Definition: Marker.hh:504
double & feature(size_t index)
double _radialDistance
Definition: Marker.hh:508
void setPositionUm(const blitz::TinyVector< double, 3 > &positionUm)
Set the absolute marker world position in micrometers.
bool selected() const
Nucleus class containing cell nucelus specific parameters.
void removeRenderer(ViewWidget *view)
Remove the renderer for the given view.
blitz::TinyVector< double, 3 > _boundingBoxUpperBoundUm
This variable contains the lower bound of this marker in micrometers relative to its world position i...
Definition: Marker.hh:534
void update()
Explicitely trigger a cache update for all associated renderers.
blitz::TinyVector< double, 3 > boundingBoxLowerBoundUm() const
Get the lower bound of the marker&#39;s bounding box for all dimensions.
Marker & operator=(Marker const &marker)
Copy assignment operator.
int predictedLabel() const
static void _loadFixedSize(blitz::Array< DataT, 1 > &buf, BlitzH5File const &inFile, std::string const &dsName, bool showWarnings=false)
Definition: Marker.hh:475
static QString markerTypeToString(Marker::MarkerType m)
Get the string representation of the given MarkerType.
std::vector< double >::iterator featuresEnd()
virtual MarkerType markerType() const =0
Get the MarkerType enum value for this marker.
std::map< ViewWidget *, MarkerRenderer * > _renderers
Definition: Marker.hh:500
std::map< int, double >::iterator probabilityMapBegin()
void setNeedsFeatureUpdate(bool needsFeatureUpdate)
static QStringList supportedMarkerTypes()
Get a QStringList containing string representations of all marker types.
void setRelativePositionUm(const blitz::TinyVector< double, 3 > &positionUm)
Set the marker position relative to the group transformation.
int label() const
std::map< int, double > _probabilityMap
Definition: Marker.hh:507
AnnotationChannelSpecs * channel() const
Get the channel this marker belongs to.
void setPhi(const double phi)
std::vector< double >::iterator featuresBegin()
const std::vector< double > & features() const
void setId(const std::string &id)
Set the marker id.
bool _boundingBoxUpToDate
If this variable is set to false, the next query for the marker&#39;s bounding box will update it...
Definition: Marker.hh:518
const std::map< int, double > & probabilityMap() const
static void load(AnnotationChannelSpecs *channel, BlitzH5File const &inFile, std::string const &group, iRoCS::ProgressReporter *pr=NULL)
void setProbabilityMap(const std::map< int, double > &probabilityMap)
MarkerType
Marker.hh "liblabelling_qt4/Marker.hh".
Definition: Marker.hh:73
void setLabel(const int label)
std::map< int, double >::iterator probabilityMapEnd()
bool _needsFeatureUpdate
Definition: Marker.hh:505
void readDataset(FixedNumericT &data, std::string const &name) const
Reads a simple, fixed size numeric data set.
static void save(AnnotationChannelSpecs const *channel, BlitzH5File &outFile, std::string const &group, iRoCS::ProgressReporter *pr=NULL)
AnnotationChannelSpecs * p_channel
Definition: Marker.hh:499
void setQcDistanceUm(const double qcDistanceUm)
bool _manual
Definition: Marker.hh:505
blitz::TinyVector< float, 3 > _randomColor
Definition: Marker.hh:510
blitz::TinyVector< double, 3 > _positionUm
Definition: Marker.hh:503