]> SALOME platform Git repositories - modules/gui.git/blob - src/VTKViewer/VTKViewer_GeometryFilter.cxx
Salome HOME
5c8cbf1af6d03e2b4470182dd219eb0a60a52869
[modules/gui.git] / src / VTKViewer / VTKViewer_GeometryFilter.cxx
1 //  SALOME OBJECT : kernel of SALOME component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VTKViewer_GeometryFilter.cxx
25 //  Author : Michael ZORIN
26 //  Module : SALOME
27 //  $Header$
28
29 #include "VTKViewer_GeometryFilter.h"
30 #include "VTKViewer_ConvexTool.h"
31
32 #include <vtkSmartPointer.h>
33 #include <vtkCellArray.h>
34 #include <vtkCellData.h>
35 #include <vtkGenericCell.h>
36 #include <vtkHexahedron.h>
37 #include <vtkMergePoints.h>
38 #include <vtkObjectFactory.h>
39 #include <vtkPointData.h>
40 #include <vtkPolyData.h>
41 #include <vtkPyramid.h>
42 #include <vtkStructuredGrid.h>
43 #include <vtkTetra.h>
44 #include <vtkUnsignedCharArray.h>
45 #include <vtkUnstructuredGrid.h>
46 #include <vtkVoxel.h>
47 #include <vtkWedge.h>
48
49 #include <algorithm>
50 #include <iterator>
51 #include <vector>
52 #include <map>
53 #include <set>
54
55 #if defined __GNUC__
56   #if __GNUC__ == 2
57     #define __GNUC_2__
58   #endif
59 #endif
60
61 //#define USE_ROBUST_TRIANGULATION
62
63 vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision$");
64 vtkStandardNewMacro(VTKViewer_GeometryFilter);
65
66 VTKViewer_GeometryFilter
67 ::VTKViewer_GeometryFilter(): 
68   myShowInside(0),
69   myStoreMapping(0),
70   myIsWireframeMode(0)
71 {}
72
73
74 VTKViewer_GeometryFilter
75 ::~VTKViewer_GeometryFilter()
76 {}
77
78
79 void
80 VTKViewer_GeometryFilter
81 ::Execute()
82 {
83   vtkDataSet *input= this->GetInput();
84   vtkIdType numCells=input->GetNumberOfCells();
85
86   if (numCells == 0)
87     {
88       return;
89     }
90   
91   if (input->GetDataObjectType() == VTK_UNSTRUCTURED_GRID){
92     this->UnstructuredGridExecute();
93     return;
94   }else
95     vtkGeometryFilter::Execute();
96 }
97
98
99 void
100 VTKViewer_GeometryFilter
101 ::UnstructuredGridExecute()
102 {
103   vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput();
104   vtkCellArray *Connectivity = input->GetCells();
105   // Check input
106   if ( Connectivity == NULL )
107     {
108     vtkDebugMacro(<<"Nothing to extract");
109     return;
110     }
111
112   vtkIdType cellId;
113   int i;
114   int allVisible;
115   vtkIdType npts = 0;
116   vtkIdType *pts = 0;
117   vtkPoints *p = input->GetPoints();
118   vtkIdType numCells=input->GetNumberOfCells();
119   vtkPointData *pd = input->GetPointData();
120   vtkCellData *cd = input->GetCellData();
121   vtkPolyData *output = this->GetOutput();
122   vtkPointData *outputPD = output->GetPointData();
123   
124   VTKViewer_OrderedTriangulator anOrderedTriangulator;
125   VTKViewer_DelaunayTriangulator aDelaunayTriangulator;
126
127   vtkCellData *outputCD = output->GetCellData();
128   vtkGenericCell *cell = vtkGenericCell::New();
129
130   vtkIdList *cellIds = vtkIdList::New();
131   vtkIdList *faceIds = vtkIdList::New();
132
133   char *cellVis;
134   vtkIdType newCellId;
135   int faceId, *faceVerts, numFacePts;
136   vtkFloatingPointType *x;
137   int PixelConvert[4], aNewPts[VTK_CELL_SIZE];
138   // ghost cell stuff
139   unsigned char  updateLevel = (unsigned char)(output->GetUpdateGhostLevel());
140   unsigned char  *cellGhostLevels = 0;  
141   
142   PixelConvert[0] = 0;
143   PixelConvert[1] = 1;
144   PixelConvert[2] = 3;
145   PixelConvert[3] = 2;
146   
147   vtkDebugMacro(<<"Executing geometry filter for unstructured grid input");
148
149   vtkDataArray* temp = 0;
150   if (cd)
151     {
152     temp = cd->GetArray("vtkGhostLevels");
153     }
154   if ( (!temp) || (temp->GetDataType() != VTK_UNSIGNED_CHAR)
155     || (temp->GetNumberOfComponents() != 1))
156     {
157     vtkDebugMacro("No appropriate ghost levels field available.");
158     }
159   else
160     {
161     cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0);
162     }
163   
164   // Determine nature of what we have to do
165   if ( (!this->CellClipping) && (!this->PointClipping) &&
166        (!this->ExtentClipping) )
167     {
168     allVisible = 1;
169     cellVis = NULL;
170     }
171   else
172     {
173     allVisible = 0;
174     cellVis = new char[numCells];
175     }
176
177   // Just pass points through, never merge
178   output->SetPoints(input->GetPoints());
179   outputPD->PassData(pd);
180
181   outputCD->CopyAllocate(cd,numCells,numCells/2);
182
183   output->Allocate(numCells/4+1,numCells);
184   
185   // Loop over the cells determining what's visible
186   if (!allVisible)
187     {
188     for (cellId=0, Connectivity->InitTraversal(); 
189          Connectivity->GetNextCell(npts,pts); 
190          cellId++)
191       {
192       cellVis[cellId] = 1;
193       if ( this->CellClipping && cellId < this->CellMinimum ||
194            cellId > this->CellMaximum )
195         {
196         cellVis[cellId] = 0;
197         }
198       else
199         {
200         for (i=0; i < npts; i++) 
201           {
202           x = p->GetPoint(pts[i]);
203           if ( (this->PointClipping && (pts[i] < this->PointMinimum ||
204                                         pts[i] > this->PointMaximum) ) ||
205                (this->ExtentClipping && 
206                 (x[0] < this->Extent[0] || x[0] > this->Extent[1] ||
207                  x[1] < this->Extent[2] || x[1] > this->Extent[3] ||
208                  x[2] < this->Extent[4] || x[2] > this->Extent[5] )) )
209             {
210             cellVis[cellId] = 0;
211             break;
212             }//point/extent clipping
213           }//for each point
214         }//if point clipping needs checking
215       }//for all cells
216     }//if not all visible
217   
218   // Loop over all cells now that visibility is known
219   // (Have to compute visibility first for 3D cell boundarys)
220   int progressInterval = numCells/20 + 1;
221   if(myStoreMapping){
222     myVTK2ObjIds.clear();
223     myVTK2ObjIds.reserve(numCells);
224   }
225   for (cellId=0, Connectivity->InitTraversal(); 
226        Connectivity->GetNextCell(npts,pts); 
227        cellId++)
228     {
229     //Progress and abort method support
230     if ( !(cellId % progressInterval) )
231       {
232       vtkDebugMacro(<<"Process cell #" << cellId);
233       this->UpdateProgress ((float)cellId/numCells);
234       }
235
236     // Handle ghost cells here.  Another option was used cellVis array.
237     if (cellGhostLevels && cellGhostLevels[cellId] > updateLevel)
238       { // Do not create surfaces in outer ghost cells.
239       continue;
240       }
241     
242     if (allVisible || cellVis[cellId])  //now if visible extract geometry
243       {
244       //special code for nonlinear cells - rarely occurs, so right now it
245       //is slow.
246       vtkIdType aCellType = input->GetCellType(cellId);
247       switch (aCellType)
248         {
249         case VTK_EMPTY_CELL:
250           break;
251
252         case VTK_VERTEX:
253         case VTK_POLY_VERTEX:
254           newCellId = output->InsertNextCell(aCellType,npts,pts);
255           if(myStoreMapping){
256             myVTK2ObjIds.push_back(cellId); //apo
257           }
258           outputCD->CopyData(cd,cellId,newCellId);
259           break;
260
261         case VTK_LINE: 
262         case VTK_POLY_LINE:
263           newCellId = output->InsertNextCell(aCellType,npts,pts);
264           if(myStoreMapping)
265             myVTK2ObjIds.push_back(cellId);
266           outputCD->CopyData(cd,cellId,newCellId);
267           break;
268
269         case VTK_TRIANGLE:
270         case VTK_QUAD:
271         case VTK_POLYGON:
272           newCellId = output->InsertNextCell(aCellType,npts,pts);
273           if(myStoreMapping)
274             myVTK2ObjIds.push_back(cellId);
275           outputCD->CopyData(cd,cellId,newCellId);
276           break;
277
278         case VTK_TRIANGLE_STRIP:
279           newCellId = output->InsertNextCell(aCellType,npts,pts);
280           if(myStoreMapping)
281             myVTK2ObjIds.push_back(cellId);
282           outputCD->CopyData(cd,cellId,newCellId);
283           break;
284
285         case VTK_PIXEL:
286           newCellId = output->InsertNextCell(aCellType,npts,pts);
287           if(myStoreMapping)
288             myVTK2ObjIds.push_back(cellId);
289           outputCD->CopyData(cd,cellId,newCellId);
290           break;
291           
292         case VTK_CONVEX_POINT_SET: {
293           bool anIsOk = anOrderedTriangulator.Execute(input,
294                                                       cd,
295                                                       cellId,
296                                                       myShowInside,
297                                                       allVisible,
298                                                       cellVis,
299                                                       output,
300                                                       outputCD,
301                                                       myStoreMapping,
302                                                       myVTK2ObjIds,
303                                                       true);
304           if(!anIsOk)
305             aDelaunayTriangulator.Execute(input,
306                                           cd,
307                                           cellId,
308                                           myShowInside,
309                                           allVisible,
310                                           cellVis,
311                                           output,
312                                           outputCD,
313                                           myStoreMapping,
314                                           myVTK2ObjIds,
315                                           false);
316               
317           break;
318         }
319         case VTK_TETRA: {
320           for (faceId = 0; faceId < 4; faceId++)
321             {
322             faceIds->Reset();
323             faceVerts = vtkTetra::GetFaceArray(faceId);
324             faceIds->InsertNextId(pts[faceVerts[0]]);
325             faceIds->InsertNextId(pts[faceVerts[1]]);
326             faceIds->InsertNextId(pts[faceVerts[2]]);
327             aCellType = VTK_TRIANGLE;
328             numFacePts = 3;
329             input->GetCellNeighbors(cellId, faceIds, cellIds);
330             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ||
331                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
332               {
333               for ( i=0; i < numFacePts; i++)
334                 aNewPts[i] = pts[faceVerts[i]];
335               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
336               if(myStoreMapping)
337                 myVTK2ObjIds.push_back(cellId);
338               outputCD->CopyData(cd,cellId,newCellId);
339               }
340             }
341           break;
342         }
343         case VTK_VOXEL: {
344           for (faceId = 0; faceId < 6; faceId++)
345             {
346             faceIds->Reset();
347             faceVerts = vtkVoxel::GetFaceArray(faceId);
348             faceIds->InsertNextId(pts[faceVerts[0]]);
349             faceIds->InsertNextId(pts[faceVerts[1]]);
350             faceIds->InsertNextId(pts[faceVerts[2]]);
351             faceIds->InsertNextId(pts[faceVerts[3]]);
352             aCellType = VTK_QUAD;
353             numFacePts = 4;
354             input->GetCellNeighbors(cellId, faceIds, cellIds);
355             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
356                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
357               {
358               for ( i=0; i < numFacePts; i++)
359                 aNewPts[i] = pts[faceVerts[PixelConvert[i]]];
360               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
361               if(myStoreMapping)
362                 myVTK2ObjIds.push_back(cellId);
363               outputCD->CopyData(cd,cellId,newCellId);
364               }
365             }
366           break;
367         }
368         case VTK_HEXAHEDRON: {
369           for (faceId = 0; faceId < 6; faceId++)
370             {
371             faceIds->Reset();
372             faceVerts = vtkHexahedron::GetFaceArray(faceId);
373             faceIds->InsertNextId(pts[faceVerts[0]]);
374             faceIds->InsertNextId(pts[faceVerts[1]]);
375             faceIds->InsertNextId(pts[faceVerts[2]]);
376             faceIds->InsertNextId(pts[faceVerts[3]]);
377             aCellType = VTK_QUAD;
378             numFacePts = 4;
379             input->GetCellNeighbors(cellId, faceIds, cellIds);
380             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ||
381                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
382               {
383               for ( i=0; i < numFacePts; i++)
384                 aNewPts[i] = pts[faceVerts[i]];
385               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
386               if(myStoreMapping)
387                 myVTK2ObjIds.push_back(cellId);
388               outputCD->CopyData(cd,cellId,newCellId);
389               }
390             }
391           break;
392         }
393         case VTK_WEDGE: {
394           for (faceId = 0; faceId < 5; faceId++)
395             {
396             faceIds->Reset();
397             faceVerts = vtkWedge::GetFaceArray(faceId);
398             faceIds->InsertNextId(pts[faceVerts[0]]);
399             faceIds->InsertNextId(pts[faceVerts[1]]);
400             faceIds->InsertNextId(pts[faceVerts[2]]);
401             aCellType = VTK_TRIANGLE;
402             numFacePts = 3;
403             if (faceVerts[3] >= 0)
404               {
405               faceIds->InsertNextId(pts[faceVerts[3]]);
406               aCellType = VTK_QUAD;
407               numFacePts = 4;
408               }
409             input->GetCellNeighbors(cellId, faceIds, cellIds);
410             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
411                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
412               {
413               for ( i=0; i < numFacePts; i++)
414                 aNewPts[i] = pts[faceVerts[i]];
415               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
416               if(myStoreMapping)
417                 myVTK2ObjIds.push_back(cellId);
418               outputCD->CopyData(cd,cellId,newCellId);
419               }
420             }
421           break;
422         }
423         case VTK_PYRAMID: {
424           for (faceId = 0; faceId < 5; faceId++)
425             {
426             faceIds->Reset();
427             faceVerts = vtkPyramid::GetFaceArray(faceId);
428             faceIds->InsertNextId(pts[faceVerts[0]]);
429             faceIds->InsertNextId(pts[faceVerts[1]]);
430             faceIds->InsertNextId(pts[faceVerts[2]]);
431             aCellType = VTK_TRIANGLE;
432             numFacePts = 3;
433             if (faceVerts[3] >= 0)
434               {
435               faceIds->InsertNextId(pts[faceVerts[3]]);
436               aCellType = VTK_QUAD;
437               numFacePts = 4;
438               }
439             input->GetCellNeighbors(cellId, faceIds, cellIds);
440             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside || 
441                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
442               {
443               for ( i=0; i < numFacePts; i++)
444                 aNewPts[i] = pts[faceVerts[i]];
445               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
446               if(myStoreMapping)
447                 myVTK2ObjIds.push_back(cellId);
448               outputCD->CopyData(cd,cellId,newCellId);
449               }
450             }
451           break;
452         }
453         //Quadratic cells
454         case VTK_QUADRATIC_EDGE:
455         case VTK_QUADRATIC_TRIANGLE:
456         case VTK_QUADRATIC_QUAD:
457         case VTK_QUADRATIC_TETRA:
458         case VTK_QUADRATIC_HEXAHEDRON:
459           if(!myIsWireframeMode){
460             input->GetCell(cellId,cell);
461             vtkIdList *pts = vtkIdList::New();  
462             vtkPoints *coords = vtkPoints::New();
463             vtkIdList *cellIds = vtkIdList::New();
464             vtkIdType newCellId;
465             
466             if ( cell->GetCellDimension() == 1 ) {
467               aCellType = VTK_LINE;
468               numFacePts = 2;
469               cell->Triangulate(0,pts,coords);
470               for (i=0; i < pts->GetNumberOfIds(); i+=2) {
471                 aNewPts[0] = pts->GetId(i);
472                 aNewPts[1] = pts->GetId(i+1);
473                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
474                 if(myStoreMapping)
475                   myVTK2ObjIds.push_back(cellId);
476                 outputCD->CopyData(cd,cellId,newCellId);
477               }
478             }
479             else if ( cell->GetCellDimension() == 2 ) {
480               aCellType = VTK_TRIANGLE;
481               numFacePts = 3;
482               cell->Triangulate(0,pts,coords);
483               for (i=0; i < pts->GetNumberOfIds(); i+=3) {
484                 aNewPts[0] = pts->GetId(i);
485                 aNewPts[1] = pts->GetId(i+1);
486                 aNewPts[2] = pts->GetId(i+2);
487                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
488                 if(myStoreMapping)
489                   myVTK2ObjIds.push_back(cellId);
490                 outputCD->CopyData(cd,cellId,newCellId);
491               }
492             } 
493             else //3D nonlinear cell
494             {
495               aCellType = VTK_TRIANGLE;
496               numFacePts = 3;
497               for (int j=0; j < cell->GetNumberOfFaces(); j++){
498                 vtkCell *face = cell->GetFace(j);
499                 input->GetCellNeighbors(cellId, face->PointIds, cellIds);
500                 if ( cellIds->GetNumberOfIds() <= 0 || myShowInside ) {
501                   face->Triangulate(0,pts,coords);
502                   for (i=0; i < pts->GetNumberOfIds(); i+=3) {
503                     aNewPts[0] = pts->GetId(i);
504                     aNewPts[1] = pts->GetId(i+1);
505                     aNewPts[2] = pts->GetId(i+2);
506                     newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
507                     if(myStoreMapping)
508                       myVTK2ObjIds.push_back(cellId);
509                     outputCD->CopyData(cd,cellId,newCellId);
510                   }
511                 }
512               }
513             } //3d cell
514             cellIds->Delete();
515             coords->Delete();
516             pts->Delete();
517             break;
518           }else{
519             switch(aCellType){
520             case VTK_QUADRATIC_EDGE: {
521               aCellType = VTK_POLY_LINE;
522               numFacePts = 3;
523               
524               aNewPts[0] = pts[0];
525               aNewPts[2] = pts[1];
526               aNewPts[1] = pts[2];
527               
528               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
529               if(myStoreMapping)
530                 myVTK2ObjIds.push_back(cellId);
531               
532               outputCD->CopyData(cd,cellId,newCellId);
533               break;
534             }
535             case VTK_QUADRATIC_TRIANGLE: {
536               aCellType = VTK_POLYGON;
537               numFacePts = 6;
538               
539               aNewPts[0] = pts[0];
540               aNewPts[1] = pts[3];
541               aNewPts[2] = pts[1];
542               aNewPts[3] = pts[4];
543               aNewPts[4] = pts[2];
544               aNewPts[5] = pts[5];
545               
546               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
547               if(myStoreMapping)
548                 myVTK2ObjIds.push_back(cellId);
549               
550               outputCD->CopyData(cd,cellId,newCellId);
551               break;
552             }
553             case VTK_QUADRATIC_QUAD: {
554               aCellType = VTK_POLYGON;
555               numFacePts = 8;
556               
557               aNewPts[0] = pts[0];
558               aNewPts[1] = pts[4];
559               aNewPts[2] = pts[1];
560               aNewPts[3] = pts[5];
561               aNewPts[4] = pts[2];
562               aNewPts[5] = pts[6];
563               aNewPts[6] = pts[3];
564               aNewPts[7] = pts[7];
565               
566               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
567               if(myStoreMapping)
568                 myVTK2ObjIds.push_back(cellId);
569               
570               outputCD->CopyData(cd,cellId,newCellId);
571               break;
572             }
573             case VTK_QUADRATIC_TETRA: {
574               aCellType = VTK_POLYGON;
575               numFacePts = 6;
576               
577               //---------------------------------------------------------------
578               aNewPts[0] = pts[0];
579               aNewPts[1] = pts[4];
580               aNewPts[2] = pts[1];
581               aNewPts[3] = pts[5];
582               aNewPts[4] = pts[2];
583               aNewPts[5] = pts[6];
584               
585               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
586               if(myStoreMapping)
587                 myVTK2ObjIds.push_back(cellId);
588               
589               outputCD->CopyData(cd,cellId,newCellId);
590
591               //---------------------------------------------------------------
592               aNewPts[0] = pts[0];
593               aNewPts[1] = pts[7];
594               aNewPts[2] = pts[3];
595               aNewPts[3] = pts[8];
596               aNewPts[4] = pts[1];
597               aNewPts[5] = pts[4];
598               
599               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
600               if(myStoreMapping)
601                 myVTK2ObjIds.push_back(cellId);
602               
603               outputCD->CopyData(cd,cellId,newCellId);
604
605               //---------------------------------------------------------------
606               aNewPts[0] = pts[1];
607               aNewPts[1] = pts[8];
608               aNewPts[2] = pts[3];
609               aNewPts[3] = pts[9];
610               aNewPts[4] = pts[2];
611               aNewPts[5] = pts[5];
612               
613               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
614               if(myStoreMapping)
615                 myVTK2ObjIds.push_back(cellId);
616               
617               outputCD->CopyData(cd,cellId,newCellId);
618
619               //---------------------------------------------------------------
620               aNewPts[0] = pts[2];
621               aNewPts[1] = pts[9];
622               aNewPts[2] = pts[3];
623               aNewPts[3] = pts[7];
624               aNewPts[4] = pts[0];
625               aNewPts[5] = pts[6];
626               
627               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
628               if(myStoreMapping)
629                 myVTK2ObjIds.push_back(cellId);
630               
631               outputCD->CopyData(cd,cellId,newCellId);
632
633               break;
634             }
635             case VTK_QUADRATIC_HEXAHEDRON: {
636               aCellType = VTK_POLYGON;
637               numFacePts = 8;
638               
639               //---------------------------------------------------------------
640               aNewPts[0] = pts[0];
641               aNewPts[1] = pts[8];
642               aNewPts[2] = pts[1];
643               aNewPts[3] = pts[17];
644               aNewPts[4] = pts[5];
645               aNewPts[5] = pts[12];
646               aNewPts[6] = pts[4];
647               aNewPts[7] = pts[16];
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               //---------------------------------------------------------------
656               aNewPts[0] = pts[1];
657               aNewPts[1] = pts[9];
658               aNewPts[2] = pts[2];
659               aNewPts[3] = pts[18];
660               aNewPts[4] = pts[6];
661               aNewPts[5] = pts[13];
662               aNewPts[6] = pts[5];
663               aNewPts[7] = pts[17];
664               
665               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
666               if(myStoreMapping)
667                 myVTK2ObjIds.push_back(cellId);
668               
669               outputCD->CopyData(cd,cellId,newCellId);
670               
671               //---------------------------------------------------------------
672               aNewPts[0] = pts[2];
673               aNewPts[1] = pts[10];
674               aNewPts[2] = pts[3];
675               aNewPts[3] = pts[19];
676               aNewPts[4] = pts[7];
677               aNewPts[5] = pts[14];
678               aNewPts[6] = pts[6];
679               aNewPts[7] = pts[18];
680               
681               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
682               if(myStoreMapping)
683                 myVTK2ObjIds.push_back(cellId);
684               
685               outputCD->CopyData(cd,cellId,newCellId);
686               
687               //---------------------------------------------------------------
688               aNewPts[0] = pts[3];
689               aNewPts[1] = pts[11];
690               aNewPts[2] = pts[0];
691               aNewPts[3] = pts[16];
692               aNewPts[4] = pts[4];
693               aNewPts[5] = pts[15];
694               aNewPts[6] = pts[7];
695               aNewPts[7] = pts[19];
696               
697               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
698               if(myStoreMapping)
699                 myVTK2ObjIds.push_back(cellId);
700               
701               outputCD->CopyData(cd,cellId,newCellId);
702               
703               //---------------------------------------------------------------
704               aNewPts[0] = pts[0];
705               aNewPts[1] = pts[8];
706               aNewPts[2] = pts[1];
707               aNewPts[3] = pts[9];
708               aNewPts[4] = pts[2];
709               aNewPts[5] = pts[10];
710               aNewPts[6] = pts[3];
711               aNewPts[7] = pts[11];
712               
713               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
714               if(myStoreMapping)
715                 myVTK2ObjIds.push_back(cellId);
716               
717               outputCD->CopyData(cd,cellId,newCellId);
718               
719               //---------------------------------------------------------------
720               aNewPts[0] = pts[4];
721               aNewPts[1] = pts[12];
722               aNewPts[2] = pts[5];
723               aNewPts[3] = pts[13];
724               aNewPts[4] = pts[6];
725               aNewPts[5] = pts[14];
726               aNewPts[6] = pts[7];
727               aNewPts[7] = pts[15];
728               
729               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
730               if(myStoreMapping)
731                 myVTK2ObjIds.push_back(cellId);
732               
733               outputCD->CopyData(cd,cellId,newCellId);
734               
735               break;
736             }}
737           }
738         } //switch
739       } //if visible
740     } //for all cells
741   
742   output->Squeeze();
743
744   vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points,"
745   << output->GetNumberOfCells() << " cells.");
746
747   cell->Delete();
748
749   cellIds->Delete();
750   faceIds->Delete();
751
752   if ( cellVis )
753     {
754     delete [] cellVis;
755     }
756 }
757
758
759 void
760 VTKViewer_GeometryFilter
761 ::SetInside(int theShowInside)
762 {
763   if(myShowInside == theShowInside) 
764     return;
765
766   myShowInside = theShowInside;
767   this->Modified();
768 }
769
770 int
771 VTKViewer_GeometryFilter
772 ::GetInside()
773 {
774   return myShowInside;
775 }
776
777
778 void 
779 VTKViewer_GeometryFilter
780 ::SetWireframeMode(int theIsWireframeMode)
781 {
782   if(myIsWireframeMode == theIsWireframeMode)
783     return;
784
785   myIsWireframeMode = theIsWireframeMode;
786   this->Modified();
787 }
788
789 int
790 VTKViewer_GeometryFilter
791 ::GetWireframeMode()
792 {
793   return myIsWireframeMode;
794 }
795
796
797 void
798 VTKViewer_GeometryFilter
799 ::SetStoreMapping(int theStoreMapping)
800 {
801   if(myStoreMapping == theStoreMapping) 
802     return;
803
804   myStoreMapping = theStoreMapping;
805   this->Modified();
806 }
807
808 int
809 VTKViewer_GeometryFilter
810 ::GetStoreMapping()
811 {
812   return myStoreMapping;
813 }
814
815
816 vtkIdType VTKViewer_GeometryFilter::GetElemObjId(int theVtkID){
817   if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1;
818 #if defined __GNUC_2__
819   return myVTK2ObjIds[theVtkID];
820 #else
821   return myVTK2ObjIds.at(theVtkID);
822 #endif
823 }