Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
otb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
273
Issues
273
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Main Repositories
otb
Commits
4afaa793
Commit
4afaa793
authored
Jul 07, 2015
by
Guillaume Pasero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: faster application loading
parent
b5e6d7f5
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
268 additions
and
28 deletions
+268
-28
CMake/otbcli.bat.in
CMake/otbcli.bat.in
+1
-1
CMake/otbcli.sh.in
CMake/otbcli.sh.in
+2
-2
CMake/otbgui.bat.in
CMake/otbgui.bat.in
+1
-1
CMake/otbgui.sh.in
CMake/otbgui.sh.in
+2
-2
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationFactory.h
.../ApplicationEngine/include/otbWrapperApplicationFactory.h
+4
-3
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationFactoryBase.h
...licationEngine/include/otbWrapperApplicationFactoryBase.h
+58
-0
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationRegistry.h
...ApplicationEngine/include/otbWrapperApplicationRegistry.h
+7
-1
Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt
Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt
+1
-0
Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationFactoryBase.cxx
...pplicationEngine/src/otbWrapperApplicationFactoryBase.cxx
+43
-0
Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationRegistry.cxx
...s/ApplicationEngine/src/otbWrapperApplicationRegistry.cxx
+149
-18
No files found.
CMake/otbcli.bat.in
View file @
4afaa793
...
...
@@ -17,7 +17,7 @@ if exist %CURRENT_SCRIPT_DIR%otbApplicationLauncherCommandLine.exe (
setlocal
:: works for install tree
if exist %CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@ (
set
ITK_AUTOLOAD_PATH=%CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@;%ITK_AUTOLOAD
_PATH%
set
OTB_APPLICATION_PATH=%CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@;%OTB_APPLICATION
_PATH%
)
:: start the application
...
...
CMake/otbcli.sh.in
View file @
4afaa793
...
...
@@ -19,11 +19,11 @@ fi
# works for install tree
if
[
-d
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@
]
then
ITK_AUTOLOAD_PATH
=
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@:
$ITK_AUTOLOAD
_PATH
OTB_APPLICATION_PATH
=
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@:
$OTB_APPLICATION
_PATH
fi
# export it to make it available to otbApplicationLauncherCommandLine environment
export
ITK_AUTOLOAD
_PATH
export
OTB_APPLICATION
_PATH
# start the application
$OTB_CLI_LAUNCHER
"
$@
"
CMake/otbgui.bat.in
View file @
4afaa793
...
...
@@ -17,7 +17,7 @@ if exist %CURRENT_SCRIPT_DIR%otbApplicationLauncherQt.exe (
setlocal
:: works for install tree
if exist %CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@ (
set
ITK_AUTOLOAD_PATH=%CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@;%ITK_AUTOLOAD
_PATH%
set
OTB_APPLICATION_PATH=%CURRENT_SCRIPT_DIR%../@OTB_INSTALL_APP_DIR@;%OTB_APPLICATION
_PATH%
)
set LC_NUMERIC=C
...
...
CMake/otbgui.sh.in
View file @
4afaa793
...
...
@@ -19,11 +19,11 @@ fi
# use the default install tree path for applications
if
[
-d
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@
]
then
ITK_AUTOLOAD_PATH
=
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@:
$ITK_AUTOLOAD
_PATH
OTB_APPLICATION_PATH
=
$CURRENT_SCRIPT_DIR
/../@OTB_INSTALL_APP_DIR@:
$OTB_APPLICATION
_PATH
fi
# export it to make it available to otbApplicationLauncherCommandLine environment
export
ITK_AUTOLOAD
_PATH
export
OTB_APPLICATION
_PATH
# avoid numerical issues caused by locale
export
LC_NUMERIC
=
C
...
...
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationFactory.h
View file @
4afaa793
...
...
@@ -18,6 +18,7 @@
#ifndef __otbWrapperApplicationFactory_h
#define __otbWrapperApplicationFactory_h
#include "otbWrapperApplicationFactoryBase.h"
#include "itkVersion.h"
namespace
otb
...
...
@@ -26,12 +27,12 @@ namespace Wrapper
{
template
<
class
TApplication
>
class
ITK_ABI_EXPORT
ApplicationFactory
:
public
itk
::
Object
FactoryBase
class
ITK_ABI_EXPORT
ApplicationFactory
:
public
Application
FactoryBase
{
public:
/** Standard class typedefs. */
typedef
ApplicationFactory
Self
;
typedef
itk
::
Object
FactoryBase
Superclass
;
typedef
Application
FactoryBase
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
...
...
@@ -50,7 +51,7 @@ public:
itkFactorylessNewMacro
(
Self
);
/** Run-time type information (and related methods). */
itkTypeMacro
(
ApplicationFactory
,
itk
::
Object
FactoryBase
);
itkTypeMacro
(
ApplicationFactory
,
Application
FactoryBase
);
void
SetClassName
(
const
char
*
name
)
{
...
...
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationFactoryBase.h
0 → 100644
View file @
4afaa793
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbWrapperApplicationFactoryBase_h
#define __otbWrapperApplicationFactoryBase_h
#include "itkObjectFactoryBase.h"
#include "otbWrapperApplication.h"
namespace
otb
{
namespace
Wrapper
{
class
ITK_ABI_EXPORT
ApplicationFactoryBase
:
public
itk
::
ObjectFactoryBase
{
public:
/** Standard class typedefs. */
typedef
ApplicationFactoryBase
Self
;
typedef
itk
::
ObjectFactoryBase
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Run-time type information (and related methods). */
itkTypeMacro
(
ApplicationFactoryBase
,
itk
::
ObjectFactoryBase
);
/** Create an application using the CreateObject() method of the current factory */
Application
::
Pointer
CreateApplication
(
const
char
*
name
);
protected:
ApplicationFactoryBase
(){}
virtual
~
ApplicationFactoryBase
(){}
private:
ApplicationFactoryBase
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
};
}
// end namespace Wrapper
}
//end namespace otb
#endif
Modules/Wrappers/ApplicationEngine/include/otbWrapperApplicationRegistry.h
View file @
4afaa793
...
...
@@ -39,7 +39,7 @@ class ITK_ABI_EXPORT ApplicationRegistry : public itk::Object
{
public:
/** Standard class typedefs. */
typedef
ApplicationRegistry
Self
;
typedef
ApplicationRegistry
Self
;
typedef
itk
::
Object
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
...
...
@@ -64,6 +64,10 @@ public:
/** Create the specified Application */
static
Application
::
Pointer
CreateApplication
(
const
std
::
string
&
applicationName
);
/** Create the specified Application (faster)
* method using dynamic library name to load the right module */
static
Application
::
Pointer
CreateApplicationFaster
(
const
std
::
string
&
applicationName
);
protected:
ApplicationRegistry
();
...
...
@@ -72,6 +76,8 @@ protected:
private:
ApplicationRegistry
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
static
void
RefreshApplicationFactories
();
};
...
...
Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt
View file @
4afaa793
...
...
@@ -26,6 +26,7 @@ set(OTBApplicationEngine_SRC
otbWrapperApplication.cxx
otbWrapperChoiceParameter.cxx
otbWrapperApplicationRegistry.cxx
otbWrapperApplicationFactoryBase.cxx
)
add_library
(
OTBApplicationEngine
${
OTBApplicationEngine_SRC
}
)
...
...
Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationFactoryBase.cxx
0 → 100644
View file @
4afaa793
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbWrapperApplicationFactoryBase.h"
namespace
otb
{
namespace
Wrapper
{
Application
::
Pointer
ApplicationFactoryBase
::
CreateApplication
(
const
char
*
name
)
{
Application
::
Pointer
appli
;
LightObject
::
Pointer
obj
=
this
->
CreateObject
(
name
);
if
(
obj
.
IsNotNull
())
{
Application
*
app
=
dynamic_cast
<
Application
*>
(
obj
.
GetPointer
());
if
(
app
)
{
appli
=
app
;
}
}
return
appli
;
}
}
}
Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationRegistry.cxx
View file @
4afaa793
...
...
@@ -16,8 +16,10 @@
=========================================================================*/
#include "otbWrapperApplicationRegistry.h"
#include "otbWrapperApplicationFactoryBase.h"
#include "otbMacro.h"
#include "itksys/SystemTools.hxx"
#include "itkDynamicLoader.h"
#include <iterator>
namespace
otb
...
...
@@ -37,23 +39,20 @@ void
ApplicationRegistry
::
SetApplicationPath
(
std
::
string
newpath
)
{
std
::
ostringstream
putEnvPath
;
putEnvPath
<<
"
ITK_AUTOLOAD
_PATH="
<<
newpath
;
putEnvPath
<<
"
OTB_APPLICATION
_PATH="
<<
newpath
;
// do NOT use putenv() directly, since the string memory must be managed carefully
itksys
::
SystemTools
::
PutEnv
(
putEnvPath
.
str
().
c_str
());
// Reload factories to take into account new path
itk
::
ObjectFactoryBase
::
ReHash
();
}
void
ApplicationRegistry
::
AddApplicationPath
(
std
::
string
newpath
)
{
std
::
ostringstream
putEnvPath
;
putEnvPath
<<
"
ITK_AUTOLOAD
_PATH="
;
putEnvPath
<<
"
OTB_APPLICATION
_PATH="
;
// Can be NULL if the env var is not set
const
char
*
currentEnv
=
itksys
::
SystemTools
::
GetEnv
(
"
ITK_AUTOLOAD
_PATH"
);
const
char
*
currentEnv
=
itksys
::
SystemTools
::
GetEnv
(
"
OTB_APPLICATION
_PATH"
);
#if defined(WIN32)
const
char
pathSeparator
=
';'
;
...
...
@@ -70,18 +69,6 @@ ApplicationRegistry::AddApplicationPath(std::string newpath)
// do NOT use putenv() directly, since the string memory must be managed carefully
itksys
::
SystemTools
::
PutEnv
(
putEnvPath
.
str
().
c_str
());
// Reload factories to take into account new path
itk
::
ObjectFactoryBase
::
ReHash
();
std
::
ostringstream
resetEnvPath
;
resetEnvPath
<<
"ITK_AUTOLOAD_PATH="
;
if
(
currentEnv
)
{
resetEnvPath
<<
currentEnv
;
}
itksys
::
SystemTools
::
PutEnv
(
resetEnvPath
.
str
().
c_str
());
}
Application
::
Pointer
...
...
@@ -89,6 +76,16 @@ ApplicationRegistry::CreateApplication(const std::string& name)
{
ApplicationPointer
appli
;
// Fast search
appli
=
ApplicationRegistry
::
CreateApplicationFaster
(
name
);
if
(
appli
.
IsNotNull
())
{
return
appli
;
}
// Classic search
ApplicationRegistry
::
RefreshApplicationFactories
();
LightObject
::
Pointer
possibleApp
=
itk
::
ObjectFactoryBase
::
CreateInstance
(
name
.
c_str
());
if
(
possibleApp
.
IsNotNull
())
...
...
@@ -109,11 +106,102 @@ ApplicationRegistry::CreateApplication(const std::string& name)
return
appli
;
}
typedef
itk
::
ObjectFactoryBase
*
(
*
ITK_LOAD_FUNCTION
)();
Application
::
Pointer
ApplicationRegistry
::
CreateApplicationFaster
(
const
std
::
string
&
name
)
{
ApplicationPointer
appli
;
std
::
string
appExtension
=
itksys
::
DynamicLoader
::
LibExtension
();
#ifdef __APPLE__
appExtension
=
".dylib"
;
#endif
std
::
ostringstream
appLibName
;
appLibName
<<
"otbapp_"
<<
name
<<
appExtension
;
#if defined(WIN32)
const
char
pathSeparator
=
';'
;
#else
const
char
pathSeparator
=
':'
;
#endif
#ifdef _WIN32
const
char
sep
=
'\\'
;
#else
const
char
sep
=
'/'
;
#endif
const
char
*
otbAppPath
=
itksys
::
SystemTools
::
GetEnv
(
"OTB_APPLICATION_PATH"
);
const
char
*
itkLoadPath
=
itksys
::
SystemTools
::
GetEnv
(
"ITK_AUTOLOAD_PATH"
);
std
::
ostringstream
currentPath
;
if
(
otbAppPath
)
{
currentPath
<<
otbAppPath
<<
pathSeparator
;
}
if
(
itkLoadPath
)
{
currentPath
<<
itkLoadPath
;
}
std
::
vector
<
itksys
::
String
>
pathList
=
itksys
::
SystemTools
::
SplitString
(
currentPath
.
str
().
c_str
(),
pathSeparator
,
false
);
for
(
unsigned
int
i
=
0
;
i
<
pathList
.
size
()
;
++
i
)
{
std
::
string
possiblePath
=
pathList
[
i
];
if
(
!
possiblePath
.
empty
()
&&
possiblePath
[
possiblePath
.
size
()
-
1
]
!=
sep
)
{
possiblePath
+=
sep
;
}
possiblePath
+=
appLibName
.
str
();
if
(
itksys
::
SystemTools
::
FileExists
(
possiblePath
.
c_str
(),
true
))
{
itk
::
LibHandle
lib
=
itk
::
DynamicLoader
::
OpenLibrary
(
possiblePath
.
c_str
()
);
if
(
lib
)
{
/**
* Look for the symbol itkLoad in the library
*/
ITK_LOAD_FUNCTION
loadfunction
=
(
ITK_LOAD_FUNCTION
)
itk
::
DynamicLoader
::
GetSymbolAddress
(
lib
,
"itkLoad"
);
/**
* if the symbol is found call it to create the factory
* from the library
*/
if
(
loadfunction
)
{
itk
::
ObjectFactoryBase
*
newfactory
=
(
*
loadfunction
)(
);
if
(
dynamic_cast
<
ApplicationFactoryBase
*>
(
newfactory
))
{
ApplicationFactoryBase
*
appFactory
=
dynamic_cast
<
ApplicationFactoryBase
*>
(
newfactory
);
appli
=
appFactory
->
CreateApplication
(
name
.
c_str
());
appli
->
Init
();
break
;
}
}
else
{
// In the past, some platforms crashed on the call
// DynamicLoader::CloseLibrary(lib) if the lib has symbols
// that the current executable is using.
itk
::
DynamicLoader
::
CloseLibrary
(
lib
);
}
}
}
}
return
appli
;
}
std
::
vector
<
std
::
string
>
ApplicationRegistry
::
GetAvailableApplications
()
{
ApplicationPointer
appli
;
ApplicationRegistry
::
RefreshApplicationFactories
();
std
::
list
<
ApplicationPointer
>
possibleApp
;
std
::
list
<
LightObject
::
Pointer
>
allobjects
=
itk
::
ObjectFactoryBase
::
CreateAllInstance
(
"otbWrapperApplication"
);
...
...
@@ -147,6 +235,49 @@ ApplicationRegistry::GetAvailableApplications()
return
appVec
;
}
void
ApplicationRegistry
::
RefreshApplicationFactories
()
{
std
::
ostringstream
putEnvPath
;
putEnvPath
<<
"ITK_AUTOLOAD_PATH="
;
// Can be NULL if the env var is not set
const
char
*
currentEnv
=
itksys
::
SystemTools
::
GetEnv
(
"ITK_AUTOLOAD_PATH"
);
// OTB specific application path
const
char
*
otbApplicationPath
=
itksys
::
SystemTools
::
GetEnv
(
"OTB_APPLICATION_PATH"
);
#if defined(WIN32)
const
char
pathSeparator
=
';'
;
#else
const
char
pathSeparator
=
':'
;
#endif
if
(
otbApplicationPath
)
{
putEnvPath
<<
otbApplicationPath
<<
pathSeparator
;
}
if
(
currentEnv
)
{
putEnvPath
<<
currentEnv
;
}
// do NOT use putenv() directly, since the string memory must be managed carefully
itksys
::
SystemTools
::
PutEnv
(
putEnvPath
.
str
().
c_str
());
// Reload factories to take into account new path
itk
::
ObjectFactoryBase
::
ReHash
();
std
::
ostringstream
resetEnvPath
;
resetEnvPath
<<
"ITK_AUTOLOAD_PATH="
;
if
(
currentEnv
)
{
resetEnvPath
<<
currentEnv
;
}
itksys
::
SystemTools
::
PutEnv
(
resetEnvPath
.
str
().
c_str
());
}
}
// end namespace Wrapper
}
//end namespace otb
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment