TTK
Loading...
Searching...
No Matches
FTMSegmentation.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#ifndef TTK_ENABLE_KAMIKAZE
14#include <iostream>
15#endif
16#include <sstream>
17
18#include <list>
19#include <tuple>
20#include <vector>
21
22#include "FTMDataTypes.h"
23#include "FTMStructures.h"
24
25namespace ttk {
26 namespace ftm {
27
28 // one segment: like a vector<SimplexId>
29 // have a fixed size
30 class Segment {
31 private:
32 std::vector<SimplexId> vertices_;
33
34 public:
36
37 void sort(const Scalars *s);
38 void createFromList(const Scalars *s,
39 std::list<std::vector<SimplexId>> &regularsList,
40 const bool reverse);
41
42 segm_const_it begin() const;
43 segm_const_it end() const;
44 segm_it begin();
45 segm_it end();
46 SimplexId size() const;
47
48 SimplexId operator[](const size_t &idx) const;
49 SimplexId &operator[](const size_t &idx);
50 };
51
52 // All the segments of the mesh, like a vector<Segment>
53 class Segments {
54 private:
55 std::vector<Segment> segments_;
56
57 public:
59
60 Segments(const Segment &) = delete;
61
62 // add one vertex
63 std::tuple<segm_it, segm_it> addLateSimpleSegment(SimplexId v);
64
65 // sort all segment (in parallel?)
66 void sortAll(const Scalars *s);
67
68 // callable once
69 void resize(const std::vector<SimplexId> &sizes);
70
71 // vector like
72 idSegment size() const;
73 void clear();
74 Segment &operator[](const size_t &idx);
75 const Segment &operator[](const size_t &idx) const;
76
77 // print
78 inline std::string print() const {
79 std::stringstream res;
80 res << "{" << std::endl;
81 for(const auto &s : segments_) {
82 if(s.size()) {
83 res << s[0] << " " << s[s.size() - 1] << " : " << s.size()
84 << std::endl;
85 }
86 }
87 res << "}" << std::endl;
88 return res.str();
89 }
90 };
91
92 // The segmentation of one arc is a list of segment
93 class ArcRegion {
94 private:
95 // list of segment composing this segmentation and for each segment
96 // the begin and the end inside it (as a segment may be subdivided)
97 std::list<Region> segmentsIn_;
98 // when and how to compact ?
99 std::vector<SimplexId> segmentation_;
100
101#ifndef TTK_ENABLE_KAMIKAZE
102 // true if the segmentation have been sent to the segmentation_ vector
103 bool segmented_;
104#endif
105
106 public:
107 // create a new arc region with the associated Segment in Segments
108 ArcRegion();
109
110 ArcRegion(const segm_it &begin, const segm_it &end);
111
112 // vertex used for the split (not in segmentation anymore), remaining
113 // region
114 std::tuple<SimplexId, ArcRegion> splitFront(SimplexId v,
115 const Scalars *s);
116
117 // vertex used for the split (not in segmentation anymore), remaining
118 // region
119 std::tuple<SimplexId, ArcRegion> splitBack(SimplexId v, const Scalars *s);
120
122 const Scalars *s,
123 const std::vector<idCorresp> &vert2treeOther
124 = std::vector<idCorresp>()) const;
125
126 void concat(const segm_it &begin, const segm_it &end);
127
128 void concat(const ArcRegion &r);
129
130 // if contiguous with current region, merge them
131 // else return false
132 bool merge(const ArcRegion &r);
133
134 void clear() {
135 segmentsIn_.clear();
136 segmentation_.clear();
137 }
138
139 // Put all segments in one vector in the arc
140 // Suppose that all segment are already sorted
141 // see Segments::sortAll
142 // For Contour Tree segmentation, you have to precise the current arc
143 // since a segment can contain vertices for several arcs
144 void createSegmentation(const Scalars *s);
145
146 inline SimplexId count() const {
147 SimplexId res = 0;
148 for(const auto &reg : segmentsIn_) {
149 res += std::abs(distance(reg.segmentBegin, reg.segmentEnd));
150 }
151 return res;
152 }
153
154 inline std::string print() const {
155 std::stringstream res;
156 res << "{";
157 for(const auto &reg : segmentsIn_) {
158 res << " " << *reg.segmentBegin;
159 res << "-" << *(reg.segmentEnd - 1);
160
161 // auto it = reg.segmentBegin;
162 // for(; it != reg.segmentEnd; ++it){
163 // res << *it << ", ";
164 // }
165 }
166 res << " }";
167 return res.str();
168 }
169
170 // Direct access to the list of region
171 const decltype(segmentsIn_) &getRegions() const {
172 return segmentsIn_;
173 }
174
175 decltype(segmentsIn_) &getRegions() {
176 return segmentsIn_;
177 }
178
179 // vector like manip
180
181 inline SimplexId size() const {
182#ifndef TTK_ENABLE_KAMIKAZE
183 if(!segmented_)
184 std::cerr << "Needs to create segmentation before size" << std::endl;
185#endif
186 return segmentation_.size();
187 }
188
190#ifndef TTK_ENABLE_KAMIKAZE
191 if(!segmented_)
192 std::cerr
193 << "Needs to create segmentation before getting segmentation"
194 << std::endl;
195#endif
196 return segmentation_[v];
197 }
198
200#ifndef TTK_ENABLE_KAMIKAZE
201 if(!segmented_)
202 std::cerr
203 << "Needs to create segmentation before getting segmentation"
204 << std::endl;
205#endif
206 return segmentation_[v];
207 }
208
209 decltype(segmentation_)::iterator begin() {
210 return segmentation_.begin();
211 }
212
213 decltype(segmentation_)::iterator end() {
214 return segmentation_.end();
215 }
216 };
217
218 } // namespace ftm
219} // namespace ttk
std::string print() const
bool merge(const ArcRegion &r)
decltype(segmentation_) ::iterator end()
SimplexId & operator[](SimplexId v)
std::tuple< SimplexId, ArcRegion > splitFront(SimplexId v, const Scalars *s)
SimplexId findBelow(SimplexId v, const Scalars *s, const std::vector< idCorresp > &vert2treeOther=std::vector< idCorresp >()) const
decltype(segmentsIn_) & getRegions()
SimplexId size() const
void createSegmentation(const Scalars *s)
SimplexId operator[](SimplexId v) const
void concat(const segm_it &begin, const segm_it &end)
decltype(segmentation_) ::iterator begin()
std::tuple< SimplexId, ArcRegion > splitBack(SimplexId v, const Scalars *s)
const decltype(segmentsIn_) & getRegions() const
SimplexId count() const
segm_const_it begin() const
SimplexId operator[](const size_t &idx) const
void createFromList(const Scalars *s, std::list< std::vector< SimplexId > > &regularsList, const bool reverse)
segm_const_it end() const
void sort(const Scalars *s)
SimplexId size() const
std::tuple< segm_it, segm_it > addLateSimpleSegment(SimplexId v)
std::string print() const
idSegment size() const
void sortAll(const Scalars *s)
Segment & operator[](const size_t &idx)
Segments(const Segment &)=delete
void resize(const std::vector< SimplexId > &sizes)
idSuperArc idSegment
for the segmentation, we have an array of segment containing area of the mesh
std::vector< SimplexId >::iterator segm_it
std::vector< SimplexId >::const_iterator segm_const_it
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22