forked from zippy84/vtkbool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkPolyDataContactFilter.h
137 lines (96 loc) · 3.69 KB
/
vtkPolyDataContactFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright 2012-2020 Ronald Römer
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __vtkPolyDataContactFilter_h
#define __vtkPolyDataContactFilter_h
#include <vtkPolyDataAlgorithm.h>
#include "Utilities.h"
class vtkOBBNode;
class vtkMatrix4x4;
enum class Src {
A = 1,
B = 2
};
class InterPt {
public:
InterPt () : onEdge(false), end(NO_USE), srcA(NO_USE), srcB(NO_USE) {}
InterPt (double _t, vtkIdType _end, double x, double y, double z) : InterPt() {
t = _t;
onEdge = true;
end = _end;
pt[0] = x;
pt[1] = y;
pt[2] = z;
}
double t;
bool onEdge;
vtkIdType edge[2], end, srcA, srcB;
double pt[3];
friend std::ostream& operator<< (std::ostream &out, const InterPt &s) {
out << "pt [" << s.pt[0] << ", " << s.pt[1] << ", " << s.pt[2] << "]"
<< ", t " << s.t
<< ", edge [" << s.edge[0] << ", " << s.edge[1] << "]"
<< ", end " << s.end
<< ", src " << s.src;
return out;
}
void Merge (const InterPt &other) {
assert(src != other.src);
if (src == Src::A) {
srcA = end == NO_USE ? edge[0] : end;
} else {
srcB = end == NO_USE ? edge[0] : end;
}
if (std::abs(other.t-t) < 1e-5) {
if (other.src == Src::A) {
srcA = other.end == NO_USE ? other.edge[0] : other.end;
} else {
srcB = other.end == NO_USE ? other.edge[0] : other.end;
}
}
}
Src src;
};
typedef std::vector<InterPt> InterPtsType;
typedef std::vector<std::pair<InterPt, InterPt>> OverlapsType;
class LonePt {
public:
LonePt (vtkIdType _i, vtkIdType _srcA, vtkIdType _srcB) : i(_i), srcA(_srcA), srcB(_srcB) {}
vtkIdType i, srcA, srcB;
};
typedef std::map<Pair, std::vector<LonePt>> LonePtsType;
class VTK_EXPORT vtkPolyDataContactFilter : public vtkPolyDataAlgorithm {
void PreparePolyData (vtkPolyData *pd);
static void InterEdgeLine (InterPtsType &interPts, const double *eA, const double *eB, const double *r, const double *pt);
static void InterPolyLine (InterPtsType &interPts, vtkPolyData *pd, vtkIdType num, const vtkIdType *poly, const double *r, const double *pt, Src src, const double *n);
void InterPolys (vtkIdType idA, vtkIdType idB);
static void OverlapLines (OverlapsType &ols, InterPtsType &intersA, InterPtsType &intersB);
void AddMissingLines (vtkPolyData *lines);
vtkIntArray *contA, *contB;
vtkPolyData *contLines;
vtkPoints *contPts;
vtkPolyData *pdA, *pdB;
vtkIntArray *sourcesA, *sourcesB;
public:
vtkTypeMacro(vtkPolyDataContactFilter, vtkPolyDataAlgorithm);
static vtkPolyDataContactFilter* New();
static int InterOBBNodes (vtkOBBNode *nodeA, vtkOBBNode *nodeB, vtkMatrix4x4 *mat, void *caller);
protected:
vtkPolyDataContactFilter ();
~vtkPolyDataContactFilter ();
int ProcessRequest (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector);
void PrintSelf (ostream&, vtkIndent) override {};
private:
vtkPolyDataContactFilter (const vtkPolyDataContactFilter&) = delete;
void operator= (const vtkPolyDataContactFilter&) = delete;
};
#endif