# vtkCGALRegionFairing error

**URL:** <https://discourse.vtk.org/t/vtkcgalregionfairing-error/14262>\
**Category:** Development\
**Created:** [July 20, 2024, 5:55am UTC](https://discourse.vtk.org/t/vtkcgalregionfairing-error/14262 "2024-07-20T05:55:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabaya](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sabaya](https://discourse.vtk.org/u/sabaya)\
**Post date:** [July 20, 2024, 5:55am UTC](https://discourse.vtk.org/t/vtkcgalregionfairing-error/14262/1 "2024-07-20T05:55:48Z")

</div>

Hey there, I’ve performed a boolean operation on my two polydata sets. Additionally, I’ve identified the intersection line between them. Next, I found the neighbors of the intersection points and saved them in a vtkPoints set named ‘FairingPoints’. Now, I’m attempting to use vtkCGALRegionFairing with this code:

```auto
vtkSmartPointer<vtkBooleanOperationPolyDataFilter> booleanFilter = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
        booleanFilter->SetInputData(0, CubeSmoothFilter1->GetOutput());
        booleanFilter->SetInputData(1, OriginalData);
        booleanFilter->SetOperationToUnion();
        booleanFilter->Update();

        vtkNew<vtkTriangleFilter> BooltriangleFilter;
        BooltriangleFilter->SetInputData(booleanFilter->GetOutput());
        BooltriangleFilter->Update();

        vtkSmartPointer<vtkPolyData> BooleanPolydata;
        BooleanPolydata = BooltriangleFilter->GetOutput();

        vtkNew<vtkIdFilter> BoolId;
        BoolId->SetInputData(BooleanPolydata);
        BoolId->SetCellIds(false);
        BoolId->SetCellIds(false);
        BoolId->SetPointIds(true);

        BoolId->SetPointIdsArrayName("PointIds");
        BoolId->Update();

        vtkSmartPointer<vtkDataSet> BooleanWithId;
        BooleanWithId = BoolId->GetOutput();

        cout << "Boolean Done!" << endl;

        vtkNew<vtkPoints> FairingPoints;

        
        // Create the control locator from foot points polydata set.
        vtkNew<vtkPointLocator> ControlLocator;
        ControlLocator->SetDataSet(BooleanPolydata);
        ControlLocator->BuildLocator();

        vtkSmartPointer<vtkIdList> closestPoints = vtkSmartPointer<vtkIdList>::New();

        for (int i = 0; i < FootPointsPolydata->GetNumberOfPoints(); ++i) {
            double queryPoint[3];
            FootPointsPolydata->GetPoint(i, queryPoint);

            ControlLocator->FindPointsWithinRadius(5, queryPoint, closestPoints);

            for (vtkIdType j = 0; j < closestPoints->GetNumberOfIds(); ++j) {
                vtkIdType id = closestPoints->GetId(j);
                double point[3];
                BooleanPolydata->GetPoint(id, point);
                FairingPoints->InsertNextPoint(point);
            }
        }

        vtkSmartPointer<vtkIntArray> ROIIdsArr = vtkSmartPointer<vtkIntArray>::New();
        ROIIdsArr->SetNumberOfTuples(FairingPoints->GetNumberOfPoints());

        //roi pointIds
        // should be from main data
        for (vtkIdType i = 0; i < FairingPoints->GetNumberOfPoints(); ++i)
        {
            double point[3];
            FairingPoints->GetPoint(i, point);
            vtkIdType pointId = BooleanWithId->FindPoint(point);
            ROIIdsArr->SetTypedComponent(i, 0, pointId);
            
        }
        vtkNew<vtkIdTypeArray> arr;
        arr->SetNumberOfTuples(ROIIdsArr->GetNumberOfValues());
        for (vtkIdType idx = 0; idx < ROIIdsArr->GetNumberOfValues(); ++idx)
        {
            arr->SetValue(idx, ROIIdsArr->GetValue(idx));
        }

        // Create point selection for the ROI
        vtkNew<vtkSelection> sel;
        vtkNew<vtkSelectionNode> node;
        sel->AddNode(node);
        node->GetProperties()->Set(vtkSelectionNode::CONTENT_TYPE(), vtkSelectionNode::INDICES);
        node->GetProperties()->Set(vtkSelectionNode::FIELD_TYPE(), vtkSelectionNode::POINT);
        node->SetSelectionList(arr);

        vtkNew<vtkCGALRegionFairing> fr;
        fr->SetInputData(0, BooleanWithId);
        fr->SetInputData(1, sel);
        fr->UpdateAttributesOff();
        fr->Update();

        cout << "fairing Done!" << endl;

```

but i met this error:

```auto
CGAL error: assertion violation!
Expression : CGAL::is_triangle(he, m_pmesh)
File : E:\VTK\vcpkg\vcpkg\installed\x64-windows\include\CGAL/Weights/cotangent_weights.h
Line : 356
Explanation:
Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html
2024-07-18 11:29:28.149 ( 63.142s) []vtkCGALRegionFairing.cx:103 ERR| vtkCGALRegionFairing (000001DEC454D2C0): CGAL Exception: CGAL ERROR: assertion violation!
Expr: CGAL::is_triangle(he, m_pmesh)
File: E:\VTK\vcpkg\vcpkg\installed\x64-windows\include\CGAL/Weights/cotangent_weights.h
Line: 356
2024-07-18 11:29:28.180 ( 63.174s) [] vtkExecutive.cxx:741 ERR| vtkCompositeDataPipeline (000001DEBE85A710): Algorithm vtkCGALRegionFairing (000001DEC454D2C0) returned failure for request: vtkInformation (000001DEBF27BF50)
  Debug: Off
  Modified Time: 2640979
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA
  FORWARD_DIRECTION: 0
  ALGORITHM_AFTER_FORWARD: 1
  FROM_OUTPUT_PORT: 0

```

what can i do for this problem?

---

<div class="post-metadata">

**Author:** ![Francois\_Mazen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/francois_mazen/32/3290_2.png) [@Francois\_Mazen](https://discourse.vtk.org/u/Francois_Mazen)\
**Post date:** [July 24, 2024, 5:50am UTC](https://discourse.vtk.org/t/vtkcgalregionfairing-error/14262/2 "2024-07-24T05:50:17Z")

</div>

I guess you are using [VESPA](https://gitlab.kitware.com/vtk/meshing/vespa) ?

In this case @Charles_Gueunet may have some clues.

---

<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:** [July 24, 2024, 7:01am UTC](https://discourse.vtk.org/t/vtkcgalregionfairing-error/14262/3 "2024-07-24T07:01:29Z")

</div>

It seems CGAL complains about a non triangle cell. I find this strange as you applied a triangle filter, so we need to understand what is the issue here.  
I would recommend you to try check `BooleanWithId` for any non-triangle cells. Maybe you have edge cells in it, the `vtkTriangleFilter` won’t triangle them.  
If you need, you can share your dataset, I can have a look too and tell how I did if I find anything.
