20 #ifndef MIRTK_SpectralDecomposition_H 21 #define MIRTK_SpectralDecomposition_H 23 #include "mirtk/Pair.h" 24 #include "mirtk/Array.h" 25 #include "mirtk/PointSet.h" 26 #include "mirtk/Vector.h" 27 #include "mirtk/Matrix.h" 28 #include "mirtk/SparseMatrix.h" 29 #include "mirtk/Parallel.h" 31 #include "mirtk/PointSetExport.h" 33 #include "vtkSmartPointer.h" 34 #include "vtkPolyData.h" 35 #include "vtkPointData.h" 36 #include "vtkDataArray.h" 37 #include "vtkIdList.h" 38 #include "vtkAbstractPointLocator.h" 42 namespace SpectralDecomposition {
50 typedef Array<Pair<int, double> > FeatureWeights;
52 const double EPSILON = 1e-6;
59 Array<int> WeightedMatching(
const Matrix &cost);
72 vtkAbstractPointLocator *_P2;
82 for (
int i = re.begin(); i != re.end(); ++i) {
83 const Point &p = _P1(i);
84 _Idx[i] =
static_cast<int>(_P2->FindClosestPoint(p.
_x, p.
_y, p.
_z));
99 vtkAbstractPointLocator *_P2;
100 Array<Array<int> > &_Idx;
111 vtkIdList *ids = vtkIdList::New();
112 for (
int i = re.begin(); i != re.end(); ++i) {
114 _P2->FindClosestNPoints(_Num, p, ids);
115 for (vtkIdType j = 0; j < ids->GetNumberOfIds(); ++j) {
116 _Idx[i][j] =
static_cast<int>(ids->GetId(j));
142 FeatureWeights EdgeWeights(vtkPolyData *dataset,
143 const Array<string> &names,
144 const Array<double> *weights = NULL);
158 FeatureWeights NodeWeights(vtkPolyData *dataset,
159 const Array<string> &names,
160 const Array<double> *weights = NULL);
164 inline int NumberOfFeatures(vtkPolyData *dataset,
const FeatureWeights *weights = NULL)
168 vtkPointData *
const data = dataset->GetPointData();
169 FeatureWeights::const_iterator weight = weights->begin();
170 while (weight != weights->end()) {
171 vtkDataArray *
const feature = data->GetArray(weight->first);
172 d += feature->GetNumberOfComponents();
181 inline void GetFeatures(vtkPolyData *dataset, vtkIdType i,
double *p,
const FeatureWeights *weights = NULL)
183 dataset->GetPoint(i, p);
186 vtkPointData *
const data = dataset->GetPointData();
187 FeatureWeights::const_iterator weight = weights->begin();
188 while (weight != weights->end()) {
189 vtkDataArray *
const feature = data->GetArray(weight->first);
190 feature->GetTuple(i, p);
191 for (
int c = 0; c < feature->GetNumberOfComponents(); ++c) {
192 p[c] *= weight->second;
194 p += feature->GetNumberOfComponents();
202 inline double Distance2BetweenPoints(
const double *p1,
const double *p2)
205 dx = p2[0] - p1[0], dist2 = dx * dx;
206 dx = p2[1] - p1[1], dist2 += dx * dx;
207 dx = p2[2] - p1[2], dist2 += dx * dx;
213 inline double Distance2BetweenPoints(
const double *p1,
const double *p2,
int d)
215 double dx, dist2 = .0;
216 for (
int i = 0; i < d; ++i) {
230 int r1,
int c1, vtkPolyData *dataset,
231 FeatureWeights weights = FeatureWeights());
234 void AdjacencyMatrix(SparseMatrix &adjw,
235 vtkPolyData *dataset,
236 FeatureWeights weights = FeatureWeights());
239 SparseMatrix AdjacencyMatrix(vtkPolyData *dataset,
241 FeatureWeights weights = FeatureWeights());
244 template <
typename TCorWeight>
250 const Array<int> *target_sample,
252 const Array<int> *source_sample,
254 bool weight_transpose =
false);
257 template <
typename TCorWeight>
258 void ConnectivityMatrix(SparseMatrix &lnkw,
260 const Array<int> *target_sample,
262 const Array<int> *source_sample,
267 template <
typename TCorWeight>
268 SparseMatrix ConnectivityMatrix(vtkPolyData *target,
269 const Array<int> *target_sample,
271 const Array<int> *source_sample,
277 void Degree(
Vector &D,
const SparseMatrix &A);
280 Vector Degree(
const SparseMatrix &A);
283 void DegreeMatrix(SparseMatrix &D,
const SparseMatrix &A);
286 SparseMatrix DegreeMatrix(
const SparseMatrix &A);
296 void NormalizedLaplacian(SparseMatrix &L,
const SparseMatrix &A,
306 void Laplacian(SparseMatrix &L, vtkPolyData *dataset,
307 FeatureWeights edge_weights = FeatureWeights(),
308 FeatureWeights node_weights = FeatureWeights());
324 int ComputeEigenmodes(
const SparseMatrix &L,
int k,
Matrix &m,
Vector &v);
340 int ComputeEigenmodes(vtkPolyData *d,
int k,
Matrix &m,
Vector &v,
341 FeatureWeights ew = FeatureWeights(),
342 FeatureWeights nw = FeatureWeights());
358 int ComputeEigenmodes(vtkPolyData *d,
int k,
359 FeatureWeights ew = FeatureWeights(),
360 FeatureWeights nw = FeatureWeights());
376 int ratio = 10,
int knn = 1);
392 int ratio = 10,
int knn = 1);
405 void WeightEigenmodes(
const Matrix &m1,
const Vector &v1,
415 void NormalizeEigenmodes(
Matrix &m);
425 vtkSmartPointer<vtkDataArray>
426 ToPointDataArray(
const Matrix &m,
int r1 = 0,
427 int n = -1,
int k = -1,
const char *name =
"eigenmodes");
432 int SetEigenmodes(vtkPolyData *d,
const Matrix &m,
const char *name =
"eigenmodes");
437 int SetEigenmodes(vtkPolyData *d,
const Matrix &m,
438 int r1,
int k = -1,
const char *name =
"eigenmodes");
441 Matrix GetEigenmodes(vtkPolyData *d,
const char *name =
"eigenmodes");
463 int ComputeEigenmodes(vtkPolyData *d1, vtkPolyData *d2,
int k,
464 FeatureWeights ew = FeatureWeights(),
465 FeatureWeights nw = FeatureWeights());
470 #endif // MIRTK_SpectralDecomposition_H
For each point in the first set, find closest point in the second set.
double _x
x coordinate of Point
SparseDoubleMatrix SparseMatrix
Sparse matrix with default entry value type.
static Array< int > Run(const PointSet &p1, const PointSet &p2)
For each point in the first set, find closest point in the second set.
void operator()(const blocked_range< int > &re) const
Internal function executed by worker threads.
Point & GetPoint(int)
Get n-th point.
For each point in the first set, find closest point in the second set.
MIRTKCU_API float2x2 transpose(float2x2 m)
Transpose 2x2 matrix.
double _z
z coordinate of Point
Array< Entry > Entries
List of non-zero entries.
double _y
y coordinate of Point