Skip to content

Commit dab1073

Browse files
committed
fix matrix transform
1 parent 293c786 commit dab1073

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

Contact.cxx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,23 @@ vtkSmartPointer<vtkPolyData> Contact::GetLines (vtkPolyData *pdA, vtkLinearTrans
186186
newPdB = pdB;
187187
}
188188

189-
if (transA != nullptr || transB != nullptr) {
190-
auto tmpMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
189+
auto matrixA = vtkSmartPointer<vtkMatrix4x4>::New();
191190

192-
vtkMatrix4x4::Invert(transA->GetMatrix(), tmpMatrix);
193-
vtkMatrix4x4::Multiply4x4(tmpMatrix, transB->GetMatrix(), matrix);
191+
if (transA != nullptr) {
192+
matrixA = transA->GetMatrix();
194193
}
195194

195+
auto matrixB = vtkSmartPointer<vtkMatrix4x4>::New();
196+
197+
if (transB != nullptr) {
198+
matrixB = transB->GetMatrix();
199+
}
200+
201+
auto tmpMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
202+
203+
vtkMatrix4x4::Invert(matrixA, tmpMatrix);
204+
vtkMatrix4x4::Multiply4x4(tmpMatrix, matrixB, matrix);
205+
196206
sourcesA->Reset();
197207
sourcesB->Reset();
198208
contA->Reset();

transform/test.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,28 @@
2323
moveBoxTransform.Translate(20.076142063093318, -8.288617300972092, -53.29349952031101)
2424
moveBoxMatrix = moveBoxTransform.GetMatrix()
2525

26-
identityMatrix = vtkMatrix4x4()
27-
2826
bf = vtkPolyDataBooleanFilter()
2927
bf.SetInputData(0, mandibleReader.GetOutput())
3028
bf.SetInputData(1, boxReader.GetOutput())
3129

32-
bf.SetMatrix(0, identityMatrix)
33-
bf.SetMatrix(1, moveBoxMatrix)
30+
# identityMatrix = vtkMatrix4x4()
31+
# bf.SetMatrix(0, identityMatrix)
3432

3533
for i in range(10):
3634
moveBoxTransform.Translate(0, -10, 0)
3735
moveBoxMatrix = moveBoxTransform.GetMatrix()
3836

3937
print(moveBoxMatrix.GetElement(1, 3))
4038

41-
transformFilter = vtkTransformPolyDataFilter()
42-
transformFilter.SetInputData(boxReader.GetOutput())
43-
transformFilter.SetTransform(moveBoxTransform)
44-
transformFilter.Update()
39+
# transformFilter = vtkTransformPolyDataFilter()
40+
# transformFilter.SetInputData(boxReader.GetOutput())
41+
# transformFilter.SetTransform(moveBoxTransform)
42+
# transformFilter.Update()
4543

46-
_writer = vtkPolyDataWriter()
47-
_writer.SetFileName(f'out/pdB_{i}.vtk')
48-
_writer.SetInputConnection(transformFilter.GetOutputPort())
49-
_writer.Update()
44+
# _writer = vtkPolyDataWriter()
45+
# _writer.SetFileName(f'out/pdB_{i}.vtk')
46+
# _writer.SetInputConnection(transformFilter.GetOutputPort())
47+
# _writer.Update()
5048

5149
bf.SetMatrix(1, moveBoxMatrix)
5250

vtkPolyDataBooleanFilter.cxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,18 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio
155155

156156
start = clock::now();
157157

158+
modPdA = vtkSmartPointer<vtkPolyData>::New();
159+
modPdB = vtkSmartPointer<vtkPolyData>::New();
160+
158161
if (transforms[0] != nullptr) {
159162
auto tfA = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
160163
tfA->SetInputData(cleanA);
161164
tfA->SetTransform(transforms[0]);
162165
tfA->Update();
163166

164-
modPdA = vtkSmartPointer<vtkPolyData>::New();
165167
modPdA->DeepCopy(tfA->GetOutput());
166168
} else {
167-
modPdA = cleanA;
169+
modPdA->DeepCopy(cleanA);
168170
}
169171

170172
if (transforms[1] != nullptr) {
@@ -173,10 +175,9 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio
173175
tfB->SetTransform(transforms[1]);
174176
tfB->Update();
175177

176-
modPdB = vtkSmartPointer<vtkPolyData>::New();
177178
modPdB->DeepCopy(tfB->GetOutput());
178179
} else {
179-
modPdB = cleanB;
180+
modPdB->DeepCopy(cleanB);
180181
}
181182

182183
modPdA->EditableOn();
@@ -202,7 +203,7 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio
202203
#endif
203204

204205
if (contLines->GetNumberOfCells() == 0) {
205-
vtkErrorMacro("There is no contact 1.");
206+
vtkErrorMacro("There is no contact.");
206207
return 1;
207208
}
208209

@@ -258,7 +259,7 @@ int vtkPolyDataBooleanFilter::RequestData(vtkInformation *request, vtkInformatio
258259
// löscht bestimmte strips
259260

260261
if (CleanStrips()) {
261-
vtkErrorMacro("There is no contact 2.");
262+
vtkErrorMacro("There is no contact.");
262263
return 1;
263264
}
264265

0 commit comments

Comments
 (0)