2#include <boost/container/small_vector.hpp>
12 const std::vector<std::array<SimplexId, 2>> &edgeList,
17#ifndef TTK_ENABLE_KAMIKAZE
20 if(edgeStars.
size() != edgeList.size())
27 std::vector<SimplexId> offsets(edgeNumber + 1);
29 std::vector<SimplexId> links(edgeStars.
dataSize());
34#ifdef TTK_ENABLE_OPENMP
35#pragma omp parallel for num_threads(threadNumber_)
37 for(
SimplexId i = 0; i < edgeNumber; i++) {
39 offsets[i] = edgeStars.
offset(i);
43 for(
int k = 0; k < 3; k++) {
45 if(v != edgeList[i][0] && v != edgeList[i][1]) {
47 links[offsets[i] + j] = v;
55 offsets[edgeNumber] = edgeStars.
offset(edgeNumber);
57 edgeLinks.
setData(std::move(links), std::move(offsets));
59 printMsg(
"Built " + std::to_string(edgeNumber) +
" edge links", 1,
67 const std::vector<std::array<SimplexId, 2>> &edgeList,
69 const std::vector<std::array<SimplexId, 6>> &cellEdges,
72#ifndef TTK_ENABLE_KAMIKAZE
75 if((edgeStars.
empty()) || (edgeStars.
size() != edgeList.size()))
84 std::vector<SimplexId> offsets(edgeNumber + 1);
86 std::vector<SimplexId> links(edgeStars.
dataSize());
91#ifdef TTK_ENABLE_OPENMP
92#pragma omp parallel for num_threads(threadNumber_)
94 for(
SimplexId i = 0; i < edgeNumber; i++) {
96 offsets[i] = edgeStars.
offset(i);
99 const auto &e = edgeList[i];
101 const auto c = edgeStars.
get(i, j);
102 for(
size_t k = 0; k < cellEdges[c].size(); k++) {
104 const auto ceid = cellEdges[c][k];
106 const auto &ce = edgeList[ceid];
108 if(ce[0] != e[0] && ce[0] != e[1] && ce[1] != e[0] && ce[1] != e[1]) {
110 links[offsets[i] + j] = ceid;
118 offsets[edgeNumber] = edgeStars.
offset(edgeNumber);
120 edgeLinks.
setData(std::move(links), std::move(offsets));
122 printMsg(
"Built " + std::to_string(edgeNumber) +
" edge links", 1,
130template <std::
size_t n>
197template <std::
size_t n>
201 std::vector<std::array<SimplexId, 2>> &edgeList,
203 std::vector<std::array<SimplexId, n>> &cellEdgeList)
const {
211 if(n != dim * (dim + 1) / 2 && n != 4) {
212 this->
printErr(
"Wrong template parameter (" + std::to_string(n)
213 +
" edges per " + std::to_string(dim) +
"D cell)");
214 this->
printErr(
"Cannot build edge list");
221 cellEdgeList.resize(cellNumber);
232 using boost::container::small_vector;
234 std::vector<small_vector<EdgeData, 8>> edgeTable(vertexNumber);
236 const int timeBuckets = std::min<ttk::SimplexId>(10, cellNumber);
239 for(
SimplexId cid = 0; cid < cellNumber; cid++) {
243 const auto localEdges{getLocalEdges<n>(cellArray, cid)};
245 for(
const auto &le : localEdges) {
252 auto &vec = edgeTable[v0];
254 = std::find_if(vec.begin(), vec.end(),
255 [&](
const EdgeData &a) { return a.highVert == v1; });
256 if(pos == vec.end()) {
258 vec.emplace_back(EdgeData{v1, edgeCount});
259 cellEdgeList[cid][ecid] = edgeCount;
263 cellEdgeList[cid][ecid] = pos->id;
268 if(!(cid % ((cellNumber) / timeBuckets)))
269 printMsg(
"Building edges", (cid / (
float)cellNumber),
275 edgeList.resize(edgeCount);
277#ifdef TTK_ENABLE_OPENMP
278#pragma omp parallel for num_threads(this->threadNumber_)
280 for(
SimplexId i = 0; i < vertexNumber; ++i) {
281 const auto &etable = edgeTable[i];
282 for(
const auto &data : etable) {
283 edgeList[data.id] = {i, data.highVert};
288 std::vector<SimplexId> offsets(edgeCount + 1);
290 std::vector<SimplexId> starIds(edgeCount);
293 for(
const auto &ce : cellEdgeList) {
294 for(
const auto eid : ce) {
300 for(
size_t i = 1; i < offsets.size(); ++i) {
301 offsets[i] += offsets[i - 1];
305 std::vector<SimplexId> edgeSt(offsets.back());
308 for(
size_t i = 0; i < cellEdgeList.size(); ++i) {
309 const auto &ce{cellEdgeList[i]};
310 for(
const auto eid : ce) {
311 edgeSt[offsets[eid] + starIds[eid]] = i;
317 edgeStars.
setData(std::move(edgeSt), std::move(offsets));
320 "Built " + std::to_string(edgeCount) +
" edges", 1, t.
getElapsedTime(), 1);
330template int OneSkeleton::buildEdgeList<1>(
333 std::vector<std::array<SimplexId, 2>> &edgeList,
335 std::vector<std::array<SimplexId, 1>> &cellEdgeList)
const;
338template int OneSkeleton::buildEdgeList<3>(
341 std::vector<std::array<SimplexId, 2>> &edgeList,
343 std::vector<std::array<SimplexId, 3>> &cellEdgeList)
const;
346template int OneSkeleton::buildEdgeList<4>(
349 std::vector<std::array<SimplexId, 2>> &edgeList,
351 std::vector<std::array<SimplexId, 4>> &cellEdgeList)
const;
354template int OneSkeleton::buildEdgeList<6>(
357 std::vector<std::array<SimplexId, 2>> &edgeList,
359 std::vector<std::array<SimplexId, 6>> &cellEdgeList)
const;
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
std::array< SimplexId, 2 > edgeType
std::array< edgeType, n > getLocalEdges(const CellArray &ttkNotUsed(cellArray), const SimplexId ttkNotUsed(cid))
CellArray generic array of cells
LongSimplexId getCellVertex(const LongSimplexId cellId, const SimplexId localVertId) const
LongSimplexId getNbCells() const
Get the number of cells in the array.
SimplexId getCellVertexNumber(const LongSimplexId cellId) const
void setDebugMsgPrefix(const std::string &prefix)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Replacement for std::vector<std::vector<SimplexId>>
size_t dataSize() const
Returns the size of the data_ member.
SimplexId get(SimplexId id, SimplexId local) const
Returns the data inside the sub-vectors.
void setData(std::vector< SimplexId > &&data, std::vector< SimplexId > &&offsets)
Set internal data from pre-existing vectors.
SimplexId size(SimplexId id) const
Get the size of a particular sub-vector.
SimplexId offset(SimplexId id) const
Get the offset of a particular sub-vector.
bool empty() const
If the underlying buffers are empty.
int buildEdgeLinks(const std::vector< std::array< SimplexId, 2 > > &edgeList, const FlatJaggedArray &edgeStars, const CellArray &cellArray, FlatJaggedArray &edgeLinks) const
int buildEdgeList(const SimplexId &vertexNumber, const CellArray &cellArray, std::vector< std::array< SimplexId, 2 > > &edgeList, FlatJaggedArray &edgeStars, std::vector< std::array< SimplexId, n > > &cellEdgeList) const
int SimplexId
Identifier type for simplices of any dimension.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)