Back to index

salome-gui  6.5.0
VTKViewer_GeometryFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : VTKViewer_GeometryFilter.cxx
00024 //  Author : Michael ZORIN
00025 //  Module : SALOME
00026 //
00027 #include "VTKViewer_GeometryFilter.h"
00028 #include "VTKViewer_ConvexTool.h"
00029 #include "VTKViewer_ArcBuilder.h"
00030 
00031 #include <vtkSmartPointer.h>
00032 #include <vtkCellArray.h>
00033 #include <vtkCellData.h>
00034 #include <vtkGenericCell.h>
00035 #include <vtkHexagonalPrism.h>
00036 #include <vtkHexahedron.h>
00037 #include <vtkInformation.h>
00038 #include <vtkInformationVector.h>
00039 #include <vtkMergePoints.h>
00040 #include <vtkObjectFactory.h>
00041 #include <vtkPointData.h>
00042 #include <vtkPolyData.h>
00043 #include <vtkPolygon.h>
00044 #include <vtkPyramid.h>
00045 #include <vtkStructuredGrid.h>
00046 #include <vtkTetra.h>
00047 #include <vtkUnsignedCharArray.h>
00048 #include <vtkUnstructuredGrid.h>
00049 #include <vtkVoxel.h>
00050 #include <vtkWedge.h>
00051 
00052 #include <algorithm>
00053 #include <iterator>
00054 #include <vector>
00055 #include <map>
00056 #include <set>
00057 
00058 #include "utilities.h"
00059 
00060 #if defined __GNUC__
00061   #if __GNUC__ == 2
00062     #define __GNUC_2__
00063   #endif
00064 #endif
00065 
00066 #define VTK_XVERSION (VTK_MAJOR_VERSION*10000+VTK_MINOR_VERSION*100+VTK_BUILD_VERSION)
00067 
00068 //#define __MYDEBUG__
00069 //#define USE_ROBUST_TRIANGULATION
00070 
00071 vtkCxxRevisionMacro(VTKViewer_GeometryFilter, "$Revision: 1.7.2.5.8.10.2.1 $");
00072 vtkStandardNewMacro(VTKViewer_GeometryFilter);
00073 
00074 VTKViewer_GeometryFilter
00075 ::VTKViewer_GeometryFilter():
00076   myShowInside(0),
00077   myStoreMapping(0),
00078   myAppendCoincident3D(0),
00079   myIsWireframeMode(0),
00080   myIsBuildArc(false),
00081   myMaxArcAngle(2)
00082 {}
00083 
00084 
00085 VTKViewer_GeometryFilter
00086 ::~VTKViewer_GeometryFilter()
00087 {}
00088 
00089 
00090 int
00091 VTKViewer_GeometryFilter
00092 ::RequestData(
00093   vtkInformation *request,
00094   vtkInformationVector **inputVector,
00095   vtkInformationVector *outputVector)
00096 {
00097   // get the info objects
00098   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
00099   vtkInformation *outInfo = outputVector->GetInformationObject(0);
00100 
00101   // get the input and ouptut
00102   vtkDataSet *input = vtkDataSet::SafeDownCast(
00103     inInfo->Get(vtkDataObject::DATA_OBJECT()));
00104   vtkPolyData *output = vtkPolyData::SafeDownCast(
00105     outInfo->Get(vtkDataObject::DATA_OBJECT()));
00106 
00107   vtkIdType numCells=input->GetNumberOfCells();
00108 
00109   if (numCells == 0)
00110     {
00111       return 0;
00112     }
00113 
00114   if (input->GetDataObjectType() == VTK_UNSTRUCTURED_GRID){
00115     return this->UnstructuredGridExecute(input, output, outInfo);
00116   }else
00117     return Superclass::RequestData(request,inputVector,outputVector);
00118 
00119   return 1;
00120 }
00121 
00122 
00123 int
00124 VTKViewer_GeometryFilter
00125 ::UnstructuredGridExecute(
00126                           vtkDataSet *dataSetInput,
00127                           vtkPolyData *output,
00128                           vtkInformation *outInfo)
00129 {
00130 
00131   vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)dataSetInput;
00132   vtkCellArray *Connectivity = input->GetCells();
00133   // Check input
00134   if ( Connectivity == NULL )
00135     {
00136     vtkDebugMacro(<<"Nothing to extract");
00137     return 0;
00138     }
00139 
00140   vtkIdType cellId;
00141   int i;
00142   int allVisible;
00143   vtkIdType npts = 0;
00144   vtkIdType *pts = 0;
00145   vtkPoints *p = input->GetPoints();
00146   vtkIdType numCells=input->GetNumberOfCells();
00147   vtkPointData *pd = input->GetPointData();
00148   vtkCellData *cd = input->GetCellData();
00149   vtkPointData *outputPD = output->GetPointData();
00150 
00151   VTKViewer_OrderedTriangulator anOrderedTriangulator;
00152   VTKViewer_DelaunayTriangulator aDelaunayTriangulator;
00153 
00154   vtkCellData *outputCD = output->GetCellData();
00155   vtkGenericCell *cell = vtkGenericCell::New();
00156 
00157   vtkIdList *cellIds = vtkIdList::New();
00158   vtkIdList *faceIds = vtkIdList::New();
00159 
00160   char *cellVis;
00161   vtkIdType newCellId;
00162   int faceId, *faceVerts, numFacePts;
00163   vtkFloatingPointType *x;
00164   vtkIdType PixelConvert[4];
00165   // Change the type from int to vtkIdType in order to avoid compilation errors while using VTK
00166   // from ParaView-3.4.0 compiled on 64-bit Debian platform with VTK_USE_64BIT_IDS = ON
00167   vtkIdType aNewPts[VTK_CELL_SIZE];
00168   // ghost cell stuff
00169   unsigned char  updateLevel = (unsigned char)(output->GetUpdateGhostLevel());
00170   unsigned char  *cellGhostLevels = 0;
00171 
00172   PixelConvert[0] = 0;
00173   PixelConvert[1] = 1;
00174   PixelConvert[2] = 3;
00175   PixelConvert[3] = 2;
00176 
00177   vtkDebugMacro(<<"Executing geometry filter for unstructured grid input");
00178 
00179   vtkDataArray* temp = 0;
00180   if (cd)
00181     {
00182     temp = cd->GetArray("vtkGhostLevels");
00183     }
00184   if ( (!temp) || (temp->GetDataType() != VTK_UNSIGNED_CHAR)
00185     || (temp->GetNumberOfComponents() != 1))
00186     {
00187     vtkDebugMacro("No appropriate ghost levels field available.");
00188     }
00189   else
00190     {
00191     cellGhostLevels = ((vtkUnsignedCharArray*)temp)->GetPointer(0);
00192     }
00193 
00194   // Determine nature of what we have to do
00195   if ( (!this->CellClipping) && (!this->PointClipping) &&
00196        (!this->ExtentClipping) )
00197     {
00198     allVisible = 1;
00199     cellVis = NULL;
00200     }
00201   else
00202     {
00203     allVisible = 0;
00204     cellVis = new char[numCells];
00205     }
00206 
00207   // Issue 0020115: [CEA 308] Quadratic elements visualization
00208   // Fix of remark described in note 0005222 - SIGSEGV
00209   vtkPoints* outputPoints = vtkPoints::New();
00210   outputPoints->DeepCopy(input->GetPoints());
00211   output->SetPoints(outputPoints);
00212   outputPoints->Delete();
00213 
00214   outputPD->PassData(pd);
00215 
00216   outputCD->CopyAllocate(cd,numCells,numCells/2);
00217 
00218   output->Allocate(numCells/4+1,numCells);
00219 
00220   // Loop over the cells determining what's visible
00221   if (!allVisible)
00222     {
00223     for (cellId=0, Connectivity->InitTraversal();
00224          Connectivity->GetNextCell(npts,pts);
00225          cellId++)
00226       {
00227       cellVis[cellId] = 1;
00228       if ( ( this->CellClipping && cellId < this->CellMinimum ) ||
00229            cellId > this->CellMaximum )
00230         {
00231         cellVis[cellId] = 0;
00232         }
00233       else
00234         {
00235         for (i=0; i < npts; i++)
00236           {
00237           x = p->GetPoint(pts[i]);
00238           if ( ( ( ( this->PointClipping && (pts[i] < this->PointMinimum ) ) ||
00239                                              pts[i] > this->PointMaximum) ) ||
00240                ( this->ExtentClipping &&
00241                 ( x[0] < this->Extent[0] || x[0] > this->Extent[1] ||
00242                   x[1] < this->Extent[2] || x[1] > this->Extent[3] ||
00243                   x[2] < this->Extent[4] || x[2] > this->Extent[5] )) )
00244             {
00245             cellVis[cellId] = 0;
00246             break;
00247             }//point/extent clipping
00248           }//for each point
00249         }//if point clipping needs checking
00250       }//for all cells
00251     }//if not all visible
00252 
00253   // Loop over all cells now that visibility is known
00254   // (Have to compute visibility first for 3D cell boundarys)
00255   int progressInterval = numCells/20 + 1;
00256   TMapOfVectorId aDimension2VTK2ObjIds;
00257   if(myStoreMapping){
00258     myVTK2ObjIds.clear();
00259     myVTK2ObjIds.reserve(numCells);
00260   }
00261   for (cellId=0, Connectivity->InitTraversal();
00262        Connectivity->GetNextCell(npts,pts);
00263        cellId++)
00264     {
00265     //Progress and abort method support
00266     if ( !(cellId % progressInterval) )
00267       {
00268       vtkDebugMacro(<<"Process cell #" << cellId);
00269       this->UpdateProgress ((float)cellId/numCells);
00270       }
00271 
00272     // Handle ghost cells here.  Another option was used cellVis array.
00273     if (cellGhostLevels && cellGhostLevels[cellId] > updateLevel)
00274       { // Do not create surfaces in outer ghost cells.
00275       continue;
00276       }
00277 
00278     if (allVisible || cellVis[cellId])  //now if visible extract geometry
00279       {
00280       //special code for nonlinear cells - rarely occurs, so right now it
00281       //is slow.
00282       vtkIdType aCellType = input->GetCellType(cellId);
00283       switch (aCellType)
00284         {
00285         case VTK_EMPTY_CELL:
00286           break;
00287 
00288         case VTK_VERTEX:
00289         case VTK_POLY_VERTEX:
00290           newCellId = output->InsertNextCell(aCellType,npts,pts);
00291           if(myStoreMapping){
00292             InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00293           }
00294           outputCD->CopyData(cd,cellId,newCellId);
00295           break;
00296 
00297         case VTK_LINE:
00298         case VTK_POLY_LINE:
00299           newCellId = output->InsertNextCell(aCellType,npts,pts);
00300           if(myStoreMapping)
00301             InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00302           outputCD->CopyData(cd,cellId,newCellId);
00303           break;
00304 
00305         case VTK_TRIANGLE:
00306         case VTK_QUAD:
00307         case VTK_POLYGON:
00308           newCellId = output->InsertNextCell(aCellType,npts,pts);
00309           if(myStoreMapping)
00310             InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00311           outputCD->CopyData(cd,cellId,newCellId);
00312           break;
00313 
00314         case VTK_TRIANGLE_STRIP:
00315           newCellId = output->InsertNextCell(aCellType,npts,pts);
00316           if(myStoreMapping)
00317             InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00318           outputCD->CopyData(cd,cellId,newCellId);
00319           break;
00320 
00321         case VTK_PIXEL:
00322           newCellId = output->InsertNextCell(aCellType,npts,pts);
00323           if(myStoreMapping)
00324             InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00325           outputCD->CopyData(cd,cellId,newCellId);
00326           break;
00327 
00328         case VTK_CONVEX_POINT_SET: {
00329           bool anIsOk = anOrderedTriangulator.Execute(input,
00330                                                       cd,
00331                                                       cellId,
00332                                                       myShowInside,
00333                                                       allVisible,
00334                                                       myAppendCoincident3D,
00335                                                       cellVis,
00336                                                       output,
00337                                                       outputCD,
00338                                                       myStoreMapping,
00339                                                       myVTK2ObjIds,
00340                                                       aDimension2VTK2ObjIds,
00341                                                       true);
00342           if(!anIsOk)
00343             aDelaunayTriangulator.Execute(input,
00344                                           cd,
00345                                           cellId,
00346                                           myShowInside,
00347                                           allVisible,
00348                                           myAppendCoincident3D,
00349                                           cellVis,
00350                                           output,
00351                                           outputCD,
00352                                           myStoreMapping,
00353                                           myVTK2ObjIds,
00354                                           aDimension2VTK2ObjIds,
00355                                           false);
00356 
00357           break;
00358         }
00359         case VTK_TETRA: {
00360           for (faceId = 0; faceId < 4; faceId++)
00361             {
00362             faceIds->Reset();
00363             faceVerts = vtkTetra::GetFaceArray(faceId);
00364             faceIds->InsertNextId(pts[faceVerts[0]]);
00365             faceIds->InsertNextId(pts[faceVerts[1]]);
00366             faceIds->InsertNextId(pts[faceVerts[2]]);
00367             aCellType = VTK_TRIANGLE;
00368             numFacePts = 3;
00369             input->GetCellNeighbors(cellId, faceIds, cellIds);
00370             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00371             if ( process || myShowInside ||
00372                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00373               {
00374               for ( i=0; i < numFacePts; i++)
00375                 aNewPts[i] = pts[faceVerts[i]];
00376               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00377               if(myStoreMapping)
00378                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00379               outputCD->CopyData(cd,cellId,newCellId);
00380               }
00381             }
00382           break;
00383         }
00384         case VTK_VOXEL: {
00385           for (faceId = 0; faceId < 6; faceId++)
00386             {
00387             faceIds->Reset();
00388             faceVerts = vtkVoxel::GetFaceArray(faceId);
00389             faceIds->InsertNextId(pts[faceVerts[0]]);
00390             faceIds->InsertNextId(pts[faceVerts[1]]);
00391             faceIds->InsertNextId(pts[faceVerts[2]]);
00392             faceIds->InsertNextId(pts[faceVerts[3]]);
00393             aCellType = VTK_QUAD;
00394             numFacePts = 4;
00395             input->GetCellNeighbors(cellId, faceIds, cellIds);
00396             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00397             if ( process || myShowInside ||
00398                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00399               {
00400               for ( i=0; i < numFacePts; i++)
00401                 aNewPts[i] = pts[faceVerts[PixelConvert[i]]];
00402               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00403               if(myStoreMapping)
00404                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00405               outputCD->CopyData(cd,cellId,newCellId);
00406               }
00407             }
00408           break;
00409         }
00410         case VTK_HEXAHEDRON: {
00411           for (faceId = 0; faceId < 6; faceId++)
00412             {
00413             faceIds->Reset();
00414             faceVerts = vtkHexahedron::GetFaceArray(faceId);
00415             faceIds->InsertNextId(pts[faceVerts[0]]);
00416             faceIds->InsertNextId(pts[faceVerts[1]]);
00417             faceIds->InsertNextId(pts[faceVerts[2]]);
00418             faceIds->InsertNextId(pts[faceVerts[3]]);
00419             aCellType = VTK_QUAD;
00420             numFacePts = 4;
00421             input->GetCellNeighbors(cellId, faceIds, cellIds);
00422             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00423             if ( process || myShowInside ||
00424                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00425               {
00426               for ( i=0; i < numFacePts; i++)
00427                 aNewPts[i] = pts[faceVerts[i]];
00428               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00429               if(myStoreMapping)
00430                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00431               outputCD->CopyData(cd,cellId,newCellId);
00432               }
00433             }
00434           break;
00435         }
00436         case VTK_WEDGE: {
00437           for (faceId = 0; faceId < 5; faceId++)
00438             {
00439             faceIds->Reset();
00440             faceVerts = vtkWedge::GetFaceArray(faceId);
00441             faceIds->InsertNextId(pts[faceVerts[0]]);
00442             faceIds->InsertNextId(pts[faceVerts[1]]);
00443             faceIds->InsertNextId(pts[faceVerts[2]]);
00444             aCellType = VTK_TRIANGLE;
00445             numFacePts = 3;
00446             if (faceVerts[3] >= 0)
00447               {
00448               faceIds->InsertNextId(pts[faceVerts[3]]);
00449               aCellType = VTK_QUAD;
00450               numFacePts = 4;
00451               }
00452 
00453             input->GetCellNeighbors(cellId, faceIds, cellIds);
00454             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00455             if ( process || myShowInside ||
00456                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00457               {
00458               for ( i=0; i < numFacePts; i++)
00459                 aNewPts[i] = pts[faceVerts[i]];
00460               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00461               if(myStoreMapping)
00462                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00463               outputCD->CopyData(cd,cellId,newCellId);
00464               }
00465             }
00466           break;
00467         }
00468         case VTK_HEXAGONAL_PRISM: {
00469           for (faceId = 0; faceId < 8; faceId++)
00470           {
00471             faceVerts = vtkHexagonalPrism::GetFaceArray(faceId);
00472             faceIds->Reset();
00473             faceIds->InsertNextId(pts[faceVerts[0]]);
00474             faceIds->InsertNextId(pts[faceVerts[1]]);
00475             faceIds->InsertNextId(pts[faceVerts[2]]);
00476             faceIds->InsertNextId(pts[faceVerts[3]]);
00477             aCellType = VTK_QUAD;
00478             numFacePts = 4;
00479             if (faceVerts[5] >= 0)
00480             {
00481               faceIds->InsertNextId(pts[faceVerts[4]]);
00482               faceIds->InsertNextId(pts[faceVerts[5]]);
00483               aCellType = VTK_POLYGON;
00484               numFacePts = 6;
00485             }
00486             input->GetCellNeighbors(cellId, faceIds, cellIds);
00487             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00488             if ( process || myShowInside ||
00489                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00490             {
00491               for ( i=0; i < numFacePts; i++)
00492                 aNewPts[i] = pts[faceVerts[i]];
00493               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00494               if(myStoreMapping)
00495                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00496               outputCD->CopyData(cd,cellId,newCellId);
00497             }
00498             }
00499           break;
00500         }
00501         case VTK_PYRAMID: {
00502           for (faceId = 0; faceId < 5; faceId++)
00503             {
00504             faceIds->Reset();
00505             faceVerts = vtkPyramid::GetFaceArray(faceId);
00506             faceIds->InsertNextId(pts[faceVerts[0]]);
00507             faceIds->InsertNextId(pts[faceVerts[1]]);
00508             faceIds->InsertNextId(pts[faceVerts[2]]);
00509             aCellType = VTK_TRIANGLE;
00510             numFacePts = 3;
00511             if (faceVerts[3] >= 0)
00512               {
00513               faceIds->InsertNextId(pts[faceVerts[3]]);
00514               aCellType = VTK_QUAD;
00515               numFacePts = 4;
00516               }
00517             input->GetCellNeighbors(cellId, faceIds, cellIds);
00518             bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00519             if ( process || myShowInside ||
00520                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
00521               {
00522               for ( i=0; i < numFacePts; i++)
00523                 aNewPts[i] = pts[faceVerts[i]];
00524               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00525               if(myStoreMapping)
00526                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00527               outputCD->CopyData(cd,cellId,newCellId);
00528               }
00529             }
00530           break;
00531         }
00532 
00533 #if VTK_XVERSION > 50700
00534         case VTK_POLYHEDRON:
00535           {
00536             //MESSAGE("VTK_POLYHEDRON geometry filter");
00537             vtkIdType nFaces = 0;
00538             vtkIdType* ptIds = 0;
00539             int idp = 0;
00540             input->GetFaceStream(cellId, nFaces, ptIds);
00541             for (faceId = 0; faceId < nFaces; faceId++)
00542               {
00543                 faceIds->Reset();
00544                 numFacePts = ptIds[idp];
00545                 //MESSAGE("numFacePts="<< numFacePts);
00546                 int pt0 = ++idp;
00547                 for (i = 0; i < numFacePts; i++)
00548                   {
00549                     //MESSAGE("ptIds[" << idp + i << "]=" << ptIds[idp + i]);
00550                     faceIds->InsertNextId(ptIds[idp + i]);
00551                   }
00552                 idp += numFacePts;
00553                 switch (numFacePts)
00554                   {
00555                   case 3:
00556                     aCellType = VTK_TRIANGLE;
00557                     break;
00558                   case 4:
00559                     aCellType = VTK_QUAD;
00560                     break;
00561                   default:
00562                     aCellType = VTK_POLYGON;
00563                     break;
00564                   }
00565                 // TODO understand and fix display of several polyhedrons                
00566                 input->GetCellNeighbors(cellId, faceIds, cellIds);
00567                 bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00568                 if (process || myShowInside
00569                     || (!allVisible && !cellVis[cellIds->GetId(0)]))
00570                   {
00571                     for (i = 0; i < numFacePts; i++)
00572                       aNewPts[i] = ptIds[pt0 + i];
00573                     newCellId = output->InsertNextCell(aCellType, numFacePts, aNewPts);
00574                     if (myStoreMapping)
00575                       InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00576                     outputCD->CopyData(cd, cellId, newCellId);
00577                   }
00578               }
00579             break;
00580           }
00581 #endif
00582         //Quadratic cells
00583         case VTK_QUADRATIC_EDGE:
00584         case VTK_QUADRATIC_TRIANGLE:
00585         case VTK_QUADRATIC_QUAD:
00586         case VTK_BIQUADRATIC_QUAD:
00587         case VTK_QUADRATIC_TETRA:
00588         case VTK_QUADRATIC_HEXAHEDRON:
00589         case VTK_TRIQUADRATIC_HEXAHEDRON:
00590         case VTK_QUADRATIC_WEDGE:
00591         case VTK_QUADRATIC_PYRAMID:
00592           if(!myIsWireframeMode) {
00593             input->GetCell(cellId,cell);
00594             vtkIdList *lpts = vtkIdList::New();
00595             vtkPoints *coords = vtkPoints::New();
00596             vtkIdList *cellIds = vtkIdList::New();
00597             vtkIdType newCellId;
00598 
00599             if ( cell->GetCellDimension() == 1 ) {
00600               vtkIdType arcResult = -1;
00601               if(myIsBuildArc) {
00602                 arcResult = Build1DArc(cellId, input, output, pts, myMaxArcAngle);
00603                 newCellId = arcResult;
00604               }
00605 
00606               if(!myIsBuildArc || arcResult == -1 ) {
00607                 aCellType = VTK_LINE;
00608                 numFacePts = 2;
00609                 cell->Triangulate(0,lpts,coords);
00610                 for (i=0; i < lpts->GetNumberOfIds(); i+=2) {
00611                   aNewPts[0] = lpts->GetId(i);
00612                   aNewPts[1] = lpts->GetId(i+1);
00613                   newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00614                   if(myStoreMapping)
00615                     InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00616                   outputCD->CopyData(cd,cellId,newCellId);
00617                 }
00618               }
00619               else {
00620                 if(myStoreMapping)
00621                   InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00622                 outputCD->CopyData(cd,cellId,newCellId);
00623               }
00624             }
00625             else if ( cell->GetCellDimension() == 2 ) {
00626               if(!myIsBuildArc) {
00627                 aCellType = VTK_TRIANGLE;
00628                 numFacePts = 3;
00629                 cell->Triangulate(0,lpts,coords);
00630                 for (i=0; i < lpts->GetNumberOfIds(); i+=3) {
00631                   aNewPts[0] = lpts->GetId(i);
00632                   aNewPts[1] = lpts->GetId(i+1);
00633                   aNewPts[2] = lpts->GetId(i+2);
00634                   newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00635                   if(myStoreMapping)
00636                     InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00637                   outputCD->CopyData(cd,cellId,newCellId);
00638                 }
00639               }
00640               else{
00641                 BuildArcedPolygon(cellId,input,output,aDimension2VTK2ObjIds,true);
00642               }
00643             }
00644             else //3D nonlinear cell
00645             {
00646               aCellType = VTK_TRIANGLE;
00647               numFacePts = 3;
00648               for (int j=0; j < cell->GetNumberOfFaces(); j++){
00649                 vtkCell *face = cell->GetFace(j);
00650                 input->GetCellNeighbors(cellId, face->PointIds, cellIds);
00651                 bool process = cellIds->GetNumberOfIds() <= 0 ? true : myAppendCoincident3D;
00652                 if ( process || myShowInside ) {
00653                   face->Triangulate(0,lpts,coords);
00654                   for (i=0; i < lpts->GetNumberOfIds(); i+=3) {
00655                     aNewPts[0] = lpts->GetId(i);
00656                     aNewPts[1] = lpts->GetId(i+1);
00657                     aNewPts[2] = lpts->GetId(i+2);
00658                     newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00659                     if(myStoreMapping)
00660                       InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00661                     outputCD->CopyData(cd,cellId,newCellId);
00662                   }
00663                 }
00664               }
00665             } //3d nonlinear cell
00666             cellIds->Delete();
00667             coords->Delete();
00668             lpts->Delete();
00669             break;
00670           } else { // wireframe
00671             switch(aCellType) {
00672             case VTK_QUADRATIC_EDGE: {
00673               vtkIdType arcResult =-1;
00674               if(myIsBuildArc) {
00675                arcResult = Build1DArc(cellId, input, output, pts,myMaxArcAngle);
00676                newCellId = arcResult;
00677               }
00678               if(!myIsBuildArc || arcResult == -1) {
00679                 aCellType = VTK_POLY_LINE;
00680                 numFacePts = 3;
00681 
00682                 aNewPts[0] = pts[0];
00683                 aNewPts[2] = pts[1];
00684                 aNewPts[1] = pts[2];
00685 
00686                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00687               }
00688 
00689               if(myStoreMapping)
00690                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00691 
00692               outputCD->CopyData(cd,cellId,newCellId);
00693               break;
00694             }
00695             case VTK_QUADRATIC_TRIANGLE: {
00696               if(!myIsBuildArc) {
00697                 aCellType = VTK_POLYGON;
00698                 numFacePts = 6;
00699 
00700                 aNewPts[0] = pts[0];
00701                 aNewPts[1] = pts[3];
00702                 aNewPts[2] = pts[1];
00703                 aNewPts[3] = pts[4];
00704                 aNewPts[4] = pts[2];
00705                 aNewPts[5] = pts[5];
00706 
00707                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00708                 if(myStoreMapping)
00709                   InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00710 
00711                 outputCD->CopyData(cd,cellId,newCellId);
00712               }
00713               else
00714                 BuildArcedPolygon(cellId,input,output,aDimension2VTK2ObjIds);
00715               break;
00716             }
00717             case VTK_BIQUADRATIC_QUAD:
00718             case VTK_QUADRATIC_QUAD: {
00719               if(!myIsBuildArc) {
00720                 aCellType = VTK_POLYGON;
00721                 numFacePts = 8;
00722 
00723                 aNewPts[0] = pts[0];
00724                 aNewPts[1] = pts[4];
00725                 aNewPts[2] = pts[1];
00726                 aNewPts[3] = pts[5];
00727                 aNewPts[4] = pts[2];
00728                 aNewPts[5] = pts[6];
00729                 aNewPts[6] = pts[3];
00730                 aNewPts[7] = pts[7];
00731 
00732                 newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00733                 if(myStoreMapping)
00734                   InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00735 
00736                 outputCD->CopyData(cd,cellId,newCellId);
00737               }
00738               else
00739                 BuildArcedPolygon(cellId,input,output,aDimension2VTK2ObjIds);
00740               break;
00741             }
00742             case VTK_QUADRATIC_TETRA: {
00743               aCellType = VTK_POLYGON;
00744               numFacePts = 6;
00745 
00746               //---------------------------------------------------------------
00747               aNewPts[0] = pts[0];
00748               aNewPts[1] = pts[4];
00749               aNewPts[2] = pts[1];
00750               aNewPts[3] = pts[5];
00751               aNewPts[4] = pts[2];
00752               aNewPts[5] = pts[6];
00753 
00754               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00755               if(myStoreMapping)
00756                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00757 
00758               outputCD->CopyData(cd,cellId,newCellId);
00759 
00760               //---------------------------------------------------------------
00761               aNewPts[0] = pts[0];
00762               aNewPts[1] = pts[7];
00763               aNewPts[2] = pts[3];
00764               aNewPts[3] = pts[8];
00765               aNewPts[4] = pts[1];
00766               aNewPts[5] = pts[4];
00767 
00768               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00769               if(myStoreMapping)
00770                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00771 
00772               outputCD->CopyData(cd,cellId,newCellId);
00773 
00774               //---------------------------------------------------------------
00775               aNewPts[0] = pts[1];
00776               aNewPts[1] = pts[8];
00777               aNewPts[2] = pts[3];
00778               aNewPts[3] = pts[9];
00779               aNewPts[4] = pts[2];
00780               aNewPts[5] = pts[5];
00781 
00782               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00783               if(myStoreMapping)
00784                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00785 
00786               outputCD->CopyData(cd,cellId,newCellId);
00787 
00788               //---------------------------------------------------------------
00789               aNewPts[0] = pts[2];
00790               aNewPts[1] = pts[9];
00791               aNewPts[2] = pts[3];
00792               aNewPts[3] = pts[7];
00793               aNewPts[4] = pts[0];
00794               aNewPts[5] = pts[6];
00795 
00796               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00797               if(myStoreMapping)
00798                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00799 
00800               outputCD->CopyData(cd,cellId,newCellId);
00801 
00802               break;
00803             }
00804             case VTK_QUADRATIC_WEDGE: {
00805               aCellType = VTK_POLYGON;
00806               numFacePts = 6;
00807               //---------------------------------------------------------------
00808               //Face 1
00809               aNewPts[0] = pts[0];
00810               aNewPts[1] = pts[6];
00811               aNewPts[2] = pts[1];
00812               aNewPts[3] = pts[7];
00813               aNewPts[4] = pts[2];
00814               aNewPts[5] = pts[8];
00815               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00816               if(myStoreMapping)
00817                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00818               outputCD->CopyData(cd,cellId,newCellId);
00819 
00820               //---------------------------------------------------------------
00821               //Face 2
00822               aNewPts[0] = pts[3];
00823               aNewPts[1] = pts[9];
00824               aNewPts[2] = pts[4];
00825               aNewPts[3] = pts[10];
00826               aNewPts[4] = pts[5];
00827               aNewPts[5] = pts[11];
00828               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00829               if(myStoreMapping)
00830                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00831               outputCD->CopyData(cd,cellId,newCellId);
00832 
00833               //---------------------------------------------------------------
00834               //Face 3
00835               numFacePts = 8;
00836               aNewPts[0] = pts[0];
00837               aNewPts[1] = pts[8];
00838               aNewPts[2] = pts[2];
00839               aNewPts[3] = pts[14];
00840               aNewPts[4] = pts[5];
00841               aNewPts[5] = pts[11];
00842               aNewPts[6] = pts[3];
00843               aNewPts[7] = pts[12];
00844               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00845               if(myStoreMapping)
00846                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00847               outputCD->CopyData(cd,cellId,newCellId);
00848 
00849               //---------------------------------------------------------------
00850               //Face 4
00851               aNewPts[0] = pts[1];
00852               aNewPts[1] = pts[13];
00853               aNewPts[2] = pts[4];
00854               aNewPts[3] = pts[10];
00855               aNewPts[4] = pts[5];
00856               aNewPts[5] = pts[14];
00857               aNewPts[6] = pts[2];
00858               aNewPts[7] = pts[7];
00859               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00860               if(myStoreMapping)
00861                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00862               outputCD->CopyData(cd,cellId,newCellId);
00863 
00864               //---------------------------------------------------------------
00865               //Face 5
00866               aNewPts[0] = pts[0];
00867               aNewPts[1] = pts[12];
00868               aNewPts[2] = pts[3];
00869               aNewPts[3] = pts[9];
00870               aNewPts[4] = pts[4];
00871               aNewPts[5] = pts[13];
00872               aNewPts[6] = pts[1];
00873               aNewPts[7] = pts[6];
00874               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00875               if(myStoreMapping)
00876                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00877               outputCD->CopyData(cd,cellId,newCellId);
00878               break;
00879             }
00880             case VTK_TRIQUADRATIC_HEXAHEDRON:
00881             case VTK_QUADRATIC_HEXAHEDRON: {
00882               aCellType = VTK_POLYGON;
00883               numFacePts = 8;
00884 
00885               //---------------------------------------------------------------
00886               aNewPts[0] = pts[0];
00887               aNewPts[1] = pts[8];
00888               aNewPts[2] = pts[1];
00889               aNewPts[3] = pts[17];
00890               aNewPts[4] = pts[5];
00891               aNewPts[5] = pts[12];
00892               aNewPts[6] = pts[4];
00893               aNewPts[7] = pts[16];
00894 
00895               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00896               if(myStoreMapping)
00897                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00898 
00899               outputCD->CopyData(cd,cellId,newCellId);
00900 
00901               //---------------------------------------------------------------
00902               aNewPts[0] = pts[1];
00903               aNewPts[1] = pts[9];
00904               aNewPts[2] = pts[2];
00905               aNewPts[3] = pts[18];
00906               aNewPts[4] = pts[6];
00907               aNewPts[5] = pts[13];
00908               aNewPts[6] = pts[5];
00909               aNewPts[7] = pts[17];
00910 
00911               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00912               if(myStoreMapping)
00913                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00914 
00915               outputCD->CopyData(cd,cellId,newCellId);
00916 
00917               //---------------------------------------------------------------
00918               aNewPts[0] = pts[2];
00919               aNewPts[1] = pts[10];
00920               aNewPts[2] = pts[3];
00921               aNewPts[3] = pts[19];
00922               aNewPts[4] = pts[7];
00923               aNewPts[5] = pts[14];
00924               aNewPts[6] = pts[6];
00925               aNewPts[7] = pts[18];
00926 
00927               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00928               if(myStoreMapping)
00929                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00930 
00931               outputCD->CopyData(cd,cellId,newCellId);
00932 
00933               //---------------------------------------------------------------
00934               aNewPts[0] = pts[3];
00935               aNewPts[1] = pts[11];
00936               aNewPts[2] = pts[0];
00937               aNewPts[3] = pts[16];
00938               aNewPts[4] = pts[4];
00939               aNewPts[5] = pts[15];
00940               aNewPts[6] = pts[7];
00941               aNewPts[7] = pts[19];
00942 
00943               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00944               if(myStoreMapping)
00945                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00946 
00947               outputCD->CopyData(cd,cellId,newCellId);
00948 
00949               //---------------------------------------------------------------
00950               aNewPts[0] = pts[0];
00951               aNewPts[1] = pts[8];
00952               aNewPts[2] = pts[1];
00953               aNewPts[3] = pts[9];
00954               aNewPts[4] = pts[2];
00955               aNewPts[5] = pts[10];
00956               aNewPts[6] = pts[3];
00957               aNewPts[7] = pts[11];
00958 
00959               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00960               if(myStoreMapping)
00961                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00962 
00963               outputCD->CopyData(cd,cellId,newCellId);
00964 
00965               //---------------------------------------------------------------
00966               aNewPts[0] = pts[4];
00967               aNewPts[1] = pts[12];
00968               aNewPts[2] = pts[5];
00969               aNewPts[3] = pts[13];
00970               aNewPts[4] = pts[6];
00971               aNewPts[5] = pts[14];
00972               aNewPts[6] = pts[7];
00973               aNewPts[7] = pts[15];
00974 
00975               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00976               if(myStoreMapping)
00977                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00978 
00979               outputCD->CopyData(cd,cellId,newCellId);
00980 
00981               break;
00982             }
00983             case VTK_QUADRATIC_PYRAMID: {
00984               aCellType = VTK_POLYGON;
00985               numFacePts = 6;
00986 
00987               //---------------------------------------------------------------
00988               aNewPts[0] = pts[0];
00989               aNewPts[1] = pts[8];
00990               aNewPts[2] = pts[3];
00991               aNewPts[3] = pts[12];
00992               aNewPts[4] = pts[4];
00993               aNewPts[5] = pts[9];
00994 
00995               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
00996               if(myStoreMapping)
00997                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
00998 
00999               outputCD->CopyData(cd,cellId,newCellId);
01000 
01001               //---------------------------------------------------------------
01002               aNewPts[0] = pts[0];
01003               aNewPts[1] = pts[9];
01004               aNewPts[2] = pts[4];
01005               aNewPts[3] = pts[10];
01006               aNewPts[4] = pts[1];
01007               aNewPts[5] = pts[5];
01008 
01009               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
01010               if(myStoreMapping)
01011                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
01012 
01013               outputCD->CopyData(cd,cellId,newCellId);
01014 
01015               //---------------------------------------------------------------
01016               aNewPts[0] = pts[1];
01017               aNewPts[1] = pts[10];
01018               aNewPts[2] = pts[4];
01019               aNewPts[3] = pts[11];
01020               aNewPts[4] = pts[2];
01021               aNewPts[5] = pts[6];
01022 
01023               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
01024               if(myStoreMapping)
01025                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
01026 
01027               outputCD->CopyData(cd,cellId,newCellId);
01028 
01029               //---------------------------------------------------------------
01030               aNewPts[0] = pts[2];
01031               aNewPts[1] = pts[11];
01032               aNewPts[2] = pts[4];
01033               aNewPts[3] = pts[12];
01034               aNewPts[4] = pts[3];
01035               aNewPts[5] = pts[7];
01036 
01037               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
01038               if(myStoreMapping)
01039                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
01040 
01041               outputCD->CopyData(cd,cellId,newCellId);
01042 
01043               //---------------------------------------------------------------
01044               numFacePts = 8;
01045               aNewPts[0] = pts[0];
01046               aNewPts[1] = pts[5];
01047               aNewPts[2] = pts[1];
01048               aNewPts[3] = pts[6];
01049               aNewPts[4] = pts[2];
01050               aNewPts[5] = pts[7];
01051               aNewPts[6] = pts[3];
01052               aNewPts[7] = pts[8];
01053 
01054               newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
01055               if(myStoreMapping)
01056                 InsertId( cellId, aCellType, myVTK2ObjIds, aDimension2VTK2ObjIds );
01057 
01058               outputCD->CopyData(cd,cellId,newCellId);
01059 
01060               break;
01061             } // case VTK_QUADRATIC_PYRAMID:
01062             } // switch by type
01063           } // end WIREFRAME
01064           break;
01065         } //switch
01066       } //if visible
01067     } //for all cells
01068 
01069   output->Squeeze();
01070 
01071   vtkDebugMacro(<<"Extracted " << input->GetNumberOfPoints() << " points,"
01072                 << output->GetNumberOfCells() << " cells.");
01073 
01074   cell->Delete();
01075 
01076   cellIds->Delete();
01077   faceIds->Delete();
01078 
01079   if ( cellVis )
01080   {
01081     delete [] cellVis;
01082   }
01083 
01084   // to sort myVTK2ObjIds vector by cell dimension (ascending)
01085   if( myStoreMapping && !aDimension2VTK2ObjIds.empty() )
01086   {
01087     myVTK2ObjIds.clear();
01088     for( vtkIdType aDimension = 0; aDimension <= 2; aDimension++ )
01089     {
01090       TMapOfVectorId::const_iterator anIter = aDimension2VTK2ObjIds.find( aDimension );
01091       if( anIter != aDimension2VTK2ObjIds.end() )
01092       {
01093         const TVectorId& aCellIds = anIter->second;
01094         TVectorId::const_iterator anIdIter, anIdIterEnd = aCellIds.end();
01095         for( anIdIter = aCellIds.begin(); anIdIter != anIdIterEnd; anIdIter++ )
01096         {
01097           const vtkIdType aCellId = *anIdIter;
01098           myVTK2ObjIds.push_back( aCellId );
01099         }
01100       }
01101     }
01102   }
01103 
01104   return 1;
01105 }
01106 
01107 void
01108 VTKViewer_GeometryFilter
01109 ::InsertId( const vtkIdType theCellId,
01110             const vtkIdType theCellType,
01111             TVectorId& theVTK2ObjIds,
01112             TMapOfVectorId& theDimension2VTK2ObjIds )
01113 {
01114   theVTK2ObjIds.push_back( theCellId );
01115 
01116   int aDimension = 0;
01117   switch( theCellType )
01118   {
01119     case VTK_VERTEX:
01120     case VTK_POLY_VERTEX:
01121       aDimension = 0;
01122       break;
01123     case VTK_LINE:
01124     case VTK_POLY_LINE:
01125       aDimension = 1;
01126       break;
01127     case VTK_TRIANGLE:
01128     case VTK_TRIANGLE_STRIP:
01129     case VTK_POLYGON:
01130     case VTK_PIXEL:
01131     case VTK_QUAD:
01132       aDimension = 2;
01133       break;
01134   }
01135 
01136   TVectorId& aCellIds = theDimension2VTK2ObjIds[ aDimension ];
01137   aCellIds.push_back( theCellId );
01138 }
01139 
01140 void
01141 VTKViewer_GeometryFilter
01142 ::SetInside(int theShowInside)
01143 {
01144   if(myShowInside == theShowInside)
01145     return;
01146 
01147   myShowInside = theShowInside;
01148   this->Modified();
01149 }
01150 
01151 int
01152 VTKViewer_GeometryFilter
01153 ::GetInside()
01154 {
01155   return myShowInside;
01156 }
01157 
01158 
01159 void
01160 VTKViewer_GeometryFilter
01161 ::SetWireframeMode(int theIsWireframeMode)
01162 {
01163   if(myIsWireframeMode == theIsWireframeMode)
01164     return;
01165 
01166   myIsWireframeMode = theIsWireframeMode;
01167   this->Modified();
01168 }
01169 
01170 int
01171 VTKViewer_GeometryFilter
01172 ::GetWireframeMode()
01173 {
01174   return myIsWireframeMode;
01175 }
01176 
01177 
01178 void
01179 VTKViewer_GeometryFilter
01180 ::SetStoreMapping(int theStoreMapping)
01181 {
01182   if(myStoreMapping == theStoreMapping)
01183     return;
01184 
01185   myStoreMapping = theStoreMapping;
01186   this->Modified();
01187 }
01188 
01189 int
01190 VTKViewer_GeometryFilter
01191 ::GetStoreMapping()
01192 {
01193   return myStoreMapping;
01194 }
01195 
01196 
01197 vtkIdType VTKViewer_GeometryFilter::GetElemObjId( int theVtkID )
01198 {
01199   if( theVtkID < 0 || theVtkID >= (int)myVTK2ObjIds.size() )
01200     return -1;
01201   return myVTK2ObjIds[theVtkID];
01202 }
01203 
01204 
01205 void VTKViewer_GeometryFilter::BuildArcedPolygon(vtkIdType cellId,
01206                                                  vtkUnstructuredGrid* input,
01207                                                  vtkPolyData *output,
01208                                                  TMapOfVectorId& theDimension2VTK2ObjIds,
01209                                                  bool triangulate){
01210   vtkIdType aCellType = VTK_POLYGON;
01211   vtkIdType *aNewPoints = NULL;
01212   vtkIdType aNbPoints = 0;
01213   vtkIdType newCellId;
01214 
01215   //Input and output cell data
01216   vtkCellData *cd = input->GetCellData();
01217   vtkCellData *outputCD = output->GetCellData();
01218 
01219   //Input and output scalars on point data
01220   vtkDataArray* inputScalars = input->GetPointData()->GetScalars();
01221   vtkDataArray* outputScalars = output->GetPointData()->GetScalars();
01222 
01223   std::vector<vtkPoints*> aCollection;
01224   std::vector< std::vector<double> > aScalarCollection;
01225 
01226   vtkCell* aCell = input->GetCell(cellId);
01227   switch(aCell->GetCellType()) {
01228     case VTK_QUADRATIC_TRIANGLE:
01229     {
01230       //Get All points from input cell
01231       Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
01232       Pnt P1 = CreatePnt( aCell, inputScalars, 1 );
01233       Pnt P2 = CreatePnt( aCell, inputScalars, 2 );
01234       Pnt P3 = CreatePnt( aCell, inputScalars, 3 );
01235       Pnt P4 = CreatePnt( aCell, inputScalars, 4 );
01236       Pnt P5 = CreatePnt( aCell, inputScalars, 5 );
01237 
01238       VTKViewer_ArcBuilder aBuilder1(P0,P3,P1,myMaxArcAngle); //Build arc using 0, 3 and 1 points
01239 #ifdef __MYDEBUG__
01240       cout << "Quadrangle arc 1 " << ( aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01241 #endif
01242 
01243       VTKViewer_ArcBuilder aBuilder2(P1,P4,P2,myMaxArcAngle); //Build arc using 1, 4 and 2 points
01244 #ifdef __MYDEBUG__
01245       cout << "Quadrangle arc 2 " << ( aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01246 #endif
01247 
01248       VTKViewer_ArcBuilder aBuilder3(P2,P5,P0,myMaxArcAngle); //Build arc using 2, 5 and 0 points
01249 #ifdef __MYDEBUG__
01250       cout << "Quadrangle arc 3 " << ( aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01251 #endif
01252 
01253       aCollection.push_back(aBuilder1.GetPoints());
01254       aCollection.push_back(aBuilder2.GetPoints());
01255       aCollection.push_back(aBuilder3.GetPoints());
01256 
01257       aScalarCollection.push_back(aBuilder1.GetScalarValues());
01258       aScalarCollection.push_back(aBuilder2.GetScalarValues());
01259       aScalarCollection.push_back(aBuilder3.GetScalarValues());
01260       break;
01261     }
01262     case VTK_BIQUADRATIC_QUAD:
01263     case VTK_QUADRATIC_QUAD:
01264     {
01265       //Get All points from input cell
01266       Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
01267       Pnt P1 = CreatePnt( aCell, inputScalars, 1 );
01268       Pnt P2 = CreatePnt( aCell, inputScalars, 2 );
01269       Pnt P3 = CreatePnt( aCell, inputScalars, 3 );
01270       Pnt P4 = CreatePnt( aCell, inputScalars, 4 );
01271       Pnt P5 = CreatePnt( aCell, inputScalars, 5 );
01272       Pnt P6 = CreatePnt( aCell, inputScalars, 6 );
01273       Pnt P7 = CreatePnt( aCell, inputScalars, 7 );
01274 
01275       VTKViewer_ArcBuilder aBuilder1(P0,P4,P1,myMaxArcAngle); //Build arc using 0, 4 and 1 points
01276 #ifdef __MYDEBUG__
01277       cout << "Quadrangle arc 1 " << ( aBuilder1.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01278 #endif
01279 
01280       VTKViewer_ArcBuilder aBuilder2(P1,P5,P2,myMaxArcAngle); //Build arc using 1, 5 and 2 points
01281 #ifdef __MYDEBUG__
01282       cout << "Quadrangle arc 2 " << ( aBuilder2.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01283 #endif
01284 
01285       VTKViewer_ArcBuilder aBuilder3(P2,P6,P3,myMaxArcAngle); //Build arc using 2, 6 and 3 points
01286 #ifdef __MYDEBUG__
01287       cout << "Quadrangle arc 3 " << ( aBuilder3.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01288 #endif
01289 
01290       VTKViewer_ArcBuilder aBuilder4(P3,P7,P0,myMaxArcAngle); //Build arc using 3, 7 and 0 points
01291 #ifdef __MYDEBUG__
01292       cout << "Quadrangle arc 4 " << ( aBuilder4.GetStatus() == VTKViewer_ArcBuilder::Arc_Done ? "" : "NOT " ) << "done !!!" << endl;
01293 #endif
01294 
01295       aCollection.push_back(aBuilder1.GetPoints());
01296       aCollection.push_back(aBuilder2.GetPoints());
01297       aCollection.push_back(aBuilder3.GetPoints());
01298       aCollection.push_back(aBuilder4.GetPoints());
01299 
01300       aScalarCollection.push_back(aBuilder1.GetScalarValues());
01301       aScalarCollection.push_back(aBuilder2.GetScalarValues());
01302       aScalarCollection.push_back(aBuilder3.GetScalarValues());
01303       aScalarCollection.push_back(aBuilder4.GetScalarValues());
01304       break;
01305     }
01306     default: //Unsupported cell type
01307       return;
01308   }
01309 
01310   if(triangulate){
01311     const vtkIdType numFacePts = 3;
01312     vtkIdList *pts = vtkIdList::New();
01313     vtkPoints *coords = vtkPoints::New();
01314     aCellType = VTK_TRIANGLE;
01315     vtkIdType aNewPts[numFacePts];
01316     vtkIdType aTriangleId;
01317 
01318     vtkPolygon *aPlg = vtkPolygon::New();
01319     std::map<int, double> aPntId2ScalarValue;
01320     aNbPoints = MergevtkPoints(aCollection, aScalarCollection, aPlg->GetPoints(), aPntId2ScalarValue, aNewPoints);
01321     aPlg->GetPointIds()->SetNumberOfIds(aNbPoints);
01322 
01323     for(vtkIdType i = 0; i < aNbPoints;i++) {
01324       aPlg->GetPointIds()->SetId(i, aNewPoints[i]);
01325     }
01326 
01327     aPlg->Triangulate(0,pts,coords);
01328 
01329     for (vtkIdType i=0; i < pts->GetNumberOfIds(); i+=3) {
01330       aNewPts[0] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i));
01331       aNewPts[1] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+1));
01332       aNewPts[2] = output->GetPoints()->InsertNextPoint(coords->GetPoint(i+2));
01333 
01334       if(outputScalars) {
01335         outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i)]);
01336         outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i+1)]);
01337         outputScalars->InsertNextTuple1(aPntId2ScalarValue[pts->GetId(i+2)]);
01338       }
01339 
01340       aTriangleId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
01341 
01342       if(myStoreMapping)
01343         InsertId( cellId, aCellType, myVTK2ObjIds, theDimension2VTK2ObjIds );
01344       outputCD->CopyData(cd,cellId,aTriangleId);
01345     }
01346     pts->Delete();
01347     coords->Delete();
01348     aPlg->Delete();
01349   }
01350   else {
01351     std::map<int, double> aPntId2ScalarValue;
01352     aNbPoints = MergevtkPoints(aCollection, aScalarCollection, output->GetPoints(), aPntId2ScalarValue, aNewPoints);
01353     if(outputScalars)
01354       for(vtkIdType i = 0; i < aNbPoints; i++)
01355         outputScalars->InsertNextTuple1(aPntId2ScalarValue[aNewPoints[i]]);
01356     newCellId = output->InsertNextCell(aCellType,aNbPoints,aNewPoints);
01357     outputCD->CopyData(cd,cellId,newCellId);
01358 
01359     if(myStoreMapping)
01360       InsertId( cellId, aCellType, myVTK2ObjIds, theDimension2VTK2ObjIds );
01361   }
01362 
01363   if (aNewPoints)
01364     delete [] aNewPoints;
01365 }
01366 
01367 
01368 void VTKViewer_GeometryFilter::SetQuadraticArcMode(bool theFlag)
01369 {
01370   if(myIsBuildArc != theFlag) {
01371     myIsBuildArc = theFlag;
01372     this->Modified();
01373   }
01374 }
01375 bool VTKViewer_GeometryFilter::GetQuadraticArcMode() const
01376 {
01377   return myIsBuildArc;
01378 }
01379 
01380 void VTKViewer_GeometryFilter::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle)
01381 {
01382   if(myMaxArcAngle != theMaxAngle) {
01383     myMaxArcAngle = theMaxAngle;
01384     this->Modified();
01385   }
01386 }
01387 
01388 vtkFloatingPointType VTKViewer_GeometryFilter:: GetQuadraticArcAngle() const
01389 {
01390   return myMaxArcAngle;
01391 }
01392 
01393 
01394 int VTKViewer_GeometryFilter::GetAppendCoincident3D() const {
01395   return myAppendCoincident3D;
01396 }
01397 
01398 void VTKViewer_GeometryFilter::SetAppendCoincident3D(int theFlag) {
01399   if(myAppendCoincident3D != theFlag){
01400     myAppendCoincident3D = theFlag;
01401     this->Modified();
01402   }
01403 }