VMTK
Loading...
Searching...
No Matches
vtkvmtkLinearToQuadraticMeshFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkLinearToQuadraticMeshFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:47:48 $
7Version: $Revision: 1.6 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
25#include "vtkGeometryFilter.h"
26#include "vtkInterpolatingSubdivisionFilter.h"
27#include "vtkLinearSubdivisionFilter.h"
28#include "vtkButterflySubdivisionFilter.h"
29#include "vtkPolyData.h"
30#include "vtkCellLocator.h"
31#include "vtkUnstructuredGrid.h"
32#include "vtkPointData.h"
33#include "vtkCellData.h"
34#include "vtkCellArray.h"
35#include "vtkGenericCell.h"
36#include "vtkEdgeTable.h"
37#include "vtkIdTypeArray.h"
38#include "vtkIntArray.h"
39#include "vtkMath.h"
40#include "vtkInformation.h"
41#include "vtkInformationVector.h"
42#include "vtkObjectFactory.h"
43
44
46
59
61{
62 if (this->ReferenceSurface)
63 {
64 this->ReferenceSurface->Delete();
65 this->ReferenceSurface = NULL;
66 }
67
68 if (this->CellEntityIdsArrayName)
69 {
70 delete[] this->CellEntityIdsArrayName;
71 this->CellEntityIdsArrayName = NULL;
72 }
73}
74
76 vtkInformation *vtkNotUsed(request),
77 vtkInformationVector **inputVector,
78 vtkInformationVector *outputVector)
79{
80 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
81 vtkInformation *outInfo = outputVector->GetInformationObject(0);
82
83 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
84 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
85
86 vtkIntArray* cellEntityIdsArray = vtkIntArray::New();
87 if (this->ReferenceSurface)
88 {
89 if (this->CellEntityIdsArrayName)
90 {
91 if (input->GetCellData()->GetArray(this->CellEntityIdsArrayName) == NULL)
92 {
93 vtkErrorMacro(<< "Error: CellEntityIdsArray with name specified does not exist");
94 return 1;
95 }
96 cellEntityIdsArray->DeepCopy(input->GetCellData()->GetArray(this->CellEntityIdsArrayName));
97 }
98 }
99
100 vtkPoints* outputPoints = vtkPoints::New();
101
102 int numberOfInputPoints = input->GetNumberOfPoints();
103
104 vtkEdgeTable* edgeTable = vtkEdgeTable::New();
105 edgeTable->InitEdgeInsertion(numberOfInputPoints,1);
106
107 vtkEdgeTable* faceTable = vtkEdgeTable::New();
108 faceTable->InitEdgeInsertion(numberOfInputPoints,1);
109
110 vtkPointData* inputPointData = input->GetPointData();
111 vtkPointData* outputPointData = output->GetPointData();
112 outputPointData->InterpolateAllocate(inputPointData,5*numberOfInputPoints);
113
114 vtkCellData* inputCellData = input->GetCellData();
115 vtkCellData* outputCellData = output->GetCellData();
116 outputCellData->CopyAllocate(inputCellData,numberOfInputPoints);
117
118 int i, j;
119 for (i=0; i<numberOfInputPoints; i++)
120 {
121 outputPoints->InsertNextPoint(input->GetPoint(i));
122 outputPointData->CopyData(inputPointData,i,i);
123 }
124
125 vtkGenericCell* cell = vtkGenericCell::New();
126
127 vtkIdTypeArray* tetraIds = vtkIdTypeArray::New();
128 input->GetIdsOfCellsOfType(VTK_TETRA,tetraIds);
129
130 int numberOfInputTetras = tetraIds->GetNumberOfTuples();
131
132 vtkIdTypeArray* triangleIds = vtkIdTypeArray::New();
133 input->GetIdsOfCellsOfType(VTK_TRIANGLE,triangleIds);
134
135 int numberOfInputTriangles = triangleIds->GetNumberOfTuples();
136
137 vtkIdTypeArray* wedgeIds = vtkIdTypeArray::New();
138 input->GetIdsOfCellsOfType(VTK_WEDGE,wedgeIds);
139
140 int numberOfInputWedges = wedgeIds->GetNumberOfTuples();
141
142 vtkIdTypeArray* hexahedraIds = vtkIdTypeArray::New();
143 input->GetIdsOfCellsOfType(VTK_HEXAHEDRON,hexahedraIds);
144
145 int numberOfInputHexahedra = hexahedraIds->GetNumberOfTuples();
146
147 vtkIdTypeArray* quadIds = vtkIdTypeArray::New();
148 input->GetIdsOfCellsOfType(VTK_QUAD,quadIds);
149
150 int numberOfInputQuads = quadIds->GetNumberOfTuples();
151
152 int numberOfInputCells = numberOfInputTetras + numberOfInputTriangles + numberOfInputWedges + numberOfInputHexahedra + numberOfInputQuads;
153
154 output->SetPoints(outputPoints);
155 output->Allocate(numberOfInputCells);
156
157 int numberOfCells = input->GetNumberOfCells();
158 vtkIdList* inputToOutputCellIds = vtkIdList::New();
159 inputToOutputCellIds->SetNumberOfIds(numberOfInputCells);
160
161 for (i=0; i<numberOfCells; i++)
162 {
163 inputToOutputCellIds->SetId(i,-1);
164 }
165
166 vtkIdType cellId;
167 double point0[3], point1[3], point2[3], point3[3], point4[3], point5[3], point6[3], point7[3];
168 vtkIdType pointId0, pointId1, pointId2, pointId3, pointId4, pointId5, pointId6, pointId7;
169 double point[3];
170 vtkIdType edgePointId01, edgePointId02, edgePointId03, edgePointId12, edgePointId13, edgePointId23;
171 vtkIdType edgePointId14, edgePointId34, edgePointId45, edgePointId35, edgePointId25, edgePointId37;
172 vtkIdType edgePointId56, edgePointId67, edgePointId74, edgePointId04, edgePointId15, edgePointId26;
173 vtkIdType facePointId0143, facePointId1254, facePointId2035;
174 vtkIdType facePointId3047, facePointId1265, facePointId0154, facePointId2376, facePointId0123, facePointId4567;
175 vtkIdType midVolumePoint;
176 facePointId0143 = facePointId1254 = facePointId2035 = -1;
177 facePointId3047 = facePointId1265 = facePointId0154 = facePointId2376 = facePointId0123 = facePointId4567 = -1;
178 midVolumePoint = -1;
179 vtkIdType neighborCellId;
180 vtkIdType pts[27];
181 double weights[4];
182 double weightsVolume[8];
183 weights[0] = weights[1] = weights[2] = weights[3] = 0.25;
184 weightsVolume[0] = weightsVolume[1] = weightsVolume[2] = weightsVolume[3] = weightsVolume[4] = weightsVolume[5] = weightsVolume[6] = weightsVolume[7] = 0.125;
185
186 vtkIdList* facePointIds = vtkIdList::New();
187 vtkIdList* cellNeighbors = vtkIdList::New();
188
189 for (i=0; i<numberOfInputWedges; i++)
190 {
191 cellId = wedgeIds->GetValue(i);
192 input->GetCell(cellId,cell);
193
194 cell->Points->GetPoint(0,point0);
195 cell->Points->GetPoint(1,point1);
196 cell->Points->GetPoint(2,point2);
197 cell->Points->GetPoint(3,point3);
198 cell->Points->GetPoint(4,point4);
199 cell->Points->GetPoint(5,point5);
200
201 pointId0 = cell->PointIds->GetId(0);
202 pointId1 = cell->PointIds->GetId(1);
203 pointId2 = cell->PointIds->GetId(2);
204 pointId3 = cell->PointIds->GetId(3);
205 pointId4 = cell->PointIds->GetId(4);
206 pointId5 = cell->PointIds->GetId(5);
207
208 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
209 if (edgePointId01 == -1)
210 {
211 for (j=0; j<3; j++)
212 {
213 point[j] = 0.5 * (point0[j] + point1[j]);
214 }
215 edgePointId01 = outputPoints->InsertNextPoint(point);
216 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
217 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
218 }
219
220 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
221 if (edgePointId02 == -1)
222 {
223 for (j=0; j<3; j++)
224 {
225 point[j] = 0.5 * (point0[j] + point2[j]);
226 }
227 edgePointId02 = outputPoints->InsertNextPoint(point);
228 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
229 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
230 }
231
232 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
233 if (edgePointId12 == -1)
234 {
235 for (j=0; j<3; j++)
236 {
237 point[j] = 0.5 * (point1[j] + point2[j]);
238 }
239 edgePointId12 = outputPoints->InsertNextPoint(point);
240 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
241 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
242 }
243
244 edgePointId34 = edgeTable->IsEdge(pointId3,pointId4);
245 if (edgePointId34 == -1)
246 {
247 for (j=0; j<3; j++)
248 {
249 point[j] = 0.5 * (point3[j] + point4[j]);
250 }
251 edgePointId34 = outputPoints->InsertNextPoint(point);
252 outputPointData->InterpolateEdge(inputPointData,edgePointId34,pointId3,pointId4,0.5);
253 edgeTable->InsertEdge(pointId3,pointId4,edgePointId34);
254 }
255
256 edgePointId35 = edgeTable->IsEdge(pointId3,pointId5);
257 if (edgePointId35 == -1)
258 {
259 for (j=0; j<3; j++)
260 {
261 point[j] = 0.5 * (point3[j] + point5[j]);
262 }
263 edgePointId35 = outputPoints->InsertNextPoint(point);
264 outputPointData->InterpolateEdge(inputPointData,edgePointId35,pointId3,pointId5,0.5);
265 edgeTable->InsertEdge(pointId3,pointId5,edgePointId35);
266 }
267
268 edgePointId45 = edgeTable->IsEdge(pointId4,pointId5);
269 if (edgePointId45 == -1)
270 {
271 for (j=0; j<3; j++)
272 {
273 point[j] = 0.5 * (point4[j] + point5[j]);
274 }
275 edgePointId45 = outputPoints->InsertNextPoint(point);
276 outputPointData->InterpolateEdge(inputPointData,edgePointId45,pointId4,pointId5,0.5);
277 edgeTable->InsertEdge(pointId4,pointId5,edgePointId45);
278 }
279
280 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
281 if (edgePointId03 == -1)
282 {
283 for (j=0; j<3; j++)
284 {
285 point[j] = 0.5 * (point0[j] + point3[j]);
286 }
287 edgePointId03 = outputPoints->InsertNextPoint(point);
288 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
289 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
290 }
291
292 edgePointId14 = edgeTable->IsEdge(pointId1,pointId4);
293 if (edgePointId14 == -1)
294 {
295 for (j=0; j<3; j++)
296 {
297 point[j] = 0.5 * (point1[j] + point4[j]);
298 }
299 edgePointId14 = outputPoints->InsertNextPoint(point);
300 outputPointData->InterpolateEdge(inputPointData,edgePointId14,pointId1,pointId4,0.5);
301 edgeTable->InsertEdge(pointId1,pointId4,edgePointId14);
302 }
303
304 edgePointId25 = edgeTable->IsEdge(pointId2,pointId5);
305 if (edgePointId25 == -1)
306 {
307 for (j=0; j<3; j++)
308 {
309 point[j] = 0.5 * (point2[j] + point5[j]);
310 }
311 edgePointId25 = outputPoints->InsertNextPoint(point);
312 outputPointData->InterpolateEdge(inputPointData,edgePointId25,pointId2,pointId5,0.5);
313 edgeTable->InsertEdge(pointId2,pointId5,edgePointId25);
314 }
315
316 if (this->UseBiquadraticWedge)
317 {
318 facePointIds->Initialize();
319 facePointIds->InsertNextId(pointId0);
320 facePointIds->InsertNextId(pointId1);
321 facePointIds->InsertNextId(pointId4);
322 facePointIds->InsertNextId(pointId3);
323 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
324 neighborCellId = -1;
325 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
326 {
327 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
328 {
329 neighborCellId = cellNeighbors->GetId(j);
330 break;
331 }
332 }
333 if (neighborCellId != -1)
334 {
335 facePointId0143 = faceTable->IsEdge(cellId,neighborCellId);
336 if (facePointId0143 == -1)
337 {
338 for (j=0; j<3; j++)
339 {
340 point[j] = 0.25 * (point0[j] + point1[j] + point4[j] + point3[j]);
341 }
342 facePointId0143 = outputPoints->InsertNextPoint(point);
343 outputPointData->InterpolatePoint(inputPointData,facePointId0143,facePointIds,weights);
344 faceTable->InsertEdge(cellId,neighborCellId,facePointId0143);
345 }
346 }
347
348 facePointIds->Initialize();
349 facePointIds->InsertNextId(pointId1);
350 facePointIds->InsertNextId(pointId2);
351 facePointIds->InsertNextId(pointId5);
352 facePointIds->InsertNextId(pointId4);
353 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
354 neighborCellId = -1;
355 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
356 {
357 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
358 {
359 neighborCellId = cellNeighbors->GetId(j);
360 break;
361 }
362 }
363 if (neighborCellId != -1)
364 {
365 facePointId1254 = faceTable->IsEdge(cellId,neighborCellId);
366 if (facePointId1254 == -1)
367 {
368 for (j=0; j<3; j++)
369 {
370 point[j] = 0.25 * (point1[j] + point2[j] + point5[j] + point4[j]);
371 }
372 facePointId1254 = outputPoints->InsertNextPoint(point);
373 outputPointData->InterpolatePoint(inputPointData,facePointId1254,facePointIds,weights);
374 faceTable->InsertEdge(cellId,neighborCellId,facePointId1254);
375 }
376 }
377
378 facePointIds->Initialize();
379 facePointIds->InsertNextId(pointId2);
380 facePointIds->InsertNextId(pointId0);
381 facePointIds->InsertNextId(pointId3);
382 facePointIds->InsertNextId(pointId5);
383 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
384 neighborCellId = -1;
385 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
386 {
387 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
388 {
389 neighborCellId = cellNeighbors->GetId(j);
390 break;
391 }
392 }
393 if (neighborCellId != -1)
394 {
395 facePointId2035 = faceTable->IsEdge(cellId,neighborCellId);
396 if (facePointId2035 == -1)
397 {
398 for (j=0; j<3; j++)
399 {
400 point[j] = 0.25 * (point2[j] + point0[j] + point3[j] + point5[j]);
401 }
402 facePointId2035 = outputPoints->InsertNextPoint(point);
403 outputPointData->InterpolatePoint(inputPointData,facePointId2035,facePointIds,weights);
404 faceTable->InsertEdge(cellId,neighborCellId,facePointId2035);
405 }
406 }
407 }
408
409 pts[0] = pointId0;
410 pts[1] = pointId1;
411 pts[2] = pointId2;
412 pts[3] = pointId3;
413 pts[4] = pointId4;
414 pts[5] = pointId5;
415
416 pts[6] = edgePointId01;
417 pts[7] = edgePointId12;
418 pts[8] = edgePointId02;
419 pts[9] = edgePointId34;
420 pts[10] = edgePointId45;
421 pts[11] = edgePointId35;
422 pts[12] = edgePointId03;
423 pts[13] = edgePointId14;
424 pts[14] = edgePointId25;
425 pts[15] = facePointId0143;
426 pts[16] = facePointId1254;
427 pts[17] = facePointId2035;
428
429 vtkIdType newCellId;
430
431 if (this->UseBiquadraticWedge)
432 {
433 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUADRATIC_WEDGE, 18, pts);
434 }
435 else
436 {
437 newCellId = output->InsertNextCell(VTK_QUADRATIC_WEDGE, 15, pts);
438 }
439
440 inputToOutputCellIds->SetId(cellId,newCellId);
441 outputCellData->CopyData(inputCellData,cellId,newCellId);
442 }
443
444 for (i=0; i<numberOfInputTetras; i++)
445 {
446 cellId = tetraIds->GetValue(i);
447 input->GetCell(cellId,cell);
448
449 cell->Points->GetPoint(0,point0);
450 cell->Points->GetPoint(1,point1);
451 cell->Points->GetPoint(2,point2);
452 cell->Points->GetPoint(3,point3);
453
454 pointId0 = cell->PointIds->GetId(0);
455 pointId1 = cell->PointIds->GetId(1);
456 pointId2 = cell->PointIds->GetId(2);
457 pointId3 = cell->PointIds->GetId(3);
458
459 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
460 if (edgePointId01 == -1)
461 {
462 for (j=0; j<3; j++)
463 {
464 point[j] = 0.5 * (point0[j] + point1[j]);
465 }
466 edgePointId01 = outputPoints->InsertNextPoint(point);
467 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
468 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
469 }
470
471 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
472 if (edgePointId02 == -1)
473 {
474 for (j=0; j<3; j++)
475 {
476 point[j] = 0.5 * (point0[j] + point2[j]);
477 }
478 edgePointId02 = outputPoints->InsertNextPoint(point);
479 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
480 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
481 }
482
483 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
484 if (edgePointId03 == -1)
485 {
486 for (j=0; j<3; j++)
487 {
488 point[j] = 0.5 * (point0[j] + point3[j]);
489 }
490 edgePointId03 = outputPoints->InsertNextPoint(point);
491 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
492 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
493 }
494
495 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
496 if (edgePointId12 == -1)
497 {
498 for (j=0; j<3; j++)
499 {
500 point[j] = 0.5 * (point1[j] + point2[j]);
501 }
502 edgePointId12 = outputPoints->InsertNextPoint(point);
503 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
504 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
505 }
506
507 edgePointId13 = edgeTable->IsEdge(pointId1,pointId3);
508 if (edgePointId13 == -1)
509 {
510 for (j=0; j<3; j++)
511 {
512 point[j] = 0.5 * (point1[j] + point3[j]);
513 }
514 edgePointId13 = outputPoints->InsertNextPoint(point);
515 outputPointData->InterpolateEdge(inputPointData,edgePointId13,pointId1,pointId3,0.5);
516 edgeTable->InsertEdge(pointId1,pointId3,edgePointId13);
517 }
518
519 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
520 if (edgePointId23 == -1)
521 {
522 for (j=0; j<3; j++)
523 {
524 point[j] = 0.5 * (point2[j] + point3[j]);
525 }
526 edgePointId23 = outputPoints->InsertNextPoint(point);
527 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
528 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
529 }
530
531 pts[0] = pointId0;
532 pts[1] = pointId1;
533 pts[2] = pointId2;
534 pts[3] = pointId3;
535 pts[4] = edgePointId01;
536 pts[5] = edgePointId12;
537 pts[6] = edgePointId02;
538 pts[7] = edgePointId03;
539 pts[8] = edgePointId13;
540 pts[9] = edgePointId23;
541
542 vtkIdType newCellId = output->InsertNextCell(VTK_QUADRATIC_TETRA, 10, pts);
543
544 inputToOutputCellIds->SetId(cellId,newCellId);
545 outputCellData->CopyData(inputCellData,cellId,newCellId);
546 }
547
548 for (i=0; i<numberOfInputHexahedra; i++)
549 {
550 cellId = hexahedraIds->GetValue(i);
551 input->GetCell(cellId,cell);
552
553 cell->Points->GetPoint(0,point0);
554 cell->Points->GetPoint(1,point1);
555 cell->Points->GetPoint(2,point2);
556 cell->Points->GetPoint(3,point3);
557 cell->Points->GetPoint(4,point4);
558 cell->Points->GetPoint(5,point5);
559 cell->Points->GetPoint(6,point6);
560 cell->Points->GetPoint(7,point7);
561
562 pointId0 = cell->PointIds->GetId(0);
563 pointId1 = cell->PointIds->GetId(1);
564 pointId2 = cell->PointIds->GetId(2);
565 pointId3 = cell->PointIds->GetId(3);
566 pointId4 = cell->PointIds->GetId(4);
567 pointId5 = cell->PointIds->GetId(5);
568 pointId6 = cell->PointIds->GetId(6);
569 pointId7 = cell->PointIds->GetId(7);
570
571 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
572 if (edgePointId01 == -1)
573 {
574 for (j=0; j<3; j++)
575 {
576 point[j] = 0.5 * (point0[j] + point1[j]);
577 }
578 edgePointId01 = outputPoints->InsertNextPoint(point);
579 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
580 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
581 }
582
583 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
584 if (edgePointId12 == -1)
585 {
586 for (j=0; j<3; j++)
587 {
588 point[j] = 0.5 * (point1[j] + point2[j]);
589 }
590 edgePointId12 = outputPoints->InsertNextPoint(point);
591 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
592 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
593 }
594
595 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
596 if (edgePointId23 == -1)
597 {
598 for (j=0; j<3; j++)
599 {
600 point[j] = 0.5 * (point2[j] + point3[j]);
601 }
602 edgePointId23 = outputPoints->InsertNextPoint(point);
603 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
604 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
605 }
606
607 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
608 if (edgePointId03 == -1)
609 {
610 for (j=0; j<3; j++)
611 {
612 point[j] = 0.5 * (point0[j] + point3[j]);
613 }
614 edgePointId03 = outputPoints->InsertNextPoint(point);
615 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
616 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
617 }
618
619 edgePointId04 = edgeTable->IsEdge(pointId0,pointId4);
620 if (edgePointId04 == -1)
621 {
622 for (j=0; j<3; j++)
623 {
624 point[j] = 0.5 * (point0[j] + point4[j]);
625 }
626 edgePointId04 = outputPoints->InsertNextPoint(point);
627 outputPointData->InterpolateEdge(inputPointData,edgePointId04,pointId0,pointId4,0.5);
628 edgeTable->InsertEdge(pointId0,pointId4,edgePointId04);
629 }
630
631 edgePointId15 = edgeTable->IsEdge(pointId1,pointId5);
632 if (edgePointId15 == -1)
633 {
634 for (j=0; j<3; j++)
635 {
636 point[j] = 0.5 * (point1[j] + point5[j]);
637 }
638 edgePointId15 = outputPoints->InsertNextPoint(point);
639 outputPointData->InterpolateEdge(inputPointData,edgePointId15,pointId1,pointId5,0.5);
640 edgeTable->InsertEdge(pointId1,pointId5,edgePointId15);
641 }
642
643 edgePointId26 = edgeTable->IsEdge(pointId2,pointId6);
644 if (edgePointId26 == -1)
645 {
646 for (j=0; j<3; j++)
647 {
648 point[j] = 0.5 * (point2[j] + point6[j]);
649 }
650 edgePointId26 = outputPoints->InsertNextPoint(point);
651 outputPointData->InterpolateEdge(inputPointData,edgePointId26,pointId2,pointId6,0.5);
652 edgeTable->InsertEdge(pointId2,pointId6,edgePointId26);
653 }
654
655 edgePointId37 = edgeTable->IsEdge(pointId3,pointId7);
656 if (edgePointId37 == -1)
657 {
658 for (j=0; j<3; j++)
659 {
660 point[j] = 0.5 * (point3[j] + point7[j]);
661 }
662 edgePointId37 = outputPoints->InsertNextPoint(point);
663 outputPointData->InterpolateEdge(inputPointData,edgePointId37,pointId3,pointId7,0.5);
664 edgeTable->InsertEdge(pointId3,pointId7,edgePointId37);
665 }
666
667 edgePointId45 = edgeTable->IsEdge(pointId4,pointId5);
668 if (edgePointId45 == -1)
669 {
670 for (j=0; j<3; j++)
671 {
672 point[j] = 0.5 * (point4[j] + point5[j]);
673 }
674 edgePointId45 = outputPoints->InsertNextPoint(point);
675 outputPointData->InterpolateEdge(inputPointData,edgePointId45,pointId4,pointId5,0.5);
676 edgeTable->InsertEdge(pointId4,pointId5,edgePointId45);
677 }
678
679 edgePointId56 = edgeTable->IsEdge(pointId5,pointId6);
680 if (edgePointId56 == -1)
681 {
682 for (j=0; j<3; j++)
683 {
684 point[j] = 0.5 * (point5[j] + point6[j]);
685 }
686 edgePointId56 = outputPoints->InsertNextPoint(point);
687 outputPointData->InterpolateEdge(inputPointData,edgePointId56,pointId5,pointId6,0.5);
688 edgeTable->InsertEdge(pointId5,pointId6,edgePointId56);
689 }
690
691 edgePointId67 = edgeTable->IsEdge(pointId6,pointId7);
692 if (edgePointId67 == -1)
693 {
694 for (j=0; j<3; j++)
695 {
696 point[j] = 0.5 * (point6[j] + point7[j]);
697 }
698 edgePointId67 = outputPoints->InsertNextPoint(point);
699 outputPointData->InterpolateEdge(inputPointData,edgePointId67,pointId6,pointId7,0.5);
700 edgeTable->InsertEdge(pointId6,pointId7,edgePointId67);
701 }
702
703 edgePointId74 = edgeTable->IsEdge(pointId4,pointId7);
704 if (edgePointId74 == -1)
705 {
706 for (j=0; j<3; j++)
707 {
708 point[j] = 0.5 * (point4[j] + point7[j]);
709 }
710 edgePointId74 = outputPoints->InsertNextPoint(point);
711 outputPointData->InterpolateEdge(inputPointData,edgePointId74,pointId4,pointId7,0.5);
712 edgeTable->InsertEdge(pointId4,pointId7,edgePointId74);
713 }
714
715 if (this->NumberOfNodesHexahedra > 20)
716 {
717
718 facePointIds->Initialize();
719 facePointIds->InsertNextId(pointId0);
720 facePointIds->InsertNextId(pointId1);
721 facePointIds->InsertNextId(pointId5);
722 facePointIds->InsertNextId(pointId4);
723 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
724 facePointId0154 = -1;
725 if (cellNeighbors->GetNumberOfIds() == 0)
726 {
727 neighborCellId = numberOfInputCells + 1;
728 }
729 else
730 {
731 neighborCellId = -1;
732 }
733 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
734 {
735 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
736 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
737 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
738 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
739 {
740 neighborCellId = cellNeighbors->GetId(j);
741 break;
742 }
743 }
744 if (neighborCellId != -1)
745 {
746 facePointId0154 = faceTable->IsEdge(cellId,neighborCellId);
747 if (facePointId0154 == -1)
748 {
749 for (j=0; j<3; j++)
750 {
751 point[j] = 0.25 * (point0[j] + point1[j] + point5[j] + point4[j]);
752 }
753 facePointId0154 = outputPoints->InsertNextPoint(point);
754 outputPointData->InterpolatePoint(inputPointData,facePointId0154,facePointIds,weights);
755 faceTable->InsertEdge(cellId,neighborCellId,facePointId0154);
756 }
757 }
758
759 facePointIds->Initialize();
760 facePointIds->InsertNextId(pointId1);
761 facePointIds->InsertNextId(pointId2);
762 facePointIds->InsertNextId(pointId6);
763 facePointIds->InsertNextId(pointId5);
764 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
765 facePointId1265 = -1;
766 if (cellNeighbors->GetNumberOfIds() == 0)
767 {
768 neighborCellId = numberOfInputCells + 2;
769 }
770 else
771 {
772 neighborCellId = -1;
773 }
774 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
775 {
776 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
777 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
778 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
779 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
780 {
781 neighborCellId = cellNeighbors->GetId(j);
782 break;
783 }
784 }
785 if (neighborCellId != -1)
786 {
787 facePointId1265 = faceTable->IsEdge(cellId,neighborCellId);
788 if (facePointId1265 == -1)
789 {
790 for (j=0; j<3; j++)
791 {
792 point[j] = 0.25 * (point1[j] + point2[j] + point6[j] + point5[j]);
793 }
794 facePointId1265 = outputPoints->InsertNextPoint(point);
795 outputPointData->InterpolatePoint(inputPointData,facePointId1265,facePointIds,weights);
796 faceTable->InsertEdge(cellId,neighborCellId,facePointId1265);
797 }
798 }
799
800 facePointIds->Initialize();
801 facePointIds->InsertNextId(pointId2);
802 facePointIds->InsertNextId(pointId3);
803 facePointIds->InsertNextId(pointId7);
804 facePointIds->InsertNextId(pointId6);
805 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
806 facePointId2376 = -1;
807 if (cellNeighbors->GetNumberOfIds() == 0)
808 {
809 neighborCellId = numberOfInputCells + 3;
810 }
811 else
812 {
813 neighborCellId = -1;
814 }
815 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
816 {
817 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
818 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
819 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
820 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
821 {
822 neighborCellId = cellNeighbors->GetId(j);
823 break;
824 }
825 }
826 if (neighborCellId != -1)
827 {
828 facePointId2376 = faceTable->IsEdge(cellId,neighborCellId);
829 if (facePointId2376 == -1)
830 {
831 for (j=0; j<3; j++)
832 {
833 point[j] = 0.25 * (point2[j] + point3[j] + point7[j] + point6[j]);
834 }
835 facePointId2376 = outputPoints->InsertNextPoint(point);
836 outputPointData->InterpolatePoint(inputPointData,facePointId2376,facePointIds,weights);
837 faceTable->InsertEdge(cellId,neighborCellId,facePointId2376);
838 }
839 }
840
841 facePointIds->Initialize();
842 facePointIds->InsertNextId(pointId3);
843 facePointIds->InsertNextId(pointId0);
844 facePointIds->InsertNextId(pointId4);
845 facePointIds->InsertNextId(pointId7);
846 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
847 facePointId3047 = -1;
848 if (cellNeighbors->GetNumberOfIds() == 0)
849 {
850 neighborCellId = numberOfInputCells + 4;
851 }
852 else
853 {
854 neighborCellId = -1;
855 }
856 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
857 {
858 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
859 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
860 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
861 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
862 {
863 neighborCellId = cellNeighbors->GetId(j);
864 break;
865 }
866 }
867 if (neighborCellId != -1)
868 {
869 facePointId3047 = faceTable->IsEdge(cellId,neighborCellId);
870 if (facePointId3047 == -1)
871 {
872 for (j=0; j<3; j++)
873 {
874 point[j] = 0.25 * (point3[j] + point0[j] + point4[j] + point7[j]);
875 }
876 facePointId3047 = outputPoints->InsertNextPoint(point);
877 outputPointData->InterpolatePoint(inputPointData,facePointId3047,facePointIds,weights);
878 faceTable->InsertEdge(cellId,neighborCellId,facePointId3047);
879 }
880 }
881
882 if (this->NumberOfNodesHexahedra > 24)
883 {
884
885 facePointIds->Initialize();
886 facePointIds->InsertNextId(pointId0);
887 facePointIds->InsertNextId(pointId1);
888 facePointIds->InsertNextId(pointId2);
889 facePointIds->InsertNextId(pointId3);
890 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
891 facePointId0123 = -1;
892 if (cellNeighbors->GetNumberOfIds() == 0)
893 {
894 neighborCellId = numberOfInputCells + 5;
895 }
896 else
897 {
898 neighborCellId = -1;
899 }
900 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
901 {
902 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
903 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
904 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
905 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
906 {
907 neighborCellId = cellNeighbors->GetId(j);
908 break;
909 }
910 }
911 if (neighborCellId != -1)
912 {
913 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
914 if (facePointId0123 == -1)
915 {
916 for (j=0; j<3; j++)
917 {
918 point[j] = 0.25 * (point0[j] + point1[j] + point2[j] + point3[j]);
919 }
920 facePointId0123 = outputPoints->InsertNextPoint(point);
921 outputPointData->InterpolatePoint(inputPointData,facePointId0123,facePointIds,weights);
922 faceTable->InsertEdge(cellId,neighborCellId,facePointId0123);
923 }
924 }
925
926 facePointIds->Initialize();
927 facePointIds->InsertNextId(pointId4);
928 facePointIds->InsertNextId(pointId5);
929 facePointIds->InsertNextId(pointId6);
930 facePointIds->InsertNextId(pointId7);
931 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
932 facePointId4567 = -1;
933 if (cellNeighbors->GetNumberOfIds() == 0)
934 {
935 neighborCellId = numberOfInputCells + 6;
936 }
937 else
938 {
939 neighborCellId = -1;
940 }
941 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
942 {
943 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
944 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
945 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
946 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
947 {
948 neighborCellId = cellNeighbors->GetId(j);
949 break;
950 }
951 }
952 if (neighborCellId != -1)
953 {
954 facePointId4567 = faceTable->IsEdge(cellId,neighborCellId);
955 if (facePointId4567 == -1)
956 {
957 for (j=0; j<3; j++)
958 {
959 point[j] = 0.25 * (point4[j] + point5[j] + point6[j] + point7[j]);
960 }
961 facePointId4567 = outputPoints->InsertNextPoint(point);
962 outputPointData->InterpolatePoint(inputPointData,facePointId4567,facePointIds,weights);
963 faceTable->InsertEdge(cellId,neighborCellId,facePointId4567);
964 }
965 }
966
967 facePointIds->Initialize();
968 facePointIds->InsertNextId(pointId0);
969 facePointIds->InsertNextId(pointId1);
970 facePointIds->InsertNextId(pointId2);
971 facePointIds->InsertNextId(pointId3);
972 facePointIds->InsertNextId(pointId4);
973 facePointIds->InsertNextId(pointId5);
974 facePointIds->InsertNextId(pointId6);
975 facePointIds->InsertNextId(pointId7);
976 for (j=0; j<3; j++)
977 {
978 point[j] = 0.125 * (point0[j] + point1[j] + point2[j] + point3[j] + point4[j] + point5[j] + point6[j] + point7[j]);
979 }
980 midVolumePoint = outputPoints->InsertNextPoint(point);
981 outputPointData->InterpolatePoint(inputPointData,midVolumePoint,facePointIds,weightsVolume);
982 }
983 }
984
985 pts[0] = pointId0;
986 pts[1] = pointId1;
987 pts[2] = pointId2;
988 pts[3] = pointId3;
989 pts[4] = pointId4;
990 pts[5] = pointId5;
991 pts[6] = pointId6;
992 pts[7] = pointId7;
993 pts[8] = edgePointId01;
994 pts[9] = edgePointId12;
995 pts[10] = edgePointId23;
996 pts[11] = edgePointId03;
997 pts[12] = edgePointId45;
998 pts[13] = edgePointId56;
999 pts[14] = edgePointId67;
1000 pts[15] = edgePointId74;
1001 pts[16] = edgePointId04;
1002 pts[17] = edgePointId15;
1003 pts[18] = edgePointId26;
1004 pts[19] = edgePointId37;
1005
1006 if (this->NumberOfNodesHexahedra > 20)
1007 {
1008 pts[20] = facePointId3047;
1009 pts[21] = facePointId1265;
1010 pts[22] = facePointId0154;
1011 pts[23] = facePointId2376;
1012 if (this->NumberOfNodesHexahedra > 24)
1013 {
1014 pts[24] = facePointId0123;
1015 pts[25] = facePointId4567;
1016 pts[26] = midVolumePoint;
1017 }
1018 }
1019
1020 vtkIdType newCellId;
1021
1022 switch (this->NumberOfNodesHexahedra)
1023 {
1024 case 20:
1025 {
1026 newCellId = output->InsertNextCell(VTK_QUADRATIC_HEXAHEDRON, 20, pts);
1027 break;
1028 }
1029 case 24:
1030 {
1031 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON, 24, pts);
1032 break;
1033 }
1034 case 27:
1035 {
1036 newCellId = output->InsertNextCell(VTK_TRIQUADRATIC_HEXAHEDRON, 27, pts);
1037 break;
1038 }
1039 default:
1040 {
1041 newCellId = output->InsertNextCell(VTK_HEXAHEDRON, 8, pts);
1042 vtkErrorMacro(<<"Invalid number of nodes for a quadratic hexahedral mesh- choose 20, 24, or 27.");
1043 return 1;
1044 }
1045 }
1046
1047 inputToOutputCellIds->SetId(cellId,newCellId);
1048 outputCellData->CopyData(inputCellData,cellId,newCellId);
1049 }
1050
1051 vtkCellLocator* locator = NULL;
1052 if (this->ReferenceSurface)
1053 {
1054 locator = vtkCellLocator::New();
1055 locator->SetDataSet(this->ReferenceSurface);
1056 locator->BuildLocator();
1057 }
1058
1059 double projectedPoint[3];
1060 vtkIdType referenceCellId;
1061 int subId;
1062 double dist2;
1063
1064 vtkEdgeTable* surfaceEdgeTable = vtkEdgeTable::New();
1065 vtkEdgeTable* surfaceFaceTable = vtkEdgeTable::New();
1066 surfaceEdgeTable->InitEdgeInsertion(numberOfInputPoints,1);
1067 surfaceFaceTable->InitEdgeInsertion(numberOfInputPoints,1);
1068
1069 for (i=0; i<numberOfInputTriangles; i++)
1070 {
1071 cellId = triangleIds->GetValue(i);
1072 input->GetCell(cellId,cell);
1073
1074 bool project = true;
1075 if (locator)
1076 {
1077 if (this->CellEntityIdsArrayName)
1078 {
1079 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1080 {
1081 project = false;
1082 }
1083 }
1084 }
1085
1086 cell->Points->GetPoint(0,point0);
1087 cell->Points->GetPoint(1,point1);
1088 cell->Points->GetPoint(2,point2);
1089
1090 pointId0 = cell->PointIds->GetId(0);
1091 pointId1 = cell->PointIds->GetId(1);
1092 pointId2 = cell->PointIds->GetId(2);
1093
1094 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1095 if (edgePointId01 == -1)
1096 {
1097 for (j=0; j<3; j++)
1098 {
1099 point[j] = 0.5 * (point0[j] + point1[j]);
1100 }
1101 edgePointId01 = outputPoints->InsertNextPoint(point);
1102 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
1103 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1104 }
1105
1106 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
1107 if (edgePointId02 == -1)
1108 {
1109 for (j=0; j<3; j++)
1110 {
1111 point[j] = 0.5 * (point0[j] + point2[j]);
1112 }
1113 edgePointId02 = outputPoints->InsertNextPoint(point);
1114 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
1115 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
1116 }
1117
1118 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1119 if (edgePointId12 == -1)
1120 {
1121 for (j=0; j<3; j++)
1122 {
1123 point[j] = 0.5 * (point1[j] + point2[j]);
1124 }
1125 edgePointId12 = outputPoints->InsertNextPoint(point);
1126 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
1127 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1128 }
1129
1130 if (project)
1131 {
1132 surfaceEdgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1133 surfaceEdgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
1134 surfaceEdgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1135 }
1136
1137 pts[0] = pointId0;
1138 pts[1] = pointId1;
1139 pts[2] = pointId2;
1140 pts[3] = edgePointId01;
1141 pts[4] = edgePointId12;
1142 pts[5] = edgePointId02;
1143
1144 vtkIdType newCellId = output->InsertNextCell(VTK_QUADRATIC_TRIANGLE, 6, pts);
1145
1146 inputToOutputCellIds->SetId(cellId,newCellId);
1147 outputCellData->CopyData(inputCellData,cellId,newCellId);
1148
1149 if (locator && project)
1150 {
1151 double point01[3], point12[3], point02[3];
1152 outputPoints->GetPoint(edgePointId01,point01);
1153 locator->FindClosestPoint(point01,projectedPoint,referenceCellId,subId,dist2);
1154 outputPoints->SetPoint(edgePointId01,projectedPoint);
1155 outputPoints->GetPoint(edgePointId12,point12);
1156 locator->FindClosestPoint(point12,projectedPoint,referenceCellId,subId,dist2);
1157 outputPoints->SetPoint(edgePointId12,projectedPoint);
1158 outputPoints->GetPoint(edgePointId02,point02);
1159 locator->FindClosestPoint(point02,projectedPoint,referenceCellId,subId,dist2);
1160 outputPoints->SetPoint(edgePointId02,projectedPoint);
1161 }
1162 }
1163
1164 for (i=0; i<numberOfInputQuads; i++)
1165 {
1166 cellId = quadIds->GetValue(i);
1167 input->GetCell(cellId,cell);
1168
1169 bool project = true;
1170 if (locator)
1171 {
1172 if (this->CellEntityIdsArrayName)
1173 {
1174 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1175 {
1176 project = false;
1177 }
1178 }
1179 }
1180
1181 cell->Points->GetPoint(0,point0);
1182 cell->Points->GetPoint(1,point1);
1183 cell->Points->GetPoint(2,point2);
1184 cell->Points->GetPoint(3,point3);
1185
1186 pointId0 = cell->PointIds->GetId(0);
1187 pointId1 = cell->PointIds->GetId(1);
1188 pointId2 = cell->PointIds->GetId(2);
1189 pointId3 = cell->PointIds->GetId(3);
1190
1191 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1192 if (edgePointId01 == -1)
1193 {
1194 for (j=0; j<3; j++)
1195 {
1196 point[j] = 0.5 * (point0[j] + point1[j]);
1197 }
1198 edgePointId01 = outputPoints->InsertNextPoint(point);
1199 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
1200 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1201 }
1202
1203 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1204 if (edgePointId12 == -1)
1205 {
1206 for (j=0; j<3; j++)
1207 {
1208 point[j] = 0.5 * (point1[j] + point2[j]);
1209 }
1210 edgePointId12 = outputPoints->InsertNextPoint(point);
1211 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
1212 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1213 }
1214
1215 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
1216 if (edgePointId23 == -1)
1217 {
1218 for (j=0; j<3; j++)
1219 {
1220 point[j] = 0.5 * (point2[j] + point3[j]);
1221 }
1222 edgePointId23 = outputPoints->InsertNextPoint(point);
1223 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
1224 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
1225 }
1226
1227 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
1228 if (edgePointId03 == -1)
1229 {
1230 for (j=0; j<3; j++)
1231 {
1232 point[j] = 0.5 * (point0[j] + point3[j]);
1233 }
1234 edgePointId03 = outputPoints->InsertNextPoint(point);
1235 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
1236 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
1237 }
1238
1239 if (project)
1240 {
1241 surfaceEdgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1242 surfaceEdgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1243 surfaceEdgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
1244 surfaceEdgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
1245 }
1246
1247 pts[0] = pointId0;
1248 pts[1] = pointId1;
1249 pts[2] = pointId2;
1250 pts[3] = pointId3;
1251 pts[4] = edgePointId01;
1252 pts[5] = edgePointId12;
1253 pts[6] = edgePointId23;
1254 pts[7] = edgePointId03;
1255
1256 if (this->NumberOfNodesHexahedra > 20)
1257 {
1258 facePointIds->Initialize();
1259 facePointIds->InsertNextId(pointId0);
1260 facePointIds->InsertNextId(pointId1);
1261 facePointIds->InsertNextId(pointId2);
1262 facePointIds->InsertNextId(pointId3);
1263 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
1264 neighborCellId = -1;
1265 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
1266 {
1267 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
1268 input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON)
1269 {
1270 neighborCellId = cellNeighbors->GetId(j);
1271 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
1272 break;
1273 }
1274 }
1275 if (neighborCellId != -1)
1276 {
1277 pts[8] = facePointId0123;
1278 if (project)
1279 {
1280 surfaceFaceTable->InsertEdge(cellId,neighborCellId,facePointId0123);
1281 }
1282 }
1283 }
1284
1285 vtkIdType newCellId;
1286 switch (this->NumberOfNodesHexahedra)
1287 {
1288 case 20:
1289 {
1290 newCellId = output->InsertNextCell(VTK_QUADRATIC_QUAD, 8, pts);
1291 break;
1292 }
1293 case 27:
1294 {
1295 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUAD, 9, pts);
1296 break;
1297 }
1298 default:
1299 {
1300 newCellId = output->InsertNextCell(VTK_QUAD, 4, pts);
1301 vtkErrorMacro(<<"Invalid number of nodes (" << this->NumberOfNodesHexahedra << ") for a hexahedral mesh with quadratic quad surface- choose 20 or 27.\n");
1302 return 1;
1303 }
1304 }
1305
1306 inputToOutputCellIds->SetId(cellId,newCellId);
1307 outputCellData->CopyData(inputCellData,cellId,newCellId);
1308
1309 if (locator && project)
1310 {
1311 double point01[3], point12[3], point23[3], point03[3], facePoint[3];
1312 outputPoints->GetPoint(edgePointId01,point01);
1313 locator->FindClosestPoint(point01,projectedPoint,referenceCellId,subId,dist2);
1314 outputPoints->SetPoint(edgePointId01,projectedPoint);
1315 outputPoints->GetPoint(edgePointId12,point12);
1316 locator->FindClosestPoint(point12,projectedPoint,referenceCellId,subId,dist2);
1317 outputPoints->SetPoint(edgePointId12,projectedPoint);
1318 outputPoints->GetPoint(edgePointId23,point23);
1319 locator->FindClosestPoint(point23,projectedPoint,referenceCellId,subId,dist2);
1320 outputPoints->SetPoint(edgePointId23,projectedPoint);
1321 outputPoints->GetPoint(edgePointId03,point03);
1322 locator->FindClosestPoint(point03,projectedPoint,referenceCellId,subId,dist2);
1323 outputPoints->SetPoint(edgePointId03,projectedPoint);
1324 if (this->NumberOfNodesHexahedra > 20)
1325 {
1326 outputPoints->GetPoint(facePointId0123,facePoint);
1327 locator->FindClosestPoint(facePoint,projectedPoint,referenceCellId,subId,dist2);
1328 outputPoints->SetPoint(facePointId0123,projectedPoint);
1329 }
1330 }
1331 }
1332
1333//#define LEGACY_RELAXATION
1334#ifdef LEGACY_RELAXATION
1335 int numberOfRelaxationSteps = 10;
1336 int maxSignChangeIterations = 20;
1337 int signChangeCounter = 0;
1338 bool anySignChange = true;
1339 while (anySignChange)
1340 {
1341 if (signChangeCounter >= maxSignChangeIterations)
1342 {
1343 break;
1344 }
1345 signChangeCounter++;
1346 anySignChange = false;
1347 for (i=0; i<numberOfInputTriangles; i++)
1348 {
1349 cellId = triangleIds->GetValue(i);
1350 input->GetCell(cellId,cell);
1351
1352 cell->Points->GetPoint(0,point0);
1353 cell->Points->GetPoint(1,point1);
1354 cell->Points->GetPoint(2,point2);
1355
1356 pointId0 = cell->PointIds->GetId(0);
1357 pointId1 = cell->PointIds->GetId(1);
1358 pointId2 = cell->PointIds->GetId(2);
1359
1360 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1361 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1362 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
1363
1364 if (locator)
1365 {
1366 bool project = true;
1367 if (this->CellEntityIdsArrayName)
1368 {
1369 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1370 {
1371 project = false;
1372 }
1373 }
1374
1375 if (project)
1376 {
1377 vtkIdType volumeCellId = -1;
1378 vtkIdList* volumeCellIds = vtkIdList::New();
1379 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1380 if (volumeCellIds->GetNumberOfIds() == 0)
1381 {
1382 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" does not have a volume element attached.");
1383 volumeCellIds->Delete();
1384 continue;
1385 }
1386 if (volumeCellIds->GetNumberOfIds() > 1)
1387 {
1388 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" has more than one volume element attached.");
1389 volumeCellIds->Delete();
1390 continue;
1391 }
1392 volumeCellId = volumeCellIds->GetId(0);
1393 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1394 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1395 double point01[3], point12[3], point02[3];
1396 double projectedPoint01[3], projectedPoint12[3], projectedPoint02[3];
1397 outputPoints->GetPoint(edgePointId01,projectedPoint01);
1398 outputPoints->GetPoint(edgePointId12,projectedPoint12);
1399 outputPoints->GetPoint(edgePointId02,projectedPoint02);
1400 int s;
1401 for (s=0; s<numberOfRelaxationSteps; s++)
1402 {
1403 if (!this->HasJacobianChangedSign(linearVolumeCell,quadraticVolumeCell))
1404 {
1405 break;
1406 }
1407 anySignChange = true;
1408 vtkWarningMacro(<<"Warning: projection causes element "<<volumeCellId<<" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1409 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1410 for (j=0; j<3; j++)
1411 {
1412 point01[j] = (1.0 - relaxation) * projectedPoint01[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1413 point12[j] = (1.0 - relaxation) * projectedPoint12[j] + relaxation * (0.5 * (point1[j] + point2[j]));
1414 point02[j] = (1.0 - relaxation) * projectedPoint02[j] + relaxation * (0.5 * (point0[j] + point2[j]));
1415 }
1416 outputPoints->SetPoint(edgePointId01,point01);
1417 outputPoints->SetPoint(edgePointId12,point12);
1418 outputPoints->SetPoint(edgePointId02,point02);
1419 quadraticVolumeCell = output->GetCell(volumeCellId);
1420 }
1421 volumeCellIds->Delete();
1422 }
1423 }
1424 }
1425
1426 for (i=0; i<numberOfInputQuads; i++)
1427 {
1428 cellId = quadIds->GetValue(i);
1429 input->GetCell(cellId,cell);
1430
1431 cell->Points->GetPoint(0,point0);
1432 cell->Points->GetPoint(1,point1);
1433 cell->Points->GetPoint(2,point2);
1434 cell->Points->GetPoint(3,point3);
1435
1436 pointId0 = cell->PointIds->GetId(0);
1437 pointId1 = cell->PointIds->GetId(1);
1438 pointId2 = cell->PointIds->GetId(2);
1439 pointId3 = cell->PointIds->GetId(3);
1440
1441 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1442 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1443 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
1444 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
1445
1446 if (locator)
1447 {
1448 bool project = true;
1449 if (this->CellEntityIdsArrayName)
1450 {
1451 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1452 {
1453 project = false;
1454 }
1455 }
1456 if (project)
1457 {
1458 vtkIdType volumeCellId = 0;
1459 vtkIdList* volumeCellIds = vtkIdList::New();
1460 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1461 if (volumeCellIds->GetNumberOfIds() == 0)
1462 {
1463 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" does not have a volume element attached.");
1464 volumeCellIds->Delete();
1465 continue;
1466 }
1467 if (volumeCellIds->GetNumberOfIds() > 1)
1468 {
1469 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" has more than one volume element attached.");
1470 volumeCellIds->Delete();
1471 continue;
1472 }
1473 volumeCellId = volumeCellIds->GetId(0);
1474 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1475 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1476 double point01[3], point12[3], point23[3], point03[3];
1477 double projectedPoint01[3], projectedPoint12[3], projectedPoint23[3], projectedPoint03[3];
1478 outputPoints->GetPoint(edgePointId01,projectedPoint01);
1479 outputPoints->GetPoint(edgePointId12,projectedPoint12);
1480 outputPoints->GetPoint(edgePointId23,projectedPoint23);
1481 outputPoints->GetPoint(edgePointId03,projectedPoint03);
1482
1483 int s;
1484 for (s=0; s<numberOfRelaxationSteps; s++)
1485 {
1486 if (!this->HasJacobianChangedSign(linearVolumeCell,quadraticVolumeCell))
1487 {
1488 break;
1489 }
1490 anySignChange = true;
1491 vtkWarningMacro(<<"Warning: projection causes element "<<volumeCellId<<" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1492 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1493 for (j=0; j<3; j++)
1494 {
1495 point01[j] = (1.0 - relaxation) * projectedPoint01[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1496 point12[j] = (1.0 - relaxation) * projectedPoint12[j] + relaxation * (0.5 * (point1[j] + point2[j]));
1497 point23[j] = (1.0 - relaxation) * projectedPoint23[j] + relaxation * (0.5 * (point2[j] + point3[j]));
1498 point03[j] = (1.0 - relaxation) * projectedPoint03[j] + relaxation * (0.5 * (point0[j] + point3[j]));
1499 }
1500 outputPoints->SetPoint(edgePointId01,point01);
1501 outputPoints->SetPoint(edgePointId12,point12);
1502 outputPoints->SetPoint(edgePointId23,point23);
1503 outputPoints->SetPoint(edgePointId03,point03);
1504 quadraticVolumeCell = output->GetCell(volumeCellId);
1505 }
1506 volumeCellIds->Delete();
1507 }
1508 }
1509 }
1510 }
1511#else
1512 int numberOfRelaxationSteps = 10;
1513 int maxSignChangeIterations = 20;
1514 int signChangeCounter = 0;
1515 bool anySignChange = true;
1516 if (!locator)
1517 {
1518 anySignChange = false;
1519 }
1520 while (anySignChange)
1521 {
1522 if (signChangeCounter >= maxSignChangeIterations)
1523 {
1524 break;
1525 }
1526 signChangeCounter++;
1527 anySignChange = false;
1528
1529 surfaceEdgeTable->InitTraversal();
1530 vtkIdType edgePointId = surfaceEdgeTable->GetNextEdge(pointId0,pointId1);
1531 vtkIdList* edgePointIds = vtkIdList::New();
1532 vtkIdList* cellEdgeNeighbors = vtkIdList::New();
1533 while (edgePointId >= 0)
1534 {
1535 edgePointIds->Initialize();
1536 edgePointIds->InsertNextId(pointId0);
1537 edgePointIds->InsertNextId(pointId1);
1538 input->GetCellNeighbors(-1,edgePointIds,cellEdgeNeighbors);
1539 int numberOfCellEdgeNeighbors = cellEdgeNeighbors->GetNumberOfIds();
1540 for (i=0; i<numberOfCellEdgeNeighbors; i++)
1541 {
1542 vtkIdType volumeCellId = cellEdgeNeighbors->GetId(i);
1543 if (input->GetCell(volumeCellId)->GetCellDimension() != 3)
1544 {
1545 continue;
1546 }
1547 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1548 vtkIdType outputCellId = inputToOutputCellIds->GetId(volumeCellId);
1549 if (outputCellId == -1)
1550 {
1551 continue;
1552 }
1553 vtkCell* quadraticVolumeCell = output->GetCell(outputCellId);
1554
1555 int s;
1556 for (s=0; s<numberOfRelaxationSteps; s++)
1557 {
1558 if (!this->HasJacobianChangedSign(linearVolumeCell,quadraticVolumeCell))
1559 {
1560 break;
1561 }
1562 anySignChange = true;
1563 vtkWarningMacro(<<"Warning: projection causes element "<<volumeCellId<<" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1564 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1565 int numberOfEdges = linearVolumeCell->GetNumberOfEdges();
1566 int e;
1567 for (e=0; e<numberOfEdges; e++)
1568 {
1569 vtkCell* edge = linearVolumeCell->GetEdge(e);
1570 vtkIdType pointId0 = edge->GetPointId(0);
1571 vtkIdType pointId1 = edge->GetPointId(1);
1572 vtkIdType edgePointId = surfaceEdgeTable->IsEdge(pointId0,pointId1);
1573 if (edgePointId == -1)
1574 {
1575 continue;
1576 }
1577 double edgePoint[3], relaxedEdgePoint[3];
1578 input->GetPoint(pointId0,point0);
1579 input->GetPoint(pointId1,point1);
1580 output->GetPoint(edgePointId,edgePoint);
1581 for (j=0; j<3; j++)
1582 {
1583 relaxedEdgePoint[j] = (1.0 - relaxation) * edgePoint[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1584 }
1585 outputPoints->SetPoint(edgePointId,relaxedEdgePoint);
1586 }
1587 quadraticVolumeCell = output->GetCell(outputCellId);
1588 }
1589 }
1590 edgePointId = surfaceEdgeTable->GetNextEdge(pointId0,pointId1);
1591 }
1592 edgePointIds->Delete();
1593 cellEdgeNeighbors->Delete();
1594 }
1595#endif
1596
1597 // Legacy relaxation for non-edge points on surface faces
1598 if (numberOfInputQuads > 0 && this->NumberOfNodesHexahedra > 20)
1599 {
1600 int numberOfRelaxationSteps = 10;
1601 int maxSignChangeIterations = 20;
1602 int signChangeCounter = 0;
1603 bool anySignChange = true;
1604 while (anySignChange)
1605 {
1606 if (signChangeCounter >= maxSignChangeIterations)
1607 {
1608 break;
1609 }
1610 signChangeCounter++;
1611 anySignChange = false;
1612
1613 for (i=0; i<numberOfInputQuads; i++)
1614 {
1615 cellId = quadIds->GetValue(i);
1616 input->GetCell(cellId,cell);
1617
1618 cell->Points->GetPoint(0,point0);
1619 cell->Points->GetPoint(1,point1);
1620 cell->Points->GetPoint(2,point2);
1621 cell->Points->GetPoint(3,point3);
1622
1623 pointId0 = cell->PointIds->GetId(0);
1624 pointId1 = cell->PointIds->GetId(1);
1625 pointId2 = cell->PointIds->GetId(2);
1626 pointId3 = cell->PointIds->GetId(3);
1627
1628 facePointIds->Initialize();
1629 facePointIds->InsertNextId(pointId0);
1630 facePointIds->InsertNextId(pointId1);
1631 facePointIds->InsertNextId(pointId2);
1632 facePointIds->InsertNextId(pointId3);
1633 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
1634 neighborCellId = -1;
1635 facePointId0123 = -1;
1636 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
1637 {
1638 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
1639 input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON)
1640 {
1641 neighborCellId = cellNeighbors->GetId(j);
1642 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
1643 break;
1644 }
1645 }
1646 if (locator)
1647 {
1648 bool project = true;
1649 if (this->CellEntityIdsArrayName)
1650 {
1651 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1652 {
1653 project = false;
1654 }
1655 }
1656 if (project)
1657 {
1658 vtkIdType volumeCellId = 0;
1659 vtkIdList* volumeCellIds = vtkIdList::New();
1660 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1661 if (volumeCellIds->GetNumberOfIds() == 0)
1662 {
1663 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" does not have a volume element attached.");
1664 volumeCellIds->Delete();
1665 continue;
1666 }
1667 if (volumeCellIds->GetNumberOfIds() > 1)
1668 {
1669 vtkWarningMacro(<<"Warning: surface element "<<cellId<<" has more than one volume element attached.");
1670 volumeCellIds->Delete();
1671 continue;
1672 }
1673 volumeCellId = volumeCellIds->GetId(0);
1674 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1675 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1676 double facePoint[3];
1677 double projectedFacePoint0123[3];
1678
1679 outputPoints->GetPoint(facePointId0123,projectedFacePoint0123);
1680 int s;
1681 for (s=0; s<numberOfRelaxationSteps; s++)
1682 {
1683 if (!this->HasJacobianChangedSign(linearVolumeCell,quadraticVolumeCell))
1684 {
1685 break;
1686 }
1687 anySignChange = true;
1688 vtkWarningMacro(<<"Warning: projection causes element "<<volumeCellId<<" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1689 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1690 for (j=0; j<3; j++)
1691 {
1692 facePoint[j] = (1.0 - relaxation) * projectedFacePoint0123[j] + relaxation * (0.25 * (point0[j] + point1[j] + point2[j] + point3[j]));
1693 }
1694 outputPoints->SetPoint(facePointId0123,facePoint);
1695 quadraticVolumeCell = output->GetCell(volumeCellId);
1696 }
1697 volumeCellIds->Delete();
1698 }
1699 }
1700 }
1701 }
1702 }
1703
1704 if (this->TestFinalJacobians)
1705 {
1706 for (i=0; i<numberOfCells; i++)
1707 {
1708 vtkCell* linearVolumeCell = input->GetCell(i);
1709 if (linearVolumeCell->GetCellDimension() != 3)
1710 {
1711 continue;
1712 }
1713 vtkIdType outputCellId = inputToOutputCellIds->GetId(i);
1714 if (outputCellId == -1)
1715 {
1716 continue;
1717 }
1718 vtkCell* quadraticVolumeCell = output->GetCell(outputCellId);
1719
1720 if (this->HasJacobianChangedSign(linearVolumeCell,quadraticVolumeCell))
1721 {
1722 vtkErrorMacro("Error: negative Jacobian detected in cell "<<outputCellId<<" even after relaxation. Output quadratic mesh will have negative Jacobians.");
1723 }
1724 }
1725 }
1726
1727 surfaceEdgeTable->Delete();
1728 surfaceFaceTable->Delete();
1729
1730 outputPoints->Delete();
1731 edgeTable->Delete();
1732 faceTable->Delete();
1733
1734 triangleIds->Delete();
1735 tetraIds->Delete();
1736 wedgeIds->Delete();
1737 hexahedraIds->Delete();
1738 quadIds->Delete();
1739 facePointIds->Delete();
1740 cellNeighbors->Delete();
1741
1742 cell->Delete();
1743 if (locator)
1744 {
1745 locator->Delete();
1746 locator = NULL;
1747 }
1748 cellEntityIdsArray->Delete();
1749
1750 inputToOutputCellIds->Delete();
1751
1752 output->Squeeze();
1753
1754 return 1;
1755}
1756
1757double vtkvmtkLinearToQuadraticMeshFilter::ComputeJacobian(vtkCell* cell, double pcoords[3])
1758{
1759 double jacobian = 0.0;
1760
1761 int numberOfCellPoints = cell->GetNumberOfPoints();
1762 double* derivs = new double[3*numberOfCellPoints];
1763
1765
1766 int i, j;
1767
1768 double jacobianMatrix[3][3];
1769 for (i=0; i<3; i++)
1770 {
1771 jacobianMatrix[0][i] = jacobianMatrix[1][i] = jacobianMatrix[2][i] = 0.0;
1772 }
1773
1774 double x[3];
1775 for (j=0; j<numberOfCellPoints; j++)
1776 {
1777 cell->GetPoints()->GetPoint(j,x);
1778 for (i=0; i<3; i++)
1779 {
1780 jacobianMatrix[0][i] += x[i] * derivs[j];
1781 jacobianMatrix[1][i] += x[i] * derivs[numberOfCellPoints+j];
1782 jacobianMatrix[2][i] += x[i] * derivs[2*numberOfCellPoints+j];
1783 }
1784 }
1785 delete[] derivs;
1786
1787 jacobian = vtkMath::Determinant3x3(jacobianMatrix);
1788
1789 return jacobian;
1790}
1791
1792bool vtkvmtkLinearToQuadraticMeshFilter::HasJacobianChangedSign(vtkCell* linearVolumeCell, vtkCell* quadraticVolumeCell)
1793{
1795 gaussQuadrature->SetOrder(this->QuadratureOrder);
1796 gaussQuadrature->Initialize(quadraticVolumeCell->GetCellType());
1797 bool signChanged = false;
1798 int numberOfQuadraturePoints = gaussQuadrature->GetNumberOfQuadraturePoints();
1799 double quadraturePCoords[3];
1800 int q;
1801 for (q=0; q<numberOfQuadraturePoints; q++)
1802 {
1803 gaussQuadrature->GetQuadraturePoint(q,quadraturePCoords);
1804 double linearJacobian = this->ComputeJacobian(linearVolumeCell,quadraturePCoords);
1805 double quadraticJacobian = this->ComputeJacobian(quadraticVolumeCell,quadraturePCoords);
1806 if (linearJacobian*quadraticJacobian < 0.0)
1807 {
1808 signChanged = true;
1809 break;
1810 }
1811 }
1812 gaussQuadrature->Delete();
1813 if (signChanged)
1814 {
1815 return signChanged;
1816 }
1817
1818 double* parametricCoords = quadraticVolumeCell->GetParametricCoords();
1819 int numberOfCellPoints = quadraticVolumeCell->GetNumberOfPoints();
1820 for (q=0; q<numberOfCellPoints; q++)
1821 {
1822 quadraturePCoords[0] = parametricCoords[q*numberOfCellPoints + 0];
1823 quadraturePCoords[1] = parametricCoords[q*numberOfCellPoints + 1];
1824 quadraturePCoords[2] = parametricCoords[q*numberOfCellPoints + 2];
1825 double linearJacobian = this->ComputeJacobian(linearVolumeCell,quadraturePCoords);
1826 double quadraticJacobian = this->ComputeJacobian(quadraticVolumeCell,quadraturePCoords);
1827 if (linearJacobian*quadraticJacobian < this->NegativeJacobianTolerance)
1828 {
1829 signChanged = true;
1830 break;
1831 }
1832 }
1833
1834 return signChanged;
1835}
1836
1837void vtkvmtkLinearToQuadraticMeshFilter::PrintSelf(std::ostream& os, vtkIndent indent)
1838{
1839 this->Superclass::PrintSelf(os,indent);
1840}
static void GetInterpolationDerivs(vtkCell *cell, double *pcoords, double *derivs)
Implements a finite element quadrature rule that approximates the definite integral of a function as ...
double * GetQuadraturePoint(vtkIdType id)
static vtkvmtkGaussQuadrature * New()
void Initialize(vtkIdType cellType)
virtual void SetOrder(int)
Converts linear mesh elements to quadratic mesh elements (optionally) by executing by projecting mid ...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
bool HasJacobianChangedSign(vtkCell *linearVolumeCell, vtkCell *quadraticVolumeCell)
double ComputeJacobian(vtkCell *cell, double pcoords[3])
vtkStandardNewMacro(vtkvmtkLinearToQuadraticMeshFilter)