Skip to content

Commit

Permalink
Initial Debian support
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Oct 30, 2021
1 parent 1a5250b commit 3351dc2
Show file tree
Hide file tree
Showing 44 changed files with 714 additions and 4,287 deletions.
6 changes: 6 additions & 0 deletions Debian/data-control.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: surfice-data
Version: <ver>
Architecture: all
Maintainer: NeuroDebian Team <[email protected]>
Description: data files for Surfice
Surfice GUI-based visualization for neuroimaging meshes
66 changes: 66 additions & 0 deletions Debian/make_deb_amd64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# Fail if anything not planed to go wrong, goes wrong
set -eu
sw=surfice
source ../vers.inc
ver=$kVers
arch=amd64
#set widgetset set for default(QT5)
wigetset=
sw=${sw}${wigetset}

pkg=${sw}_${ver}_${arch}
#deb=${pkg}.deb
exePath=${pkg}/usr/bin/
appPath=${pkg}/usr/share/applications/
docPath=${pkg}/usr/share/doc/${sw}/
iconPath=${pkg}/usr/share/icons/hicolor/scalable/apps/
manPath=${pkg}/usr/share/man/man1/
man=${sw}.1.gz

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $SCRIPT_DIR

if [ -z "$wigetset" ]
then
lazbuild --ws=qt5 ../surfice.lpi
else
lazbuild --ws=gtk2 ../surfice.lpi
fi

#remove previous package files
rm -rf ${pkg}
#copy all required files
#copy control file
mkdir -p ${pkg}/DEBIAN
#cp ./${sw}-control.txt ${pkg}/DEBIAN/control
sed "s/<ver>/$ver/" ./${sw}-control.txt > ${pkg}/DEBIAN/control
#copy executable
mkdir -p ${exePath}
cp ../${sw} ${exePath}${sw}
#copy desktop file
mkdir -p ${appPath}
#cp ${sw}.desktop ${appPath}${sw}.desktop
sed "s/<ver>/$ver/" ./${sw}.desktop > ${appPath}${sw}.desktop

#copy icon svg
mkdir -p ${iconPath}
cp ${sw}.svg ${iconPath}${sw}.svg

#copy documents
mkdir -p ${docPath}
cp ../license.txt ${docPath}copyright
#copy manual
mkdir -p ${manPath}
cp ${man} ${manPath}${man}

dpkg-deb --build --root-owner-group ${pkg}
#remove temporary files
rm -rf ${pkg}

echo Test the package:
echo sudo dpkg -I ${pkg}.deb
echo sudo dpkg -c ${pkg}.deb
echo sudo dpkg -i ${pkg}.deb
exit 0

37 changes: 37 additions & 0 deletions Debian/make_deb_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#Create Debian package for all versions of Surfice

# Fail if anything not planed to go wrong, goes wrong
set -eu
sw=surfice-data
source ../vers.inc
ver=$kVers
pkg=${sw}_${ver}_all
#deb=${pkg}.deb
resourcePath=${pkg}/usr/share/surfice/


SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $SCRIPT_DIR

#remove previous package files
rm -rf ${pkg}
#copy all required files
mkdir -p ${pkg}/DEBIAN
#cp ./data-control.txt ${pkg}/DEBIAN/control
sed "s/<ver>/$ver/" ./data-control.txt > ${pkg}/DEBIAN/control

mkdir -p ${resourcePath}
cp -a ../Resources/. ${resourcePath}
#Linux does not need Windows resources python36.dll and python36.zip
rm -rf ${resourcePath}python*.*

dpkg-deb --build --root-owner-group ${pkg}
#remove temporary files
rm -rf ${pkg}
exit 0





7 changes: 7 additions & 0 deletions Debian/surfice-control.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Package: surfice
Version: <ver>
Architecture: amd64
Maintainer: NeuroDebian Team <[email protected]>
Depends: libqt5pas1, libc6 (>= 2.14), python3:any (>= 3.6), surfice-data (= <ver>)
Description: Surfice
Surfice GUI-based visualization for neuroimaging meshes (using QT5)
18 changes: 18 additions & 0 deletions Debian/surfice.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.TH "SURFICE" "1" "September 2021" "Chris Rorden" "User Commands"
.SH NAME
surfice \- neuroimaging mesh viewing tool
.SH "DESCRIPTION"
Surfice is a GUI-based visualization and analysis tool for neuroimaging
data. It can display triangulated meshes in many formats, including
PLY, GIfTI, FreeSurfer, and OBJ. Surfice can also display diffusion tensor
tractography maps from various formats including TRK and TCK. In addition,
it is able to show connectome maps.
.SH "AUTHOR"
\fBsurfice\fR was written by Chris Rorden.
.PP
This manual page was written by Chris Rorden,
for the Debian project (but may be used by others).
.SH "SEE ALSO"
.BR dcm2niix "(1)"
.TP
\fBSurfice Homepage and Wiki:\fR https://www.nitrc.org/plugins/mwiki/index.php/surfice:MainPage
14 changes: 14 additions & 0 deletions Debian/surfice.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Desktop Entry]
Version=<ver>
Name=Surfice
GenericName=2D/3D MRI Surface Viewer
GenericName[de]=2D/3D Betrachter für MRT-Daten
GenericName[ru]=Просмотр 2D/3D МРТ-данных
Comment=Edit Exec and Icon paths for your system
Exec=surfice %F
TryExec=surfice
Icon=/usr/share/icons/hicolor/scalable/apps/surfice.svg
Terminal=false
Type=Application
Categories=Education;Graphics;Science;DataVisualization;MedicalSoftware;QT5;Viewer;

77 changes: 77 additions & 0 deletions Debian/surfice.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion PythonBridge/DynamicImports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ CodePointer(PyFunction_GetCode) :=Import('PyFunction_GetCode');
CodePointer(PyFunction_GetGlobals) :=Import('PyFunction_GetGlobals');
CodePointer(PyFunction_New) :=Import('PyFunction_New');
CodePointer(PyImport_AddModule) :=Import('PyImport_AddModule');
CodePointer(PyImport_Cleanup) :=Import('PyImport_Cleanup');
//CodePointer(PyImport_Cleanup) :=Import('PyImport_Cleanup');
CodePointer(PyImport_GetMagicNumber) :=Import('PyImport_GetMagicNumber');
CodePointer(PyImport_ImportFrozenModule):=Import('PyImport_ImportFrozenModule');
CodePointer(PyImport_ImportModule) :=Import('PyImport_ImportModule');
Expand Down
2 changes: 1 addition & 1 deletion PythonBridge/DynamicTypes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ PyFunction_GetCode:function (ob:PPyObject):PPyObject; cdecl;
PyFunction_GetGlobals:function (ob:PPyObject):PPyObject; cdecl;
PyFunction_New:function (ob1,ob2:PPyObject):PPyObject; cdecl;
PyImport_AddModule:function (name:PAnsiChar):PPyObject; cdecl;
PyImport_Cleanup:procedure; cdecl;
//PyImport_Cleanup:procedure; cdecl;
PyImport_GetMagicNumber:function :LONGINT; cdecl;
PyImport_ImportFrozenModule:function (key:PAnsiChar):integer; cdecl;
PyImport_ImportModule:function (name:PAnsiChar):PPyObject; cdecl;
Expand Down
5 changes: 2 additions & 3 deletions PythonBridge/Python3Core.pas
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{$mode objfpc}
{$include pyopts.inc} //for define PYTHON_DYNAMIC
{$assertions on}

{$ifdef win32}
{$define cpux86}
{$endif}
{$ifdef windows}
{$define PYTHON_DYNAMIC}
{$endif}


{$ifdef fpc}
{$ifdef cpu64}
Expand Down
100 changes: 92 additions & 8 deletions PythonBridge/PythonBridge.pas
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{$mode objfpc}
{$assertions on}
{$ifdef windows}
{$define PYTHON_DYNAMIC}
{$endif}
{$include pyopts.inc} //for define PYTHON_DYNAMIC



