TTK
Loading...
Searching...
No Matches
LDistanceMatrix.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <LDistance.h>
14#include <Wrapper.h>
15
16#include <string>
17#include <vector>
18
19namespace ttk {
20 class LDistanceMatrix : virtual public Debug {
21 public:
23
24 inline void setDistanceType(const std::string &val) {
25 DistanceType = val;
26 }
27
28 template <typename TIn, typename TOut>
29 int execute(std::vector<TOut *> &output,
30 const std::vector<const TIn *> &inputs,
31 const size_t nPoints) const;
32
37 template <typename TIn, typename TOut>
38 int execute(std::vector<std::vector<TOut>> &output,
39 const std::vector<const TIn *> &inputs,
40 const size_t nPoints) const;
41
42 protected:
43 std::string DistanceType{"2"};
44 };
45} // namespace ttk
46
47template <typename TIn, typename TOut>
48int ttk::LDistanceMatrix::execute(std::vector<TOut *> &output,
49 const std::vector<const TIn *> &inputs,
50 const size_t nPoints) const {
51
52 const size_t nInputs = inputs.size();
53
54 if(output.size() != nInputs)
55 this->printErr(
56 " When using the raw version of execute in LDistanceMatrix module, the "
57 "output must be "
58 "initialized, with the same number of lines as the number of inputs.");
59 for(size_t i = 0; i < nInputs; i++)
60 if(output[i] == nullptr)
61 this->printErr(" When using the raw version of execute in "
62 "LDistanceMatrix module, the output must be "
63 "fully initialized: each line pointer must not be NULL.");
64
65 LDistance worker{};
66 worker.setThreadNumber(1);
67 worker.setPrintRes(false);
68
69 // compute matrix upper triangle
70#ifdef TTK_ENABLE_OPENMP
71#pragma omp parallel for num_threads(this->threadNumber_) firstprivate(worker)
72#endif // TTK_ENABLE_OPENMP
73 for(size_t i = 0; i < nInputs; ++i) {
74 output[i][i] = 0;
75 for(size_t j = i + 1; j < nInputs; ++j) {
76 // call execute with nullptr output
77 worker.execute(inputs[i], inputs[j], {}, this->DistanceType, nPoints);
78 // store result
79 output[i][j] = worker.getResult();
80 output[j][i] = worker.getResult();
81 }
82 }
83
84 return 0;
85}
86
87template <typename TIn, typename TOut>
88int ttk::LDistanceMatrix::execute(std::vector<std::vector<TOut>> &output,
89 const std::vector<const TIn *> &inputs,
90 const size_t nPoints) const {
91
92 const auto nInputs = inputs.size();
93 output.resize(nInputs);
94
95 std::vector<double *> outputRaw(nInputs);
96 for(size_t i = 0; i < nInputs; i++) {
97 output[i].resize(nInputs);
98 outputRaw[i] = output[i].data();
99 }
100 return execute(outputRaw, inputs, nPoints);
101}
virtual int setThreadNumber(const int threadNumber)
Definition BaseClass.h:80
Minimalist debugging class.
Definition Debug.h:88
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
int execute(std::vector< TOut * > &output, const std::vector< const TIn * > &inputs, const size_t nPoints) const
void setDistanceType(const std::string &val)
TTK lDistance processing package.
Definition LDistance.h:26
The Topology ToolKit.