15 #define RESIZE_FACTOR 20
16 #define MATLAB_INDEX_FACTOR 1
134 if (
Data.empty())
return false;
153 void PrintPairs(
const std::vector<TPairedExtrema>& pairs)
const
155 for (std::vector<TPairedExtrema>::const_iterator it = pairs.begin();
156 it != pairs.end(); it++)
158 std::cout <<
"Persistence: " << (*it).Persistence
159 <<
" minimum index: " << (*it).MinIndex
160 <<
" maximum index: " << (*it).MaxIndex
172 void PrintResults(
const float threshold = 0.0,
const bool matlabIndexing =
false)
const
176 std::cout <<
"Error. Threshold value must be greater than or equal to 0" << std::endl;
178 if (threshold==0 && !matlabIndexing)
184 std::vector<TPairedExtrema> pairs;
206 bool GetPairedExtrema(std::vector<TPairedExtrema> & pairs,
const float threshold = 0,
const bool matlabIndexing =
false)
const
217 pairs = std::vector<TPairedExtrema>(lower_bound,
PairedExtrema.end());
221 for (std::vector<TPairedExtrema>::iterator p = pairs.begin(); p != pairs.end(); p++)
241 bool GetExtremaIndices(std::vector<int> & min, std::vector<int> & max,
const float threshold = 0,
const bool matlabIndexing =
false)
const
252 int matlabIndexFactor = 0;
257 for (std::vector<TPairedExtrema>::const_iterator p = lower_bound; p !=
PairedExtrema.end(); p++)
259 min.push_back((*p).MinIndex + matlabIndexFactor);
260 max.push_back((*p).MaxIndex + matlabIndexFactor);
307 std::vector<int> min, max;
308 std::vector<int> combinedIndices;
314 std::sort(min.begin(), min.end());
315 std::sort(max.begin(), max.end());
316 combinedIndices.reserve(min.size() + max.size());
317 std::set_union(min.begin(), min.end(), max.begin(), max.end(), std::inserter(combinedIndices, combinedIndices.begin()));
320 if (combinedIndices.size() != (min.size() + max.size()) ||
321 std::binary_search(combinedIndices.begin(), combinedIndices.end(), globalMinIdx) ==
true)
326 if ((globalMinIdx > (
int)
Data.size()-1) || (globalMinIdx < -1)) flag =
false;
327 if (globalMinIdx == -1 && min.size() != 0) flag =
false;
329 std::vector<int>::iterator minUniqueEnd = std::unique(min.begin(), min.end());
330 std::vector<int>::iterator maxUniqueEnd = std::unique(max.begin(), max.end());
332 if (minUniqueEnd != min.end() ||
333 maxUniqueEnd != max.end() ||
334 (minUniqueEnd - min.begin()) != (maxUniqueEnd - max.begin()))
391 int survivorIdx, destroyedIdx;
395 survivorIdx = firstIdx;
396 destroyedIdx = secondIdx;
400 survivorIdx = secondIdx;
401 destroyedIdx = firstIdx;
403 else if (firstIdx < secondIdx)
406 survivorIdx = firstIdx;
407 destroyedIdx = secondIdx;
411 survivorIdx = secondIdx;
412 destroyedIdx = firstIdx;
420 Colors[Components[destroyedIdx].LeftEdgeIndex] = survivorIdx;
423 if (Components[survivorIdx].MinIndex > Components[destroyedIdx].MinIndex)
425 Components[survivorIdx].LeftEdgeIndex = Components[destroyedIdx].LeftEdgeIndex;
429 Components[survivorIdx].RightEdgeIndex = Components[destroyedIdx].RightEdgeIndex;
444 if (
Data[firstIdx] >
Data[secondIdx])
449 else if (
Data[secondIdx] >
Data[firstIdx])
455 else if (firstIdx < secondIdx)
524 assert(
Components[componentIdx].Alive ==
true)
528 if (dataIdx + 1 ==
Components[componentIdx].LeftEdgeIndex)
530 Components[componentIdx].LeftEdgeIndex = dataIdx;
533 else if (dataIdx - 1 ==
Components[componentIdx].RightEdgeIndex)
535 Components[componentIdx].RightEdgeIndex = dataIdx;
540 std::string errorMessage =
"ExtendComponent: index mismatch. Data index: ";
541 errorMessage += std::to_string((
long long)dataIdx);
542 throw (errorMessage);
546 Colors[dataIdx] = componentIdx;
585 if (
Data.size()==0)
return;
587 for (std::vector<float>::size_type i = 0; i !=
Data.size(); i++)
593 dataidxpair.
Idx = (int)i;
639 else if (i ==
Colors.size()-1)
667 int leftComp, rightComp;
707 if (threshold == 0 || threshold < 0)
return PairedExtrema.begin();
732 throw "Error. Component 0 is not Alive, assumed to contain global minimum";
736 for (std::vector<TComponent>::const_iterator it =
Components.begin()+1; it !=
Components.end(); it++)
738 if ((*it).Alive ==
true)
745 throw "Error. Found more than one alive component";