# Problem with CGAL Istotropic remeshing

**URL:** https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581
**Category:** Development
**Created:** [October 31, 2023, 7:03am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581 "2023-10-31T07:03:05Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [October 31, 2023, 7:03am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/1 "2023-10-31T07:03:05Z")

</div>

Hi  
I have a CGAL Code that works for remeshing but when I want to use the same task in VESPA, it gives me nothing. does anybody else who can help me?  
the results are shown below:

My code in CGAL:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e33b0caed4e06359a7b079e26601d79cb2119e7e.png)  
My code in VESPA:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/a67bf76b8edfbb1ebc86cd553f68b93311b527cf.png)  
the output in cmd:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e8e372f127f96e2e87e7c4e285cd1ef7c63005cc.png)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [October 31, 2023, 8:07am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/2 "2023-10-31T08:07:30Z")

</div>

@Charles_Gueunet

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [October 31, 2023, 8:39am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/3 "2023-10-31T08:39:49Z")

</div>

@kimia_ghodoosi As I see you used the same target length for both your native CGAL code and the Vespa one, I assume the preprocess you do with `split_long_edges` is the reason you don’t have the error in your version.

An easy fix would be to update the Vespa code with your own version to see if it works. A better approach would be to merge both. If you do so, please open a MR and I would be glad to update Vespa accordingly 🙂

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [October 31, 2023, 9:43am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/4 "2023-10-31T09:43:20Z")

</div>

does VTK have a class for remeshing? if I decide not to use CGAL or VESPA.  
@Charles_Gueunet

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [October 31, 2023, 12:55pm UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/5 "2023-10-31T12:55:56Z")

</div>

Sorry, I wanted to use toCGAL method for converting my polydata to a CGAL mesh but it doesn’t work although i created an object like this vtkNew rm  
could you please help me to convert a vtk polydata to a cgal surface mesh?

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [November 13, 2023, 3:29pm UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/6 "2023-11-13T15:29:45Z")

</div>

Regarding re-meshing, the closest thing you will find Delaunay. You can also have some decimation filters like the `vtkQadricDecimation`, as shown [here](https://www.linkedin.com/posts/kitware-sas_vtk-mesh-opensource-activity-7042389113550819328-2bYR), but this is more re-meshing.

for the CGal conversion, you may have a look at the `vtkCGALPolyDataAlgorithm::toCGAL` method [here](https://gitlab.kitware.com/vtk-cgal/vespa/-/blame/master/vespa/Algorithm/vtkCGALPolyDataAlgorithm.cxx?ref_type=heads#L21).  
Keep in mind that this method is used when adding new filters into Vespa. Using the library, you simply need to set your polydata as input of your filter.

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [December 26, 2023, 11:21am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/7 "2023-12-26T11:21:38Z")

</div>

Hi. I tried vtkQuadricDecimation and it was very good in Debug mode but it didn’t have the same result in release mode.do know how i can solve this problem?

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [December 28, 2023, 10:33am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/8 "2023-12-28T10:33:15Z")

</div>

Do you have a sharable state + data so I can try to reproduce the behavior ? You may want to try to compile in `RelWithDebInfo` in order to get the `Release` optimizations while still keeping some debug abilities. With a bit of luck, the undefined behavior will still leads to bug in this mode.

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [December 31, 2023, 11:08am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/9 "2023-12-31T11:08:48Z")

</div>

well, I built my project in “RelWithDebInfo” but it has the same problem that had had in Release mode.  
This is my code:  
double target\_reduction = targetReduction;  
vtkNew decimate;  
decimate-\>SetInputData(polydata);  
decimate-\>AttributeErrorMetricOn();  
decimate-\>SetTargetReduction(targetReduction);  
decimate-\>VolumePreservationOn();  
decimate-\>Update();

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [December 31, 2023, 11:18am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/11 "2023-12-31T11:18:31Z")

</div>

and my data is here

> **[2.STL](https://drive.google.com/file/d/1ML8qpLYuxPEaHVXIO0Z7pRpwYKlSGmVW/view?usp=drive_link)**
>
> Google Drive file.

the output is here:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/b/b5ffc89794f54323e7b31b6be966048a317c6aa4.png)

@Charles_Gueunet

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [January 4, 2024, 9:51am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/12 "2024-01-04T09:51:33Z")

</div>

@kimia_ghodoosi I quickly tried the following C++ pipeline:

```cpp
  vtkNew<vtkSTLReader> reader;
  reader->SetFileName(baseName.c_str());

  vtkNew<vtkConnectivityFilter> largestCC;
  largestCC->SetInputConnection(reader->GetOutputPort());
  largestCC->SetExtractionModeToLargestRegion();

  vtkNew<vtkQuadricDecimation> decimate;
  decimate->SetInputConnection(largestCC->GetOutputPort());
  decimate->AttributeErrorMetricOn();
  decimate->SetTargetReduction(0.9);
  decimate->SetVolumePreservation(true);
  decimate->Update();

  std::cout << "Actual reduction: " << decimate->GetActualReduction() << std::endl;

  vtkNew<vtkXMLPolyDataWriter> w;
  w->SetInputConnection(decimate->GetOutputPort());
  w->SetFileName("result.vtp");
  w->SetDataModeToAscii();
  w->Write();

```

With both VTK and my test module build in `Release`  
It leads to the following result:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/3374fb896eee9bad9640a3c504257e0a315ea4d0.jpeg)

Which seems fine to me. Here is the [result.vtp](https://discourse.vtk.org/uploads/short-url/2U8BaCxAWOdQPSyCaufa0qW7xa5.vtp) (317.1 KB) for inspection.  
I used VTK master for this pipeline, and I added a connectivity filter to extract the largest area.

Best,  
Charles

---

<div class="post-metadata">

### Author: ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)
#### Post date: [January 8, 2024, 6:39am UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/14 "2024-01-08T06:39:17Z")

</div>

Thank you so much for your response but I have the same problem that I had, with your code.my version of visual studio is 2019 and my VTK version is 9.2.6. do you think that the problem occures because of my Visual Studio or VTK?  
@Charles_Gueunet

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [January 11, 2024, 1:06pm UTC](https://discourse.vtk.org/t/problem-with-cgal-istotropic-remeshing/12581/15 "2024-01-11T13:06:26Z")

</div>

@kimia_ghodoosi I would suspect the version of VTK may be a potential suspect here as we improved the `vtkQuadricDecimation` in between v9.2 and v9.3. Can you try with the v9.3 release ?