unit PythonBridge;
interface
uses
{$ifdef windows}windows,{$endif}{$ifdef lcl} dialogs, {$endif} Python3Core, SysUtils;
{$ifdef linux}LazFileUtils,{$endif}{$ifdef windows}windows,{$endif}{$ifdef lcl} dialogs, {$endif} Python3Core, SysUtils;

type
TPythonBridgeMethod = record
Expand Down Expand Up @@ -95,6 +93,63 @@ function findDll(resourceDir: string): string; //Detect .DLL version
Function SetDllDirectory(lpPathName: LPCTSTR):LongBool; stdcall; external 'kernel32.dll' name 'SetDllDirectoryA'; //uses add windows,sysutils,
{$endif}

{$ifdef linux} {$ifdef PYTHON_DYNAMIC}
function findLibDebian(base: string): string;
//https://matthew-brett.github.io/pydagogue/debian_python_paths.html
// check base of "/usr/local/lib" and "/usr/lib"
//lib = /usr/lib/python3.9/config-3.9-x86_64-linux-gnu/libpython3.9.so
//e.g. Ubuntu 18.04
//lib = /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.so
var
i: integer;
begin
for i := 11 downto 6 do begin
result := format('%s/python3.%d/config-3.%d-x86_64-linux-gnu/libpython3.%d.so', [base, i, i, i]);
if FileExists(result) then exit;
//pymalloc PEP-3149: ABI version tagged .so files.
result := format('%s/python3.%d/config-3.%d-x86_64-linux-gnu/libpython3.%dm.so', [base, i, i, i]);
if FileExists(result) then exit;
end;
writeln('Unable to find a library with a name like '+result);
result := '';
end;

function findFirstRecursive(const SearchPath: String; SearchMask: String): string;
//example findFirstRecursive('/usr/lib/', 'libpython3*so')
//uses LazFileUtils
var
ret: string;
procedure find1(Dir: string);
var
SR: TSearchRec;
begin
if (ret <> '') or (FileIsSymlink(Dir)) then exit;
if FindFirst(IncludeTrailingBackslash(Dir) + SearchMask, faAnyFile or faDirectory, SR) = 0 then begin
ret := IncludeTrailingBackslash(Dir) +SR.Name;
FindClose(SR);
exit;
end;
if FindFirst(IncludeTrailingBackslash(Dir) + '*.*', faAnyFile or faDirectory, SR) = 0 then
try
repeat
if ((SR.Attr and faDirectory) <> 0) and (SR.Name <> '.') and (SR.Name <> '..') then
find1(IncludeTrailingBackslash(Dir) + SR.Name); // recursive call!
until FindNext(Sr) <> 0;
finally
FindClose(SR);
end;
end;
begin
ret := '';
find1(SearchPath);
result := ret;
end;

function findLinuxLibPython3(pthroot: string = '/usr/lib/'): string;
begin
result := findFirstRecursive(pthroot, 'libpython3*so');
end;
{$endif} {$endif}
function PythonLoadAndInitialize(resourceDir: ansistring; callback: PythonDataMethodCallback): boolean;
var
home: ansistring;
Expand All @@ -109,6 +164,31 @@ function PythonLoadAndInitialize(resourceDir: ansistring; callback: PythonDataMe
Assert(FileExists(home), 'Python home can''t be found at '+home);
PythonInitialize(home, callback);
{$else}
{$ifdef PYTHON_DYNAMIC}
//https://matthew-brett.github.io/pydagogue/debian_python_paths.html
home := '';
if (FileExists(resourceDir)) then begin
home := ResourceDir;
writeln('Assuming this is a valid python library (e.g. "libpython3.9.so")'+home);
end;
{$ifdef linux}
if not (FileExists(home)) then
home := findLibDebian('/usr/lib');
if not (FileExists(home)) then
home := findLibDebian('/usr/local/lib');
if not (FileExists(home)) then
home := findLinuxLibPython3('/usr/local/lib');
{$endif}
if not (FileExists(home)) then begin
{$ifdef lcl}
ShowMessage('Unable to find Python library: '+home);
{$else}
writeln('Unable to find Python home: '+home);
{$endif}
exit(false);
end;
LoadLibrary(home);
{$else}
home := resourceDir + pathdelim + 'python37';
if not (DirectoryExists(home)) then begin
{$ifdef lcl}
Expand All @@ -118,9 +198,7 @@ function PythonLoadAndInitialize(resourceDir: ansistring; callback: PythonDataMe
{$endif}
exit(false);
end;
writeln('Python Home: ' + home);
PythonInitialize(home, callback);
Assert(DirectoryExists(home), 'Python home can''t be found at '+home);
{$endif PYTHON_DYNAMIC}
PythonInitialize(home, callback);
{$endif}
result := true;
Expand Down Expand Up @@ -382,8 +460,14 @@ function RedirectIO: boolean;
function PythonInitialize(pythonHome: ansistring; callback: PythonDataMethodCallback): boolean;
begin
DataMethodCallback := callback;
{$ifdef unix}
{$ifndef PYTHON_DYNAMIC}
Py_SetPythonHome(Py_DecodeLocale(PAnsiChar(pythonHome), nil));
{$endif}
{$else}
Py_SetPythonHome(Py_DecodeLocale(PAnsiChar(pythonHome), nil));
//Py_SetPythonHome(PWideChar(pythonHome));

{$endif}
Py_Initialize;
result := RedirectIO;
end;
Expand Down
9 changes: 9 additions & 0 deletions PythonBridge/pyopts.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{$ifdef windows}
{$define PYTHON_DYNAMIC}
{$endif}
{$ifdef linux}
{$define PYTHON_DYNAMIC}
{$endif}
{$ifdef darwin}
//{$define PYTHON_DYNAMIC}
{$endif}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ else
fi
```

You can also build this project from the command line (assuming you have FPC Lazarus and the requried packages installed):
You can also build this project from the command line (assuming you have FPC Lazarus and the required packages installed):

```
lazbuild surfice.lpr
Expand Down
2 changes: 1 addition & 1 deletion Resources/shaders/Gooch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void main() {
// Fluxus Shader Library
// ---------------------
// Gooch NPR Shading Model
// Orginally for technical drawing style
// Originally for technical drawing style
// rendering, uses warm and cool colours
// to depict shading to keep detail in the
// shadowed areas
Expand Down
2 changes: 1 addition & 1 deletion Resources/shadersOld/Gooch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
// Fluxus Shader Library
// ---------------------
// Gooch NPR Shading Model
// Orginally for technical drawing style
// Originally for technical drawing style
// rendering, uses warm and cool colours
// to depict shading to keep detail in the
// shadowed areas
Expand Down
2 changes: 1 addition & 1 deletion Resources/shadersOld/Wire.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Comment: object shimmers as is rotates. Wires useful for evaluating mesh quality
// early geometry shaders. Works fine on NVidia GPU on same setup (hybrid laptop) and with
// Intel drivers that come with OSX.

//#define INTELBUG // <- ENALBE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
//#define INTELBUG // <- ENABLE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
#ifdef INTELBUG
in vec3 vL[3]; //[3] because this makes a triangle
in vec3 vN[3];
Expand Down
2 changes: 1 addition & 1 deletion Resources/shadersOld/Wireframe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Hint: setting FaceAlpha less than one can cause object to shimmer as is rotates.
// early geometry shaders. Works fine on NVidia GPU on same setup (hybrid laptop) and with
// Intel drivers that come with OSX.

//#define INTELBUG // <- ENALBE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
//#define INTELBUG // <- ENABLE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
#ifdef INTELBUG
in vec3 vL[3]; //[3] because this makes a triangle
in vec3 vN[3];
Expand Down
2 changes: 1 addition & 1 deletion Resources/shadersOld/xExploded.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uniform float Explode;
// early geometry shaders. Works fine on NVidia GPU on same setup (hybrid laptop) and with
// Intel drivers that come with OSX.

//#define INTELBUG // <- ENALBE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
//#define INTELBUG // <- ENABLE THIS LINE TO WORK WITH BORKED INTEL DRIVERS
#ifdef INTELBUG
in vec3 vL[3]; //[3] because this makes a triangle
in vec3 vN[3];
Expand Down
Loading

0 comments on commit 3351dc2

Please sign in to comment.