Commit 67302efa authored by Julien Michel's avatar Julien Michel

INIT

parents
PROJECT(Monteverdi2)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}
${CMAKE_MODULE_PATH})
#----------------------------------------------------------------------------
#Prevents conflicts with visual min/max function
#Add the OSSIMSTATIC flag to prevent from including dclspec(dllimport) from ossim
if(WIN32)
add_definitions(-DNOMINMAX -DOSSIM_STATIC)
endif(WIN32)
#----------------------------------------------------------------------------
# Orfeo ToolBox
find_package(OTB REQUIRED)
if(OTB_FOUND)
include(${OTB_USE_FILE})
else(OTB_FOUND)
message(FATAL_ERROR "OTB not found. Please set OTB_DIR")
endif(OTB_FOUND)
#----------------------------------------------------------------------------
# OpenGL (needed by Qt4)
find_package( OpenGL REQUIRED )
if (OPENGL_FOUND)
MESSAGE("OpenGL found")
include_directories(${OPENGL_INCLUDE_DIR})
else (OPENGL_FOUND)
MESSAGE("OpenGL missing")
endif (OPENGL_FOUND)
find_package(GLFW REQUIRED)
if(GLFW_FOUND)
MESSAGE("GLFW found")
include_directories(${GLFW_INCLUDE_DIR})
else(GLFW_FOUND)
MESSAGE("GLFW missing")
endif(GLFW_FOUND)
ADD_LIBRARY(OTBIce otbGPUTileLoader.cxx otbViewSettings.cxx otbGlView.cxx otbGlActor.cxx otbGlImageActor.cxx)
TARGET_LINK_LIBRARIES(OTBIce OTBIO ${OPENGL_LIBRARY})
ADD_EXECUTABLE(otbGPUTileLoaderTest otbGPUTileLoaderTest.cxx)
TARGET_LINK_LIBRARIES(otbGPUTileLoaderTest OTBIce ${GLFW_LIBRARY})
ADD_EXECUTABLE(otbIce otbIce.cxx)
TARGET_LINK_LIBRARIES(otbIce OTBIce ${GLFW_LIBRARY})
# Locate the glfw library
# This module defines the following variables:
# GLFW_LIBRARY, the name of the library;
# GLFW_INCLUDE_DIR, where to find glfw include files.
# GLFW_FOUND, true if both the GLFW_LIBRARY and GLFW_INCLUDE_DIR have been found.
#
# To help locate the library and include file, you could define an environment variable called
# GLFW_ROOT which points to the root of the glfw library installation. This is pretty useful
# on a Windows platform.
#
#
# Usage example to compile an "executable" target to the glfw library:
#
# FIND_PACKAGE (glfw REQUIRED)
# INCLUDE_DIRECTORIES (${GLFW_INCLUDE_DIR})
# ADD_EXECUTABLE (executable ${EXECUTABLE_SRCS})
# TARGET_LINK_LIBRARIES (executable ${GLFW_LIBRARY})
#
# TODO:
# Allow the user to select to link to a shared library or to a static library.
#Search for the include file...
FIND_PATH(GLFW_INCLUDE_DIR GL/glfw.h DOC "Path to GLFW include directory."
HINTS
$ENV{GLFW_ROOT}
PATH_SUFFIX include # For finding the include file under the root of the glfw expanded archive, typically on Windows.
PATHS
/usr/include/
/usr/local/include/
# By default headers are under GL subfolder
/usr/include/GL
/usr/local/include/GL
${GLFW_ROOT_DIR}/include/ # added by ptr
)
FIND_LIBRARY(GLFW_LIBRARY DOC "Absolute path to GLFW library."
NAMES glfw GLFW.lib
HINTS
$ENV{GLFW_ROOT}
PATH_SUFFIXES lib/win32 # For finding the library file under the root of the glfw expanded archive, typically on Windows.
PATHS
/usr/local/lib
/usr/lib
${GLFW_ROOT_DIR}/lib-msvc100/release # added by ptr
)
IF(GLFW_INCLUDE_DIR AND EXISTS "${GLFW_INCLUDE_DIR}/GL/glfw.h")
FILE(STRINGS "${GLFW_INCLUDE_DIR}/GL/glfw.h" glfw_version_str
REGEX "^#[\t ]*define[\t ]+GLFW_VERSION_(MAJOR|MINOR|REVISION)[\t ]+[0-9]+$")
UNSET(GLFW_VERSION_STRING)
FOREACH(VPART MAJOR MINOR REVISION)
FOREACH(VLINE ${glfw_version_str})
IF(VLINE MATCHES "^#[\t ]*define[\t ]+GLFW_VERSION_${VPART}")
STRING(REGEX REPLACE "^#[\t ]*define[\t ]+GLFW_VERSION_${VPART}[\t ]+([0-9]+)$" "\\1"
GLFW_VERSION_PART "${VLINE}")
IF(GLFW_VERSION_STRING)
SET(GLFW_VERSION_STRING "${GLFW_VERSION_STRING}.${GLFW_VERSION_PART}")
ELSE(GLFW_VERSION_STRING)
SET(GLFW_VERSION_STRING "${GLFW_VERSION_PART}")
ENDIF(GLFW_VERSION_STRING)
UNSET(GLFW_VERSION_PART)
ENDIF()
ENDFOREACH(VLINE)
ENDFOREACH(VPART)
ENDIF(GLFW_INCLUDE_DIR AND EXISTS "${GLFW_INCLUDE_DIR}/GL/glfw.h")
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW
REQUIRED_VARS GLFW_LIBRARY GLFW_INCLUDE_DIR
VERSION_VAR GLFW_VERSION_STRING)
\ No newline at end of file
This diff is collapsed.
#include "otbVectorImage.h"
#include "otbMultiChannelExtractROI.h"
#include "otbVectorRescaleIntensityImageFilter.h"
#include "otbImageFileReader.h"
#include "otbThreads.h"
#include <deque>
namespace otb
{
class Tile
{
public:
unsigned int m_Loaded;
unsigned int m_TileIdx;
unsigned int m_TextureId;
double m_ULX;
double m_ULY;
double m_LRX;
double m_LRY;
unsigned int m_Resolution;
unsigned int m_RedIdx;
unsigned int m_GreenIdx;
unsigned int m_BlueIdx;
};
class GPUTileLoader
: public itk::LightObject
{
public:
typedef GPUTileLoader Self;
typedef itk::LightObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
typedef otb::VectorImage<float> VectorImageType;
typedef otb::ImageFileReader<VectorImageType> ReaderType;
typedef otb::MultiChannelExtractROI<float,float> ExtractROIFilterType;
typedef otb::VectorRescaleIntensityImageFilter<VectorImageType,VectorImageType> RescaleFilterType;
typedef std::deque<Tile> TileFIFOType;
typedef itk::MultiThreader ThreaderType;
void Initialize(std::string filename);
void UpdateResolution(unsigned int resolution = 1);
void UpdateViewport(double ulx, double uly, double lrx, double lry);
void UpdateGeometry();
void UpdateColor(unsigned int red = 1, unsigned int green = 2, unsigned int blue = 3);
void Render();
void Update();
void Start();
void Stop();
protected:
GPUTileLoader();
~GPUTileLoader();
private:
void ProcessingLoop();
void LoadTile(Tile& tile);
void UnloadTile(Tile& tile);
bool TileAlreadyLoaded(const Tile& tile);
void ClearLoadedTiles();
void CleanLoadedTiles();
static ITK_THREAD_RETURN_TYPE StaticThreadedRun(void * t);
void ThreadedRun();
static int Sleep(unsigned int microsec = 500);
bool m_Running;
std::string m_FileName;
ReaderType::Pointer m_ImageFileReader;
VectorImageType::SizeType m_ImageSize;
// Tiles to process
TileFIFOType m_LoadingQueue;
// Tiles cache
TileFIFOType m_LoadedTiles;
VectorImageType::SizeType m_Size;
unsigned int m_Resolution;
unsigned int m_RedIdx;
unsigned int m_GreenIdx;
unsigned int m_BlueIdx;
// The viewport
double m_ULX;
double m_ULY;
double m_LRX;
double m_LRY;
unsigned int m_TileSize;
double m_MinRed;
double m_MaxRed;
double m_MinBlue;
double m_MaxBlue;
double m_MinGreen;
double m_MaxGreen;
ThreaderType::Pointer m_Threader;
int m_ThreadId;
};
}
#include "otbGPUTileLoader.h"
#include <GLFW/glfw3.h>
class ViewSettings
{
public:
static ViewSettings & GetInstance()
{
static ViewSettings instance;
return instance;
}
static void static_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
GetInstance().key_callback(window, key, scancode, action, mods);
}
static void static_framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
GetInstance().framebuffer_size_callback(window, width, height);
}
static void static_mouse_button_callback(GLFWwindow * window, int button, int action, int mode)
{
GetInstance().mouse_button_callback(window,button,action,mode);
}
static void static_cursor_pos_callback(GLFWwindow * window, double xpos, double ypos)
{
GetInstance().cursor_pos_callback(window, xpos, ypos);
}
static void static_scroll_callback(GLFWwindow * window, double xoffset, double yoffset)
{
GetInstance().scroll_callback(window,xoffset,yoffset);
}
void scroll_callback(GLFWwindow * window, double xoffset, double yoffset)
{
if(yoffset>0)
{
Zoom(1/1.1);
}
else if(yoffset < 0)
{
Zoom(1.1);
}
}
void mouse_button_callback(GLFWwindow * window, int button, int action, int mode)
{
if(button == GLFW_MOUSE_BUTTON_1)
{
if(action == GLFW_PRESS)
{
m_Drag = true;
glfwGetCursorPos(window,&m_StartDragX,&m_StartDragY);
}
else if(action == GLFW_RELEASE)
{
m_Drag = false;
m_ULX-=m_DeltaDragX;
m_ULY+=m_DeltaDragY;
m_LRX-=m_DeltaDragX;
m_LRY+=m_DeltaDragY;
m_StartDragX = 0;
m_StartDragY = 0;
m_DeltaDragX = 0;
m_DeltaDragY = 0;
}
}
}
void cursor_pos_callback(GLFWwindow * window, double xpos, double ypos)
{
double posx, posy;
glfwGetCursorPos(window,&posx,&posy);
if(m_Drag)
{
m_DeltaDragX = posx - m_StartDragX;
m_DeltaDragY = posy - m_StartDragY;
}
m_ZoomCenterX = posx;
m_ZoomCenterY = posy;
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if(m_KeyEventLock)
{
return;
}
m_KeyEventLock = true;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
double deltax = (m_LRX-m_ULX)/4;
double deltay = (m_LRY-m_ULY)/4;
if(key == GLFW_KEY_LEFT)
{
m_ULX-=deltax;
m_LRX-=deltax;
}
if(key == GLFW_KEY_RIGHT)
{
m_ULX+=deltax;
m_LRX+=deltax;
}
if(key == GLFW_KEY_UP)
{
m_ULY+=deltay;
m_LRY+=deltay;
}
if(key == GLFW_KEY_DOWN)
{
m_ULY-=deltay;
m_LRY-=deltay;
}
if(key == GLFW_KEY_KP_ADD )
{
m_ZoomCenterX = (m_ULX+m_LRX)*0.5;
m_ZoomCenterY = (m_ULY+m_LRY)*0.5;
Zoom(1/1.1);
}
if(key == GLFW_KEY_KP_SUBTRACT)
{
m_ZoomCenterX = (m_ULX+m_LRX)*0.5;
m_ZoomCenterY = (m_ULY+m_LRY)*0.5;
Zoom(1.1);
}
m_KeyEventLock = false;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
m_LRX = m_ULX + width;
m_LRY = m_ULY + height;
}
double m_ULX;
double m_ULY;
double m_LRX;
double m_LRY;
double m_Scale;
bool m_Drag;
double m_StartDragX;
double m_StartDragY;
double m_DeltaDragX;
double m_DeltaDragY;
double m_ZoomCenterX;
double m_ZoomCenterY;
private:
bool m_KeyEventLock;
ViewSettings()
: m_ULX(0),
m_ULY(0),
m_LRX(0),
m_LRY(0),
m_Scale(1.),
m_Drag(false),
m_StartDragX(0),
m_StartDragY(0),
m_DeltaDragX(0),
m_DeltaDragY(0)
{}
ViewSettings(ViewSettings const&);
void operator=(ViewSettings const&);
void Zoom(double scale)
{
double w = m_LRX-m_ULX;
double h = m_LRY-m_ULY;
w*=scale;
h*=scale;
m_ULX = m_ZoomCenterX-w/2;
m_LRX = m_ZoomCenterX+w/2;
m_ULY = m_ZoomCenterY-h/2;
m_LRY = m_ZoomCenterY+h/2;
m_Scale = scale;
}
};
void error_callback(int error, const char* description)
{
std::cerr<<description<<std::endl;
}
int main(int argc, char * argv[])
{
if(!glfwInit())
{
std::cerr<<"Could not initalize glfw!"<<std::endl;
return EXIT_FAILURE;
}
glfwSetErrorCallback(error_callback);
// Open a window and create its OpenGL context
GLFWwindow* window;
window = glfwCreateWindow(640, 480,"I see", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, &ViewSettings::static_key_callback);
glfwSetFramebufferSizeCallback(window,&ViewSettings::static_framebuffer_size_callback);
glfwSetMouseButtonCallback(window,&ViewSettings::static_mouse_button_callback);
glfwSetCursorPosCallback(window,&ViewSettings::static_cursor_pos_callback);
glfwSetScrollCallback(window,&ViewSettings::static_scroll_callback);
ViewSettings & settings = ViewSettings::GetInstance();
settings.m_LRX = 640;
settings.m_LRY = 480;
otb::GPUTileLoader::Pointer tileLoader = otb::GPUTileLoader::New();
tileLoader->Initialize(argv[1]);
tileLoader->Update();
glClearColor(0.5,0.5,0.5,1.0);
glShadeModel(GL_FLAT);
while (!glfwWindowShouldClose(window))
{
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, (GLint)width, (GLint)height);
//std::cout<<"Settings: "<<settings.m_ULX<<" "<<settings.m_ULY<<" "<<settings.m_LRX<<" "<<settings.m_LRY<<std::endl;
if(!settings.m_Drag)
{
tileLoader->UpdateViewport(settings.m_ULX,settings.m_ULY,settings.m_LRX,settings.m_LRY);
tileLoader->Update();
}
// Clear back-buffer(s) before rendering sub-components.
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(settings.m_ULX, settings.m_LRX, settings.m_ULY, settings.m_LRY, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
if(settings.m_Drag)
{
glTranslatef(settings.m_DeltaDragX,-settings.m_DeltaDragY,0);
}
glScalef(settings.m_Scale,settings.m_Scale,1);
// // Render current loader tiles
tileLoader->Render();
glPopMatrix();
// Swap buffers
glfwSwapBuffers(window);
glfwWaitEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return EXIT_SUCCESS;
}
#include "otbGlActor.h"
namespace otb
{
GlActor::GlActor()
: m_Settings(ViewSettings::New()),
m_Visible(false)
{}
GlActor::~GlActor()
{}
}
#ifndef otb_GlActor_h
#define otb_GlActor_h
#include "itkObject.h"
#include "otbViewSettings.h"
namespace otb
{
class GlActor
: public itk::Object
{
public:
typedef GlActor Self;
typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkSetObjectMacro(Settings,ViewSettings);
itkGetObjectMacro(Settings,ViewSettings);
itkGetConstObjectMacro(Settings,ViewSettings);
itkSetMacro(Visible,bool);
itkGetMacro(Visible,bool);
itkBooleanMacro(Visible);
// Retrieve the full extent of the actor
virtual void GetExtent(double & ulx, double & uly, double & lrx, double & lry) const = 0;
// Update internal actor state with respect to ViewSettings
virtual void ProcessViewSettings() = 0;
// Heavy load/unload operations of data
virtual void UpdateData() = 0;
// Gl rendering of current state
virtual void Render() = 0;
protected:
GlActor();
virtual ~GlActor();
private:
// prevent implementation
GlActor(const Self&);
void operator=(const Self&);
ViewSettings::Pointer m_Settings;
// Visibility flag
bool m_Visible;
}; // End class GlActor
} // End namespace otb
#endif
This diff is collapsed.
#ifndef otb_GlImageActor_h
#define otb_GlImageActor_h
#include "otbGlActor.h"
#include "otbVectorImage.h"
#include "otbMultiChannelExtractROI.h"
#include "otbVectorRescaleIntensityImageFilter.h"
#include "otbImageFileReader.h"
#include "otbGenericRSTransform.h"
namespace otb
{
class GlImageActor
: public GlActor
{
public:
typedef GlImageActor Self;
typedef GlActor Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
typedef VectorImage<float> VectorImageType;
typedef VectorImageType::ImageKeywordlistType ImageKeywordlistType;
typedef VectorImageType::SizeType SizeType;
typedef VectorImageType::IndexType IndexType;
typedef VectorImageType::RegionType RegionType;
typedef VectorImageType::SpacingType SpacingType;
typedef VectorImageType::PointType PointType;
// Initialize with a new image
void Initialize(const std::string & filename);
// Retrieve the full extent of the actor
virtual void GetExtent(double & ulx, double & uly, double & lrx, double & lry) const;
// Update internal actor state with respect to ViewSettings
virtual void ProcessViewSettings();
// Heavy load/unload operations of data
virtual void UpdateData();
// Gl rendering of current state
virtual void Render();
const PointType & GetOrigin() const;
const SpacingType & GetSpacing() const;
std::string GetWkt() const;
ImageKeywordlistType GetKwl() const;
protected:
GlImageActor();
virtual ~GlImageActor();
typedef ImageFileReader<VectorImageType> ReaderType;
typedef MultiChannelExtractROI<float,float> ExtractROIFilterType;
typedef VectorRescaleIntensityImageFilter<VectorImageType,VectorImageType> RescaleFilterType;
typedef otb::GenericRSTransform<> RSTransformType;
// Internal class to hold tiles
class Tile
{
public:
Tile()
: m_Loaded(false),
m_ImageRegion(),
m_UL(),
m_UR(),
m_LL(),
m_LR(),
m_Resolution(1),
m_RedIdx(1),
m_GreenIdx(2),
m_BlueIdx(3)
{
m_UL.Fill(0);
m_UR.Fill(0);
m_LL.Fill(0);
m_LR.Fill(0);
}
bool m_Loaded;
unsigned int m_TextureId;
RegionType m_ImageRegion;
PointType m_UL;
PointType m_UR;
PointType m_LL;
PointType m_LR;
unsigned int m_Resolution;
unsigned int m_RedIdx;
unsigned int m_GreenIdx;
unsigned int m_BlueIdx;
};
typedef std::vector<Tile> TileVectorType;
private:
// prevent implementation
GlImageActor(const Self&);
void operator=(const Self&);
// Load tile to GPU
void LoadTile(Tile& tile);