/*========================================================================= Program: Visualization Toolkit Module: TestCellLocator.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkStaticCellLinks.h" #include "vtkStaticCellLinksTemplate.h" #include "vtkSmartPointer.h" #include "vtkImageData.h" #include "vtkUnstructuredGrid.h" #include "vtkPolyData.h" #include "vtkExtractGeometry.h" #include "vtkSphere.h" #include "vtkSphereSource.h" #include "vtkTimerLog.h" // Test the building of static cell links in both unstructured and structured // grids. int TestStaticCellLinks( int, char *[] ) { int dataDim = 3; // First create a volume which will be converted to an unstructured grid vtkSmartPointer volume = vtkSmartPointer::New(); volume->SetDimensions(dataDim,dataDim,dataDim); volume->AllocateScalars(VTK_INT,1); //---------------------------------------------------------------------------- // Build links on volume vtkSmartPointer imlinks = vtkSmartPointer::New(); imlinks->BuildLinks(volume); vtkIdType ncells = imlinks->GetNumberOfCells(0); const vtkIdType *imcells = imlinks->GetCells(0); cout << "Volume:\n"; cout << " Lower Left corner (numCells, cells): " << ncells << " ("; for (int i=0; iGetNumberOfCells(13); imcells = imlinks->GetCells(13); cout << " Center (ncells, cells): " << ncells << " ("; for (int i=0; iGetNumberOfCells(26); imcells = imlinks->GetCells(26); cout << " Upper Right corner (ncells, cells): " << ncells << " ("; for (int i=0; i sphere = vtkSmartPointer::New(); sphere->SetCenter(0,0,0); sphere->SetRadius(100000); // Side effect of this filter is conversion of volume to unstructured grid vtkSmartPointer extract = vtkSmartPointer::New(); extract->SetInputData(volume); extract->SetImplicitFunction(sphere); extract->Update(); // Grab the output, build links on unstructured grid vtkSmartPointer ugrid = extract->GetOutput(); vtkStaticCellLinksTemplate slinks; slinks.BuildLinks(ugrid); int numCells = slinks.GetNumberOfCells(0); const int *cells = slinks.GetCells(0); cout << "\nUnstructured Grid:\n"; cout << " Lower Left corner (numCells, cells): " << numCells << " ("; for (int i=0; i ss = vtkSmartPointer::New(); ss->SetThetaResolution(12); ss->SetPhiResolution(10); ss->Update(); vtkSmartPointer pdata = ss->GetOutput(); slinks.Initialize(); //reuse slinks.BuildLinks(pdata); // The first point is at the pole numCells = slinks.GetNumberOfCells(0); cells = slinks.GetCells(0); cout << "\nPolydata:\n"; cout << " Pole: (numCells, cells): " << numCells << " ("; for (int i=0; i