morphoTreeAdjust 0.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/CMakeLists.txt +1 -1
- {morphotreeadjust-0.1/morphoTreeAdjust.egg-info → morphotreeadjust-0.1.2}/PKG-INFO +1 -1
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/CMakeLists.txt +3 -3
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/include/AdjacencyRelation.hpp +6 -2
- morphotreeadjust-0.1.2/morphoTreeAdjust/include/Common.hpp +57 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/include/ComponentTree.hpp +104 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/include/ComponentTreeAdjustment.hpp +281 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/include/ComponentTreeGeneralAdjustment.hpp +6 -3
- morphotreeadjust-0.1.2/morphoTreeAdjust/include/NodeCT.hpp +603 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/morphoTreeAdjust.cpp +154 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/pybind/PyBindComponentTree.hpp +43 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/pybind/PyBindComponentTreeAdjustment.cpp +32 -0
- morphotreeadjust-0.1.2/morphoTreeAdjust/pybind/PyBindComponentTreeAdjustment.hpp +34 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/src/AdjacencyRelation.cpp +19 -10
- morphotreeadjust-0.1.2/morphoTreeAdjust/src/ComponentTreeAdjustment.cpp +436 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/src/ComponentTreeGeneralAdjustment.cpp +4 -2
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2/morphoTreeAdjust.egg-info}/PKG-INFO +1 -1
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust.egg-info/SOURCES.txt +2 -4
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/setup.py +1 -1
- morphotreeadjust-0.1/morphoTreeAdjust/include/ComponentTree.hpp +0 -71
- morphotreeadjust-0.1/morphoTreeAdjust/include/ComponentTreeAdjustment.hpp +0 -130
- morphotreeadjust-0.1/morphoTreeAdjust/include/NodeCT.hpp +0 -298
- morphotreeadjust-0.1/morphoTreeAdjust/morphoTreeAdjust.cpp +0 -192
- morphotreeadjust-0.1/morphoTreeAdjust/pybind/PyBindComponentTree.cpp +0 -101
- morphotreeadjust-0.1/morphoTreeAdjust/pybind/PyBindComponentTree.hpp +0 -75
- morphotreeadjust-0.1/morphoTreeAdjust/pybind/PyBindComponentTreeAdjustment.cpp +0 -28
- morphotreeadjust-0.1/morphoTreeAdjust/pybind/PyBindComponentTreeAdjustment.hpp +0 -31
- morphotreeadjust-0.1/morphoTreeAdjust/src/ComponentTree.cpp +0 -329
- morphotreeadjust-0.1/morphoTreeAdjust/src/ComponentTreeAdjustment.cpp +0 -421
- morphotreeadjust-0.1/morphoTreeAdjust/src/NodeCT.cpp +0 -97
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/LICENSE +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/MANIFEST.in +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/README.md +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust.egg-info/dependency_links.txt +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust.egg-info/not-zip-safe +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust.egg-info/top_level.txt +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/pybind11.cmake +0 -0
- {morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/setup.cfg +0 -0
|
@@ -22,7 +22,7 @@ project(morphoTreeAdjust)
|
|
|
22
22
|
include_directories("${CMAKE_SOURCE_DIR}/python")
|
|
23
23
|
|
|
24
24
|
file (GLOB SOURCE_FILES "morphoTreeAdjust/src/*.cpp" "morphoTreeAdjust/pybind/*.cpp")
|
|
25
|
-
file (GLOB HEADER_FILES "morphoTreeAdjust/include/*.hpp" "morphoTreeAdjust/pybind/*.hpp")
|
|
25
|
+
file (GLOB HEADER_FILES "morphoTreeAdjust/include/*.hpp" "morphoTreeAdjust/include/*.tpp" "morphoTreeAdjust/pybind/*.hpp")
|
|
26
26
|
file (GLOB PYTHON_FILES "morphoTreeAdjust/*.cpp" "morphoTreeAdjust/*.hpp")
|
|
27
27
|
|
|
28
28
|
# Set up such that XCode organizes the files
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: morphoTreeAdjust
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: MorphoTreeAdjust is a C++/Python implementation for adjusting the morpholofical trees.
|
|
5
5
|
Home-page: https://github.com/wonderalexandre/ComponentTreeLearn
|
|
6
6
|
Author: Wonder Alexandre Luz Alves
|
|
@@ -38,15 +38,15 @@ set(PROJECT_INCLUDE_DIR "include")
|
|
|
38
38
|
# Source files
|
|
39
39
|
set(SOURCE_FILES
|
|
40
40
|
${PROJECT_INCLUDE_DIR}/NodeCT.hpp
|
|
41
|
-
${PROJECT_SOURCE_DIR}/NodeCT.
|
|
41
|
+
${PROJECT_SOURCE_DIR}/NodeCT.tpp
|
|
42
42
|
${PROJECT_INCLUDE_DIR}/ComponentTree.hpp
|
|
43
|
-
${PROJECT_SOURCE_DIR}/ComponentTree.
|
|
43
|
+
${PROJECT_SOURCE_DIR}/ComponentTree.tpp
|
|
44
44
|
${PROJECT_INCLUDE_DIR}/AdjacencyRelation.hpp
|
|
45
45
|
${PROJECT_SOURCE_DIR}/AdjacencyRelation.cpp
|
|
46
46
|
${PROJECT_INCLUDE_DIR}/ComponentTreeAdjustment.hpp
|
|
47
47
|
${PROJECT_SOURCE_DIR}/ComponentTreeAdjustment.cpp
|
|
48
48
|
${PROJECT_PYBIND_DIR}/PyBindComponentTree.hpp
|
|
49
|
-
${PROJECT_PYBIND_DIR}/PyBindComponentTree.
|
|
49
|
+
${PROJECT_PYBIND_DIR}/PyBindComponentTree.tpp
|
|
50
50
|
${PROJECT_PYBIND_DIR}/PyBindComponentTreeAdjustment.hpp
|
|
51
51
|
${PROJECT_PYBIND_DIR}/PyBindComponentTreeAdjustment.cpp
|
|
52
52
|
|
{morphotreeadjust-0.1 → morphotreeadjust-0.1.2}/morphoTreeAdjust/include/AdjacencyRelation.hpp
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
#include <list>
|
|
3
3
|
#include <vector>
|
|
4
|
+
#include "../include/Common.hpp"
|
|
4
5
|
|
|
5
6
|
#ifndef ADJACENCY_H
|
|
6
7
|
#define ADJACENCY_H
|
|
@@ -13,6 +14,7 @@ private:
|
|
|
13
14
|
int col;
|
|
14
15
|
int numCols;
|
|
15
16
|
int numRows;
|
|
17
|
+
int radius;
|
|
16
18
|
int n;
|
|
17
19
|
|
|
18
20
|
int *offsetRow;
|
|
@@ -28,11 +30,13 @@ public:
|
|
|
28
30
|
int getSize();
|
|
29
31
|
AdjacencyRelation& getAdjPixels(int row, int col);
|
|
30
32
|
AdjacencyRelation& getAdjPixels(int index);
|
|
31
|
-
|
|
33
|
+
bool isAdjacent(int p, int q);
|
|
34
|
+
bool isAdjacent(int px, int py, int qx, int qy);
|
|
35
|
+
double getRadius();
|
|
32
36
|
class IteratorAdjacency {
|
|
33
37
|
private:
|
|
34
38
|
int index;
|
|
35
|
-
AdjacencyRelation* instance;
|
|
39
|
+
AdjacencyRelation* instance;
|
|
36
40
|
|
|
37
41
|
public:
|
|
38
42
|
using iterator_category = std::input_iterator_tag;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#ifndef COMMONS_HPP
|
|
2
|
+
#define COMMONS_HPP
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#define NDEBUG // Remove os asserts do código
|
|
6
|
+
#include <cassert>
|
|
7
|
+
#include <list>
|
|
8
|
+
#include <unordered_set>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <queue>
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <limits>
|
|
13
|
+
|
|
14
|
+
#define PRINT_LOG 1
|
|
15
|
+
|
|
16
|
+
#define PRINT_DEBUG 0
|
|
17
|
+
|
|
18
|
+
// Forward declaration dos templates
|
|
19
|
+
template <typename T>
|
|
20
|
+
class ComponentTree;
|
|
21
|
+
|
|
22
|
+
template <typename T>
|
|
23
|
+
class NodeCT;
|
|
24
|
+
|
|
25
|
+
// Definição de tipos para CNPs
|
|
26
|
+
using Pixels = std::list<int>; // Representa uma lista de pixels (CNPs)
|
|
27
|
+
using FlatZone = std::list<int>; // Representa uma flatzone
|
|
28
|
+
using FlatZones = std::unordered_map<int, FlatZone>; // Representa uma lista de flatzones (CNPs ficarão separados em flatzones)
|
|
29
|
+
|
|
30
|
+
//Alias em função do tipo dos CNPs
|
|
31
|
+
using FlatZoneRef = std::reference_wrapper<FlatZone>; // Representa uma flatzone
|
|
32
|
+
using FlatZonesRef = std::list<FlatZoneRef>; // Representa uma lista de flatzones
|
|
33
|
+
using ComponentTreeFZ = ComponentTree<FlatZones>; //representa um component tree por flatzones
|
|
34
|
+
using ComponentTreeP = ComponentTree<Pixels>; //representa um component tree sem tratamento de flatzones
|
|
35
|
+
using NodeFZ = NodeCT<FlatZones>; //representa um node com separação dos cnps em flatzones
|
|
36
|
+
using NodeP = NodeCT<Pixels>; //representa um node sem tratamento de flatzones
|
|
37
|
+
|
|
38
|
+
using FlatzoneGraph = std::unordered_set<int>**;
|
|
39
|
+
using AdjacentFlatzones = std::unordered_set<int>;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
struct FlatZoneNode {
|
|
43
|
+
NodeFZ* node = nullptr;
|
|
44
|
+
FlatZone* flatzone = nullptr;
|
|
45
|
+
int idFlatZone;
|
|
46
|
+
|
|
47
|
+
FlatZoneNode(){}
|
|
48
|
+
|
|
49
|
+
// Construtor para mover a FlatZone
|
|
50
|
+
FlatZoneNode(NodeFZ* n, FlatZone& fz) : node(n), flatzone(&fz), idFlatZone(fz.front()) {}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#endif
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#include <list>
|
|
2
|
+
#include <vector>
|
|
3
|
+
#include <array>
|
|
4
|
+
#include <unordered_set>
|
|
5
|
+
#include <utility>
|
|
6
|
+
#include <optional>
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <variant>
|
|
9
|
+
|
|
10
|
+
#include "../include/AdjacencyRelation.hpp"
|
|
11
|
+
#include "../include/Common.hpp"
|
|
12
|
+
|
|
13
|
+
#ifndef COMPONENT_TREE_H
|
|
14
|
+
#define COMPONENT_TREE_H
|
|
15
|
+
|
|
16
|
+
template <typename CNPsType>
|
|
17
|
+
class NodeCT; // Forward declaration
|
|
18
|
+
|
|
19
|
+
template <typename CNPsType>
|
|
20
|
+
class ComponentTree {
|
|
21
|
+
protected:
|
|
22
|
+
NodeCT<CNPsType>* root;
|
|
23
|
+
NodeCT<CNPsType>** pixelToNode; //mapping from pixel to node
|
|
24
|
+
|
|
25
|
+
int numNodes;
|
|
26
|
+
int maxIndex;
|
|
27
|
+
bool maxtreeTreeType; //maxtree is true; mintree is false
|
|
28
|
+
|
|
29
|
+
int numCols;
|
|
30
|
+
int numRows;
|
|
31
|
+
int numPixels;
|
|
32
|
+
|
|
33
|
+
AdjacencyRelation* adj; //disk of a given ratio: ratio(1) for 4-connect and ratio(1.5) for 8-connect
|
|
34
|
+
|
|
35
|
+
int* countingSort(int* img);
|
|
36
|
+
int* createTreeByUnionFind(int* orderedPixels, int* img);
|
|
37
|
+
int findRoot(int* zPar, int x);
|
|
38
|
+
void reconstruction(NodeCT<CNPsType>* node, int* imgOut);
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
|
|
42
|
+
// Define `flatzoneGraph` apenas para `FlatZones`
|
|
43
|
+
using FlatzoneGraphType = std::conditional_t<std::is_same_v<CNPsType, FlatZones>,
|
|
44
|
+
FlatzoneGraph,
|
|
45
|
+
std::monostate>;
|
|
46
|
+
FlatzoneGraphType flatzoneGraph;
|
|
47
|
+
|
|
48
|
+
ComponentTree(int numRows, int numCols, bool isMaxtree, double radiusOfAdjacencyRelation);
|
|
49
|
+
|
|
50
|
+
ComponentTree(int* img, int numRows, int numCols, bool isMaxtree, double radiusOfAdjacencyRelation);
|
|
51
|
+
|
|
52
|
+
~ComponentTree();
|
|
53
|
+
|
|
54
|
+
template<typename T = CNPsType, typename std::enable_if_t<std::is_same<T, FlatZones>::value, int> = 0>
|
|
55
|
+
std::list<int>& getFlatzoneByID(int p);
|
|
56
|
+
|
|
57
|
+
template<typename T = CNPsType, typename std::enable_if_t<std::is_same<T, FlatZones>::value, int> = 0>
|
|
58
|
+
void updateGraphAfterPruning(std::list<FlatZone>& flatZoneList, FlatZone& unifiedFlatzone, NodeFZ* nodeStar);
|
|
59
|
+
|
|
60
|
+
template<typename T = CNPsType, typename std::enable_if_t<std::is_same<T, FlatZones>::value, int> = 0>
|
|
61
|
+
void updateGraph(std::list<FlatZoneNode>& flatZoneNodeList, FlatZone& unifiedFlatzone, NodeFZ* nodeStar);
|
|
62
|
+
|
|
63
|
+
void assignCNPs();
|
|
64
|
+
|
|
65
|
+
void build(int* img);
|
|
66
|
+
|
|
67
|
+
NodeCT<CNPsType>* getSC(int p);
|
|
68
|
+
|
|
69
|
+
NodeCT<CNPsType>* getRoot();
|
|
70
|
+
|
|
71
|
+
void setRoot(NodeCT<CNPsType>* n);
|
|
72
|
+
|
|
73
|
+
bool isMaxtree();
|
|
74
|
+
|
|
75
|
+
int getNumNodes();
|
|
76
|
+
|
|
77
|
+
void setNumNodes(int numNodes) { this->numNodes = numNodes; }
|
|
78
|
+
|
|
79
|
+
int getNumRowsOfImage();
|
|
80
|
+
|
|
81
|
+
int getNumColsOfImage();
|
|
82
|
+
|
|
83
|
+
void computerArea(NodeCT<CNPsType>* node);
|
|
84
|
+
|
|
85
|
+
int* reconstructionImage();
|
|
86
|
+
|
|
87
|
+
AdjacencyRelation* getAdjacencyRelation();
|
|
88
|
+
|
|
89
|
+
void setSC(int p, NodeCT<CNPsType>* n);
|
|
90
|
+
|
|
91
|
+
void prunning(NodeCT<CNPsType>* node);
|
|
92
|
+
|
|
93
|
+
std::vector<NodeCT<CNPsType>*> getLeaves();
|
|
94
|
+
|
|
95
|
+
std::vector<NodeCT<CNPsType>*> getNodesThreshold(int threshold);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#include "ComponentTree.tpp"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
#endif
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
#include <iterator>
|
|
2
|
+
#include <functional>
|
|
3
|
+
#include <iostream>
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
#include "../include/AdjacencyRelation.hpp"
|
|
8
|
+
#include "../include/NodeCT.hpp"
|
|
9
|
+
#include "../include/ComponentTree.hpp"
|
|
10
|
+
#include "../include/Common.hpp"
|
|
11
|
+
|
|
12
|
+
#ifndef COMPONENT_TREE_ADJUSTMENT_H
|
|
13
|
+
#define COMPONENT_TREE_ADJUSTMENT_H
|
|
14
|
+
|
|
15
|
+
#include <array>
|
|
16
|
+
#include <vector>
|
|
17
|
+
#include <unordered_set>
|
|
18
|
+
class MergedNodesCollection {
|
|
19
|
+
protected:
|
|
20
|
+
std::array<std::vector<NodeFZ*>, 256> collectionF;
|
|
21
|
+
bool* visited;
|
|
22
|
+
bool* visitedAdj;
|
|
23
|
+
|
|
24
|
+
int maxIndex;
|
|
25
|
+
std::vector<int> lambdaList; // Lista ordenada de lambdas (sempre crescente)
|
|
26
|
+
int currentIndex = 0; // Índice atual
|
|
27
|
+
bool isMaxtree; // Se true, percorre de forma decrescente
|
|
28
|
+
std::vector<NodeFZ*> nodesNL;
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
|
|
32
|
+
// Construtor permite definir a ordem de iteração
|
|
33
|
+
MergedNodesCollection(int maxIndex): maxIndex(maxIndex) {
|
|
34
|
+
this->visited = new bool[this->maxIndex](); // Inicializa com false
|
|
35
|
+
this->visitedAdj = new bool[this->maxIndex]();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
~MergedNodesCollection() {
|
|
39
|
+
delete[] this->visited; // Libera memória
|
|
40
|
+
delete[] this->visitedAdj;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
std::vector<NodeFZ*>& getMergedNodes(int level) {
|
|
44
|
+
return collectionF[level];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void computerAdjacentNodes(ComponentTreeFZ* tree, std::vector<FlatZoneRef>& flatZones) {
|
|
48
|
+
bool isMaxtree = tree->isMaxtree();
|
|
49
|
+
|
|
50
|
+
for (FlatZoneRef flatZonePRef : flatZones) {
|
|
51
|
+
FlatZone& flatZoneP = flatZonePRef.get();
|
|
52
|
+
int flatZoneID_P = flatZoneP.front();
|
|
53
|
+
int grayFlatZoneP = tree->getSC(flatZoneID_P)->getLevel(); //is same that: f(p)
|
|
54
|
+
|
|
55
|
+
for (int flatZoneID_Q : *tree->flatzoneGraph[flatZoneID_P]) {
|
|
56
|
+
NodeFZ* node = tree->getSC(flatZoneID_Q);
|
|
57
|
+
if ( (isMaxtree && node->getLevel() > grayFlatZoneP) || (!isMaxtree && node->getLevel() < grayFlatZoneP) ) {
|
|
58
|
+
if(!visitedAdj[node->getIndex()]){
|
|
59
|
+
nodesNL.push_back(node);
|
|
60
|
+
visitedAdj[node->getIndex()] = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
resetAdjacentNode();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
std::vector<NodeFZ*>& getAdjacentNodes(){
|
|
69
|
+
return nodesNL;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
std::array<std::vector<NodeFZ*>, 256>& getCollectionF(){
|
|
74
|
+
return collectionF;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void resetAdjacentNode(){
|
|
78
|
+
for(NodeFZ* node: nodesNL){
|
|
79
|
+
visitedAdj[node->getIndex()] = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void resetCollection(bool descendingOrder) {
|
|
84
|
+
this->isMaxtree = descendingOrder;
|
|
85
|
+
for (auto& vec : collectionF) {
|
|
86
|
+
vec.clear();
|
|
87
|
+
}
|
|
88
|
+
nodesNL.clear();
|
|
89
|
+
lambdaList.clear();
|
|
90
|
+
std::fill(visited, visited + maxIndex, false);
|
|
91
|
+
currentIndex = 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void addNodesOfPath(NodeFZ* nodeNL, NodeFZ* nodeTauL) {
|
|
95
|
+
if(!visited[nodeNL->getIndex()])
|
|
96
|
+
for (NodeFZ* n : nodeNL->getNodesOfPathToRoot()) {
|
|
97
|
+
int index = n->getIndex();
|
|
98
|
+
if(!visited[index]) {
|
|
99
|
+
collectionF[n->getLevel()].push_back(n);
|
|
100
|
+
visited[index] = true;
|
|
101
|
+
}else{
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (n == nodeTauL) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
int firstLambda() {
|
|
114
|
+
lambdaList.clear();
|
|
115
|
+
for (int i = 0; i < 256; ++i) {
|
|
116
|
+
if (!collectionF[i].empty()) {
|
|
117
|
+
lambdaList.push_back(i);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
currentIndex = isMaxtree ? lambdaList.size() - 1 : 0;
|
|
121
|
+
return lambdaList[currentIndex];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
int nextLambda() {
|
|
126
|
+
if (isMaxtree) {
|
|
127
|
+
return lambdaList[--currentIndex];
|
|
128
|
+
} else {
|
|
129
|
+
return lambdaList[++currentIndex];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
class UnionNodes {
|
|
135
|
+
protected:
|
|
136
|
+
bool isMaxtree; // Se true, percorre de forma decrescente
|
|
137
|
+
std::list<FlatZoneNode> flatZoneNodeList;
|
|
138
|
+
std::list<int> listFlatzoneIDs;
|
|
139
|
+
FlatZoneNode nodeTauStar; //nodeTauStar é o nó correspondente da folha da sub-arvore a ser podada com maior (ou menor, para min-tree) intensidade
|
|
140
|
+
std::unordered_set<NodeFZ*> nodesToBeRemoved; //nodes que foram removido devido ao fusão das zonas planas quando newGrayLevel = \lambda
|
|
141
|
+
|
|
142
|
+
public:
|
|
143
|
+
|
|
144
|
+
// Construtor permite definir a ordem de iteração
|
|
145
|
+
UnionNodes(bool isMaxtree): isMaxtree(isMaxtree) {}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
std::list<FlatZoneNode>& getFlatzoneNodeList() {
|
|
149
|
+
return flatZoneNodeList;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
std::vector<FlatZoneRef> getFlatzones() {
|
|
153
|
+
std::vector<FlatZoneRef> flatzones;
|
|
154
|
+
for(FlatZoneNode fzNode: flatZoneNodeList){
|
|
155
|
+
flatzones.push_back(*fzNode.flatzone);
|
|
156
|
+
}
|
|
157
|
+
return flatzones;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
FlatZoneNode getNodeTauStar() {
|
|
161
|
+
return nodeTauStar;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
std::unordered_set<NodeFZ*>& getNodesToBeRemoved() {
|
|
165
|
+
return nodesToBeRemoved;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void addCNPsToConnectedFlatzone(NodeFZ* nodeUnion, ComponentTreeFZ* tree) {
|
|
169
|
+
if (flatZoneNodeList.size() > 1) {
|
|
170
|
+
FlatZone unifiedFlatzone;
|
|
171
|
+
tree->updateGraph(flatZoneNodeList, unifiedFlatzone, nodeTauStar.node);
|
|
172
|
+
nodeUnion->addCNPsToConnectedFlatzone(std::move(unifiedFlatzone), tree);
|
|
173
|
+
}else{
|
|
174
|
+
nodeUnion->addCNPsToConnectedFlatzone(std::move(*nodeTauStar.flatzone), tree);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void removeFlatzones(ComponentTreeFZ* tree) {
|
|
180
|
+
for(FlatZoneNode fzNode: flatZoneNodeList){
|
|
181
|
+
NodeFZ* node = fzNode.node;
|
|
182
|
+
node->removeFlatzone(fzNode.idFlatZone);
|
|
183
|
+
if(fzNode.node->getNumCNPs() == 0){
|
|
184
|
+
nodesToBeRemoved.insert(fzNode.node);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
bool isRemoved(NodeFZ* node){
|
|
190
|
+
return nodesToBeRemoved.find(node) == nodesToBeRemoved.end();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void resetCollection(bool isMaxtree) {
|
|
194
|
+
this->isMaxtree = isMaxtree;
|
|
195
|
+
this->flatZoneNodeList.clear();
|
|
196
|
+
this->listFlatzoneIDs.clear();
|
|
197
|
+
this->nodesToBeRemoved.clear();
|
|
198
|
+
|
|
199
|
+
this->nodeTauStar.node = nullptr;
|
|
200
|
+
this->nodeTauStar.flatzone = nullptr;
|
|
201
|
+
this->nodeTauStar.idFlatZone = -1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void addNode(NodeFZ* nodeTau, std::list<int>& fzTau) {
|
|
205
|
+
flatZoneNodeList.emplace_back(nodeTau, fzTau);
|
|
206
|
+
listFlatzoneIDs.push_back(fzTau.front());
|
|
207
|
+
|
|
208
|
+
if (!this->nodeTauStar.node || ( (!isMaxtree && nodeTau->getLevel() > nodeTauStar.node->getLevel()) || (isMaxtree && nodeTau->getLevel() < nodeTauStar.node->getLevel()))) {
|
|
209
|
+
this->nodeTauStar.node = nodeTau;
|
|
210
|
+
this->nodeTauStar.flatzone = &fzTau;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class ComponentTreeAdjustment {
|
|
218
|
+
|
|
219
|
+
protected:
|
|
220
|
+
ComponentTreeFZ* mintree;
|
|
221
|
+
ComponentTreeFZ* maxtree;
|
|
222
|
+
int maxIndex;
|
|
223
|
+
int pixelUpperBound=-1;
|
|
224
|
+
UnionNodes unionNodeTauSubtree;
|
|
225
|
+
MergedNodesCollection F;
|
|
226
|
+
std::unordered_set<NodeFZ*> Fb;
|
|
227
|
+
std::ostringstream outputLog;
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
void disconnect(NodeFZ* node, bool isFreeMemory=false) {
|
|
232
|
+
if(node->getParent() != nullptr){
|
|
233
|
+
node->getParent()->getChildren().remove(node);
|
|
234
|
+
node->setParent(nullptr);
|
|
235
|
+
if(isFreeMemory){
|
|
236
|
+
delete node;
|
|
237
|
+
node = nullptr;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
void mergedParentAndChildren(NodeFZ* nodeUnion, NodeFZ* n){
|
|
243
|
+
for (NodeFZ* son : n->getChildren()) {
|
|
244
|
+
son->setParent(nodeUnion);
|
|
245
|
+
}
|
|
246
|
+
nodeUnion->getChildren().splice(nodeUnion->getChildren().end(), n->getChildren());
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
public:
|
|
251
|
+
|
|
252
|
+
ComponentTreeAdjustment(ComponentTreeFZ* maxtree, ComponentTreeFZ* mintree);
|
|
253
|
+
|
|
254
|
+
~ComponentTreeAdjustment();
|
|
255
|
+
|
|
256
|
+
std::string getOutputLog() {
|
|
257
|
+
return outputLog.str();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
void buildMergedAndNestedCollections(ComponentTreeFZ* tree, std::vector<FlatZoneRef>& flatZone, int newGrayLevel, bool isMaxtree);
|
|
262
|
+
|
|
263
|
+
void updateTree(ComponentTreeFZ* tree, NodeFZ *L_leaf);
|
|
264
|
+
|
|
265
|
+
void updateTree2(ComponentTreeFZ* tree, NodeFZ *rSubtree);
|
|
266
|
+
|
|
267
|
+
void adjustMinTree(ComponentTreeFZ* mintree, ComponentTreeFZ* maxtree, std::vector<NodeFZ*> nodesToPruning);
|
|
268
|
+
|
|
269
|
+
void adjustMaxTree(ComponentTreeFZ* maxtree, ComponentTreeFZ* mintree, std::vector<NodeFZ*> nodesToPruning);
|
|
270
|
+
|
|
271
|
+
void adjustMinTree2(ComponentTreeFZ* mintree, ComponentTreeFZ* maxtree, std::vector<NodeFZ*> nodesToPruning);
|
|
272
|
+
|
|
273
|
+
void adjustMaxTree2(ComponentTreeFZ* maxtree, ComponentTreeFZ* mintree, std::vector<NodeFZ*> nodesToPruning);
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
#endif
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#include <unordered_set>
|
|
2
2
|
#include <map>
|
|
3
|
-
#include<iterator>
|
|
3
|
+
#include <iterator>
|
|
4
4
|
|
|
5
5
|
#include "../include/AdjacencyRelation.hpp"
|
|
6
6
|
#include "../include/NodeCT.hpp"
|
|
7
7
|
#include "../include/ComponentTree.hpp"
|
|
8
|
+
#include "../include/Common.hpp"
|
|
8
9
|
|
|
9
10
|
#ifndef COMPONENT_TREE_GENERAL_ADJUSTMENT_H
|
|
10
11
|
#define COMPONENT_TREE_GENERAL_ADJUSTMENT_H
|
|
11
12
|
|
|
12
13
|
class ComponentTreeGeneralAdjustment {
|
|
13
|
-
|
|
14
|
+
/*
|
|
14
15
|
private:
|
|
15
16
|
std::map <int, std::unordered_set<NodeCT*, NodeCT::NodeHashFunction>* > collectionF;
|
|
16
17
|
|
|
@@ -52,10 +53,12 @@ class ComponentTreeGeneralAdjustment {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
56
|
+
*/
|
|
55
57
|
public:
|
|
56
58
|
|
|
57
|
-
void adjustMaxTree(ComponentTree &maxtree, std::list<int> flatZone, int newGrayLevel);
|
|
59
|
+
void adjustMaxTree(ComponentTree<FlatZones> &maxtree, std::list<int> flatZone, int newGrayLevel);
|
|
58
60
|
|
|
59
61
|
};
|
|
60
62
|
|
|
63
|
+
|
|
61
64
|
#endif
|