コード例 #1
0
ファイル: bindings.cpp プロジェクト: GaussCheng/openrave
    static void construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data )
    {
        //get the storage
        typedef converter::rvalue_from_python_storage< multi_array_t > storage_t;
        storage_t * the_storage = reinterpret_cast< storage_t * >( data );
        void * memory_chunk = the_storage->storage.bytes;
        //new (memory_chunk) multi_array_t(obj);

        //new placement
        object py_obj( handle<>( borrowed( obj ) ) );
        shape_t shape;
        get_shape( py_obj, shape );
        multi_array_t * a = new (memory_chunk) multi_array_t( shape );

        //extract each element from numpy array and put in c array
        index i( a->num_dimensions(), 0 );
        do {
            boost::python::list numpy_index;
            for( unsigned dim = 0; a->num_dimensions() != dim; ++dim ) {
                numpy_index.append( i[ dim ] );
            }
            (*a)(i) = extract<typename multi_array_t::element>(py_obj[ boost::python::tuple( numpy_index ) ]);
        }
        while( increment_index( i, *a ) );

        data->convertible = memory_chunk;
    }
コード例 #2
0
//-----------------------------------------------------------------------------
// Removes all instances of a callable from the CTickListenerManager vector.
//-----------------------------------------------------------------------------
void CTickListenerManager::unregister_listener(PyObject* pCallable)
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	// Remove the callback from the ServerCommandManager instance
	m_vecCallables.FindAndRemove(oCallable);
}
コード例 #3
0
	static std::list<TYPE> extractFromList( api::object value ) {
		std::list<TYPE> retList;

		for( Py_ssize_t i = 0; i < PyList_Size( value.ptr() ); i++ ) {
			retList.push_back( convert( api::object( handle<>( borrowed( PyList_GetItem( value.ptr(), i )  ) ) ) ).as<TYPE>() );
		}

		return retList;
	}
コード例 #4
0
ファイル: enum.cpp プロジェクト: bk5115545/omegalib
PyObject* enum_base::to_python(PyTypeObject* type_, long x)
{
    object type((type_handle(borrowed(type_))));

    dict d = extract<dict>(type.attr("values"))();
    object v = d.get(x, object());
    return incref(
        (v == object() ? type(x) : v).ptr());
}
コード例 #5
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
 static TTuple to_c_tuple( PyObject* py_obj ){
     if( !convertible( py_obj ) ){
         throw std::runtime_error( "Unable to construct boost::tuples::tuple from Python object!" );
     }
     TTuple c_tuple;
     python::object py_sequence( handle<>( borrowed( py_obj ) ) );
     construct_impl( py_sequence, c_tuple, mpl::int_< 0 >(), length_type() );
     return c_tuple;
 }
コード例 #6
0
ファイル: CurvesAlgoBinding.cpp プロジェクト: boberfly/cortex
void bindCurvesAlgo()
{
	object curveAlgoModule( borrowed( PyImport_AddModule( "IECore.CurvesAlgo" ) ) );
	scope().attr( "CurvesAlgo" ) = curveAlgoModule;

	scope meshAlgoScope( curveAlgoModule );

	def( "resamplePrimitiveVariable", &CurvesAlgo::resamplePrimitiveVariable );
	def( "deleteCurves", &CurvesAlgo::deleteCurves );
}
コード例 #7
0
void bindColorAlgo()
{
	object module( borrowed( PyImport_AddModule( "IECoreImage.ColorAlgo" ) ) );
	scope().attr( "ColorAlgo" ) = module;

	scope moduleScope( module );

	def( "transformImage", &ColorAlgo::transformImage, ( arg_( "image" ), arg_( "inputSpace" ), arg_( "outputSpace" ) ) );
	def( "transformChannel", &ColorAlgo::transformChannel, ( arg_( "channel" ), arg_( "inputSpace" ), arg_( "outputSpace" ) ) );
}
コード例 #8
0
void bindParameterAlgo()
{

	object parameterAlgoModule( handle<>( borrowed( PyImport_AddModule( "IECoreArnold.ParameterAlgo" ) ) ) );
	scope().attr( "ParameterAlgo" ) = parameterAlgoModule;
	scope parameterAlgoModuleScope( parameterAlgoModule );

	def( "setParameter", &setParameter );
	def( "getParameter", &getParameter );

}
コード例 #9
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
    static void
    construct( PyObject* py_obj, converter::rvalue_from_python_stage1_data* data){
        typedef converter::rvalue_from_python_storage<TTuple> storage_t;
        storage_t* the_storage = reinterpret_cast<storage_t*>( data );
        void* memory_chunk = the_storage->storage.bytes;
        TTuple* c_tuple = new (memory_chunk) TTuple();
        data->convertible = memory_chunk;

        python::object py_sequence( handle<>( borrowed( py_obj ) ) );
        construct_impl( py_sequence, *c_tuple, mpl::int_< 0 >(), length_type() );
    }
コード例 #10
0
ファイル: testpcap.cpp プロジェクト: bahamut8348/xkcode
	object MakeFile()
	{
		FILE* fp = pcap_dump_file( mFileHandle );
		if( fp == NULL )
		{
			PyErr_SetString( PyExc_Exception, "Can't make file." );
			throw_error_already_set();
		}
		PyObject* o = PyFile_FromFile( fp, "savefile", "wb", fclose );
		return object(borrowed(o));
	}
コード例 #11
0
//-----------------------------------------------------------------------------
// Adds a callable to the end of the CTickListenerManager vector.
//-----------------------------------------------------------------------------
void CTickListenerManager::register_listener(PyObject* pCallable)
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	// Is the callable already in the vector?
	if( !m_vecCallables.HasElement(oCallable) )
	{
		// Add the callable to the vector
		m_vecCallables.AddToTail(oCallable);
	}
}
コード例 #12
0
void bindCurvesAlgo()
{
	object curveAlgoModule( borrowed( PyImport_AddModule( "IECore.CurvesAlgo" ) ) );
	scope().attr( "CurvesAlgo" ) = curveAlgoModule;

	scope meshAlgoScope( curveAlgoModule );

	def( "resamplePrimitiveVariable", &CurvesAlgo::resamplePrimitiveVariable );
	def( "deleteCurves", &CurvesAlgo::deleteCurves, arg_( "invert" ) = false );
	def( "segment", ::segment, segmentOverLoads());
	def( "updateEndpointMultiplicity", &CurvesAlgo::updateEndpointMultiplicity );
}
コード例 #13
0
//-----------------------------------------------------------------------------
// Adds a callable to a CClientCommandManager instance.
//-----------------------------------------------------------------------------
void CClientCommandManager::AddCallback( PyObject* pCallable )
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	// Is the callable already in the vector?
	if( !m_vecCallables.HasElement(oCallable) )
	{
		// Add the callable to the vector
		m_vecCallables.AddToTail(oCallable);
	}
}
コード例 #14
0
ファイル: bindings.cpp プロジェクト: GaussCheng/openrave
    static void* convertible( PyObject * obj )
    {
        try {
            shape_t shape;
            get_shape( object( handle<>( borrowed( obj ) ) ), shape );
            if( multi_array_t::dimensionality != shape.size() ) return 0;
        }
        catch(... ) {
            return 0;
        }

        return obj;
    }
コード例 #15
0
//-----------------------------------------------------------------------------
// Removes all instances of a callable from the CListenerManager vector.
//-----------------------------------------------------------------------------
void CListenerManager::UnregisterListener(PyObject* pCallable)
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	int index = FindCallback(oCallable); //m_vecCallables.Find(oCallable);

	if (index == -1) {
		BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Callback not registered.")
	}
	else {
		m_vecCallables.Remove(index);
	}
}
コード例 #16
0
//-----------------------------------------------------------------------------
// Adds a callable to the end of the CListenerManager vector.
//-----------------------------------------------------------------------------
void CListenerManager::RegisterListener(PyObject* pCallable)
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	// Is the callable already in the vector?
	if( !IsRegistered(oCallable) )
	{
		m_vecCallables.AddToTail(oCallable);
	}
	else {
		BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Callback already registered.")
	}
}
コード例 #17
0
 static void construct(PyObject* source, rvalue_from_python_stage1_data* data)
 {
     void* const storage = ((converter::rvalue_from_python_storage<shared_ptr<T> >*)data)->storage.bytes;
     // Deal with the "None" case.
     if (data->convertible == source)
         new (storage) shared_ptr<T>();
     else
         new (storage) shared_ptr<T>(
             static_cast<T*>(data->convertible),
             shared_ptr_deleter(handle<>(borrowed(source)))
             );
     
     data->convertible = storage;
 }
コード例 #18
0
ファイル: PythonBridge.cpp プロジェクト: JeffersonK/vast
void PythonBridge::initializePython()
{
	Py_Initialize();
	main_module.reset( new object(  handle<> ( borrowed( PyImport_AddModule( "__main__" ) ) ) ) );
	main_namespace.reset( new object ( main_module->attr( "__dict__" ) ) );
	handle<> ignored( ( PyRun_String( "from isis import util; from isis import data", Py_file_input, main_namespace->ptr(), main_namespace->ptr() ) ) );

	//redirect stdio
	( *main_namespace )["PythonStdIoRedirect"] = class_<PythonStdIoRedirect>( "PythonStdIoRedirect", init<>() )
			.def( "write", &PythonStdIoRedirect::Write );

	boost::python::import( "sys" ).attr( "stderr" ) = python_stdio_redirector;
	boost::python::import( "sys" ).attr( "stdout" ) = python_stdio_redirector;
}
コード例 #19
0
//-----------------------------------------------------------------------------
// Removes a callable from a CClientCommandManager instance.
//-----------------------------------------------------------------------------
void CClientCommandManager::RemoveCallback( PyObject* pCallable )
{
	// Get the object instance of the callable
	object oCallable = object(handle<>(borrowed(pCallable)));

	// Remove the callback from the CClientCommandManager instance
	m_vecCallables.FindAndRemove(oCallable);

	// Are there any more callbacks registered for this command?
	if( !m_vecCallables.Count() )
	{
		// Remove the CClientCommandManager instance
		RemoveCClientCommandManager(m_Name);
	}
}
コード例 #20
0
 static void construct(PyObject* source, rvalue_from_python_stage1_data* data)
 {
     void* const storage = ((converter::rvalue_from_python_storage<shared_ptr<T> >*)data)->storage.bytes;
     // Deal with the "None" case.
     if (data->convertible == source)
         new (storage) shared_ptr<T>();
     else
     {
         boost::shared_ptr<void> hold_convertible_ref_count(
           (void*)0, shared_ptr_deleter(handle<>(borrowed(source))) );
         // use aliasing constructor
         new (storage) shared_ptr<T>(
             hold_convertible_ref_count,
             static_cast<T*>(data->convertible));
     }
     
     data->convertible = storage;
 }
コード例 #21
0
void bindMeshAlgo()
{
	object meshAlgoModule( borrowed( PyImport_AddModule( "IECore.MeshAlgo" ) ) );
	scope().attr( "MeshAlgo" ) = meshAlgoModule;

	scope meshAlgoScope( meshAlgoModule );

	StdPairToTupleConverter<PrimitiveVariable, PrimitiveVariable>();

	def( "calculateTangents", &MeshAlgo::calculateTangents, ( arg_( "mesh" ), arg_( "uvSet" ) = "uv", arg_( "orthoTangents" ) = true, arg_( "position" ) = "P" ) );
	def( "calculateFaceArea", &MeshAlgo::calculateFaceArea, ( arg_( "mesh" ), arg_( "position" ) = "P" ) );
	def( "calculateFaceTextureArea", &MeshAlgo::calculateFaceTextureArea, ( arg_( "mesh" ), arg_( "uvSet" ) = "uv", arg_( "position" ) = "P" ) );
	def( "calculateDistortion", &MeshAlgo::calculateDistortion, ( arg_( "mesh" ), arg_( "uvSet" ) = "uv", arg_( "referencePosition" ) = "Pref", arg_( "position" ) = "P" ) );
	def( "resamplePrimitiveVariable", &MeshAlgo::resamplePrimitiveVariable );
	def( "deleteFaces", &MeshAlgo::deleteFaces, arg_( "invert" ) = false );
	def( "reverseWinding", &MeshAlgo::reverseWinding );
	def( "reorderVertices", &MeshAlgo::reorderVertices, ( arg_( "mesh" ), arg_( "id0" ), arg_( "id1" ), arg_( "id2" ) ) );
	def( "distributePoints", &MeshAlgo::distributePoints, ( arg_( "mesh" ), arg_( "density" ) = 100.0, arg_( "offset" ) = Imath::V2f( 0 ), arg_( "densityMask" ) = "density", arg_( "uvSet" ) = "uv", arg_( "position" ) = "P" ) );
	def( "segment", &::segment, segmentOverLoads() );
}
コード例 #22
0
ファイル: Python.cpp プロジェクト: AtomicFiction/cortex
	Python()
	{
		IECorePython::ScopedGILLock gilLock;
	
		object mainModule = object( handle<>( borrowed( PyImport_AddModule( "__main__" ) ) ) );
		object mainModuleNamespace = mainModule.attr( "__dict__" );
	
		std::string toExecute = "import IECore\nimport IECoreNuke";
		
		try
		{
			handle<> resultHandle( PyRun_String(
				toExecute.c_str(),
				Py_file_input,
				mainModuleNamespace.ptr(),
				mainModuleNamespace.ptr()
			) );
		}
		catch( error_already_set & )
		{
			PyErr_Print();
		}
	}
コード例 #23
0
    static void construct(PyObject* source, rvalue_from_python_stage1_data* data)
    {
      std::cout << __PRETTY_FUNCTION__ <<"\n";
      void* const storage = ((converter::rvalue_from_python_storage<shared_ptr<T> >*)data)->storage.address();
        // Deal with the "None" case.
        if (data->convertible == source)
            new (storage) shared_ptr<T>();
        else
        {
            boost::shared_ptr<void> hold_convertible_ref_count(
              (void*)0, shared_ptr_deleter(handle<>(borrowed(source))) );
	    std::cout << "hold convertible: " << hold_convertible_ref_count;
            // use aliasing constructor
	    // points to /* T */ data->convertible
	    // share refcount with hold_convertible_ref_count (1)
            new (storage) shared_ptr<T>(
                hold_convertible_ref_count,
                static_cast<T*>(data->convertible));
        }
        
        /* void */ data->convertible = storage;
	std::cout << "exit construct\n";
    }
コード例 #24
0
ファイル: tuples.hpp プロジェクト: CTrauma/pypp11
    static void*
    convertible(PyObject* py_obj){

        if( !PySequence_Check( py_obj ) ){
            return 0;
        }

        if( !PyObject_HasAttrString( py_obj, "__len__" ) ){
            return 0;
        }

        python::object py_sequence( handle<>( borrowed( py_obj ) ) );
    
        if( tuples::length< TTuple >::value != len( py_sequence ) ){
            return 0;
        }

        if( convertible_impl( py_sequence, mpl::int_< 0 >(), length_type() ) ){
            return py_obj;
        }
        else{
            return 0;
        }
    }
コード例 #25
0
void bindSceneAlgo()
{
	object module( borrowed( PyImport_AddModule( "GafferScene.SceneAlgo" ) ) );
	scope().attr( "SceneAlgo" ) = module;
	scope moduleScope( module );

	def( "exists", &existsWrapper );
	def( "visible", visibleWrapper );
	def( "matchingPaths", &matchingPathsWrapper1 );
	def( "matchingPaths", &matchingPathsWrapper2 );
	def( "matchingPaths", &matchingPathsWrapper3 );
	def( "shutter", &shutterWrapper );
	def( "setExists", &setExistsWrapper );
	def(
		"sets",
		&setsWrapper1,
		( arg( "scene" ), arg( "_copy" ) = true )
	);
	def(
		"sets",
		&setsWrapper2,
		( arg( "scene" ), arg( "setNames" ), arg( "_copy" ) = true )
	);
}
コード例 #26
0
const_object_slice
object_operators<U>::slice(object_cref start, slice_nil) const
{
    object_cref2 x = *static_cast<U const*>(this);
    return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
}
コード例 #27
0
const_object_slice
object_operators<U>::slice(slice_nil, object_cref finish) const
{
    object_cref2 x = *static_cast<U const*>(this);
    return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
}
コード例 #28
0
const_object_slice
object_operators<U>::slice(object_cref start, object_cref finish) const
{
    object_cref2 x = *static_cast<U const*>(this);
    return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
}
コード例 #29
0
 arg_rvalue_from_python(PyObject * p) : _p(borrowed(p)) {}
コード例 #30
0
 inline arg_to_python(Eigen::PythonMatrix<_Scalar,_Rows,_Cols> const & v) :
     handle<>(borrowed(v.getPyObject().ptr())) {}