Commit 95502905 authored by David E. DeMarle's avatar David E. DeMarle Committed by Kitware Robot
Browse files

Merge topic 'my-topic'

e6713b43 Add missing override
adaba0b6 Fix an unused var warning in this class
f6de9158 Correct function name
ad2cbcb5 Replace the tedious copying with ShallowCopy
2075a749 Fix wrong comment out
9db34c27

 Add vtkRemoveDuplicatePolys class
Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarDavid E. DeMarle <dave.demarle@kitware.com>
Acked-by: default avatarRoman Grothausmann <grothausmann.roman@mh-hannover.de>
Merge-request: !4265
parents fb550f9b e6713b43
......@@ -54,6 +54,7 @@ set(Module_SRCS
vtkQuadricClustering.cxx
vtkQuadricDecimation.cxx
vtkRearrangeFields.cxx
vtkRemoveDuplicatePolys.cxx
vtkResampleToImage.cxx
vtkResampleWithDataSet.cxx
vtkReverseSense.cxx
......
......@@ -41,6 +41,7 @@ vtk_add_test_cxx(vtkFiltersCoreCxxTests tests
TestResampleWithDataSet.cxx,
TestResampleWithDataSet2.cxx
TestResampleWithDataSet3.cxx
TestRemoveDuplicatePolys.cxx,NO_VALID
TestSmoothPolyDataFilter.cxx,NO_VALID
TestSMPPipelineContour.cxx,NO_VALID
TestStripper.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestRemoveDuplicatePolys.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 <vtkCellArray.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <vtkRemoveDuplicatePolys.h>
#include <vtkSmartPointer.h>
int TestRemoveDuplicatePolys(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
vtkSmartPointer<vtkMinimalStandardRandomSequence> randomSequence
= vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
randomSequence->SetSeed(1);
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New();
for (unsigned int i = 0; i < 3; ++i)
{
double point[3];
for(unsigned int j = 0; j < 3; ++j)
{
randomSequence->Next();
point[j] = randomSequence->GetValue();
}
points->InsertNextPoint(point);
}
verts->InsertNextCell(3);
verts->InsertCellPoint(0);
verts->InsertCellPoint(1);
verts->InsertCellPoint(2);
verts->InsertNextCell(3);
verts->InsertCellPoint(1);
verts->InsertCellPoint(2);
verts->InsertCellPoint(0);
verts->InsertNextCell(3);
verts->InsertCellPoint(2);
verts->InsertCellPoint(0);
verts->InsertCellPoint(1);
verts->InsertNextCell(3);
verts->InsertCellPoint(0);
verts->InsertCellPoint(2);
verts->InsertCellPoint(1);
verts->InsertNextCell(3);
verts->InsertCellPoint(1);
verts->InsertCellPoint(0);
verts->InsertCellPoint(2);
verts->InsertNextCell(3);
verts->InsertCellPoint(2);
verts->InsertCellPoint(1);
verts->InsertCellPoint(0);
points->Squeeze();
verts->Squeeze();
vtkSmartPointer<vtkPolyData> inputPolyData
= vtkSmartPointer<vtkPolyData>::New();
inputPolyData->SetPoints(points);
inputPolyData->SetPolys(verts);
vtkSmartPointer<vtkRemoveDuplicatePolys> removePolyData
= vtkSmartPointer<vtkRemoveDuplicatePolys>::New();
removePolyData->SetInputData(inputPolyData);
removePolyData->Update();
vtkSmartPointer<vtkPolyData> outputPolyData = removePolyData->GetOutput();
if (outputPolyData->GetNumberOfPolys() != 1)
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRemoveDuplicatePolys.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 "vtkRemoveDuplicatePolys.h"
#include "vtkCell.h"
#include "vtkCellData.h"
#include "vtkCollection.h"
#include "vtkIntArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include <algorithm>
#include <set>
#include <map>
#include <vector>
vtkStandardNewMacro(vtkRemoveDuplicatePolys);
//----------------------------------------------------------------------------
vtkRemoveDuplicatePolys::vtkRemoveDuplicatePolys()
{
}
//----------------------------------------------------------------------------
vtkRemoveDuplicatePolys::~vtkRemoveDuplicatePolys()
{
}
//----------------------------------------------------------------------------
void vtkRemoveDuplicatePolys::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkRemoveDuplicatePolys::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkPolyData *input = vtkPolyData::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
if (input->GetNumberOfPolys() == 0)
{
// set up a polyData with same data arrays as input, but
// no points, polys or data.
output->ShallowCopy(input);
return 1;
}
// Copy over the original points. Assume there are no degenerate points.
output->SetPoints(input->GetPoints());
// Remove duplicate polys.
std::map<std::set<int>, vtkIdType> polySet;
std::map<std::set<int>, vtkIdType>::iterator polyIter;
// Now copy the polys.
vtkIdList *polyPoints = vtkIdList::New();
const int numberOfPolys = input->GetNumberOfPolys();
vtkIdType progressStep = numberOfPolys / 100;
if (progressStep == 0)
{
progressStep = 1;
}
output->Allocate(numberOfPolys);
int ndup = 0;
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->CopyAllocate(input->GetCellData(), numberOfPolys);
for (int id = 0; id < numberOfPolys; ++id)
{
if (id % progressStep == 0)
{
this->UpdateProgress(0.8 + 0.2 * (static_cast<float>(id) / numberOfPolys));
}
// duplicate points do not make poly vertices or triangles
// strips degenerate so don't remove them
int polyType = input->GetCellType(id);
if (polyType == VTK_POLY_VERTEX || polyType == VTK_TRIANGLE_STRIP)
{
input->GetCellPoints(id, polyPoints);
vtkIdType newId = output->InsertNextCell(polyType, polyPoints);
output->GetCellData()->CopyData(input->GetCellData(), id, newId);
continue;
}
input->GetCellPoints(id, polyPoints);
std::set<int> nn;
std::vector<int> ptIds;
for (int i = 0; i < polyPoints->GetNumberOfIds(); ++i)
{
int polyPtId = polyPoints->GetId(i);
nn.insert(polyPtId);
ptIds.push_back(polyPtId);
}
// this conditional may generate non-referenced nodes
polyIter = polySet.find(nn);
// only copy a cell to the output if it is neither degenerate nor duplicate
if (nn.size() == static_cast<unsigned int>(polyPoints->GetNumberOfIds()) &&
polyIter == polySet.end())
{
vtkIdType newId = output->InsertNextCell(input->GetCellType(id), polyPoints);
output->GetCellData()->CopyData(input->GetCellData(), id, newId);
polySet[nn] = newId;
}
else if (polyIter != polySet.end())
{
++ndup; // cell has duplicate(s)
}
}
if (ndup)
{
vtkDebugMacro(<< "vtkRemoveDuplicatePolys : " << ndup
<< " duplicate polys (multiple instances of a polygon) have been"
<< " removed." << endl);
polyPoints->Delete();
output->Squeeze();
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRemoveDuplicatePolys.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.
=========================================================================*/
/**
* @class vtkRemoveDuplicatePolys
* @brief remove duplicate/degenerate polygons
*
* vtkRemoveDuplicatePolys is a filter that removes duplicate or degenerate
* polygons. Assumes the input grid does not contain duplicate points. You
* may want to run vtkCleanPolyData first to assert it. If duplicated
* polygons are found they are removed in the output.
*
* @sa
* vtkCleanPolyData
*/
#ifndef vtkRemoveDuplicatePolys_h
#define vtkRemoveDuplicatePolys_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
class VTKFILTERSCORE_EXPORT vtkRemoveDuplicatePolys : public vtkPolyDataAlgorithm
{
public:
static vtkRemoveDuplicatePolys *New();
void PrintSelf(ostream& os, vtkIndent indent) override;
vtkTypeMacro(vtkRemoveDuplicatePolys,vtkPolyDataAlgorithm);
protected:
vtkRemoveDuplicatePolys();
~vtkRemoveDuplicatePolys() override;
// Usual data generation method.
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *) override;
private:
vtkRemoveDuplicatePolys(const vtkRemoveDuplicatePolys&) = delete;
void operator=(const vtkRemoveDuplicatePolys&) = delete;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment