1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
28 #include "VISU_MergeFilterUtilities.hxx"
30 #include <vtkCellData.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkPointData.h>
33 #include <vtkPolyData.h>
34 #include <vtkRectilinearGrid.h>
35 #include <vtkStructuredGrid.h>
36 #include <vtkStructuredPoints.h>
37 #include <vtkUnstructuredGrid.h>
39 #include <vtkIdList.h>
52 //---------------------------------------------------------------
53 template<class TDataSet>
56 CopyDataOnCells(TDataSet *theInput,
57 vtkIntArray *theGeometryCellMapper,
58 vtkIntArray *theDataCellMapper,
59 vtkDataSet* theScalarsDataSet,
60 vtkDataSet* theVectorsDataSet,
61 vtkDataSet* theNormalsDataSet,
62 vtkDataSet* theTCoordsDataSet,
63 vtkDataSet* theTensorsDataSet,
64 VISU::TFieldList* theFieldList,
67 if(IsDifferent(theGeometryCellMapper, theDataCellMapper)){
68 TObjectIdArray anIntersection;
69 GetIntersection(theGeometryCellMapper,
73 TObjectId2TupleIdMap aGeomObjectId2TupleIdMap;
74 GetObjectId2TupleIdMap(theGeometryCellMapper, aGeomObjectId2TupleIdMap);
76 TObjectId2TupleIdMap aDataObjectId2TupleIdMap;
77 GetObjectId2TupleIdMap(theDataCellMapper, aDataObjectId2TupleIdMap);
79 vtkCellData *aCellData = theScalarsDataSet->GetCellData();
80 vtkCellData *anOutputCellData = theOutput->GetCellData();
81 anOutputCellData->CopyAllocate(aCellData);
83 if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet)
84 anOutputCellData->CopyVectorsOff();
86 vtkIdType aNbTuples = anIntersection.size();
87 theOutput->Allocate(aNbTuples);
88 vtkIdList *aCellIds = vtkIdList::New();
89 for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
90 TObjectId& anObjectId = anIntersection[aTupleId];
91 vtkIdType aCellId = aGeomObjectId2TupleIdMap[anObjectId];
92 vtkCell *aCell = theInput->GetCell(aCellId);
94 vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
95 for(vtkIdType anId = 0; anId < aNbPointIds; anId++)
96 aCellIds->InsertNextId(aCell->GetPointIds()->GetId(anId));
97 vtkIdType aCellType = theInput->GetCellType(aCellId);
98 vtkIdType aNewCellId = theOutput->InsertNextCell(aCellType, aCellIds);
99 vtkIdType aDataCellId = aDataObjectId2TupleIdMap[anObjectId];
100 anOutputCellData->CopyData(aCellData, aDataCellId, aNewCellId);
104 theOutput->SetPoints(theInput->GetPoints());
107 theOutput->CopyStructure(theInput);
108 theOutput->GetCellData()->ShallowCopy(theScalarsDataSet->GetCellData());
110 theOutput->GetPointData()->ShallowCopy(theInput->GetPointData());
112 //If need, copy vectors data.
113 if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet){
114 bool isVectorsOnCells = theVectorsDataSet->GetCellData()->GetVectors() != NULL;
115 bool isVectorsDataOnPoints = theVectorsDataSet->GetPointData()->GetVectors() != NULL;
116 if(isVectorsOnCells) {
117 CopyVectorsOnCells(theVectorsDataSet,theOutput);
119 else if(isVectorsDataOnPoints){
120 CopyVectorsOnPoints(theVectorsDataSet,theOutput);
125 void CopyVectorsOnCells(vtkDataSet *theVectorsDataSet,
126 vtkDataSet *theOutput)
128 vtkDataArray *anInputVectors = theVectorsDataSet->GetCellData()->GetVectors();
129 vtkDataArray *anOutputVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
131 //Clear output vector data
132 theOutput->GetCellData()->SetVectors(NULL);
135 vtkIntArray* anOutputIDMapper = GetIDMapper(theOutput,
137 "VISU_CELLS_MAPPER");
139 vtkIntArray* anInputIDMapper = GetIDMapper(theVectorsDataSet,
141 "VISU_CELLS_MAPPER");
143 TObjectIdArray anIntersection;
144 GetIntersection(anOutputIDMapper,
148 vtkIdType aNbTuples = anIntersection.size();
149 anOutputVectors->SetNumberOfComponents(anInputVectors->GetNumberOfComponents());
150 anOutputVectors->SetNumberOfTuples(aNbTuples);
151 theOutput->GetCellData()->SetVectors(anOutputVectors);
152 anOutputVectors->Delete();
154 TObjectId2TupleIdMap anOutputObjectId2TupleIdMap;
155 GetObjectId2TupleIdMap(anOutputIDMapper, anOutputObjectId2TupleIdMap);
157 TObjectId2TupleIdMap anInputObjectId2TupleIdMap;
158 GetObjectId2TupleIdMap(anInputIDMapper, anInputObjectId2TupleIdMap);
160 for(vtkIdType iTupleId = 0; iTupleId < aNbTuples; iTupleId++ ){
161 TObjectId &anObjectId = anIntersection[iTupleId];
162 vtkIdType anOutputCellId = anOutputObjectId2TupleIdMap[anObjectId];
163 vtkIdType anInputCellId = anInputObjectId2TupleIdMap[anObjectId];
164 anOutputVectors->SetTuple(anOutputCellId,anInputVectors->GetTuple(anInputCellId));
168 //---------------------------------------------------------------
169 template<class TDataSet>
171 CopyDataOnPoints(TDataSet *theInput,
172 vtkIntArray *theGeometryPointMapper,
173 vtkIntArray *theDataPointMapper,
174 vtkDataSet* theScalarsDataSet,
175 vtkDataSet* theVectorsDataSet,
176 vtkDataSet* theNormalsDataSet,
177 vtkDataSet* theTCoordsDataSet,
178 vtkDataSet* theTensorsDataSet,
179 VISU::TFieldList* theFieldList,
182 if(IsDifferent(theGeometryPointMapper, theDataPointMapper)){
183 TObjectId2TupleIdMap aDataObjectId2PointIdMap;
184 GetObjectId2TupleIdMap(theDataPointMapper, aDataObjectId2PointIdMap);
186 vtkCellData *aCellData = theInput->GetCellData();
187 vtkCellData *anOutputCellData = theOutput->GetCellData();
188 anOutputCellData->CopyAllocate(aCellData);
190 vtkIdList *aCellIds = vtkIdList::New();
191 int aNbCells = theInput->GetNumberOfCells();
192 theOutput->Allocate(aNbCells);
193 for(int aCellId = 0; aCellId < aNbCells; aCellId++){
195 vtkCell *aCell = theInput->GetCell(aCellId);
196 vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
197 for(vtkIdType anId = 0; anId < aNbPointIds; anId++){
198 vtkIdType aPointId = aCell->GetPointIds()->GetId(anId);
199 int* aPointer = theGeometryPointMapper->GetPointer(aPointId * 2);
200 TCellId aCellId = *aPointer;
201 TEntityId anEntityId = *(aPointer + 1);
202 TObjectId anObjectId(aCellId, anEntityId);
203 TObjectId2TupleIdMap::iterator anIter = aDataObjectId2PointIdMap.find(anObjectId);
204 if(anIter != aDataObjectId2PointIdMap.end()){
205 aPointId = anIter->second;
206 aCellIds->InsertNextId(aPointId);
208 goto PASS_INSERT_NEXT_CELL;
211 vtkIdType aCellType = theInput->GetCellType(aCellId);
212 vtkIdType aNewCellId = theOutput->InsertNextCell(aCellType, aCellIds);
213 anOutputCellData->CopyData(aCellData, aCellId, aNewCellId);
215 PASS_INSERT_NEXT_CELL:
220 // Copy geometry points
221 // 1. Create vtkPoints instance of the same data type
222 vtkPointSet* aScalarsDataSet = dynamic_cast<vtkPointSet*>(theScalarsDataSet);
223 vtkPoints* anGeometryPoints = theInput->GetPoints();
224 vtkPoints* aDataPoints = aScalarsDataSet->GetPoints();
225 vtkPoints* anOutputPoints = vtkPoints::New(aDataPoints->GetDataType());
226 theOutput->SetPoints(anOutputPoints);
227 anOutputPoints->Delete();
229 // 2. Perform mapping of geometry points
230 TObjectId2TupleIdMap aGeomObjectId2TupleIdMap;
231 GetObjectId2TupleIdMap(theGeometryPointMapper, aGeomObjectId2TupleIdMap);
233 // 3. Loop over all data points
234 int aNbDataPoints = theDataPointMapper->GetNumberOfTuples();
235 anOutputPoints->SetNumberOfPoints(aNbDataPoints);
236 for(int aPointId = 0; aPointId < aNbDataPoints; aPointId++){
237 int* aPointer = theDataPointMapper->GetPointer(aPointId * 2);
238 TCellId aCellId = *aPointer;
239 TEntityId anEntityId = *(aPointer + 1);
240 TObjectId anObjectId(aCellId, anEntityId);
241 TObjectId2TupleIdMap::iterator anIter = aGeomObjectId2TupleIdMap.find(anObjectId);
242 if(anIter != aGeomObjectId2TupleIdMap.end()){
243 // If the point exists in the geometry put it to output
244 int aGeometryPointId = anIter->second;
245 vtkFloatingPointType aCoords[3];
246 anGeometryPoints->GetPoint(aGeometryPointId, aCoords);
247 anOutputPoints->SetPoint(aPointId, aCoords);
249 // If no, the point from data should be used
250 vtkFloatingPointType aCoords[3];
251 aDataPoints->GetPoint(aPointId, aCoords);
252 anOutputPoints->SetPoint(aPointId, aCoords);
256 theOutput->CopyStructure(theInput);
257 theOutput->GetCellData()->ShallowCopy(theInput->GetCellData());
259 theOutput->GetPointData()->ShallowCopy(theScalarsDataSet->GetPointData());
261 //If need, copy vectors data.
262 if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet){
263 bool isVectorsOnCells = theVectorsDataSet->GetCellData()->GetVectors() != NULL;
264 bool isVectorsDataOnPoints = theVectorsDataSet->GetPointData()->GetVectors() != NULL;
266 //Merge cells if need
268 if(!IsDifferent(theGeometryPointMapper, theDataPointMapper)){
269 vtkIntArray* theGeometryCellMapper = GetIDMapper(theVectorsDataSet,
271 "VISU_CELLS_MAPPER");
273 vtkIntArray* theDataCellMapper = GetIDMapper(theScalarsDataSet,
275 "VISU_CELLS_MAPPER");
278 if(IsDifferent(theGeometryCellMapper, theDataCellMapper)){
279 TObjectIdArray anIntersection;
281 GetIntersection(theGeometryCellMapper,
285 TObjectId2TupleIdMap aGeomObjectId2TupleIdMap;
286 GetObjectId2TupleIdMap(theGeometryCellMapper, aGeomObjectId2TupleIdMap);
288 TObjectId2TupleIdMap aDataObjectId2TupleIdMap;
289 GetObjectId2TupleIdMap(theDataCellMapper, aDataObjectId2TupleIdMap);
291 vtkCellData *aCellData = theScalarsDataSet->GetCellData();
292 vtkCellData *anOutputCellData = theOutput->GetCellData();
293 anOutputCellData->CopyAllocate(aCellData);
295 vtkIdType aNbTuples = anIntersection.size();
296 theOutput->Allocate(aNbTuples);
297 vtkIdList *aCellIds = vtkIdList::New();
298 for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
299 TObjectId& anObjectId = anIntersection[aTupleId];
300 vtkIdType aCellId = aGeomObjectId2TupleIdMap[anObjectId];
301 vtkCell *aCell = theInput->GetCell(aCellId);
303 vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
304 for(vtkIdType anId = 0; anId < aNbPointIds; anId++)
305 aCellIds->InsertNextId(aCell->GetPointIds()->GetId(anId));
306 vtkIdType aCellType = theInput->GetCellType(aCellId);
307 vtkIdType aNewCellId = theOutput->InsertNextCell(aCellType, aCellIds);
308 vtkIdType aDataCellId = aDataObjectId2TupleIdMap[anObjectId];
309 anOutputCellData->CopyData(aCellData, aDataCellId, aNewCellId);
316 if(isVectorsOnCells) {
317 CopyVectorsOnCells(theVectorsDataSet,theOutput);
319 else if(isVectorsDataOnPoints){
320 CopyVectorsOnPoints(theVectorsDataSet,theOutput);
325 void CopyVectorsOnPoints(vtkDataSet *theVectorsDataSet,
326 vtkDataSet *theOutput)
328 vtkDataArray *anInputVectors = theVectorsDataSet->GetPointData()->GetVectors();
330 //Clear output vector data
331 theOutput->GetPointData()->SetVectors(NULL);
333 vtkDataArray *anOutputVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
336 vtkIntArray* anOutputIDMapper = GetIDMapper(theOutput,
338 "VISU_POINTS_MAPPER");
340 vtkIntArray* anInputIDMapper = GetIDMapper(theVectorsDataSet,
342 "VISU_POINTS_MAPPER");
343 TObjectIdArray anIntersection;
345 GetIntersection(anOutputIDMapper,
349 vtkIdType aNbTuples = anIntersection.size();
350 anOutputVectors->SetNumberOfComponents(anInputVectors->GetNumberOfComponents());
351 anOutputVectors->SetNumberOfTuples(aNbTuples);
355 TObjectId2TupleIdMap anOutputObjectId2TupleIdMap;
356 GetObjectId2TupleIdMap(anOutputIDMapper, anOutputObjectId2TupleIdMap);
358 TObjectId2TupleIdMap anInputObjectId2TupleIdMap;
359 GetObjectId2TupleIdMap(anInputIDMapper, anInputObjectId2TupleIdMap);
361 for(vtkIdType iTupleId = 0; iTupleId < aNbTuples; iTupleId++ ){
362 TObjectId& anObjectId = anIntersection[iTupleId];
363 vtkIdType anOutputPointId = anOutputObjectId2TupleIdMap[anObjectId];
364 vtkIdType anInputPointId = anInputObjectId2TupleIdMap[anObjectId];
365 anOutputVectors->SetTuple(anOutputPointId,anInputVectors->GetTuple(anInputPointId));
368 theOutput->GetPointData()->SetVectors(anOutputVectors);
369 anOutputVectors->Delete();
373 //---------------------------------------------------------------
374 typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)();
375 typedef int (vtkDataSetAttributes::* TSetAttribute)(vtkDataArray*);
379 CopyArray(vtkDataArray* theDataArray,
380 vtkDataSetAttributes* theOutput,
381 TSetAttribute theSetAttribute,
382 vtkIdType theFixedNbTuples)
385 vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
386 if(theFixedNbTuples == aNbTuples)
387 (theOutput->*theSetAttribute)(theDataArray);
392 //---------------------------------------------------------------
395 CopyAttribute(vtkDataSetAttributes* theInput,
396 TGetAttribute theGetAttribute,
397 vtkDataSetAttributes* theOutput,
398 TSetAttribute theSetAttribute,
399 vtkIdType theFixedNbTuples)
401 CopyArray((theInput->*theGetAttribute)(),
402 theOutput, theSetAttribute,
407 //---------------------------------------------------------------
410 CopyDataSetAttribute(vtkDataSet *theInput,
411 TGetAttribute theGetAttribute,
412 vtkDataSet *theOutput,
413 TSetAttribute theSetAttribute,
414 vtkIdType theNbPoints,
415 vtkIdType theNbCells)
417 CopyAttribute(theInput->GetPointData(),
419 theOutput->GetPointData(),
422 CopyAttribute(theInput->GetCellData(),
424 theOutput->GetCellData(),
430 //---------------------------------------------------------------
433 CopyField(vtkDataSetAttributes* theInput,
434 const char* theFieldName,
435 vtkDataSetAttributes* theOutput,
436 vtkIdType theFixedNbTuples)
438 CopyArray(theInput->GetArray(theFieldName),
440 &vtkDataSetAttributes::AddArray,
445 //---------------------------------------------------------------
448 CopyDataSetField(vtkDataSet* theInput,
449 const char* theFieldName,
450 vtkDataSet* theOutput,
451 vtkIdType theNbPoints,
452 vtkIdType theNbCells)
455 CopyField(theInput->GetPointData(),
457 theOutput->GetPointData(),
459 CopyField(theInput->GetCellData(),
461 theOutput->GetCellData(),
466 //---------------------------------------------------------------
468 BasicExecute(vtkDataSet *theInput,
469 vtkDataSet* theScalarsDataSet,
470 vtkDataSet* theVectorsDataSet,
471 vtkDataSet* theNormalsDataSet,
472 vtkDataSet* theTCoordsDataSet,
473 vtkDataSet* theTensorsDataSet,
474 VISU::TFieldList* theFieldList,
475 vtkDataSet *theOutput)
477 theOutput->CopyStructure(theInput);
479 vtkIdType aNbPoints = theInput->GetNumberOfPoints();
480 vtkIdType aNbCells = theInput->GetNumberOfCells();
482 // merge data only if it is consistent
483 if(theScalarsDataSet)
484 CopyDataSetAttribute(theScalarsDataSet,
485 &vtkDataSetAttributes::GetScalars,
487 &vtkDataSetAttributes::SetScalars,
491 if(theVectorsDataSet)
492 CopyDataSetAttribute(theVectorsDataSet,
493 &vtkDataSetAttributes::GetVectors,
495 &vtkDataSetAttributes::SetVectors,
499 if(theNormalsDataSet)
500 CopyDataSetAttribute(theNormalsDataSet,
501 &vtkDataSetAttributes::GetNormals,
503 &vtkDataSetAttributes::SetNormals,
507 if(theTCoordsDataSet)
508 CopyDataSetAttribute(theTCoordsDataSet,
509 &vtkDataSetAttributes::GetTCoords,
511 &vtkDataSetAttributes::SetTCoords,
515 if(theTensorsDataSet)
516 CopyDataSetAttribute(theTensorsDataSet,
517 &vtkDataSetAttributes::GetTensors,
519 &vtkDataSetAttributes::SetTensors,
523 VISU::TFieldListIterator anIter(theFieldList);
524 for(anIter.Begin(); !anIter.End() ; anIter.Next()){
525 vtkDataSet *aDataSet = anIter.Get()->Ptr;
526 const char* aFieldName = anIter.Get()->GetName();
527 CopyDataSetField(aDataSet,
536 //---------------------------------------------------------------
537 template<class TDataSet>
539 Execute(TDataSet *theInput,
540 vtkDataSet* theScalarsDataSet,
541 vtkDataSet* theVectorsDataSet,
542 vtkDataSet* theNormalsDataSet,
543 vtkDataSet* theTCoordsDataSet,
544 vtkDataSet* theTensorsDataSet,
545 VISU::TFieldList* theFieldList,
546 bool theIsMergingInputs,
549 if(theIsMergingInputs){
550 vtkCellData *aCellData = theInput->GetCellData();
551 if(vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER")){
552 bool anIsDataOnCells = false;
553 if(vtkDataSet* aDataSet = theScalarsDataSet)
554 if(vtkCellData* aCellData = aDataSet->GetCellData())
555 anIsDataOnCells = (aCellData->GetArray("VISU_FIELD") != NULL);
557 vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
558 vtkIntArray* aDataCellMapper = GetIDMapper(theFieldList,
560 "VISU_CELLS_MAPPER");
561 CopyDataOnCells(theInput,
572 vtkPointData *aPointData = theInput->GetPointData();
573 vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
574 vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
575 vtkIntArray* aDataPointMapper = GetIDMapper(theFieldList,
577 "VISU_POINTS_MAPPER");
578 CopyDataOnPoints(theInput,
579 aGeometryPointMapper,
591 BasicExecute(theInput,
607 //---------------------------------------------------------------
609 GetObjectIdSet(vtkIntArray *theArray,
610 TObjectIdSet& theObjectIdSet)
612 theObjectIdSet.clear();
613 int aMaxId = theArray->GetMaxId();
614 int* aPointer = theArray->GetPointer(0);
615 int* anEndPointer = theArray->GetPointer(aMaxId + 1);
616 for(; aPointer != anEndPointer; aPointer += 2){
617 TCellId aCellId = *aPointer;
618 TEntityId anEntityId = *(aPointer + 1);
619 TObjectId anObjectId(aCellId, anEntityId);
620 theObjectIdSet.insert(anObjectId);
625 //---------------------------------------------------------------
627 GetObjectId2TupleIdMap(vtkIntArray *theArray,
628 TObjectId2TupleIdMap& theObjectId2TupleIdMap)
630 theObjectId2TupleIdMap.clear();
631 int* aPointer = theArray->GetPointer(0);
632 int aNbTuples = theArray->GetNumberOfTuples();
633 for(vtkIdType aTupleId = 0; aTupleId < aNbTuples; aTupleId++, aPointer += 2){
634 TCellId aCellId = *aPointer;
635 TEntityId anEntityId = *(aPointer + 1);
636 TObjectId anObjectId(aCellId, anEntityId);
637 theObjectId2TupleIdMap[anObjectId] = aTupleId;
641 //---------------------------------------------------------------
643 GetObjectId2TupleGaussIdArray(vtkIntArray *theArray,
644 TObjectId2TupleGaussIdMap& theObjectId2TupleGaussIdMap)
646 theObjectId2TupleGaussIdMap.clear();
647 int* aPointer = theArray->GetPointer(0);
648 int aNbTuples = theArray->GetNumberOfTuples();
649 for(vtkIdType aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
650 int aCellId = *aPointer;
651 TObjectId2TupleGaussIdMap::iterator it = theObjectId2TupleGaussIdMap.find(aCellId);
652 if(it == theObjectId2TupleGaussIdMap.end()){
653 TCellIdArray anIdArray;
654 anIdArray.push_back(aTupleId);
655 theObjectId2TupleGaussIdMap.insert(make_pair(aCellId,anIdArray));
658 (*it).second.push_back(aTupleId);
664 //---------------------------------------------------------------
665 template<class TGetFieldData>
667 GetIDMapper(VISU::TFieldList* theFieldList,
668 TGetFieldData theGetFieldData,
669 const char* theFieldName)
671 VISU::TFieldListIterator anIter(theFieldList);
672 for(anIter.Begin(); !anIter.End() ; anIter.Next()){
673 const char* aFieldName = anIter.Get()->GetName();
674 if(strcmp(aFieldName, theFieldName) == 0){
675 vtkDataSet* aDataSet = anIter.Get()->Ptr;
676 vtkFieldData *aFieldData = theGetFieldData(aDataSet);
677 vtkDataArray *anIDMapper = aFieldData->GetArray(theFieldName);
678 return dynamic_cast<vtkIntArray*>(anIDMapper);
685 //---------------------------------------------------------------
686 template<class TGetFieldData>
688 GetIDMapper(vtkDataSet* theIDMapperDataSet,
689 TGetFieldData theGetFieldData,
690 const char* theFieldName)
692 vtkFieldData *aFieldData = theGetFieldData(theIDMapperDataSet);
693 vtkDataArray *anIDMapper = aFieldData->GetArray(theFieldName);
694 return dynamic_cast<vtkIntArray*>(anIDMapper);
698 //---------------------------------------------------------------
700 IsDifferent(vtkIntArray *theFirstIDMapper,
701 vtkIntArray *theSecondIDMapper)
703 vtkIdType aFirstNbTuples = theFirstIDMapper->GetNumberOfTuples();
704 vtkIdType aSecondNbTuples = theSecondIDMapper->GetNumberOfTuples();
705 if(aFirstNbTuples != aSecondNbTuples)
708 int aMaxId = theFirstIDMapper->GetMaxId();
709 int* aFirstPointer = theFirstIDMapper->GetPointer(0);
710 int* aSecondPointer = theSecondIDMapper->GetPointer(0);
711 for(int anId = 0; anId <= aMaxId; anId++){
712 if(*aFirstPointer++ != *aSecondPointer++)
720 //---------------------------------------------------------------
722 GetIntersection(vtkIntArray *theFirstIDMapper,
723 vtkIntArray *theSecondIDMapper,
724 TObjectIdArray& theResult)
726 TObjectIdSet aFirstObjectIdSet;
727 GetObjectIdSet(theFirstIDMapper, aFirstObjectIdSet);
729 TObjectIdSet aSecondObjectIdSet;
730 GetObjectIdSet(theSecondIDMapper, aSecondObjectIdSet);
732 size_t aMaxLength = std::max(aFirstObjectIdSet.size(), aSecondObjectIdSet.size());
733 theResult.resize(aMaxLength);
734 TObjectIdArray::iterator anArrayIter = theResult.begin();
735 anArrayIter = std::set_intersection(aFirstObjectIdSet.begin(),
736 aFirstObjectIdSet.end(),
737 aSecondObjectIdSet.begin(),
738 aSecondObjectIdSet.end(),
740 theResult.erase(anArrayIter, theResult.end());
743 //---------------------------------------------------------------
745 Execute(vtkUnstructuredGrid *theInput,
746 vtkUnstructuredGrid *theOutput,
747 vtkDataSet* theScalarsDataSet,
748 vtkDataSet* theVectorsDataSet,
749 vtkDataSet* theNormalsDataSet,
750 vtkDataSet* theTCoordsDataSet,
751 vtkDataSet* theTensorsDataSet,
752 TFieldList* theFieldList,
753 bool theIsMergingInputs)
755 return ::Execute(theInput,
767 //---------------------------------------------------------------
769 Execute(vtkPolyData *theInput,
770 vtkPolyData *theOutput,
771 vtkDataSet* theScalarsDataSet,
772 vtkDataSet* theVectorsDataSet,
773 vtkDataSet* theNormalsDataSet,
774 vtkDataSet* theTCoordsDataSet,
775 vtkDataSet* theTensorsDataSet,
776 TFieldList* theFieldList,
777 bool theIsMergingInputs)
779 return ::Execute(theInput,