Example #1
0
    def __init__(self, libName, VISSYMDEF):
        """Constructor.
        
        libName is the name of the library that implements the sloargs interface.
        The name can either be just the base lib name or an absolute file name.
        VISSYMDEF is a ctype Structure object that describes the VISSYMDEF
        struct for this particular renderer.
        """

        self._VISSYMDEF = VISSYMDEF

        libName = rmanlibutil.resolveRManLib(libName)
        self.libName = libName

        # Load the library...
        try:
            self._sloargs = self._loadLibrary(libName)
        except:
            raise ValueError('Failed to load library "%s": %s' %
                             (libName, sys.exc_info()[1]))
        try:
            self._declareFunctions(self._sloargs)
        except:
            raise ValueError(
                'Library "%s" does not implement the sloargs interface: %s' %
                (libName, sys.exc_info()[1]))
Example #2
0
    def _loadPtcLib(self, libName):
        """Load a RenderMan library providing the point cloud API.
        """
        resolvedLibName = rmanlibutil.resolveRManLib(libName)
        ptclib = ctypes.cdll.LoadLibrary(resolvedLibName)
        
        ptclib.PtcPointCloud = ctypes.c_void_p

        # Writing point cloud files
        ptclib.PtcCreatePointCloudFile.argtypes = [ctypes.c_char_p,
                                                   ctypes.c_int,
                                                   ctypes.POINTER(ctypes.c_char_p),
                                                   ctypes.POINTER(ctypes.c_char_p),
                                                   ctypes.POINTER(ctypes.c_float),
                                                   ctypes.POINTER(ctypes.c_float),
                                                   ctypes.POINTER(ctypes.c_float)]
        ptclib.PtcCreatePointCloudFile.restype = ptclib.PtcPointCloud
        
        ptclib.PtcWriteDataPoint.argtypes = [ptclib.PtcPointCloud,
                                             ctypes.POINTER(ctypes.c_float),
                                             ctypes.POINTER(ctypes.c_float),
                                             ctypes.c_float,
                                             ctypes.POINTER(ctypes.c_float)]
        ptclib.PtcWriteDataPoint.restype = ctypes.c_int
        
        ptclib.PtcFinishPointCloudFile.argtypes = [ptclib.PtcPointCloud]
        ptclib.PtcFinishPointCloudFile.restype = None
        
        return ptclib
Example #3
0
File: _cri.py Project: behnam/cgkit
def loadRI(libName):
    """Load a RenderMan library and return a module-like handle to it.
    
    libName is the name of a shared library that implements the RenderMan
    interface. The name can either be an absolute file name or just the
    name of the library (without suffix or "lib" prefix) in which case 
    the function tries to find the library file itself.
    The return value is the library handle as returned by the ctypes 
    LoadLibrary() function. This handle has already been prepared so that
    it can be used like a module that contains the RenderMan interface.
    """
    
    # Try to figure out the location of the lib if the name is not an absolute path...
    libName = rmanlibutil.resolveRManLib(libName)
        
    # Load the library...
    ri = cdll.LoadLibrary(libName)
    
    _createRiTypes(ri)
    _createRiTokens(ri)
    _createRiConstants(ri)
    _createRiFunctions(ri)

    # Create an alias for every Ri function and RI_ constant that has the prefix removed...
    for name in dir(ri):
        if name.startswith("Ri"):
            setattr(ri, name[2:], getattr(ri, name))
        elif name.startswith("RI_"):
            setattr(ri, name[3:], getattr(ri, name))

    ri.__class__.RiLastError = property(_getLastError, _setLastError)
    ri.__class__.LastError = property(_getLastError, _setLastError)

    return ri
Example #4
0
 def _loadPtcLib(self, libName):
     """Load a RenderMan library providing the point cloud API.
     """
     resolvedLibName = rmanlibutil.resolveRManLib(libName)
     ptclib = ctypes.cdll.LoadLibrary(resolvedLibName)
     
     ptclib.PtcPointCloud = ctypes.c_void_p
     
     # Reading point cloud files
     ptclib.PtcOpenPointCloudFile.argtypes = [ctypes.c_char_p,
                                              ctypes.POINTER(ctypes.c_int),
                                              ctypes.POINTER(ctypes.c_char_p),
                                              ctypes.POINTER(ctypes.c_char_p)]
     ptclib.PtcOpenPointCloudFile.restype = ptclib.PtcPointCloud
     
     ptclib.PtcGetPointCloudInfo.argtypes = [ptclib.PtcPointCloud, ctypes.c_char_p, ctypes.c_char_p]
     ptclib.PtcGetPointCloudInfo.restype = ctypes.c_int
     
     ptclib.PtcReadDataPoint.argtypes = [ptclib.PtcPointCloud,
                                         ctypes.POINTER(ctypes.c_float),
                                         ctypes.POINTER(ctypes.c_float),
                                         ctypes.POINTER(ctypes.c_float),
                                         ctypes.POINTER(ctypes.c_float)]
     ptclib.PtcReadDataPoint.restype = ctypes.c_int
     
     ptclib.PtcClosePointCloudFile.argtypes = [ptclib.PtcPointCloud]
     ptclib.PtcClosePointCloudFile.restype = None
     
     return ptclib
