2 Copyright 2012-2022 Ronald Römer
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 #ifndef __vtkPolyDataContactFilter_h
18 #define __vtkPolyDataContactFilter_h
24 #include <vtkPolyDataAlgorithm.h>
25 #include <vtkIdTypeArray.h>
27 #include "Utilities.h"
47 InterPt (double x, double y, double z, double t, vtkIdType a, vtkIdType b, End end, Src src) : t(t), edge(a, b), end(end), src(src), srcA(NOTSET), srcB(NOTSET), inaccurate(false) {
60 friend std::ostream& operator<< (std::ostream &out, const InterPt &s) {
61 out << "pt [" << s.pt[0] << ", " << s.pt[1] << ", " << s.pt[2] << "]"
63 << ", edge " << s.edge
70 void Merge (const InterPt &other) {
71 assert(src != other.src);
74 srcA = end == End::END ? edge.g : edge.f;
76 srcB = end == End::END ? edge.g : edge.f;
79 if (std::abs(other.t-t) < 1e-5) {
80 if (other.src == Src::A) {
81 srcA = other.end == End::END ? other.edge.g : other.edge.f;
83 srcB = other.end == End::END ? other.edge.g : other.edge.f;
87 if (other.inaccurate) {
94 typedef std::vector<InterPt> InterPtsType;
96 typedef std::vector<std::tuple<InterPt, InterPt, vtkIdType, vtkIdType>> OverlapsType;
98 typedef std::set<Pair> InvalidEdgesType;
100 class VTK_EXPORT vtkPolyDataContactFilter : public vtkPolyDataAlgorithm {
102 void PreparePolyData (vtkPolyData *pd);
104 static void InterEdgeLine (InterPtsType &interPts, vtkPolyData *pd, vtkIdType idA, vtkIdType idB, const double *r, const double *pt, Src src);
105 static void InterPolyLine (InterPtsType &interPts, vtkPolyData *pd, vtkIdType num, const vtkIdType *poly, const double *r, const double *pt, Src src, const double *n);
106 void InterPolys (vtkIdType idA, vtkIdType idB);
107 void OverlapLines (OverlapsType &ols, InterPtsType &intersA, InterPtsType &intersB, vtkIdType idA, vtkIdType idB);
108 void AddContactLines (InterPtsType &intersA, InterPtsType &intersB, vtkIdType idA, vtkIdType idB);
110 static void CheckInters (InterPtsType &interPts, vtkPolyData *pd, vtkIdType idA, vtkIdType idB);
112 vtkIdTypeArray *contA, *contB;
114 vtkPolyData *contLines;
117 vtkPolyData *pdA, *pdB;
119 vtkIdTypeArray *sourcesA, *sourcesB;
121 vtkIdTypeArray *neigsA, *neigsB;
123 bool invalidA, invalidB;
124 InvalidEdgesType edgesA, edgesB;
126 void GetInvalidEdges (vtkPolyData *pd, InvalidEdgesType &edges);
128 vtkIdTypeArray *accuracy;
131 vtkTypeMacro(vtkPolyDataContactFilter, vtkPolyDataAlgorithm);
133 static vtkPolyDataContactFilter* New();
135 static int InterOBBNodes (vtkOBBNode *nodeA, vtkOBBNode *nodeB, vtkMatrix4x4 *mat, void *caller);
138 vtkPolyDataContactFilter ();
139 ~vtkPolyDataContactFilter ();
141 int ProcessRequest (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override;
143 void PrintSelf (ostream&, vtkIndent) override {};
146 vtkPolyDataContactFilter (const vtkPolyDataContactFilter&) = delete;
147 void operator= (const vtkPolyDataContactFilter&) = delete;