-
Notifications
You must be signed in to change notification settings - Fork 54
[Prefabs] dataclasses to pydantic BaseModel #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EulalieCoevoet
wants to merge
53
commits into
sofa-framework:25_04_work_on_new_prefabs
Choose a base branch
from
EulalieCoevoet:pr_basemodelpydantic
base: 25_04_work_on_new_prefabs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
d6d0794
add folder for STLIB
bakpaul 8df6143
Add reusable methods
bakpaul 778d912
Add working files
bakpaul 31ee7a7
Created example scenes
bakpaul 59bb89b
Fix example
bakpaul 21c0af2
orga folders
hugtalbot ec2b2c3
Fix package
bakpaul 73849a3
bootstrap examples
bakpaul 86e9a0d
start beginner scene
hugtalbot f8050b3
Move around files
bakpaul e597d65
Move examples into SofaPython3 main example folder
bakpaul ee70863
Add unsaved modifications
bakpaul a30190f
reoganisation after discussion
EulalieCoevoet 63b2f72
Add gemetries
bakpaul 690d6c9
WIP FileParameters
bakpaul 71232f4
Add beginner example
bakpaul cdea524
Add unsaved changes
bakpaul 6896284
Start work on visual and collision
bakpaul 4b3df06
work on Tuesday : visual, geometry
hugtalbot 763b4ac
add basePrefabParameters.py
hugtalbot 4352fc2
Add extracted geometry
bakpaul ade7fa7
Fix visual example
bakpaul 1516840
Finished collisions
bakpaul 37aee53
[stlib-splib] work on prefabs: cleaning (#501)
EulalieCoevoet 3b98ae4
[stlib] adds README
EulalieCoevoet 2a55a36
[stlib] minor changes from discussion
EulalieCoevoet d40d019
[splib] updates entity
EulalieCoevoet 666d8e8
update README
hugtalbot 1c32b92
add init in prefab
hugtalbot 879b59d
Add first implem of entity
bakpaul 7b62fb2
before the train 3/3
hugtalbot c64a3f6
very last commit befor train
EulalieCoevoet 5d23215
WIP
bakpaul 4ce1fba
Retore original. Still crash due to wrong string conversion
bakpaul ab456df
[stlib] Deformable Entity (#502)
EulalieCoevoet aaa8c1d
Fix linkpath by introducing init method + make addDeformableMaterial …
bakpaul 2465a82
[STLIB] Add the unified "add" in Sofa.Core.Node (#503)
damienmarchal d066293
Add new tests for prefabs
bakpaul 80be8cb
Revert modification of __genericAdd
bakpaul ae77763
update addMass using elementType
hugtalbot 266a6ce
[Prefabs] Reorder files to match concepts (#547)
bakpaul 12baea2
[Prefabs] cleaning to fix deformable example (#549)
EulalieCoevoet d850a24
Fix by passing state link when using other topology than edges (#550)
bakpaul 8509991
Fix constraint solvr name
bakpaul 92fc7fb
Register in the PythonFactory Rigid3::Coord (#544)
damienmarchal ec84018
Squashed commit of the following:
bakpaul 8b239c6
revert some changes
EulalieCoevoet aee9423
dataclasses to pydantic BaseModel
EulalieCoevoet b2eff82
Merge branch 'master' into pr_basemodelpydantic
EulalieCoevoet 9ee6042
list of changes:
EulalieCoevoet 559753a
adds docs and prefab class
EulalieCoevoet 63966a5
moves cube, sphere, bunny to entity directory, refactor FileInternalD…
EulalieCoevoet 7e288d4
Merge branch '25_04_work_on_new_prefabs' into pr_basemodelpydantic
EulalieCoevoet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated but fine by me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import Sofa.Core | ||
| from baseParameters import BaseParameters | ||
| import Sofa | ||
| from stlib.core.baseParameters import BaseParameters | ||
|
|
||
| class BaseEntity(Sofa.Core.Prefab): | ||
| class BaseEntity(Sofa.Prefab): | ||
|
|
||
| parameters : BaseParameters | ||
|
|
||
| def __init__(self): | ||
| Sofa.Core.Prefab.__init__(self) | ||
| Sofa.Prefab.__init__(self) | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,34 @@ | ||
| import dataclasses | ||
| from splib.core.utils import DEFAULT_VALUE | ||
|
|
||
| import dataclasses | ||
| from pydantic import BaseModel, ValidationError | ||
| from dynapydantic import SubclassTrackingModel | ||
| from typing import Callable, Optional, Any | ||
| import Sofa | ||
|
|
||
| class BaseParameters(SubclassTrackingModel, | ||
| discriminator_field="type", | ||
| discriminator_value_generator=lambda t: t.__name__,): | ||
|
|
||
| @dataclasses.dataclass | ||
| class BaseParameters(object): | ||
| name : str = "Object" | ||
| kwargs : dict = dataclasses.field(default_factory=dict) | ||
| kwargs : dict = {} | ||
|
|
||
| @classmethod | ||
| def fromYaml(self, data: str): | ||
| import yaml | ||
| dataDict = yaml.safe_load(data) | ||
| return self.fromDict(dataDict) | ||
|
|
||
| @classmethod | ||
| def fromDict(self, data: dict): | ||
| try: | ||
| return self.model_validate(data, strict=True) | ||
| except ValidationError as exc: | ||
| for error in exc.errors(): | ||
| loc = error.get("loc") | ||
| message = "" | ||
| for locPart in loc: | ||
| message += locPart.__str__() + ": " | ||
| message += error.get("msg") | ||
| Sofa.msg_error(self.__name__, message) | ||
|
|
||
|
|
||
| def toDict(self): | ||
| return dataclasses.asdict(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,29 @@ | ||
| import copy | ||
| import Sofa | ||
| import Sofa.Core | ||
| from stlib.core.basePrefabParameters import BasePrefabParameters | ||
|
|
||
| from stlib.core.baseParameters import BaseParameters | ||
|
|
||
|
|
||
| class BasePrefabParameters(BaseParameters): | ||
| name : str = "object" | ||
| kwargs : dict = {} | ||
|
|
||
| # Transformation information | ||
| # TODO: these data are going to be added in Node in SOFA (C++ implementation) | ||
| translation : list[float] = [0., 0., 0.] | ||
| rotation : list[float] = [0., 0., 0.] | ||
| scale : list[float] = [1., 1., 1.] | ||
|
|
||
|
|
||
| class BasePrefab(Sofa.Core.Node): | ||
| """ | ||
| A Prefab is a Sofa.Node that assembles a set of components and nodes | ||
| """ | ||
|
|
||
| parameters : BasePrefabParameters | ||
|
|
||
| def __init__(self, parameters: BasePrefabParameters): | ||
| Sofa.Core.Node.__init__(self, name=parameters.name) | ||
| self.parameters = parameters | ||
|
|
||
| def init(self): | ||
| raise NotImplemented("To be overridden by child class") | ||
| raise NotImplemented("This method should be implemented in the child class to initialize the prefab's components and nodes based on the provided parameters.") | ||
|
|
||
|
|
||
| def localToGlobalCoordinates(pointCloudInput, pointCloudOutput): | ||
| raise NotImplemented("Send an email to Damien, he will help you. Guaranteed :)") | ||
|
|
||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from stlib.entities import Entity, EntityParameters | ||
| from stlib.visual import VisualParameters | ||
| from stlib.geometries.file import FileParameters | ||
| from stlib.materials.deformable import DeformableMaterialParameters | ||
| from splib.core.enum_types import ElementType | ||
|
|
||
| from typing import Optional | ||
|
|
||
|
|
||
| class BunnyParameters(EntityParameters): | ||
| name : str = "Bunny" | ||
| deformable : bool = False | ||
| visual : Optional[VisualParameters] = VisualParameters(geometry = FileParameters(filename="mesh/Bunny.stl")) | ||
|
|
||
| def model_post_init(self, _): | ||
| # TODO: | ||
| # 1. apply size as scale in geometry, material, collision and visual | ||
| if self.deformable: | ||
| self.geometry = FileParameters(filename="mesh/Bunny.vtk", elementType=ElementType.TETRAHEDRA) | ||
| self.material = DeformableMaterialParameters() | ||
| return | ||
|
|
||
|
|
||
| class Bunny(Entity): | ||
|
|
||
| def __init__(self, parameters: BunnyParameters): | ||
| super().__init__(parameters) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot that we wanted to have this. At one point we'll need to merge this with the node modifier part.