Skip to content
Snippets Groups Projects
Commit 7f0f54dc authored by Thomas Galland's avatar Thomas Galland Committed by Kitware Robot
Browse files

Merge topic 'fixContourHelper'


66c0964f Refactor vtkContourHelper
c101d44a Fix: vtkContourHelper

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Tested-by: default avatarbuildbot <buildbot@kitware.com>
Reviewed-by: default avatarMathieu Westphal (Kitware) <mathieu.westphal@kitware.com>
Reviewed-by: default avatarJulien Fausty <julien.fausty@kitware.com>
Merge-request: !10180
parents d9fb4595 66c0964f
No related branches found
No related tags found
No related merge requests found
......@@ -25,90 +25,80 @@
//------------------------------------------------------------------------------
VTK_ABI_NAMESPACE_BEGIN
vtkContourHelper::vtkContourHelper(vtkIncrementalPointLocator* locator, vtkCellArray* verts,
vtkCellArray* lines, vtkCellArray* polys, vtkPointData* inPd, vtkCellData* inCd,
vtkPointData* outPd, vtkCellData* outCd, int estimatedSize, bool outputTriangles)
vtkContourHelper::vtkContourHelper(vtkIncrementalPointLocator* locator, vtkCellArray* outVerts,
vtkCellArray* outLines, vtkCellArray* outPolys, vtkPointData* inPd, vtkCellData* inCd,
vtkPointData* outPd, vtkCellData* outCd, int trisEstimatedSize, bool outputTriangles)
: Locator(locator)
, Verts(verts)
, Lines(lines)
, Polys(polys)
, OutVerts(outVerts)
, OutLines(outLines)
, OutPolys(outPolys)
, InPd(inPd)
, InCd(inCd)
, OutPd(outPd)
, OutCd(outCd)
, GenerateTriangles(outputTriangles)
, TrisEstimatedSize(trisEstimatedSize)
, OutputTriangles(outputTriangles)
{
this->Tris = vtkCellArray::New();
this->TriOutCd = vtkCellData::New();
if (this->GenerateTriangles)
{
this->Tris->AllocateEstimate(estimatedSize, 3);
this->TriOutCd->Initialize();
}
this->PolyCollection = vtkIdListCollection::New();
}
//------------------------------------------------------------------------------
vtkContourHelper::~vtkContourHelper()
{
this->Tris->Delete();
this->TriOutCd->Delete();
this->PolyCollection->Delete();
}
//------------------------------------------------------------------------------
void vtkContourHelper::Contour(
vtkCell* cell, double value, vtkDataArray* cellScalars, vtkIdType cellId)
{
bool mergeTriangles = (!this->GenerateTriangles) && cell->GetCellDimension() == 3;
vtkCellData* outCD = nullptr;
vtkCellArray* outPoly = nullptr;
if (mergeTriangles)
{
outPoly = this->Tris;
outCD = this->TriOutCd;
}
else
{
outPoly = this->Polys;
outCD = this->OutCd;
}
cell->Contour(value, cellScalars, this->Locator, this->Verts, this->Lines, outPoly, this->InPd,
this->OutPd, this->InCd, cellId, outCD);
if (mergeTriangles)
if (!this->OutputTriangles && cell->GetCellDimension() == 3)
{
this->PolyBuilder.Reset();
// Retrieve the output triangles of the contour in temporary structures.
vtkNew<vtkCellArray> outTriTemp;
outTriTemp->AllocateEstimate(this->TrisEstimatedSize, 3);
vtkNew<vtkCellData> outTriDataTemp;
outTriDataTemp->Initialize();
cell->Contour(value, cellScalars, this->Locator, this->OutVerts, this->OutLines, outTriTemp,
this->InPd, this->OutPd, this->InCd, cellId, outTriDataTemp);
vtkIdType cellSize;
const vtkIdType* cellVerts;
while (this->Tris->GetNextCell(cellSize, cellVerts))
// Add output triangles to the PolygonBuilder in order to merge them into polygons.
vtkPolygonBuilder polyBuilder;
polyBuilder.Reset();
vtkIdType cellSize = 0;
const vtkIdType* cellVerts = nullptr;
while (outTriTemp->GetNextCell(cellSize, cellVerts))
{
if (cellSize == 3)
{
this->PolyBuilder.InsertTriangle(cellVerts);
polyBuilder.InsertTriangle(cellVerts);
}
else // for whatever reason, the cell contouring is already outputting polys
else
{
vtkIdType outCellId = this->Polys->InsertNextCell(cellSize, cellVerts);
// If for whatever reason, the cell contouring is already outputting polys.
// Add them directly to the output.
vtkIdType outCellId = this->OutPolys->InsertNextCell(cellSize, cellVerts);
this->OutCd->CopyData(this->InCd, cellId,
outCellId + this->Verts->GetNumberOfCells() + this->Lines->GetNumberOfCells());
outCellId + this->OutVerts->GetNumberOfCells() + this->OutLines->GetNumberOfCells());
}
}
this->PolyBuilder.GetPolygons(this->PolyCollection);
int nPolys = this->PolyCollection->GetNumberOfItems();
for (int polyId = 0; polyId < nPolys; ++polyId)
// Add constructed polygons to the output.
vtkNew<vtkIdListCollection> polyCollection;
polyBuilder.GetPolygons(polyCollection);
for (int polyId = 0; polyId < polyCollection->GetNumberOfItems(); ++polyId)
{
vtkIdList* poly = this->PolyCollection->GetItem(polyId);
vtkIdList* poly = polyCollection->GetItem(polyId);
if (poly->GetNumberOfIds() != 0)
{
vtkIdType outCellId = this->Polys->InsertNextCell(poly);
vtkIdType outCellId = this->OutPolys->InsertNextCell(poly);
this->OutCd->CopyData(this->InCd, cellId,
outCellId + this->Verts->GetNumberOfCells() + this->Lines->GetNumberOfCells());
outCellId + this->OutVerts->GetNumberOfCells() + this->OutLines->GetNumberOfCells());
}
poly->Delete();
}
this->PolyCollection->RemoveAllItems();
polyCollection->RemoveAllItems();
}
else
{
// We do not need to merge output triangles, so we call the contour method directly.
cell->Contour(value, cellScalars, this->Locator, this->OutVerts, this->OutLines, this->OutPolys,
this->InPd, this->OutPd, this->InCd, cellId, this->OutCd);
}
}
VTK_ABI_NAMESPACE_END
......@@ -13,13 +13,19 @@
=========================================================================*/
/**
* @class vtkContourHelper
* @brief A utility class used by various contour filters
* @class vtkContourHelper
* @brief A utility class used by various contour filters
*
* This is a simple utility class that can be used by various contour filters to
* produce either triangles and/or polygons based on the outputTriangles parameter.
* If outputTriangles is set to true, trisEstimatedSize is used to allocate memory
* for temporary triangles created by contouring before merging them.
* If outputTriangles is set to false, contouring triangles are outputted and
* trisEstimatedSize is not used.
*
* When working with multidimensional dataset, it is needed to process cells
* from low to high dimensions.
*
* This is a simple utility class that can be used by various contour filters to
* produce either triangles and/or polygons based on the outputTriangles parameter
* When working with multidimensional dataset, it is needed to process cells
* from low to high dimensions.
* @sa
* vtkContourGrid vtkCutter vtkContourFilter
*/
......@@ -28,8 +34,7 @@
#define vtkContourHelper_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPolygonBuilder.h" //for a member variable
#include "vtkSmartPointer.h" //for a member variable
#include "vtkWeakPointer.h" // For vtkWeakPointer
VTK_ABI_NAMESPACE_BEGIN
class vtkIncrementalPointLocator;
......@@ -38,35 +43,32 @@ class vtkPointData;
class vtkCellData;
class vtkCell;
class vtkDataArray;
class vtkIdListCollection;
class VTKFILTERSCORE_EXPORT vtkContourHelper
{
public:
vtkContourHelper(vtkIncrementalPointLocator* locator, vtkCellArray* verts, vtkCellArray* lines,
vtkCellArray* polys, vtkPointData* inPd, vtkCellData* inCd, vtkPointData* outPd,
vtkCellData* outCd, int estimatedSize, bool outputTriangles);
~vtkContourHelper();
vtkContourHelper(vtkIncrementalPointLocator* locator, vtkCellArray* outVerts,
vtkCellArray* outLines, vtkCellArray* outPolys, vtkPointData* inPd, vtkCellData* inCd,
vtkPointData* outPd, vtkCellData* outCd, int trisEstimatedSize, bool outputTriangles);
~vtkContourHelper() = default;
void Contour(vtkCell* cell, double value, vtkDataArray* cellScalars, vtkIdType cellId);
private:
vtkContourHelper(const vtkContourHelper&) = delete;
vtkContourHelper& operator=(const vtkContourHelper&) = delete;
vtkIncrementalPointLocator* Locator;
vtkCellArray* Verts;
vtkCellArray* Lines;
vtkCellArray* Polys;
vtkPointData* InPd;
vtkCellData* InCd;
vtkPointData* OutPd;
vtkCellData* OutCd;
vtkSmartPointer<vtkCellData> TriOutCd;
vtkCellArray* Tris;
vtkPolygonBuilder PolyBuilder;
vtkIdListCollection* PolyCollection;
bool GenerateTriangles;
// Filled upon construction
vtkWeakPointer<vtkIncrementalPointLocator> Locator;
vtkWeakPointer<vtkCellArray> OutVerts;
vtkWeakPointer<vtkCellArray> OutLines;
vtkWeakPointer<vtkCellArray> OutPolys;
vtkWeakPointer<vtkPointData> InPd;
vtkWeakPointer<vtkCellData> InCd;
vtkWeakPointer<vtkPointData> OutPd;
vtkWeakPointer<vtkCellData> OutCd;
int TrisEstimatedSize = 0;
bool OutputTriangles = false;
};
VTK_ABI_NAMESPACE_END
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment