Commit 8732975e authored by jannick.wolters's avatar jannick.wolters
Browse files

fixed python issue

parent 3c753eb2
Pipeline #95164 passed with stages
in 28 minutes and 42 seconds
......@@ -23,7 +23,7 @@ def extract(image_name):
img = Image.open(image_name).convert('L') #image data
I = np.asarray(img) # image as greyscale
I = I/255; # rescale values to [0,1]
J = deepcopy(np.flipud(I))
J = deepcopy(np.flipud(I))
dimensions = (1,1) # [cm]
return J , dimensions
......@@ -326,27 +326,34 @@ Matrix createSU2MeshFromImage( std::string imageName, std::string SU2Filename )
ErrorMessages::Error( "Output directory '" + outDir.string() + "' does not exists!", CURRENT_FUNCTION );
}
std::string pyPath = RTSN_PYTHON_PATH;
if( !Py_IsInitialized() ) {
setenv( "PYTHONPATH", RTSN_PYTHON_PATH, 1 );
Py_Initialize();
Py_InitializeEx( 0 );
if( !Py_IsInitialized() ) {
ErrorMessages::Error( "Python init failed!", CURRENT_FUNCTION );
}
PyRun_SimpleString( ( "import sys\nsys.path.append('" + pyPath + "')" ).c_str() );
}
PyObject *pArgs, *pReturn, *pModule, *pFunc;
PyArrayObject* np_ret;
auto image = PyUnicode_FromString( imageName.c_str() );
auto su2 = PyUnicode_FromString( SU2Filename.c_str() );
PyObject* pName = PyUnicode_FromString( "mesh_from_image" );
pModule = PyImport_Import( pName );
Py_CLEAR( pName );
std::string moduleName = "mesh_from_image";
pModule = PyImport_ImportModule( moduleName.c_str() );
if( !pModule ) {
ErrorMessages::Error( "'mesh_from_image.py' can not be imported!", CURRENT_FUNCTION );
PyErr_Print();
ErrorMessages::Error( "'" + moduleName + "' can not be imported!", CURRENT_FUNCTION );
}
pFunc = PyObject_GetAttrString( pModule, "generate" );
if( !pFunc || !PyCallable_Check( pFunc ) ) {
Py_CLEAR( pModule );
Py_CLEAR( pFunc );
PyErr_Print();
Py_DecRef( pModule );
Py_DecRef( pFunc );
ErrorMessages::Error( "'generate' is null or not callable!", CURRENT_FUNCTION );
}
......@@ -361,16 +368,11 @@ Matrix createSU2MeshFromImage( std::string imageName, std::string SU2Filename )
double* c_out = reinterpret_cast<double*>( PyArray_DATA( np_ret ) );
Matrix gsImage( m, n, c_out );
// for( unsigned i = 0; i < m; ++i ) {
// for( unsigned j = 0; j < n; ++j ) {
// gsImage( i, j ) = c_out[j * m + i];
// }
//}
// Finalizing
Py_CLEAR( pFunc );
Py_CLEAR( pModule );
Py_CLEAR( np_ret );
Py_DecRef( pFunc );
Py_DecRef( pModule );
Py_DECREF( np_ret );
return gsImage.transpose();
}
......@@ -30,6 +30,7 @@ int main( int argc, char** argv ) {
solver->Solve();
solver->Save();
if( Py_IsInitialized() ) Py_Finalize();
MPI_Finalize();
return EXIT_SUCCESS;
}
......@@ -9,6 +9,7 @@ int main( int argc, char** argv ) {
wchar_t* program = Py_DecodeLocale( argv[0], NULL );
Py_SetProgramName( program );
const int result = Catch::Session().run( argc, argv );
if( Py_IsInitialized() ) Py_Finalize();
MPI_Finalize();
return result;
}
......@@ -87,7 +87,7 @@ TEST_CASE( "convert image data to grayscale matrix", "[image I/O]" ) {
delete mesh;
// std::remove( outputFile.c_str() );
std::remove( outputFile.c_str() );
}
std::remove( testMesh.c_str() );
......
......@@ -35,6 +35,6 @@ RUN wget --no-check-certificate --quiet https://www.vtk.org/files/release/8.2/VT
&& cd - \
&& rm -rf VTK-*
RUN pip3 install numpy pygmsh Pillow
RUN pip3 install numpy pygmsh Pillow pydicom
WORKDIR /home
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment