Commit a9656682 authored by Will Schroeder's avatar Will Schroeder Committed by Kitware Robot
Browse files

Merge topic 'Threaded-CellLinks'

f6c3cc4a Documentation polish
8d8b2bd4 Dashboard warnings
9d7356ed Adapted back to multibuild workflow
c79ca6b3 Dealing with memory leak issues
fc96d38a Fixed memory leak
4bd8735d Tested and working
ceb86646 Separated templated code; created wrappable class
340b7506

 Cleaned dashboard warnings
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel's avatarBen Boeckel <ben.boeckel@kitware.com>
Merge-request: !912
parents 0dc32341 f6c3cc4a
set(Module_SRCS
vtkAbstractCellLinks.cxx
vtkAbstractCellLocator.cxx
vtkAbstractPointLocator.cxx
vtkAdjacentVertexIterator.cxx
......@@ -156,6 +157,8 @@ set(Module_SRCS
vtkSmoothErrorMetric.cxx
vtkSphere.cxx
vtkSpline.cxx
vtkStaticCellLinks.cxx
vtkStaticCellLinksTemplate.txx
vtkStaticPointLocator.cxx
vtkStructuredData.cxx
vtkStructuredExtent.cxx
......@@ -213,9 +216,11 @@ set(${vtk-module}_HDRS
vtkCellType.h
vtkMappedUnstructuredGrid.h
vtkMappedUnstructuredGridCellIterator.h
vtkStaticCellLinksTemplate.h
)
set_source_files_properties(
vtkAbstractCellLinks
vtkAbstractCellLocator
vtkAbstractPointLocator
vtkCell
......@@ -271,6 +276,7 @@ set_source_files_properties(
vtkImageProgressIterator
vtkPixelExtent.cxx
vtkPixelTransfer.cxx
vtkStaticCellLinksTemplate.txx
vtkVector
vtkColor
vtkRect
......
......@@ -48,6 +48,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
quadraticEvaluation.cxx
TestBoundingBox.cxx
TestPlane.cxx
TestStaticCellLinks.cxx
TestStructuredData.cxx
TestDataObjectTypes.cxx
TestPolyDataRemoveDeletedCells.cxx
......
/*=========================================================================
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<vtkImageData> volume =
vtkSmartPointer<vtkImageData>::New();
volume->SetDimensions(dataDim,dataDim,dataDim);
volume->AllocateScalars(VTK_INT,1);
//----------------------------------------------------------------------------
// Build links on volume
vtkSmartPointer<vtkStaticCellLinks> imlinks =
vtkSmartPointer<vtkStaticCellLinks>::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; i<ncells; ++i)
{
cout << imcells[i];
if ( i < (ncells-1) ) cout << "," ;
}
cout << ")\n";
if ( ncells != 1 || imcells[0] != 0 )
{
return EXIT_FAILURE;
}
ncells = imlinks->GetNumberOfCells(13);
imcells = imlinks->GetCells(13);
cout << " Center (ncells, cells): " << ncells << " (";
for (int i=0; i<ncells; ++i)
{
cout << imcells[i];
if ( i < (ncells-1) ) cout << "," ;
}
cout << ")\n";
if ( ncells != 8 )
{
return EXIT_FAILURE;
}
ncells = imlinks->GetNumberOfCells(26);
imcells = imlinks->GetCells(26);
cout << " Upper Right corner (ncells, cells): " << ncells << " (";
for (int i=0; i<ncells; ++i)
{
cout << imcells[i];
if ( i < (ncells-1) ) cout << "," ;
}
cout << ")\n";
if ( ncells != 1 || imcells[0] != 7 )
{
return EXIT_FAILURE;
}
//----------------------------------------------------------------------------
// Unstructured grid
vtkSmartPointer<vtkSphere> sphere =
vtkSmartPointer<vtkSphere>::New();
sphere->SetCenter(0,0,0);
sphere->SetRadius(100000);
// Side effect of this filter is conversion of volume to unstructured grid
vtkSmartPointer<vtkExtractGeometry> extract =
vtkSmartPointer<vtkExtractGeometry>::New();
extract->SetInputData(volume);
extract->SetImplicitFunction(sphere);
extract->Update();
// Grab the output, build links on unstructured grid
vtkSmartPointer<vtkUnstructuredGrid> ugrid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
ugrid = extract->GetOutput();
vtkStaticCellLinksTemplate<int> 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<numCells; ++i)
{
cout << cells[i];
if ( i < (numCells-1) ) cout << "," ;
}
cout << ")\n";
if ( numCells != 1 || cells[0] != 0 )
{
return EXIT_FAILURE;
}
numCells = slinks.GetNumberOfCells(13);
cells = slinks.GetCells(13);
cout << " Center (numCells, cells): " << numCells << " (";
for (int i=0; i<numCells; ++i)
{
cout << cells[i];
if ( i < (numCells-1) ) cout << "," ;
}
cout << ")\n";
if ( numCells != 8 )
{
return EXIT_FAILURE;
}
numCells = slinks.GetNumberOfCells(26);
cells = slinks.GetCells(26);
cout << " Upper Right corner (numCells, cells): " << numCells << " (";
for (int i=0; i<numCells; ++i)
{
cout << cells[i];
if ( i < (numCells-1) ) cout << "," ;
}
cout << ")\n";
if ( numCells != 1 || cells[0] != 7 )
{
return EXIT_FAILURE;
}
//----------------------------------------------------------------------------
// Polydata
vtkSmartPointer<vtkSphereSource> ss =
vtkSmartPointer<vtkSphereSource>::New();
ss->SetThetaResolution(12);
ss->SetPhiResolution(10);
ss->Update();
vtkSmartPointer<vtkPolyData> pdata =
vtkSmartPointer<vtkPolyData>::New();
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<numCells; ++i)
{
cout << cells[i];
if ( i < (numCells-1) ) cout << "," ;
}
cout << ")\n";
if ( numCells != 12 )
{
return EXIT_FAILURE;
}
// The next point is at near the equator
numCells = slinks.GetNumberOfCells(5);
cells = slinks.GetCells(5);
cout << " Equator: (numCells, cells): " << numCells << " (";
for (int i=0; i<numCells; ++i)
{
cout << cells[i];
if ( i < (numCells-1) ) cout << "," ;
}
cout << ")\n";
if ( numCells != 6 )
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAbstractCellLinks.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 "vtkAbstractCellLinks.h"
#include "vtkObjectFactory.h"
#include "vtkCellArray.h"
//----------------------------------------------------------------------------
vtkAbstractCellLinks::vtkAbstractCellLinks()
{
}
//----------------------------------------------------------------------------
vtkAbstractCellLinks::~vtkAbstractCellLinks()
{
}
//----------------------------------------------------------------------------
int vtkAbstractCellLinks::
GetIdType(vtkIdType maxPtId, vtkIdType maxCellId, vtkCellArray *ca)
{
vtkIdType numEntries = ca->GetNumberOfConnectivityEntries();
vtkIdType max = maxPtId;
max = (maxCellId > max ? maxCellId : max);
max = (numEntries > max ? numEntries : max);
if ( max >= VTK_INT_MAX )
{
return VTK_ID_TYPE;
}
else if ( max >= VTK_SHORT_MAX )
{
return VTK_INT;
}
else
{
return VTK_SHORT;
}
}
//----------------------------------------------------------------------------
void vtkAbstractCellLinks::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAbstractCellLinks.h
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.
=========================================================================*/
// .NAME vtkAbstractCellLinks - an abstract base class for classes that build
// topological links from points to cells
// .SECTION Description
// vtkAbstractCellLinks is a family of supplemental objects to vtkCellArray and
// vtkCellTypes, enabling fast access from points to the cells using the
// points. vtkAbstractCellLinks is an array of links, each link representing a
// list of cell ids using a particular point. The information provided by
// this object can be used to determine neighbors and construct other local
// topological information.
//
// .SECTION See Also
// vtkCellLinks vtkStaticCellLinks vtkStaticCellLinksTemplate
#ifndef vtkAbstractCellLinks_h
#define vtkAbstractCellLinks_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkObject.h"
class vtkDataSet;
class vtkCellArray;
class VTKCOMMONDATAMODEL_EXPORT vtkAbstractCellLinks : public vtkObject
{
public:
// Description:
// Standard type and print methods.
vtkTypeMacro(vtkAbstractCellLinks,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Build the link list array. All subclasses must implement this method.
virtual void BuildLinks(vtkDataSet *data) = 0;
// Description:
// Based on the input (i.e., number of points, number of cells, and length
// of connectivity array) this helper method returns the integral type to
// use when instantiating cell link-related classes in order to properly
// represent the data. The return value is one of the types
// (VTK_ID_TYPE,VTK_INT,VTK_SHORT) defined in the file
// vtkType.h. Subclasses may choose to instantiate themselves with
// different integral types for performance and/or memory reasons.
static int GetIdType(vtkIdType maxPtId, vtkIdType maxCellId, vtkCellArray *ca);
protected:
vtkAbstractCellLinks();
virtual ~vtkAbstractCellLinks();
private:
vtkAbstractCellLinks(const vtkAbstractCellLinks&); // Not implemented.
void operator=(const vtkAbstractCellLinks&); // Not implemented.
};
#endif
......@@ -22,6 +22,27 @@
vtkStandardNewMacro(vtkCellLinks);
//----------------------------------------------------------------------------
vtkCellLinks::~vtkCellLinks()
{
this->Initialize();
}
//----------------------------------------------------------------------------
void vtkCellLinks::Initialize()
{
if ( this->Array != NULL )
{
for (vtkIdType i=0; i<=this->MaxId; i++)
{
delete [] this->Array[i].cells;
}
delete [] this->Array;
this->Array = NULL;
}
}
//----------------------------------------------------------------------------
void vtkCellLinks::Allocate(vtkIdType sz, vtkIdType ext)
{
......@@ -39,22 +60,6 @@ void vtkCellLinks::Allocate(vtkIdType sz, vtkIdType ext)
}
}
//----------------------------------------------------------------------------
vtkCellLinks::~vtkCellLinks()
{
if ( this->Array == NULL )
{
return;
}
for (vtkIdType i=0; i<=this->MaxId; i++)
{
delete [] this->Array[i].cells;
}
delete [] this->Array;
}
//----------------------------------------------------------------------------
// Allocate memory for the list of lists of cell ids.
void vtkCellLinks::AllocateLinks(vtkIdType n)
......
......@@ -16,21 +16,29 @@
// .SECTION Description
// vtkCellLinks is a supplemental object to vtkCellArray and vtkCellTypes,
// enabling access from points to the cells using the points. vtkCellLinks is
// a list of Links, each link represents a dynamic list of cell id's using the
// point. The information provided by this object can be used to determine
// neighbors and construct other local topological information.
// a list of cell ids, each such link representing a dynamic list of cell ids
// using the point. The information provided by this object can be used to
// determine neighbors and construct other local topological information.
// .SECTION Caveats
// Note that this class is designed to support incremental link construction.
// More efficient cell links structures can be built with vtkStaticCellLinks
// (and vtkStaticCellLinksTemplate). However these other classes are typically
// meant for one-time (static) construction.
// .SECTION See Also
// vtkCellArray vtkCellTypes
// vtkCellArray vtkCellTypes vtkStaticCellLinks vtkStaticCellLinksTemplate
#ifndef vtkCellLinks_h
#define vtkCellLinks_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkObject.h"
#include "vtkAbstractCellLinks.h"
class vtkDataSet;
class vtkCellArray;
class VTKCOMMONDATAMODEL_EXPORT vtkCellLinks : public vtkObject
class VTKCOMMONDATAMODEL_EXPORT vtkCellLinks : public vtkAbstractCellLinks
{
public:
......@@ -42,15 +50,30 @@ public:
};
//ETX
// Description:
// Standard methods to instantiate, print, and obtain type information.
static vtkCellLinks *New();
vtkTypeMacro(vtkCellLinks,vtkObject);
vtkTypeMacro(vtkCellLinks,vtkAbstractCellLinks);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Build the link list array. All subclasses of vtkAbstractCellLinks
// must support this method.
virtual void BuildLinks(vtkDataSet *data);
// Description:
// Build the link list array with a provided connectivity array.
void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
// Description:
// Allocate the specified number of links (i.e., number of points) that
// will be built.
void Allocate(vtkIdType numLinks, vtkIdType ext=1000);
// Description:
// Clear out any previously allocated data structures
void Initialize();
// Description:
// Get a link structure given a point id.
Link &GetLink(vtkIdType ptId) {return this->Array[ptId];};
......@@ -59,14 +82,6 @@ public:
// Get the number of cells using the point specified by ptId.
unsigned short GetNcells(vtkIdType ptId) { return this->Array[ptId].ncells;};
// Description:
// Build the link list array.
void BuildLinks(vtkDataSet *data);
// Description:
// Build the link list array.
void BuildLinks(vtkDataSet *data, vtkCellArray *Connectivity);
// Description:
// Return a list of cell ids using the point.
vtkIdType *GetCells(vtkIdType ptId) {return this->Array[ptId].cells;};
......@@ -127,7 +142,7 @@ public:
protected:
vtkCellLinks():Array(NULL),Size(0),MaxId(-1),Extend(1000) {}
~vtkCellLinks();
virtual ~vtkCellLinks();
// Description:
// Increment the count of the number of cells using the point.
......@@ -145,6 +160,7 @@ protected:
vtkIdType MaxId; // maximum index inserted thus far
vtkIdType Extend; // grow array by this point
Link *Resize(vtkIdType sz); // function to resize data
private:
vtkCellLinks(const vtkCellLinks&); // Not implemented.
void operator=(const vtkCellLinks&); // Not implemented.
......@@ -214,4 +230,3 @@ inline void vtkCellLinks::ResizeCellList(vtkIdType ptId, int size)
}
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkStaticCellLinks.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 "vtkObjectFactory.h"
vtkStandardNewMacro(vtkStaticCellLinks);
//----------------------------------------------------------------------------
vtkStaticCellLinks::vtkStaticCellLinks()
{
this->Impl = new vtkStaticCellLinksTemplate<vtkIdType>;
}
//----------------------------------------------------------------------------
vtkStaticCellLinks::~vtkStaticCellLinks()
{
delete this->Impl;
}
//----------------------------------------------------------------------------
void vtkStaticCellLinks::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkStaticCellLinks.h
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.
=========================================================================*/
// .NAME vtkStaticCellLinks - object represents upward pointers from points
// to list of cells using each point
// .SECTION Description
// vtkStaticCellLinks is a supplemental object to vtkCellArray and
// vtkCellTypes, enabling access from points to the cells using the
// points. vtkStaticCellLinks is an array of links, each link represents a
// list of cell ids using a particular point. The information provided by
// this object can be used to determine neighbors and construct other local
// topological information. This class is a faster implementation of
// vtkCellLinks. However, it cannot be incrementally constructed; it is meant
// to be constructed once (statically) and must be rebuilt if the cells
// change.
// .SECTION Caveats
// This is a drop-in replacement for vtkCellLinks using static link
// construction. It uses the templated vtkStaticCellLinksTemplate class,
// instantiating vtkStaticCellLinksTemplate with a vtkIdType template
// parameter. Note that for best performance, the vtkStaticCellLinksTemplate
// class may be used directly, instantiating it with the appropriate id
// type. This class is also wrappable and can be used from an interpreted
// language such as Python.
// .SECTION See Also
// vtkCellLinks vtkStaticCellLinksTemplate
#ifndef vtkStaticCellLinks_h
#define vtkStaticCellLinks_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkAbstractCellLinks.h"
#include "vtkStaticCellLinksTemplate.h" // For implementations
class vtkDataSet;
class vtkCellArray;