1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkUnstructuredGrid.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkUnstructuredGrid.h"
16
17 #include "vtkCellArray.h"
18 #include "vtkCellData.h"
19 #include "vtkCellLinks.h"
20 #include "vtkConvexPointSet.h"
21 #include "vtkCubicLine.h"
22 #include "vtkEmptyCell.h"
23 #include "vtkGenericCell.h"
24 #include "vtkHexahedron.h"
25 #include "vtkIdTypeArray.h"
26 #include "vtkInformation.h"
27 #include "vtkInformationVector.h"
28 #include "vtkLagrangeCurve.h"
29 #include "vtkLagrangeQuadrilateral.h"
30 #include "vtkLagrangeHexahedron.h"
31 #include "vtkLagrangeTriangle.h"
32 #include "vtkLagrangeTetra.h"
33 #include "vtkLagrangeWedge.h"
34 #include "vtkLine.h"
35 #include "vtkNew.h"
36 #include "vtkObjectFactory.h"
37 #include "vtkPixel.h"
38 #include "vtkPointData.h"
39 #include "vtkPolyLine.h"
40 #include "vtkPolyVertex.h"
41 #include "vtkPolygon.h"
42 #include "vtkPolyhedron.h"
43 #include "vtkPyramid.h"
44 #include "vtkPentagonalPrism.h"
45 #include "vtkHexagonalPrism.h"
46 #include "vtkQuad.h"
47 #include "vtkQuadraticEdge.h"
48 #include "vtkQuadraticHexahedron.h"
49 #include "vtkQuadraticWedge.h"
50 #include "vtkQuadraticPolygon.h"
51 #include "vtkQuadraticPyramid.h"
52 #include "vtkQuadraticQuad.h"
53 #include "vtkQuadraticTetra.h"
54 #include "vtkQuadraticTriangle.h"
55 #include "vtkTetra.h"
56 #include "vtkTriangle.h"
57 #include "vtkTriangleStrip.h"
58 #include "vtkUnsignedCharArray.h"
59 #include "vtkUnstructuredGridCellIterator.h"
60 #include "vtkVertex.h"
61 #include "vtkVoxel.h"
62 #include "vtkWedge.h"
63 #include "vtkTriQuadraticHexahedron.h"
64 #include "vtkQuadraticLinearWedge.h"
65 #include "vtkQuadraticLinearQuad.h"
66 #include "vtkBiQuadraticQuad.h"
67 #include "vtkBiQuadraticQuadraticWedge.h"
68 #include "vtkBiQuadraticQuadraticHexahedron.h"
69 #include "vtkBiQuadraticTriangle.h"
70
71 #include <set>
72
73 vtkStandardNewMacro(vtkUnstructuredGrid);
74
vtkUnstructuredGrid()75 vtkUnstructuredGrid::vtkUnstructuredGrid ()
76 {
77 this->Vertex = nullptr;
78 this->PolyVertex = nullptr;
79 this->LagrangeCurve = nullptr;
80 this->LagrangeQuadrilateral = nullptr;
81 this->LagrangeHexahedron = nullptr;
82 this->LagrangeTriangle = nullptr;
83 this->LagrangeTetra = nullptr;
84 this->LagrangeWedge = nullptr;
85 this->Line = nullptr;
86 this->PolyLine = nullptr;
87 this->Triangle = nullptr;
88 this->TriangleStrip = nullptr;
89 this->Pixel = nullptr;
90 this->Quad = nullptr;
91 this->Polygon = nullptr;
92 this->Tetra = nullptr;
93 this->Voxel = nullptr;
94 this->Hexahedron = nullptr;
95 this->Wedge = nullptr;
96 this->Pyramid = nullptr;
97 this->PentagonalPrism = nullptr;
98 this->HexagonalPrism = nullptr;
99 this->QuadraticEdge = nullptr;
100 this->QuadraticTriangle =nullptr;
101 this->QuadraticQuad = nullptr;
102 this->QuadraticPolygon = nullptr;
103 this->QuadraticTetra = nullptr;
104 this->QuadraticHexahedron = nullptr;
105 this->QuadraticWedge = nullptr;
106 this->QuadraticPyramid = nullptr;
107 this->QuadraticLinearQuad = nullptr;
108 this->BiQuadraticQuad = nullptr;
109 this->TriQuadraticHexahedron = nullptr;
110 this->QuadraticLinearWedge = nullptr;
111 this->BiQuadraticQuadraticWedge = nullptr;
112 this->BiQuadraticQuadraticHexahedron = nullptr;
113 this->BiQuadraticTriangle = nullptr;
114 this->CubicLine = nullptr;
115
116 this->ConvexPointSet = nullptr;
117 this->Polyhedron = nullptr;
118 this->EmptyCell = nullptr;
119
120 this->Information->Set(vtkDataObject::DATA_EXTENT_TYPE(), VTK_PIECES_EXTENT);
121 this->Information->Set(vtkDataObject::DATA_PIECE_NUMBER(), -1);
122 this->Information->Set(vtkDataObject::DATA_NUMBER_OF_PIECES(), 1);
123 this->Information->Set(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS(), 0);
124
125 this->Connectivity = nullptr;
126 this->Links = nullptr;
127 this->Types = nullptr;
128 this->Locations = nullptr;
129
130 this->Faces = nullptr;
131 this->FaceLocations = nullptr;
132
133 this->Allocate(1000,1000);
134 }
135
136 //----------------------------------------------------------------------------
137 // Allocate memory space for data insertion. Execute this method before
138 // inserting any cells into object.
Allocate(vtkIdType numCells,int extSize)139 void vtkUnstructuredGrid::Allocate (vtkIdType numCells, int extSize)
140 {
141 if ( numCells < 1 )
142 {
143 numCells = 1000;
144 }
145 if ( extSize < 1 )
146 {
147 extSize = 1000;
148 }
149
150 if ( this->Connectivity )
151 {
152 this->Connectivity->UnRegister(this);
153 }
154 this->Connectivity = vtkCellArray::New();
155 this->Connectivity->Allocate(numCells,4*extSize);
156 this->Connectivity->Register(this);
157 this->Connectivity->Delete();
158
159 if ( this->Types )
160 {
161 this->Types->UnRegister(this);
162 }
163 this->Types = vtkUnsignedCharArray::New();
164 this->Types->Allocate(numCells,extSize);
165 this->Types->Register(this);
166 this->Types->Delete();
167
168 if ( this->Locations )
169 {
170 this->Locations->UnRegister(this);
171 }
172 this->Locations = vtkIdTypeArray::New();
173 this->Locations->Allocate(numCells,extSize);
174 this->Locations->Register(this);
175 this->Locations->Delete();
176 }
177
178 //----------------------------------------------------------------------------
~vtkUnstructuredGrid()179 vtkUnstructuredGrid::~vtkUnstructuredGrid()
180 {
181 this->Cleanup();
182
183 if(this->Vertex)
184 {
185 this->Vertex->Delete();
186 }
187 if(this->PolyVertex)
188 {
189 this->PolyVertex->Delete();
190 }
191 if(this->LagrangeCurve)
192 {
193 this->LagrangeCurve->Delete();
194 }
195 if(this->LagrangeQuadrilateral)
196 {
197 this->LagrangeQuadrilateral->Delete();
198 }
199 if(this->LagrangeHexahedron)
200 {
201 this->LagrangeHexahedron->Delete();
202 }
203 if(this->LagrangeTriangle)
204 {
205 this->LagrangeTriangle->Delete();
206 }
207 if(this->LagrangeTetra)
208 {
209 this->LagrangeTetra->Delete();
210 }
211 if(this->LagrangeWedge)
212 {
213 this->LagrangeWedge->Delete();
214 }
215 if(this->Line)
216 {
217 this->Line->Delete();
218 }
219 if(this->PolyLine)
220 {
221 this->PolyLine->Delete();
222 }
223 if(this->Triangle)
224 {
225 this->Triangle->Delete();
226 }
227 if(this->TriangleStrip)
228 {
229 this->TriangleStrip->Delete();
230 }
231 if(this->Pixel)
232 {
233 this->Pixel->Delete();
234 }
235 if(this->Quad)
236 {
237 this->Quad->Delete();
238 }
239 if(this->Polygon)
240 {
241 this->Polygon->Delete();
242 }
243 if(this->Tetra)
244 {
245 this->Tetra->Delete();
246 }
247 if(this->Voxel)
248 {
249 this->Voxel->Delete();
250 }
251 if(this->Hexahedron)
252 {
253 this->Hexahedron->Delete();
254 }
255 if(this->Wedge)
256 {
257 this->Wedge->Delete();
258 }
259 if(this->Pyramid)
260 {
261 this->Pyramid->Delete();
262 }
263 if(this->PentagonalPrism)
264 {
265 this->PentagonalPrism->Delete();
266 }
267 if(this->HexagonalPrism)
268 {
269 this->HexagonalPrism->Delete();
270 }
271 if(this->QuadraticEdge)
272 {
273 this->QuadraticEdge->Delete();
274 }
275 if(this->QuadraticTriangle)
276 {
277 this->QuadraticTriangle->Delete();
278 }
279 if(this->QuadraticQuad)
280 {
281 this->QuadraticQuad->Delete();
282 }
283 if(this->QuadraticPolygon)
284 {
285 this->QuadraticPolygon->Delete();
286 }
287 if(this->QuadraticTetra)
288 {
289 this->QuadraticTetra->Delete();
290 }
291 if(this->QuadraticHexahedron)
292 {
293 this->QuadraticHexahedron->Delete();
294 }
295 if(this->QuadraticWedge)
296 {
297 this->QuadraticWedge->Delete();
298 }
299 if(this->QuadraticPyramid)
300 {
301 this->QuadraticPyramid->Delete();
302 }
303 if(this->QuadraticLinearQuad)
304 {
305 this->QuadraticLinearQuad->Delete ();
306 }
307 if(this->BiQuadraticQuad)
308 {
309 this->BiQuadraticQuad->Delete ();
310 }
311 if(this->TriQuadraticHexahedron)
312 {
313 this->TriQuadraticHexahedron->Delete ();
314 }
315 if(this->QuadraticLinearWedge)
316 {
317 this->QuadraticLinearWedge->Delete ();
318 }
319 if(this->BiQuadraticQuadraticWedge)
320 {
321 this->BiQuadraticQuadraticWedge->Delete ();
322 }
323 if(this->BiQuadraticQuadraticHexahedron)
324 {
325 this->BiQuadraticQuadraticHexahedron->Delete ();
326 }
327 if(this->BiQuadraticTriangle)
328 {
329 this->BiQuadraticTriangle->Delete ();
330 }
331 if(this->CubicLine)
332 {
333 this->CubicLine->Delete ();
334 }
335
336 if(this->ConvexPointSet)
337 {
338 this->ConvexPointSet->Delete();
339 }
340 if(this->Polyhedron)
341 {
342 this->Polyhedron->Delete();
343 }
344 if(this->EmptyCell)
345 {
346 this->EmptyCell->Delete();
347 }
348 }
349
350 //----------------------------------------------------------------------------
GetPiece()351 int vtkUnstructuredGrid::GetPiece()
352 {
353 return this->Information->Get(vtkDataObject::DATA_PIECE_NUMBER());
354 }
355
356 //----------------------------------------------------------------------------
GetNumberOfPieces()357 int vtkUnstructuredGrid::GetNumberOfPieces()
358 {
359 return this->Information->Get(vtkDataObject::DATA_NUMBER_OF_PIECES());
360 }
361
362 //----------------------------------------------------------------------------
GetGhostLevel()363 int vtkUnstructuredGrid::GetGhostLevel()
364 {
365 return this->Information->Get(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS());
366 }
367
368 //----------------------------------------------------------------------------
369 // Copy the geometric and topological structure of an input unstructured grid.
CopyStructure(vtkDataSet * ds)370 void vtkUnstructuredGrid::CopyStructure(vtkDataSet *ds)
371 {
372 // If ds is a vtkUnstructuredGrid, do a shallow copy of the cell data.
373 if (vtkUnstructuredGrid *ug = vtkUnstructuredGrid::SafeDownCast(ds))
374 {
375 if (this->Connectivity != ug->Connectivity)
376 {
377 if ( this->Connectivity )
378 {
379 this->Connectivity->UnRegister(this);
380 }
381 this->Connectivity = ug->Connectivity;
382 if (this->Connectivity)
383 {
384 this->Connectivity->Register(this);
385 }
386 }
387
388 if (this->Links != ug->Links)
389 {
390 if ( this->Links )
391 {
392 this->Links->UnRegister(this);
393 }
394 this->Links = ug->Links;
395 if (this->Links)
396 {
397 this->Links->Register(this);
398 }
399 }
400
401 if (this->Types != ug->Types)
402 {
403 if ( this->Types )
404 {
405 this->Types->UnRegister(this);
406 }
407 this->Types = ug->Types;
408 if (this->Types)
409 {
410 this->Types->Register(this);
411 }
412 }
413
414 if (this->Locations != ug->Locations)
415 {
416 if ( this->Locations )
417 {
418 this->Locations->UnRegister(this);
419 }
420 this->Locations = ug->Locations;
421 if (this->Locations)
422 {
423 this->Locations->Register(this);
424 }
425 }
426
427 if (this->Faces != ug->Faces)
428 {
429 if ( this->Faces )
430 {
431 this->Faces->UnRegister(this);
432 }
433 this->Faces = ug->Faces;
434 if (this->Faces)
435 {
436 this->Faces->Register(this);
437 }
438 }
439
440 if (this->FaceLocations != ug->FaceLocations)
441 {
442 if ( this->FaceLocations )
443 {
444 this->FaceLocations->UnRegister(this);
445 }
446 this->FaceLocations = ug->FaceLocations;
447 if (this->FaceLocations)
448 {
449 this->FaceLocations->Register(this);
450 }
451 }
452 }
453
454 this->Superclass::CopyStructure(ds);
455 }
456
457 //----------------------------------------------------------------------------
Cleanup()458 void vtkUnstructuredGrid::Cleanup()
459 {
460 if ( this->Connectivity )
461 {
462 this->Connectivity->UnRegister(this);
463 this->Connectivity = nullptr;
464 }
465
466 if ( this->Links )
467 {
468 this->Links->UnRegister(this);
469 this->Links = nullptr;
470 }
471
472 if ( this->Types )
473 {
474 this->Types->UnRegister(this);
475 this->Types = nullptr;
476 }
477
478 if ( this->Locations )
479 {
480 this->Locations->UnRegister(this);
481 this->Locations = nullptr;
482 }
483
484 if ( this->Faces )
485 {
486 this->Faces->UnRegister(this);
487 this->Faces = nullptr;
488 }
489
490 if ( this->FaceLocations )
491 {
492 this->FaceLocations->UnRegister(this);
493 this->FaceLocations = nullptr;
494 }
495 }
496
497 //----------------------------------------------------------------------------
Initialize()498 void vtkUnstructuredGrid::Initialize()
499 {
500 vtkPointSet::Initialize();
501
502 this->Cleanup();
503
504 if(this->Information)
505 {
506 this->Information->Set(vtkDataObject::DATA_PIECE_NUMBER(), -1);
507 this->Information->Set(vtkDataObject::DATA_NUMBER_OF_PIECES(), 0);
508 this->Information->Set(vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS(), 0);
509 }
510 }
511
512 //----------------------------------------------------------------------------
GetCellType(vtkIdType cellId)513 int vtkUnstructuredGrid::GetCellType(vtkIdType cellId)
514 {
515
516 vtkDebugMacro(<< "Returning cell type " << static_cast<int>(this->Types->GetValue(cellId)));
517 return static_cast<int>(this->Types->GetValue(cellId));
518 }
519
520 //----------------------------------------------------------------------------
GetCell(vtkIdType cellId)521 vtkCell *vtkUnstructuredGrid::GetCell(vtkIdType cellId)
522 {
523 vtkIdType i;
524 vtkIdType loc;
525 vtkCell *cell = nullptr;
526 vtkIdType *pts, numPts;
527
528 loc = this->Locations->GetValue(cellId);
529 vtkDebugMacro(<< "location = " << loc);
530 this->Connectivity->GetCell(loc,numPts,pts);
531
532 int cellType = static_cast<int>(this->Types->GetValue(cellId));
533 switch (cellType)
534 {
535 case VTK_VERTEX:
536 if(!this->Vertex)
537 {
538 this->Vertex = vtkVertex::New();
539 }
540 cell = this->Vertex;
541 break;
542
543 case VTK_POLY_VERTEX:
544 if(!this->PolyVertex)
545 {
546 this->PolyVertex = vtkPolyVertex::New();
547 }
548 cell = this->PolyVertex;
549 break;
550
551 case VTK_LINE:
552 if(!this->Line)
553 {
554 this->Line = vtkLine::New();
555 }
556 cell = this->Line;
557 break;
558
559 case VTK_LAGRANGE_CURVE:
560 if(!this->LagrangeCurve)
561 {
562 this->LagrangeCurve = vtkLagrangeCurve::New();
563 }
564 cell = this->LagrangeCurve;
565 break;
566
567 case VTK_LAGRANGE_QUADRILATERAL:
568 if(!this->LagrangeQuadrilateral)
569 {
570 this->LagrangeQuadrilateral = vtkLagrangeQuadrilateral::New();
571 }
572 cell = this->LagrangeQuadrilateral;
573 break;
574
575 case VTK_LAGRANGE_HEXAHEDRON:
576 if(!this->LagrangeHexahedron)
577 {
578 this->LagrangeHexahedron = vtkLagrangeHexahedron::New();
579 }
580 cell = this->LagrangeHexahedron;
581 break;
582
583 case VTK_LAGRANGE_TRIANGLE:
584 if(!this->LagrangeTriangle)
585 {
586 this->LagrangeTriangle = vtkLagrangeTriangle::New();
587 }
588 cell = this->LagrangeTriangle;
589 break;
590
591 case VTK_LAGRANGE_TETRAHEDRON:
592 if(!this->LagrangeTetra)
593 {
594 this->LagrangeTetra = vtkLagrangeTetra::New();
595 }
596 cell = this->LagrangeTetra;
597 break;
598
599 case VTK_LAGRANGE_WEDGE:
600 if(!this->LagrangeWedge)
601 {
602 this->LagrangeWedge = vtkLagrangeWedge::New();
603 }
604 cell = this->LagrangeWedge;
605 break;
606
607 case VTK_POLY_LINE:
608 if(!this->PolyLine)
609 {
610 this->PolyLine = vtkPolyLine::New();
611 }
612 cell = this->PolyLine;
613 break;
614
615 case VTK_TRIANGLE:
616 if(!this->Triangle)
617 {
618 this->Triangle = vtkTriangle::New();
619 }
620 cell = this->Triangle;
621 break;
622
623 case VTK_TRIANGLE_STRIP:
624 if(!this->TriangleStrip)
625 {
626 this->TriangleStrip = vtkTriangleStrip::New();
627 }
628 cell = this->TriangleStrip;
629 break;
630
631 case VTK_PIXEL:
632 if(!this->Pixel)
633 {
634 this->Pixel = vtkPixel::New();
635 }
636 cell = this->Pixel;
637 break;
638
639 case VTK_QUAD:
640 if(!this->Quad)
641 {
642 this->Quad = vtkQuad::New();
643 }
644 cell = this->Quad;
645 break;
646
647 case VTK_POLYGON:
648 if(!this->Polygon)
649 {
650 this->Polygon = vtkPolygon::New();
651 }
652 cell = this->Polygon;
653 break;
654
655 case VTK_TETRA:
656 if(!this->Tetra)
657 {
658 this->Tetra = vtkTetra::New();
659 }
660 cell = this->Tetra;
661 break;
662
663 case VTK_VOXEL:
664 if(!this->Voxel)
665 {
666 this->Voxel = vtkVoxel::New();
667 }
668 cell = this->Voxel;
669 break;
670
671 case VTK_HEXAHEDRON:
672 if(!this->Hexahedron)
673 {
674 this->Hexahedron = vtkHexahedron::New();
675 }
676 cell = this->Hexahedron;
677 break;
678
679 case VTK_WEDGE:
680 if(!this->Wedge)
681 {
682 this->Wedge = vtkWedge::New();
683 }
684 cell = this->Wedge;
685 break;
686
687 case VTK_PYRAMID:
688 if(!this->Pyramid)
689 {
690 this->Pyramid = vtkPyramid::New();
691 }
692 cell = this->Pyramid;
693 break;
694
695 case VTK_PENTAGONAL_PRISM:
696 if(!this->PentagonalPrism)
697 {
698 this->PentagonalPrism = vtkPentagonalPrism::New();
699 }
700 cell = this->PentagonalPrism;
701 break;
702
703 case VTK_HEXAGONAL_PRISM:
704 if(!this->HexagonalPrism)
705 {
706 this->HexagonalPrism = vtkHexagonalPrism::New();
707 }
708 cell = this->HexagonalPrism;
709 break;
710
711 case VTK_QUADRATIC_EDGE:
712 if(!this->QuadraticEdge)
713 {
714 this->QuadraticEdge = vtkQuadraticEdge::New();
715 }
716 cell = this->QuadraticEdge;
717 break;
718
719 case VTK_QUADRATIC_TRIANGLE:
720 if(!this->QuadraticTriangle)
721 {
722 this->QuadraticTriangle = vtkQuadraticTriangle::New();
723 }
724 cell = this->QuadraticTriangle;
725 break;
726
727 case VTK_QUADRATIC_QUAD:
728 if(!this->QuadraticQuad)
729 {
730 this->QuadraticQuad = vtkQuadraticQuad::New();
731 }
732 cell = this->QuadraticQuad;
733 break;
734
735 case VTK_QUADRATIC_POLYGON:
736 if(!this->QuadraticPolygon)
737 {
738 this->QuadraticPolygon = vtkQuadraticPolygon::New();
739 }
740 cell = this->QuadraticPolygon;
741 break;
742
743 case VTK_QUADRATIC_TETRA:
744 if(!this->QuadraticTetra)
745 {
746 this->QuadraticTetra = vtkQuadraticTetra::New();
747 }
748 cell = this->QuadraticTetra;
749 break;
750
751 case VTK_QUADRATIC_HEXAHEDRON:
752 if(!this->QuadraticHexahedron)
753 {
754 this->QuadraticHexahedron = vtkQuadraticHexahedron::New();
755 }
756 cell = this->QuadraticHexahedron;
757 break;
758
759 case VTK_QUADRATIC_WEDGE:
760 if(!this->QuadraticWedge)
761 {
762 this->QuadraticWedge = vtkQuadraticWedge::New();
763 }
764 cell = this->QuadraticWedge;
765 break;
766
767 case VTK_QUADRATIC_PYRAMID:
768 if(!this->QuadraticPyramid)
769 {
770 this->QuadraticPyramid = vtkQuadraticPyramid::New();
771 }
772 cell = this->QuadraticPyramid;
773 break;
774
775 case VTK_QUADRATIC_LINEAR_QUAD:
776 if(!this->QuadraticLinearQuad)
777 {
778 this->QuadraticLinearQuad = vtkQuadraticLinearQuad::New();
779 }
780 cell = this->QuadraticLinearQuad;
781 break;
782
783 case VTK_BIQUADRATIC_QUAD:
784 if(!this->BiQuadraticQuad)
785 {
786 this ->BiQuadraticQuad = vtkBiQuadraticQuad::New();
787 }
788 cell = this->BiQuadraticQuad;
789 break;
790
791 case VTK_TRIQUADRATIC_HEXAHEDRON:
792 if(!this->TriQuadraticHexahedron)
793 {
794 this->TriQuadraticHexahedron = vtkTriQuadraticHexahedron::New();
795 }
796 cell = this->TriQuadraticHexahedron;
797 break;
798
799 case VTK_QUADRATIC_LINEAR_WEDGE:
800 if(!this->QuadraticLinearWedge)
801 {
802 this->QuadraticLinearWedge = vtkQuadraticLinearWedge::New();
803 }
804 cell = this->QuadraticLinearWedge;
805 break;
806
807 case VTK_BIQUADRATIC_QUADRATIC_WEDGE:
808 if(!this->BiQuadraticQuadraticWedge)
809 {
810 this->BiQuadraticQuadraticWedge = vtkBiQuadraticQuadraticWedge::New();
811 }
812 cell = this->BiQuadraticQuadraticWedge;
813 break;
814
815 case VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON:
816 if(!this->BiQuadraticQuadraticHexahedron)
817 {
818 this->BiQuadraticQuadraticHexahedron = vtkBiQuadraticQuadraticHexahedron::New();
819 }
820 cell = this->BiQuadraticQuadraticHexahedron;
821 break;
822 case VTK_BIQUADRATIC_TRIANGLE:
823 if(!this->BiQuadraticTriangle)
824 {
825 this->BiQuadraticTriangle = vtkBiQuadraticTriangle::New();
826 }
827 cell = this->BiQuadraticTriangle;
828 break;
829 case VTK_CUBIC_LINE:
830 if(!this->CubicLine)
831 {
832 this->CubicLine = vtkCubicLine::New();
833 }
834 cell = this->CubicLine;
835 break;
836
837 case VTK_CONVEX_POINT_SET:
838 if(!this->ConvexPointSet)
839 {
840 this->ConvexPointSet = vtkConvexPointSet::New();
841 }
842 cell = this->ConvexPointSet;
843 break;
844
845 case VTK_POLYHEDRON:
846 if(!this->Polyhedron)
847 {
848 this->Polyhedron = vtkPolyhedron::New();
849 }
850 this->Polyhedron->SetFaces(this->GetFaces(cellId));
851 cell = this->Polyhedron;
852 break;
853
854 case VTK_EMPTY_CELL:
855 if(!this->EmptyCell)
856 {
857 this->EmptyCell = vtkEmptyCell::New();
858 }
859 cell = this->EmptyCell;
860 break;
861 }
862
863 if( !cell )
864 {
865 return nullptr;
866 }
867
868 // Copy the points over to the cell.
869 cell->PointIds->SetNumberOfIds(numPts);
870 cell->Points->SetNumberOfPoints(numPts);
871 for (i=0; i<numPts; i++)
872 {
873 cell->PointIds->SetId(i,pts[i]);
874 cell->Points->SetPoint(i,this->Points->GetPoint(pts[i]));
875 }
876
877 // Some cells require special initialization to build data structures
878 // and such.
879 if ( cell->RequiresInitialization() )
880 {
881 cell->Initialize();
882 }
883
884 return cell;
885 }
886
887 //----------------------------------------------------------------------------
GetCell(vtkIdType cellId,vtkGenericCell * cell)888 void vtkUnstructuredGrid::GetCell(vtkIdType cellId, vtkGenericCell *cell)
889 {
890 vtkIdType loc;
891 vtkIdType *pts, numPts;
892
893 int cellType = static_cast<int>(this->Types->GetValue(cellId));
894 cell->SetCellType(cellType);
895
896 loc = this->Locations->GetValue(cellId);
897 this->Connectivity->GetCell(loc,numPts,pts);
898
899 cell->PointIds->SetNumberOfIds(numPts);
900
901 std::copy(pts, pts + numPts, cell->PointIds->GetPointer(0));
902 this->Points->GetPoints(cell->PointIds, cell->Points);
903
904 // Explicit face representation
905 if ( cell->RequiresExplicitFaceRepresentation() )
906 {
907 cell->SetFaces(this->GetFaces(cellId));
908 }
909
910 // Some cells require special initialization to build data structures
911 // and such.
912 if ( cell->RequiresInitialization() )
913 {
914 cell->Initialize();
915 }
916 }
917
918 //----------------------------------------------------------------------------
919 // Fast implementation of GetCellBounds(). Bounds are calculated without
920 // constructing a cell.
GetCellBounds(vtkIdType cellId,double bounds[6])921 void vtkUnstructuredGrid::GetCellBounds(vtkIdType cellId, double bounds[6])
922 {
923 vtkIdType i;
924 vtkIdType loc;
925 double x[3];
926 vtkIdType *pts, numPts;
927
928 loc = this->Locations->GetValue(cellId);
929 this->Connectivity->GetCell(loc,numPts,pts);
930
931 // carefully compute the bounds
932 if (numPts)
933 {
934 this->Points->GetPoint( pts[0], x );
935 bounds[0] = x[0];
936 bounds[2] = x[1];
937 bounds[4] = x[2];
938 bounds[1] = x[0];
939 bounds[3] = x[1];
940 bounds[5] = x[2];
941 for (i=1; i < numPts; i++)
942 {
943 this->Points->GetPoint( pts[i], x );
944 bounds[0] = (x[0] < bounds[0] ? x[0] : bounds[0]);
945 bounds[1] = (x[0] > bounds[1] ? x[0] : bounds[1]);
946 bounds[2] = (x[1] < bounds[2] ? x[1] : bounds[2]);
947 bounds[3] = (x[1] > bounds[3] ? x[1] : bounds[3]);
948 bounds[4] = (x[2] < bounds[4] ? x[2] : bounds[4]);
949 bounds[5] = (x[2] > bounds[5] ? x[2] : bounds[5]);
950 }
951 }
952 else
953 {
954 vtkMath::UninitializeBounds(bounds);
955 }
956
957 }
958
959 //----------------------------------------------------------------------------
GetMaxCellSize()960 int vtkUnstructuredGrid::GetMaxCellSize()
961 {
962 if (this->Connectivity)
963 {
964 return this->Connectivity->GetMaxCellSize();
965 }
966 else
967 {
968 return 0;
969 }
970 }
971
972 //----------------------------------------------------------------------------
GetNumberOfCells()973 vtkIdType vtkUnstructuredGrid::GetNumberOfCells()
974 {
975 vtkDebugMacro(<< "NUMBER OF CELLS = " <<
976 (this->Connectivity ? this->Connectivity->GetNumberOfCells() : 0));
977 return (this->Connectivity ? this->Connectivity->GetNumberOfCells() : 0);
978 }
979
980 //----------------------------------------------------------------------------
981 // Insert/create cell in object by type and list of point ids defining
982 // cell topology. Using a special input format, this function also support
983 // polyhedron cells.
InternalInsertNextCell(int type,vtkIdList * ptIds)984 vtkIdType vtkUnstructuredGrid::InternalInsertNextCell(int type, vtkIdList *ptIds)
985 {
986 if (type == VTK_POLYHEDRON)
987 {
988 // For polyhedron cell, input ptIds is of format:
989 // (numCellFaces, numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...)
990 vtkIdType* dataPtr = ptIds->GetPointer(0);
991 return this->InsertNextCell(type, dataPtr[0], dataPtr+1);
992 }
993
994 vtkIdType npts = ptIds->GetNumberOfIds();
995 // insert connectivity
996 this->Connectivity->InsertNextCell(ptIds);
997 // insert type and storage information
998 vtkDebugMacro(<< "insert location "
999 << this->Connectivity->GetInsertLocation(npts));
1000 this->Locations->InsertNextValue(this->Connectivity->GetInsertLocation(npts));
1001
1002 // If faces have been created, we need to pad them (we are not creating
1003 // a polyhedral cell in this method)
1004 if ( this->FaceLocations )
1005 {
1006 this->FaceLocations->InsertNextValue(-1);
1007 }
1008
1009 // insert cell type
1010 return this->Types->InsertNextValue(static_cast<unsigned char>(type));
1011 }
1012
1013 //----------------------------------------------------------------------------
1014 // Insert/create cell in object by type and list of point ids defining
1015 // cell topology. Using a special input format, this function also support
1016 // polyhedron cells.
InternalInsertNextCell(int type,vtkIdType npts,const vtkIdType ptIds[])1017 vtkIdType vtkUnstructuredGrid::InternalInsertNextCell(int type, vtkIdType npts,
1018 const vtkIdType ptIds[])
1019 {
1020 if (type != VTK_POLYHEDRON)
1021 {
1022 // insert connectivity
1023 this->Connectivity->InsertNextCell(npts,ptIds);
1024 // insert type and storage information
1025 vtkDebugMacro(<< "insert location "
1026 << this->Connectivity->GetInsertLocation(npts));
1027 this->Locations->InsertNextValue(
1028 this->Connectivity->GetInsertLocation(npts));
1029
1030 // If faces have been created, we need to pad them (we are not creating
1031 // a polyhedral cell in this method)
1032 if ( this->FaceLocations )
1033 {
1034 this->FaceLocations->InsertNextValue(-1);
1035 }
1036 }
1037 else
1038 {
1039 // For polyhedron, npts is actually number of faces, ptIds is of format:
1040 // (numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...)
1041 vtkIdType realnpts;
1042
1043 // We defer allocation for the faces because they are not commonly used and
1044 // we only want to allocate when necessary.
1045 if ( ! this->Faces )
1046 {
1047 this->Faces = vtkIdTypeArray::New();
1048 this->Faces->Allocate(this->Types->GetSize());
1049 this->FaceLocations = vtkIdTypeArray::New();
1050 this->FaceLocations->Allocate(this->Types->GetSize());
1051 // FaceLocations must be padded until the current position
1052 for(vtkIdType i = 0; i <= this->Types->GetMaxId(); i++)
1053 {
1054 this->FaceLocations->InsertNextValue(-1);
1055 }
1056 }
1057
1058 // insert cell location
1059 this->Locations->InsertNextValue(this->Connectivity->GetData()->GetMaxId()+1);
1060 // insert face location
1061 this->FaceLocations->InsertNextValue(this->Faces->GetMaxId()+1);
1062 // insert cell connectivity and faces stream
1063 vtkUnstructuredGrid::DecomposeAPolyhedronCell(
1064 npts, ptIds, realnpts, this->Connectivity, this->Faces);
1065 }
1066
1067 return this->Types->InsertNextValue(static_cast<unsigned char>(type));
1068 }
1069
1070 //----------------------------------------------------------------------------
1071 // Insert/create cell in object by type and list of point and face ids
1072 // defining cell topology. This method is meant for face-explicit cells (e.g.
1073 // polyhedron).
1074 vtkIdType vtkUnstructuredGrid::
InternalInsertNextCell(int type,vtkIdType npts,const vtkIdType pts[],vtkIdType nfaces,const vtkIdType faces[])1075 InternalInsertNextCell(int type, vtkIdType npts, const vtkIdType pts[],
1076 vtkIdType nfaces, const vtkIdType faces[])
1077 {
1078 if (type != VTK_POLYHEDRON)
1079 {
1080 return this->InsertNextCell(type, npts, pts);
1081 }
1082 // Insert connectivity (points that make up polyhedron)
1083 this->Connectivity->InsertNextCell(npts,pts);
1084
1085 // Insert location of cell in connectivity array
1086 this->Locations->InsertNextValue(
1087 this->Connectivity->GetInsertLocation(npts));
1088
1089 // Now insert faces; allocate storage if necessary.
1090 // We defer allocation for the faces because they are not commonly used and
1091 // we only want to allocate when necessary.
1092 if ( ! this->Faces )
1093 {
1094 this->Faces = vtkIdTypeArray::New();
1095 this->Faces->Allocate(this->Types->GetSize());
1096 this->FaceLocations = vtkIdTypeArray::New();
1097 this->FaceLocations->Allocate(this->Types->GetSize());
1098 // FaceLocations must be padded until the current position
1099 for(vtkIdType i = 0; i <= this->Types->GetMaxId(); i++)
1100 {
1101 this->FaceLocations->InsertNextValue(-1);
1102 }
1103 }
1104
1105 // Okay the faces go in
1106 this->FaceLocations->InsertNextValue(
1107 this->Faces->GetMaxId() + 1);
1108 this->Faces->InsertNextValue(nfaces);
1109
1110 for (int faceNum=0; faceNum < nfaces; ++faceNum)
1111 {
1112 npts = faces[0];
1113 this->Faces->InsertNextValue(npts);
1114 for (vtkIdType i=1; i <= npts; ++i)
1115 {
1116 this->Faces->InsertNextValue(faces[i]);
1117 }
1118 faces += npts + 1;
1119 } //for all faces
1120
1121 return this->Types->InsertNextValue(static_cast<unsigned char>(type));
1122 }
1123
1124
1125 //----------------------------------------------------------------------------
InitializeFacesRepresentation(vtkIdType numPrevCells)1126 int vtkUnstructuredGrid::InitializeFacesRepresentation(vtkIdType numPrevCells)
1127 {
1128 if (this->Faces || this->FaceLocations)
1129 {
1130 vtkErrorMacro("Face information already exist for this unstuructured grid. "
1131 "InitializeFacesRepresentation returned without execution.");
1132 return 0;
1133 }
1134
1135 this->Faces = vtkIdTypeArray::New();
1136 this->Faces->Allocate(this->Types->GetSize());
1137
1138 this->FaceLocations = vtkIdTypeArray::New();
1139 this->FaceLocations->Allocate(this->Types->GetSize());
1140 // FaceLocations must be padded until the current position
1141 for(vtkIdType i = 0; i < numPrevCells; i++)
1142 {
1143 this->FaceLocations->InsertNextValue(-1);
1144 }
1145
1146 return 1;
1147 }
1148
1149 //----------------------------------------------------------------------------
GetMeshMTime()1150 vtkMTimeType vtkUnstructuredGrid::GetMeshMTime()
1151 {
1152 return vtkMath::Max(this->Points ? this->Points->GetMTime() : 0,
1153 this->Connectivity ? this->Connectivity->GetMTime() : 0);
1154 }
1155
1156 //----------------------------------------------------------------------------
1157 // Return faces for a polyhedral cell (or face-explicit cell).
GetFaces(vtkIdType cellId)1158 vtkIdType *vtkUnstructuredGrid::GetFaces(vtkIdType cellId)
1159 {
1160 // Get the locations of the face
1161 vtkIdType loc;
1162 if ( !this->Faces ||
1163 cellId < 0 || cellId > this->FaceLocations->GetMaxId() ||
1164 (loc=this->FaceLocations->GetValue(cellId)) == -1 )
1165 {
1166 return nullptr;
1167 }
1168
1169 return this->Faces->GetPointer(loc);
1170 }
1171
1172 //----------------------------------------------------------------------------
SetCells(int type,vtkCellArray * cells)1173 void vtkUnstructuredGrid::SetCells(int type, vtkCellArray *cells)
1174 {
1175 int *types = new int [cells->GetNumberOfCells()];
1176 for (vtkIdType i = 0; i < cells->GetNumberOfCells(); i++)
1177 {
1178 types[i] = type;
1179 }
1180
1181 this->SetCells(types, cells);
1182
1183 delete [] types;
1184 }
1185
1186 //----------------------------------------------------------------------------
SetCells(int * types,vtkCellArray * cells)1187 void vtkUnstructuredGrid::SetCells(int *types, vtkCellArray *cells)
1188 {
1189 // check if cells contain any polyhedron cell
1190 vtkIdType ncells = cells->GetNumberOfCells();
1191 bool containPolyhedron = false;
1192 vtkIdType i;
1193 for (i = 0; i < ncells; i++)
1194 {
1195 if (types[i] == VTK_POLYHEDRON)
1196 {
1197 containPolyhedron = true;
1198 break; // We can terminate early
1199 }
1200 }
1201
1202 vtkIdType npts, nfaces, realnpts, *pts;
1203
1204 vtkIdTypeArray *cellLocations = vtkIdTypeArray::New();
1205 cellLocations->Allocate(ncells);
1206 vtkUnsignedCharArray *cellTypes = vtkUnsignedCharArray::New();
1207 cellTypes->Allocate(ncells);
1208
1209 if (!containPolyhedron)
1210 {
1211 // only need to build types and locations
1212 for (i=0, cells->InitTraversal(); cells->GetNextCell(npts,pts); i++)
1213 {
1214 cellTypes->InsertNextValue(static_cast<unsigned char>(types[i]));
1215 cellLocations->InsertNextValue(cells->GetTraversalLocation(npts));
1216 }
1217
1218 this->SetCells(cellTypes, cellLocations, cells, nullptr, nullptr);
1219
1220 cellTypes->Delete();
1221 cellLocations->Delete();
1222 return;
1223 }
1224
1225 // If a polyhedron cell exists, its input cellArray is of special format.
1226 // [nCell0Faces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...]
1227 // We need to convert it into new cell connectivities of standard format,
1228 // update cellLocations as well as create faces and facelocations.
1229 vtkCellArray *newCells = vtkCellArray::New();
1230 newCells->Allocate(cells->GetActualMemorySize());
1231 vtkIdTypeArray *faces = vtkIdTypeArray::New();
1232 faces->Allocate(cells->GetActualMemorySize());
1233 vtkIdTypeArray *faceLocations = vtkIdTypeArray::New();
1234 faceLocations->Allocate(ncells);
1235
1236 for (i=0, cells->InitTraversal(); cells->GetNextCell(npts,pts); i++)
1237 {
1238 cellTypes->InsertNextValue(static_cast<unsigned char>(types[i]));
1239 cellLocations->InsertNextValue(newCells->GetData()->GetMaxId()+1);
1240 if (types[i] != VTK_POLYHEDRON)
1241 {
1242 newCells->InsertNextCell(npts, pts);
1243 faceLocations->InsertNextValue(-1);
1244 }
1245 else
1246 {
1247 faceLocations->InsertNextValue(faces->GetMaxId()+1);
1248 vtkUnstructuredGrid::DecomposeAPolyhedronCell(
1249 pts, realnpts, nfaces, newCells, faces);
1250 }
1251 }
1252
1253 this->SetCells(cellTypes, cellLocations, newCells, faceLocations, faces);
1254
1255 cellTypes->Delete();
1256 cellLocations->Delete();
1257 newCells->Delete();
1258 faces->Delete();
1259 faceLocations->Delete();
1260 }
1261
1262 //----------------------------------------------------------------------------
SetCells(vtkUnsignedCharArray * cellTypes,vtkIdTypeArray * cellLocations,vtkCellArray * cells)1263 void vtkUnstructuredGrid::SetCells(vtkUnsignedCharArray *cellTypes,
1264 vtkIdTypeArray *cellLocations,
1265 vtkCellArray *cells)
1266 {
1267 // check if cells contain any polyhedron cell
1268 vtkIdType ncells = cells->GetNumberOfCells();
1269 bool containPolyhedron = false;
1270 vtkIdType i;
1271 for (i = 0; i < ncells; i++)
1272 {
1273 if (cellTypes->GetValue(i) == VTK_POLYHEDRON)
1274 {
1275 containPolyhedron = true;
1276 break; // We can terminate early
1277 }
1278 }
1279
1280 // directly set connectivity and location if there is no polyhedron
1281 if (!containPolyhedron)
1282 {
1283 this->SetCells(cellTypes, cellLocations, cells, nullptr, nullptr);
1284 return;
1285 }
1286
1287 // If a polyhedron cell exists, its input cellArray is of special format.
1288 // [nCell0Faces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...]
1289 // We need to convert it into new cell connectivities of standard format,
1290 // update cellLocations as well as create faces and facelocations.
1291 vtkCellArray *newCells = vtkCellArray::New();
1292 newCells->Allocate(cells->GetActualMemorySize());
1293 vtkIdTypeArray *newCellLocations = vtkIdTypeArray::New();
1294 newCellLocations->Allocate(ncells);
1295 vtkIdTypeArray *faces = vtkIdTypeArray::New();
1296 faces->Allocate(cells->GetActualMemorySize());
1297 vtkIdTypeArray *faceLocations = vtkIdTypeArray::New();
1298 faceLocations->Allocate(ncells);
1299
1300 vtkIdType npts, nfaces, realnpts, *pts;
1301 for (i=0, cells->InitTraversal(); cells->GetNextCell(npts,pts); i++)
1302 {
1303 newCellLocations->InsertNextValue(newCells->GetData()->GetMaxId()+1);
1304 if (cellTypes->GetValue(i) != VTK_POLYHEDRON)
1305 {
1306 newCells->InsertNextCell(npts, pts);
1307 faceLocations->InsertNextValue(-1);
1308 }
1309 else
1310 {
1311 faceLocations->InsertNextValue(faces->GetMaxId()+1);
1312 vtkUnstructuredGrid::DecomposeAPolyhedronCell(
1313 pts, realnpts, nfaces, newCells, faces);
1314 }
1315 }
1316
1317 // set the new cells
1318 this->SetCells(cellTypes, newCellLocations, newCells, faceLocations, faces);
1319
1320 newCells->Delete();
1321 newCellLocations->Delete();
1322 faces->Delete();
1323 faceLocations->Delete();
1324 }
1325
1326 //----------------------------------------------------------------------------
SetCells(vtkUnsignedCharArray * cellTypes,vtkIdTypeArray * cellLocations,vtkCellArray * cells,vtkIdTypeArray * faceLocations,vtkIdTypeArray * faces)1327 void vtkUnstructuredGrid::SetCells(vtkUnsignedCharArray *cellTypes,
1328 vtkIdTypeArray *cellLocations,
1329 vtkCellArray *cells,
1330 vtkIdTypeArray *faceLocations,
1331 vtkIdTypeArray *faces)
1332 {
1333 if ( this->Connectivity )
1334 {
1335 this->Connectivity->UnRegister(this);
1336 }
1337 this->Connectivity = cells;
1338 if ( this->Connectivity )
1339 {
1340 this->Connectivity->Register(this);
1341 }
1342
1343 if ( this->Types )
1344 {
1345 this->Types->UnRegister(this);
1346 }
1347 this->Types = cellTypes;
1348 if ( this->Types )
1349 {
1350 this->Types->Register(this);
1351 }
1352
1353 if ( this->Locations )
1354 {
1355 this->Locations->UnRegister(this);
1356 }
1357 this->Locations = cellLocations;
1358 if ( this->Locations )
1359 {
1360 this->Locations->Register(this);
1361 }
1362
1363 if ( this->Faces )
1364 {
1365 this->Faces->UnRegister(this);
1366 }
1367 this->Faces = faces;
1368 if ( this->Faces )
1369 {
1370 this->Faces->Register(this);
1371 }
1372
1373 if ( this->FaceLocations )
1374 {
1375 this->FaceLocations->UnRegister(this);
1376 }
1377 this->FaceLocations = faceLocations;
1378 if ( this->FaceLocations )
1379 {
1380 this->FaceLocations->Register(this);
1381 }
1382 }
1383
1384 //----------------------------------------------------------------------------
BuildLinks()1385 void vtkUnstructuredGrid::BuildLinks()
1386 {
1387 // Remove the old links if they are already built
1388 if (this->Links)
1389 {
1390 this->Links->UnRegister(this);
1391 }
1392
1393 this->Links = vtkCellLinks::New();
1394 this->Links->Allocate(this->GetNumberOfPoints());
1395 this->Links->Register(this);
1396 this->Links->BuildLinks(this, this->Connectivity);
1397 this->Links->Delete();
1398 }
1399
1400 //----------------------------------------------------------------------------
GetCellPoints(vtkIdType cellId,vtkIdList * ptIds)1401 void vtkUnstructuredGrid::GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
1402 {
1403 vtkIdType i, loc;
1404 vtkIdType *pts, numPts;
1405
1406 loc = this->Locations->GetValue(cellId);
1407 this->Connectivity->GetCell(loc,numPts,pts);
1408 ptIds->SetNumberOfIds(numPts);
1409 for (i=0; i<numPts; i++)
1410 {
1411 ptIds->SetId(i,pts[i]);
1412 }
1413
1414 }
1415
1416 //----------------------------------------------------------------------------
1417 // Return a pointer to a list of point ids defining cell. (More efficient than alternative
1418 // method.)
GetCellPoints(vtkIdType cellId,vtkIdType & npts,vtkIdType * & pts)1419 void vtkUnstructuredGrid::GetCellPoints(vtkIdType cellId, vtkIdType& npts,
1420 vtkIdType* &pts)
1421 {
1422 vtkIdType loc;
1423
1424 loc = this->Locations->GetValue(cellId);
1425
1426 this->Connectivity->GetCell(loc,npts,pts);
1427 }
1428
1429 //----------------------------------------------------------------------------
GetFaceStream(vtkIdType cellId,vtkIdList * ptIds)1430 void vtkUnstructuredGrid::GetFaceStream(vtkIdType cellId, vtkIdList *ptIds)
1431 {
1432 if (this->GetCellType(cellId) != VTK_POLYHEDRON)
1433 {
1434 this->GetCellPoints(cellId, ptIds);
1435 return;
1436 }
1437
1438 ptIds->Reset();
1439
1440 if (!this->Faces || !this->FaceLocations)
1441 {
1442 return;
1443 }
1444
1445 vtkIdType loc = this->FaceLocations->GetValue(cellId);
1446 vtkIdType* facePtr = this->Faces->GetPointer(loc);
1447
1448 vtkIdType nfaces = *facePtr++;
1449 ptIds->InsertNextId(nfaces);
1450 for (vtkIdType i = 0; i < nfaces; i++)
1451 {
1452 vtkIdType npts = *facePtr++;
1453 ptIds->InsertNextId(npts);
1454 for (vtkIdType j = 0; j < npts; j++)
1455 {
1456 ptIds->InsertNextId(*facePtr++);
1457 }
1458 }
1459 }
1460
1461 //----------------------------------------------------------------------------
GetFaceStream(vtkIdType cellId,vtkIdType & nfaces,vtkIdType * & ptIds)1462 void vtkUnstructuredGrid::GetFaceStream(vtkIdType cellId, vtkIdType& nfaces,
1463 vtkIdType* &ptIds)
1464 {
1465 if (this->GetCellType(cellId) != VTK_POLYHEDRON)
1466 {
1467 this->GetCellPoints(cellId, nfaces, ptIds);
1468 return;
1469 }
1470
1471 if (!this->Faces || !this->FaceLocations)
1472 {
1473 return;
1474 }
1475
1476 vtkIdType loc = this->FaceLocations->GetValue(cellId);
1477 vtkIdType* facePtr = this->Faces->GetPointer(loc);
1478
1479 nfaces = *facePtr;
1480 ptIds = facePtr+1;
1481 }
1482
1483 //----------------------------------------------------------------------------
GetPointCells(vtkIdType ptId,vtkIdList * cellIds)1484 void vtkUnstructuredGrid::GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
1485 {
1486 vtkIdType *cells;
1487 int numCells;
1488 int i;
1489
1490 if ( ! this->Links )
1491 {
1492 this->BuildLinks();
1493 }
1494 cellIds->Reset();
1495
1496 numCells = this->Links->GetNcells(ptId);
1497 cells = this->Links->GetCells(ptId);
1498
1499 cellIds->SetNumberOfIds(numCells);
1500 for (i=0; i < numCells; i++)
1501 {
1502 cellIds->SetId(i,cells[i]);
1503 }
1504 }
1505
1506 //----------------------------------------------------------------------------
NewCellIterator()1507 vtkCellIterator *vtkUnstructuredGrid::NewCellIterator()
1508 {
1509 vtkUnstructuredGridCellIterator *iter(vtkUnstructuredGridCellIterator::New());
1510 iter->SetUnstructuredGrid(this);
1511 return iter;
1512 }
1513
1514 //----------------------------------------------------------------------------
Reset()1515 void vtkUnstructuredGrid::Reset()
1516 {
1517 if ( this->Connectivity )
1518 {
1519 this->Connectivity->Reset();
1520 }
1521 if ( this->Links )
1522 {
1523 this->Links->Reset();
1524 }
1525 if ( this->Types )
1526 {
1527 this->Types->Reset();
1528 }
1529 if ( this->Locations )
1530 {
1531 this->Locations->Reset();
1532 }
1533 if ( this->Faces )
1534 {
1535 this->Faces->Reset();
1536 }
1537 if ( this->FaceLocations )
1538 {
1539 this->FaceLocations->Reset();
1540 }
1541 }
1542
1543 //----------------------------------------------------------------------------
Squeeze()1544 void vtkUnstructuredGrid::Squeeze()
1545 {
1546 if ( this->Connectivity )
1547 {
1548 this->Connectivity->Squeeze();
1549 }
1550 if ( this->Links )
1551 {
1552 this->Links->Squeeze();
1553 }
1554 if ( this->Types )
1555 {
1556 this->Types->Squeeze();
1557 }
1558 if ( this->Locations )
1559 {
1560 this->Locations->Squeeze();
1561 }
1562 if ( this->Faces )
1563 {
1564 this->Faces->Squeeze();
1565 }
1566 if ( this->FaceLocations )
1567 {
1568 this->FaceLocations->Squeeze();
1569 }
1570
1571 vtkPointSet::Squeeze();
1572 }
1573
1574 //----------------------------------------------------------------------------
1575 // Remove a reference to a cell in a particular point's link list. You may
1576 // also consider using RemoveCellReference() to remove the references from
1577 // all the cell's points to the cell. This operator does not reallocate
1578 // memory; use the operator ResizeCellList() to do this if necessary.
RemoveReferenceToCell(vtkIdType ptId,vtkIdType cellId)1579 void vtkUnstructuredGrid::RemoveReferenceToCell(vtkIdType ptId,
1580 vtkIdType cellId)
1581 {
1582 this->Links->RemoveCellReference(cellId, ptId);
1583 }
1584
1585 //----------------------------------------------------------------------------
1586 // Add a reference to a cell in a particular point's link list. (You may also
1587 // consider using AddCellReference() to add the references from all the
1588 // cell's points to the cell.) This operator does not realloc memory; use the
1589 // operator ResizeCellList() to do this if necessary.
AddReferenceToCell(vtkIdType ptId,vtkIdType cellId)1590 void vtkUnstructuredGrid::AddReferenceToCell(vtkIdType ptId, vtkIdType cellId)
1591 {
1592 this->Links->AddCellReference(cellId, ptId);
1593 }
1594
1595 //----------------------------------------------------------------------------
1596 // Resize the list of cells using a particular point. (This operator assumes
1597 // that BuildLinks() has been called.)
ResizeCellList(vtkIdType ptId,int size)1598 void vtkUnstructuredGrid::ResizeCellList(vtkIdType ptId, int size)
1599 {
1600 this->Links->ResizeCellList(ptId,size);
1601 }
1602
1603 //----------------------------------------------------------------------------
1604 // Replace the points defining cell "cellId" with a new set of points. This
1605 // operator is (typically) used when links from points to cells have not been
1606 // built (i.e., BuildLinks() has not been executed). Use the operator
1607 // ReplaceLinkedCell() to replace a cell when cell structure has been built.
InternalReplaceCell(vtkIdType cellId,int npts,const vtkIdType pts[])1608 void vtkUnstructuredGrid::InternalReplaceCell(vtkIdType cellId, int npts,
1609 const vtkIdType pts[])
1610 {
1611 vtkIdType loc;
1612
1613 loc = this->Locations->GetValue(cellId);
1614 this->Connectivity->ReplaceCell(loc,npts,pts);
1615 }
1616
1617 //----------------------------------------------------------------------------
1618 // Add a new cell to the cell data structure (after cell links have been
1619 // built). This method adds the cell and then updates the links from the points
1620 // to the cells. (Memory is allocated as necessary.)
InsertNextLinkedCell(int type,int npts,const vtkIdType pts[])1621 vtkIdType vtkUnstructuredGrid::InsertNextLinkedCell(int type, int npts,
1622 const vtkIdType pts[])
1623 {
1624 vtkIdType i, id;
1625
1626 id = this->InsertNextCell(type,npts,pts);
1627
1628 for (i=0; i<npts; i++)
1629 {
1630 this->Links->ResizeCellList(pts[i],1);
1631 this->Links->AddCellReference(id,pts[i]);
1632 }
1633
1634 return id;
1635 }
1636
1637 //----------------------------------------------------------------------------
GetActualMemorySize()1638 unsigned long vtkUnstructuredGrid::GetActualMemorySize()
1639 {
1640 unsigned long size=this->vtkPointSet::GetActualMemorySize();
1641 if ( this->Connectivity )
1642 {
1643 size += this->Connectivity->GetActualMemorySize();
1644 }
1645
1646 if ( this->Links )
1647 {
1648 size += this->Links->GetActualMemorySize();
1649 }
1650
1651 if ( this->Types )
1652 {
1653 size += this->Types->GetActualMemorySize();
1654 }
1655
1656 if ( this->Locations )
1657 {
1658 size += this->Locations->GetActualMemorySize();
1659 }
1660
1661 if ( this->Faces )
1662 {
1663 size += this->Faces->GetActualMemorySize();
1664 }
1665
1666 if ( this->FaceLocations )
1667 {
1668 size += this->FaceLocations->GetActualMemorySize();
1669 }
1670
1671 return size;
1672 }
1673
1674 //----------------------------------------------------------------------------
ShallowCopy(vtkDataObject * dataObject)1675 void vtkUnstructuredGrid::ShallowCopy(vtkDataObject *dataObject)
1676 {
1677 if (vtkUnstructuredGrid *grid = vtkUnstructuredGrid::SafeDownCast(dataObject))
1678 {
1679 // I do not know if this is correct but.
1680
1681 if (this->Connectivity)
1682 {
1683 this->Connectivity->UnRegister(this);
1684 }
1685 this->Connectivity = grid->Connectivity;
1686 if (this->Connectivity)
1687 {
1688 this->Connectivity->Register(this);
1689 }
1690
1691 if (this->Links)
1692 {
1693 this->Links->Delete();
1694 }
1695 this->Links = grid->Links;
1696 if (this->Links)
1697 {
1698 this->Links->Register(this);
1699 }
1700
1701 if (this->Types)
1702 {
1703 this->Types->UnRegister(this);
1704 }
1705 this->Types = grid->Types;
1706 if (this->Types)
1707 {
1708 this->Types->Register(this);
1709 }
1710
1711 if (this->Locations)
1712 {
1713 this->Locations->UnRegister(this);
1714 }
1715 this->Locations = grid->Locations;
1716 if (this->Locations)
1717 {
1718 this->Locations->Register(this);
1719 }
1720
1721 if (this->Faces)
1722 {
1723 this->Faces->UnRegister(this);
1724 }
1725 this->Faces = grid->Faces;
1726 if (this->Faces)
1727 {
1728 this->Faces->Register(this);
1729 }
1730
1731 if (this->FaceLocations)
1732 {
1733 this->FaceLocations->UnRegister(this);
1734 }
1735 this->FaceLocations = grid->FaceLocations;
1736 if (this->FaceLocations)
1737 {
1738 this->FaceLocations->Register(this);
1739 }
1740 }
1741 else if (vtkUnstructuredGridBase *ugb =
1742 vtkUnstructuredGridBase::SafeDownCast(dataObject))
1743 {
1744 // The source object has vtkUnstructuredGrid topology, but a different
1745 // cell implementation. Deep copy the cells, and shallow copy the rest:
1746 vtkSmartPointer<vtkCellIterator> cellIter =
1747 vtkSmartPointer<vtkCellIterator>::Take(ugb->NewCellIterator());
1748 for (cellIter->InitTraversal(); !cellIter->IsDoneWithTraversal();
1749 cellIter->GoToNextCell())
1750 {
1751 this->InsertNextCell(cellIter->GetCellType(),
1752 cellIter->GetNumberOfPoints(),
1753 cellIter->GetPointIds()->GetPointer(0),
1754 cellIter->GetNumberOfFaces(),
1755 cellIter->GetFaces()->GetPointer(1));
1756 }
1757 }
1758
1759 this->Superclass::ShallowCopy(dataObject);
1760 }
1761
1762 //----------------------------------------------------------------------------
DeepCopy(vtkDataObject * dataObject)1763 void vtkUnstructuredGrid::DeepCopy(vtkDataObject *dataObject)
1764 {
1765 vtkUnstructuredGrid *grid = vtkUnstructuredGrid::SafeDownCast(dataObject);
1766
1767 if ( grid != nullptr )
1768 {
1769 if ( this->Connectivity )
1770 {
1771 this->Connectivity->UnRegister(this);
1772 this->Connectivity = nullptr;
1773 }
1774 if (grid->Connectivity)
1775 {
1776 this->Connectivity = vtkCellArray::New();
1777 this->Connectivity->DeepCopy(grid->Connectivity);
1778 this->Connectivity->Register(this);
1779 this->Connectivity->Delete();
1780 }
1781
1782 if ( this->Links )
1783 {
1784 this->Links->UnRegister(this);
1785 this->Links = nullptr;
1786 }
1787 if ( this->Types )
1788 {
1789 this->Types->UnRegister(this);
1790 this->Types = nullptr;
1791 }
1792 if (grid->Types)
1793 {
1794 this->Types = vtkUnsignedCharArray::New();
1795 this->Types->DeepCopy(grid->Types);
1796 this->Types->Register(this);
1797 this->Types->Delete();
1798 }
1799
1800 if ( this->Locations )
1801 {
1802 this->Locations->UnRegister(this);
1803 this->Locations = nullptr;
1804 }
1805 if (grid->Locations)
1806 {
1807 this->Locations = vtkIdTypeArray::New();
1808 this->Locations->DeepCopy(grid->Locations);
1809 this->Locations->Register(this);
1810 this->Locations->Delete();
1811 }
1812
1813 if ( this->Faces )
1814 {
1815 this->Faces->UnRegister(this);
1816 this->Faces = nullptr;
1817 }
1818 if (grid->Faces)
1819 {
1820 this->Faces = vtkIdTypeArray::New();
1821 this->Faces->DeepCopy(grid->Faces);
1822 this->Faces->Register(this);
1823 this->Faces->Delete();
1824 }
1825
1826 if ( this->FaceLocations )
1827 {
1828 this->FaceLocations->UnRegister(this);
1829 this->FaceLocations = nullptr;
1830 }
1831 if (grid->FaceLocations)
1832 {
1833 this->FaceLocations = vtkIdTypeArray::New();
1834 this->FaceLocations->DeepCopy(grid->FaceLocations);
1835 this->FaceLocations->Register(this);
1836 this->FaceLocations->Delete();
1837 }
1838
1839 // Skip the unstructured grid base implementation, as it uses a less
1840 // efficient method of copying cell data.
1841 this->vtkUnstructuredGridBase::Superclass::DeepCopy(grid);
1842 }
1843 else
1844 {
1845 // Use the vtkUnstructuredGridBase deep copy implementation.
1846 this->Superclass::DeepCopy(dataObject);
1847 }
1848
1849 // Finally Build Links if we need to
1850 if (grid && grid->Links)
1851 {
1852 this->BuildLinks();
1853 }
1854 }
1855
1856
1857 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)1858 void vtkUnstructuredGrid::PrintSelf(ostream& os, vtkIndent indent)
1859 {
1860 this->Superclass::PrintSelf(os,indent);
1861
1862 os << indent << "Number Of Pieces: " << this->GetNumberOfPieces() << endl;
1863 os << indent << "Piece: " << this->GetPiece() << endl;
1864 os << indent << "Ghost Level: " << this->GetGhostLevel() << endl;
1865 }
1866
1867 //----------------------------------------------------------------------------
1868 // Determine neighbors as follows. Find the (shortest) list of cells that
1869 // uses one of the points in ptIds. For each cell, in the list, see whether
1870 // it contains the other points in the ptIds list. If so, it's a neighbor.
1871 //
GetCellNeighbors(vtkIdType cellId,vtkIdList * ptIds,vtkIdList * cellIds)1872 void vtkUnstructuredGrid::GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
1873 vtkIdList *cellIds)
1874 {
1875 if ( ! this->Links )
1876 {
1877 this->BuildLinks();
1878 }
1879
1880 cellIds->Reset();
1881
1882 vtkIdType numPts = ptIds->GetNumberOfIds();
1883 if (numPts <= 0)
1884 {
1885 vtkErrorMacro("input point ids empty.");
1886 return;
1887 }
1888
1889 //Find the point used by the fewest number of cells
1890 vtkIdType *pts = ptIds->GetPointer(0);
1891 int minNumCells = VTK_INT_MAX;
1892 vtkIdType *minCells = nullptr;
1893 vtkIdType minPtId = 0;
1894 for (vtkIdType i=0; i<numPts; i++)
1895 {
1896 vtkIdType ptId = pts[i];
1897 int numCells = this->Links->GetNcells(ptId);
1898 vtkIdType *cells = this->Links->GetCells(ptId);
1899 if ( numCells < minNumCells )
1900 {
1901 minNumCells = numCells;
1902 minCells = cells;
1903 minPtId = ptId;
1904 }
1905 }
1906
1907 //Now for each cell, see if it contains all the points
1908 //in the ptIds list.
1909 bool match;
1910 for (int i=0; i<minNumCells; i++)
1911 {
1912 if ( minCells[i] != cellId ) //don't include current cell
1913 {
1914 vtkIdType *cellPts;
1915 vtkIdType npts;
1916 this->GetCellPoints(minCells[i],npts,cellPts);
1917 match=true;
1918 for (vtkIdType j=0; j<numPts && match; j++) //for all pts in input cell
1919 {
1920 if ( pts[j] != minPtId ) //of course minPtId is contained by cell
1921 {
1922 match=false;
1923 for (vtkIdType k=0; k<npts; k++) //for all points in candidate cell
1924 {
1925 if ( pts[j] == cellPts[k] )
1926 {
1927 match = true; //a match was found
1928 break;
1929 }
1930 }//for all points in current cell
1931 }//if not guaranteed match
1932 }//for all points in input cell
1933 if ( match )
1934 {
1935 cellIds->InsertNextId(minCells[i]);
1936 }
1937 }//if not the reference cell
1938 }//for all candidate cells attached to point
1939 }
1940
1941
1942 //----------------------------------------------------------------------------
IsHomogeneous()1943 int vtkUnstructuredGrid::IsHomogeneous()
1944 {
1945 unsigned char type;
1946 if (this->Types && this->Types->GetMaxId() >= 0)
1947 {
1948 type = Types->GetValue(0);
1949 for (int cellId = 0; cellId < this->GetNumberOfCells(); cellId++)
1950 {
1951 if (this->Types->GetValue(cellId) != type)
1952 {
1953 return 0;
1954 }
1955 }
1956 return 1;
1957 }
1958 return 0;
1959 }
1960
1961 //----------------------------------------------------------------------------
1962 // Fill container with indices of cells which match given type.
GetIdsOfCellsOfType(int type,vtkIdTypeArray * array)1963 void vtkUnstructuredGrid::GetIdsOfCellsOfType(int type, vtkIdTypeArray *array)
1964 {
1965 for (int cellId = 0; cellId < this->GetNumberOfCells(); cellId++)
1966 {
1967 if (static_cast<int>(Types->GetValue(cellId)) == type)
1968 {
1969 array->InsertNextValue(cellId);
1970 }
1971 }
1972 }
1973
1974
1975 //----------------------------------------------------------------------------
RemoveGhostCells()1976 void vtkUnstructuredGrid::RemoveGhostCells()
1977 {
1978 vtkUnstructuredGrid* newGrid = vtkUnstructuredGrid::New();
1979 vtkUnsignedCharArray* temp;
1980 unsigned char* cellGhosts;
1981
1982 vtkIdType cellId, newCellId;
1983 vtkIdList *cellPts, *pointMap;
1984 vtkIdList *newCellPts;
1985 vtkCell *cell;
1986 vtkPoints *newPoints;
1987 vtkIdType i, ptId, newId, numPts;
1988 vtkIdType numCellPts;
1989 double *x;
1990 vtkPointData* pd = this->GetPointData();
1991 vtkPointData* outPD = newGrid->GetPointData();
1992 vtkCellData* cd = this->GetCellData();
1993 vtkCellData* outCD = newGrid->GetCellData();
1994
1995
1996 // Get a pointer to the cell ghost array.
1997 temp = this->GetCellGhostArray();
1998 if (temp == nullptr)
1999 {
2000 vtkDebugMacro("Could not find cell ghost array.");
2001 newGrid->Delete();
2002 return;
2003 }
2004 if ((temp->GetNumberOfComponents() != 1)
2005 || (temp->GetNumberOfTuples() < this->GetNumberOfCells()))
2006 {
2007 vtkErrorMacro("Poorly formed ghost array.");
2008 newGrid->Delete();
2009 return;
2010 }
2011 cellGhosts = temp->GetPointer(0);
2012
2013
2014 // Now threshold based on the cell ghost array.
2015
2016 // ensure that all attributes are copied over, including global ids.
2017 outPD->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
2018 outCD->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
2019
2020 outPD->CopyAllocate(pd);
2021 outCD->CopyAllocate(cd);
2022
2023 numPts = this->GetNumberOfPoints();
2024 newGrid->Allocate(this->GetNumberOfCells());
2025 newPoints = vtkPoints::New();
2026 newPoints->SetDataType(this->GetPoints()->GetDataType());
2027 newPoints->Allocate(numPts);
2028
2029 pointMap = vtkIdList::New(); //maps old point ids into new
2030 pointMap->SetNumberOfIds(numPts);
2031 for (i=0; i < numPts; i++)
2032 {
2033 pointMap->SetId(i,-1);
2034 }
2035
2036
2037 newCellPts = vtkIdList::New();
2038
2039 // Check that the scalars of each cell satisfy the threshold criterion
2040 for (cellId=0; cellId < this->GetNumberOfCells(); cellId++)
2041 {
2042 cell = this->GetCell(cellId);
2043 cellPts = cell->GetPointIds();
2044 numCellPts = cell->GetNumberOfPoints();
2045
2046 if ( (cellGhosts[cellId] & vtkDataSetAttributes::DUPLICATECELL) == 0 ) // Keep the cell.
2047 {
2048 for (i=0; i < numCellPts; i++)
2049 {
2050 ptId = cellPts->GetId(i);
2051 if ( (newId = pointMap->GetId(ptId)) < 0 )
2052 {
2053 x = this->GetPoint(ptId);
2054 newId = newPoints->InsertNextPoint(x);
2055 pointMap->SetId(ptId,newId);
2056 outPD->CopyData(pd,ptId,newId);
2057 }
2058 newCellPts->InsertId(i,newId);
2059 }
2060 newCellId = newGrid->InsertNextCell(cell->GetCellType(),newCellPts);
2061 outCD->CopyData(cd,cellId,newCellId);
2062 newCellPts->Reset();
2063 } // satisfied thresholding
2064 } // for all cells
2065
2066 // now clean up / update ourselves
2067 pointMap->Delete();
2068 newCellPts->Delete();
2069
2070 newGrid->SetPoints(newPoints);
2071 newPoints->Delete();
2072
2073 this->CopyStructure(newGrid);
2074 this->GetPointData()->ShallowCopy(newGrid->GetPointData());
2075 this->GetCellData()->ShallowCopy(newGrid->GetCellData());
2076 newGrid->Delete();
2077 newGrid = nullptr;
2078
2079 this->Squeeze();
2080 }
2081
2082 //----------------------------------------------------------------------------
DecomposeAPolyhedronCell(vtkCellArray * polyhedronCell,vtkIdType & numCellPts,vtkIdType & nCellfaces,vtkCellArray * cellArray,vtkIdTypeArray * faces)2083 void vtkUnstructuredGrid::DecomposeAPolyhedronCell(vtkCellArray * polyhedronCell,
2084 vtkIdType & numCellPts, vtkIdType & nCellfaces,
2085 vtkCellArray * cellArray, vtkIdTypeArray * faces)
2086 {
2087 vtkIdType *cellStream = nullptr;
2088 vtkIdType cellLength = 0;
2089
2090 polyhedronCell->InitTraversal();
2091 polyhedronCell->GetNextCell(cellLength, cellStream);
2092
2093 vtkUnstructuredGrid::DecomposeAPolyhedronCell(
2094 cellStream, numCellPts, nCellfaces, cellArray, faces);
2095 }
2096
2097 //----------------------------------------------------------------------------
DecomposeAPolyhedronCell(vtkIdType * cellStream,vtkIdType & numCellPts,vtkIdType & nCellFaces,vtkCellArray * cellArray,vtkIdTypeArray * faces)2098 void vtkUnstructuredGrid::DecomposeAPolyhedronCell(vtkIdType *cellStream,
2099 vtkIdType & numCellPts, vtkIdType & nCellFaces,
2100 vtkCellArray * cellArray, vtkIdTypeArray * faces)
2101 {
2102 nCellFaces = cellStream[0];
2103 if (nCellFaces <= 0)
2104 {
2105 return;
2106 }
2107
2108 vtkUnstructuredGrid::DecomposeAPolyhedronCell(
2109 nCellFaces, cellStream+1, numCellPts, cellArray, faces);
2110 }
2111
2112 //----------------------------------------------------------------------------
DecomposeAPolyhedronCell(vtkIdType nCellFaces,const vtkIdType cellStream[],vtkIdType & numCellPts,vtkCellArray * cellArray,vtkIdTypeArray * faces)2113 void vtkUnstructuredGrid::DecomposeAPolyhedronCell(vtkIdType nCellFaces,
2114 const vtkIdType cellStream[], vtkIdType & numCellPts,
2115 vtkCellArray * cellArray, vtkIdTypeArray * faces)
2116 {
2117 std::set<vtkIdType> cellPointSet;
2118 std::set<vtkIdType>::iterator it;
2119
2120 // insert number of faces into the face array
2121 faces->InsertNextValue(nCellFaces);
2122
2123 // for each face
2124 for (vtkIdType fid = 0; fid < nCellFaces; fid++)
2125 {
2126 // extract all points on the same face, store them into a set
2127 vtkIdType npts = *cellStream++;
2128 faces->InsertNextValue(npts);
2129 for (vtkIdType i = 0; i < npts; i++)
2130 {
2131 vtkIdType pid = *cellStream++;
2132 faces->InsertNextValue(pid);
2133 cellPointSet.insert(pid);
2134 }
2135 }
2136
2137 // standard cell connectivity array that stores the number of points plus
2138 // a list of point ids.
2139 cellArray->InsertNextCell(static_cast<int>(cellPointSet.size()));
2140 for (it = cellPointSet.begin(); it != cellPointSet.end(); ++it)
2141 {
2142 cellArray->InsertCellPoint(*it);
2143 }
2144
2145 // the real number of points in the polyhedron cell.
2146 numCellPts = static_cast<vtkIdType>(cellPointSet.size());
2147 }
2148
2149 //----------------------------------------------------------------------------
ConvertFaceStreamPointIds(vtkIdList * faceStream,vtkIdType * idMap)2150 void vtkUnstructuredGrid::ConvertFaceStreamPointIds(vtkIdList * faceStream,
2151 vtkIdType * idMap)
2152 {
2153 vtkIdType* idPtr = faceStream->GetPointer(0);
2154 vtkIdType nfaces = *idPtr++;
2155 for (vtkIdType i = 0; i < nfaces; i++)
2156 {
2157 vtkIdType npts = *idPtr++;
2158 for (vtkIdType j = 0; j < npts; j++)
2159 {
2160 *idPtr = idMap[*idPtr];
2161 idPtr++;
2162 }
2163 }
2164 }
2165
2166 //----------------------------------------------------------------------------
ConvertFaceStreamPointIds(vtkIdType nfaces,vtkIdType * faceStream,vtkIdType * idMap)2167 void vtkUnstructuredGrid::ConvertFaceStreamPointIds(vtkIdType nfaces,
2168 vtkIdType * faceStream,
2169 vtkIdType * idMap)
2170 {
2171 vtkIdType* idPtr = faceStream;
2172 for (vtkIdType i = 0; i < nfaces; i++)
2173 {
2174 vtkIdType npts = *idPtr++;
2175 for (vtkIdType j = 0; j < npts; j++)
2176 {
2177 *idPtr = idMap[*idPtr];
2178 idPtr++;
2179 }
2180 }
2181 }
2182
2183 //----------------------------------------------------------------------------
GetData(vtkInformation * info)2184 vtkUnstructuredGrid* vtkUnstructuredGrid::GetData(vtkInformation* info)
2185 {
2186 return info? vtkUnstructuredGrid::SafeDownCast(info->Get(DATA_OBJECT())) : nullptr;
2187 }
2188
2189 //----------------------------------------------------------------------------
GetData(vtkInformationVector * v,int i)2190 vtkUnstructuredGrid* vtkUnstructuredGrid::GetData(vtkInformationVector* v,
2191 int i)
2192 {
2193 return vtkUnstructuredGrid::GetData(v->GetInformationObject(i));
2194 }
2195