# vtkDecimatePro using vtkDataSet

**URL:** https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956
**Category:** Support
**Created:** [June 8, 2021, 1:26am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956 "2021-06-08T01:26:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Hyunwoo\_Kim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hyunwoo_kim/32/3465_2.png) [@Hyunwoo\_Kim](https://discourse.vtk.org/u/Hyunwoo_Kim)
#### Post date: [June 8, 2021, 1:26am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/1 "2021-06-08T01:26:24Z")

</div>

Hi,

I’m trying to use vtkDecimatePro for a surface mesh.

An input data I use is a format of the vtkDataSet.

However, the vtkDecimatePro seems to need a vtkPolyData format.

I’ve already tried to vtkPolyData::safeDownCast(myDataSet), and the process failed for some reason.

the data was converted to the vtkImageData, though.

I want to use vtkSmoothPolyDataFilter, vtkPolyDataNormal, vtkStripper after the vtkDecimatePro.

Is this an awesome way to use these filters with my dataset?

* * *

this is my dataset, and I wrote this file with a vtkDataSetReader.

[volumeData.zip](https://discourse.vtk.org/uploads/short-url/lrFnjO4qG19rkHgvoJEPcY5RHfG.zip) (8.3 KB)

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [June 8, 2021, 1:43pm UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/2 "2021-06-08T13:43:32Z")

</div>

Just use the vtkExtractSurface filter to get the vtkPolyData that you need from your dataset.

---

<div class="post-metadata">

### Author: ![Hyunwoo\_Kim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hyunwoo_kim/32/3465_2.png) [@Hyunwoo\_Kim](https://discourse.vtk.org/u/Hyunwoo_Kim)
#### Post date: [June 9, 2021, 2:34am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/3 "2021-06-09T02:34:37Z")

</div>

I got an error!, what have I done wrong?

```
vtkNew<vtkExtractSurface> surface;
surface->SetInputData(m_VolumeReader->GetOutput());
surface->SetRadius(5 * .99);
surface->Update();

vtkNew<vtkPolyData> testPolyData;
testPolyData->DeepCopy(surface->GetOutput());
vtkNew<vtkPolyDataMapper> testMapper;
testMapper->SetInputData(testPolyData);
testMapper->Update();
vtkNew<vtkActor> testActor;
testActor->SetMapper(testMapper);

m_ren->AddActor(testActor);

```

ERROR: In D:\Libraries\VTK\VTK 9.0.1\VTK-9.0.1\Common\ExecutionModel\vtkExecutive.cxx, line 753  
vtkCompositeDataPipeline (161CBD28): Algorithm vtkExtractSurface(161CBAA8) returned failure for request: vtkInformation (17B37C28)  
Debug: Off  
Modified Time: 11830  
Reference Count: 1  
Registered Events: (none)  
Request: REQUEST\_DATA  
FORWARD\_DIRECTION: 0  
ALGORITHM\_AFTER\_FORWARD: 1  
FROM\_OUTPUT\_PORT: 0

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [June 9, 2021, 2:55am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/4 "2021-06-09T02:55:13Z")

</div>

Nothing obvious but why don’t you use the pipeline (port/connection) rather than data object, updates, deepCopy?

---

<div class="post-metadata">

### Author: ![Hyunwoo\_Kim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hyunwoo_kim/32/3465_2.png) [@Hyunwoo\_Kim](https://discourse.vtk.org/u/Hyunwoo_Kim)
#### Post date: [June 9, 2021, 4:32am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/5 "2021-06-09T04:32:28Z")

</div>

I was converting VTK version from 5.0.3 to 9.0.1.  
Therefore, I’d to change some custom vtk clas using vtkPolyDataAlgorithm.  
In that process, I changed the pipeline.  
I’m finding why converted source don’t render actors correctly, so I tried to change some code between pipeline and just data.

1: [about RequestData - #7 by Hyunwoo\_Kim](https://discourse.vtk.org/t/about-requestdata/5925/7)  
2: [vtkImageData rendering issue](https://discourse.vtk.org/t/vtkimagedata-rendering-issue/5966)

here is my issues, and If you have any solution, It would be so appreciated…

---

<div class="post-metadata">

### Author: ![Hyunwoo\_Kim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hyunwoo_kim/32/3465_2.png) [@Hyunwoo\_Kim](https://discourse.vtk.org/u/Hyunwoo_Kim)
#### Post date: [June 9, 2021, 5:44am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/6 "2021-06-09T05:44:36Z")

</div>

I think the volume data is wrong.  
I wrote a dataset file.

It is incorrect data, isn’t it?

# .vtkvol

vtk DataFile Version 5.1  
vtk output  
ASCII  
DATASET STRUCTURED\_POINTS  
DIMENSIONS 128 128 256  
SPACING 0.2 0.2 0.1  
ORIGIN -12.8 -12.8 0  
POINT\_DATA 4194304  
SCALARS ImageScalars short  
LOOKUP\_TABLE default  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851  
-12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851 -12851

```
vtkVolumeData->SetOrigin(sx, sy, sz);
vtkVolumeData->SetSpacing(dx, dy, fPosZ);
vtkVolumeData->AllocateScalars(VTK_SHORT, 1);
vtkVolumeData->SetDimensions(cxImageData,cyImageData,czImageData);
vtkVolumeData->GlobalReleaseDataFlagOn();

scalars->SetArray(m_pFullVolume->GetData(), cxImageData*cyImageData*czImageData, 0);

vtkVolumeData->GetPointData()->SetScalars(scalars);

```

is this style not supported anymore in the VTK 9 version?

---

<div class="post-metadata">

### Author: ![Hyunwoo\_Kim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hyunwoo_kim/32/3465_2.png) [@Hyunwoo\_Kim](https://discourse.vtk.org/u/Hyunwoo_Kim)
#### Post date: [June 9, 2021, 7:32am UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/7 "2021-06-09T07:32:50Z")

</div>

this is a piece of additional information!

# Changed Data

vtk DataFile Version 5.1  
vtk output  
ASCII  
DATASET STRUCTURED\_POINTS  
DIMENSIONS 128 128 256  
SPACING 0.2 0.2 0.1  
ORIGIN -12.8 -12.8 0  
POINT\_DATA 4194304  
SCALARS ImageScalars short  
LOOKUP\_TABLE default  
1000 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 999 999 999 999 999 999 999 999  
999 1000 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998  
998 998 998 998 998 998 998 998 998

# Read DataSet & check max index

```
vtkDataSetReader* m_VolumeReader = vtkDataSetReader::New();
m_VolumeReader->SetFileName("D:\\Data\\.vtkvol");
m_VolumeReader->ReadAllScalarsOn();
m_VolumeReader->Update();

vtkDataSet* dataset = m_VolumeReader->GetOutput();
double num = dataset->GetNumberOfPoints();
vtkPointData* pointdata = dataset->GetPointData();
vtkDataArray* array_ = pointdata->GetScalars();

int numpts = array_->GetMaxId();

```

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [June 9, 2021, 2:47pm UTC](https://discourse.vtk.org/t/vtkdecimatepro-using-vtkdataset/5956/8 "2021-06-09T14:47:07Z")

</div>

That seems correct with VTK 9.
