# meshFT
**meshFT** is a minimalistic PyTorch-based python library that provides a differentiable fourier transform that compute Fourier transform of triangle meshes in a given box. We support operations both on CPU and GPU. We provide **C++/CUDA** bindings to compute efficiently the forward and backward passes, to enable differentiable rasterization of triangulated data at scale.
<img src="mesh_ft.png" alt="drawing" style="background-color: transparent;" width="400"/>
Our main contribution, that allows meshFT to compute transforms in tractable times, relies on a tunable narrow-band filter in the frequency space that avoid computing high frequencies of the Fourier transform. (see API)
### Installation
`pip install meshft`
### Example
Load a mesh and compute its Fourier transform
```shell
pip install meshFT
```
```py
import trimesh, torch
import numpy as np
from meshft import compute_box_size, Fourier3dMesh
device = 'cpu'
#Create a sphere and convert Verts, Faces into torch tensors
Mesh = trimesh.primitives.Sphere(subdivisions = 1)
faces = np.array(Mesh.faces)
verts = np.array(Mesh.vertices)
Verts = torch.tensor(verts,dtype = torch.float,requires_grad=True)
Faces = torch.tensor(faces,dtype = torch.long)
#Give the dimensions of the box
box_size = np.array([[-1.2, 1.2],
[-1.2, 1.2],
[-1.2, 1.2]])
#Or compute it automatically with a given offset
#box_size = compute_box_size(verts,offset=0.2)
#Give the dimensions of the voxel grid
box_shape = np.array([50]*3)
#Compute the mesh Fourier transform
meshFT = Fourier3dMesh(box_size,box_shape,device=device, dtype = torch.float32)
ftmesh = meshFT(Verts,Faces)
#Compute the backward pass
loss = torch.sum(torch.abs(ftmesh))
loss.backward()
#Visualize the inverse FT:
#import napari
#a = torch.fft.ifftn(ftmesh)
#v = napari.view_image(np.abs(a.detach()).numpy())
```
---
### API and Documentation
- `Fourier3dMesh(self, box_size,box_shape,device = 'cpu', dtype = torch.float, gaussian_filter = False, sigma_base = 100.0, narrowband_thresh = 0.01)`:
- `box_shape: [x_res,y_res,z_res]` Size of the fourier box (in voxels)
- `box_size:[[x_min,xmax],[y_min,y_max],[z_min,z_max]]` Dimensions of the box (in the spatial dimensions of the mesh)
- `gaussian_filter` has to be set to `True` to activate the narrow-band filter
- `sigma_base` defines the inverse width of the gaussian filter. Lower it to conserve more frequencies
- `narrowband_thresh` threshold under which frequencies are not computed
---
### Credits, contact, citations
If you use this tool, please cite
Raw data
{
"_id": null,
"home_page": "https://github.com/sacha-ichbiah/meshFT",
"name": "MeshFT",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Sacha Ichbiah",
"author_email": "sacha.ichbiah@polytechnique.org",
"download_url": "https://files.pythonhosted.org/packages/66/a1/e0358d1d0c7c5239f843eeef3b5d8952e886dc3b0725618f6e993e76779c/MeshFT-1.1.0.tar.gz",
"platform": null,
"description": "# meshFT\n**meshFT** is a minimalistic PyTorch-based python library that provides a differentiable fourier transform that compute Fourier transform of triangle meshes in a given box. We support operations both on CPU and GPU. We provide **C++/CUDA** bindings to compute efficiently the forward and backward passes, to enable differentiable rasterization of triangulated data at scale. \n\n<img src=\"mesh_ft.png\" alt=\"drawing\" style=\"background-color: transparent;\" width=\"400\"/>\n\nOur main contribution, that allows meshFT to compute transforms in tractable times, relies on a tunable narrow-band filter in the frequency space that avoid computing high frequencies of the Fourier transform. (see API)\n\n\n### Installation\n\n`pip install meshft`\n\n\n### Example \n\nLoad a mesh and compute its Fourier transform\n\n```shell\npip install meshFT\n\n```\n\n```py\nimport trimesh, torch\nimport numpy as np\nfrom meshft import compute_box_size, Fourier3dMesh\n\ndevice = 'cpu'\n\n#Create a sphere and convert Verts, Faces into torch tensors\nMesh = trimesh.primitives.Sphere(subdivisions = 1)\nfaces = np.array(Mesh.faces)\nverts = np.array(Mesh.vertices)\nVerts = torch.tensor(verts,dtype = torch.float,requires_grad=True)\nFaces = torch.tensor(faces,dtype = torch.long)\n\n#Give the dimensions of the box\nbox_size = np.array([[-1.2, 1.2],\n [-1.2, 1.2],\n [-1.2, 1.2]])\n#Or compute it automatically with a given offset\n#box_size = compute_box_size(verts,offset=0.2)\n\n#Give the dimensions of the voxel grid\nbox_shape = np.array([50]*3)\n\n#Compute the mesh Fourier transform\nmeshFT = Fourier3dMesh(box_size,box_shape,device=device, dtype = torch.float32)\nftmesh = meshFT(Verts,Faces)\n\n#Compute the backward pass\nloss = torch.sum(torch.abs(ftmesh))\nloss.backward()\n\n#Visualize the inverse FT: \n#import napari\n#a = torch.fft.ifftn(ftmesh)\n#v = napari.view_image(np.abs(a.detach()).numpy())\n```\n\n---\n\n### API and Documentation\n\n\n- `Fourier3dMesh(self, box_size,box_shape,device = 'cpu', dtype = torch.float, gaussian_filter = False, sigma_base = 100.0, narrowband_thresh = 0.01)`: \n - `box_shape: [x_res,y_res,z_res]` Size of the fourier box (in voxels)\n - `box_size:[[x_min,xmax],[y_min,y_max],[z_min,z_max]]` Dimensions of the box (in the spatial dimensions of the mesh)\n - `gaussian_filter` has to be set to `True` to activate the narrow-band filter\n - `sigma_base` defines the inverse width of the gaussian filter. Lower it to conserve more frequencies\n - `narrowband_thresh` threshold under which frequencies are not computed\n---\n\n### Credits, contact, citations\nIf you use this tool, please cite \n\n\n\n\n\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "MeshFT implementation",
"version": "1.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "66a1e0358d1d0c7c5239f843eeef3b5d8952e886dc3b0725618f6e993e76779c",
"md5": "f9f0c5149e6872198abe76d283636522",
"sha256": "607952680164d85e995f2cf04f78e5c939f938cd616080c9a3cfef48f361c268"
},
"downloads": -1,
"filename": "MeshFT-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "f9f0c5149e6872198abe76d283636522",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5448,
"upload_time": "2023-03-19T16:34:30",
"upload_time_iso_8601": "2023-03-19T16:34:30.571376Z",
"url": "https://files.pythonhosted.org/packages/66/a1/e0358d1d0c7c5239f843eeef3b5d8952e886dc3b0725618f6e993e76779c/MeshFT-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-19 16:34:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "sacha-ichbiah",
"github_project": "meshFT",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "meshft"
}