Skip to content

Commit

Permalink
Remove QuadMap and belonging classes from MappedSketch
Browse files Browse the repository at this point in the history
Their logic will be implemented into Grid and optimizers/smoothers
  • Loading branch information
FranzBangar committed Jul 9, 2024
1 parent 417e765 commit 8a08ecd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
30 changes: 11 additions & 19 deletions src/classy_blocks/construct/flat/sketches/mapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,31 @@
import numpy as np

from classy_blocks.construct.flat.face import Face
from classy_blocks.construct.flat.map import QuadMap
from classy_blocks.construct.flat.sketch import Sketch
from classy_blocks.optimize.grid import QuadGrid
from classy_blocks.types import IndexType, NPPointType, PointListType
from classy_blocks.util.constants import DTYPE


class MappedSketch(Sketch):
"""A sketch that is created from predefined points.
The points are connected to form quads which define Faces."""

def __init__(self, positions: PointListType, quads: List[IndexType]):
self.quad_map = QuadMap(np.array(positions, dtype=DTYPE), quads)
self.quad_grid = QuadGrid(np.array(positions, dtype=DTYPE), quads)
self._faces: List[Face] = []

self._faces = [Face(cell.points) for cell in self.quad_grid.cells]
for quad in quads:
face = Face([positions[iq] for iq in quad])
self._faces.append(face)

self.add_edges()

def add_edges(self) -> None:
"""An optional method that will add edges to wherever they need to be."""
"""An optional method that will add edges to faces;
use `sketch.faces` property to access them."""

@property
def faces(self):
"""A 'flattened' grid of faces"""
# Update from latest grid
# for i, face in enumerate(self._faces):
# face.update(self.quad_grid.cells[i].points)

# return self._faces

# update from quad map
return [quad.face for quad in self.quad_map.quads]
return self._faces

@property
def grid(self):
Expand All @@ -47,7 +39,7 @@ def center(self) -> NPPointType:
"""Center of this sketch"""
return np.average([face.center for face in self.faces], axis=0)

def smooth(self, n_iter: int = 5) -> None:
"""Smooth the internal points using laplacian smoothing"""
for _ in range(n_iter):
self.quad_map.smooth_laplacian()
# def smooth(self, n_iter: int = 5) -> None:
# """Smooth the internal points using laplacian smoothing"""
# for _ in range(n_iter):
# self.quad_map.smooth_laplacian()
22 changes: 4 additions & 18 deletions tests/test_construct/test_flat/test_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,22 @@ def positions(self):
@property
def quads(self):
return [
(0, 1, 4, 3),
(1, 2, 5, 4),
(3, 4, 7, 6),
(4, 5, 8, 7),
[0, 1, 4, 3],
[1, 2, 5, 4],
[3, 4, 7, 6],
[4, 5, 8, 7],
]

@property
def sketch(self):
return MappedSketch(self.positions, self.quads)

def test_smooth(self):
# a grid of vertices 3x3

sketch = MappedSketch(self.positions, self.quads)
sketch.smooth(10)

np.testing.assert_almost_equal(sketch.faces[0].point_array[2], [1, 1, 0])

def test_faces(self):
self.assertEqual(len(self.sketch.faces), 4)

def test_grid(self):
self.assertEqual(len(self.sketch.grid), 1)

def test_center(self):
sketch = MappedSketch(self.positions, self.quads)
sketch.smooth(10)

np.testing.assert_almost_equal(sketch.center, [1, 1, 0])


class GridSketchTests(unittest.TestCase):
def test_construct(self):
Expand Down

0 comments on commit 8a08ecd

Please sign in to comment.