Topological representation of cloth state for robot manipulation

Forty years ago the notion of configuration space (C-space) revolutionised robot motion planning for rigid and articulated objects. Despite great progress, handling deformable materials has remained elusive because of their infinite-dimensional shape-state space. Finding low-complexity representations has become a pressing research goal. This work tries to make a tiny step in this direction by proposing a state representation for textiles relying on the C-space of some distinctive points. A stratification of the configuration space for n points in the cloth is derived from that of the flag manifold, and topological techniques to determine adjacencies in manipulation-centred state graphs are developed. Their algorithmic implementation permits obtaining cloth state–space representations of different granularities and tailored to particular purposes. An example of their usage to distinguish between cloth states having different manipulation affordances is provided. Suggestions on how the proposed state graphs can serve as a common ground to link the perception, planning and manipulation of textiles are also made.


Introduction
Robot manipulation in human environments is an important research field that in recent years has experienced tremendous progress. Impressive results have been obtained among the many open problems pinpointed a decade ago (Kemp et al. 2007), such as humanoid whole-body reaching, mobile manipulation and human-robot collaboration. Research has focused on core capabilities as grasping everyday objects, carrying and placing them, as well as robot hand-over to or  Indeed, non-rigid objects -textile items in particularpose many additional challenges with respect to rigid object manipulation, such as difficult perception, complexity in modelling the object and predicting its behaviour, and the many uncertainties hindering motion planning to reach a desired outcome. Despite these difficulties, the manipulation of clothing items is nowadays gaining attention in the robotics community due to the rise of assistive and service robotics (Torras 2016). As clothing items pervade human environments, automating their versatile manipulation would have a large impact on society, in sectors ranging from healthcare to clothing industry. The key problem underlying all these difficulties is that, whereas handling a rigid object only changes its pose, namely 6 parameters (the configuration space is the well-known R 3 × SO(3)), the manipulation of a textile object takes place in a shape-state space which is potentially infinite-dimensional. This huge dimensionality jump prevents the extension of the techniques developed for rigid objects (for perception, planning, learning and manipulation) to textile ones, and calls for a radically different approach.

Related work
The extension of available techniques consists of modelling cloth as a finite element mesh and applying both physics simulation and motion planning algorithms for closed-loop multi-articulated objects. This is appropriate for rendering where realistic appearance is sought, and impressive advances have taken place recently in the computer vision and computer graphics communities (Pumarola et al. 2018;Bai et al. 2016), but robot manipulation has not benefited so far from them, because of its substantially different final aims. In the graphics context, the goal can be among others to render the dressing of a human body, representing with accuracy the clothing as offsets from the body (Ma et al. 2019;Guan et al. 2012;Pons-Moll et al. 2017), as well as to estimate with precision the clothing pose based on generative models for 3D shapes using topology (Hilaga et al. 2001).
For these approaches, rendering precision is important, while for robot manipulation, local details such as wrinkles and accurate position can be overlooked in favour of properly determining the macro-state the cloth is in. By macro-state we mean a set of cloth configurations that can be manipulated in the same way, i.e., that have similar grasping affordances.
In the robot manipulation community there is a longstanding general agreement that "low complexity representations for the deformable objects should be the objective" (Smith et al. 2012) and some attempts to use topological constructs to this end have been made, using writhe matrices, winding numbers and Laplacian coordinates for topologybased representations (Ivan et al. 2013;Yuan et al. 2019), as well as loops detection (Pokorny et al. 2013) and topology coordinates for representing human pose as captured by a motion capture system (Koganti et al. 2017), but also in combination with deep learning approaches (Yan et al. 2020).
Further along this line, we propose to characterise cloth macro-states, called just 'states' in what follows, using combinatorial topology techniques. Inspired by previous works on the topological representation of robot configuration spaces (Canny 1988;Torras et al. 2006), we consider a set of significant points in the cloth and rely on the process of stratification to decompose the configuration space (C-space) of such points into manipulation-wise meaningful states, as well as to derive their adjacencies.
The outcome is a succinct manipulation-oriented cloth state representation in the form of a graph that permits encoding actions as probabilistic state transitions and then applying the powerful probabilistic task planning machinery developed within the AI community (Geißer et al. 2019;Canal et al. 2019). Another potential advantage is the simplification of perception, since states can be recognised without accurately recovering the cloth configuration, and only local features relevant for grasping need to be located. The paper is structured as follows. In Sect. 3 we use the notion of stratification to study the topological space of configurations of points, focussing first on the case of 4 points. We investigate how such stratification can be obtained using the algebraic condition given by the alignment of three points. This allows us to assign to each configuration of n points a concise "label" and ensure that those with different label are effectively separated by the stratification in different strata. We also provide an explicit algorithm to construct such stratification for the case n < 7. We proceed then, in Sect. 4, to investigate the complexity of the stratification and how to simplify it. This can be efficiently done using its topological properties and the action of the symmetric group S n , defining the state of a configuration of points as a collection of one or more strata. Thanks to such states, we can investigate how the points of a mesh are distributed with respect to some fixed ones (for example the corner ones in a rectangular textile) and compare different mesh poses based on the state-distribution of their points.

Configuration space of a textile rectangle using n points
Given a rectangular cloth on a planar surface, we could consider it as a surface embedded in R 3 with no self-intersection. Unfortunately, considering the different configurations of such surface and studying their space bears difficulties. On the already complex space of all possible surfaces with same area and no self-intersections, we need to impose also constraints such as gravity force and cloth stiffness. In order to simplify, we consider instead the cloth as a set of n points on the real plane R 2 and the space of all possible configurations of them, Con f n (R 2 ). This space belongs to the far more general family of configuration spaces of points on manifolds, Such spaces are interesting topological objects and both their homotopy type and homological properties have been studied by several authors. In Arnold (1969) some results regarding the homotopy type of Con f n (X ) are obtained, assuming X is of dimension 2, while the real homotopy type of Con f n (X ), when X is a smooth projective variety, was independently computed by Kriz (1994) and Totaro (1996). In Cohen et al. (1976) under the assumption X = R n , the homology of Con f n (X ) is computed and, in particular, it is proved that Con f n (R n ) is the classifying space of the n-strand pure braid group. Since our aim is to distinguish states based on the types of robot manipulations they permit, we will investigate how such space can be subdivided into meaningful regions, each one formed by several configurations of n points. The proce- Fig. 1 The points p 1 and p 2 are fixed, while p 4 has to be inside the grey circle, of radius d (Color figure online) dure introduced here allows us to assign to any configuration of points a binary vector, whose length depends on the number of points considered. In this way we can group together configurations with the same vector representation and in addition we will be able to plan which regions of C-space we need to "visit" if we want to move from one state to another.
To obtain such structure for Con f n (R 2 ) we will employ the notion of stratification of a topological space. The idea behind such notion is to decompose topological spaces of dimension m into smooth parts of dimension m, such that the boundary between any two of them is a subspace of dimension m − 1. As we can iterate such process at each dimension 0 ≤ k ≤ m, the stratification assumes the form of a filtration, ∅ ⊆ X 1 ⊆ X 2 ⊆ · · · ⊆ X m = Con f n (R 2 ), where each X i is the union of disconnected smooth parts, called strata of dimension i and the boundary, called singularity of dimension i − 1, between two strata belongs to X i−1 . The structure of a stratification can be quite complex, however for simple cases one can visualise it clearly. Consider 4 points in the plane, as in Fig. 1, such that p 1 and p 2 are fixed and || p 4 − p 1 || ≤ d.
Their C-space is a solid torus, product of a disk, encoding the position of p 4 , and a circle, encoding the angle of p 1 p 2 and p 3 p 4 , and it is clearly contained in Con f 4 (R 2 ). Its stratification can be seen in Fig. 2 , where we use alignment between points to define singularities.
Our first step towards the construction of a stratification for Con f n (R 2 ) is to investigate the simplest non-trivial case of n = 4, which will prove to be essential in the treatment of the general case. For both this case and the general one the main idea consist in identify as singularity a subspace of Con f n (R 2 ), where three points are aligned, so that, in the highest dimensional strata no triple of point can be aligned. We will show that such alignment is defined by an algebraic condition (a null determinant) and it provides us with a concise way to encode the different strata (as vectors of signs of determinants). This property allows us to determine easily the corresponding stratum (or singularity) of any point configuration. We also introduce a constructive way, Algorithm 1, to build such stratification when n < 7 in a finite number of steps.

C-space of a textile rectangle using 4 points
For the case n = 4 we will rely on the stratification of the flag manifold of RP 2 , Flag(3). The elements of Flag(3) are On the top we can see four disconnected 3D strata of the Cspace, obtained by cutting the torus with the 2D singularities. These are two disks (in purple on the bottom), which correspond to p 3 ∈ p 1 p 2 , and one annullus (in light green on the bottom), corresponding to p 4 ∈ p 1 p 2 . On the bottom picture we show also the 1D singularities (in black) and two 0D singularities (in yellow). The former correspond to p 1 = p 4 (a circle) and p 3 p 4 = p 1 p 2 (two segments). The latter correponds to the case when both p 4 = p 1 and p 3 p 4 = p 1 p 2 (Color figure online) The strata corresponding to such stratification are Bruhat cells, as shown in Hiller (1982); Monk (1959). The resulting stratification can be seen in Fig. 3, we refer the reader to Milnor and Stasheff (1975) for a more detailed description.
Consider the points p 1 , p 2 , p 3 and p 4 in R 2 as points in the projective plane, by adding 1 as last projective coordinate. We define V * = {p 1 , p 1 p 2 } as reference flag and consider the flag V = {p 3 , p 3 p 4 }. Note that, in an abuse of language, we are denoting p i both the point in RP 2 and the one in R 2 . Each stratum in Fig. 3 of dimension at most 2 corresponds to some point alignment. For example if V is in the stratum v − l * then { p 1 , p 2 , p 3 } are aligned, both in R 2 and RP 2 . This means that we can induce a stratification of Con f n (R 2 ) using the one of Flag(3). In particular, any alignment of p i , p j , p k can be seen as a pure algebraic condition on the points coordinates, given by the singularity of the determinant d i, j,k = |p i p j p k |. The sign of such determinant will depend on the clockwise or counter-clockwise position of the ordered triple ( p i , p j , p k ). Because the determinant is a continuous map onto R, if two configurations p and q differ by one and only one determinant sign, say d i, j,k , then we know that any continuous path from one configuration to the other has to cross the singularity loci of d i, j,k .
The stratification in Fig. 2 can be interpreted using the Flag(3) stratification. Considering the reference flag V * = { p 1 , p 1 p 2 } and V = {p 4 , p 4 p 3 }, we have that the annulus, singularity of dimension 2, corresponds to v − l * . Inside it we have v − v * , which is the singularity of dimension 1, displayed as a black circle. Finally, the singularities of dimension 0, displayed as yellow points, are v −v * , l −l * . Actually, there are 2 determinants that we are not considering, namely d 1,3,4 and d 2,3,4 . The singularity surfaces are more difficult to visualize and would lead to a much finer stratification. Given any configuration of 4 points in R 2 we can map it continuously to R 4 , assigning to each coordinate the determinant value of d 1,2,3 , d 1,2,4 , d 1,3,4 and d 2,3,4 , respectively. The singularity locus of a determinant can be seen either as an alignment of three points, as a flag intersection, or also as a hyperplane in R 4 corresponding to one coordinate equal to 0. If we consider R 4 minus the coordinate hyperplanes, x i = 0 for i = 1, . . . 4, we obtain 16 disconnected smooth regions, each one containing points with same coordinates signs, that is, corresponding to configurations of points with same determinant signs. The reader should be aware however that such mapping is not one-to-one More than one configuration can be mapped to the same point in R 4 , as the determinants are invariant under R 2 -isometries.
The counter-image of these regions of R 4 are the highest dimensional strata of the stratification of Con f n (R 2 ) and they correspond to the subsets of all configuration with identical determinant signs. We can then uniquely associate to each stratum the label of the determinant signs sequence of any configuration of points in it, that is, a binary vector with 4 entries.
Note that each configuration in Fig. 4 would require in principle different robot manipulations for a folding task, e.g., using the taxonomy in Borràs et al. (2020), we would use point-tableplane sliding for the spread out configuration; point-point pick-up for the corner in the middle of the cloth; point-gripperplane sliding for the overfolded cloth, so as to turn it out.
These labels will not only tell us how to group "similar" configurations but also how "different" two configurations are. For example, we can count how many signs, resp. singularities, a continuous path from one configuration to another The region on the lower left corner (coloured in green) is the only one in common between the regions in which d 1,2,4 is negative (left of p 1 p 2 , coloured in yellow) and the ones in which d 2,3,4 is negative (below p 2 p 3 , coloured in blue). In this region also d 1,3,4 is negative (Color figure online) will change, resp. cross. The reader can now see that for n < 4 such approach would be trivial. In the case of n = 3 we get only two strata, corresponding to p 3 being on the right/left of the line p 1 p 2 . If n = 1, 2 then it is clear we cannot even define any determinant.
In the case n = 4, the maximum number of strata we could obtain is 2 4 = 16, however using the determinants expressions, we derive the following algebraic equation It is straightforward to see that it is impossible that either d 1,2,3 and d 1,3,4 are positive and d 1,2,4 and d 2,3,4 are negative or vice versa. We can verify it explicitly considering the regions obtained assuming 3 points fixed, say p 1 , p 2 and p 3 , and d 1,2,3 either positive or negative. The former case is showed in Fig. 5.
Another consequence of such equation is that, if a configuration of points belongs to a stratum with odd number of minuses in its label, then there exists one point lying inside the triangle spanned by the others. We will call from now on such strata internal, otherwise we call them external. A graph of the adjacencies between the strata is shown in Fig. 6. We refer the reader to "Appendix A" for a thorough study of Fig. 6 Representation of Con f 4 (R 2 ), with strata adjacencies indicated by links between different sign sequences. We used cyan ellipses to denote external strata and red rectangles for internal ones (Color figure online) such relationships with respect to the Flag(3) stratification for the case n = 4.

C-space of a textile rectangle using n points
We can apply a similar procedure and obtain a similar definition of stratum for the general case of n points, however some issues regarding the admissibility of sign sequences need to be addressed.
As n increases, the number of flags and their position with respect to each other becomes more difficult to encode and a description based on it would make less clear the structure of the space. To avoid it we will employ only the determinants to detect changes between configurations. We know that given n points we have k = n 3 different triples of points, that is, k possible determinants. We can map any configuration of n points to a point (x 1 , . . . , x k ), where each x i corresponds to the determinant of a particular triple of points. We know that each coordinate hyperplane, x i = 0 for i = 1, . . . , k, corresponds to a singularity, that is, a determinant equal to zero, and the determinants are again continuous functions. We can then define a stratum of Con f n (R 2 ) as the set of all configurations of n points with the same determinant sign sequence, and represent singularities between strata by null determinants, or equivalently by the alignments of three points. Such strata will correspond to regions of R k after removing all coordinate hyperplanes. From now on, we consider the determinants ordered with lexicographic order on their indices with the constraint that for k = 3, . . . , n, the first k 3 ones are those of { p 1 , . . . , p k }.
Even if we are able to encode each configuration of points as a sign sequence, we do not have a priori a way to determine if a sign sequence is admissible. This is an essential step of our study, because we want to be able, not only to group "similar" configurations, but as well navigate such stratification. For example if we want to find the optimal way to move n points from one configuration to another belonging to a different stratum, we might need to know which are the allowable paths, that is, which strata we can visit.
Suppose that n−1 points are fixed and we want to study the regions in which the arrangement of lines spanned by pairs of these points divide R 2 . Note that, these would represent strata of Con f n (R 2 ), with identical determinant signs for the fixed n − 1 points. This approach together with the knowledge of the stratification of Con f n−1 (R 2 ) would allow to construct the stratification of Con f n (R 2 ). Line arrangements, both in the real and projective planes, have been studied extensively in various contexts, see Grünbaum (1972) and references therein. Several authors have worked on how to bound the number of regions, triangles or polygons (Roudneff 1986;Strommer 1977;Simmons 1973). In Aichholzer et al. (2018), the authors consider the problem of characterising geometric graphs using the order type of their vertex set. Using the notion of minimal representation of a graph, they identify which edges prevent the order type from changing via continuous deformations of the graph. Even if this approach is the closest to ours, to our knowledge in the literature there is not a detailed study of the adjacency relations of Con f n (R 2 ). In particular there is not a study that tells us exactly which determinant signs sequence is admissible and which is not. We present here an iterative technique to construct the stratification of Con f n (R 2 ).
The adjacency of two strata σ, τ can be seen as the possibility of nullifying one and only one determinant via continuous movement of a configuration p in σ to another q in τ . So if, given any stratum σ , we are able to detect with a deterministic test which determinants can or cannot be nullified, we are effectively identifying which strata are adjacent to σ . We can iteratively apply such test to these strata and, as Con f n (R 2 ) is connected (Cohen et al. 1976), we would recover all the existing strata. For any n ≥ 3 there exists always a configuration p * such that each determinant sign of any triple of points is positive, namely when the points are placed to form a convex n-gon and they are in counterclockwise order. In other words, there is always a stratum σ * whose sign sequence is formed only by positive signs and that can be always used as starting point in such iterative process to find the strata of Con f n (R 2 ). We will now proceed to explain how we can rigorously describe such test.
We know that the symmetric group S n acts on Con f n (R 2 ) via point permutations. That is, if we have p = {p i } n i=1 , a configuration of n points, then the induced action of g, call it f g , is defined as furthermore it is also an automorphism of the singularity loci, as the singularity of a matrix does not change when we permute its rows. The action of g on the sign sequences can be easily deduced. Let σ be the stratum of p and g ∈ S n , then the sign of d g(i),g( j),g(k) of the stratum τ = g · σ to which g · p belongs is the same, resp. opposite, of d i, j,k if the signature of (g(i), g( j), g(k)) is positive, resp. negative. From now on, we will study the adjacency between σ and τ that differs by the sign of d 1,2,3 , otherwise we can reduce to such case via a permutation of S n . In what follows, we assume w.l.o.g. that σ has d 1,2,3 with positive sign. In other words, the adjacency test for σ is reduced, via a suitable permutation, to establish if the determinant d 1,2,3 can be nullified. Such property is equivalent to the existence of the following map.

Definition 1 (Crossing map) Let p be a configuration in
The existence of a crossing map for p ∈ σ , a continuous path in Con f n (R 2 ), is equivalent to the existence of τ , a stratum with sign sequence identical to that of σ but for the d 1,2,3 sign. It is clear now that such existence for a p ∈ σ is equivalent to the adjacency test for σ we were looking for. We present here two theorems that allow us to determine if and when a crossing map exists. Such theorems are constructive, that is, we show also how we move continuously a point (or more if needed) to change only one determinant sign. We know that any triple of not-aligned points in R 2 divide it in 7 open regions (Fig. 7), which are essential for the following discussion.
We are now ready to state the following.  The lines spanned by a triple of non-aligned points p 1 , p 2 , p 3 divide R 2 in 7 regions. These can be split in three couples of dual regions and a self-dual region, here visually divided by colour and pattern. Each dual couple is formed by an external region and an internal one, as any point belonging to the former, resp. the latter, together with p 1 , p 2 , p 3 , forms an external, resp. internal, sign sequence. The self-dual region consists of one internal region (Color figure online) The idea behind this theorem is that if we want to nullify d 1,2,3 we need to align p 1 , p 2 , p 3 , without aligning any other triple in the process. For example if a point p k is inside the triangle spanned by these three points it is clear that aligning them would result in aligning all 4 of them.
As the sign sequence is invariant among all configurations of points in the same stratum σ , we have the following.
The following result tells us when instead it is possible to change sign, that is when the adjacency exists.
Theorem 2 Consider p ∈ Con f n (R 2 ) such that Theorem 1 is not satisfied. Suppose that for any pair 4 < i, j ≤ n it is true that either p i and p j belong to the same region and the tuple ( p 1 , p 3 , p i , p j ) has an even number of minuses or they are in a dual couple and the tuple ( p 1 , p 3 , p i , p j ) has an odd number of minuses. Then there exists a crossing map for p.
When Theorem 2 is satisfied we can construct explicitly a crossing map so that all points but p 2 are fixed and p 2 moves along the line p 4 p 2 . In terms of strata adjacency we have the following corollary.
Note that, when two signs sequences differ only by one sign, they need to be adjacent, which means that, if they are not, either one or both are not present as strata in Con f n (R 2 ). It is true that Theorem 2 is a necessary and sufficient condition for strata adjacency when n < 7, but this is not true for higher n. When n < 7 there is only one pair such that 4 < i < j ≤ n, that is, i = 5 and j = 6. This means that all points are involved: p 1 , p 2 and p 3 determine the dual regions of the plane and p 4 determines the crossing map for p 2 , permitted by the position of p 5 , p 6 . For the case n ≥ 7 the conditions in Theorem 2 involve subsets of p and not all of them. When it is not satisfied, there might exist other ways to move p 2 across the line p 1 p 3 , that is, a crossing map for p, for example moving more than one point.
The adjacency test between a stratum σ with positive sign d 1,2,3 and τ = H 1,2,3 (σ ), the one with identical determinant signs but d 1,2,3 , follows, where we denoted the duality relationship by and its negative by ∦. In the next section we Algorithm 1: Adjacent Input : Sign sequence σ Output : Boolean will describe how to effectively compute the sign sequences admissible in Con f n (R 2 ) when n ≤ 6 and how this structure can then be applied effectively to describe the "state" of the cloth.

Implementation and results
In this section we will demonstrate how Theorem 1 and Theorem 2 can be implemented in a finite algorithm that returns the stratification of Con f n (R 2 ). We will show that the number of existing strata increases significantly with the number of points, and to consider such approach, as it is, for a mesh of hundreds of points would be unfeasible, both for the construction of the stratification and its practical use. We propose here to group different strata in macro-states, called just states from now on, using both symmetric relationships and topological properties of the stratification. We will show that using this revised approach we can assign to a mesh on hundreds of points a discrete distribution over such states, allowing us to distinguish between different cloth poses. In Sect. 3 we showed that the combination of Theorem 1 and Theorem 2 can be used to determine the existence of a crossing map. Algorithm 1 assess the adjacency of a stratum σ with respect the singularity of d 1,2,3 . We know that the action of S n allows to swap any triple (i, j, k) with (1, 2, 3), so this means that existence of any adjacency with respect to a given d i, j,k can be determined after permuting some indices.
We present now two further algorithms: Algorithm 2 where we combine Algorithm 1 and the action of S n on Con f n (R 2 ) to determine all adjacencies of a stratum, and Algorithm 3 where, from a chosen stratum σ , we search existing adjacencies iteratively to obtain all existing strata in Con f n (R 2 ).

