vtkDataSetRemoveGhostCells.C 25.7 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkDataSetRemoveGhostCells.C,v $
  Language:  C++
  Date:      $Date: 2001/05/01 20:49:40 $
  Version:   $Revision: 1.1 $


Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
   of any contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

 * Modified source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/
#include "vtkDataSetRemoveGhostCells.h"
hrchilds's avatar
hrchilds committed
43 44

#include <vtkCellData.h>
hrchilds's avatar
hrchilds committed
45
#include <vtkCellArray.h>
46
#include <vtkExecutive.h>
hrchilds's avatar
hrchilds committed
47
#include <vtkFloatArray.h>
hrchilds's avatar
hrchilds committed
48
#include <vtkIdTypeArray.h>
49 50
#include <vtkInformation.h>
#include <vtkInformationVector.h>
hrchilds's avatar
hrchilds committed
51 52
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
hrchilds's avatar
hrchilds committed
53
#include <vtkPolyData.h>
hrchilds's avatar
hrchilds committed
54
#include <vtkRectilinearGrid.h>
hrchilds's avatar
hrchilds committed
55
#include <vtkStructuredGrid.h>
hrchilds's avatar
hrchilds committed
56 57
#include <vtkUnsignedCharArray.h>
#include <vtkUnstructuredGrid.h>
hrchilds's avatar
hrchilds committed
58

hrchilds's avatar
hrchilds committed
59
#include <vtkVisItUtility.h>
hrchilds's avatar
hrchilds committed
60 61
#include <vtkVisItExtractGrid.h>
#include <vtkVisItExtractRectilinearGrid.h>
hrchilds's avatar
hrchilds committed
62

63 64
#include <avtGhostData.h>

hrchilds's avatar
hrchilds committed
65 66 67 68 69 70 71
//------------------------------------------------------------------------------
// Modifications:
//   Kathleen Bonnell, Wed Mar  6 13:48:48 PST 2002
//   Use vtk Macro instead of old New method.
//------------------------------------------------------------------------------
vtkStandardNewMacro(vtkDataSetRemoveGhostCells);

hrchilds's avatar
hrchilds committed
72 73

// ****************************************************************************
74 75
//  Purpose:
//    Construct with ghost level = 1.
hrchilds's avatar
hrchilds committed
76
//
77 78 79
//  Modifications:
//    Hank Childs, Mon Aug 30 16:27:16 PDT 2004
//    Remove references to ghost level, since it is no longer a data member.
hrchilds's avatar
hrchilds committed
80
//
81 82
//    Hank Childs, Fri Aug  3 16:56:36 PDT 2007
//    Initialize GhostNodeTypesToRemove.
83
//
84 85
//    Hank Childs, Sun Oct 28 10:48:50 PST 2007
//    Initialize GhostZoneTypesToRemove.
hrchilds's avatar
hrchilds committed
86
//
hrchilds's avatar
hrchilds committed
87 88
// ****************************************************************************

hrchilds's avatar
hrchilds committed
89 90
vtkDataSetRemoveGhostCells::vtkDataSetRemoveGhostCells()
{
91
    GhostNodeTypesToRemove = 255;
hrchilds's avatar
hrchilds committed
92
    GhostZoneTypesToRemove = 255;
hrchilds's avatar
hrchilds committed
93 94 95
}


96 97 98 99 100 101
// ****************************************************************************
//  Modifications:
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
// ****************************************************************************
hrchilds's avatar
hrchilds committed
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
int
vtkDataSetRemoveGhostCells::RequestData(
    vtkInformation *vtkNotUsed(request),
    vtkInformationVector **inputVector,
    vtkInformationVector *outputVector)
{
    // get the info objects
    vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
    vtkInformation *outInfo = outputVector->GetInformationObject(0);

    //
    // Initialize some frequently used values.
    //
    input  = vtkDataSet::SafeDownCast(
        inInfo->Get(vtkDataObject::DATA_OBJECT()));
    output = vtkDataSet::SafeDownCast(
        outInfo->Get(vtkDataObject::DATA_OBJECT()));

    switch(input->GetDataObjectType())
    {
hrchilds's avatar
hrchilds committed
123
      case VTK_RECTILINEAR_GRID :
124 125 126
        RectilinearGridExecute();
        break;

hrchilds's avatar
hrchilds committed
127
      case VTK_POLY_DATA :
128 129
        PolyDataExecute();
        break;
hrchilds's avatar
hrchilds committed
130 131

      case VTK_UNSTRUCTURED_GRID :
132 133
        UnstructuredGridExecute();
        break;
hrchilds's avatar
hrchilds committed
134 135

      case VTK_STRUCTURED_GRID :
136 137
        StructuredGridExecute();
        break;
hrchilds's avatar
hrchilds committed
138 139

      default: 
140 141 142 143 144 145 146
        vtkDebugMacro(<<"vtkDataSetRemoveGhostCells not set up to "
                        "operate on this data type" );
        output->DeepCopy(input); 
        break;
    }

    return 1;
hrchilds's avatar
hrchilds committed
147 148
}

149

hrchilds's avatar
hrchilds committed
150 151 152 153 154
// ****************************************************************************
//  Modifications:
//    Hank Childs, Thu Mar  2 11:14:53 PST 2006
//    Created.
//
hrchilds's avatar
hrchilds committed
155 156 157
//    Hank Childs, Fri Jun  9 12:54:36 PDT 2006
//    Remove unused variables.
//
158 159 160 161 162
//    Jeremy Meredith, Tue Oct 14 15:30:07 EDT 2008
//    Moved the count of the number of output cells up sooner, and
//    use it to determine if all the cells are selected -- and if they
//    are, then just short-circuit out.
//
163 164 165
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
hrchilds's avatar
hrchilds committed
166 167
// ****************************************************************************

168 169
void
vtkDataSetRemoveGhostCells::GenericExecute()
hrchilds's avatar
hrchilds committed
170 171 172
{
    int  i;

173
    vtkDataSet *ds = input;
hrchilds's avatar
hrchilds committed
174 175 176
    vtkDataArray *arr = ds->GetCellData()->GetArray("avtGhostZones");
    if (arr == NULL)
    {
177
        output->ShallowCopy(ds);
hrchilds's avatar
hrchilds committed
178 179
        return;
    }
180 181 182 183 184 185 186 187 188
    int nOut = 0;
    int nCells = ds->GetNumberOfCells();
    for (i = 0 ; i < nCells ; i++)
        if (arr->GetTuple1(i) == 0)
            nOut++;

    // If *all* the cells are selected, exit early, returning the input
    if (nOut == nCells)
    {
189
        output->ShallowCopy(ds);
190 191
        return;
    }
hrchilds's avatar
hrchilds committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
     
    vtkPoints *ptsObj = vtkVisItUtility::GetPoints(ds);
    vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
    ugrid->SetPoints(ptsObj);
    ptsObj->Delete();
    ugrid->GetPointData()->ShallowCopy(ds->GetPointData());
    ugrid->Allocate(8*nOut);
   
    int cellId = 0;
    vtkCellData *inCD  = ds->GetCellData();
    vtkCellData *outCD = ugrid->GetCellData();
    outCD->CopyAllocate(inCD, nOut);
    vtkIdList *ptList = vtkIdList::New();
    for (i = 0 ; i < nCells ; i++)
    {
        if (arr->GetTuple1(i) != 0)
            continue;
   
        ds->GetCellPoints(i, ptList);
        int type = ds->GetCellType(i);
        ugrid->InsertNextCell(type, ptList);
        outCD->CopyData(inCD, i, cellId++);
    }
    ptList->Delete();

    ugrid->Squeeze();
218
    this->GetExecutive()->SetOutputData(0, ugrid);
hrchilds's avatar
hrchilds committed
219 220 221 222
    ugrid->Delete();
}


hrchilds's avatar
hrchilds committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236
// ***************************************************************************
//  Modifications:
//    Kathleen Bonnell, Fri Aug 31 08:50:30 PDT 2001
//    Removed check of field data.  No longer necessary with new vtk.
//
//    Hank Childs, Fri Oct 19 08:33:28 PDT 2001
//    Fix memory leak.
//
//    Hank Childs, Sat Jun 29 16:27:41 PDT 2002
//    Copy over field data.
//
//    Kathleen Bonnell, Wed Jul 10 16:02:56 PDT 2002 
//    Reworked code to utilize vtk RemoveGhostCells method. 
//
hrchilds's avatar
hrchilds committed
237 238 239 240
//    Hank Childs, Thu Aug 26 10:53:28 PDT 2004
//    Renamed ghost arrays.  Added logic to remove cells that are ghosted,
//    since we can no longer use VTK's routine.
//
hrchilds's avatar
hrchilds committed
241 242 243
//    Hank Childs, Sun Oct 28 10:48:50 PST 2007
//    Added support for GhostZoneTypesToRemove.
//
244 245 246 247 248
//    Hank Childs & Cyrus Harrison, Mon Jan 14 08:36:03 PST 2008
//    Removed shallow copy of input dataset b/c this would copy the links
//    (if they existed) potentially providing bogus connectivity info after
//    the ghost zones were removed.
//
249 250 251
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
hrchilds's avatar
hrchilds committed
252 253
// ****************************************************************************

254 255
void
vtkDataSetRemoveGhostCells::UnstructuredGridExecute()
hrchilds's avatar
hrchilds committed
256
{
hrchilds's avatar
hrchilds committed
257 258
  vtkIdType i;

hrchilds's avatar
hrchilds committed
259 260
  vtkDebugMacro(<< "Executing remove ghost cells filter for unstructured grid");
 
261 262
  vtkUnstructuredGrid *inGrid  = (vtkUnstructuredGrid*)input;
  vtkUnstructuredGrid *outGrid = (vtkUnstructuredGrid*)output;
hrchilds's avatar
hrchilds committed
263
 
264 265 266 267
  outGrid->vtkPointSet::ShallowCopy(inGrid);
  outGrid->SetPoints(inGrid->GetPoints());
  outGrid->GetPointData()->ShallowCopy(inGrid->GetPointData());
  outGrid->GetFieldData()->ShallowCopy(inGrid->GetFieldData());
hrchilds's avatar
hrchilds committed
268

269
  vtkDataArray *arr = inGrid->GetCellData()->GetArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
270
  if (arr == NULL)
271
  {
272 273 274
      outGrid->GetCellData()->ShallowCopy(inGrid->GetCellData());
      outGrid->SetCells(inGrid->GetCellTypesArray(),
                        inGrid->GetCellLocationsArray(), inGrid->GetCells());
hrchilds's avatar
hrchilds committed
275
      return;
276
  }
hrchilds's avatar
hrchilds committed
277 278 279 280 281 282 283
  if (arr->GetDataType() != VTK_UNSIGNED_CHAR)
  {
      vtkErrorMacro("Can only operate on unsigned char ghost data");
      return;
  }
  vtkUnsignedCharArray *ghosts = (vtkUnsignedCharArray *) arr;

284 285
  vtkIdType ncells = inGrid->GetNumberOfCells();
  int totalSize = inGrid->GetCells()->GetSize();
hrchilds's avatar
hrchilds committed
286 287 288 289 290 291 292 293 294

  // Over-allocate for now.
  vtkIdType *buff = new vtkIdType[totalSize];
  vtkIdType *b = buff;

  vtkUnsignedCharArray *cellTypes = vtkUnsignedCharArray::New();
  cellTypes->SetNumberOfValues(ncells);
  unsigned char *ct = cellTypes->GetPointer(0);

hrchilds's avatar
hrchilds committed
295
  vtkIdTypeArray *cellLocations = vtkIdTypeArray::New();
hrchilds's avatar
hrchilds committed
296
  cellLocations->SetNumberOfValues(ncells);
297
  vtkIdType *cl = cellLocations->GetPointer(0);
hrchilds's avatar
hrchilds committed
298

299 300
  vtkCellData *inCD = inGrid->GetCellData();
  vtkCellData *outCD = outGrid->GetCellData();
hrchilds's avatar
hrchilds committed
301 302 303 304 305
  outCD->CopyAllocate(inCD, ncells);
  int currentIndex = 0;
  vtkIdType cellId = 0;
  for (i = 0 ; i < ncells ; i++)
  {
hrchilds's avatar
hrchilds committed
306 307
      unsigned char effectiveVal =ghosts->GetValue(i) & GhostZoneTypesToRemove;
      if (avtGhostData::IsGhostZone(effectiveVal))
hrchilds's avatar
hrchilds committed
308 309 310 311
          continue;

      vtkIdType npts;
      vtkIdType *pts;
312 313
      inGrid->GetCellPoints(i, npts, pts);
      *ct++ = inGrid->GetCellType(i);
hrchilds's avatar
hrchilds committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
      *cl++ = currentIndex;
      *b++ = npts;
      currentIndex += npts+1;
      for (vtkIdType j = 0 ; j < npts ; j++)
          *b++ = pts[j];
      outCD->CopyData(inCD, i, cellId++);
  }

  // We copied all of the cell information into a buffer.  Now that we know
  // the correct size, copy it into a properly typed VTK object.
  vtkIdTypeArray *nlist = vtkIdTypeArray::New();
  nlist->SetNumberOfValues(currentIndex);
  vtkIdType *nl = nlist->GetPointer(0);
  for (i = 0 ; i < currentIndex ; i++) 
      nl[i] = buff[i];
  delete [] buff;

  vtkCellArray *cells = vtkCellArray::New();
  cells->SetCells(cellId, nlist);
  nlist->Delete();

335
  outGrid->SetCells(cellTypes, cellLocations, cells);
hrchilds's avatar
hrchilds committed
336 337 338 339
  cellTypes->Delete();
  cellLocations->Delete();
  cells->Delete();

340
  outGrid->Squeeze();
hrchilds's avatar
hrchilds committed
341
  if (GhostZoneTypesToRemove == 255)
342
    outGrid->GetCellData()->RemoveArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
}


// ***************************************************************************
//  Modifications:
//    Kathleen Bonnell, Fri Aug 31 08:50:30 PDT 2001
//    Removed check of field data, as it is no longer necessary with VTK 4.0 
//    Made pts of type vtkIdType to match VTK 4.0 API.
//
//    Hank Childs, Sat Jun 29 16:27:41 PDT 2002
//    Copy over field data.
//
//    Kathleen Bonnell, Wed Jul 10 16:02:56 PDT 2002 
//    Reworked code to utilize vtk RemoveGhostCells method. 
//
//    Hank Childs, Fri Sep 13 20:19:52 PDT 2002
//    Reverted back to removing ghost zones by hand since the VTK
//    implementation is buggy.
//
hrchilds's avatar
hrchilds committed
362 363 364
//    Hank Childs, Sun Jun 27 09:49:22 PDT 2004
//    Account for ghost nodes as well as ghost zones.
//
hrchilds's avatar
hrchilds committed
365 366 367 368 369 370 371 372 373 374 375 376
//    Jeremy Meredith, Wed Jul 21 17:37:09 PDT 2004
//    I added a new value for ghost nodes that has new meaning.  Specifically
//    *all* nodes had to be nonzero in a cell for that cell to be removed.
//    With my changes, if *any* node for a cell is "2", then that cell is
//    removed.  This is consistent with the concept of IBLANKing for nodal
//    data, because when a nodal value is meant to be hidden, you must remove
//    any cells that contain that node.  There are other uses for ghost
//    nodes, in particular for removing the polygons between domains.  See
//    http://www.nas.nasa.gov/FAST/RND-93-010.walatka-clucas/htmldocs/chp5.file_io.html
//    for a discussion of this -- the relevant pieces have been pasted into
//    avtOVERFLOWFileFormat::GetMesh.
//
hrchilds's avatar
hrchilds committed
377 378 379 380 381 382
//    Hank Childs, Wed Aug 11 15:33:31 PDT 2004
//    Allow for the presence of both ghost zones and ghost nodes.  This can
//    happen when ghost zones are created by the database and then ghost nodes
//    are created by the reflect filter, for example.  Also remove ghost nodes
//    array when we are done with it, since it just slows down processing.
//
hrchilds's avatar
hrchilds committed
383 384 385
//    Hank Childs, Fri Aug 27 15:10:50 PDT 2004
//    Use the new ghost data names.
//
386 387 388
//    Hank Childs, Fri Aug  3 13:34:38 PDT 2007
//    Added support for GhostNodeTypesToRemove.
//
hrchilds's avatar
hrchilds committed
389 390 391
//    Hank Childs, Sun Oct 28 10:48:50 PST 2007
//    Added support for GhostZoneTypesToRemove.
//
392 393 394
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
hrchilds's avatar
hrchilds committed
395 396
// ***************************************************************************

397 398
void
vtkDataSetRemoveGhostCells::PolyDataExecute()
hrchilds's avatar
hrchilds committed
399
{
400 401
  vtkPolyData *inGrid  = (vtkPolyData*)input;
  vtkPolyData *outGrid = (vtkPolyData*)output;
hrchilds's avatar
hrchilds committed
402

hrchilds's avatar
hrchilds committed
403
  vtkUnsignedCharArray *ghost_zones = (vtkUnsignedCharArray *)
404
                            inGrid->GetCellData()->GetArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
405

hrchilds's avatar
hrchilds committed
406
  vtkUnsignedCharArray *ghost_nodes = (vtkUnsignedCharArray *)
407
                            inGrid->GetPointData()->GetArray("avtGhostNodes");
hrchilds's avatar
hrchilds committed
408 409

  if ((ghost_zones == NULL) && (ghost_nodes == NULL))
hrchilds's avatar
hrchilds committed
410
    {
411
    outGrid->ShallowCopy(inGrid);
hrchilds's avatar
hrchilds committed
412 413 414
    return;
    }

415 416 417
  outGrid->SetPoints(inGrid->GetPoints());
  outGrid->GetPointData()->PassData(inGrid->GetPointData());
  outGrid->GetFieldData()->PassData(inGrid->GetFieldData());
hrchilds's avatar
hrchilds committed
418

419 420
  vtkCellData *inCD  = inGrid->GetCellData();
  vtkCellData *outCD = outGrid->GetCellData();
hrchilds's avatar
hrchilds committed
421 422
  outCD->CopyAllocate(inCD);
 
hrchilds's avatar
hrchilds committed
423
  bool usingGhostZones = (ghost_zones != NULL);
hrchilds's avatar
hrchilds committed
424
  bool usingGhostNodes = (ghost_nodes != NULL);
hrchilds's avatar
hrchilds committed
425 426 427 428
  unsigned char *zone_ptr = NULL;
  unsigned char *node_ptr = NULL;
  if (usingGhostZones)
    zone_ptr = ghost_zones->GetPointer(0);
hrchilds's avatar
hrchilds committed
429
  if (usingGhostNodes)
hrchilds's avatar
hrchilds committed
430 431
    node_ptr = ghost_nodes->GetPointer(0);

432 433 434
  int nCells = inGrid->GetNumberOfCells();
  outGrid->Allocate(nCells);
  inGrid->BuildCells();
hrchilds's avatar
hrchilds committed
435 436 437 438 439
  vtkIdType npts;
  vtkIdType *pts;
  int cell = 0;
  for (int i = 0 ; i < nCells ; i++)
    {
hrchilds's avatar
hrchilds committed
440
    if (usingGhostZones)
hrchilds's avatar
hrchilds committed
441
      {
hrchilds's avatar
hrchilds committed
442 443
      unsigned char effectiveVal = zone_ptr[i] & GhostZoneTypesToRemove;
      if (avtGhostData::IsGhostZone(effectiveVal))
hrchilds's avatar
hrchilds committed
444 445 446
        {
        continue;
        }
hrchilds's avatar
hrchilds committed
447
      }
hrchilds's avatar
hrchilds committed
448

449
    inGrid->GetCellPoints(i, npts, pts);
hrchilds's avatar
hrchilds committed
450

hrchilds's avatar
hrchilds committed
451
    if (usingGhostNodes)
hrchilds's avatar
hrchilds committed
452
      {
453 454
      bool haveOneRealNode = false;
      bool haveOneRemovedNode = false;
hrchilds's avatar
hrchilds committed
455 456
      for (int j = 0 ; j < npts ; j++)
        {
457 458 459 460 461
        unsigned char effectiveVal = node_ptr[pts[j]] & GhostNodeTypesToRemove;
        if (!avtGhostData::DiscardFaceIfAllNodesAreOfThisType(effectiveVal))
            haveOneRealNode = true;
        if (avtGhostData::DiscardFaceIfOneNodeIsOfThisType(effectiveVal))
            haveOneRemovedNode = true;
hrchilds's avatar
hrchilds committed
462
        }
463
      if (!haveOneRealNode || haveOneRemovedNode)
hrchilds's avatar
hrchilds committed
464 465 466
        continue;
      }

467
    outGrid->InsertNextCell(inGrid->GetCellType(i), npts, pts);
hrchilds's avatar
hrchilds committed
468 469
    outCD->CopyData(inCD, i, cell++);
    }
hrchilds's avatar
hrchilds committed
470
  if (GhostZoneTypesToRemove == 255)
471 472 473
    outGrid->GetCellData()->RemoveArray("avtGhostZones");
  outGrid->GetPointData()->RemoveArray("avtGhostNodes");
  outGrid->Squeeze();
hrchilds's avatar
hrchilds committed
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
}


