Skip to content

Commit

Permalink
Deprecating vtkCellTypes
Browse files Browse the repository at this point in the history
`vtkCellTypes` currently holds an attribute `LocationArray` which is not
needed anymore. this commit deprecates all methods that are related to
this attribute.
  • Loading branch information
yohannbearzi committed Nov 12, 2021
1 parent fc8c31a commit 613d4e3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
8 changes: 1 addition & 7 deletions Common/DataModel/Testing/Cxx/otherCellTypes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ void TestOCT()
ct->InsertNextCell(VTK_PIXEL, 1);

vtkUnsignedCharArray* cellTypes = vtkUnsignedCharArray::New();
vtkIntArray* cellLocations = vtkIntArray::New();

cellLocations->InsertNextValue(0);
cellTypes->InsertNextValue(VTK_QUAD);

cellLocations->InsertNextValue(1);
cellTypes->InsertNextValue(VTK_PIXEL);

cellLocations->InsertNextValue(2);
cellTypes->InsertNextValue(VTK_TETRA);

ct->SetCellTypes(3, cellTypes, cellLocations);
ct->SetCellTypes(3, cellTypes);

ct->GetCellLocation(1);
ct->DeleteCell(1);

ct->GetNumberOfTypes();
Expand All @@ -69,7 +64,6 @@ void TestOCT()

ct1->Delete();
ct->Delete();
cellLocations->Delete();
cellTypes->Delete();
}

Expand Down
13 changes: 13 additions & 0 deletions Common/DataModel/vtkCellTypes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
=========================================================================*/

// Hide VTK_DEPRECATED_IN_9_2_0() warnings for this class.
#define VTK_DEPRECATION_LEVEL 0

#include "vtkCellTypes.h"
#include "vtkIdTypeArray.h"
#include "vtkIntArray.h"
Expand Down Expand Up @@ -148,6 +151,7 @@ vtkIdType vtkCellTypes::InsertNextCell(unsigned char type, vtkIdType loc)
void vtkCellTypes::SetCellTypes(
vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIntArray* cellLocations)
{
VTK_LEGACY_BODY(vtkCellTypes::SetCellTypes, "VTK 9.2");
this->TypeArray = cellTypes;
if (!this->LocationArray)
{
Expand All @@ -157,11 +161,20 @@ void vtkCellTypes::SetCellTypes(
this->MaxId = ncells - 1;
}

//------------------------------------------------------------------------------
// Specify a group of cell types.
void vtkCellTypes::SetCellTypes(vtkIdType ncells, vtkUnsignedCharArray* cellTypes)
{
this->TypeArray = cellTypes;
this->MaxId = ncells - 1;
}

//------------------------------------------------------------------------------
// Specify a group of cell types.
void vtkCellTypes::SetCellTypes(
vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIdTypeArray* cellLocations)
{
VTK_LEGACY_BODY(vtkCellTypes::SetCellTypes, "VTK 9.2");
this->TypeArray = cellTypes;
this->LocationArray = cellLocations;
this->MaxId = ncells - 1;
Expand Down
23 changes: 19 additions & 4 deletions Common/DataModel/vtkCellTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "vtkObject.h"

#include "vtkCellType.h" // Needed for inline methods
#include "vtkDeprecation.h" // Needed for deprecation
#include "vtkIdTypeArray.h" // Needed for inline methods
#include "vtkSmartPointer.h" // Needed for internals
#include "vtkUnsignedCharArray.h" // Needed for inline methods
Expand Down Expand Up @@ -70,19 +71,28 @@ class VTKCOMMONDATAMODEL_EXPORT vtkCellTypes : public vtkObject

/**
* Specify a group of cell types.
*
* \deprecated Please use method version that doesn't use `cellLocations` instead.
*/
VTK_DEPRECATED_IN_9_2_0("Please use version without cellLocations.")
void SetCellTypes(
vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIdTypeArray* cellLocations);

/**
* Specify a group of cell types. This version is provided to maintain
* backwards compatibility and does a copy of the cellLocations
* Specify a group of cell types.
*/
void SetCellTypes(vtkIdType ncells, vtkUnsignedCharArray* cellTypes);

VTK_DEPRECATED_IN_9_2_0("Please use version without cellLocations.")
void SetCellTypes(vtkIdType ncells, vtkUnsignedCharArray* cellTypes, vtkIntArray* cellLocations);

/**
* Return the location of the cell in the associated vtkCellArray.
*
* \deprecated This method will go away in future releases. Please do not realy on `CellLocation`
* in this class.
*/
VTK_DEPRECATED_IN_9_2_0("The Location API will disappear.")
vtkIdType GetCellLocation(vtkIdType cellId) { return this->LocationArray->GetValue(cellId); }

/**
Expand Down Expand Up @@ -169,8 +179,13 @@ class VTKCOMMONDATAMODEL_EXPORT vtkCellTypes : public vtkObject
~vtkCellTypes() override = default;

vtkSmartPointer<vtkUnsignedCharArray> TypeArray; // pointer to types array
vtkSmartPointer<vtkIdTypeArray> LocationArray; // pointer to array of offsets
vtkIdType MaxId; // maximum index inserted thus far

// DEPRECATION_IN_9_2_0 Note for whoever is in deprecation duties:
// The attribute LocationArray needs to be deleted, and any code in this class that would fail
// compiling because of its removal deleted as well.
vtkSmartPointer<vtkIdTypeArray> LocationArray; // pointer to array of offsets

vtkIdType MaxId; // maximum index inserted thus far

private:
vtkCellTypes(const vtkCellTypes&) = delete;
Expand Down
10 changes: 10 additions & 0 deletions Documentation/dev/deprecation-vtkCellTypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Deprecation in vtkCellTypes

Usage of `LocationArray` in `vtkCellTypes` is deprecated. This is an old legacy feature that was
used by `vtkUnstructuredGrid`. Currently, this class is used to store a list of distinct cell types
present in a `vtkUnstructuredGrid`, making `LocationArray` irrelevant.
In the long run, `vtkCellTypes` will become a static method only class. So it is advised to not use
instances of this class anymore. Using static methods is fine.

A new more direct interface to the array listing distinct cell types is implemented
in `vtkUnstructuredGrid` (see release notes about deprecation in `vtkUnstructuredGrid`).

0 comments on commit 613d4e3

Please sign in to comment.