Salome HOME
c9f40a734dd00ac6d5490479762214f21dc7d7a6
[modules/gui.git] / src / VTKViewer / VTKViewer_GeometryFilter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME OBJECT : kernel of SALOME component
23 //  File   : VTKViewer_GeometryFilter.cxx
24 //  Author : Michael ZORIN
25 //  Module : SALOME
26 //  $Header$ 
27 //
28 #include "VTKViewer_GeometryFilter.h"
29 #include "VTKViewer_ConvexTool.h"
30
31 #include <vtkSmartPointer.h>
32 #include <vtkCellArray.h>
33 #include <vtkCellData.h>
34 #include <vtkGenericCell.h>
35 #include <vtkHexahedron.h>
36 #include <vtkMergePoints.h>
37 #include <vtkObjectFactory.h>
38 #include <vtkPointData.h>
39 #include <vtkPolyData.h>
40 #include <vtkPyramid.h>
41 #include <vtkStructuredGrid.h>
42 #include <vtkTetra.h>
43 #include <vtkUnsignedCharArray.h>
44 #include <vtkUnstructuredGrid.h>
45 #include <vtkVoxel.h>
46 #include <vtkWedge.h>
47 #include <vtkInformationVector.h>
48 #include <vtkInformation.h>
49
50 #include <algorithm>
51 #include <iterator>
52 #include <vector>
53 #include <map>
54 #include <set>
55
56 #if defined __GNUC__
57   #if __GNUC__ == 2
58     #define __GNUC_2__
59   #endif
60 #endif
61
62 //#define USE_ROBUST_TRIANGULATION
63
64 vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision$");
65 vtkStandardNewMacro(VTKViewer_GeometryFilter);
66
67 VTKViewer_GeometryFilter
68 ::VTKViewer_GeometryFilter(): 
69   myShowInside(0),
70   myStoreMapping(0),
71   myIsWireframeMode(0)
72 {}
73
74
75 VTKViewer_GeometryFilter
76 ::~VTKViewer_GeometryFilter()
77 {}
78
79
80 int
81 VTKViewer_GeometryFilter
82 ::RequestData(
83   vtkInformation *request,
84   vtkInformationVector **inputVector,
85   vtkInformationVector *outputVector)
86 {
87   // get the info objects
88   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
89   vtkInformation *outInfo = outputVector->GetInformationObject(0);
90
91   // get the input and ouptut
92   vtkDataSet *input = vtkDataSet::SafeDownCast(
93     inInfo->Get(vtkDataObject::DATA_OBJECT()));
94   vtkPolyData *output = vtkPolyData::SafeDownCast(
95     outInfo->Get(vtkDataObject::DATA_OBJECT()));
96
97   vtkIdType numCells=input->GetNumberOfCells();
98
99   if (numCells == 0)
100     {
101       return 0;
102     }
103   
104   if (input->GetDataObjectType() == VTK_UNSTRUCTURED_GRID){
105     return this->UnstructuredGridExecute(input, output, outInfo);
106   }else
107     return Superclass::RequestData(request,inputVector,outputVector);
108
109   return 1;
110 }
111
112
113 int
114 VTKViewer_GeometryFilter
115 ::UnstructuredGridExecute(
116                           vtkDataSet *dataSetInput,
117                           vtkPolyData *output,
118                           vtkInformation *outInfo)
119 {
120   
121   vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)dataSetInput;
122   vtkCellArray *Connectivity = input->GetCells();
123   // Check input
124   if ( Connectivity == NULL )
125     {
126     vtkDebugMacro(<<"Nothing to extract");
127     return 0;
128     }
129
130   vtkIdType cellId;
131   int i;
132   int allVisible;
133   vtkIdType npts = 0;
134   vtkIdType *pts = 0;
135   vtkPoints *p = input->GetPoints();
136   vtkIdType numCells=input->GetNumberOfCells();
137   vtkPointData *pd = input->GetPointData();
138   vtkCellData *cd = input->GetCellData();
139   vtkPointData *outputPD = output->GetPointData();
140   
141   VTKViewer_OrderedTriangulator anOrderedTriangulator;
142   VTKViewer_DelaunayTriangulator aDelaunayTriangulator;
143
144   vtkCellData *outputCD = output->GetCellData();
145   vtkGenericCell *cell = vtkGenericCell::New();
146
147   vtkIdList *cellIds = vtkIdList::New();
148   vtkIdList *faceIds = vtkIdList::New();
149
150   char *cellVis;
151   vtkIdType newCellId;
152   int faceId, *faceVerts, numFacePts;
153   vtkFloatingPointType *x;
154   vtkIdType PixelConvert[4];
155   // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
156   // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
157   vtkIdType aNewPts[VTK_CELL_SIZE];
158   // ghost cell stuff
159   unsigned char  updateLevel = (unsigned char)(output->GetUpdateGhostLevel());
160   unsigned char  *cellGhostLevels = 0;  
161   
162   PixelConvert[0] = 0;
163   PixelConvert[1] = 1;
164   PixelConvert[2] = 3;
165   PixelConvert[3] = 2;
166   
167   vtkDebugMacro(<<"Executing geometry filter for unstructured grid input");
168
169   vtkDataArray* temp = 0;
170   if (cd)
171     {
172     temp = cd->GetArray("vtkGhostLevels");
173     }
174   if ( (!temp) || (temp->GetDataType() != VTK_UNSIGNED_CHAR)
175     || (temp->GetNumberOfComponents() != 1))
176     {
177     vtkDebugMacro("No appropriate ghost levels field available.");
178     }
179   else
180     {
181     cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0);
182     }
183   
184   // Determine nature of what we have to do
185   if ( (!this->CellClipping) && (!this->PointClipping) &&
186        (!this->ExtentClipping) )
187     {
188     allVisible = 1;
189     cellVis = NULL;
190     }
191   else
192     {
193     allVisible = 0;
194     cellVis = new char[numCells];
195     }
196
197   // Just pass points through, never merge
198   output->SetPoints(input->GetPoints());
199   outputPD->PassData(pd);
200
201   outputCD->CopyAllocate(cd,numCells,numCells/2);
202
203   output->Allocate(numCells/4+1,numCells);
204   
205   // Loop over the cells determining what's visible
206   if (!allVisible)
207     {
208     for (cellId=0, Connectivity->InitTraversal(); 
209          Connectivity->GetNextCell(npts,pts); 
210          cellId++)
211       {
212       cellVis[cellId] = 1;
213       if ( this->CellClipping && cellId < this->CellMinimum ||
214            cellId > this->CellMaximum )
215         {
216         cellVis[cellId] = 0;
217         }
218       else
219         {
220         for (i=0; i < npts; i++) 
221           {
222           x = p->GetPoint(pts[i]);
223           if ( (this->PointClipping && (pts[i] < this->PointMinimum ||
224                                         pts[i] > this->PointMaximum) ) ||
225                (this->ExtentClipping && 
226                 (x[0] < this->Extent[0] || x[0] > this->Extent[1] ||
227                  x[1] < this->Extent[2] || x[1] > this->Extent[3] ||
228                  x[2] < this->Extent[4] || x[2] > this->Extent[5] )) )
229             {
230             cellVis[cellId] = 0;
231             break;
232             }//point/extent clipping
233           }//for each point
234         }//if point clipping needs checking
235       }//for all cells
236     }//if not all visible
237   
238   // Loop over all cells now that visibility is known
239   // (Have to compute visibility first for 3D cell boundarys)
240   int progressInterval = numCells/20 + 1;
241   if(myStoreMapping){
242     myVTK2ObjIds.clear();
243     myVTK2ObjIds.reserve(numCells);
244   }
245   for (cellId=0, Connectivity->InitTraversal(); 
246        Connectivity->GetNextCell(npts,pts); 
247        cellId++)
248     {
249     //Progress and abort method support
250     if ( !(cellId % progressInterval) )
251       {
252       vtkDebugMacro(<<"Process cell #" << cellId);
253       this->UpdateProgress ((float)cellId/numCells);
254       }
255
256     // Handle ghost cells here.  Another option was used cellVis array.
257     if (cellGhostLevels && cellGhostLevels[cellId] > updateLevel)
258       { // Do not create surfaces in outer ghost cells.
259       continue;
260       }
261     
262     if (allVisible || cellVis[cellId])  //now if visible extract geometry
263       {
264       //special code for nonlinear cells - rarely occurs, so right now it
265       //is slow.
266       vtkIdType aCellType = input->GetCellType(cellId);
267       switch (aCellType)
268         {
269         case VTK_EMPTY_CELL:
270           break;
271
272         case VTK_VERTEX:
273         case VTK_POLY_VERTEX:
274           newCellId = output->InsertNextCell(aCellType,npts,pts);
275           if(myStoreMapping){
276             myVTK2ObjIds.push_back(cellId); //apo
277           }
278           outputCD->CopyData(cd,cellId,newCellId);
279           break;
280
281         case VTK_LINE: 
282         case VTK_POLY_LINE:
283           newCellId = output->InsertNextCell(aCellType,npts,pts);
284           if(myStoreMapping)
285             myVTK2ObjIds.push_back(cellId);
286           outputCD->CopyData(cd,cellId,newCellId);
287           break;
288
289         case VTK_TRIANGLE:
290         case VTK_QUAD:
291         case VTK_POLYGON:
292           newCellId = output->InsertNextCell(aCellType,npts,pts);
293           if(myStoreMapping)
294             myVTK2ObjIds.push_back(cellId);
295           outputCD->CopyData(cd,cellId,newCellId);
296           break;
297
298         case VTK_TRIANGLE_STRIP:
299           newCellId = output->InsertNextCell(aCellType,npts,pts);
300           if(myStoreMapping)
301             myVTK2ObjIds.push_back(cellId);
302           outputCD->CopyData(cd,cellId,newCellId);
303           break;
304
305         case VTK_PIXEL:
306           newCellId = output->InsertNextCell(aCellType,npts,pts);
307           if(myStoreMapping)
308             myVTK2ObjIds.push_back(cellId);
309           outputCD->CopyData(cd,cellId,newCellId);
310           break;
311           
312         case VTK_CONVEX_POINT_SET: {
313           bool anIsOk = anOrderedTriangulator.Execute(input,
314                                                       cd,
315                                                       cellId,
316                                                       myShowInside,
317                                                       allVisible,
318                                                       cellVis,
319                                                       output,
320                                                       outputCD,
321                                                       myStoreMapping,
322                                                       myVTK2ObjIds,
323                                                       true);
324           if(!anIsOk)
325             aDelaunayTriangulator.Execute(input,
326                                           cd,
327                                           cellId,
328                                           myShowInside,
329                                           allVisible,
330                                           cellVis,
331                                           output,
332                                           outputCD,
333                                           myStoreMapping,
334                                           myVTK2ObjIds,
335                                           false);
336               
337           break;
338         }
339         case VTK_TETRA: {
340           for (faceId = 0; faceId < 4; faceId++)
341             {
342             faceIds->Reset();
343             faceVerts = vtkTetra::GetFaceArray(faceId);
344             faceIds->InsertNextId(pts[faceVerts[0]]);
345             faceIds->InsertNextId(pts[faceVerts[1]]);
346             faceIds->InsertNextId(pts[faceVerts[2]]);
347             aCellType = VTK_TRIANGLE;
348             numFacePts = 3;
349             input->GetCellNeighbors(cellId, faceIds, cellIds);
350             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ||
351                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
352               {
353               for ( i=0; i < numFacePts; i++)
354                 aNewPts[i] = pts[faceVerts[i]];
355               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
356               if(myStoreMapping)
357                 myVTK2ObjIds.push_back(cellId);
358               outputCD->CopyData(cd,cellId,newCellId);
359               }
360             }
361           break;
362         }
363         case VTK_VOXEL: {
364           for (faceId = 0; faceId < 6; faceId++)
365             {
366             faceIds->Reset();
367             faceVerts = vtkVoxel::GetFaceArray(faceId);
368             faceIds->InsertNextId(pts[faceVerts[0]]);
369             faceIds->InsertNextId(pts[faceVerts[1]]);
370             faceIds->InsertNextId(pts[faceVerts[2]]);
371             faceIds->InsertNextId(pts[faceVerts[3]]);
372             aCellType = VTK_QUAD;
373             numFacePts = 4;
374             input->GetCellNeighbors(cellId, faceIds, cellIds);
375             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
376                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
377               {
378               for ( i=0; i < numFacePts; i++)
379                 aNewPts[i] = pts[faceVerts[PixelConvert[i]]];
380               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
381               if(myStoreMapping)
382                 myVTK2ObjIds.push_back(cellId);
383               outputCD->CopyData(cd,cellId,newCellId);
384               }
385             }
386           break;
387         }
388         case VTK_HEXAHEDRON: {
389           for (faceId = 0; faceId < 6; faceId++)
390             {
391             faceIds->Reset();
392             faceVerts = vtkHexahedron::GetFaceArray(faceId);
393             faceIds->InsertNextId(pts[faceVerts[0]]);
394             faceIds->InsertNextId(pts[faceVerts[1]]);
395             faceIds->InsertNextId(pts[faceVerts[2]]);
396             faceIds->InsertNextId(pts[faceVerts[3]]);
397             aCellType = VTK_QUAD;
398             numFacePts = 4;
399             input->GetCellNeighbors(cellId, faceIds, cellIds);
400             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ||
401                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
402               {
403               for ( i=0; i < numFacePts; i++)
404                 aNewPts[i] = pts[faceVerts[i]];
405               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
406               if(myStoreMapping)
407                 myVTK2ObjIds.push_back(cellId);
408               outputCD->CopyData(cd,cellId,newCellId);
409               }
410             }
411           break;
412         }
413         case VTK_WEDGE: {
414           for (faceId = 0; faceId < 5; faceId++)
415             {
416             faceIds->Reset();
417             faceVerts = vtkWedge::GetFaceArray(faceId);
418             faceIds->InsertNextId(pts[faceVerts[0]]);
419             faceIds->InsertNextId(pts[faceVerts[1]]);
420             faceIds->InsertNextId(pts[faceVerts[2]]);
421             aCellType = VTK_TRIANGLE;
422             numFacePts = 3;
423             if (faceVerts[3] >= 0)
424               {
425               faceIds->InsertNextId(pts[faceVerts[3]]);
426               aCellType = VTK_QUAD;
427               numFacePts = 4;
428               }
429             input->GetCellNeighbors(cellId, faceIds, cellIds);
430             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
431                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
432               {
433               for ( i=0; i < numFacePts; i++)
434                 aNewPts[i] = pts[faceVerts[i]];
435               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
436               if(myStoreMapping)
437                 myVTK2ObjIds.push_back(cellId);
438               outputCD->CopyData(cd,cellId,newCellId);
439               }
440             }
441           break;
442         }
443         case VTK_PYRAMID: {
444           for (faceId = 0; faceId < 5; faceId++)
445             {
446             faceIds->Reset();
447             faceVerts = vtkPyramid::GetFaceArray(faceId);
448             faceIds->InsertNextId(pts[faceVerts[0]]);
449             faceIds->InsertNextId(pts[faceVerts[1]]);
450             faceIds->InsertNextId(pts[faceVerts[2]]);
451             aCellType = VTK_TRIANGLE;
452             numFacePts = 3;
453             if (faceVerts[3] >= 0)
454               {
455               faceIds->InsertNextId(pts[faceVerts[3]]);
456               aCellType = VTK_QUAD;
457               numFacePts = 4;
458               }
459             input->GetCellNeighbors(cellId, faceIds, cellIds);
460             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
461                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
462               {
463               for ( i=0; i < numFacePts; i++)
464                 aNewPts[i] = pts[faceVerts[i]];
465               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
466               if(myStoreMapping)
467                 myVTK2ObjIds.push_back(cellId);
468               outputCD->CopyData(cd,cellId,newCellId);
469               }
470             }
471           break;
472         }
473         //Quadratic cells
474         case VTK_QUADRATIC_EDGE:
475         case VTK_QUADRATIC_TRIANGLE:
476         case VTK_QUADRATIC_QUAD:
477         case VTK_QUADRATIC_TETRA:
478         case VTK_QUADRATIC_HEXAHEDRON:
479         case VTK_QUADRATIC_WEDGE:
480         case VTK_QUADRATIC_PYRAMID:
481           if(!myIsWireframeMode){
482             input->GetCell(cellId,cell);
483             vtkIdList *pts = vtkIdList::New();  
484             vtkPoints *coords = vtkPoints::New();
485             vtkIdList *cellIds = vtkIdList::New();
486             vtkIdType newCellId;
487             
488             if ( cell->GetCellDimension() == 1 ) {
489               aCellType = VTK_LINE;
490               numFacePts = 2;
491               cell->Triangulate(0,pts,coords);
492               for (i=0; i < pts->GetNumberOfIds(); i+=2) {
493                 aNewPts[0] = pts->GetId(i);
494                 aNewPts[1] = pts->GetId(i+1);
495                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
496                 if(myStoreMapping)
497                   myVTK2ObjIds.push_back(cellId);
498                 outputCD->CopyData(cd,cellId,newCellId);
499               }
500             }
501             else if ( cell->GetCellDimension() == 2 ) {
502               aCellType = VTK_TRIANGLE;
503               numFacePts = 3;
504               cell->Triangulate(0,pts,coords);
505               for (i=0; i < pts->GetNumberOfIds(); i+=3) {
506                 aNewPts[0] = pts->GetId(i);
507                 aNewPts[1] = pts->GetId(i+1);
508                 aNewPts[2] = pts->GetId(i+2);
509                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
510                 if(myStoreMapping)
511                   myVTK2ObjIds.push_back(cellId);
512                 outputCD->CopyData(cd,cellId,newCellId);
513               }
514             } 
515             else //3D nonlinear cell
516             {
517               aCellType = VTK_TRIANGLE;
518               numFacePts = 3;
519               for (int j=0; j < cell->GetNumberOfFaces(); j++){
520                 vtkCell *face = cell->GetFace(j);
521                 input->GetCellNeighbors(cellId, face->PointIds, cellIds);
522                 if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ) {
523                   face->Triangulate(0,pts,coords);
524                   for (i=0; i < pts->GetNumberOfIds(); i+=3) {
525                     aNewPts[0] = pts->GetId(i);
526                     aNewPts[1] = pts->GetId(i+1);
527                     aNewPts[2] = pts->GetId(i+2);
528                     newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
529                     if(myStoreMapping)
530                       myVTK2ObjIds.push_back(cellId);
531                     outputCD->CopyData(cd,cellId,newCellId);
532                   }
533                 }
534               }
535             } //3d cell
536             cellIds->Delete();
537             coords->Delete();
538             pts->Delete();
539             break;
540           }else{
541             switch(aCellType){
542             case VTK_QUADRATIC_EDGE: {
543               aCellType = VTK_POLY_LINE;
544               numFacePts = 3;
545               
546               aNewPts[0] = pts[0];
547               aNewPts[2] = pts[1];
548               aNewPts[1] = pts[2];
549               
550               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
551               if(myStoreMapping)
552                 myVTK2ObjIds.push_back(cellId);
553               
554               outputCD->CopyData(cd,cellId,newCellId);
555               break;
556             }
557             case VTK_QUADRATIC_TRIANGLE: {
558               aCellType = VTK_POLYGON;
559               numFacePts = 6;
560               
561               aNewPts[0] = pts[0];
562               aNewPts[1] = pts[3];
563               aNewPts[2] = pts[1];
564               aNewPts[3] = pts[4];
565               aNewPts[4] = pts[2];
566               aNewPts[5] = pts[5];
567               
568               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
569               if(myStoreMapping)
570                 myVTK2ObjIds.push_back(cellId);
571               
572               outputCD->CopyData(cd,cellId,newCellId);
573               break;
574             }
575             case VTK_QUADRATIC_QUAD: {
576               aCellType = VTK_POLYGON;
577               numFacePts = 8;
578               
579               aNewPts[0] = pts[0];
580               aNewPts[1] = pts[4];
581               aNewPts[2] = pts[1];
582               aNewPts[3] = pts[5];
583               aNewPts[4] = pts[2];
584               aNewPts[5] = pts[6];
585               aNewPts[6] = pts[3];
586               aNewPts[7] = pts[7];
587               
588               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
589               if(myStoreMapping)
590                 myVTK2ObjIds.push_back(cellId);
591               
592               outputCD->CopyData(cd,cellId,newCellId);
593               break;
594             }
595             case VTK_QUADRATIC_TETRA: {
596               aCellType = VTK_POLYGON;
597               numFacePts = 6;
598               
599               //---------------------------------------------------------------
600               aNewPts[0] = pts[0];
601               aNewPts[1] = pts[4];
602               aNewPts[2] = pts[1];
603               aNewPts[3] = pts[5];
604               aNewPts[4] = pts[2];
605               aNewPts[5] = pts[6];
606               
607               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
608               if(myStoreMapping)
609                 myVTK2ObjIds.push_back(cellId);
610               
611               outputCD->CopyData(cd,cellId,newCellId);
612
613               //---------------------------------------------------------------
614               aNewPts[0] = pts[0];
615               aNewPts[1] = pts[7];
616               aNewPts[2] = pts[3];
617               aNewPts[3] = pts[8];
618               aNewPts[4] = pts[1];
619               aNewPts[5] = pts[4];
620               
621               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
622               if(myStoreMapping)
623                 myVTK2ObjIds.push_back(cellId);
624               
625               outputCD->CopyData(cd,cellId,newCellId);
626
627               //---------------------------------------------------------------
628               aNewPts[0] = pts[1];
629               aNewPts[1] = pts[8];
630               aNewPts[2] = pts[3];
631               aNewPts[3] = pts[9];
632               aNewPts[4] = pts[2];
633               aNewPts[5] = pts[5];
634               
635               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
636               if(myStoreMapping)
637                 myVTK2ObjIds.push_back(cellId);
638               
639               outputCD->CopyData(cd,cellId,newCellId);
640
641               //---------------------------------------------------------------
642               aNewPts[0] = pts[2];
643               aNewPts[1] = pts[9];
644               aNewPts[2] = pts[3];
645               aNewPts[3] = pts[7];
646               aNewPts[4] = pts[0];
647               aNewPts[5] = pts[6];
648               
649               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
650               if(myStoreMapping)
651                 myVTK2ObjIds.push_back(cellId);
652               
653               outputCD->CopyData(cd,cellId,newCellId);
654
655               break;
656             }
657             case VTK_QUADRATIC_WEDGE: {
658               aCellType = VTK_POLYGON;
659               numFacePts = 6;
660               //---------------------------------------------------------------
661               //Face 1
662               aNewPts[0] = pts[0];
663               aNewPts[1] = pts[6];
664               aNewPts[2] = pts[1];
665               aNewPts[3] = pts[7];
666               aNewPts[4] = pts[2];
667               aNewPts[5] = pts[8];
668               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
669               if(myStoreMapping)
670                 myVTK2ObjIds.push_back(cellId);
671               outputCD->CopyData(cd,cellId,newCellId);
672               
673               //---------------------------------------------------------------
674               //Face 2
675               aNewPts[0] = pts[3];
676               aNewPts[1] = pts[9];
677               aNewPts[2] = pts[4];
678               aNewPts[3] = pts[10];
679               aNewPts[4] = pts[5];
680               aNewPts[5] = pts[11];
681               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
682               if(myStoreMapping)
683                 myVTK2ObjIds.push_back(cellId);
684               outputCD->CopyData(cd,cellId,newCellId);
685               
686               //---------------------------------------------------------------
687               //Face 3
688               numFacePts = 8;
689               aNewPts[0] = pts[0];
690               aNewPts[1] = pts[8];
691               aNewPts[2] = pts[2];
692               aNewPts[3] = pts[14];
693               aNewPts[4] = pts[5];
694               aNewPts[5] = pts[11];
695               aNewPts[6] = pts[3];
696               aNewPts[7] = pts[12];
697               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
698               if(myStoreMapping)
699                 myVTK2ObjIds.push_back(cellId);
700               outputCD->CopyData(cd,cellId,newCellId);
701
702               //---------------------------------------------------------------
703               //Face 4
704               aNewPts[0] = pts[1];
705               aNewPts[1] = pts[13];
706               aNewPts[2] = pts[4];
707               aNewPts[3] = pts[10];
708               aNewPts[4] = pts[5];
709               aNewPts[5] = pts[14];
710               aNewPts[6] = pts[2];
711               aNewPts[7] = pts[7];
712               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
713               if(myStoreMapping)
714                 myVTK2ObjIds.push_back(cellId);
715               outputCD->CopyData(cd,cellId,newCellId);
716
717               //---------------------------------------------------------------
718               //Face 5
719               aNewPts[0] = pts[0];
720               aNewPts[1] = pts[12];
721               aNewPts[2] = pts[3];
722               aNewPts[3] = pts[9];
723               aNewPts[4] = pts[4];
724               aNewPts[5] = pts[13];
725               aNewPts[6] = pts[1];
726               aNewPts[7] = pts[6];
727               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
728               if(myStoreMapping)
729                 myVTK2ObjIds.push_back(cellId);
730               outputCD->CopyData(cd,cellId,newCellId);
731               break;
732             }
733             case VTK_QUADRATIC_HEXAHEDRON: {
734               aCellType = VTK_POLYGON;
735               numFacePts = 8;
736               
737               //---------------------------------------------------------------
738               aNewPts[0] = pts[0];
739               aNewPts[1] = pts[8];
740               aNewPts[2] = pts[1];
741               aNewPts[3] = pts[17];
742               aNewPts[4] = pts[5];
743               aNewPts[5] = pts[12];
744               aNewPts[6] = pts[4];
745               aNewPts[7] = pts[16];
746               
747               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
748               if(myStoreMapping)
749                 myVTK2ObjIds.push_back(cellId);
750               
751               outputCD->CopyData(cd,cellId,newCellId);
752               
753               //---------------------------------------------------------------
754               aNewPts[0] = pts[1];
755               aNewPts[1] = pts[9];
756               aNewPts[2] = pts[2];
757               aNewPts[3] = pts[18];
758               aNewPts[4] = pts[6];
759               aNewPts[5] = pts[13];
760               aNewPts[6] = pts[5];
761               aNewPts[7] = pts[17];
762               
763               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
764               if(myStoreMapping)
765                 myVTK2ObjIds.push_back(cellId);
766               
767               outputCD->CopyData(cd,cellId,newCellId);
768               
769               //---------------------------------------------------------------
770               aNewPts[0] = pts[2];
771               aNewPts[1] = pts[10];
772               aNewPts[2] = pts[3];
773               aNewPts[3] = pts[19];
774               aNewPts[4] = pts[7];
775               aNewPts[5] = pts[14];
776               aNewPts[6] = pts[6];
777               aNewPts[7] = pts[18];
778               
779               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
780               if(myStoreMapping)
781                 myVTK2ObjIds.push_back(cellId);
782               
783               outputCD->CopyData(cd,cellId,newCellId);
784               
785               //---------------------------------------------------------------
786               aNewPts[0] = pts[3];
787               aNewPts[1] = pts[11];
788               aNewPts[2] = pts[0];
789               aNewPts[3] = pts[16];
790               aNewPts[4] = pts[4];
791               aNewPts[5] = pts[15];
792               aNewPts[6] = pts[7];
793               aNewPts[7] = pts[19];
794               
795               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
796               if(myStoreMapping)
797                 myVTK2ObjIds.push_back(cellId);
798               
799               outputCD->CopyData(cd,cellId,newCellId);
800               
801               //---------------------------------------------------------------
802               aNewPts[0] = pts[0];
803               aNewPts[1] = pts[8];
804               aNewPts[2] = pts[1];
805               aNewPts[3] = pts[9];
806               aNewPts[4] = pts[2];
807               aNewPts[5] = pts[10];
808               aNewPts[6] = pts[3];
809               aNewPts[7] = pts[11];
810               
811               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
812               if(myStoreMapping)
813                 myVTK2ObjIds.push_back(cellId);
814               
815               outputCD->CopyData(cd,cellId,newCellId);
816               
817               //---------------------------------------------------------------
818               aNewPts[0] = pts[4];
819               aNewPts[1] = pts[12];
820               aNewPts[2] = pts[5];
821               aNewPts[3] = pts[13];
822               aNewPts[4] = pts[6];
823               aNewPts[5] = pts[14];
824               aNewPts[6] = pts[7];
825               aNewPts[7] = pts[15];
826               
827               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
828               if(myStoreMapping)
829                 myVTK2ObjIds.push_back(cellId);
830               
831               outputCD->CopyData(cd,cellId,newCellId);
832               
833               break;
834             }
835             case VTK_QUADRATIC_PYRAMID: {
836               aCellType = VTK_POLYGON;
837               numFacePts = 6;
838               
839               //---------------------------------------------------------------
840               aNewPts[0] = pts[0];
841               aNewPts[1] = pts[8];
842               aNewPts[2] = pts[3];
843               aNewPts[3] = pts[12];
844               aNewPts[4] = pts[4];
845               aNewPts[5] = pts[9];
846               
847               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
848               if(myStoreMapping)
849                 myVTK2ObjIds.push_back(cellId);
850               
851               outputCD->CopyData(cd,cellId,newCellId);
852
853               //---------------------------------------------------------------
854               aNewPts[0] = pts[0];
855               aNewPts[1] = pts[9];
856               aNewPts[2] = pts[4];
857               aNewPts[3] = pts[10];
858               aNewPts[4] = pts[1];
859               aNewPts[5] = pts[5];
860               
861               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
862               if(myStoreMapping)
863                 myVTK2ObjIds.push_back(cellId);
864               
865               outputCD->CopyData(cd,cellId,newCellId);
866
867               //---------------------------------------------------------------
868               aNewPts[0] = pts[1];
869               aNewPts[1] = pts[10];
870               aNewPts[2] = pts[4];
871               aNewPts[3] = pts[11];
872               aNewPts[4] = pts[2];
873               aNewPts[5] = pts[6];
874               
875               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
876               if(myStoreMapping)
877                 myVTK2ObjIds.push_back(cellId);
878               
879               outputCD->CopyData(cd,cellId,newCellId);
880
881               //---------------------------------------------------------------
882               aNewPts[0] = pts[2];
883               aNewPts[1] = pts[11];
884               aNewPts[2] = pts[4];
885               aNewPts[3] = pts[12];
886               aNewPts[4] = pts[3];
887               aNewPts[5] = pts[7];
888               
889               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
890               if(myStoreMapping)
891                 myVTK2ObjIds.push_back(cellId);
892               
893               outputCD->CopyData(cd,cellId,newCellId);
894
895               //---------------------------------------------------------------
896               numFacePts = 8;
897               aNewPts[0] = pts[0];
898               aNewPts[1] = pts[5];
899               aNewPts[2] = pts[1];
900               aNewPts[3] = pts[6];
901               aNewPts[4] = pts[2];
902               aNewPts[5] = pts[7];
903               aNewPts[6] = pts[3];
904               aNewPts[7] = pts[8];
905               
906               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
907               if(myStoreMapping)
908                 myVTK2ObjIds.push_back(cellId);
909               
910               outputCD->CopyData(cd,cellId,newCellId);
911
912               break;
913             }}
914           }
915         } //switch
916       } //if visible
917     } //for all cells
918   
919   output->Squeeze();
920
921   vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points,"
922   << output->GetNumberOfCells() << " cells.");
923
924   cell->Delete();
925
926   cellIds->Delete();
927   faceIds->Delete();
928
929   if ( cellVis )
930     {
931     delete [] cellVis;
932     }
933
934   return 1;
935 }
936
937
938 void
939 VTKViewer_GeometryFilter
940 ::SetInside(int theShowInside)
941 {
942   if(myShowInside == theShowInside) 
943     return;
944
945   myShowInside = theShowInside;
946   this->Modified();
947 }
948
949 int
950 VTKViewer_GeometryFilter
951 ::GetInside()
952 {
953   return myShowInside;
954 }
955
956
957 void 
958 VTKViewer_GeometryFilter
959 ::SetWireframeMode(int theIsWireframeMode)
960 {
961   if(myIsWireframeMode == theIsWireframeMode)
962     return;
963
964   myIsWireframeMode = theIsWireframeMode;
965   this->Modified();
966 }
967
968 int
969 VTKViewer_GeometryFilter
970 ::GetWireframeMode()
971 {
972   return myIsWireframeMode;
973 }
974
975
976 void
977 VTKViewer_GeometryFilter
978 ::SetStoreMapping(int theStoreMapping)
979 {
980   if(myStoreMapping == theStoreMapping) 
981     return;
982
983   myStoreMapping = theStoreMapping;
984   this->Modified();
985 }
986
987 int
988 VTKViewer_GeometryFilter
989 ::GetStoreMapping()
990 {
991   return myStoreMapping;
992 }
993
994
995 vtkIdType VTKViewer_GeometryFilter::GetElemObjId( int theVtkID )
996 {
997   if( myVTK2ObjIds.empty() || theVtkID > (int)myVTK2ObjIds.size() )
998     return -1;
999 #if defined __GNUC_2__
1000   return myVTK2ObjIds[theVtkID];
1001 #else
1002   return myVTK2ObjIds.at(theVtkID);
1003 #endif
1004 }