]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_ExtractUnstructuredGrid.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / CONVERTOR / VISU_ExtractUnstructuredGrid.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 //  VISU CONVERTOR :
23 // File:    VISU_ExtractUnstructuredGrid.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26 //
27 #include "VISU_ExtractUnstructuredGrid.hxx"
28 #include "VISU_ConvertorUtils.hxx"
29
30 #include <vtkUnstructuredGrid.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkIdList.h>
33 #include <vtkCell.h>
34 #include <vtkInformation.h>
35 #include <vtkInformationVector.h>
36
37 using namespace std;
38
39 #ifdef _DEBUG_
40 static int MYDEBUG = 0;
41 #else
42 static int MYDEBUG = 0;
43 #endif
44
45 vtkStandardNewMacro(VISU_ExtractUnstructuredGrid);
46
47 VISU_ExtractUnstructuredGrid::VISU_ExtractUnstructuredGrid(){}
48
49 VISU_ExtractUnstructuredGrid::~VISU_ExtractUnstructuredGrid(){}
50
51 void VISU_ExtractUnstructuredGrid::RemoveCell(vtkIdType theCellId){
52   myRemovedCellIds.insert(theCellId);
53   Modified();
54 }
55
56 void VISU_ExtractUnstructuredGrid::RemoveCellsWithType(vtkIdType theCellType){
57   myRemovedCellTypes.insert(theCellType);
58   Modified();
59 }
60
61 namespace{
62   inline void InsertCell(vtkUnstructuredGrid *theInput, 
63                           vtkUnstructuredGrid *theOutput,
64                           vtkIdType theCellId, vtkIdList *theCellIds)
65   {
66     theCellIds->Reset();
67     vtkCell *aCell = theInput->GetCell(theCellId);
68     vtkIdType aNbIds = aCell->PointIds->GetNumberOfIds();
69     for(vtkIdType i = 0; i < aNbIds; i++)
70       theCellIds->InsertNextId(aCell->GetPointIds()->GetId(i));
71     theOutput->InsertNextCell(theInput->GetCellType(theCellId), theCellIds);
72   }
73 }
74
75 int VISU_ExtractUnstructuredGrid::RequestData(
76   vtkInformation *vtkNotUsed(request),
77   vtkInformationVector **inputVector,
78   vtkInformationVector *outputVector)
79 {
80   // get the info objects
81   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
82   vtkInformation *outInfo = outputVector->GetInformationObject(0);
83
84   // get the input and ouptut
85   vtkUnstructuredGrid *anInput = vtkUnstructuredGrid::SafeDownCast(
86     inInfo->Get(vtkDataObject::DATA_OBJECT()));
87   vtkUnstructuredGrid *anOutput = vtkUnstructuredGrid::SafeDownCast(
88     outInfo->Get(vtkDataObject::DATA_OBJECT()));
89   
90
91   vtkIdType aNbCells = anInput->GetNumberOfCells();
92   anOutput->Allocate(aNbCells);
93   MSG(MYDEBUG,"Execute - anInput->GetNumberOfCells() = "<<anInput->GetNumberOfCells());
94   vtkIdList *aCellIds = vtkIdList::New();
95   MSG(MYDEBUG,"Execute - myRemovedCellIds.empty() = "<<myRemovedCellIds.empty()<<
96       "; myRemovedCellTypes.empty() = "<<myRemovedCellTypes.empty());
97   if(myRemovedCellIds.empty() && myRemovedCellTypes.empty())
98     anOutput->CopyStructure(anInput);
99   else if(!myRemovedCellIds.empty() && myRemovedCellTypes.empty()){
100     for(vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++)
101       if(myRemovedCellIds.find(aCellId) == myRemovedCellIds.end())
102         InsertCell(anInput,anOutput,aCellId,aCellIds);
103   }else if(myRemovedCellIds.empty() && !myRemovedCellTypes.empty()){
104     for(vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++)
105       if(myRemovedCellTypes.find(anInput->GetCellType(aCellId)) == myRemovedCellTypes.end())
106         InsertCell(anInput,anOutput,aCellId,aCellIds);
107   }else if(!myRemovedCellIds.empty() && !myRemovedCellTypes.empty())
108     for(vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++)
109       if(myRemovedCellTypes.find(anInput->GetCellType(aCellId)) == myRemovedCellTypes.end())
110         if(myRemovedCellIds.find(aCellId) == myRemovedCellIds.end())
111           InsertCell(anInput,anOutput,aCellId,aCellIds);
112   aCellIds->Delete();
113   anOutput->SetPoints(anInput->GetPoints());
114   MSG(MYDEBUG,"Execute - anOutput->GetNumberOfCells() = "<<anOutput->GetNumberOfCells());
115   
116   return 1;
117 }