SMIL  1.0.4
DendroNode.hpp
1 /*
2  * Copyright (c) 2011-2015, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
18  * AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
22  * LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * last modification by Amin Fehri
31  *
32  */
33 
34 #ifndef _DENDRO_NODE_HPP
35 #define _DENDRO_NODE_HPP
36 
37 #include "Core/include/DCore.h"
38 #include "Morpho/include/DMorpho.h"
39 #include "Morpho/include/DStructuringElement.h"
40 
41 #include <unistd.h> // For usleep
42 
43 #include <algorithm>
44 #include <cmath>
45 #include <functional>
46 #include <iostream>
47 #include <numeric>
48 #include <vector>
49 
50 namespace smil
51 {
55  template <class MarkerLabelT = size_t>
56  class DendroNode
57  {
58  protected:
59  double valuation;
60  double internalNodeValuationInitial;
61  double internalNodeValuationFinal;
62  double leafValuation;
63  double energy;
64  MarkerLabelT marker;
65  MarkerLabelT label;
66  MarkerLabelT nbMarkersUnder;
67  vector<MarkerLabelT> markersCount;
68  vector<MarkerLabelT> lookupProgeny;
69  bool isInternalNode;
70  DendroNode * father;
71  DendroNode * childLeft;
72  DendroNode * childRight;
73  DendroNode * neighborLeft;
74  DendroNode * neighborRight;
75  std::vector<double> moments;
76  vector<MarkerLabelT> contoursCount;
77  double contoursSize;
78  double fidelityTerm;
79 
80  public:
84  : valuation(0), internalNodeValuationInitial(0),
85  internalNodeValuationFinal(0), leafValuation(0), energy(0), marker(0),
86  label(0), nbMarkersUnder(0), markersCount(0), lookupProgeny(0),
87  isInternalNode(0), father(0), childLeft(0), childRight(0),
88  neighborLeft(0), neighborRight(0), moments(0), contoursCount(0),
89  contoursSize(0), fidelityTerm(0)
90  {
91  }
93  DendroNode(const DendroNodeType &dendroNodeToCopy)
94  { // shallow copy
95  valuation = dendroNodeToCopy.valuation;
96  internalNodeValuationInitial =
97  dendroNodeToCopy.internalNodeValuationInitial;
98  internalNodeValuationFinal = dendroNodeToCopy.internalNodeValuationFinal;
99  leafValuation = dendroNodeToCopy.leafValuation;
100  energy = dendroNodeToCopy.energy;
101  marker = dendroNodeToCopy.marker;
102  label = dendroNodeToCopy.label;
103  nbMarkersUnder = dendroNodeToCopy.nbMarkersUnder;
104  markersCount = dendroNodeToCopy.markersCount;
105  lookupProgeny = dendroNodeToCopy.lookupProgeny;
106  isInternalNode = dendroNodeToCopy.isInternalNode;
107  moments = dendroNodeToCopy.moments;
108  contoursCount = dendroNodeToCopy.contoursCount;
109  contoursSize = dendroNodeToCopy.contoursSize;
110  fidelityTerm = dendroNodeToCopy.fidelityTerm;
111 
112  if (dendroNodeToCopy.father != NULL) {
113  father = new DendroNodeType(*(dendroNodeToCopy.father));
114  } else {
115  father = NULL;
116  }
117  if (dendroNodeToCopy.childLeft != NULL) {
118  childLeft = new DendroNodeType(*(dendroNodeToCopy.childLeft));
119  } else {
120  childLeft = NULL;
121  }
122  if (dendroNodeToCopy.childRight != NULL) {
123  childRight = new DendroNodeType(*(dendroNodeToCopy.childRight));
124  } else {
125  childRight = NULL;
126  }
127  if (dendroNodeToCopy.neighborLeft != NULL) {
128  neighborLeft = new DendroNodeType(*(dendroNodeToCopy.neighborLeft));
129  } else {
130  neighborLeft = NULL;
131  }
132  if (dendroNodeToCopy.neighborRight != NULL) {
133  neighborRight = new DendroNodeType(*(dendroNodeToCopy.neighborRight));
134  } else {
135  neighborRight = NULL;
136  }
137  }
139  DendroNode &operator=(DendroNode const &dendroNodeToCopy)
140  {
141  if (this != &dendroNodeToCopy) {
142  valuation = dendroNodeToCopy.valuation;
143  internalNodeValuationInitial =
144  dendroNodeToCopy.internalNodeValuationInitial;
145  internalNodeValuationFinal =
146  dendroNodeToCopy.internalNodeValuationFinal;
147  leafValuation = dendroNodeToCopy.leafValuation;
148  marker = dendroNodeToCopy.marker;
149  markersCount = dendroNodeToCopy.markersCount;
150  lookupProgeny = dendroNodeToCopy.lookupProgeny;
151  label = dendroNodeToCopy.label;
152  nbMarkersUnder = dendroNodeToCopy.nbMarkersUnder;
153  isInternalNode = dendroNodeToCopy.isInternalNode;
154  moments = dendroNodeToCopy.moments;
155  contoursCount = dendroNodeToCopy.contoursCount;
156  contoursSize = dendroNodeToCopy.contoursSize;
157  fidelityTerm = dendroNodeToCopy.fidelityTerm;
158  if (dendroNodeToCopy.father != NULL) {
159  delete father;
160  father = new DendroNodeType(*(dendroNodeToCopy.father));
161  } else {
162  father = NULL;
163  }
164  if (dendroNodeToCopy.childLeft != NULL) {
165  delete childLeft;
166  childLeft = new DendroNodeType(*(dendroNodeToCopy.childLeft));
167  } else {
168  childLeft = NULL;
169  }
170  if (dendroNodeToCopy.childRight != NULL) {
171  delete childRight;
172  childRight = new DendroNodeType(*(dendroNodeToCopy.childRight));
173  } else {
174  childRight = NULL;
175  }
176  if (dendroNodeToCopy.neighborLeft != NULL) {
177  delete neighborLeft;
178  neighborLeft = new DendroNodeType(*(dendroNodeToCopy.neighborLeft));
179  } else {
180  neighborLeft = NULL;
181  }
182  if (dendroNodeToCopy.neighborRight != NULL) {
183  delete neighborRight;
184  neighborRight = new DendroNodeType(*(dendroNodeToCopy.neighborRight));
185  } else {
186  neighborRight = NULL;
187  }
188  }
189  return *this;
190  }
192  virtual ~DendroNode()
193  {
194  }
197  {
198  return internalNodeValuationInitial;
199  };
200  void setInternalNodeValuationInitial(double nValuation)
201  {
202  internalNodeValuationInitial = nValuation;
203  };
204  double getInternalNodeValuationFinal()
205  {
206  return internalNodeValuationFinal;
207  };
208  void setInternalNodeValuationFinal(double nValuation)
209  {
210  internalNodeValuationFinal = nValuation;
211  };
212  double getValuation()
213  {
214  return valuation;
215  };
216  void setValuation(double nValuation)
217  {
218  valuation = nValuation;
219  };
220  double getLeafValuation()
221  {
222  return leafValuation;
223  };
224  void setLeafValuation(double nValuation)
225  {
226  leafValuation = nValuation;
227  };
228  void setEnergy(double nEnergy)
229  {
230  energy = nEnergy;
231  }
232  double getEnergy()
233  {
234  return energy;
235  };
236  MarkerLabelT getMarker()
237  {
238  return marker;
239  };
240  void setMarker(double nMarker)
241  {
242  marker = nMarker;
243  };
244  MarkerLabelT getLabel()
245  {
246  return label;
247  };
248  void setLabel(double nLabel)
249  {
250  label = nLabel;
251  };
252  MarkerLabelT getNbMarkersUnder()
253  {
254  return nbMarkersUnder;
255  };
256  void setNbMarkersUnder(MarkerLabelT nNbMarkersUnder)
257  {
258  nbMarkersUnder = nNbMarkersUnder;
259  };
260  std::vector<MarkerLabelT> &getMarkersCount()
261  {
262  return markersCount;
263  };
264  void setMarkersCount(std::vector<MarkerLabelT> nMarkersCount)
265  {
266  markersCount = nMarkersCount;
267  };
268  std::vector<MarkerLabelT> &getLookupProgeny()
269  {
270  return lookupProgeny;
271  }
272  void setLookupProgeny(std::vector<MarkerLabelT> nLookupProgeny)
273  {
274  lookupProgeny = nLookupProgeny;
275  }
276  bool getIsInternalNode()
277  {
278  return isInternalNode;
279  };
280  void setIsInternalNode(bool nIsInternalNode)
281  {
282  isInternalNode = nIsInternalNode;
283  };
284  DendroNode *getFather()
285  {
286  return father;
287  };
288  void setFather(DendroNode *nFather)
289  {
290  father = nFather;
291  };
292  DendroNode *getChildLeft()
293  {
294  return childLeft;
295  };
296  void setChildLeft(DendroNode *nChildLeft)
297  {
298  childLeft = nChildLeft;
299  };
300  DendroNode *getChildRight()
301  {
302  return childRight;
303  };
304  void setChildRight(DendroNode *nChildRight)
305  {
306  childRight = nChildRight;
307  };
308  DendroNode *getNeighborLeft()
309  {
310  return neighborLeft;
311  };
312  void setNeighborLeft(DendroNode *nNeighborLeft)
313  {
314  neighborLeft = nNeighborLeft;
315  };
316  DendroNode *getNeighborRight()
317  {
318  return neighborRight;
319  };
320  void setNeighborRight(DendroNode *nNeighborRight)
321  {
322  neighborRight = nNeighborRight;
323  };
324  std::vector<double> getMoments()
325  {
326  return moments;
327  }
328  void setMoments(std::vector<double> nMoments)
329  {
330  moments = nMoments;
331  }
332  vector<MarkerLabelT> getContoursCount()
333  {
334  return contoursCount;
335  }
336  void setContoursCount(vector<MarkerLabelT> nContoursCount)
337  {
338  contoursCount = nContoursCount;
339  };
340  double getContoursSize()
341  {
342  return contoursSize;
343  }
344  void setContoursSize(double nContoursSize)
345  {
346  contoursSize = nContoursSize;
347  }
348  double getFidelityTerm()
349  {
350  return fidelityTerm;
351  };
352  void setFidelityTerm(double nFidelityTerm)
353  {
354  fidelityTerm = nFidelityTerm;
355  }
356  DendroNode *getAncestor()
357  {
358  DendroNode *refToReturn = this;
359  if (refToReturn->getFather() != NULL) {
360  while (refToReturn != refToReturn->getFather() &&
361  refToReturn->getFather() != NULL) {
362  refToReturn = refToReturn->getFather();
363  }
364  }
365  return refToReturn;
366  };
367  DendroNode *getSelf()
368  {
369  return this;
370  };
372  static bool isInferior(DendroNode *dendroNodeL, DendroNode *dendroNodeR)
373  {
374  return dendroNodeL->getInternalNodeValuationInitial() <
375  dendroNodeR->getInternalNodeValuationInitial();
376  };
377  static bool isSuperior(DendroNode *dendroNodeL, DendroNode *dendroNodeR)
378  {
379  return dendroNodeL->getInternalNodeValuationInitial() >
380  dendroNodeR->getInternalNodeValuationInitial();
381  };
383  bool operator<(const DendroNode &nDendroNode)
384  {
385  return internalNodeValuationInitial <
386  nDendroNode.internalNodeValuationInitial;
387  };
388  bool operator>(const DendroNode &nDendroNode)
389  {
390  return internalNodeValuationInitial >
391  nDendroNode.internalNodeValuationInitial;
392  };
393  bool operator==(const DendroNode &nDendroNode)
394  {
395  return internalNodeValuationInitial ==
396  nDendroNode.internalNodeValuationInitial;
397  };
398  }; // end DendroNode
399 
400 } // namespace smil
401 
402 #endif // _DENDRO_NODE_HPP
DendroNode : node of a Dendrogram.
Definition: DendroNode.hpp:57
DendroNode()
Default constructor.
Definition: DendroNode.hpp:83
DendroNode & operator=(DendroNode const &dendroNodeToCopy)
Assignment operator.
Definition: DendroNode.hpp:139
DendroNode(const DendroNodeType &dendroNodeToCopy)
Copy constructor.
Definition: DendroNode.hpp:93
double getInternalNodeValuationInitial()
Setters and getters.
Definition: DendroNode.hpp:196
bool operator<(const DendroNode &nDendroNode)
Operators overriding.
Definition: DendroNode.hpp:383
static bool isInferior(DendroNode *dendroNodeL, DendroNode *dendroNodeR)
Comparison functions.
Definition: DendroNode.hpp:372
virtual ~DendroNode()
Destructor.
Definition: DendroNode.hpp:192
size_t label(const Image< T1 > &imIn, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
label() - Image labelization
Definition: DMorphoLabel.hpp:564