Example #5
0
def loadRI(libName):
    """Load a RenderMan library and return a module-like handle to it.
    
    libName is the name of a shared library that implements the RenderMan
    interface. The name can either be an absolute file name or just the
    name of the library (without suffix or "lib" prefix) in which case 
    the function tries to find the library file itself.
    The return value is the library handle as returned by the ctypes 
    LoadLibrary() function. This handle has already been prepared so that
    it can be used like a module that contains the RenderMan interface.
    """

    # Try to figure out the location of the lib if the name is not an absolute path...
    libName = rmanlibutil.resolveRManLib(libName)

    # Load the library...
    ri = cdll.LoadLibrary(libName)

    _createRiTypes(ri)
    _createRiTokens(ri)
    _createRiConstants(ri)
    _createRiFunctions(ri)

    # Create an alias for every Ri function and RI_ constant that has the prefix removed...
    for name in dir(ri):
        if name.startswith("Ri"):
            setattr(ri, name[2:], getattr(ri, name))
        elif name.startswith("RI_"):
            setattr(ri, name[3:], getattr(ri, name))

    ri.__class__.RiLastError = property(_getLastError, _setLastError)
    ri.__class__.LastError = property(_getLastError, _setLastError)

    return ri
Example #6
0
    def _loadPtcLib(self, libName):
        """Load a RenderMan library providing the point cloud API.
        """
        resolvedLibName = rmanlibutil.resolveRManLib(libName)
        ptclib = ctypes.cdll.LoadLibrary(resolvedLibName)

        ptclib.PtcPointCloud = ctypes.c_void_p

        # Writing point cloud files
        ptclib.PtcCreatePointCloudFile.argtypes = [
            ctypes.c_char_p, ctypes.c_int,
            ctypes.POINTER(ctypes.c_char_p),
            ctypes.POINTER(ctypes.c_char_p),
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float)
        ]
        ptclib.PtcCreatePointCloudFile.restype = ptclib.PtcPointCloud

        ptclib.PtcWriteDataPoint.argtypes = [
            ptclib.PtcPointCloud,
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float), ctypes.c_float,
            ctypes.POINTER(ctypes.c_float)
        ]
        ptclib.PtcWriteDataPoint.restype = ctypes.c_int

        ptclib.PtcFinishPointCloudFile.argtypes = [ptclib.PtcPointCloud]
        ptclib.PtcFinishPointCloudFile.restype = None

        return ptclib
Example #7
0
    def _loadPtcLib(self, libName):
        """Load a RenderMan library providing the point cloud API.
        """
        resolvedLibName = rmanlibutil.resolveRManLib(libName)
        ptclib = ctypes.cdll.LoadLibrary(resolvedLibName)

        ptclib.PtcPointCloud = ctypes.c_void_p

        # Reading point cloud files
        ptclib.PtcOpenPointCloudFile.argtypes = [
            ctypes.c_char_p,
            ctypes.POINTER(ctypes.c_int),
            ctypes.POINTER(ctypes.c_char_p),
            ctypes.POINTER(ctypes.c_char_p)
        ]
        ptclib.PtcOpenPointCloudFile.restype = ptclib.PtcPointCloud

        ptclib.PtcGetPointCloudInfo.argtypes = [
            ptclib.PtcPointCloud, ctypes.c_char_p, ctypes.c_char_p
        ]
        ptclib.PtcGetPointCloudInfo.restype = ctypes.c_int

        ptclib.PtcReadDataPoint.argtypes = [
            ptclib.PtcPointCloud,
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float),
            ctypes.POINTER(ctypes.c_float)
        ]
        ptclib.PtcReadDataPoint.restype = ctypes.c_int

        ptclib.PtcClosePointCloudFile.argtypes = [ptclib.PtcPointCloud]
        ptclib.PtcClosePointCloudFile.restype = None

        return ptclib
Example #8
0
    def __init__(self, libName, VISSYMDEF):
        """Constructor.
        
        libName is the name of the library that implements the sloargs interface.
        The name can either be just the base lib name or an absolute file name.
        VISSYMDEF is a ctype Structure object that describes the VISSYMDEF
        struct for this particular renderer.
        """
        
        self._VISSYMDEF = VISSYMDEF

        libName = rmanlibutil.resolveRManLib(libName)
        self.libName = libName
        
        # Load the library...
        try:
            self._sloargs = self._loadLibrary(libName)
        except:
            raise ValueError('Failed to load library "%s": %s'%(libName, sys.exc_info()[1]))
        try:
            self._declareFunctions(self._sloargs)
        except:
            raise ValueError('Library "%s" does not implement the sloargs interface: %s'%(libName, sys.exc_info()[1]))