// ***************************************************************************
//  Modifications:
//    Kathleen Bonnell, Fri Aug 31 08:50:30 PDT 2001
//    VTK 4.0 compatibility issues: Removed check of field data.  
//    Use vtkDataArray for rectilinear grid coordinates instead of vtkScalars,
//    use correct access methods for this array.
//
//    Hank Childs, Sat Jun 29 16:27:41 PDT 2002
//    Copy over field data and set the dimensions.
//
//    Kathleen Bonnell, Wed Jul 10 16:02:56 PDT 2002 
//    Reworked code to utilize vtk ExtractRectilinearGrid filter. 
//    Use new avtRealDims array.
//
hrchilds's avatar
hrchilds committed
491 492 493 494
//    Hank Childs, Sun Nov  9 13:19:45 PST 2003
//    Tell output that it doesn't have ghost zones, even if we couldn't handle
//    it correctly.  This makes the life of the wireframe filter much easier.
//
hrchilds's avatar
hrchilds committed
495 496 497
//    Hank Childs, Fri Aug 27 15:10:50 PDT 2004
//    Use the new ghost data names.
//
hrchilds's avatar
hrchilds committed
498 499 500
//    Hank Childs, Thu Mar  2 11:14:53 PST 2006
//    Call generic execute if there are no real dims.
//
hrchilds's avatar
hrchilds committed
501 502 503
//    Hank Childs, Sun Oct 28 10:56:37 PST 2007
//    Added support for GhostZoneTypesToRemove.
//
504 505 506
//    Cyrus Harrison, Fri Mar 26 15:29:47 PDT 2010
//    Guard against invalid 'avtRealDims' data.
//
507 508 509
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
510 511 512
//    Kathleen Biagas, Fri Jan 25 16:04:46 PST 2013
//    Call Update on the filter, not the data object.
//
hrchilds's avatar
hrchilds committed
513 514
// ***************************************************************************

515 516
void
vtkDataSetRemoveGhostCells::RectilinearGridExecute()
hrchilds's avatar
hrchilds committed
517
{
518 519
  vtkRectilinearGrid *inGrid  = (vtkRectilinearGrid*)input;
  vtkRectilinearGrid *outGrid = (vtkRectilinearGrid*)output;
520

521
  vtkDataArray *realDims = inGrid->GetFieldData()->GetArray("avtRealDims");
522 523 524 525 526 527 528


    bool realDimsOk = false;

    if(realDims &&
       realDims->GetDataType() == VTK_INT &&
       realDims->GetNumberOfComponents() == 1)
hrchilds's avatar
hrchilds committed
529
    {
530 531 532 533 534 535
        // make sure the realDims data isn't garbage (the facelist filter
        // will undermine us here if we don't double check)
        vtkIntArray *iarr = (vtkIntArray *)realDims;

        int ddims[3];
        int rdims[6];
536
        inGrid->GetDimensions(ddims);
537 538 539 540 541 542 543 544 545 546 547 548
        memcpy(rdims,iarr->GetPointer(0),sizeof(int)*6);

        if( ((rdims[1] - rdims[0]) < ddims[0]) &&
            ((rdims[3] - rdims[2]) < ddims[1]) &&
            ((rdims[5] - rdims[4]) < ddims[2]) )
        realDimsOk = true;
    }

    if (!realDimsOk)
    {
        GenericExecute();
        return;
hrchilds's avatar
hrchilds committed
549 550 551 552 553 554 555 556 557
    }

  vtkDebugMacro(<< "Executing remove ghost cells filter for rectilinear grid");

  int i, voi[6];
  for (i = 0; i < 6; i++)
    {
    voi[i] = (int) realDims->GetComponent(i, 0);
    }
hrchilds's avatar
hrchilds committed
558

559
  vtkUnsignedCharArray *arr = (vtkUnsignedCharArray *)
560
                              inGrid->GetCellData()->GetArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
561 562 563 564
  if (GhostZoneTypesToRemove != 255 && arr != NULL)
  {
    unsigned char *ghosts = arr->GetPointer(0);
    int dims[3];
565
    inGrid->GetDimensions(dims);
hrchilds's avatar
hrchilds committed
566

567
    // Check to make sure that the zones we are going to remove are
hrchilds's avatar
hrchilds committed
568 569 570 571
    // uniformly of the type we should remove.
    // It will modify the voi if necessary.
    ConfirmRegion(ghosts, dims, voi);
  }
hrchilds's avatar
hrchilds committed
572
 
hrchilds's avatar
hrchilds committed
573
  vtkVisItExtractRectilinearGrid *extractor = vtkVisItExtractRectilinearGrid::New();
574
  extractor->SetInputData(inGrid);
hrchilds's avatar
hrchilds committed
575
  extractor->SetVOI(voi);
576
  extractor->Update();
hrchilds's avatar
hrchilds committed
577
 
578
  outGrid->ShallowCopy(extractor->GetOutput());
hrchilds's avatar
hrchilds committed
579
  extractor->Delete();
580 581
  outGrid->GetFieldData()->PassData(inGrid->GetFieldData());
  outGrid->GetFieldData()->RemoveArray("avtRealDims");
hrchilds's avatar
hrchilds committed
582 583
  if (GhostZoneTypesToRemove == 255)
  {
584
    outGrid->GetCellData()->RemoveArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
585
  }
hrchilds's avatar
hrchilds committed
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
}


