initWorkspaceCaffeTools.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function initWorkspaceCaffeTools
  2. % function initWorkspaceCaffeTools
  3. %
  4. % Author: Alexander Freytag
  5. %
  6. % BRIEF:
  7. % Add local subfolders and 3rd party libraries to Matlabs work space.
  8. % Needs to be adapted to your system!
  9. %
  10. %
  11. % Exemplary call from external position:
  12. % CAFFETOOLDIR = '/place/to/this/repository/';
  13. % currentDir = pwd;
  14. % cd ( CAFFETOOLDIR );
  15. % initWorkspaceCaffeTools;
  16. % cd ( currentDir );
  17. %
  18. %% setup paths of 3rd-party libraries in a user-specific manner
  19. CAFFEDIR = [];
  20. if strcmp( getenv('USER'), 'freytag')
  21. [~, s_hostname] = system( 'hostname' );
  22. s_hostname = s_hostname ( 1:(length(s_hostname)-1) ) ;
  23. s_dest_caffebuild = sprintf( '/home/freytag/lib/caffe_%s/matlab/', s_hostname );
  24. CAFFEDIR = s_dest_caffebuild;
  25. else
  26. fprintf('Unknown user %s and unknown default settings', getenv('USER') );
  27. end
  28. %% add paths which come with this repository
  29. %%
  30. % add main path
  31. b_recursive = false;
  32. b_overwrite = true;
  33. s_pathMain = fullfile(pwd);
  34. addPathSafely ( s_pathMain, b_recursive, b_overwrite )
  35. clear ( 's_pathMain' );
  36. %% 3rd party, untouched
  37. if ( isempty(CAFFEDIR) )
  38. fprintf('initWorkspaceCaffeTools-WARNING - no CAFFEDIR dir found on your machine. Code is available at http://caffe.berkeleyvision.org/installation.html \n');
  39. else
  40. b_recursive = true;
  41. b_overwrite = true;
  42. addPathSafely ( CAFFEDIR, b_recursive, b_overwrite );
  43. end
  44. %% clean up
  45. clear( 'CAFFEDIR' );
  46. end
  47. function addPathSafely ( s_path, b_recursive, b_overwrite )
  48. if ( ~isempty(strfind(path, [s_path , pathsep])) )
  49. if ( b_overwrite )
  50. if ( b_recursive )
  51. rmpath( genpath( s_path ) );
  52. else
  53. rmpath( s_path );
  54. end
  55. else
  56. fprintf('initWorkspaceCaffeTools - %s already in your path but overwriting de-activated.\n', s_path);
  57. return;
  58. end
  59. end
  60. if ( b_recursive )
  61. addpath( genpath( s_path ) );
  62. else
  63. addpath( s_path );
  64. end
  65. end