Algorithm 2: Reachable
Input : Sign sequence σ Output : Sign sequences adjacent to σ After applying Algorithm 2 to any σ we obtain a set of existing strata, to which we can reapply Algorithm 2. This iterative application of Algorithm 2 can be done a finite number of times, as the number of all possible sign sequences is finite. Thanks to the connectedness of Con f n (R 2 ), it is also true that we cannot miss any existing strata, if we iterate enough times. Algorithm 3 encodes such iterative process, assuming that the starting stratum is σ * , with all positive determinant signs, obtained placing n points as vertices of a convex n-gon and in counter-clockwise order. Thanks to Algorithm 3 we are able to recover the structure of Con f n (R 2 ) and, with it, also the number of strata, that is, sign sequences, present. As we can see in Table 1, the Algorithm 3: C-Space Input : σ * stratum of Con f n (R 2 ) Output : Configuration space Con f n (R 2 )  number of strata increases rapidly, and it is expected to rise quadratically in terms of n (Strommer 1977). As we are aiming to deal with meshes with hundreds of points, considering the strata as representating cloth poses, it might be computationally challenging as their number grows dramatically. To overcome such problem, we will show how to group different strata, and so configurations entailing similar robotic manipulations, in states. In Cohen et al. (1976) the action of S n on Con f n (R n ) is studied and, in particular, we obtain that the quotient of this action gives us the unordered configuration space of n points. In terms of our stratification, such action induces an identification between configurations, and so between strata, whose determinant signs coincide after a permutation of the point labels, {1, . . . , n}. An example of different configurations belonging to the same S n -state is displayed in Fig. 8.
Such action however does not always preserve faithfully the adjacency relationships, as it can happen that two strata in the same S n -equivalence class are adjacent. From our point of view, such possibility should be avoided, as a general rule. It implies that there exists a state containing a singularity loci, as two adjacent strata belong to it. We acknowledge the possibility that for a particular goal, the practitioner might allow it, if that singularity loci is not relevant for the particular task or goal sought. Each stratum is labelled with a binary vector of determinant signs and we can measure the distance between two strata with the Hamming distance. It measures how many different determinant signs they have, or equivalently the number of singularity loci to be crossed to continuously move from one stratum to the other. The following equivalence relation ensures that no pair of adjacent strata belongs to the same state.
Definition 2 (∼ σ -States) Given a stratum of Con f n (R 2 ), call it σ , we say that two strata τ 1 and τ 2 belongs to the same state if they are equally distant from σ w.r.t. the Hamming distance and they are in the same S n -state. We will denote such equivalence relation as τ 1 ∼ σ τ 2 .
It is easy to see that given two adjacent strata it is impossible for them to be inside the same state, as they will always have different sign distances from σ . It can be shown explicitly that, for different σ , the number of ∼ σ -states might change. To avoid confusion and be coherent in the choice of such σ we will assume from now on that σ = σ * , that is, the stratum with correspondent sign sequence formed by only positive signs. Table 2 shows the number of S n -states and ∼ σ -states for n < 7.
For any two states we can define a distance between them as the minimum Hamming distance between two strata in each state, which will always be greater than 0 if the states are different. We will say then that two states are adjacent if such distance is 1, as it implies that there exists at least two adjacent strata, one in each state.
As in each state we can have one or more strata, to avoid confusion, from now on we label each state using the sign sequence of one of them. As choice of label we consider the lowest sign sequence in the lexicographic order, assuming + < −. In Fig. 9 we can see the S 5 -states of Con f 5 (R 2 ), using the labelling just explained, where we connected together states that are adjacent.
As anticipated such states do not always preserve adjacencies. Consider the sign sequence τ = (+ + + + + Fig. 9 Adjacency graph of the S 5 -states using lexicographic order for the choice of labels Fig. 10 Adjacency graph of the σ * -states of Con f 5 (R 2 ) using lexicographic order for the choice of labels + + + − −), which is in Con f n (R 2 ). We know that τ cannot be in A = (+++++++++−−−) otherwise it would be its label and so it has to be in B = (+++++++++−). This means that in B we have two adjacent strata, as the label of a state corresponds to a stratum in it. For the ∼ σ -states this does not happen, thanks to their definition, even if they are a refinement of the S n -states, as to be ∼ σ -equivalent two strata need to be S n -equivalent. We show their adjacency graph in Fig. 10.
We know that the stratum with all negative signs always exists, as it is obtained displaying the points in clockwise order. Its distance from σ is exactly n 3 . This means that the number of ∼ σ -states for Con f n (R 2 ) is at least n 3 .
Again, even using states for representing C-space, instead of the stratification, their number for a mesh with hundreds of points becomes computationally challenging.
To avoid such challenge we propose to consider instead the distribution of states for the subsets of m points in the mesh, Fig. 11 For the same mesh of a rectangular cloth with ∼ 700 points on the top, we plot on the bottom the distribution of S n -states (on the left) and the ∼ σ -states (on the right) using different colours for the internal points based on their associated states (Color figure online) assuming the 4 corner points always in these subsets. As the case of m = 5 is the simplest and visual considerations can be made quite clearly, we will focus first on this case and only after show its generalisation. The cloth simulations presented here are obtained synthetically using a Blender simulator (Sánchez-Riera et al. 2010).
As we are considering subsets with m points (with 4 corner points always present) there exists a one-to-one matching between each subset and the (internal) point of the mesh. We can then associate the S n -state, or ∼ σ -state, of this subset to its unique internal point and vice versa. This allows us to show in a clear fashion how the distribution of states varies from different cloth meshes. In Fig. 11 we show how this distribution can change when using different states, S n -states and ∼ σ -states.
It is clear that we are dividing the mesh cloth in different "zones", each one associated to a different state, and so having more states could imply obtaining more zones for the same mesh. We refer the reader to "Appendix C" for more particular state definitions. They are presented with a discussion on the differences with the S n -states and ∼ σ -states, as well as on the possible uses for the practitioner. It is important to note that the definition of state we propose can be adapted to different needs from the user, as well as different goals. For example the coarsening of the states, that is, of the grouping of strata in Con f n (R 2 ), can be tuned and focus can be put or reduced on different states depending on their relative importance for the task at hand.
Given a mesh, we can map its state-zones to a vector in R k , with k the number of states considered, simply assigning to the i th -coordinate the number of internal points associated to the i th state. In other words, given a mesh of n points, we are assigning to it a vector that encapsulates the state distribution of its points. The reader should bear in mind that this procedure can be also viewed in terms of configurations of n points. We are effectively projecting a configuration in Con f n (R 2 ) to n − 4 copies of the state-decomposition of Con f 5 (R 2 ). Then, the state decomposition of Con f n (R 2 ) can be obtained by identifying strata with identical Con f 5 (R 2 )- Fig. 12 We consider the distribution of points in S 5 -states for different cloth meshes. The distribution of points in each S n -state, a vector in R 3 , is displayed for each mesh as a histogram. For brevity we indicate state (+ + + + + + + + +−) with A, state (+ + + + + + + − −−) with B and state (+ + + + + + + + ++) with C Fig. 13 A confusion matrix between different mesh poses using the heat function to represent low distance values (in red) and high ones (in blue). We can see that the similarity decreases for this particular example as the corner is moved across and out of the initial rectangle area (Color figure online) state distribution with respect to such projection. Examples of such identification follow in Fig. 12.
This state distribution can be considered as a vector in the Euclidean space R k , so one could also identify "close" enough state-distribution vectors with respect to the Euclidean distance. We show in Fig. 13 how this distance can be able to encode such similarities and differences.
If we want to generalise this approach for m > 5 we should bear in mind that the association with the internal points will be impossible, that is, a "zone" decomposition of the mesh cloth would be meaningless. We will be considering all n − 4 m − 4 subsets of m − 4 internal points, so we cannot associate uniquely a state to a point. However, given a mesh cloth of n points such that the 4 corner points are given and a state definition, we can again associate to it a vector in R k where k is the number of states in Con f m (R 2 ). This allows us to see any cloth mesh as a vector in an Euclidean space and measure distances between different meshes, and additionally it gives also a way to decompose Con f n (R 2 ) into regions on the basis of their associated vectors.

Conclusion
We have proposed an approach to represent the state of textiles in a global, coarse way useful for robot manipulation. It is well founded in topological grounds, as it relies on the configuration space (C-space) of distinctive points in the cloth, whose combinatorial structure is derived from the stratification of the flag manifold. Moreover, two theorems, Theorem 1 and Theorem 2, defining conditions for adjacency in C-space, have been proved. Their algorithmic implementation in Algorithm 3 permits to derive the decomposition of the C-space of a rectangular cloth with different granularities dependent on the particular goal sought. More concretely, we proved in Sect. 3 how to determine computationally the adjacency relations of the strata in Con f n (R 2 ) for n ≤ 6 and we are currently working on more general techniques for n > 6. Note that this doesn't limit the number of points used to determine the state of cloth, since all points in the cloth mesh can be used to this end (Fig. 11).
Such topological characterisation of cloth state represents a key element for the development of a theory of cloth manipulation based on computational topology and machine learning, that we are undertaking, as well as its implementation in the mobile manipulation robots servicing in our assisted living facility.
The cloth representation, as a distribution of states, will be used to link perception and planning. As shown in Sect. 4, using a state classification, the practitioner can obtain a subdivision of a rectangular cloth into state-induced "zones". This could make way for a robot visual recognition of different global states of the cloth, depending on the amount of points in each zone (Fig. 13). Future works would include applying deep learning to cloth state recognition from images, by generating training instances using a physical simulator and labelling them with our proposed state encoding. Since, for the training instances we have the meshes (ground truth) Fig. 14 Example of subpath of cloth meshes and distribution of S nstates, that would appear in a graph of states and transitions to plan the folding of a towel, using the taxonomy of Borràs et al. (2020) with which the images have been generated, we can exactly obtain the state-distribution vectors of the mesh poses with our algorithms.
On the manipulation planning side, characterising the states of textile objects and the feasible transformations under given actions in a compact operational way (i.e., a graph-encoding manipulation-oriented states and transitions), would permit probabilistic planning of actions that ensure reaching a desired cloth configuration despite lowaccuracy perceptions. In this direction, a framework to characterise and systematise grasps, manipulation primitives and tasks for the versatile handling of clothes by robots has been proposed (Borràs et al. 2020). Tasks are represented as sequences of manipulation primitives, which yield state changes. We envisage to map these changes to transitions in our state graph. A toy example of this approach is displayed in Fig. 14.
In this paper we have only considered static cloth states and envisaged their usage in manipulations where cloth dynamics can be neglected. Other authors have studied recently how to learn dynamics of deformable objects and fluids (Li et al. 2019) and in a reinforcement learning context Jangir et al. (2020) distinguishing between static and dynamic cloth manipulation tasks. These approaches, together with our state-subdivision in zones of the cloth, could determine efficiently the effect of a grasp by propagating the long-range influence among cloth particles, as in Mrowca et al. (2018), and consequently enabling us to determine the state-distribution after the grasp as well as to predict, under dynamical effects, the optimal path between two different state-distribution vectors in R k .
In sum, we believe that the proposed topological representation of cloth macro-state is a promising element towards effectively closing the perception-action loop in cloth manipulation.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecomm ons.org/licenses/by/4.0/.

A Adjacency study
In this appendix, we investigate further the adjacency relations of the stratification of Con f n (R 2 ). We proceed first introducing the concept of affine flag and the corresponding stratification of Flag A (3), subset of affine flags in Flag(3).
Thanks to this stratification and the symmetric action of S 4 on Con f 4 (R 2 ) we are able to provide a matching between the singularities of Flag A (3) and those of Con f 4 (R 2 ). This allows us to determine how the singularity, that is, alignment of three points, between two strata has to be crossed, in terms of the relative position of such points.
In Sect. 3 we show how the stratification of Con f 4 (R 2 ) can be obtained using the Flag (3)  into two connected components. To distinguish them in such cases, we annotate their label with a + or − sign depending on the placement of V and V * with respect with each other, see Fulton (1997);Hiller (1982). The resulting stratification is displayed in Fig. 15. For the singularities v − l * and l − v * , the difference between the two connected components is the following. If one consider the flag as V * = {p 1 , p 1 p 2 } then (v − l * ) + is formed by all those flags V = {v, l} such that v ∈ l * and the vectors p 2 − p 1 and v − p 1 are concord, otherwise we are in the singularity (v − l * ) − . Similarly happens for the two connected components of l − v * .
Any stratum in Con f 4 (R 2 ) can be associated to a stratum of Flag A (3), modulo the definition of V and V * with respect to p 1 , p 2 , p 3 and p 4 . For example, the stratum with label (+ + ++) is ∅ + when we consider V * = {p 1 , p 1 , p 2 } and V = {p 3 , p 3 , p 4 }. We will show next how we can associated to any singularity of Con f 4 (R 2 ) between adjacent strata a singularity of Flag A (3). Thanks to the action of S 4 on Con f 4 (R 2 ), such characterisation can be easily determined. A permutation g ∈ S 4 induces on Con f 4 (R 2 ) the map f g such that it sends any configuration p to one determined by { p g(i) } 4 i=1 , permuting accordingly the points. The map f g is an automorphism of Con f 4 (R 2 ) and when restricted to the singularity loci, it remains an automorphism, as the singularity of a determinant does not change under permutation. The reader should bear in mind that this does not imply that f g is an automorphism when restricted to each singularity alone. Without loss of generality we can focus only on the maps induced by the permutations (1, 2), (2, 3) and (3, 4), as they generate the entire S 4 . As explained before the singularities (v − l * ) ± and (l − v * ) ± can be expressed in terms of "concordant" or not alignment of three points. We can track the effect of permutation on such alignments and so we can detect how a permutation g will change any singularity of Flag A (3), again assuming V and V * are previously defined. In Fig. 16 we show how the alignment changes via permutations, denoting by i − j − k the alignment where p j Fig. 16 We show the effect of each basis element, e i = (i, i + 1), of S 4 on the alignments of any three points. Any possible alignment of three points is reached using a finite composition of the basis elements We consider the following flags and • V 1 = {v 2 , l 2 } with v 2 = p 2 and l 2 = p 2 p 1 ; • V * 2 = {v 2 , l 2 } with v * 2 = p 4 and l * 2 = p 4 p 3 .
Note that, given two adjacent strata σ and τ , with connecting singularity i − j − k, their images, under the action of any g ∈ S 4 , will still be adjacent and g(i) − g( j) − g(k) will correspond to the singularity between them. We can then rewrite Fig. 16 in terms of the singularity of Flag A (3).

Fig. 18
Representation of Con f 4 (R 2 ), with strata adjacencies in terms of singularities of Flag A (3), using the pair of flags V * 1 , V 1 and V * 2 , V 2 . We used cyan ellipses to denote external strata and red rectangles for internal ones (Color figure online) Using Fig. 17 and knowing that the connecting singularity of (++++) and (−+++) is 1−2−3, or also (v 1 −l * 1 ) + , we can determine the "type" of any singularity between two adjacent strata, that is, the corresponding singularity of Flag A (3), as follows (Fig. 18).
It is easy to check that each possible singularity, (v i −l * i ) ± and (l i − v * i ) ± , is present in the stratification of Con f 4 (R 2 ) showed in Fig. 15. In particular we have that any stratum has always at least one singularity in terms of V 1 , V * 1 and one V 2 , V * 2 , which should convince the reader that we need both pairs. We leave the study of singularities with lower dimension, that is, associated to v i − v * i and (l i − l * i ) ± , for the future.

B Proofs of Theorems 1 and 2
In this section we will prove Theorem 1 and Theorem 2 in details, using the notion of dual regions, as in Fig. 7, to test if there exists a crossing map between two strata, see Definition 1.
For any crossing map H , the configurations H (0) and H (1) belong to adjacent strata. We can assume then that the configuration H (0) = p, is such that p 1 = (0, 0), p 2 = (1, 0) and p 3 = (0, 1). This can be achieved via f : Note that f does not change the sign of any determinant. In addition we can assume that H 1 is constant over t, that is H 1 (t) ≡ (0, 0). If not, we apply to each H i : [0, 1] → R 2 the translation −H 1 : [0, 1] → R 2 . The map H − H 1 is also a crossing map, because for any t the configura- In addition, at any t the configuration q has q 1 = (0, 0).
Similarly we assume that p 2 belongs to the positive xsemiaxis. If not, we apply now a suitable rotation with centre the origin, such that for any t the point H 2 (t) is mapped to the positive x-semiaxis. Again we have a crossing map, as rotations are sign-preserving isometries, and clearly for any t the image of p 2 with respect to such map is on the positive x-semiaxis. One can alternatively assume that p 3 is on the positive, or negative, y-semiaxis instead. Furthermore we can assume that H 2 (t) ≡ (1, 0), via an homogeneous dilation at each t of R 2 with centre the origin and dilation factor y 2 > 0, which ensures that the sign sequence does not change. If we suppose that p 3 is constantly on the positive y-semiaxis, we can similarly assume H 3 (t) ≡ (0, 1).
In the following proof of Theorem 1, we make use of these assumptions, that w.l.o.g. extremely simplify the proof. For brevity, to denote the determinant of the image of points p i , p j and p k under H , we will write d i, j,k (t) when the context is clear Proof Suppose there exists p i ∈ p in the self-dual region (cf. Fig. 7) and H is a crossing map. As the sign sequence of H (0) is (+ + −+), H (1) has sign sequence (− + −+), which is impossible as it is not an admissible sequence of Con f 4 (R 2 ).
For i = 1, . . . , n let H i (t) = (x i (t), y i (t)) and suppose there exist two points p j , p k in two not dual regions. Thanks to our assumptions on H , we have d 1,2,3 (t) = y 3 (t), and, because H is a crossing map, we have that for some t 0 it is true that y 3 (0) > y 3 (t 0 ) = 0 > y 3 (1). Denoted by σ s (t), for s = j, k, the sign sequence of the points H 1 (t), H 2 (t), H 3 (t) and H s (t), we can analyse each possible case.
This is a contradiction.
This is a contradiction.
It is left to the reader to see that any other pair of different and not dual configurations can be reduced via a suitable symmetric action to the two considered above.
Given a couple of dual regions we can map it to another one using the permutation (2, 3, 1) or (3, 1, 2), which will also keep the determinant d 1,2,3 of the same sign. This means that we can reduce our considerations to only one of such couples, namely (+ + ++) and (+ − −−). We assume w.l.o.g. that the crossing map is such that H 1 (t) is the origin and H 3 (t) ≡ (0, 1) for any t. We are now ready to prove Theorem 2.
Proof The proof is divided into three parts. First we prove that any line passing through p i and p j with i, j > 4 does not cross the self-dual region. Then we prove that it does not happen also for the lines passing through p 1 , p i and p 3 , p i . As a consequence, we are able in the last part to construct explicitly a crossing map for p. Consider L : R → R 2 , parametric expression of p i p j , such that we have L(0) = p i and L(1) = p j .
with p i = (x i , y i ) and p j = (x j , y j ). We show first that the line p i p j never crosses the self-dual region. If a point q = (x, y) is in the self-dual region we have x, y > 0 and x + y < 1, as its state corresponds to the sign sequence (+ + −+). We will denote σ i, j the sign sequence of the state relative to ( p 1 , p 3 , p i , p j ). As we will make broad use of them, we write the explicit expressions of d 1,i, j and d 3,i, j , given w.l.o.g. that p 1 = (0, 0), p 2 = (1, 0) and p 3 = (0, 1).
As before we need to examine different cases depending on σ i , resp. σ j , the sign sequence of the points p 1 , p 2 , p 3 and p i , resp. p 1 , p 2 , p 3 and p j . That is, each case will correspond to a different pair of regions to which p i and p j belong.
Case 1. If both σ i and σ j are (+ − −−), then σ i, j is either (− − ++) or (− − −−). Note that the permutation (i, j) allows to pass from one case to the other, that is, we can assume both d 1,i, j and d 3,i, j positive. Suppose there exists L(t) from Eq. (2) inside the self-dual region, that is, x(t) > 0. We know that x i , x j < 0 from the expression of σ i and σ j , so by continuity there exists a t 0 such that x(t 0 ) = 0. In particular, this implies that x i − x j = 0, otherwise x(t) will be constant and always negative.
(a) If x i < x j , from Eq. (2) we have With we indicate that the value is increasing from left to right, otherwise we will use . As In conclusion, any line p i p j with i, j > 4 does not cross the self-dual region. Consider p 1 , p i with i > 4 and its parametric expression If σ i = (+ + ++) then x i < 0 < y i , so either x i t, y i t are both 0 or they are discordant, that is, the point L 1 (t) is never in the self-dual region. Similarly if σ i = (+ − −−). Consider p 3 , p i with i > 4 and its parametric expression If σ i = (++++) then x i < 0. Suppose that L 3 (t) belongs to the self-dual region, then t < 0 as x(t) > 0, but x i + y i < 1 so x(t) + y(t) > 1. That is, the point L 1 (t) is never in the self-dual region. Similarly if σ i = (+ − −−).
In conclusion we have that the only lines crossing the selfdual region will be p 2 p i for i = 1, . . . , n. In particular as any pair of them crosses at p 2 , then they cannot cross inside the self-dual region. If we move p 2 inside the self-dual region, along p 2 p 4 and so continuously, the sign sequence of p remains the same. That is, we are describing a continuous path of Con f n (R 2 ) that is contained inside the stratum σ of p. It is only when p 2 p 4 crosses p 1 p 3 that the sign sequence changes, that is, when the singularity loci is crossed at d 1,2,3 . Let L 2,4 = p 2 p 4 and λ such that L 2,4 (λ) ∈ p 1 p 3 . We can assume, modulo orientation of L 2,4 , that λ > 0 and L 2,4 (0) = p 2 , in particular this means that for any t > λ we have L 2,4 (t) with x-coordinate negative. Consider μ > λ such that for any t > λ such that L 2,4 (t) belongs to some p i p j , we have t > μ. For i = 2 consider the continuous map H i : [0, 1] → R 2 as the constant map H i (t) ≡ p i and H 2 as follows.
To check that H is a crossing map we need to check only H 2 . Clearly H 2 (0) = p 2 and H 2 is continuous. Consider 0 < t 0 = λ μ < 1, then H 2 (t 0 ) ∈ p 1 p 3 , and as H 2 is a linear map this can happen only once. It remains to prove that the sign sequence of H (1) differs only by the sign of d 1,2,3 with respect to σ . We have that H 2 (1) has negative x-coordinate, so d 1,2,3 changes sign as wanted. Furthermore, if any other determinant d 2,i, j changes sign, for (i, j) = (1, 3), then d 2,i, j (t) = 0 for t ∈ (t 0 , 1), as inside the self-dual region it cannot happen. That is, there exists λ < ν < μ such that L 2,4 (ν) belongs to p i , p j , which is impossible. All in all, H = {H i } n i=1 is a crossing map, as wanted.
Note that, thanks to these two theorems we are able to construct Algorithm 1, and, thanks to the proof of Theorem 2, we can explicitly construct the crossing map between two adjacent strata.

C Different states definitions
In Sect. 4 we proposed two different state definitions based on S 4 and on the topological structure of the stratification of Con f n (R 2 ). A practitioner however might want or need to study the state of a cloth with particular (or less) focus on a subset of points. For example, if q is a configuration of m points, subset of p ∈ Con f n (R 2 ), then one could group together strata of Con f n (R 2 ) depending on the strata of p and that of q, or instead that of p \ q. In this appendix we will show other two state definition based on the S n -states and ∼ σ -ones. Again we will assume that ∼ σ is defined using as "base-stratum" the sequence of all positive signs. Even if we show here only two cases, it is clear that depending on the cloth in analysis, the mesh properties but as well the manipulation task in mind, different states can be defined. For now on, we will assume that q are always the first m Fig. 19 Adjacency graph of Γ (m, n)-states, blue dashed lines denote a change for the state of q points in p, again for user-defined states such assumption might not be true. As explained previously, if we consider the S n -states, we are effectively forgetting the labelling given to each point. On the other hand, when using the ∼ σ -states we are able to track how far away we are from the "base-stratum" σ . If we are interested on the labels of the first m points and how their distance change, we would define the following.
Definition 3 (Γ (m, n)-States) Given two strata τ 1 , τ 2 of Con f n (R 2 ), for i = 1, 2 we denote by σ i the subsequence of the first m 3 signs, strata in Con f m (R 2 ). We say that τ 1 and τ 2 belong to the same S n -state if they are in the same S n -state and σ 1 is in the same ∼ σ -state of σ 2 . We will denote such equivalence relation as τ 1 ∼ (m,n) τ 2 .
The adjacency graph of such classes for n = 5 and m = 4 is displayed in Fig. 19, note that unlike the ∼ σ -states, self-loops can now occur as they are a refinement of the S n -states.
On the opposite case, if our intention is to study the state of the cloth, without giving importance to the labelling of q, then we can define the following states.
Definition 4 (Γ (n, m)-States) Given two strata τ 1 , τ 2 of Con f n (R 2 ), for i = 1, 2 we denote by σ i the subsequence of the first m 3 signs, strata in Con f m (R 2 ). We say that τ 1 and τ 2 belong to the same ∼ σ -state if they are in the same S n -state and σ 1 is in the same S m -state of σ 2 . We will denote such equivalence relation as τ 1 ∼ (n,m) τ 2 . The adjacency graph of such states for n = 5 and m = 4 is displayed in Fig. 19. As the graphs displayed in Figs. 19 and 20 are not isomorphic, we know that these two state definitions are different. Note that, as Γ (n, m)-states are a refinement of the ∼ σ -states, there cannot be self-loops in its adjacency graph. This does not always happen for the Γ (m, n)-states as they are a refinement of S n -states, which do have self-loops.
There are clearly a lot more possible state definitions than the ones we presented here. From our point of view, interesting ones can arise when considering instead of S n subgroups of it, for example the one generated by the cycle (1, 2 . . . , n). This would produce a refinement of S n -states which is not identical to the one of ∼ σ . Furthermore one could use such states as in Definition 4 or Definition 3 to group together configuration that are equal after cyclic permutation of m, or n, points.