Skip to content
Snippets Groups Projects
Commit 3e806668 authored by Robbie Li's avatar Robbie Li
Browse files

use vtkNew to alloc the points and polys

parent a69e71b4
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMergePoints.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
......@@ -108,8 +109,8 @@ int vtkSTLReader::RequestData(
return 0;
}
vtkPoints *newPts = vtkPoints::New();
vtkCellArray *newPolys = vtkCellArray::New();
vtkNew<vtkPoints> newPts;
vtkNew<vtkCellArray> newPolys;
vtkFloatArray *newScalars = nullptr;
// Depending upon file type, read differently
......@@ -122,11 +123,9 @@ int vtkSTLReader::RequestData(
newScalars = vtkFloatArray::New();
newScalars->Allocate(5000);
}
if (!this->ReadASCIISTL(fp, newPts, newPolys, newScalars))
if (!this->ReadASCIISTL(fp, newPts.Get(), newPolys.Get(), newScalars))
{
fclose(fp);
newPts->Delete();
newPolys->Delete();
if(newScalars)
{
newScalars->Delete();
......@@ -143,8 +142,6 @@ int vtkSTLReader::RequestData(
{
vtkErrorMacro(<< "File " << this->FileName << " not found");
this->SetErrorCode(vtkErrorCode::CannotOpenFileError);
newPts->Delete();
newPolys->Delete();
if(newScalars)
{
newScalars->Delete();
......@@ -152,11 +149,9 @@ int vtkSTLReader::RequestData(
return 0;
}
if (!this->ReadBinarySTL(fp, newPts, newPolys))
if (!this->ReadBinarySTL(fp, newPts.Get(), newPolys.Get()))
{
fclose(fp);
newPts->Delete();
newPolys->Delete();
if(newScalars)
{
newScalars->Delete();
......@@ -172,8 +167,8 @@ int vtkSTLReader::RequestData(
fclose(fp);
// If merging is on, create hash table and merge points/triangles.
vtkPoints *mergedPts = newPts;
vtkCellArray *mergedPolys = newPolys;
vtkPoints *mergedPts = newPts.Get();
vtkCellArray *mergedPolys = newPolys.Get();
vtkFloatArray *mergedScalars = newScalars;
if (this->Merging)
{
......@@ -220,8 +215,6 @@ int vtkSTLReader::RequestData(
nextCell++;
}
newPts->Delete();
newPolys->Delete();
if (newScalars)
{
newScalars->Delete();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment