{"id":13706681,"url":"https://github.com/peekxc/simplextree","last_synced_at":"2025-10-17T00:13:37.179Z","repository":{"id":39884806,"uuid":"176528351","full_name":"peekxc/simplextree","owner":"peekxc","description":"R package for simplifying general computation on simplicial complexes","archived":false,"fork":false,"pushed_at":"2023-10-17T17:12:09.000Z","size":3517,"stargazers_count":16,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T16:05:50.878Z","etag":null,"topics":["r","rcpp","simplicial-complex","topological-data-analysis","topology"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peekxc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-03-19T14:21:27.000Z","updated_at":"2025-03-29T23:48:54.000Z","dependencies_parsed_at":"2024-01-14T20:30:55.284Z","dependency_job_id":null,"html_url":"https://github.com/peekxc/simplextree","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peekxc%2Fsimplextree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peekxc%2Fsimplextree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peekxc%2Fsimplextree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peekxc%2Fsimplextree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peekxc","download_url":"https://codeload.github.com/peekxc/simplextree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251700557,"owners_count":21629838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","rcpp","simplicial-complex","topological-data-analysis","topology"],"created_at":"2024-08-02T22:01:04.902Z","updated_at":"2025-10-17T00:13:32.148Z","avatar_url":"https://github.com/peekxc.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# simplextree\n[![Codecov test coverage](https://img.shields.io/codecov/c/github/peekxc/simplextree)](https://codecov.io/gh/peekxc/simplextree?branch=master)\n[![CRAN badge](https://www.r-pkg.org/badges/version/simplextree)](https://cran.r-project.org/web/packages/simplextree/)\n\n`simplextree` is an [R](https://www.r-project.org/) package aimed at simplifying computation for general [simplicial complexes](https://en.wikipedia.org/wiki/Simplicial_complex) of any dimension. This package facilitates this aim by providing R bindings to a _Simplex Tree_ data structure, implemented using _modern_ [C++11](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf) and exported as a [Rcpp module](https://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-modules.pdf). The underlying library implementation also exports a [C++ header](inst/include/simplextree.h), which can be specified as a dependency and [used in other packages](#usage-with-rcpp) via [Rcpp attributes](http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf).\n\nThe Simplex Tree was originally introduced in the following paper: \n\n\u003e Boissonnat, Jean-Daniel, and Clément Maria. \"The simplex tree: An efficient data structure for general simplicial complexes.\" Algorithmica 70.3 (2014): 406-427.\n\nA _Simplex Tree_ is an ordered, [trie](https://en.wikipedia.org/wiki/Trie)-like structure whose nodes are in bijection with the faces of the complex. Here's a picture (taken from the paper) of a simplicial 3-complex (left) and its corresponding _Simplex Tree_ (right):\n\n![simplex tree picture](./man/figures/simplextree.png)\n\n## Installation \n\nThe most recent release is available on [CRAN](https://cran.r-project.org/web/packages/simplextree/) and can be installed via the usual method\n\n```R\ninstall.packages(\"simplextree\")\n```\n\nAlternatively, the current development version can be installed with the [devtools](https://github.com/r-lib/devtools) package: \n\n```R\nrequire(\"devtools\")\ndevtools::install_github(\"peekxc/simplextree\")\n```\n\n## Quickstart\n\n```R\nlibrary(simplextree)\nst \u003c- simplex_tree()              ## creates a simplex tree\nst %\u003e% insert(list(1:3, 4:5, 6))  ## Inserts simplices { 1, 2, 3 }, { 4, 5 }, and { 6 }\n\n## Summary of complex\nprint(st) \n# Simplex Tree with (6, 4, 1) (0, 1, 2)-simplices\n\n## More detailed look at structure\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0): \n# 4 (h = 1): .( 5 )\n# 5 (h = 0): \n# 6 (h = 0): \n\n## Print the set of simplices making up the star of the simplex '2'\nprint_simplices(st %\u003e% cofaces(2))\n# 2, 2 3, 2 3 4, 2 3 4 5, 2 3 5, 2 4, 2 4 5, 2 5, 1 2, 1 2 3\n\n## You can also compactly print traversals of the complex  \ndfs \u003c- preorder(st)\nprint_simplices(dfs, \"column\")\n# 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 4 4 5 6\n#   2 2 3 3 3 3 3 4 4 5 6   3 3 3 3 4 4 5   4 4 5 6   5    \n#     3   4 4 5 6   5         4 4 5   5       5            \n#           5                   5\n\n## Or save them as a list \ndfs_list \u003c- as.list(dfs)\n# list(1, c(1,2), ...)\n\n## Get connected components \nprint(st$connected_components)\n# [1] 1 1 1 4 4 5\n\n## Serialization/persistent storage options available\nsaveRDS(st %\u003e% serialize(), file = tempfile())\n\n## As are various export options\nlist_of_simplices \u003c- st$as_list()\nadj_matrix \u003c- st$as_adjacency_matrix()\n# ... see also as_adjacency_list(), as_edge_list\n```\n\n## API Reference \n\nBelow is the API reference for the R-bindings of the _SimplexTree_ class. A _SimplexTree_ object can also be passed, manipulated, and modified via C++ in another R package as well. See [Usage with Rcpp](#usage-with-rcpp). \n\nIn what follows, individual _simplex_'s are assumed to be [integer](https://stat.ethz.ch/R-manual/R-devel/library/base/html/integer.html) vectors. [Numeric](https://stat.ethz.ch/R-manual/R-devel/library/base/html/numeric.html) vectors are implicitly cast to integer vectors. Some methods accept multiple _simplices_ as well, which can be specified as a list of integer vectors. \n\n### SimplexTree\n\n\u003ca href='#simplex_tree' id='simplex_tree' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n__simplex\\_tree__()\n\nWrapper for constructing a _SimplexTree_ instance. See below. \n\n\u003ca href='#SimplexTree' id='SimplexTree' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n__SimplexTree__ (_C++ Class_)\n\nExposed binding for an internal _SimplexTree_ C++ class. The binding is exposed as an [Rcpp Module](http://dirk.eddelbuettel.com/code/rcpp/Rcpp-modules.pdf). Module instances are of the class type _Rcpp\\_SimplexTree_. \n\n_SimplexTree_ instances can be created with either `simplex_tree()` or `new(SimplexTree)`.\n\n#### Fields \n\nFields are data attributes associated with the _SimplexTree_ instance containing useful information about the simplex tree. Writeable fields can be set by the user to change the behaviour of certain methods, whereas read-only fields are automatically updated as the tree is modified.\n\n\u003ca href='#n_simplices' id='n_simplices' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **n\\_simplices** \n\nAn integer vector, where each index *k* denotes the number of (*k-1*)-simplices. _( Read-only )_\n\n\u003ca href='#dimension' id='dimension' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **dimension**\n\nThe dimension of a simplicial complex *K* is the highest dimension of any of *K*'s simplices.  _( Read-only )_\n\n\u003ca href='#id_policy' id='id_policy' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **id_policy**\n\nThe _id\\_policy_  of the _SimplexTree_ instance determines how new vertex ids are generated by the [generate_ids](#generate_ids) method. Can be either \"compressed\" or \"unique\". Defaults to \"compressed\".  \n\n#### Properties \n\nProperties are aliases to methods that act as data fields, but on access dynamically generate and return their values, much like [active bindings](https://stat.ethz.ch/R-manual/R-devel/library/base/html/bindenv.html) in R. Unlike _fields_, properties do not store their results with the instance, and do not contribute to the memory footprint of the simplicial complex.\n\n\u003ca href='#connected_components' id='connected_components' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **connected_components**\n\nReturns the connected components of the simplicial complex. \n\nEach connected component is associated with an integer; the result of this function is an integer vector mapping the (ordered) set vertices to their corresponding connected component.  \n\n\u003ca href='#vertices' id='vertices' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **vertices**\n\nReturns the 0-simplices in the simplicial complex as an _n_-length vector, where _n_ is the number of 0-simplices.\n\n\u003ca href='#edges' id='edges' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **edges**\n\nReturns the 1-simplices in the simplicial complex as an _( n x 2 )_ matrix, where _n_ is the number of 1-simplices.\n\n\u003ca href='#triangles' id='triangles' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **triangles**\n\nReturns the 2-simplices in the simplicial complex as an _( n x 3 )_ matrix, where _n_ is the number of 2-simplices.\n\n\u003ca href='#quads' id='quads' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **quads**\n\nReturns the 3-simplices in the simplicial complex as an _( n x 4 )_ matrix, where _n_ is the number of 3-simplices.\n\n\n#### Modifying the tree \n\n\u003ca href='#insert' id='insert' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **insert**(_SimplexTree_, \\[*simplices*\\])\n\nInserts *simplices* into the simplex tree. Each _simplex_ is ordered prior to insertion. If a _simplex_ already exists, the tree is not modified. To keep the property of being a simplex tree, the proper faces of _simplex_ are also inserted. \n\n\u003cdetails\u003e\n\u003csummary\u003e Insertion examples \u003c/summary\u003e\n​\t\n\n```R\nst \u003c- simplex_tree()\nst %\u003e% insert(c(1, 2, 3))       ## insert the simplex { 1, 2, 3 }\nst %\u003e% insert(list(c(4, 5), 6)) ## insert the simplices { 4, 5 } and { 6 }\nprint(st)\n# Simplex Tree with (6, 4, 1) (0, 1, 2)-simplices\n```\n\n\u003c/details\u003e\n\n\u003ca href='#remove' id='remove' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **remove**(_SimplexTree_, \\[*simplices*\\])\n\nRemoves *simplices* from the simplex tree. Each _simplex_ is ordered prior to removal. If a _simplex_ doesn't exist, the tree is not modified. To keep the property of being a simplex tree, the cofaces of _simplex_ are also removed. \n\n\u003cdetails\u003e\n\u003csummary\u003e Removal examples \u003c/summary\u003e\n​\t\n\n```R\nst \u003c- simplex_tree()\nst %\u003e% insert(list(c(1, 2, 3), c(4, 5), 6))\nst %\u003e% remove(c(2, 3)) ## { 2, 3 } and { 1, 2, 3 } both removed\nprint(st)\n# Simplex Tree with (6, 3) (0, 1)-simplices\n```\n\u003c/details\u003e\n\n\u003ca href='#contract' id='contract' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **contract**(_SimplexTree_, \\[*a, b*\\])\n\nPerforms and *edge contraction*, contracting vertex *b* to vertex *a*. This is equivalent to removing vertex *b* from the simplex tree and augmenting the link of vertex *a* with the link of vertex *b*. If the edge does not exist in the tree, the tree is not modified.\n\n\u003cdetails\u003e\n\n\u003csummary\u003e Contraction example \u003c/summary\u003e\n\t\n```R\nst \u003c- simplex_tree()\nst %\u003e% insert(1:3)\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0): \nst %\u003e% contract(c(1, 3))\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 1): .( 2 )\n# 2 (h = 0): \n```\n\u003c/details\u003e\n\n\u003ca href='#collapse' id='collapse' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **collapse**(_SimplexTree_, ...)\n\n1. (\\[_tau_\\], \\[_sigma_\\])\n2. ((_u_, _v_), _w_)\n\nPerforms an _elementary collapse_. There are multiple simplifying operations that have been referred to as elementary collapses; this method provides two such operations.\n\n(1) elementary collapse ( from [1](#simplex-tree-paper) ) \n\nCollapses _tau_ through its coface _sigma_ if _sigma_ is the only coface of _tau_, where _tau_ and _sigma_ are both _simplexes_. \n\n(2) vertex collapse ( from [2](#simplicial-map-paper) )\n\nCollapses a free pair (_u_, _v_) -\u003e (_w_), where _u_, _v_, and _w_ are all _vertices_. \n\nNote that an _elementary_ collapse in this sense has an injectivity requirement that either _u_ = _w_, such that (_u_, _v_) -\u003e (_u_), or _v_ = _w_, such that (_u_, _v_) -\u003e (_v_). If (_u_, _v_) -\u003e (_w_) is specified, where _u_ != _w_ and _v_ != _w_ , the collapse is decomposed into two elementary collapses, (_u_, _w_) -\u003e (_w_) and (_v_, _w_) -\u003e (_w_), and both are performed. \n\n\u003cdetails\u003e\n\n\u003csummary\u003e Collapse example \u003c/summary\u003e\n\t\n```R\nst \u003c- simplex_tree()\nst %\u003e% insert(1:3)\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0): \nst %\u003e% collapse(list(1:2, 1:3)) ## collapse in the sense of (1)\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 1): .( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0):\n  \nst %\u003e% insert(list(1:3, 2:5))\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 3): .( 3 4 5 )..( 4 5 5 )...( 5 )\n# 3 (h = 2): .( 4 5 )..( 5 )\n# 4 (h = 1): .( 5 )\n# 5 (h = 0): \nst %\u003e% collapse(list(3, 4), 5) ## collapse in the sense of (2)\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 5 )..( 5 )\n# 2 (h = 2): .( 5 )..( 5 )\n# 5 (h = 1): .( 5 )\n```\n\n\u003c/details\u003e\n\n\u003ca href='#expand' id='expand' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **expand**(_SimplexTree_, _k_)\n\nPerforms a _k-expansion_, constructing the _k_-skeleton as a flag complex. The expansion is performed by successively inserting all the simplices of _k_-skeleton into the tree. \n\n\u003cdetails\u003e\n\n\u003csummary\u003e Expansion example \u003c/summary\u003e\n\n```R\nst \u003c- simplex_tree()\nst %\u003e% insert(list(c(1, 2), c(2, 3), c(1, 3)))\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 1): .( 2 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0):\n  \nst %\u003e% expand(k=2) ## expand to simplicial 2-complex\nst %\u003e% print_simplices(\"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 0): \n```\n\n\u003c/details\u003e\n\n\u003ca href='#as_XPtr' id='as_XPtr' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n_SimplexTree_ $ **as_XPtr**()\n\nConverts the simplex tree into an [XPtr](https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/XPtr.h), sometimes called an _external pointer_. _XPtr_'s can be passed as an [SEXP](https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPs) to other C/C++ functions via R's C API or Rcpp. For usage, see [Usage with Rcpp](#usage-with-rcpp).\n\nThis method does _not_ register a delete finalizer. \n\n#### Querying the tree \n\n\u003ca href='#print_tree' id='print_tree' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e **print_simplices**(_SimplexTree_, format = \"short\")\n\nPrints a formatted summary of the simplicial complex to R's buffered output. By default, this shows up on the R console. Available outputs include \"summary\", \"tree\", \"cousins\", \"short\", \"column\", or \"row\". See the internal R documentation for more details. \n\n\u003ca href='#find' id='find' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**find**(_SimplexTree_, \\[*simplices*\\])\n\nTraverses the simplex tree downard starting at the root by successively using each of the ordered labels in _simplex_ as keys. Returns a logical indicating whether _simplex_ was found, for each _simplex_ in _simplices_. Each _simplex_ is sorted prior to traversing. \n\n\u003ca href='#degree' id='degree' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**degree**(_SimplexTree_, \\[*vertices*\\])\n\nReturns the degree of a given vertex or set of vertices.\n\n\u003ca href='#adjacent' id='adjacent' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**adjacent**(_SimplexTree_, _vertex_)\n\nReturns the set of vertices adjacent to a given _vertex_. \n\n\u003ca href='#is_face' id='is_face' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**is_face**(_SimplexTree_, _[tau]_, _[sigma]_)\n\nReturns a logical indicating whether _tau_ is a face of _sigma_. \n\n\u003ca href='#is_tree' id='is_tree' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**is_tree**(_SimplexTree_)\n\nReturns a logical indicating whether the simplex tree is fully connected and acyclic. \n\n\u003ca href='#generate_ids' id='generate_ids' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**generate_ids**(_SimplexTree_, _n_)\n\nGenerates _n_ new vertex ids which do not exist in the tree according to the current [id_policy](#id_policy). \n\n#### Traversals\n\nThe _SimplexTree_ data structure supports various types of _traversals_. A _traversal_ is a (possibly optimized) path that allows iteration through a subset of the _SimplexTree_. Once a traversal is parameterized, they can be saved as variables and used as arguments into the free function `traverse`, `straverse`, and `ltraverse`. They can also be converted explicitly to list form via the `as.list` S3 specialization. \n\n\u003ca href='#traverse' id='traverse' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**traverse**(_traversal_, _f_)\n\nExecutes a given _traversal_, passing each simplex in the traversal as the only argument to _f_. Output returned by _f_, if any, is discarded. This function does not return a value.\n\n\u003ca href='#straverse' id='straverse' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**ltraverse**(_traversal_, _f_)\n\nExecutes a given _traversal_, passing each simplex in the traversal as the only argument to _f_, returning a list of the same length as the traversal path whose elements contain the result of _f_.  **ltraverse** is meant to used in a similar way as [lapply](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/lapply).\n\n\u003ca href='#ltraverse' id='ltraverse' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**straverse**(_traversal_, _f_)\n\nExecutes a given _traversal_, passing each simplex in the traversal as the only argument to _f_, returning a vector of the same length as the traversal path whose elements contain the result of _f_.  **straverse** is meant to used in a similar way as [sapply](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/lapply).\n\nThe currently supported _traversals_ are the following: \n\n\u003ca href='#preorder' id='preorder' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e \n**preorder**(_SimplexTree_, _simplex_)\n\nPerforms a preorder traversal of the _SimplexTree_ starting at _simplex_. If _simplex_ is not supplied, the traversal starts at the first vertex in the complex.\n\n\u003ca href='#level_order' id='level_order' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**level_order**(_SimplexTree_, _simplex_)\n\nPerforms a level order traversal of the _SimplexTree_ starting at _simplex_. If _simplex_ is not supplied, the traversal starts at the first vertex in the complex.\n\n\u003ca href='#faces' id='faces' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**faces**(_SimplexTree_, _simplex_)\n\nPerforms a traversal over the faces of _simplex_ in the _SimplexTree_. Supplying _simplex_ is required. \n\n\u003ca href='#cofaces' id='cofaces' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**cofaces**(_SimplexTree_, _simplex_)\n\nTraverse all of the cofaces (the star) of _simplex_ in the _SimplexTree_. Supplying _simplex_ is required. \n\n\u003ca href='#cofaces' id='cofaces' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**coface_roots**(_SimplexTree_, _simplex_)\n\nTraverse all of the _roots_ whose subtrees comprise the cofaces of _simplex_ in the _SimplexTree_. Supplying _simplex_ is required. \n\n\u003ca href='#link' id='link' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e \n**link**(_SimplexTree_, _simplex_)\n\nTraverse all of the simplices of the link of _simplex_ in the _SimplexTree_. Supplying _simplex_ is required. \n\n\u003ca href='#skeleton' id='skeleton' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e \n**k_skeleton**(_SimplexTree_, _k_, _simplex_)\n\nTraverses all of simplices of dimension _k_ or less in the _SimplexTree_. If _simplex_ is not supplied, the traversal starts at the first vertex in the complex.\n\n\u003ca href='#k_simplices' id='k-simplices' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**k_simplices**(_SimplexTree_, _k_, _simplex_)\n\nTraverses all of simplices of dimension _k_ in the _SimplexTree_. If _simplex_ is not supplied, the traversal starts at the first vertex in the complex.\n\n\u003ca href='#maximal' id='maximal' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n**maximal**(_SimplexTree_)\n\nPerforms a traversal over the _maximal faces_ in the _SimplexTree_. A simplex is considered maximal in this case if it has itself as its only coface.\n\n#### Import / Export options \n\n\u003ca href='#serialize' id='serialize' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e \n**serialize**(_SimplexTree_)\n\nSerializes the simplex tree _K_ into some of smaller representation needed to recover the simplex tree.\n\n\u003ca href='#deserialize' id='deserialize' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **deserialize**(_complex_, _SimplexTree_)\n\nDeserializes _complex_, the result of [serialize](#serialize), into the given _SimplexTree_ if supplied, or an empty _SimplexTree_ otherwise. \n\n#### Conversions\n\nThe full simplicial complex can always be converted to a list of matrices, and the 1-skeleton can also be converted to any of the standard graph representations. \n\n\u003ca href='#as_list' id='as_list' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n_SimplexTree_ $ **as\\_list**()\n\nConverts the simplex tree to list of _(n x k)_ matrices, where each matrix represents the set of _k-1_ simplices.\n\n\u003ca href='#as_edge_list' id='as_edge_list' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n_SimplexTree_ $ **as\\_edge_list**()\n\nConverts the 1-skeleton to an edge list. \n\n\u003ca href='#as_adjacency_list' id='as_adjacency_list' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e\n_SimplexTree_ $ **as\\_adjacency_list**()\n\nConverts the 1-skeleton to an adjacency list. \n\n\u003ca href='#as_adjacency_matrix' id='as_adjacency_matrix' class='anchor' aria-hidden='true'\u003e#\u003c/a\u003e _SimplexTree_ $ **as\\_adjacency_matrix**()\n\nConverts the 1-skeleton to an adjacency matrix. \n\n## Usage with Rcpp\n\nThere are two ways to use a _SimplexTree_ object with Rcpp. \n\n#### 1. Pure Rcpp\n\nIf you're developing purely in Rcpp, you can just use the _SimplexTree_ class directly. The _SimplexTree_ is header-only, and can be imported via the **Rcpp::depends** attribute (see [Rcpp Attributes](http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf))\n\n\u003cdetails\u003e \n\u003csummary\u003eExample Usage in Rcpp\u003c/summary\u003e\n\n```C\n#include \"Rcpp.h\"\n\n// [[Rcpp::depends(simplextree)]]\n#include \"simplextree.h\"\n\nvoid my_function(){\n  SimplexTree st = SimplexTree();\n  ...\n}\n\n```\nIf you're developing using a package, make sure to add `simplextree` to the `LinkingTo` list to ensure the header is properly included (e.g. `-I\"\u003c...\u003e/simplextree/include\"` should appear in the build steps).\n\n\u003c/details\u003e\n\n#### 2. Moving between R and Rcpp\n\nA _SimplexTree_ Rcpp module can be passed directly from R to any Rcpp method. To do so, export the object as an external pointer (XPtr) in R, pass the [SEXP](https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPs) directly to the method, then wrap as as [smart external pointer](http://dirk.eddelbuettel.com/code/rcpp/html/classRcpp_1_1XPtr.html) on the C++ side. \n\n\u003cdetails\u003e \n\u003csummary\u003eExample Usage with R and Rcpp\u003c/summary\u003e\n\nFor example, on the C++ side, one might do:\n\n```C\n// my_source.cpp\n#include \"Rcpp.h\"\n\n// [[Rcpp::depends(simplextree)]]\n#include \"simplextree.h\"\n\n[[Rcpp::export]]\nvoid modify_tree(SEXP stree){\n  Rcpp::XPtr\u003cSimplexTree\u003e stree_ptr(stree);\n  stree_ptr-\u003eprint_tree();\n  ....\n}\n```\nThen on the R-side, use [as\\_XPtr](#as\\_XPtr) method to get an [XPtr](https://cran.r-project.org/doc/manuals/R-exts.html#External-pointers-and-weak-references). \n\n```R\n# my_source.R\nst \u003c- simplex_tree()\nmodify_tree(st$as_XPtr())\n```\nNote that the C++ class contains a superset of the functionality exported to R, however they do not necessarily have the same bindings. See the header file for a complete list. \n\n\u003c/details\u003e \n\n## Visualizing the complex\n\nSummarizing the complex can be achieved via either the overridden [S3](https://stat.ethz.ch/R-manual/R-devel/library/methods/html/Methods_for_S3.html) print generic or the more detailed [print_tree](#print_tree) method.\n\n```R\nlibrary(simplextree)\nst \u003c- simplex_tree()\nst %\u003e% insert(list(1:3, 3:6))\n\nprint(st)\n# Simplex Tree with (6, 9, 5, 1) (0, 1, 2, 3)-simplices\n\nprint_simplices(st, \"tree\")\n# 1 (h = 2): .( 2 3 )..( 3 )\n# 2 (h = 1): .( 3 )\n# 3 (h = 3): .( 4 5 6 )..( 5 6 6 )...( 6 )\n# 4 (h = 2): .( 5 6 )..( 6 )\n# 5 (h = 1): .( 6 )\n# 6 (h = 0): \n```\n\nAlternatively, the plot generic is also overridden for _SimplexTree_ objects (of class type 'Rcpp_SimplexTree') to display the complex with [base graphics](https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/graphics-package.html).\n\n```R\nst %\u003e% insert(list(6:7, 7:8, 8:10, 11:12))\nplot(st)\n```\n\n![simplex tree vis picture](./man/figures/st_vis.png)\n\nThere are many other options for controlling how the complex is displayed (e.g. the positions of the simplices, the sizes/linewidths of the vertices/edges, the vertex labels, whether to color only maximal faces or individual simplices, etc.). For the full documentation, see `?plot.simplextree`.\n\n\n## More information \n\nThe full documentation for both the plot package is available in the man pages.\n\n```R\n## see ?simplextree\n```\n\n## References \n\n\u003e \u003ca name=\"simplex-tree-paper\"\u003e1.\u003c/a\u003e Boissonnat, Jean-Daniel, and Clément Maria. \"The simplex tree: An efficient data structure for general simplicial complexes.\" Algorithmica 70.3 (2014): 406-427. \n\n\u003e \u003ca name=\"simplicial-map-paper\"\u003e2.\u003c/a\u003e Dey, Tamal K., Fengtao Fan, and Yusu Wang. \"Computing topological persistence for simplicial maps.\" Proceedings of the thirtieth annual symposium on Computational geometry. ACM, 2014.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeekxc%2Fsimplextree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeekxc%2Fsimplextree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeekxc%2Fsimplextree/lists"}