python 2.7.2 VTK 5.8
In python, vtkUnstructuredGrid.GetCell(n) always return a global static object. Assume that we have an unstructured grid object "ug". [ug.GetCell(i) for i in range(ug.GetNumberOfCells())] gives you a list of copies of the same, maybe global, cell object, which should be the copy of the last cell. If you wanna do sth with each single cell, do it before the return cell get override. Ex. [ map(ug.GetCell(i).GetPointId, range(4)) for i in range(ug.GetNumberOfCells())]
I did not test any other function such as GetFace.
Sunday, February 19, 2012
su under windows(maybe win7+)
runas [{/profile|/noprofile}] [/env] [/netonly] [/smartcard] [/showtrustlevels] [/trustlevel] /user:UserAccountName program
Example:
runas /noprofile /user:Administrator cmd
Wednesday, February 8, 2012
cmake find module -> CmakeLists.txt -> your project
1. Find modules. CMake provides a lot of find modules by default such as vtk. However you might still need to write your own ones. You need to get those include dirs and libs. Here is a tiny example for voro++.
# - Try to find voro++
# Once done this will define
# VORO++_FOUND - System has voro++
# VORO++_INCLUDE_DIRS - The voro++ include directories
# VORO++_LIBRARIES - The libraries needed to use voro++
# VORO++_DEFINITIONS - Compiler switches required for using voro++
find_package(PkgConfig)
pkg_check_modules(PC_VORO++ QUIET voro++)
set(VORO++_DEFINITIONS ${PC_VORO++_CFLAGS_OTHER})
find_path(VORO++_INCLUDE_DIR voro++.hh
HINTS ${PC_VORO++_INCLUDEDIR} ${PC_VORO++_INCLUDE_DIRS}
PATH_SUFFIXES voro++ )
find_library(VORO++_LIBRARY NAMES voro++
HINTS ${PC_VORO++_LIBDIR} ${PC_VORO++_LIBRARY_DIRS} )
set(VORO++_LIBRARIES ${VORO++_LIBRARY} )
set(VORO++_INCLUDE_DIRS ${VORO++_INCLUDE_DIR} )
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set VORO++_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(voro++ DEFAULT_MSG
VORO++_LIBRARY VORO++_INCLUDE_DIR)
mark_as_advanced(VORO++_INCLUDE_DIR VORO++_LIBRARY )
cmake_minimum_required(VERSION 2.6.2)
PROJECT(vtk_tetrahedron)
if(NOT CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH)
endif()
list(APPEND CMAKE_MODULE_PATH /home/jesse/Jesse_Studio/cmake_find)
# set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
find_package(Voro++ REQUIRED)
include_directories(${VORO++_INCLUDE_DIR})
add_executable(Tetrahedron Tetrahedron.cxx)
if(VTK_LIBRARIES)
target_link_libraries(Tetrahedron ${VTK_LIBRARIES})
else()
target_link_libraries(Tetrahedron vtkHybrid )
endif()
if(VORO++_LIBRARIES)
target_link_libraries(Tetrahedron ${VORO++_LIBRARIES})
endif()
# - Try to find voro++
# Once done this will define
# VORO++_FOUND - System has voro++
# VORO++_INCLUDE_DIRS - The voro++ include directories
# VORO++_LIBRARIES - The libraries needed to use voro++
# VORO++_DEFINITIONS - Compiler switches required for using voro++
find_package(PkgConfig)
pkg_check_modules(PC_VORO++ QUIET voro++)
set(VORO++_DEFINITIONS ${PC_VORO++_CFLAGS_OTHER})
find_path(VORO++_INCLUDE_DIR voro++.hh
HINTS ${PC_VORO++_INCLUDEDIR} ${PC_VORO++_INCLUDE_DIRS}
PATH_SUFFIXES voro++ )
find_library(VORO++_LIBRARY NAMES voro++
HINTS ${PC_VORO++_LIBDIR} ${PC_VORO++_LIBRARY_DIRS} )
set(VORO++_LIBRARIES ${VORO++_LIBRARY} )
set(VORO++_INCLUDE_DIRS ${VORO++_INCLUDE_DIR} )
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set VORO++_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(voro++ DEFAULT_MSG
VORO++_LIBRARY VORO++_INCLUDE_DIR)
mark_as_advanced(VORO++_INCLUDE_DIR VORO++_LIBRARY )
2. Then you are going to add the modules above in your CMakeLists.txt.
cmake_minimum_required(VERSION 2.6.2)
PROJECT(vtk_tetrahedron)
if(NOT CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH)
endif()
list(APPEND CMAKE_MODULE_PATH /home/jesse/Jesse_Studio/cmake_find)
# set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
find_package(Voro++ REQUIRED)
include_directories(${VORO++_INCLUDE_DIR})
add_executable(Tetrahedron Tetrahedron.cxx)
if(VTK_LIBRARIES)
target_link_libraries(Tetrahedron ${VTK_LIBRARIES})
else()
target_link_libraries(Tetrahedron vtkHybrid )
endif()
if(VORO++_LIBRARIES)
target_link_libraries(Tetrahedron ${VORO++_LIBRARIES})
endif()
3. That's it. Use you cmake normally.
Saturday, February 4, 2012
Saturday, January 7, 2012
OpenNI + linux
Under my linux I have to rm the module gspca_kinect to make openni to find the device.
It should be better to blacklist it in the init script.
It should be better to blacklist it in the init script.
Sunday, December 18, 2011
Extend Numpy with ctypes
The idea is to write extend numpy with c. Thus, you can enjoy the performance of c and also employ any c only libs. Passing data between numpy and c with numpy arrays and c pointers.
PS: ctypes dose not recognize c++ symbols. Make sure to put your wrap function between extern "C" { and }
Here is the example.
We need 3 files.
C implimentation func.c;
Python wrapping func.py;
and Python calling interface test.py.
/*func.c*/
/* You can complie it with the following command*/
/* gcc -O2 -fPIC func.c -shared -o libfunc.so */
#ifdef __cplusplus
extern "C" {
#endif
int skew_symmetric_matrix(double *t, double *tx)
{
tx[0] = 0;
tx[1] = -t[2];
tx[2] = t[1];
tx[3] = t[2];
tx[4] = 0;
tx[5] = -t[0];
tx[6] = -t[1];
tx[7] = t[0];
tx[8] = 0;
return 0;
}
#ifdef __cplusplus
}
#endif
##Python wrapping file
##func.py
PS: ctypes dose not recognize c++ symbols. Make sure to put your wrap function between extern "C" { and }
Here is the example.
We need 3 files.
C implimentation func.c;
Python wrapping func.py;
and Python calling interface test.py.
/*func.c*/
/* You can complie it with the following command*/
/* gcc -O2 -fPIC func.c -shared -o libfunc.so */
#ifdef __cplusplus
extern "C" {
#endif
int skew_symmetric_matrix(double *t, double *tx)
{
tx[0] = 0;
tx[1] = -t[2];
tx[2] = t[1];
tx[3] = t[2];
tx[4] = 0;
tx[5] = -t[0];
tx[6] = -t[1];
tx[7] = t[0];
tx[8] = 0;
return 0;
}
#ifdef __cplusplus
}
#endif
##Python wrapping file
##func.py
import numpy as np
import ctypes as ct
##load the s
_func = np.ctypeslib.load_library('libfunc', '.')
ndpointer = np.ctypeslib.ndpointer
array_double = ndpointer(dtype = ct.POINTER(ct.c_double), flags='CONTIGUOUS,ALIGNED')
##Specify the arg types the numpy arrays which have to be aligned continuously.
##Passing a[::2] directly might not work. Using a[::2].copy() instead.
##There also other arg types such as [array_double, ct.c_int, ct.c_double]
_func.skew_symmetric_matrix.argtypes = [array_double] * 2
##Define python wrapping funcion
##ctypes can only see pointers but no size or shape of your numpy array
def skew_symmetric_matrix(t):
if t.size != 3:
return None
tx = np.zeros((3, 3), dtype=np.double)
_func.skew_symmetric_matrix(t, tx)
return tx
##Python interface
##test.py
import scipy as sp, numpy as np
import func
t = np.array([1.0, 2.0, 3.0])
tx = func.skew_symmetric_matrix(t)
print (t)
print (tx)
Saturday, December 10, 2011
cblas of gotoblas2
According to
"http://shimingyoung.blogspot.com/2010/01/gotoblas-and-lapackwrapper.html"
Also edit the cblas.h by adding one line
#define blasint int
And edit the f2c.h by changing the line on the 10th line to
typedef int integer;
Otherwise, blasint is not defined while compiling.
"http://shimingyoung.blogspot.com/2010/01/gotoblas-and-lapackwrapper.html"
Also edit the cblas.h by adding one line
#define blasint int
And edit the f2c.h by changing the line on the 10th line to
typedef int integer;
Otherwise, blasint is not defined while compiling.
Subscribe to:
Posts (Atom)