// ***************************************************************************
//  Modifications:
//    Kathleen Bonnell, Fri Aug 31 08:50:30 PDT 2001
//    Removed check of field data.  No longer necessary with new vtk.
//
//    Hank Childs, Sun Apr 14 10:12:30 PDT 2002
//    Removed SetOutput call, due to a weird bug with VTK 4.0.  It wasn't
//    needed in the first place, anyway.
//
//    Hank Childs, Sat Jun 29 16:27:41 PDT 2002
//    Copy over field data and set the dimensions.
//
601 602
//    Kathleen Bonnell, Wed Jul 10 16:02:56 PDT 2002
//    Reworked code to properly use vtkExtractGrid filter.
hrchilds's avatar
hrchilds committed
603 604
//    Use new avtRealDims array.
//
hrchilds's avatar
hrchilds committed
605 606 607
//    Hank Childs, Fri Aug 27 15:10:50 PDT 2004
//    Use the new ghost data names.
//
hrchilds's avatar
hrchilds committed
608 609 610
//    Hank Childs, Thu Mar  2 11:14:53 PST 2006
//    Call generic execute if there are no real dims.
//
hrchilds's avatar
hrchilds committed
611 612 613
//    Hank Childs, Sun Oct 28 10:56:37 PST 2007
//    Added support for GhostZoneTypesToRemove.
//
614 615 616
//    Eric Brugger, Wed Jan  9 14:56:57 PST 2013
//    Modified to inherit from vtkDataSetAlgorithm.
//
617 618 619
//    Kathleen Biagas, Fri Jan 25 16:04:46 PST 2013
//    Call Update on the filter, not the data object.
//
hrchilds's avatar
hrchilds committed
620 621
// ***************************************************************************

622 623
void
vtkDataSetRemoveGhostCells::StructuredGridExecute()
hrchilds's avatar
hrchilds committed
624
{
625 626
  vtkStructuredGrid *inGrid  = (vtkStructuredGrid*)input;
  vtkStructuredGrid *outGrid = (vtkStructuredGrid*)output;
hrchilds's avatar
hrchilds committed
627
 
628
  vtkDataArray *realDims = inGrid->GetFieldData()->GetArray("avtRealDims");
hrchilds's avatar
hrchilds committed
629 630 631
  if (!realDims || (realDims->GetDataType() != VTK_INT)
    || (realDims->GetNumberOfComponents() != 1))
    {
hrchilds's avatar
hrchilds committed
632
    GenericExecute();
hrchilds's avatar
hrchilds committed
633 634 635 636 637 638 639 640 641 642 643
    return;
    }

  vtkDebugMacro(<< "Executing remove ghost cells filter for structured grid");
 
   int i, voi[6];
   for (i = 0; i < 6; i++)
     {
     voi[i] = (int) realDims->GetComponent(i, 0);
     }
 
644
  vtkUnsignedCharArray *arr = (vtkUnsignedCharArray *)
645
                              inGrid->GetCellData()->GetArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
646 647 648 649
  if (GhostZoneTypesToRemove != 255 && arr != NULL)
  {
    unsigned char *ghosts = arr->GetPointer(0);
    int dims[3];
650
    inGrid->GetDimensions(dims);
hrchilds's avatar
hrchilds committed
651

652
    // Check to make sure that the zones we are going to remove are
hrchilds's avatar
hrchilds committed
653 654 655 656 657 658
    // uniformly of the type we should remove.
    // It will modify the voi if necessary.
    ConfirmRegion(ghosts, dims, voi);
  }
 
  vtkVisItExtractGrid *extractor = vtkVisItExtractGrid::New();
659
  extractor->SetInputData(inGrid);
hrchilds's avatar
hrchilds committed
660
  extractor->SetVOI(voi);
661
  extractor->Update();
hrchilds's avatar
hrchilds committed
662
 
663
  outGrid->ShallowCopy(extractor->GetOutput());
hrchilds's avatar
hrchilds committed
664
  extractor->Delete();
665 666
  outGrid->GetFieldData()->PassData(inGrid->GetFieldData());
  outGrid->GetFieldData()->RemoveArray("avtRealDims");
hrchilds's avatar
hrchilds committed
667 668
  if (GhostZoneTypesToRemove == 255)
  {
669
    outGrid->GetCellData()->RemoveArray("avtGhostZones");
hrchilds's avatar
hrchilds committed
670
  }
hrchilds's avatar
hrchilds committed
671 672
}

