Beispiel #1
0
def set_compliant_interactor(compliance=1e-3):

    import ctypes
    plugin_name = 'compliant_qtquickgui'

    try:
        dll_path = Sofa.loadPlugin(plugin_name)

        dll = ctypes.CDLL(dll_path)

        dll.set_compliant_interactor.argtypes = [ctypes.c_double]
        dll.set_compliant_interactor.restype = None

        print('setting compliant interactor, compliance:', compliance)
        dll.set_compliant_interactor(compliance)

    except EnvironmentError as e:
        print('setting compliant interactor failed:', e)
Beispiel #2
0
import os

import Sofa
Sofa.loadPlugin("Compliant")
from _Compliant import *


def path():
    current_dir = os.path.dirname(__file__)
    return os.path.abspath(os.path.join(current_dir, '..', '..'))
Beispiel #3
0
from __future__ import print_function, absolute_import
import Sofa

from ctypes import *
from ctypes.util import find_library

import numpy as np
import scipy as sp
from scipy import sparse

from SofaPython import SofaNumpy as sofa_numpy

from collections import namedtuple
from contextlib import contextmanager

dll_path = Sofa.loadPlugin('Compliant')
dll = CDLL(dll_path)


def set_opaque(obj, name, value):
    '''set an opaque data to ctypes value'''
    value_type = type(value)

    data = obj.findData(name)
    ptr, shape, typename = data.getValueVoidPtr()

    class Opaque(Structure):
        _fields_ = (('data', value_type), )

    dst = Opaque.from_address(ptr)
    dst.data = value
Beispiel #4
0
from __future__ import print_function
from SofaPython import sparse

import numpy as np

import Sofa
Sofa.loadPlugin('Flexible')


def createScene(node):

    template = 'Affine'
    dofs = node.createObject('MechanicalObject',
                             template=template,
                             name="dof",
                             showObject="true",
                             showObjectScale="0.7",
                             size=1)
    dofs.init()

    mass = node.createObject('AffineMass', template=template)
    mass.init()
    mass.bwdInit()

    ref = np.identity(12)

    with sparse.data_view(mass, 'massMatrix') as m:
        assert (m == ref).all()

        m[10, 10] = 14
        ref[10, 10] = 14
Beispiel #5
0
import Sofa

from Compliant import StructuralAPI as api
from SofaPython import script


class Script(script.Controller):
    def onEndAnimationStep(self, dt):
        print(self.dofs.force)


Sofa.loadPlugin('Compliant')


def createScene(node):

    ode = node.createObject('CompliantImplicitSolver')
    ode.debug = True

    num = node.createObject('SequentialSolver', iterations=5, precision=0)
    num.debug = True

    # a point mass
    point = node.createChild('point')

    dofs = point.createObject('MechanicalObject',
                              template='Vec3',
                              showObject=True,
                              drawMode=1)
    point.createObject('UniformMass', template='Vec3', totalMass=1)
Beispiel #6
0
import Sofa

import numpy as np
import scipy as sp
from scipy import sparse
from contextlib import contextmanager

from ctypes import *

dll_path = Sofa.loadPlugin('Compliant')
dll = CDLL(dll_path)

# note: we don't alias eigen matrices directly as the memory layout could change
# between versions (it did once in the past IIRC), so we use a low-level
# exchange data structure instead


class Matrix(Structure):
    '''all the data needed to alias a sparse matrix in eigen/scipy'''

    _fields_ = (('rows', c_size_t), ('cols', c_size_t), ('outer_index',
                                                         POINTER(c_int)),
                ('inner_nonzero', POINTER(c_int)), ('values',
                                                    POINTER(c_double)),
                ('indices', POINTER(c_int)), ('size', c_size_t))

    @staticmethod
    def from_scipy(s):
        data = Matrix()
        values, inner_indices, outer_index = s.data, s.indices, s.indptr
Beispiel #7
0
import Sofa

import numpy as np
import scipy as sp
from scipy import sparse
from contextlib import contextmanager

from ctypes import *

dll_path = Sofa.loadPlugin('SofaPython')
dll = CDLL(dll_path)


def matrix(dtype):
    '''matrix type constructor from scalar type (c_double or c_float)'''

    from_eigen_table = {
        c_double: dll.eigen_to_scipy_double,
        c_float: dll.eigen_to_scipy_float,
    }

    to_eigen_table = {
        c_double: dll.eigen_from_scipy_double,
        c_float: dll.eigen_from_scipy_float,
    }

    # note: we don't alias eigen matrices directly as the memory layout could change
    # between versions (it did once in the past IIRC), so we use a low-level
    # exchange data structure instead
    class Matrix(Structure):
        '''all the data needed to alias a sparse matrix in eigen/scipy (see ctypes.cpp)'''
Beispiel #8
0
from __future__ import print_function
from SofaPython import sparse

import numpy as np

import Sofa
Sofa.loadPlugin('Flexible')

def createScene(node):

    template = 'Affine'
    dofs = node.createObject('MechanicalObject', template = template, name="dof", 
                             showObject="true", showObjectScale="0.7", size = 1)
    dofs.init()
    
    mass = node.createObject('AffineMass', template = template)
    mass.init()
    mass.bwdInit()

    ref = np.identity(12)
    
    with sparse.data_view(mass, 'massMatrix') as m:
        assert (m == ref).all()

        m[10, 10] = 14
        ref[10, 10] = 14

        # assert our in-place modifications are reflected
        with sparse.data_view(mass, 'massMatrix') as mm:
            assert (mm == ref).all()
Beispiel #9
0
import Sofa

import numpy as np
import scipy as sp
from scipy import sparse
from contextlib import contextmanager

from ctypes import *

dll_path = Sofa.loadPlugin('SofaPython')
dll = CDLL(dll_path)



def matrix(dtype):
    '''matrix type constructor from scalar type (c_double or c_float)'''
    
    from_eigen_table = {
        c_double: dll.eigen_to_scipy_double,
        c_float: dll.eigen_to_scipy_float,        
    }


    to_eigen_table = {
        c_double: dll.eigen_from_scipy_double,
        c_float: dll.eigen_from_scipy_float,        
    }
    

    # note: we don't alias eigen matrices directly as the memory layout could change
    # between versions (it did once in the past IIRC), so we use a low-level
Beispiel #10
0
import os
import Sofa

Sofa.loadPlugin("SofaImplicitField")

from __SofaImplicitField import *
import __SofaImplicitField