# Homogeneous quad-remeshing

**URL:** <https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505>\
**Category:** compas\
**Created:** [August 17, 2021, 12:17pm UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505 "2021-08-17T12:17:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![solub](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@solub](https://forum.compas-framework.org/u/solub)\
**Post date:** [August 17, 2021, 12:17pm UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/1 "2021-08-17T12:17:58Z")

</div>

Hi,

Is it possible to operate a quad-remeshing with homogeneous quadrilateral faces (around the same area, quasi-parallel edges) using Compas ?

Would the **libigl** or **gmsh** extensions provide something similar to the QuadRemesh algorithm available in Rhino7 ?

 ![ssr](https://us1.discourse-cdn.com/flex015/uploads/compas_framework1/original/1X/83345ad11a114b3ae228e2ab9a17a6f946187f91.png)

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [August 23, 2021, 7:00am UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/2 "2021-08-23T07:00:51Z")

</div>

hi,

there is currently no such function in COMPAS, but there are quad (re)meshing  
functions available through `compas_singular`, which is a package based on the PhD research of Robin Oval.

> **[GitHub - BlockResearchGroup/compas\_singular: Topology finding for patterns](https://github.com/BlockResearchGroup/compas_singular)**
>
> Topology finding for patterns. Contribute to BlockResearchGroup/compas\_singular development by creating an account on GitHub.

the function in `compas_libigl` (except for quad planarization) deal exclusively with triangle meshes. not sure about `igl` itself…

the GMSH mesh model of `compas_gmsh` has a “recombine” method, which recombines a triangle mesh into a quad mesh…

[https://compas.dev/compas\_gmsh/latest/api/generated/compas\_gmsh.models.MeshModel.html#compas\_gmsh.models.MeshModel](https://compas.dev/compas_gmsh/latest/api/generated/compas_gmsh.models.MeshModel.html#compas_gmsh.models.MeshModel)

---

<div class="post-metadata">

**Author:** ![solub](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@solub](https://forum.compas-framework.org/u/solub)\
**Post date:** [May 27, 2023, 5:04pm UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/3 "2023-05-27T17:04:27Z")

</div>

Hi,

I hope you won’t mind me bumping this thread as I’m considering again the possibility to create quad meshes with compas in Grasshopper.

I have both the latest version of **compas** and the **compas\_singular** package installed on my machine. When running `02_decomposition_discrete_planar.py` from the example folder (the one shown [here](https://web.archive.org/web/20200915062726/https://blockresearchgroup.github.io/compas_singular/examples/01_decomposition.html)), the following line:

```auto
# build decomposition mesh
coarsemesh = decomposition.decomposition_mesh(point_features)

```

throws this error:

```auto
Runtime error (KeyNotFoundException): dictionary is empty

Traceback:
  line 54, in boundaries, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\site-packages\compas_singular\datastructures\mesh\mesh.py"
  line 154, in branches_boundary, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\site-packages\compas_singular\algorithms\decomposition.py"
  line 174, in decomposition_polylines, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\site-packages\compas_singular\algorithms\decomposition.py"
  line 210, in decomposition_mesh, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\site-packages\compas_singular\algorithms\decomposition.py"
  line 27, in script

```

It seems the problem occurs within the `boundaries` function in the `mesh.py` file. Specifically, inside this snippet (from line 46 to 64):

```auto
boundary_edges = {}
for u, v in self.edges():
    if self.halfedge[u][v] is None:
        boundary_edges[u] = v
    elif self.halfedge[v][u] is None:
        boundary_edges[v] = u

boundaries = []
boundary = list(boundary_edges.popitem()) # <--- line 54 throwing the error
while len(boundary_edges) > 0:
    w = boundary_edges.pop(boundary[-1])
    if w == boundary[0]:
        boundaries.append(boundary)
        if len(boundary_edges) > 0:
            boundary = list(boundary_edges.popitem())
    else:
        boundary.append(w)

return boundaries

```

My guess is that line 54 is trying to `pop()` an element from the dictionary `boundary_edges` which, in this case, seems to be empty.

This is weird because neither `outer_boundary` nor `inner_boundaries` (provided as arguments when constructing the triangulated mesh) is empty. They both contain the vertices coordinates provided in the example JSON file. Same thing for `point_features`.

Could you help me figure out what’s going on?

---

<div class="post-metadata">

**Author:** ![solub](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@solub](https://forum.compas-framework.org/u/solub)\
**Post date:** [May 27, 2023, 6:31pm UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/4 "2023-05-27T18:31:54Z")

</div>

Ok, two issues I’m seeing after reviewing the source code:

- The delaunay mesh `trimesh` in the example returns without faces and edges.  
There seems to be an indexing mistake inside the `boundary_triangulation` function in [triangulation.py](https://github.com/BRG-research/compas_singular/blob/660245618ef99a6bf6fdb767719e4377e6b4d761/src/compas_singular/algorithms/triangulation.py). At line 64, `trimesh_face_circle()` from `compas.datastructures` returns a nested tuple and Mr. Oval (the author) select the first tuple instead of the center coordinates inside that tuple.

- The SkeletonDecomposition `decomposition` in the example returns a delaunay mesh instead of a `SkeletonDecomposition` object. Specifically, line 75 in [decomposition.py](https://github.com/BRG-research/compas_singular/blob/660245618ef99a6bf6fdb767719e4377e6b4d761/src/compas_singular/algorithms/decomposition.py) should return a `SkeletonDecomposition` object:

It is very strange because yesterday I had all this working fine without any change in the source code. It is beyond my why it suddenly stopped working.

---

<div class="post-metadata">

**Author:** ![solub](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@solub](https://forum.compas-framework.org/u/solub)\
**Post date:** [May 28, 2023, 12:28pm UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/5 "2023-05-28T12:28:30Z")

</div>

Finally got it working but, good lord, **compas\_singular** is a mess in its current state.

Please correct me if I’m wrong but it appears to me that the latest version available with `pip` install is only an incomplete draft of a future version, designed to be more robust and to work with the recent versions of compas. As a result, one would have to downgrade to the latest working release **and** modify it in order to get it up running with the current edition of compas.

This is the process I went through:

- follow the installation instructions archived [here](https://web.archive.org/web/20200915062726/https://blockresearchgroup.github.io/compas_singular/01_getting_started.html). If compas is installed in a specific `conda` environment, open that environment first:

- find the location of compas\_singular:

By now, the example files should be working.

Questions to @robin-oval:

- I notice that compas\_singular is not stable. Very often `decomposition.decomposition_mesh(point_features)` fails to output a coarse mesh in a single run (multiple attempts are necessary). I suspect the initial random jittering of the vertices required to compute the delaunay mesh to be the cause. Have you considered a workaround to prevent this behaviour?

- Nearly all meshes outputted by compas\_singular lack homogeneity. Most quad faces are irregular in area and distribution because of the layout assigned by the medial axis. Would there be a way to process the outputted “raw” coarse quad mesh in order to “free” it from this constraint? If so, would you mind providing an example?  

- Would you mind briefly explaining what is the purpose of `point_features` and `polyline_features` when constructing a coarse quad mesh?

- In an online lecture given to MPDA BarcelonaTech a couple of years ago you [expressed](https://youtu.be/67tjrIq3HBk?t=3249) your intention to provide compas\_singular as a pluggin (a “toolbar”) for Grasshopper. Is this still on the agenda?

Please don’t give up, we’re counting on you!

---

<div class="post-metadata">

**Author:** ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)\
**Post date:** [June 14, 2023, 6:23am UTC](https://forum.compas-framework.org/t/homogeneous-quad-remeshing/505/6 "2023-06-14T06:23:12Z")

</div>

hi,

`compas_singular` is indeed not very well maintained at the moment.  
will try to address this asap.

perhaps add the changes you had to make to the issue tracker of the package so it easier to assign someone to have a look…

thanks!