673 674 675
void
vtkDataSetRemoveGhostCells::ConfirmRegion(unsigned char *ghosts,
                                          int *pt_dims, int *voi)
hrchilds's avatar
hrchilds committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
{
    int  i, j, k;

    int dims[3];
    dims[0] = (pt_dims[0] > 1 ? pt_dims[0]-1 : 1);
    dims[1] = (pt_dims[1] > 1 ? pt_dims[1]-1 : 1);
    dims[2] = (pt_dims[2] > 1 ? pt_dims[2]-1 : 1);

    if (voi[0] > 0)
    {
        bool allGhost = true;
        i = voi[0]-1;
        for (j = 0 ; j < dims[1] && allGhost ; j++)
           for (k = 0 ; k < dims[2] && allGhost ; k++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[0] = 0;
    }
    if (voi[1] < dims[0])
    {
        bool allGhost = true;
        i = dims[0]-1;
        for (j = 0 ; j < dims[1] && allGhost ; j++)
           for (k = 0 ; k < dims[2] && allGhost ; k++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[1] = dims[0];
    }
    if (voi[2] > 0)
    {
        bool allGhost = true;
        j = voi[2]-1;
        for (i = 0 ; i < dims[0] && allGhost ; i++)
           for (k = 0 ; k < dims[2] && allGhost ; k++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[2] = 0;
    }
    if (voi[3] < dims[1])
    {
        bool allGhost = true;
        j = dims[1]-1;
        for (i = 0 ; i < dims[0] && allGhost ; i++)
           for (k = 0 ; k < dims[2] && allGhost ; k++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[3] = dims[1];
    }
    if (voi[4] > 0)
    {
        bool allGhost = true;
        k = voi[4]-1;
        for (i = 0 ; i < dims[0] && allGhost ; i++)
           for (j = 0 ; j < dims[1] && allGhost ; j++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[4] = 0;
    }
    if (voi[5] < dims[2])
    {
        bool allGhost = true;
        k = dims[2]-1;
        for (i = 0 ; i < dims[0] && allGhost ; i++)
           for (j = 0 ; j < dims[1] && allGhost ; j++)
           {
               int c = k*dims[1]*dims[0] + j*dims[0] + i;
               unsigned char effectiveVal = ghosts[c] & GhostZoneTypesToRemove;
               if (! avtGhostData::IsGhostZone(effectiveVal))
                   allGhost = false;
           }
        if (!allGhost)
            voi[5] = dims[2];
    }
}


hrchilds's avatar
hrchilds committed
777
// ****************************************************************************
778 779 780
//  Modifications:
//    Kathleen Bonnell, Wed Mar  6 13:48:48 PST 2002
//    Call superclass's method the new vtk way.
hrchilds's avatar
hrchilds committed
781
//
782 783
//    Hank Childs, Mon Aug 30 16:27:16 PDT 2004
//    Remove references to ghost level, since it is no longer a data member.
hrchilds's avatar
hrchilds committed
784 785
//
// ****************************************************************************
786 787 788

void
vtkDataSetRemoveGhostCells::PrintSelf(ostream& os, vtkIndent indent)
hrchilds's avatar
hrchilds committed
789 790 791
{
  this->Superclass::PrintSelf(os,indent);
}