Skip to content

Commit

Permalink
u180324
Browse files Browse the repository at this point in the history
  • Loading branch information
peterropac committed Mar 18, 2024
1 parent bcef0a3 commit 50af79e
Show file tree
Hide file tree
Showing 12 changed files with 2,113 additions and 990 deletions.
4 changes: 3 additions & 1 deletion Code/spomso/spomso/cores/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .modifications import ModifyObject, ModifyVectorObject
from .geom import GenericGeometry, Points
from .helper_functions import resolution_conversion, generate_grid
from .helper_functions import smarter_reshape, vector_smarter_reshape, n_vector_smarter_reshape
from .helper_functions import smarter_reshape, vector_smarter_reshape, nd_vector_smarter_reshape
from .post_processing import sigmoid_falloff, positive_sigmoid_falloff, capped_exponential
from .post_processing import linear_falloff, relu, smooth_relu, slowstart
from .post_processing import hard_binarization
Expand Down Expand Up @@ -47,6 +47,7 @@
from .vector_functions import vortex_vector_field_cylindrical, aav_vector_field_cylindrical
from .vector_functions import x_vector_field, y_vector_field, z_vector_field
from .vector_functions import from_sdf
from .geom_vector_special import lcwg1_p1, lcwg1_m1, lcwg1_2d
from .vector_functions_special import compute_crossings_2d

from .vector_modification_functions import batch_normalize
Expand All @@ -63,3 +64,4 @@
from .geom_vector import VortexCylindricalVectorField, AngledVortexCylindricalVectorField
from .geom_vector import XVectorField, YVectorField, ZVectorField
from .geom_vector import VectorFieldFromSDF
from .geom_vector_special import LCWG2D, LCWG3Dp1, LCWG3Dm1
102 changes: 60 additions & 42 deletions Code/spomso/spomso/cores/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,75 +32,90 @@ def smoothmax_boltz(x, y, width):


class CombineGeometry:
"""Class containing all the possible combination operations which can be applied to a scalar fields.
def __init__(self, operation_type: str):
"""
Constructs all the necessary attributes for the CombineGeometry object.
:param operation_type: Type of operation with which two or more geometric objects are combined.
Attributes:
operations: Dictionary containing all the possible non-parametric operations.
parametric_operations: Dictionary containing all the possible parametric operations.
Args:
operation_type: Type of operation with which two or more geometric objects are combined.
"""
self.operation_type = operation_type
self._combined_geometry = None
self.operations = {"UNION2": lambda obj1, obj2: np.minimum(obj1, obj2),
"UNION": lambda *objs: np.amin(objs, axis=0),
"SUBTRACT2": lambda obj1, obj2: np.maximum(obj1, -obj2),
"INTERSECT2": lambda obj1, obj2: np.maximum(obj1, obj2),
"INTERSECT": lambda *objs: np.amax(objs, axis=0),
}

self.parametric_operations = {"SMOOTH_UNION2_2": lambda obj1, obj2, width: smoothmin_poly2(obj1,
obj2,
width),
"SMOOTH_UNION2": lambda obj1, obj2, width: smoothmin_poly3(obj1,
obj2,
width),
"SMOOTH_INTERSECT2": lambda obj1, obj2, width: -smoothmin_poly3(-obj1,
-obj2,
width),
"SMOOTH_INTERSECT2_BOLTZMANN": lambda obj1, obj2, width: smoothmax_boltz(obj1,
obj2,
width),
"SMOOTH_SUBTRACT2": lambda obj1, obj2, width: -smoothmin_poly3(-obj1,
obj2,
width),
"SMOOTH_SUBTRACT2_BOLTZMANN": lambda obj1, obj2, width: smoothmax_boltz(obj1,
-obj2,
width)

def __init__(self, operation_type: str):
self.operation_type: str = operation_type
self._combined_geometry: Callable[[np.ndarray, tuple], np.ndarray] = None
self.operations: dict = {"UNION2": lambda obj1, obj2: np.minimum(obj1, obj2),
"UNION": lambda *objs: np.amin(objs, axis=0),
"SUBTRACT2": lambda obj1, obj2: np.maximum(obj1, -obj2),
"INTERSECT2": lambda obj1, obj2: np.maximum(obj1, obj2),
"INTERSECT": lambda *objs: np.amax(objs, axis=0),
}

self.parametric_operations: dict = {"SMOOTH_UNION2_2": lambda obj1, obj2, width: smoothmin_poly2(obj1,
obj2,
width),
"SMOOTH_UNION2": lambda obj1, obj2, width: smoothmin_poly3(obj1,
obj2,
width),
"SMOOTH_INTERSECT2": lambda obj1, obj2, width: -smoothmin_poly3(-obj1,
-obj2,
width),
"SMOOTH_INTERSECT2_BOLTZMANN": lambda obj1, obj2, width: smoothmax_boltz(obj1,
obj2,
width),
"SMOOTH_SUBTRACT2": lambda obj1, obj2, width: -smoothmin_poly3(-obj1,
obj2,
width),
"SMOOTH_SUBTRACT2_BOLTZMANN": lambda obj1, obj2, width: smoothmax_boltz(obj1,
-obj2,
width)
}

@property
def available_operations(self):
def available_operations(self) -> list:
"""
Available types of operations.
:return: List of available operations.
Returns:
List of available operations.
"""
operations_list = list(self.operations.keys())
print(f"Available non-parametric operations are: {operations_list}")
return operations_list

@property
def available_parametric_operations(self):
def available_parametric_operations(self) -> list:
"""
Available types of operations which require a parameter.
:return: List of available parametric operations.
Returns:
List of available parametric operations.
"""
operations_list = list(self.parametric_operations.keys())
print(f"Available parametric operations are: {operations_list}")
return operations_list

@property
def combined_geometry(self) -> Callable[[np.ndarray, tuple], tuple]:
def combined_geometry(self) -> Callable[[np.ndarray, tuple], np.ndarray]:
"""
Returns the SDF of the combined geometries,
which can be used to create a new geometry using GenericGeometry class.
:return: SDF of the combined geometries
Returns:
SDF of the combined geometries
"""
return self._combined_geometry

def combine(self, *combined_objects: object) -> GenericGeometry:
"""
Combines 2 or more geometric objects together.
:param combined_objects: Tuple containing geometric objects.
:return: New geometric object.
Args:
combined_objects: Tuple containing geometric objects.
Returns:
New geometric object.
"""
if self.operation_type not in self.operations.keys():
raise SyntaxError(f"{self.operation_type} is not an implemented non-parametric operation.",
Expand All @@ -120,9 +135,12 @@ def new_geo_object(co, *params):
def combine_parametric(self, *combined_objects: object, parameters: tuple | float | int) -> GenericGeometry:
"""
Combines 2 or more geometric objects together, based on the parameters of the operations.
:param combined_objects: Tuple containing geometric objects.
:param parameters: Parameters of the operation.
:return: New geometric object.
Args:
combined_objects: Tuple containing geometric objects.
parameters: Parameters of the operation.
Returns:
New geometric object.
"""
if self.operation_type not in self.parametric_operations.keys():
raise SyntaxError(f"{self.operation_type} is not an implemented parametric operation.",
Expand Down
Loading

0 comments on commit 50af79e

Please sign in to comment.