Example #1
0
def as_numpy(data, read_only=-1):
    """ maps data content as a numpy array
    :param data: the Data
    :param readOnly: (boolean) if true you should not modify the numpy array content
                     if false (read/write),  ***you have to call endEdit*** to unlock the Data and set it as dirty
    :return: numpy array
    """

    if not isinstance(read_only, bool):  # backward compatibility
        Sofa.msg_deprecated(
            "SofaNumpy",
            "as_numpy: Data must be explicitly accessed as read-only or read-write. "
            "With a read-only access, the numpy array should not be modified. "
            "With a read-write access, the Data must be explicitly unlocked and set as dirty with a call to 'Data.endEditVoidPtr'"
        )
        read_only = True  # similar to the first behavior

    if read_only:
        ptr, shape, typename = data.getValueVoidPtr()
    else:
        ptr, shape, typename = data.beginEditVoidPtr()

    nparray = wrap_as_numpy_array(ptr, shape, typename)

    if read_only: nparray.flags['WRITEABLE'] = False

    return nparray
Example #2
0
def numpy_data(obj, name):
    ## @deprecated
    Sofa.msg_deprecated(
        "SofaNumpy",
        "numpy_data: Data must be explicitly accessed as read-only or read-write. "
        " Use 'read_only()' or 'edit_data' context instead")
    data = obj.findData(name)
    return as_numpy(data, -1)
Example #3
0
def __rename_kwargs__(func_name, kwargs, aliases):
    for alias, new in aliases.items():
        if alias in kwargs:
            if new in kwargs:
                raise TypeError(
                    "'{}' received both '{}' and '{}' while '{}' is deprecated"
                    .format(func_name, alias, new, alias))
            Sofa.msg_deprecated(
                "{}' is a deprecated parameter name which has been replaced with {}."
                .format(alias, new))
            kwargs[new] = kwargs.pop(alias)
Example #4
0
def vec_as_numpy((ptr, size, typename)):
    '''maps vec as a numpy array'''
    Sofa.msg_deprecated("SofaNumpy",
                        "vec_as_numpy: use wrap_as_numpy_array instead")

    type = ctypeFromName.get(typename, None)
    if not type: raise Exception("can't map data of type " + typename)

    array_type = type * size
    array = array_type.from_address(ptr)
    return numpy.ctypeslib.as_array(array)
Example #5
0
 def getVisual(self,solidId,meshId):
     """ returns a visual object identified by solidId/meshId
     """
     Sofa.msg_deprecated("SofaPython.sml.BaseScene","getVisual is deprecated, access directly self.visuals[solidId][meshId]")
     mesh=None
     if hasattr(self, 'rigids'):  # inserted by Compliant.sml FIXME: parent class should not know child class !
         if solidId in self.rigids:
             if meshId in self.rigids[solidId].visuals:
                 mesh = self.rigids[solidId].visuals[meshId]
     if hasattr(self, 'visuals'):  # inserted by Anatomy.sml FIXME: parent class should not know child class !
         if solidId in self.visuals:
             if meshId in self.visuals[solidId]:
                 mesh = self.visuals[solidId][meshId]
     return mesh
Example #6
0
def deprecated(cls):

    # TODO maybe we should print a backtrace to locate the origin?
    # or even better, use: https://docs.python.org/2/library/warnings.html#warnings.warn
    line = '''class `{0}` from module `{1}` is deprecated. You may now derive from `Sofa.PythonScriptController` and instantiate derived classes directly.'''.format(cls.__name__, cls.__module__)
    
    Sofa.msg_deprecated('SofaPython', line)
    
    Sofa.msg_deprecated('SofaPython', 
                        'note: `createGraph` will no longer be called automatically. You need to call manually from __init__ instead.')
    
    Sofa.msg_deprecated('SofaPython',
                        'note: `onLoaded` will no longer be called automatically. You need to call manually from __init__ instead.')
    
    return cls
Example #7
0
# basic euclidean space operations on float lists.
# 
# author: [email protected]


import math
import Sofa

import __builtin__ as base

Sofa.msg_deprecated("Compliant.Vec","Compliant's Vec.py is now deprecated (and will be deleted soon), please use numpy instead" )

def dot(x, y):
    return base.sum( [xi * yi for xi, yi in zip(x, y) ] )

def norm2(x):
    return base.sum( [ xi * xi for xi in x] )

def norm(x):
    return math.sqrt( norm2(x) )

def zero(n):
    return [0.0] * n

def scal( scalar, x ):
    return [ scalar * xi for xi in x ]

def minus(x):
    return scal(-1, x)

def inv(x):
Example #8
0
# basic euclidean space operations on float lists.
#
# author: [email protected]

import math
import Sofa

import __builtin__ as base

Sofa.msg_deprecated(
    "Compliant.Vec",
    "Compliant's Vec.py is now deprecated (and will be deleted soon), please use numpy instead"
)


def dot(x, y):
    return base.sum([xi * yi for xi, yi in zip(x, y)])


def norm2(x):
    return base.sum([xi * xi for xi in x])


def norm(x):
    return math.sqrt(norm2(x))


def zero(n):
    return [0.0] * n

Example #9
0
# Rigid bodies and joints, Compliant-style.
#
# Authors: [email protected], ... ?
#
# The basic philosophy is that python provides nice data structures to
# define scene component *semantically*. Once this is done, the actual
# scene graph must be generated through the 'insert' methods. Please
# refer to the python examples in Compliant for more information.
#

import Sofa

Sofa.msg_deprecated(
    "Compliant.Rigid",
    "Compliant's Rigid.py is now deprecated (and will be deleted soon), please use StructuralAPI instead"
)

from subprocess import Popen, PIPE

from numpy import *
import SofaPython.Quaternion as quat
import Vec as vec

import Tools
from Tools import cat as concat

import os

import Frame

Example #10
0
# Rigid bodies and joints, Compliant-style.
# 
# Authors: [email protected], ... ?
#
# The basic philosophy is that python provides nice data structures to
# define scene component *semantically*. Once this is done, the actual
# scene graph must be generated through the 'insert' methods. Please
# refer to the python examples in Compliant for more information.
#


import Sofa


Sofa.msg_deprecated("Compliant.Rigid","Compliant's Rigid.py is now deprecated (and will be deleted soon), please use StructuralAPI instead" )

from subprocess import Popen, PIPE

from numpy import *
import SofaPython.Quaternion as quat
import Vec as vec

import Tools
from Tools import cat as concat

import os

import Frame

class MassInfo:
        pass