Skip to content

Commit f6f5946

Browse files
committed
Fix visual example
1 parent 33fbc73 commit f6f5946

File tree

12 files changed

+48
-41
lines changed

12 files changed

+48
-41
lines changed

examples/stlib/PrefabScene_beginner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ def createScene(root):
2222
rigidParams.geometry = CubeParameters([0, 0, 0], 1, 3)
2323
root.add(Rigid,rigidParams)
2424

25-
2625
deformableParams = Deformable.getParameters()
2726
#Add transformation somewhere here
2827
deformableParams.geometry = FileParameters("SofaScene/Logo.vtk")
2928
root.add(Deformable,deformableParams)
3029

31-
3230
return root

examples/stlib/PrefabScene_intermediate.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33

44

55
def createScene(root):
6-
Entity.Deformable(Mesh,MechaProperties)
76

8-
return root
97

10-
11-
if __name__=="__main__":
12-
root = exportScene()
13-
createScene(root)
14-
pass
8+
return root

stlib/core/baseParameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from splib.core.utils import DEFAULT_VALUE
33

44
import dataclasses
5-
from types import Callable, Optional
5+
from typing import Callable, Optional, Any
66

77
@dataclasses.dataclass
88
class BaseParameters(object):

stlib/core/basePrefab.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
2-
import Sofa.Core
2+
import Sofa
3+
import Sofa.Core
34
from stlib.core.basePrefabParameters import BasePrefabParameters
45

56

@@ -21,18 +22,18 @@ def findName(cname, node):
2122
if params.name in self.children:
2223
params.name = findName(params.name, self)
2324

24-
return typeName(parent = self, parameters=params)
25+
return self.addChild(typeName(params))
2526

2627
Sofa.Core.Node.add = addFromTypeName
2728

2829

29-
class BasePrefab(Sofa.Core.Prefab):
30+
class BasePrefab(Sofa.Core.Node):
3031
"""
3132
A Prefab is a Sofa.Node that assembles a set of components and nodes
3233
"""
3334

34-
def __init__(self, params: BaseParameters):
35-
Sofa.Core.Prefab.__init__(self, name=params.name)
35+
def __init__(self, params: BasePrefabParameters):
36+
Sofa.Core.Node.__init__(self, name=params.name)
3637

3738
def localToGlobalCoordinates(pointCloudInput, pointCloudOutput):
3839
raise NotImplemented("Send an email to Damien, he will help you. Guaranteed :)")

stlib/core/basePrefabParameters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class BasePrefabParameters(object):
77

88
# Transformation information
99
# TODO: these data are going to be added in Node in SOFA (C++ implementation)
10-
translation : list[float] = [0., 0., 0.]
11-
rotation : list[float] = [0., 0., 0.]
12-
scale : list[float] = [1., 1., 1.]
10+
translation : list[float] = dataclasses.field(default_factory = lambda : [0., 0., 0.])
11+
rotation : list[float] = dataclasses.field(default_factory = lambda : [0., 0., 0.])
12+
scale : list[float] = dataclasses.field(default_factory = lambda : [1., 1., 1.])
1313

1414
def toDict(self):
1515
return dataclasses.asdict(self)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from __deformable__ import *
2-
from __parameters__ import *
1+
from .__deformable__ import *
2+
from .__parameters__ import *

stlib/entities/rigid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from __rigid__ import *
1+
from .__rigid__ import *

stlib/geometry/__geometry__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Geometry(BasePrefab):...
1111

1212
@dataclasses.dataclass
1313
class InternalDataProvider(object):
14-
positions : Any
14+
position : Any = None
1515
# Topology information
1616
edges : Any = DEFAULT_VALUE
1717
triangles : Any = DEFAULT_VALUE
@@ -27,10 +27,12 @@ def generateAttribute(self, parent : Geometry):
2727
class GeometryParameters(BaseParameters):
2828

2929
# Type of the highest degree element
30-
elementType : Optional[ElementType]
30+
elementType : Optional[ElementType] = None
31+
data : Optional[InternalDataProvider] = None
3132

3233
dynamicTopology : bool = False
33-
data : Optional[InternalDataProvider]
34+
35+
3436

3537

3638

@@ -47,8 +49,8 @@ def __init__(self, params: GeometryParameters):
4749
params.data.generateAttribute(self)
4850
if(params.dynamicTopology):
4951
if(params.elementType is not None):
50-
addDynamicTopology(self, container = {dataclasses.asdict(params.data)})
52+
addDynamicTopology(self, container = dataclasses.asdict(params.data))
5153
else:
5254
raise ValueError
5355
else:
54-
addStaticTopology(self, container = {dataclasses.asdict(params.data)})
56+
addStaticTopology(self, container = dataclasses.asdict(params.data))

stlib/geometry/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from __geometry__ import *
1+
from .__geometry__ import *

stlib/geometry/extract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def generateAttribute(self, parent : Geometry):
3131
elif self.fromElemType == ElementType.HEXA:
3232
tmn.addObject("Hexa2QuadTopologicalMapping", input=fromLink, output=tmn.container.linkpath)
3333

34-
self.positions = tmn.container.position.linkpath
34+
self.position = tmn.container.position.linkpath
3535
self.edges = tmn.container.edges.linkpath
3636
self.triangles = tmn.container.triangles.linkpath
3737
self.quads = tmn.container.quads.linkpath
38-
self.hexaedra = tmn.container.hexaedra.linkpath
38+
self.hexahedra = tmn.container.hexahedra.linkpath
3939
self.tetrahedra = tmn.container.tetras.linkpath
4040

4141

0 commit comments

Comments
 (0)