291 if (this->
nextGrid == 0) firstSet = 1;
293 vtkUnstructuredGrid *newUgrid = vtkUnstructuredGrid::SafeDownCast(
set);
298 vtkCellArray *newCellArray = newUgrid->GetCells();
299 vtkIdType *newCells = newCellArray->GetPointer();
300 vtkIdType *newLocs = newUgrid->GetCellLocationsArray()->GetPointer(0);
301 unsigned char *newTypes = newUgrid->GetCellTypesArray()->GetPointer(0);
303 int newNumCells = newUgrid->GetNumberOfCells();
304 int newNumConnections = newCellArray->GetData()->GetNumberOfTuples();
309 vtkIdList *duplicateCellIds = NULL;
310 int numDuplicateCells = 0;
311 int numDuplicateConnections = 0;
321 for (
id = 0;
id < newNumCells;
id++) {
324 std::pair<std::map<vtkIdType, vtkIdType>::iterator,
bool> inserted =
327 std::map<vtkIdType, vtkIdType>::value_type(globalId,
330 if (inserted.second) {
333 duplicateCellIds->InsertNextId(
id);
336 int npoints = newCells[newLocs[
id]];
338 numDuplicateConnections += (npoints + 1);
342 if (numDuplicateCells == 0) {
343 duplicateCellIds->Delete();
344 duplicateCellIds = NULL;
351 vtkCellArray *cellArray = NULL;
352 vtkIdType *cells = NULL;
353 vtkIdType *locs = NULL;
354 unsigned char *types = NULL;
357 int numConnections = 0;
360 cellArray = Ugrid->GetCells();
361 cells = cellArray->GetPointer();
362 locs = Ugrid->GetCellLocationsArray()->GetPointer(0);
363 types = Ugrid->GetCellTypesArray()->GetPointer(0);
366 numCells = Ugrid->GetNumberOfCells();
367 numConnections = cellArray->GetData()->GetNumberOfTuples();
374 int totalNumCells = numCells + newNumCells - numDuplicateCells;
375 int totalNumConnections =
376 numConnections + newNumConnections - numDuplicateConnections;
379 mergedcells->SetNumberOfValues(totalNumConnections);
382 vtkIdType *idptr = mergedcells->GetPointer(0);
383 memcpy(idptr, cells,
sizeof(vtkIdType) * numConnections);
387 finalCellArray->SetCells(totalNumCells, mergedcells);
392 locationArray->SetNumberOfValues(totalNumCells);
394 vtkIdType *iptr = locationArray->GetPointer(0);
397 memcpy(iptr, locs, numCells *
sizeof(vtkIdType));
403 typeArray->SetNumberOfValues(totalNumCells);
405 unsigned char *cptr = typeArray->GetPointer(0);
408 memcpy(cptr, types, numCells *
sizeof(
unsigned char));
413 vtkIdType finalCellId = numCells;
414 vtkIdType nextCellArrayIndex =
static_cast<vtkIdType
>(numConnections);
415 vtkCellData *cellArrays =
set->GetCellData();
417 vtkIdType oldPtId, finalPtId;
419 int nextDuplicateCellId = 0;
421 for (vtkIdType oldCellId = 0; oldCellId < newNumCells; oldCellId++) {
422 vtkIdType size = *newCells++;
424 if (duplicateCellIds) {
425 vtkIdType skipId = duplicateCellIds->GetId(nextDuplicateCellId);
427 if (skipId == oldCellId) {
429 nextDuplicateCellId++;
434 locationArray->SetValue(finalCellId, nextCellArrayIndex);
436 typeArray->SetValue(finalCellId, newTypes[oldCellId]);
438 mergedcells->SetValue(nextCellArrayIndex++, size);
440 for (
id = 0;
id < size;
id++) {
441 oldPtId = *newCells++;
444 finalPtId = idMap->GetValue(oldPtId);
449 mergedcells->SetValue(nextCellArrayIndex++, finalPtId);
452 Ugrid->GetCellData()->CopyData(*(this->
cellList), cellArrays,
453 this->
nextGrid, oldCellId, finalCellId);
458 Ugrid->SetCells(typeArray, locationArray, finalCellArray);
460 mergedcells->Delete();
462 locationArray->Delete();
463 finalCellArray->Delete();
465 if (duplicateCellIds) {
466 duplicateCellIds->Delete();
vtkIdType GlobalCellIdAccessGetId(vtkIdType idx)
vtkDataSetAttributes::FieldList * cellList
int GlobalCellIdAccessStart(vtkDataSet *set)
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
vtkUnstructuredGrid * UnstructuredGrid
vtkIdType id
id in .inp file
mergeCellsSTLCloak * GlobalCellIdMap