Skip to content

Commit

Permalink
provide getGDALEnvironment to wake up GDAL on-demand for things that …
Browse files Browse the repository at this point in the history
…need it while still preventing it from being tore down while others might still depend on it
  • Loading branch information
hobu committed Oct 18, 2012
1 parent b875f82 commit 2e3cb7f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion include/pdal/GlobalEnvironment.hpp
Expand Up @@ -65,6 +65,8 @@ class PDAL_DLL GlobalEnvironment

// forwarded function
boost::random::mt19937* getRNG();

void getGDALEnvironment();

private:
GlobalEnvironment();
Expand All @@ -73,9 +75,10 @@ class PDAL_DLL GlobalEnvironment
static void init();

typedef std::map<boost::thread::id, ThreadEnvironment*> thread_map;
thread_map m_threadMap;

thread_map m_threadMap;
plang::PythonEnvironment* m_pythonEnvironment;
bool m_bIsGDALInitialized;

GlobalEnvironment(const GlobalEnvironment&); // nope
GlobalEnvironment& operator=(const GlobalEnvironment&); // nope
Expand Down
23 changes: 17 additions & 6 deletions src/GlobalEnvironment.cpp
Expand Up @@ -98,20 +98,27 @@ void GlobalEnvironment::init()
//

GlobalEnvironment::GlobalEnvironment()
#ifdef PDAL_HAVE_PYTHON
: m_pythonEnvironment(0)
#endif
, m_bIsGDALInitialized(false)
{
// this should be the not-a-thread thread environment
(void) createThreadEnvironment(boost::thread::id());

#ifdef PDAL_HAVE_GDAL
(void) GDALAllRegister();
#endif


return;
}

void GlobalEnvironment::getGDALEnvironment()
{
#ifdef PDAL_HAVE_GDAL
if (!m_bIsGDALInitialized)
{
(void) GDALAllRegister();
m_bIsGDALInitialized = true;
}
#endif
}

GlobalEnvironment::~GlobalEnvironment()
{
Expand All @@ -130,7 +137,11 @@ GlobalEnvironment::~GlobalEnvironment()
#endif

#ifdef PDAL_HAVE_GDAL
(void) GDALDestroyDriverManager();
if (m_bIsGDALInitialized)
{
(void) GDALDestroyDriverManager();
m_bIsGDALInitialized = false;
}
#endif

return;
Expand Down
4 changes: 3 additions & 1 deletion src/filters/Colorization.cpp
Expand Up @@ -39,6 +39,7 @@
#include <algorithm>

#include <pdal/PointBuffer.hpp>
#include <pdal/GlobalEnvironment.hpp>

#ifdef PDAL_HAVE_GDAL
#include <gdal.h>
Expand Down Expand Up @@ -93,7 +94,8 @@ void Colorization::initialize()
collectOptions();

#ifdef PDAL_HAVE_GDAL


pdal::GlobalEnvironment::get().getGDALEnvironment();
m_gdal_debug = new pdal::gdal::Debug(isDebug(), log());
m_forward_transform.assign(0.0);
m_inverse_transform.assign(0.0);
Expand Down

0 comments on commit 2e3cb7f

Please sign in to comment.