From 9c6275fc0991ecddf8d835ea93a6a703fe9d90eb Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 10:32:38 +0200 Subject: [PATCH 01/73] BUG: #1930: replace builtin gl_TexCoord by input variable --- .../Ice/src/otbStandardShader.cxx | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbStandardShader.cxx b/Modules/Visualization/Ice/src/otbStandardShader.cxx index 77e8e3a1bc..afc590c270 100644 --- a/Modules/Visualization/Ice/src/otbStandardShader.cxx +++ b/Modules/Visualization/Ice/src/otbStandardShader.cxx @@ -86,8 +86,9 @@ std::string StandardShader::GetSource() const "uniform float shader_chessboard_size;\n" \ "uniform float shader_slider_pos;\n" \ "uniform int shader_vertical_slider_flag;\n" \ + "in vec2 tex_coord;\n" \ "void main (void) {\n" \ - "vec4 p = texture2D(src, gl_TexCoord[0].xy);\n" \ + "vec4 p = texture(src, tex_coord);\n" \ "vec4 colors = pow( clamp( ( p+shader_b ) * shader_a, 0.0, 1.0 ), shader_gamma );\n" \ "gl_FragColor = colors;\n" \ "gl_FragColor[3] = clamp(shader_alpha,0.0,1.0);\n" \ @@ -277,9 +278,9 @@ std::string StandardShader::GetSource() const "if(dist < shader_radius)\n" \ "{\n" \ "vec2 size = vec2(textureSize(src,0));\n" \ - "vec2 dx = vec2(gl_TexCoord[0].xy);\n" \ + "vec2 dx = tex_coord;\n" \ "dx[0]+=1.0/size[0];\n" \ - "vec2 dy = vec2(gl_TexCoord[0].xy);\n" \ + "vec2 dy = tex_coord;\n" \ "dy[1]+=1.0/size[1];\n" \ "vec4 pdx = texture2D(src, dx);\n" \ "vec4 pdy = texture2D(src, dy);\n" \ @@ -314,31 +315,33 @@ void StandardShader::SetupShader() double gamma = m_ImageSettings->GetGamma(); - GLint shader_a = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_a"); + int program = otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"); + + GLint shader_a = glGetUniformLocation(program, "shader_a"); glUniform4f(shader_a,scr,scg,scb,1.); - GLint shader_b = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_b"); + GLint shader_b = glGetUniformLocation(program, "shader_b"); glUniform4f(shader_b,shr,shg,shb,0); - GLint shader_use_no_data = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_use_no_data"); + GLint shader_use_no_data = glGetUniformLocation(program, "shader_use_no_data"); glUniform1i(shader_use_no_data, m_ImageSettings->GetUseNoData() ); - GLint shader_no_data = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_no_data"); + GLint shader_no_data = glGetUniformLocation(program, "shader_no_data"); glUniform1f( shader_no_data, m_ImageSettings->GetNoData() ); - GLint shader_gamma = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_gamma"); + GLint shader_gamma = glGetUniformLocation(program, "shader_gamma"); glUniform4f( shader_gamma, gamma, gamma, gamma, gamma ); - GLint shader_alpha = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_alpha"); + GLint shader_alpha = glGetUniformLocation(program, "shader_alpha"); glUniform1f( shader_alpha, m_ImageSettings->GetAlpha() ); - GLint shader_radius = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_radius"); + GLint shader_radius = glGetUniformLocation(program, "shader_radius"); glUniform1f(shader_radius,m_Radius); - GLint shader_center = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_center"); + GLint shader_center = glGetUniformLocation(program, "shader_center"); glUniform2f(shader_center,m_Center[0],m_Center[1]); - GLint shader_type = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_type"); + GLint shader_type = glGetUniformLocation(program, "shader_type"); glUniform1i(shader_type,m_ShaderType); // std::cout @@ -347,7 +350,7 @@ void StandardShader::SetupShader() // << " b: " << m_ImageSettings->GetCurrentBlue() // << std::endl; - GLint shader_current = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_current"); + GLint shader_current = glGetUniformLocation(program, "shader_current"); glUniform3f( shader_current, m_ImageSettings->GetCurrentRed(), @@ -355,21 +358,20 @@ void StandardShader::SetupShader() m_ImageSettings->GetCurrentBlue() ); - GLint shader_localc_range = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_localc_range"); + GLint shader_localc_range = glGetUniformLocation(program, "shader_localc_range"); glUniform1f(shader_localc_range,m_LocalContrastRange); - GLint shader_spectral_angle_range = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_spectral_angle_range"); + GLint shader_spectral_angle_range = glGetUniformLocation(program, "shader_spectral_angle_range"); glUniform1f(shader_spectral_angle_range,m_SpectralAngleRange); - GLint shader_chessboard_size = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_chessboard_size"); + GLint shader_chessboard_size = glGetUniformLocation(program, "shader_chessboard_size"); glUniform1f(shader_chessboard_size,m_ChessboardSize); - GLint shader_slider_pos = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_slider_pos"); + GLint shader_slider_pos = glGetUniformLocation(program, "shader_slider_pos"); glUniform1f(shader_slider_pos,m_SliderPosition); - GLint shader_vertical_slider_flag = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_vertical_slider_flag"); + GLint shader_vertical_slider_flag = glGetUniformLocation(program, "shader_vertical_slider_flag"); glUniform1i(shader_vertical_slider_flag,m_VerticalSlider); - } -- GitLab From 5ba9732a301a01f08501c1cd02597ac657f8146a Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 10:51:01 +0200 Subject: [PATCH 02/73] REFAC: #1930: move FragmentShader to Shader --- .../Ice/include/{otbFragmentShader.h => otbShader.h} | 0 .../include/{otbFragmentShaderRegistry.h => otbShaderRegistry.h} | 0 .../Ice/src/{otbFragmentShader.cxx => otbShader.cxx} | 0 .../src/{otbFragmentShaderRegistry.cxx => otbShaderRegistry.cxx} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Modules/Visualization/Ice/include/{otbFragmentShader.h => otbShader.h} (100%) rename Modules/Visualization/Ice/include/{otbFragmentShaderRegistry.h => otbShaderRegistry.h} (100%) rename Modules/Visualization/Ice/src/{otbFragmentShader.cxx => otbShader.cxx} (100%) rename Modules/Visualization/Ice/src/{otbFragmentShaderRegistry.cxx => otbShaderRegistry.cxx} (100%) diff --git a/Modules/Visualization/Ice/include/otbFragmentShader.h b/Modules/Visualization/Ice/include/otbShader.h similarity index 100% rename from Modules/Visualization/Ice/include/otbFragmentShader.h rename to Modules/Visualization/Ice/include/otbShader.h diff --git a/Modules/Visualization/Ice/include/otbFragmentShaderRegistry.h b/Modules/Visualization/Ice/include/otbShaderRegistry.h similarity index 100% rename from Modules/Visualization/Ice/include/otbFragmentShaderRegistry.h rename to Modules/Visualization/Ice/include/otbShaderRegistry.h diff --git a/Modules/Visualization/Ice/src/otbFragmentShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx similarity index 100% rename from Modules/Visualization/Ice/src/otbFragmentShader.cxx rename to Modules/Visualization/Ice/src/otbShader.cxx diff --git a/Modules/Visualization/Ice/src/otbFragmentShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx similarity index 100% rename from Modules/Visualization/Ice/src/otbFragmentShaderRegistry.cxx rename to Modules/Visualization/Ice/src/otbShaderRegistry.cxx -- GitLab From 806084ab7f2afd269db33099cd64a242634450f8 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 10:54:33 +0200 Subject: [PATCH 03/73] REFAC: #1930: rename FragmentShader to Shader --- .../Ice/include/otbGlImageActor.h | 8 ++--- .../Visualization/Ice/include/otbGlROIActor.h | 1 - Modules/Visualization/Ice/include/otbShader.h | 16 +++++----- .../Ice/include/otbShaderRegistry.h | 16 +++++----- .../Ice/include/otbStandardShader.h | 6 ++-- Modules/Visualization/Ice/src/CMakeLists.txt | 4 +-- .../Ice/src/otbImageSettings.cxx | 3 -- Modules/Visualization/Ice/src/otbShader.cxx | 32 +++++++++---------- .../Ice/src/otbShaderRegistry.cxx | 26 +++++++-------- .../Ice/src/otbStandardShader.cxx | 4 +-- .../src/mvdImageViewRenderer.cxx | 14 ++++---- 11 files changed, 63 insertions(+), 67 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index be094a76e8..4ccb3a3e29 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -26,7 +26,7 @@ #include "itkCenteredRigid2DTransform.h" -#include "otbFragmentShader.h" +#include "otbShader.h" #include "otbGenericRSTransform.h" #include "otbGeoInterface.h" #include "otbGlActor.h" @@ -181,8 +181,8 @@ public: bool GetPixel( const PointType & physical, PixelType & pixel, IndexType & index ) const; - itkGetObjectMacro(Shader,FragmentShader); - itkSetObjectMacro(Shader,FragmentShader); + itkGetObjectMacro(Shader,Shader); + itkSetObjectMacro(Shader,Shader); itkGetObjectMacro( ImageSettings, ImageSettings ); @@ -308,7 +308,7 @@ private: unsigned int m_NumberOfComponents; ImageSettings::Pointer m_ImageSettings; - FragmentShader::Pointer m_Shader; + Shader::Pointer m_Shader; RSTransformType::Pointer m_ViewportToImageTransform; RSTransformType::Pointer m_ImageToViewportTransform; diff --git a/Modules/Visualization/Ice/include/otbGlROIActor.h b/Modules/Visualization/Ice/include/otbGlROIActor.h index 536c5dc2e5..49435f7da9 100644 --- a/Modules/Visualization/Ice/include/otbGlROIActor.h +++ b/Modules/Visualization/Ice/include/otbGlROIActor.h @@ -24,7 +24,6 @@ #include "otbGlActor.h" #include "otbGenericRSTransform.h" -#include "otbFragmentShader.h" #include "otbImageKeywordlist.h" #include "itkImageRegion.h" #include "itkVector.h" diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index d697da182b..7426fd0dd1 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -18,8 +18,8 @@ * limitations under the License. */ -#ifndef otb_FragmentShader_h -#define otb_FragmentShader_h +#ifndef otb_Shader_h +#define otb_Shader_h #include "OTBIceExport.h" @@ -29,11 +29,11 @@ namespace otb { -class OTBIce_EXPORT FragmentShader +class OTBIce_EXPORT Shader : public itk::Object { public: - typedef FragmentShader Self; + typedef Shader Self; typedef itk::Object Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; @@ -56,9 +56,9 @@ public: itkGetConstReferenceMacro(LR,PointType); protected: - FragmentShader(); + Shader(); - ~FragmentShader() override; + ~Shader() override; void BuildShader(); @@ -68,7 +68,7 @@ protected: private: // prevent implementation - FragmentShader(const Self&); + Shader(const Self&); void operator=(const Self&); PointType m_UL; @@ -76,7 +76,7 @@ private: PointType m_LL; PointType m_LR; -}; // End class FragmentShader +}; // End class Shader } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbShaderRegistry.h b/Modules/Visualization/Ice/include/otbShaderRegistry.h index c7b2ecf90e..6deaf880ca 100644 --- a/Modules/Visualization/Ice/include/otbShaderRegistry.h +++ b/Modules/Visualization/Ice/include/otbShaderRegistry.h @@ -18,8 +18,8 @@ * limitations under the License. */ -#ifndef otb_FragmentShaderRegistry_h -#define otb_FragmentShaderRegistry_h +#ifndef otb_ShaderRegistry_h +#define otb_ShaderRegistry_h #include "itkObject.h" #include "itkObjectFactory.h" @@ -27,11 +27,11 @@ namespace otb { -class FragmentShaderRegistry +class ShaderRegistry : public itk::Object { public: - typedef FragmentShaderRegistry Self; + typedef ShaderRegistry Self; typedef itk::Object Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; @@ -53,9 +53,9 @@ public: unsigned int GetShaderProgram(const std::string& name); protected: - FragmentShaderRegistry(); + ShaderRegistry(); - ~FragmentShaderRegistry() override; + ~ShaderRegistry() override; private: typedef std::map > ShaderMapType; @@ -63,14 +63,14 @@ private: itkNewMacro(Self); // prevent implementation - FragmentShaderRegistry(const Self&); + ShaderRegistry(const Self&); void operator=(const Self&); static Pointer m_Instance; ShaderMapType m_ShaderMap; -}; // End class FragmentShaderRegistry +}; // End class ShaderRegistry } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbStandardShader.h b/Modules/Visualization/Ice/include/otbStandardShader.h index 246bb8200c..dc98df5911 100644 --- a/Modules/Visualization/Ice/include/otbStandardShader.h +++ b/Modules/Visualization/Ice/include/otbStandardShader.h @@ -22,7 +22,7 @@ #define otb_StandardShader_h #include -#include "otbFragmentShader.h" +#include "otbShader.h" #include "otbImageSettings.h" #include @@ -52,11 +52,11 @@ typedef enum class OTBIce_EXPORT StandardShader - : public FragmentShader + : public Shader { public: typedef StandardShader Self; - typedef FragmentShader Superclass; + typedef Shader Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index c9740fa840..00a539ccb6 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -19,8 +19,8 @@ # set(OTBICE_SRCS - otbFragmentShader.cxx - otbFragmentShaderRegistry.cxx + otbShader.cxx + otbShaderRegistry.cxx otbGeoInterface.cxx otbGlActor.cxx otbGlImageActor.cxx diff --git a/Modules/Visualization/Ice/src/otbImageSettings.cxx b/Modules/Visualization/Ice/src/otbImageSettings.cxx index d3b75013a9..2cd090f2e4 100644 --- a/Modules/Visualization/Ice/src/otbImageSettings.cxx +++ b/Modules/Visualization/Ice/src/otbImageSettings.cxx @@ -19,9 +19,6 @@ */ #include "otbImageSettings.h" -#include "otbFragmentShaderRegistry.h" -#include "otbGlVersionChecker.h" -#include namespace otb { diff --git a/Modules/Visualization/Ice/src/otbShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx index d7e105378f..0c6547ab73 100644 --- a/Modules/Visualization/Ice/src/otbShader.cxx +++ b/Modules/Visualization/Ice/src/otbShader.cxx @@ -18,18 +18,18 @@ * limitations under the License. */ -#include "otbFragmentShader.h" -#include "otbFragmentShaderRegistry.h" +#include "otbShader.h" +#include "otbShaderRegistry.h" namespace otb { -FragmentShader::FragmentShader() +Shader::Shader() {} -FragmentShader::~FragmentShader() +Shader::~Shader() {} -void FragmentShader::BuildShader() +void Shader::BuildShader() { std::string source = this->GetSource(); std::string name = this->GetName(); @@ -37,9 +37,9 @@ void FragmentShader::BuildShader() try { // Assumption here is that each shader has its unique name - if(!otb::FragmentShaderRegistry::Instance()->IsShaderRegistered(name)) + if(!otb::ShaderRegistry::Instance()->IsShaderRegistered(name)) { - otb::FragmentShaderRegistry::Instance()->RegisterShader(name,source); + otb::ShaderRegistry::Instance()->RegisterShader(name,source); } } catch(itk::ExceptionObject& err) @@ -49,29 +49,29 @@ void FragmentShader::BuildShader() } } -void FragmentShader::LoadShader() +void Shader::LoadShader() { - otb::FragmentShaderRegistry::Instance()->LoadShader(GetName()); + otb::ShaderRegistry::Instance()->LoadShader(GetName()); } -void FragmentShader::UnloadShader() +void Shader::UnloadShader() { - otb::FragmentShaderRegistry::Instance()->UnloadShader(); + otb::ShaderRegistry::Instance()->UnloadShader(); } -void FragmentShader::SetupShader() +void Shader::SetupShader() { // // Default always report corners - // GLint shader_ul = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ul"); + // GLint shader_ul = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ul"); // glUniform2f(shader_ul,m_UL[0],m_UL[1]); - // GLint shader_ur = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ur"); + // GLint shader_ur = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ur"); // glUniform2f(shader_ur,m_UR[0],m_UR[1]); - // GLint shader_ll = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ll"); + // GLint shader_ll = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ll"); // glUniform2f(shader_ll,m_LL[0],m_LL[1]); - // GLint shader_lr = glGetUniformLocation(otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_lr"); + // GLint shader_lr = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_lr"); // glUniform2f(shader_lr,m_LR[0],m_LR[1]); } diff --git a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx index 47eefde7da..b8ec1a360f 100644 --- a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx +++ b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx @@ -18,35 +18,35 @@ * limitations under the License. */ -#include "otbFragmentShaderRegistry.h" +#include "otbShaderRegistry.h" #include namespace otb { -FragmentShaderRegistry::Pointer FragmentShaderRegistry::m_Instance; +ShaderRegistry::Pointer ShaderRegistry::m_Instance; -FragmentShaderRegistry::FragmentShaderRegistry() +ShaderRegistry::ShaderRegistry() : m_ShaderMap() {} -FragmentShaderRegistry::~FragmentShaderRegistry() +ShaderRegistry::~ShaderRegistry() { this->ClearShaders(); } -FragmentShaderRegistry::Pointer FragmentShaderRegistry::Instance() +ShaderRegistry::Pointer ShaderRegistry::Instance() { if(m_Instance.IsNull()) { - m_Instance = FragmentShaderRegistry::New(); + m_Instance = ShaderRegistry::New(); glewInit(); } return m_Instance; } -void FragmentShaderRegistry::RegisterShader(const std::string& name, const std::string& source) +void ShaderRegistry::RegisterShader(const std::string& name, const std::string& source) { if(m_ShaderMap.count(name) != 0) { @@ -97,7 +97,7 @@ void FragmentShaderRegistry::RegisterShader(const std::string& name, const std:: m_ShaderMap[name] = std::make_pair(program,shader); } -bool FragmentShaderRegistry::UnregisterShader(const std::string& name) +bool ShaderRegistry::UnregisterShader(const std::string& name) { if(m_ShaderMap.count(name) != 0) { @@ -109,12 +109,12 @@ bool FragmentShaderRegistry::UnregisterShader(const std::string& name) return false; } -bool FragmentShaderRegistry::IsShaderRegistered(const std::string& name) const +bool ShaderRegistry::IsShaderRegistered(const std::string& name) const { return (m_ShaderMap.count(name) != 0); } -bool FragmentShaderRegistry::LoadShader(const std::string& name) +bool ShaderRegistry::LoadShader(const std::string& name) { if(!IsShaderRegistered(name)) { @@ -124,12 +124,12 @@ bool FragmentShaderRegistry::LoadShader(const std::string& name) return true; } -void FragmentShaderRegistry::UnloadShader() +void ShaderRegistry::UnloadShader() { glUseProgramObjectARB(0); } -void FragmentShaderRegistry::ClearShaders() +void ShaderRegistry::ClearShaders() { std::vector keys; @@ -148,7 +148,7 @@ void FragmentShaderRegistry::ClearShaders() m_ShaderMap.clear(); } -unsigned int FragmentShaderRegistry::GetShaderProgram(const std::string& name) +unsigned int ShaderRegistry::GetShaderProgram(const std::string& name) { if(m_ShaderMap.count(name) == 0) { diff --git a/Modules/Visualization/Ice/src/otbStandardShader.cxx b/Modules/Visualization/Ice/src/otbStandardShader.cxx index afc590c270..e9f130b188 100644 --- a/Modules/Visualization/Ice/src/otbStandardShader.cxx +++ b/Modules/Visualization/Ice/src/otbStandardShader.cxx @@ -23,7 +23,7 @@ #include #include -#include "otbFragmentShaderRegistry.h" +#include "otbShaderRegistry.h" #include "otbGlVersionChecker.h" namespace otb @@ -315,7 +315,7 @@ void StandardShader::SetupShader() double gamma = m_ImageSettings->GetGamma(); - int program = otb::FragmentShaderRegistry::Instance()->GetShaderProgram("StandardShader"); + int program = otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"); GLint shader_a = glGetUniformLocation(program, "shader_a"); glUniform4f(shader_a,scr,scg,scb,1.); diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx index 815326194a..8afb7309f1 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx @@ -720,16 +720,16 @@ ImageViewRenderer // // Must use local variable to cast from T* to T::Pointer because // of ITK set/get macros... - otb::FragmentShader::Pointer fragmentShader( imageActor->GetShader() ); + otb::Shader::Pointer imageShader( imageActor->GetShader() ); - if( !fragmentShader.IsNull() ) + if( !imageShader.IsNull() ) { - // If this point is reached, shader is not null which means + // If this point is reached, imageShader is not null which means // that isGLSLEnabled() is true. assert( IsGLSLEnabled() ); otb::StandardShader::Pointer shader( - otb::DynamicCast< otb::StandardShader >( fragmentShader ) + otb::DynamicCast< otb::StandardShader >( imageShader ) ); assert( !shader.IsNull() ); @@ -1249,13 +1249,13 @@ ImageViewRenderer // // Get shader. - otb::FragmentShader::Pointer fshader( glImageActor->GetShader() ); + otb::Shader::Pointer ishader( glImageActor->GetShader() ); - if( !fshader.IsNull() ) + if( !ishader.IsNull() ) { otb::StandardShader::Pointer shader( otb::DynamicCast< otb::StandardShader >( - fshader + ishader ) ); -- GitLab From 8d659c3a6d6de383ca29eba1822b2f2e2fc76592 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 12:05:29 +0200 Subject: [PATCH 04/73] REFAC: #1930: support both vertex and fragment shaders --- Modules/Visualization/Ice/include/otbShader.h | 8 +++++++- Modules/Visualization/Ice/src/otbShader.cxx | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index 7426fd0dd1..b02082c6de 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -60,12 +60,18 @@ protected: ~Shader() override; + /** Build the shader sources and fills m_Program */ void BuildShader(); - virtual std::string GetSource() const = 0; + virtual std::string GetVertexSource() const = 0; + + virtual std::string GetFragmentSource() const = 0; virtual std::string GetName() const = 0; + /** Program object in which the shader is compiled and linked (0 if no program) */ + unsigned int m_Program; + private: // prevent implementation Shader(const Self&); diff --git a/Modules/Visualization/Ice/src/otbShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx index 0c6547ab73..56aa8469dc 100644 --- a/Modules/Visualization/Ice/src/otbShader.cxx +++ b/Modules/Visualization/Ice/src/otbShader.cxx @@ -24,6 +24,7 @@ namespace otb { Shader::Shader() + : m_Program(0) {} Shader::~Shader() @@ -31,7 +32,8 @@ Shader::~Shader() void Shader::BuildShader() { - std::string source = this->GetSource(); + std::string vSource = this->GetVertexSource(); + std::string fSource = this->GetFragmentSource(); std::string name = this->GetName(); try @@ -39,8 +41,9 @@ void Shader::BuildShader() // Assumption here is that each shader has its unique name if(!otb::ShaderRegistry::Instance()->IsShaderRegistered(name)) { - otb::ShaderRegistry::Instance()->RegisterShader(name,source); + otb::ShaderRegistry::Instance()->RegisterShader(name,vSource,fSource); } + m_Program = otb::ShaderRegistry::Instance()->GetShaderProgram(name); } catch(itk::ExceptionObject& err) { -- GitLab From a1670a010ccbc596c540bfea43c9dd523e8ae5d1 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 12:10:45 +0200 Subject: [PATCH 05/73] REFAC: #1930: adapt ShaderRegistry --- .../Ice/include/otbShaderRegistry.h | 6 +- .../Ice/src/otbShaderRegistry.cxx | 105 +++++++++++------- 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbShaderRegistry.h b/Modules/Visualization/Ice/include/otbShaderRegistry.h index 6deaf880ca..9d0b82337f 100644 --- a/Modules/Visualization/Ice/include/otbShaderRegistry.h +++ b/Modules/Visualization/Ice/include/otbShaderRegistry.h @@ -38,7 +38,7 @@ public: static Pointer Instance(); - void RegisterShader(const std::string& name, const std::string& source); + void RegisterShader(const std::string& name, const std::string& vSource, const std::string& fSource); bool UnregisterShader(const std::string& name); @@ -58,7 +58,7 @@ protected: ~ShaderRegistry() override; private: - typedef std::map > ShaderMapType; + typedef std::map ShaderMapType; itkNewMacro(Self); @@ -66,6 +66,8 @@ private: ShaderRegistry(const Self&); void operator=(const Self&); + unsigned int CompileShader(int stype, const std::string& name, const std::string& src); + static Pointer m_Instance; ShaderMapType m_ShaderMap; diff --git a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx index b8ec1a360f..462eae2746 100644 --- a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx +++ b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx @@ -46,63 +46,55 @@ ShaderRegistry::Pointer ShaderRegistry::Instance() return m_Instance; } -void ShaderRegistry::RegisterShader(const std::string& name, const std::string& source) +void ShaderRegistry::RegisterShader(const std::string& name, const std::string& vSource, const std::string& fSource) { if(m_ShaderMap.count(name) != 0) { itkExceptionMacro(<<"A shader with name "< Date: Tue, 20 Aug 2019 13:25:37 +0200 Subject: [PATCH 06/73] REFAC: #1930: add proj and modelview matrices --- Modules/Visualization/Ice/include/otbGlView.h | 4 +++ Modules/Visualization/Ice/include/otbShader.h | 33 ++++++++++++------- Modules/Visualization/Ice/src/otbGlView.cxx | 22 +++++++++++-- Modules/Visualization/Ice/src/otbShader.cxx | 2 ++ 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlView.h b/Modules/Visualization/Ice/include/otbGlView.h index 114add8e4b..d40905245e 100644 --- a/Modules/Visualization/Ice/include/otbGlView.h +++ b/Modules/Visualization/Ice/include/otbGlView.h @@ -294,6 +294,10 @@ private: StringVectorType m_RenderingOrder; + float m_ProjMatrix[16]; + + float m_ModelViewMatrix[16]; + }; // End class GlView diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index b02082c6de..272eee762b 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -29,9 +29,12 @@ namespace otb { +class GlView; + class OTBIce_EXPORT Shader : public itk::Object { +friend class GlView; public: typedef Shader Self; typedef itk::Object Superclass; @@ -46,14 +49,14 @@ public: void UnloadShader(); - itkSetMacro(UL,PointType); - itkSetMacro(UR,PointType); - itkSetMacro(LL,PointType); - itkSetMacro(LR,PointType); - itkGetConstReferenceMacro(UL,PointType); - itkGetConstReferenceMacro(UR,PointType); - itkGetConstReferenceMacro(LL,PointType); - itkGetConstReferenceMacro(LR,PointType); + //~ itkSetMacro(UL,PointType); + //~ itkSetMacro(UR,PointType); + //~ itkSetMacro(LL,PointType); + //~ itkSetMacro(LR,PointType); + //~ itkGetConstReferenceMacro(UL,PointType); + //~ itkGetConstReferenceMacro(UR,PointType); + //~ itkGetConstReferenceMacro(LL,PointType); + //~ itkGetConstReferenceMacro(LR,PointType); protected: Shader(); @@ -72,15 +75,21 @@ protected: /** Program object in which the shader is compiled and linked (0 if no program) */ unsigned int m_Program; + /** Projection matrix */ + float * m_ProjMatrix; + + /** ModelView matrix */ + float * m_ModelViewMatrix; + private: // prevent implementation Shader(const Self&); void operator=(const Self&); - PointType m_UL; - PointType m_UR; - PointType m_LL; - PointType m_LR; + //~ PointType m_UL; + //~ PointType m_UR; + //~ PointType m_LL; + //~ PointType m_LR; }; // End class Shader diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index 8e5727f6b1..7cc7a7ed47 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -43,9 +43,19 @@ namespace otb { GlView::GlView() - : m_Settings(ViewSettings::New()), - m_Actors(), - m_RenderingOrder() + : m_Settings(ViewSettings::New()) + , m_Actors() + , m_RenderingOrder() + , m_ProjMatrix{ + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0} + , m_ModelViewMatrix{ + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0} {} GlView::~GlView() @@ -501,4 +511,10 @@ GlView // itkBuffer = NULL; } + + //~ m_Settings->m_VertexShader = vShader; + //~ m_Settings->m_TextureCoordIdx = glGetAttribLocation(m_VertexProgram , "in_coord"); + + + } diff --git a/Modules/Visualization/Ice/src/otbShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx index 56aa8469dc..8c493e7f1a 100644 --- a/Modules/Visualization/Ice/src/otbShader.cxx +++ b/Modules/Visualization/Ice/src/otbShader.cxx @@ -25,6 +25,8 @@ namespace otb { Shader::Shader() : m_Program(0) + , m_ProjMatrix(nullptr) + , m_ModelViewMatrix(nullptr) {} Shader::~Shader() -- GitLab From 8310315c750a63861bce1eb4f90119c45aa45159 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 13:26:41 +0200 Subject: [PATCH 07/73] REFAC: #1930: refactor StandardShader --- .../Ice/include/otbStandardShader.h | 29 +++- .../Ice/src/otbStandardShader.cxx | 136 ++++++++++-------- 2 files changed, 103 insertions(+), 62 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbStandardShader.h b/Modules/Visualization/Ice/include/otbStandardShader.h index dc98df5911..6974adc488 100644 --- a/Modules/Visualization/Ice/include/otbStandardShader.h +++ b/Modules/Visualization/Ice/include/otbStandardShader.h @@ -99,7 +99,9 @@ protected: ~StandardShader() override; - std::string GetSource() const override; + std::string GetVertexSource() const override; + + std::string GetFragmentSource() const override; std::string GetName() const override; @@ -124,6 +126,31 @@ private: bool m_VerticalSlider; ShaderType m_ShaderType; + + bool m_HasGLSL140; + + struct UniformLocs + { + int proj; + int modelview; + int a; + int b; + int use_no_data; + int no_data; + int gamma; + int alpha; + int radius; + int center; + int type; + int current; + int localc_range; + int spectral_angle_range; + int chessboard_size; + int slider_pos; + int vertical_slider_flag; + }; + + UniformLocs m_Loc; }; // End class StandardShader } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbStandardShader.cxx b/Modules/Visualization/Ice/src/otbStandardShader.cxx index e9f130b188..d09ff37a52 100644 --- a/Modules/Visualization/Ice/src/otbStandardShader.cxx +++ b/Modules/Visualization/Ice/src/otbStandardShader.cxx @@ -41,26 +41,75 @@ StandardShader::StandardShader() : { m_Center.Fill( 0 ); + const char * glVersion = nullptr; + const char * glslVersion = nullptr; + if(!otb::GlVersionChecker::CheckGLCapabilities( glVersion, glslVersion)) + { + itkExceptionMacro(<<" Required GL and GLSL versions were not found (GL version is "<=0; + + // Register the shader in the ShaderRegistry BuildShader(); + + // Reserve variable locations + // - for vertex shader + m_Loc.proj = glGetUniformLocation(m_Program, "in_proj"); + m_Loc.modelview = glGetUniformLocation(m_Program, "in_mv"); + // - for fragment shader + m_Loc.a = glGetUniformLocation(m_Program, "shader_a"); + m_Loc.b = glGetUniformLocation(m_Program, "shader_b"); + m_Loc.use_no_data = glGetUniformLocation(m_Program, "shader_use_no_data"); + m_Loc.no_data = glGetUniformLocation(m_Program, "shader_no_data"); + m_Loc.gamma = glGetUniformLocation(m_Program, "shader_gamma"); + m_Loc.alpha = glGetUniformLocation(m_Program, "shader_alpha"); + m_Loc.radius = glGetUniformLocation(m_Program, "shader_radius"); + m_Loc.center = glGetUniformLocation(m_Program, "shader_center"); + m_Loc.type = glGetUniformLocation(m_Program, "shader_type"); + m_Loc.current = glGetUniformLocation(m_Program, "shader_current"); + m_Loc.localc_range = glGetUniformLocation(m_Program, "shader_localc_range"); + m_Loc.spectral_angle_range = glGetUniformLocation(m_Program, "shader_spectral_angle_range"); + m_Loc.chessboard_size = glGetUniformLocation(m_Program, "shader_chessboard_size"); + m_Loc.slider_pos = glGetUniformLocation(m_Program, "shader_slider_pos"); + m_Loc.vertical_slider_flag = glGetUniformLocation(m_Program, "shader_vertical_slider_flag"); + + // TODO setup texture coordinate index + //m_TextureCoordIdx = glGetAttribLocation(m_VertexProgram , "in_coord"); } StandardShader::~StandardShader() {} -std::string StandardShader::GetSource() const +std::string StandardShader::GetVertexSource() const { - const char * glVersion = nullptr; - const char * glslVersion = nullptr; - if(!otb::GlVersionChecker::CheckGLCapabilities( glVersion, glslVersion)) + std::string shader_source = ""; + if(m_HasGLSL140) { - itkExceptionMacro(<<" Required GL and GLSL versions were not found (GL version is "<=0; + return shader_source; +} +std::string StandardShader::GetFragmentSource() const +{ std::string shader_source = ""; - if(isGLSLS140Available) + if(m_HasGLSL140) { shader_source+="#version 140 \n"; } @@ -270,7 +319,7 @@ std::string StandardShader::GetSource() const "}\n" \ "}\n"; - if(isGLSLS140Available) + if(m_HasGLSL140) { shader_source+= "else if(shader_type == 6)\n" \ @@ -302,6 +351,9 @@ void StandardShader::SetupShader() { assert( !m_ImageSettings.IsNull() ); + glUniformMatrix4fv(m_Loc.proj,1, GL_FALSE, m_ProjMatrix); + glUniformMatrix4fv(m_Loc.modelview,1, GL_FALSE, m_ModelViewMatrix); + // // Compute shifts. double shr = -m_ImageSettings->GetMinRed(); @@ -315,65 +367,27 @@ void StandardShader::SetupShader() double gamma = m_ImageSettings->GetGamma(); - int program = otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"); - - GLint shader_a = glGetUniformLocation(program, "shader_a"); - glUniform4f(shader_a,scr,scg,scb,1.); - - GLint shader_b = glGetUniformLocation(program, "shader_b"); - glUniform4f(shader_b,shr,shg,shb,0); - - GLint shader_use_no_data = glGetUniformLocation(program, "shader_use_no_data"); - glUniform1i(shader_use_no_data, m_ImageSettings->GetUseNoData() ); - - GLint shader_no_data = glGetUniformLocation(program, "shader_no_data"); - glUniform1f( shader_no_data, m_ImageSettings->GetNoData() ); - - GLint shader_gamma = glGetUniformLocation(program, "shader_gamma"); - glUniform4f( shader_gamma, gamma, gamma, gamma, gamma ); - - GLint shader_alpha = glGetUniformLocation(program, "shader_alpha"); - glUniform1f( shader_alpha, m_ImageSettings->GetAlpha() ); - - GLint shader_radius = glGetUniformLocation(program, "shader_radius"); - glUniform1f(shader_radius,m_Radius); - - GLint shader_center = glGetUniformLocation(program, "shader_center"); - glUniform2f(shader_center,m_Center[0],m_Center[1]); - - GLint shader_type = glGetUniformLocation(program, "shader_type"); - glUniform1i(shader_type,m_ShaderType); - - // std::cout - // << "r: " << m_ImageSettings->GetCurrentRed() - // << " g: " << m_ImageSettings->GetCurrentGreen() - // << " b: " << m_ImageSettings->GetCurrentBlue() - // << std::endl; - - GLint shader_current = glGetUniformLocation(program, "shader_current"); + glUniform4f(m_Loc.a,scr,scg,scb,1.); + glUniform4f(m_Loc.b,shr,shg,shb,0); + glUniform1i(m_Loc.use_no_data, m_ImageSettings->GetUseNoData() ); + glUniform1f( m_Loc.no_data, m_ImageSettings->GetNoData() ); + glUniform4f( m_Loc.gamma, gamma, gamma, gamma, gamma ); + glUniform1f( m_Loc.alpha, m_ImageSettings->GetAlpha() ); + glUniform1f(m_Loc.radius,m_Radius); + glUniform2f(m_Loc.center,m_Center[0],m_Center[1]); + glUniform1i(m_Loc.type,m_ShaderType); glUniform3f( - shader_current, + m_Loc.current, m_ImageSettings->GetCurrentRed(), m_ImageSettings->GetCurrentGreen(), m_ImageSettings->GetCurrentBlue() ); - - GLint shader_localc_range = glGetUniformLocation(program, "shader_localc_range"); - glUniform1f(shader_localc_range,m_LocalContrastRange); - - GLint shader_spectral_angle_range = glGetUniformLocation(program, "shader_spectral_angle_range"); - glUniform1f(shader_spectral_angle_range,m_SpectralAngleRange); - - GLint shader_chessboard_size = glGetUniformLocation(program, "shader_chessboard_size"); - glUniform1f(shader_chessboard_size,m_ChessboardSize); - - GLint shader_slider_pos = glGetUniformLocation(program, "shader_slider_pos"); - glUniform1f(shader_slider_pos,m_SliderPosition); - - GLint shader_vertical_slider_flag = glGetUniformLocation(program, "shader_vertical_slider_flag"); - glUniform1i(shader_vertical_slider_flag,m_VerticalSlider); + glUniform1f(m_Loc.localc_range,m_LocalContrastRange); + glUniform1f(m_Loc.spectral_angle_range,m_SpectralAngleRange); + glUniform1f(m_Loc.chessboard_size,m_ChessboardSize); + glUniform1f(m_Loc.slider_pos,m_SliderPosition); + glUniform1i(m_Loc.vertical_slider_flag,m_VerticalSlider); } - } // End namespace otb -- GitLab From 200df70d2684ac8d913e2d8a515c04bfafb9d8be Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 16:33:48 +0200 Subject: [PATCH 08/73] REFAC: #1930: move shader to base class GlActor --- .../Visualization/Ice/include/otbGlActor.h | 9 ++ .../Ice/include/otbGlImageActor.h | 8 +- Modules/Visualization/Ice/include/otbShader.h | 4 +- .../Ice/include/otbStandardShader.h | 4 + Modules/Visualization/Ice/src/otbGlActor.cxx | 15 ++- .../Visualization/Ice/src/otbGlImageActor.cxx | 18 ++-- .../Ice/src/otbStandardShader.cxx | 98 +++++++++---------- 7 files changed, 86 insertions(+), 70 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlActor.h b/Modules/Visualization/Ice/include/otbGlActor.h index 7cfbf67a56..b1f8f000b5 100644 --- a/Modules/Visualization/Ice/include/otbGlActor.h +++ b/Modules/Visualization/Ice/include/otbGlActor.h @@ -24,6 +24,7 @@ #include #include "otbViewSettings.h" +#include "otbShader.h" #include "OTBIceExport.h" #include @@ -58,6 +59,9 @@ public: itkGetMacro( Overlay, bool ); itkBooleanMacro( Overlay ); + itkGetObjectMacro(Shader,Shader); + itkSetObjectMacro(Shader,Shader); + // Retrieve the full extent of the actor virtual void GetExtent(double & ulx, double & uly, double & lrx, double & lry) const = 0; @@ -70,11 +74,16 @@ public: // Gl rendering of current state virtual void Render() = 0; + /** create the shader (no shader created by default) */ + virtual void CreateShader(); + protected: GlActor(); ~GlActor() override; + Shader::Pointer m_Shader; + private: // prevent implementation GlActor(const Self&); diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 4ccb3a3e29..1ee1196809 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -26,7 +26,6 @@ #include "itkCenteredRigid2DTransform.h" -#include "otbShader.h" #include "otbGenericRSTransform.h" #include "otbGeoInterface.h" #include "otbGlActor.h" @@ -129,7 +128,7 @@ public: itkSetMacro(SoftwareRendering, bool ); itkGetMacro(SoftwareRendering, bool ); - void CreateShader(); + void CreateShader() override; void SetResolutionAlgorithm(ResolutionAlgorithm::type alg) { @@ -181,9 +180,6 @@ public: bool GetPixel( const PointType & physical, PixelType & pixel, IndexType & index ) const; - itkGetObjectMacro(Shader,Shader); - itkSetObjectMacro(Shader,Shader); - itkGetObjectMacro( ImageSettings, ImageSettings ); // @@ -308,7 +304,6 @@ private: unsigned int m_NumberOfComponents; ImageSettings::Pointer m_ImageSettings; - Shader::Pointer m_Shader; RSTransformType::Pointer m_ViewportToImageTransform; RSTransformType::Pointer m_ImageToViewportTransform; @@ -319,7 +314,6 @@ private: ResolutionAlgorithm::type m_ResolutionAlgorithm; bool m_SoftwareRendering; - }; // End class GlImageActor } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index 272eee762b..51c5d787e3 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -76,10 +76,10 @@ protected: unsigned int m_Program; /** Projection matrix */ - float * m_ProjMatrix; + const float * m_ProjMatrix; /** ModelView matrix */ - float * m_ModelViewMatrix; + const float * m_ModelViewMatrix; private: // prevent implementation diff --git a/Modules/Visualization/Ice/include/otbStandardShader.h b/Modules/Visualization/Ice/include/otbStandardShader.h index 6974adc488..29be6a1ebb 100644 --- a/Modules/Visualization/Ice/include/otbStandardShader.h +++ b/Modules/Visualization/Ice/include/otbStandardShader.h @@ -94,6 +94,8 @@ public: itkNewMacro(Self); + itkGetMacro(TextureCoordIdx,int); + protected: StandardShader(); @@ -151,6 +153,8 @@ private: }; UniformLocs m_Loc; + + int m_TextureCoordIdx; }; // End class StandardShader } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlActor.cxx b/Modules/Visualization/Ice/src/otbGlActor.cxx index c91ad6d17d..f7ee8c419d 100644 --- a/Modules/Visualization/Ice/src/otbGlActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlActor.cxx @@ -23,14 +23,19 @@ namespace otb { GlActor::GlActor() - : m_Settings(ViewSettings::New()), - m_Name("Actor"), - m_Visible(true), - m_GeometryChanged( false ), - m_Overlay( false ) + : m_Shader() + , m_Settings(ViewSettings::New()) + , m_Name("Actor") + , m_Visible(true) + , m_GeometryChanged( false ) + , m_Overlay( false ) {} GlActor::~GlActor() {} +void +GlActor::CreateShader() +{} + } // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 1a61ab0062..48d649dcf1 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -30,6 +30,7 @@ #include "itkListSample.h" #include "otbListSampleToHistogramListGenerator.h" +#include "otbCast.h" namespace otb { @@ -48,7 +49,6 @@ GlImageActor::GlImageActor() m_Spacing(), m_NumberOfComponents(0), m_ImageSettings( ImageSettings::New() ), - m_Shader(), m_ViewportToImageTransform(), m_ImageToViewportTransform(), m_ViewportForwardRotationTransform(RigidTransformType::New()), @@ -452,6 +452,10 @@ void GlImageActor::Render() } } + otb::StandardShader::Pointer shader = + otb::DynamicCast< otb::StandardShader >(m_Shader); + int texCoord = shader->GetTextureCoordIdx(); + for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) { @@ -471,15 +475,15 @@ void GlImageActor::Render() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } - + // Reset color before rendering glColor4d(1.0f,1.0f,1.0f, m_ImageSettings->GetAlpha()); - + glBegin (GL_QUADS); - glTexCoord2f (0.0, 1.0); glVertex2f(it->m_LL[0], it->m_LL[1]); - glTexCoord2f (1.0, 1.0); glVertex2f(it->m_LR[0], it->m_LR[1]); - glTexCoord2f (1.0, 0.0); glVertex2f(it->m_UR[0], it->m_UR[1]); - glTexCoord2f (0.0, 0.0); glVertex2f(it->m_UL[0], it->m_UL[1]); + glVertexAttrib2f(texCoord, 0.0, 1.0); glVertex2f(it->m_LL[0], it->m_LL[1]); + glVertexAttrib2f(texCoord, 1.0, 1.0); glVertex2f(it->m_LR[0], it->m_LR[1]); + glVertexAttrib2f(texCoord, 1.0, 0.0); glVertex2f(it->m_UR[0], it->m_UR[1]); + glVertexAttrib2f(texCoord, 0.0, 0.0); glVertex2f(it->m_UL[0], it->m_UL[1]); glEnd (); glDisable(GL_TEXTURE_2D); diff --git a/Modules/Visualization/Ice/src/otbStandardShader.cxx b/Modules/Visualization/Ice/src/otbStandardShader.cxx index d09ff37a52..c19d280387 100644 --- a/Modules/Visualization/Ice/src/otbStandardShader.cxx +++ b/Modules/Visualization/Ice/src/otbStandardShader.cxx @@ -73,8 +73,7 @@ StandardShader::StandardShader() : m_Loc.slider_pos = glGetUniformLocation(m_Program, "shader_slider_pos"); m_Loc.vertical_slider_flag = glGetUniformLocation(m_Program, "shader_vertical_slider_flag"); - // TODO setup texture coordinate index - //m_TextureCoordIdx = glGetAttribLocation(m_VertexProgram , "in_coord"); + m_TextureCoordIdx = glGetAttribLocation(m_Program , "in_coord"); } StandardShader::~StandardShader() @@ -136,40 +135,41 @@ std::string StandardShader::GetFragmentSource() const "uniform float shader_slider_pos;\n" \ "uniform int shader_vertical_slider_flag;\n" \ "in vec2 tex_coord;\n" \ + "out vec4 out_color;\n" \ "void main (void) {\n" \ "vec4 p = texture(src, tex_coord);\n" \ "vec4 colors = pow( clamp( ( p+shader_b ) * shader_a, 0.0, 1.0 ), shader_gamma );\n" \ - "gl_FragColor = colors;\n" \ - "gl_FragColor[3] = clamp(shader_alpha,0.0,1.0);\n" \ + "out_color = colors;\n" \ + "out_color[3] = clamp(shader_alpha,0.0,1.0);\n" \ "if(shader_use_no_data > 0 && vec3(p) == vec3(shader_no_data)){\n" \ - "gl_FragColor[3] = 0.;\n" \ + "out_color[3] = 0.;\n" \ "}\n" \ - "float alpha = gl_FragColor[3];\n" \ + "float alpha = out_color[3];\n" \ "float dist = distance(gl_FragCoord.xy,shader_center);\n" \ "if(shader_type == 1)\n" \ "{\n" \ "if(dist < shader_radius)\n" \ "{\n" \ "vec3 tmp = clamp((vec3(p)-vec3(shader_current)+vec3(shader_localc_range))/(2.*vec3(shader_localc_range)),0.0,1.0);\n" \ - "gl_FragColor[0] = tmp[0];\n" \ - "gl_FragColor[1] = tmp[1];\n" \ - "gl_FragColor[2] = tmp[2];\n" \ - "gl_FragColor[3] = alpha;\n" \ + "out_color[0] = tmp[0];\n" \ + "out_color[1] = tmp[1];\n" \ + "out_color[2] = tmp[2];\n" \ + "out_color[3] = alpha;\n" \ "}\n" \ "}\n" \ "else if(shader_type == 2)" \ "{\n" \ - "gl_FragColor[3] = dist > shader_radius ? 1.0 : 0.0; \n" \ + "out_color[3] = dist > shader_radius ? 1.0 : 0.0; \n" \ "}\n" \ "else if(shader_type == 3)\n" \ "{\n" \ "float alpha = (mod(floor(gl_FragCoord.x / shader_chessboard_size), 2.0) == 0.) != (mod(floor(gl_FragCoord.y / shader_chessboard_size), 2.0) == 1.) ? shader_alpha : 0.0;\n" \ - "gl_FragColor[3] = clamp(alpha,0.0,1.0);\n" \ + "out_color[3] = clamp(alpha,0.0,1.0);\n" \ "}\n" \ "else if(shader_type == 4)\n" \ "{\n" \ "float alpha = (shader_vertical_slider_flag == 0 && gl_FragCoord.x > shader_slider_pos) || (shader_vertical_slider_flag == 1 && gl_FragCoord.y > shader_slider_pos) ? 1.0 : 0.0;\n" \ - "gl_FragColor[3] = clamp(alpha,0.0,1.0);\n" \ + "out_color[3] = clamp(alpha,0.0,1.0);\n" \ "}\n" \ "else if(shader_type == 5)\n" \ "{\n" \ @@ -177,10 +177,10 @@ std::string StandardShader::GetFragmentSource() const "{\n" \ "float angle = acos(clamp(dot(vec3(p),shader_current)/(length(vec3(p))*length(shader_current)),-1.0,1.0));\n" \ "vec3 tmp = clamp(vec3(1.-shader_spectral_angle_range*abs(angle)/3.142),0.0,1.0);\n" \ - "gl_FragColor[0] = tmp[0];\n" \ - "gl_FragColor[1] = tmp[1];\n" \ - "gl_FragColor[2] = tmp[2];\n" \ - "gl_FragColor[3] = alpha;\n" \ + "out_color[0] = tmp[0];\n" \ + "out_color[1] = tmp[1];\n" \ + "out_color[2] = tmp[2];\n" \ + "out_color[3] = alpha;\n" \ "}\n" \ "}\n" \ "else if(shader_type == 7)\n" \ @@ -191,9 +191,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = -abs( 3.95 * (color - 0.492)) + 1.5;\n" \ "mapped[2] = -abs( 3.95 * (color - 0.2385)) + 1.5;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "else if(shader_type == 8)\n" \ "{\n" \ @@ -205,9 +205,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = -abs( 3.95 * (color - 0.492)) + 1.5;\n" \ "mapped[2] = -abs( 3.95 * (color - 0.2385)) + 1.5;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "}\n" \ "else if(shader_type == 9)\n" \ @@ -218,9 +218,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 63.0 / 26.0 * color - 11.0 / 13.0;\n" \ "mapped[2] = 4.5 * color - 3.5;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "else if(shader_type == 10)\n" \ "{\n" \ @@ -232,9 +232,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 63.0 / 26.0 * color - 11.0 / 13.0;\n" \ "mapped[2] = 4.5 * color - 3.5;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "}\n" \ "else if(shader_type == 11)\n" \ @@ -245,9 +245,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = color;\n" \ "mapped[2] = 1.0 - 0.5 * color;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "else if(shader_type == 12)\n" \ "{\n" \ @@ -259,9 +259,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = color;\n" \ "mapped[2] = 1.0 - 0.5 * color;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "}\n" \ "else if(shader_type == 13)\n" \ @@ -272,9 +272,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 0.5*color+0.5;\n" \ "mapped[2] = 0.4;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "else if(shader_type == 14)\n" \ "{\n" \ @@ -286,9 +286,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 0.5*color+0.5;\n" \ "mapped[2] = 0.4;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "}\n" \ "else if(shader_type == 15)\n" \ @@ -299,9 +299,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 1.0-color;\n" \ "mapped[2] = 1.0;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "else if(shader_type == 16)\n" \ "{\n" \ @@ -313,9 +313,9 @@ std::string StandardShader::GetFragmentSource() const "mapped[1] = 1.0-color;\n" \ "mapped[2] = 1.0;\n" \ "mapped = clamp(mapped,0.0,1.0);\n" \ - "gl_FragColor[0] = mapped[0];\n" \ - "gl_FragColor[1] = mapped[1];\n" \ - "gl_FragColor[2] = mapped[2];\n" \ + "out_color[0] = mapped[0];\n" \ + "out_color[1] = mapped[1];\n" \ + "out_color[2] = mapped[2];\n" \ "}\n" \ "}\n"; @@ -333,8 +333,8 @@ std::string StandardShader::GetFragmentSource() const "dy[1]+=1.0/size[1];\n" \ "vec4 pdx = texture2D(src, dx);\n" \ "vec4 pdy = texture2D(src, dy);\n" \ - "gl_FragColor = clamp(pow(5*shader_a*(0.5*abs((pdx-p))+ 0.5*abs((pdy-p))),shader_gamma),0.0,1.0);\n" \ - "gl_FragColor[3] = alpha;\n" \ + "out_color = clamp(pow(5*shader_a*(0.5*abs((pdx-p))+ 0.5*abs((pdy-p))),shader_gamma),0.0,1.0);\n" \ + "out_color[3] = alpha;\n" \ "}\n" \ "}\n"; } -- GitLab From f75093b23007bb82069b140c2bd90f7f66bcd330 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 20 Aug 2019 16:36:24 +0200 Subject: [PATCH 09/73] REFAC: #1930: minimal shader for other actors --- .../Ice/include/otbMinimalShader.h | 74 +++++++++++++++ Modules/Visualization/Ice/src/CMakeLists.txt | 1 + .../Ice/src/otbMinimalShader.cxx | 90 +++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 Modules/Visualization/Ice/include/otbMinimalShader.h create mode 100644 Modules/Visualization/Ice/src/otbMinimalShader.cxx diff --git a/Modules/Visualization/Ice/include/otbMinimalShader.h b/Modules/Visualization/Ice/include/otbMinimalShader.h new file mode 100644 index 0000000000..87ff6b0432 --- /dev/null +++ b/Modules/Visualization/Ice/include/otbMinimalShader.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_MinimalShader_h +#define otb_MinimalShader_h + +#include +#include "otbShader.h" +#include + +namespace otb +{ + +class OTBIce_EXPORT MinimalShader + : public Shader +{ +public: + typedef MinimalShader Self; + typedef Shader Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + typedef itk::Point PointType; + + void SetupShader() override; + + itkNewMacro(Self); + +protected: + MinimalShader(); + + ~MinimalShader() override; + + std::string GetVertexSource() const override; + + std::string GetFragmentSource() const override; + + std::string GetName() const override; + +private: + // prevent implementation + MinimalShader(const Self&); + void operator=(const Self&); + + struct UniformLocs + { + int proj; + int modelview; + }; + + UniformLocs m_Loc; +}; // End class MinimalShader + +} // End namespace otb + +#endif + diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index 00a539ccb6..2461c6d9cf 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(OTBICE_SRCS otbImageSettings.cxx otbStandardShader.cxx otbViewSettings.cxx + otbMinimalShader.cxx ) add_library(OTBIce ${OTBICE_SRCS}) diff --git a/Modules/Visualization/Ice/src/otbMinimalShader.cxx b/Modules/Visualization/Ice/src/otbMinimalShader.cxx new file mode 100644 index 0000000000..bd21e19f86 --- /dev/null +++ b/Modules/Visualization/Ice/src/otbMinimalShader.cxx @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbMinimalShader.h" + +#include +#include + +#include "otbShaderRegistry.h" + +namespace otb +{ + +MinimalShader::MinimalShader() +{ + // Register the shader in the ShaderRegistry + BuildShader(); + + // Reserve variable locations + // - for vertex shader + m_Loc.proj = glGetUniformLocation(m_Program, "in_proj"); + m_Loc.modelview = glGetUniformLocation(m_Program, "in_mv"); + // - for fragment shader + +} + +MinimalShader::~MinimalShader() +{} + +std::string MinimalShader::GetVertexSource() const +{ + std::string shader_source = + "#version 130 \n" \ + "in vec4 in_color;\n" \ + "out vec4 v_color;\n" \ + "uniform mat4 in_proj;\n" \ + "uniform mat4 in_mv;\n" \ + "void main()\n" \ + "{\n" \ + "v_color = in_color;\n" \ + "gl_Position = in_proj * in_mv * gl_Vertex;\n" \ + "}"; + + return shader_source; +} + +std::string MinimalShader::GetFragmentSource() const +{ + std::string shader_source = + "#version 130 \n" \ + "in vec4 v_color;\n" \ + "out vec4 out_color;\n" \ + "void main (void) {\n" \ + "out_color = v_color;\n" \ + "}"; + + return shader_source; +} + +std::string MinimalShader::GetName() const +{ + return "MinimalShader"; +} + +void MinimalShader::SetupShader() +{ + glUniformMatrix4fv(m_Loc.proj,1, GL_FALSE, m_ProjMatrix); + glUniformMatrix4fv(m_Loc.modelview,1, GL_FALSE, m_ModelViewMatrix); +} + +} // End namespace otb + + -- GitLab From 905fce99692caaaf5c9185e3eda87e79cbc11208 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 22 Aug 2019 11:45:27 +0200 Subject: [PATCH 10/73] REFAC: #1930: implement shader for GlROIActor --- .../Visualization/Ice/include/otbGlROIActor.h | 2 + .../Ice/include/otbMinimalShader.h | 4 ++ .../Visualization/Ice/src/otbGlImageActor.cxx | 11 +-- .../Visualization/Ice/src/otbGlROIActor.cxx | 22 +++++- Modules/Visualization/Ice/src/otbGlView.cxx | 67 +++++++++++++++++++ .../Ice/src/otbMinimalShader.cxx | 1 + .../Ice/src/otbShaderRegistry.cxx | 8 ++- .../IceViewer/src/otbIceViewer.cxx | 2 + .../src/mvdQuicklookViewRenderer.cxx | 2 + 9 files changed, 110 insertions(+), 9 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlROIActor.h b/Modules/Visualization/Ice/include/otbGlROIActor.h index 49435f7da9..bddc9913a5 100644 --- a/Modules/Visualization/Ice/include/otbGlROIActor.h +++ b/Modules/Visualization/Ice/include/otbGlROIActor.h @@ -60,6 +60,8 @@ public: // Gl rendering of current state void Render() override; + void CreateShader() override; + void SetUL( const PointType & ); itkGetConstReferenceMacro(UL,PointType); diff --git a/Modules/Visualization/Ice/include/otbMinimalShader.h b/Modules/Visualization/Ice/include/otbMinimalShader.h index 87ff6b0432..d9cf0e9fb6 100644 --- a/Modules/Visualization/Ice/include/otbMinimalShader.h +++ b/Modules/Visualization/Ice/include/otbMinimalShader.h @@ -43,6 +43,8 @@ public: itkNewMacro(Self); + itkGetMacro(ColorIdx, int); + protected: MinimalShader(); @@ -66,6 +68,8 @@ private: }; UniformLocs m_Loc; + + int m_ColorIdx; }; // End class MinimalShader } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 48d649dcf1..6a1e655731 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -73,11 +73,12 @@ void GlImageActor ::CreateShader() { - StandardShader::Pointer shader( StandardShader::New() ); - - shader->SetImageSettings( m_ImageSettings ); - - m_Shader = shader; + if (m_Shader.IsNull()) + { + StandardShader::Pointer shader( StandardShader::New() ); + shader->SetImageSettings( m_ImageSettings ); + m_Shader = shader; + } } const GlImageActor::PointType & GlImageActor::GetOrigin() const diff --git a/Modules/Visualization/Ice/src/otbGlROIActor.cxx b/Modules/Visualization/Ice/src/otbGlROIActor.cxx index f5e31b2709..7506449f7b 100644 --- a/Modules/Visualization/Ice/src/otbGlROIActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlROIActor.cxx @@ -20,6 +20,8 @@ #include "otbGlROIActor.h" #include "otbViewSettings.h" +#include "otbMinimalShader.h" +#include "otbCast.h" #ifdef _WIN32 #include #endif @@ -135,9 +137,15 @@ void GlROIActor::UpdateData() void GlROIActor::Render() { - glColor3d(m_Color[0],m_Color[1],m_Color[2]); + m_Shader->LoadShader(); + m_Shader->SetupShader(); + + otb::MinimalShader::Pointer shader = + otb::DynamicCast< otb::MinimalShader >(m_Shader); + int colorIdx = shader->GetColorIdx(); glBegin(GL_LINE_LOOP); + glVertexAttrib4f(colorIdx, m_Color[0],m_Color[1],m_Color[2], 1.0); glVertex2d(m_VpUL[0],m_VpUL[1]); glVertex2d(m_VpUR[0],m_VpUR[1]); glVertex2d(m_VpLR[0],m_VpLR[1]); @@ -148,8 +156,8 @@ void GlROIActor::Render() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4d(m_Color[0],m_Color[1],m_Color[2],m_Alpha); glBegin(GL_QUADS); + glVertexAttrib4f(colorIdx, m_Color[0],m_Color[1],m_Color[2], m_Alpha); glVertex2d(m_VpUL[0],m_VpUL[1]); glVertex2d(m_VpUR[0],m_VpUR[1]); glVertex2d(m_VpLR[0],m_VpLR[1]); @@ -157,8 +165,18 @@ void GlROIActor::Render() glEnd(); glDisable(GL_BLEND); } + + m_Shader->UnloadShader(); } +void GlROIActor::CreateShader() +{ + if (m_Shader.IsNull()) + { + MinimalShader::Pointer shader( MinimalShader::New() ); + m_Shader = shader; + } +} void GlROIActor::UpdateTransforms() { diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index 7cc7a7ed47..dfb4ad4c30 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -87,6 +87,12 @@ void GlView::BeforeRendering() if(it->second->GetVisible()) { it->second->ProcessViewSettings(); + Shader* shader = it->second->GetShader(); + if (shader) + { + shader->m_ProjMatrix = m_ProjMatrix; + shader->m_ModelViewMatrix = m_ModelViewMatrix; + } } } @@ -111,6 +117,23 @@ void GlView::BeforeRendering() glOrtho(ulx, lrx, lry, uly, -1, 1); + m_ProjMatrix[0] = 2.0/(lrx-ulx); + m_ProjMatrix[1] = 0.0; + m_ProjMatrix[2] = 0.0; + m_ProjMatrix[3] = 0.0; + m_ProjMatrix[4] = 0.0; + m_ProjMatrix[5] = 2.0/(uly-lry); + m_ProjMatrix[6] = 0.0; + m_ProjMatrix[7] = 0.0; + m_ProjMatrix[8] = 0.0; + m_ProjMatrix[9] = 0.0; + m_ProjMatrix[10] = -1.0; + m_ProjMatrix[11] = 0.0; + m_ProjMatrix[12] = -(lrx+ulx)/(lrx-ulx); + m_ProjMatrix[13] = -(uly+lry)/(uly-lry); + m_ProjMatrix[14] = 0.0; + m_ProjMatrix[15] = 1.0; + // std::cout // << "glOrtho( " // << ulx << ", " << lrx << ", " @@ -127,6 +150,50 @@ void GlView::BeforeRendering() glRotatef(-m_Settings->GetRotationAngle()*180/M_PI,0,0,1); glTranslatef(-m_Settings->GetRotationCenter()[0],-m_Settings->GetRotationCenter()[1],0); + double ra = -m_Settings->GetRotationAngle(); + if(ra == 0.0) + { + m_ModelViewMatrix[0] = 1.0; + m_ModelViewMatrix[1] = 0.0; + m_ModelViewMatrix[2] = 0.0; + m_ModelViewMatrix[3] = 0.0; + m_ModelViewMatrix[4] = 0.0; + m_ModelViewMatrix[5] = 1.0; + m_ModelViewMatrix[6] = 0.0; + m_ModelViewMatrix[7] = 0.0; + m_ModelViewMatrix[8] = 0.0; + m_ModelViewMatrix[9] = 0.0; + m_ModelViewMatrix[10] = 1.0; + m_ModelViewMatrix[11] = 0.0; + m_ModelViewMatrix[12] = 0.0; + m_ModelViewMatrix[13] = 0.0; + m_ModelViewMatrix[14] = 0.0; + m_ModelViewMatrix[15] = 1.0; + } + else + { + double rcx = m_Settings->GetRotationCenter()[0]; + double rcy = m_Settings->GetRotationCenter()[1]; + double cos_a = cos(ra); + double sin_a = sin(ra); + m_ModelViewMatrix[0] = cos_a; + m_ModelViewMatrix[1] = sin_a; + m_ModelViewMatrix[2] = 0.0; + m_ModelViewMatrix[3] = 0.0; + m_ModelViewMatrix[4] = -sin_a; + m_ModelViewMatrix[5] = cos_a; + m_ModelViewMatrix[6] = 0.0; + m_ModelViewMatrix[7] = 0.0; + m_ModelViewMatrix[8] = 0.0; + m_ModelViewMatrix[9] = 0.0; + m_ModelViewMatrix[10] = 1.0; + m_ModelViewMatrix[11] = 0.0; + m_ModelViewMatrix[12] = rcx * (1.0 - cos_a) + rcy * sin_a; + m_ModelViewMatrix[13] = -rcx * sin_a + rcy * (1.0 - cos_a); + m_ModelViewMatrix[14] = 0.0; + m_ModelViewMatrix[15] = 1.0; + } + // glScalef(m_Settings->GetSpacing()[0],m_Settings->GetSpacing()[1],1); } diff --git a/Modules/Visualization/Ice/src/otbMinimalShader.cxx b/Modules/Visualization/Ice/src/otbMinimalShader.cxx index bd21e19f86..e95c1e9661 100644 --- a/Modules/Visualization/Ice/src/otbMinimalShader.cxx +++ b/Modules/Visualization/Ice/src/otbMinimalShader.cxx @@ -39,6 +39,7 @@ MinimalShader::MinimalShader() m_Loc.modelview = glGetUniformLocation(m_Program, "in_mv"); // - for fragment shader + m_ColorIdx = glGetAttribLocation(m_Program , "in_color"); } MinimalShader::~MinimalShader() diff --git a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx index 462eae2746..0a6d98b654 100644 --- a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx +++ b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx @@ -40,7 +40,11 @@ ShaderRegistry::Pointer ShaderRegistry::Instance() if(m_Instance.IsNull()) { m_Instance = ShaderRegistry::New(); - glewInit(); + GLenum err = glewInit(); + if (err != GLEW_OK) + { + itkGenericExceptionMacro(<< "Failed to initialize GLEW: "<< glewGetErrorString(err)); + } } return m_Instance; @@ -151,7 +155,7 @@ unsigned int ShaderRegistry::GetShaderProgram(const std::string& name) unsigned int ShaderRegistry::CompileShader(int stype, const std::string& name, const std::string& src) { - GLuint shader = glCreateShader(stype); + GLuint shader = glCreateShader(stype); // compile the sources const char * source_cstr = src.c_str(); diff --git a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx index 452b69557f..0881ae2151 100644 --- a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx +++ b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx @@ -1223,6 +1223,8 @@ void IceViewer::key_callback(GLFWwindow* window, int key, int scancode, int acti roiActor->SetFill(true); roiActor->SetAlpha(0.2); + + roiActor->CreateShader(); m_View->AddActor(roiActor,tmpKey); m_View->MoveActorToEndOfRenderingOrder(tmpKey,true); diff --git a/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx b/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx index b42429973b..82c48ae732 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx @@ -163,6 +163,8 @@ QuicklookViewRenderer return; #endif + m_GlRoiActor->CreateShader(); + std::string key( m_GlView->AddActor( m_GlRoiActor, "ROI" ) ); m_GlRoiActor->SetVisible( true ); -- GitLab From 539994018dead15b35cfa1297b1c31da018f0e0a Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 22 Aug 2019 11:47:14 +0200 Subject: [PATCH 11/73] REFAC: #1930: set OpenGL context before initializing GlActors --- Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx index 02bd703710..7570c6d4ab 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx @@ -239,6 +239,8 @@ ImageViewWidget // Set projection parameters of manipulator from layer data. OnSetProjectionRequired(); + makeCurrent(); + // Insert image-models into image-view renderer. m_Renderer->SetLayerStack( stackedLayerModel ); -- GitLab From 09c7c7b46fd1476e47caa16f836ca78bd9c40aec Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 22 Aug 2019 16:53:38 +0200 Subject: [PATCH 12/73] REFAC: #1930: remove default OpenGL matrices, Ortho/Translate/Rotate --- .../Ice/include/otbGlVectorActor.h | 4 ++++ .../Ice/src/otbGlVectorActor.cxx | 24 +++++++++++++++---- Modules/Visualization/Ice/src/otbGlView.cxx | 21 ---------------- .../IceViewer/src/otbIceViewer.cxx | 2 ++ 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlVectorActor.h b/Modules/Visualization/Ice/include/otbGlVectorActor.h index a919f73334..21803dd76e 100644 --- a/Modules/Visualization/Ice/include/otbGlVectorActor.h +++ b/Modules/Visualization/Ice/include/otbGlVectorActor.h @@ -82,6 +82,8 @@ public: // Gl rendering of current state void Render() override; + void CreateShader() override; + PointType ViewportToVectorTransform(const PointType & point) const; itkSetMacro(Color,ColorType); @@ -180,6 +182,8 @@ private: RigidTransformType::Pointer m_ViewportForwardRotationTransform; RigidTransformType::Pointer m_ViewportBackwardRotationTransform; + int m_ColorIdx; + }; // End class GlVectorActor } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx index adb9182b6e..26532807db 100644 --- a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx @@ -20,6 +20,8 @@ #include "otbGlVectorActor.h" #include "otbViewSettings.h" +#include "otbMinimalShader.h" +#include "otbCast.h" #ifdef _WIN32 #include @@ -106,8 +108,8 @@ GlVectorActor::GlVectorActor() m_OptimizedRenderingActive(false), m_PointMarkerSize(5), m_ViewportForwardRotationTransform(RigidTransformType::New()), - m_ViewportBackwardRotationTransform(RigidTransformType::New()) - + m_ViewportBackwardRotationTransform(RigidTransformType::New()), + m_ColorIdx(0) { m_Color.Fill(0); m_Color[0]=1.0; @@ -137,6 +139,16 @@ GlVectorActor::~GlVectorActor() } +void GlVectorActor::CreateShader() +{ + if (m_Shader.IsNull()) + { + MinimalShader::Pointer shader( MinimalShader::New() ); + m_Shader = shader; + m_ColorIdx = shader->GetColorIdx(); + } +} + void GlVectorActor::SetFill(bool flag) { if(m_Fill != flag) @@ -624,17 +636,21 @@ void GlVectorActor::Render() UpdateDisplayList(); } + m_Shader->LoadShader(); + m_Shader->SetupShader(); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glLineWidth(m_LineWidth); - glColor4d(m_Color[0],m_Color[1],m_Color[2],m_Alpha); + glVertexAttrib4f(m_ColorIdx, m_Color[0],m_Color[1],m_Color[2], m_Alpha); glCallList(m_DisplayList); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); - + + m_Shader->UnloadShader(); } diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index dfb4ad4c30..ad94cacc71 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -105,9 +105,6 @@ void GlView::BeforeRendering() glClear( GL_COLOR_BUFFER_BIT ); // Setup projection according to view settings - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - double ulx = -1.0; double uly = -1.0; double lrx = 1.0; @@ -115,8 +112,6 @@ void GlView::BeforeRendering() m_Settings->GetViewportExtent(ulx,uly,lrx,lry); - glOrtho(ulx, lrx, lry, uly, -1, 1); - m_ProjMatrix[0] = 2.0/(lrx-ulx); m_ProjMatrix[1] = 0.0; m_ProjMatrix[2] = 0.0; @@ -134,22 +129,6 @@ void GlView::BeforeRendering() m_ProjMatrix[14] = 0.0; m_ProjMatrix[15] = 1.0; - // std::cout - // << "glOrtho( " - // << ulx << ", " << lrx << ", " - // << lry << ", " << uly - // << ", -1, 1 )" - // << std::endl; - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glPushMatrix(); - - glTranslatef(m_Settings->GetRotationCenter()[0],m_Settings->GetRotationCenter()[1],0); - glRotatef(-m_Settings->GetRotationAngle()*180/M_PI,0,0,1); - glTranslatef(-m_Settings->GetRotationCenter()[0],-m_Settings->GetRotationCenter()[1],0); - double ra = -m_Settings->GetRotationAngle(); if(ra == 0.0) { diff --git a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx index 0881ae2151..c63a92b32f 100644 --- a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx +++ b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx @@ -176,6 +176,8 @@ void IceViewer::AddVector(const std::string & fname, const std::string & key, co m_ColorMapIterator = m_ColorMap.begin(); } + actor->CreateShader(); + m_View->AddActor(actor,key); // Add other layers if the dataset contains some -- GitLab From afd01444e4546867fc1a380393b466153d51445b Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 3 Sep 2019 14:50:33 +0200 Subject: [PATCH 13/73] REFAC: #1930: use a vector to store all attribute indexes --- Modules/Visualization/Ice/include/otbShader.h | 4 ++++ Modules/Visualization/Ice/include/otbStandardShader.h | 4 ---- Modules/Visualization/Ice/src/otbShader.cxx | 6 ++++++ Modules/Visualization/Ice/src/otbStandardShader.cxx | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index 51c5d787e3..7bbfc5b1ef 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -58,6 +58,8 @@ public: //~ itkGetConstReferenceMacro(LL,PointType); //~ itkGetConstReferenceMacro(LR,PointType); + const std::vector & GetAttribIdx(); + protected: Shader(); @@ -81,6 +83,8 @@ protected: /** ModelView matrix */ const float * m_ModelViewMatrix; + std::vector m_AttribIdx; + private: // prevent implementation Shader(const Self&); diff --git a/Modules/Visualization/Ice/include/otbStandardShader.h b/Modules/Visualization/Ice/include/otbStandardShader.h index 29be6a1ebb..6974adc488 100644 --- a/Modules/Visualization/Ice/include/otbStandardShader.h +++ b/Modules/Visualization/Ice/include/otbStandardShader.h @@ -94,8 +94,6 @@ public: itkNewMacro(Self); - itkGetMacro(TextureCoordIdx,int); - protected: StandardShader(); @@ -153,8 +151,6 @@ private: }; UniformLocs m_Loc; - - int m_TextureCoordIdx; }; // End class StandardShader } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx index 8c493e7f1a..ea444ba04b 100644 --- a/Modules/Visualization/Ice/src/otbShader.cxx +++ b/Modules/Visualization/Ice/src/otbShader.cxx @@ -80,4 +80,10 @@ void Shader::SetupShader() // glUniform2f(shader_lr,m_LR[0],m_LR[1]); } +const std::vector & +Shader::GetAttribIdx() +{ + return m_AttribIdx; +} + } diff --git a/Modules/Visualization/Ice/src/otbStandardShader.cxx b/Modules/Visualization/Ice/src/otbStandardShader.cxx index c19d280387..828e15322c 100644 --- a/Modules/Visualization/Ice/src/otbStandardShader.cxx +++ b/Modules/Visualization/Ice/src/otbStandardShader.cxx @@ -73,7 +73,8 @@ StandardShader::StandardShader() : m_Loc.slider_pos = glGetUniformLocation(m_Program, "shader_slider_pos"); m_Loc.vertical_slider_flag = glGetUniformLocation(m_Program, "shader_vertical_slider_flag"); - m_TextureCoordIdx = glGetAttribLocation(m_Program , "in_coord"); + m_AttribIdx.push_back( glGetAttribLocation(m_Program, "position") ); + m_AttribIdx.push_back( glGetAttribLocation(m_Program , "in_coord") ); } StandardShader::~StandardShader() @@ -91,6 +92,7 @@ std::string StandardShader::GetVertexSource() const shader_source+="#version 130 \n"; } shader_source += + "in vec4 position;\n" \ "in vec2 in_coord;\n" \ "out vec2 tex_coord;\n" \ "uniform mat4 in_proj;\n" \ @@ -98,7 +100,7 @@ std::string StandardShader::GetVertexSource() const "void main()\n" \ "{\n" \ "tex_coord = in_coord;\n" \ - "gl_Position = in_proj * in_mv * gl_Vertex;\n" \ + "gl_Position = in_proj * in_mv * position;\n" \ "}"; return shader_source; -- GitLab From f78fa5a8c84fb876e472342a0acf739602d711e4 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 3 Sep 2019 14:56:11 +0200 Subject: [PATCH 14/73] REFAC: #1930: force GLEW to use modern OpenGL during glewInit() --- Modules/Visualization/Ice/src/otbShaderRegistry.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx index 0a6d98b654..9e4a088988 100644 --- a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx +++ b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx @@ -40,6 +40,7 @@ ShaderRegistry::Pointer ShaderRegistry::Instance() if(m_Instance.IsNull()) { m_Instance = ShaderRegistry::New(); + glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err != GLEW_OK) { -- GitLab From 0cfb57daae6688299db56f1a4799ccaf33837057 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 3 Sep 2019 15:11:08 +0200 Subject: [PATCH 15/73] REFAC: #1930: use VA/VBO for GlImageActor --- .../Ice/include/otbGlImageActor.h | 11 +- .../Visualization/Ice/src/otbGlImageActor.cxx | 325 +++++++----------- 2 files changed, 138 insertions(+), 198 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 1ee1196809..82fd1a377b 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -124,10 +124,6 @@ public: itkSetMacro(TileSize,unsigned int); itkGetMacro(TileSize,unsigned int); - itkBooleanMacro(SoftwareRendering ); - itkSetMacro(SoftwareRendering, bool ); - itkGetMacro(SoftwareRendering, bool ); - void CreateShader() override; void SetResolutionAlgorithm(ResolutionAlgorithm::type alg) @@ -313,7 +309,12 @@ private: ResolutionAlgorithm::type m_ResolutionAlgorithm; - bool m_SoftwareRendering; + // index of Vertex Array Object + unsigned int m_VAO; + + // index of Vector Buffer Object + unsigned int m_VBO; + }; // End class GlImageActor } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 6a1e655731..24ef203745 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -54,7 +54,8 @@ GlImageActor::GlImageActor() m_ViewportForwardRotationTransform(RigidTransformType::New()), m_ViewportBackwardRotationTransform(RigidTransformType::New()), m_ResolutionAlgorithm(ResolutionAlgorithm::Nearest), - m_SoftwareRendering(false) + m_VAO(0), + m_VBO(0) {} GlImageActor @@ -78,6 +79,63 @@ GlImageActor StandardShader::Pointer shader( StandardShader::New() ); shader->SetImageSettings( m_ImageSettings ); m_Shader = shader; + + // Use a Vertex Array Object + glGenVertexArrays(1, &m_VAO); + glBindVertexArray(m_VAO); + + // 1 square (made by 2 triangles) to be rendered + GLfloat vertexPosition[8] = { + -1.0, -1.0, + 1.0, -1.0, + 1.0, 1.0, + -1.0, 1.0 + }; + + GLfloat texCoord[8] = { + 0.0, 1.0, + 1.0, 1.0, + 1.0, 0.0, + 0.0, 0.0, + }; + + GLuint indices[6] = { + 0, 1, 2, + 2, 3, 0 + }; + + // Create a Vector Buffer Object that will store the vertices on video memory + glGenBuffers(1, &m_VBO); + + // Allocate space for vertex positions and texture coordinates + glBindBuffer(GL_ARRAY_BUFFER, m_VBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPosition) + sizeof(texCoord), NULL, GL_STATIC_DRAW); + + // Transfer the vertex positions: + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + + // Transfer the texture coordinates: + glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertexPosition), sizeof(texCoord), texCoord); + + // Create an Element Array Buffer that will store the indices array: + GLuint eab; + glGenBuffers(1, &eab); + + // Transfer the data from indices to eab + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + + // get attribute position for position and in_coord + int posIdx = m_Shader->GetAttribIdx()[0]; + int texIdx = m_Shader->GetAttribIdx()[1]; + + // Specify how the data for position can be accessed + glVertexAttribPointer(posIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(posIdx); + + // Texture coord attribute + glVertexAttribPointer(texIdx, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *)sizeof(vertexPosition)); + glEnableVertexAttribArray(texIdx); } } @@ -324,138 +382,20 @@ void GlImageActor::Render() // std::cout // << "otb::GlImageActor@" << std::hex << this << std::dec << std::endl // << "\tresolution: " << m_ResolutionAlgorithm << std::endl - // << "\tpixel: " << m_SoftwareRendering << std::endl // << "\ttile: " << m_TileSize << std::endl; - if( !m_SoftwareRendering && !m_Shader.IsNull() ) - { - // std::cout << "\tGLSL" << std::endl; - - m_Shader->LoadShader(); - m_Shader->SetupShader(); - } - else - { - // std::cout << "\tOTB" << std::endl; - - for(TileVectorType::iterator it = m_LoadedTiles.begin(); - it != m_LoadedTiles.end(); ++it) - { - if(!it->m_RescaleFilter) - { - it->m_RescaleFilter = RescaleFilterType::New(); - it->m_RescaleFilter->AutomaticInputMinMaxComputationOff(); - it->m_RescaleFilter->SetInput(it->m_Image); - } - - VectorImageType::PixelType mins(3),maxs(3),omins(3),omaxs(3); - mins.Fill(0); - maxs.Fill(255); - - double noData(0.); + m_Shader->LoadShader(); + m_Shader->SetupShader(); - assert( !m_ImageSettings.IsNull() ); - - mins[ 0 ] = m_ImageSettings->GetMinRed(); - mins[ 1 ] = m_ImageSettings->GetMinGreen(); - mins[ 2 ] = m_ImageSettings->GetMinBlue(); - - maxs[ 0 ] = m_ImageSettings->GetMaxRed(); - maxs[ 1 ] = m_ImageSettings->GetMaxGreen(); - maxs[ 2 ] = m_ImageSettings->GetMaxBlue(); - - // MANTIS-1204 - // { - double gamma = m_ImageSettings->GetGamma(); - - gamma = - gamma == 0.0 - ? std::numeric_limits< double >::max() - : 1.0 / gamma; - // } - - - if( m_ImageSettings->GetUseNoData() ) - noData = m_ImageSettings->GetNoData(); + GLfloat vertexPosition[8] = { + -1.0, -1.0, + 1.0, -1.0, + 1.0, 1.0, + -1.0, 1.0 + }; - - omins.Fill( 0 ); - omaxs.Fill( 255 ); - - it->m_RescaleFilter->SetInputMinimum(mins); - it->m_RescaleFilter->SetInputMaximum(maxs); - it->m_RescaleFilter->SetOutputMinimum(omins); - it->m_RescaleFilter->SetOutputMaximum(omaxs); - it->m_RescaleFilter->SetGamma(gamma); - - it->m_RescaleFilter->Update(); - - - itk::ImageRegionConstIterator imIt(it->m_RescaleFilter->GetOutput(),it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion()); - itk::ImageRegionConstIterator inIt(it->m_Image,it->m_Image->GetLargestPossibleRegion()); - - - - unsigned char * buffer = new unsigned char[4*it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; - - unsigned int idx = 0; - - for(imIt.GoToBegin(),inIt.GoToBegin();!imIt.IsAtEnd()&&!inIt.IsAtEnd();++imIt,++inIt) - { - buffer[idx] = static_cast(imIt.Get()[2]); - ++idx; - buffer[idx] = static_cast(imIt.Get()[1]); - ++idx; - buffer[idx] = static_cast(imIt.Get()[0]); - ++idx; - buffer[idx] = 255; - - if(m_ImageSettings->GetUseNoData() && (inIt.Get()[0] == noData ||inIt.Get()[1] == noData ||inIt.Get()[2] == noData)) - { - buffer[idx] = 0; - } - - ++idx; - } - - if(!it->m_TextureId) - { - glGenTextures(1, &(it->m_TextureId)); - } - glBindTexture(GL_TEXTURE_2D, it->m_TextureId); -#if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); -#endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -// #if defined(GL_CLAMP_TO_BORDER) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); -// #elif defined (GL_CLAMP_TO_BORDER_EXT) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); -// #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); -// #endif - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGBA8, - it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0], - it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[1], - 0, GL_BGRA, GL_UNSIGNED_BYTE, - buffer); - - it->m_Loaded = true; - - delete [] buffer; - } - } - - otb::StandardShader::Pointer shader = - otb::DynamicCast< otb::StandardShader >(m_Shader); - int texCoord = shader->GetTextureCoordIdx(); + glBindVertexArray(m_VAO); + glBindBuffer(GL_ARRAY_BUFFER, m_VBO); for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) @@ -463,8 +403,7 @@ void GlImageActor::Render() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D,it->m_TextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -478,23 +417,26 @@ void GlImageActor::Render() } // Reset color before rendering - glColor4d(1.0f,1.0f,1.0f, m_ImageSettings->GetAlpha()); - - glBegin (GL_QUADS); - glVertexAttrib2f(texCoord, 0.0, 1.0); glVertex2f(it->m_LL[0], it->m_LL[1]); - glVertexAttrib2f(texCoord, 1.0, 1.0); glVertex2f(it->m_LR[0], it->m_LR[1]); - glVertexAttrib2f(texCoord, 1.0, 0.0); glVertex2f(it->m_UR[0], it->m_UR[1]); - glVertexAttrib2f(texCoord, 0.0, 0.0); glVertex2f(it->m_UL[0], it->m_UL[1]); - glEnd (); - - glDisable(GL_TEXTURE_2D); + //glColor4d(1.0f,1.0f,1.0f, m_ImageSettings->GetAlpha()); + + vertexPosition[0] = it->m_LL[0]; + vertexPosition[1] = it->m_LL[1]; + vertexPosition[2] = it->m_LR[0]; + vertexPosition[3] = it->m_LR[1]; + vertexPosition[4] = it->m_UR[0]; + vertexPosition[5] = it->m_UR[1]; + vertexPosition[6] = it->m_UL[0]; + vertexPosition[7] = it->m_UL[1]; + + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + + glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + glDisable(GL_BLEND); } - if( !m_SoftwareRendering && !m_Shader.IsNull() ) - { - m_Shader->UnloadShader(); - } + m_Shader->UnloadShader(); + } void GlImageActor::LoadTile(Tile& tile) @@ -526,46 +468,44 @@ void GlImageActor::LoadTile(Tile& tile) tile.m_Image = extract->GetOutput(); - if(!m_SoftwareRendering) + itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); + + float * buffer = new float[4*extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; + + unsigned int idx = 0; + + for(it.GoToBegin();!it.IsAtEnd();++it) { - itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); - - float * buffer = new float[4*extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; - - unsigned int idx = 0; - - for(it.GoToBegin();!it.IsAtEnd();++it) - { - buffer[idx] = static_cast(it.Get()[2]); - ++idx; - buffer[idx] = static_cast(it.Get()[1]); - ++idx; - buffer[idx] = static_cast(it.Get()[0]); - ++idx; - buffer[idx] = 255.; - ++idx; - } - - // Now load the texture - assert( tile.m_TextureId==0 ); + buffer[idx] = static_cast(it.Get()[2]); + ++idx; + buffer[idx] = static_cast(it.Get()[1]); + ++idx; + buffer[idx] = static_cast(it.Get()[0]); + ++idx; + buffer[idx] = 255.; + ++idx; + } + + // Now load the texture + assert( tile.m_TextureId==0 ); - glGenTextures( 1, &tile.m_TextureId ); + glGenTextures( 1, &tile.m_TextureId ); - // Following assert is sometimes false on some OpenGL systems for - // some unknown reason even though the glGenTexture() call has - // succeeded. - // assert( glGetError()==GL_NO_ERROR ); + // Following assert is sometimes false on some OpenGL systems for + // some unknown reason even though the glGenTexture() call has + // succeeded. + // assert( glGetError()==GL_NO_ERROR ); - assert( tile.m_TextureId!=0 ); + assert( tile.m_TextureId!=0 ); - // std::cout << "Generated texture #" << tile.m_TextureId << std::endl; + // std::cout << "Generated texture #" << tile.m_TextureId << std::endl; - glBindTexture(GL_TEXTURE_2D, tile.m_TextureId); + glBindTexture(GL_TEXTURE_2D, tile.m_TextureId); #if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); #endif - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); // #if defined(GL_CLAMP_TO_BORDER) // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); @@ -573,23 +513,22 @@ void GlImageActor::LoadTile(Tile& tile) // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); // #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); // #endif - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGB32F, - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], - 0, GL_BGRA, GL_FLOAT, - buffer); - - tile.m_Loaded = true; - - delete [] buffer; - } - - // And push to loaded texture - m_LoadedTiles.push_back(tile); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB32F, + extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], + extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], + 0, GL_BGRA, GL_FLOAT, + buffer); + + tile.m_Loaded = true; + + delete [] buffer; + + // And push to loaded texture + m_LoadedTiles.push_back(tile); } void GlImageActor::UnloadTile(Tile& tile) -- GitLab From 91424feb843bdc46385f545b183d1428f73765a1 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 11 Sep 2019 15:39:04 +0200 Subject: [PATCH 16/73] Removed defensive code. --- .../Visualization/Ice/src/otbGlImageActor.cxx | 193 +++++++++--------- 1 file changed, 101 insertions(+), 92 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 24ef203745..bc727bf98a 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -21,9 +21,11 @@ #include "otbGlImageActor.h" #include "otbViewSettings.h" #include "otbMath.h" + #ifdef _WIN32 -#include +# include #endif + #include #include "otbStandardShader.h" @@ -32,9 +34,11 @@ #include "otbListSampleToHistogramListGenerator.h" #include "otbCast.h" + namespace otb { + GlImageActor::GlImageActor() : m_TileSize(256), m_FileName(), @@ -74,69 +78,74 @@ void GlImageActor ::CreateShader() { - if (m_Shader.IsNull()) - { - StandardShader::Pointer shader( StandardShader::New() ); - shader->SetImageSettings( m_ImageSettings ); - m_Shader = shader; + assert( m_Shader.IsNull() ); - // Use a Vertex Array Object - glGenVertexArrays(1, &m_VAO); - glBindVertexArray(m_VAO); + std::cerr << "GlImageActor::CreateShader()" << std::endl; - // 1 square (made by 2 triangles) to be rendered - GLfloat vertexPosition[8] = { - -1.0, -1.0, - 1.0, -1.0, - 1.0, 1.0, - -1.0, 1.0 - }; + StandardShader::Pointer shader( StandardShader::New() ); - GLfloat texCoord[8] = { - 0.0, 1.0, - 1.0, 1.0, - 1.0, 0.0, - 0.0, 0.0, - }; + shader->SetImageSettings( m_ImageSettings ); - GLuint indices[6] = { - 0, 1, 2, - 2, 3, 0 - }; + // Use a Vertex Array Object + glGenVertexArrays(1, &m_VAO); + glBindVertexArray(m_VAO); - // Create a Vector Buffer Object that will store the vertices on video memory - glGenBuffers(1, &m_VBO); + // 1 square (made by 2 triangles) to be rendered + GLfloat vertexPosition[8] = { + -1.0, -1.0, + 1.0, -1.0, + 1.0, 1.0, + -1.0, 1.0 + }; + + GLfloat texCoord[8] = { + 0.0, 1.0, + 1.0, 1.0, + 1.0, 0.0, + 0.0, 0.0, + }; + + GLuint indices[6] = { + 0, 1, 2, + 2, 3, 0 + }; + + // Create a Vector Buffer Object that will store the vertices on video memory + glGenBuffers(1, &m_VBO); + + // Allocate space for vertex positions and texture coordinates + glBindBuffer(GL_ARRAY_BUFFER, m_VBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPosition) + sizeof(texCoord), NULL, GL_STATIC_DRAW); - // Allocate space for vertex positions and texture coordinates - glBindBuffer(GL_ARRAY_BUFFER, m_VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPosition) + sizeof(texCoord), NULL, GL_STATIC_DRAW); + // Transfer the vertex positions: + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); - // Transfer the vertex positions: - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + // Transfer the texture coordinates: + glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertexPosition), sizeof(texCoord), texCoord); - // Transfer the texture coordinates: - glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertexPosition), sizeof(texCoord), texCoord); + // Create an Element Array Buffer that will store the indices array: + GLuint eab; + glGenBuffers(1, &eab); - // Create an Element Array Buffer that will store the indices array: - GLuint eab; - glGenBuffers(1, &eab); + // Transfer the data from indices to eab + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); - // Transfer the data from indices to eab - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + // get attribute position for position and in_coord + int posIdx = shader->GetAttribIdx()[0]; + int texIdx = shader->GetAttribIdx()[1]; - // get attribute position for position and in_coord - int posIdx = m_Shader->GetAttribIdx()[0]; - int texIdx = m_Shader->GetAttribIdx()[1]; + // Specify how the data for position can be accessed + glVertexAttribPointer(posIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(posIdx); - // Specify how the data for position can be accessed - glVertexAttribPointer(posIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(posIdx); + // Texture coord attribute + glVertexAttribPointer(texIdx, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *)sizeof(vertexPosition)); + glEnableVertexAttribArray(texIdx); - // Texture coord attribute - glVertexAttribPointer(texIdx, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *)sizeof(vertexPosition)); - glEnableVertexAttribArray(texIdx); - } + // Should be done last in order to ensure exception-safety of + // invariant. + m_Shader = shader; } const GlImageActor::PointType & GlImageActor::GetOrigin() const @@ -272,11 +281,11 @@ void GlImageActor::ProcessViewSettings() m_ViewportForwardRotationTransform->SetParameters(rigidParameters); rigidParameters[0]=-settings->GetRotationAngle(); - + m_ViewportBackwardRotationTransform->SetParameters(rigidParameters); - + UpdateTransforms(); - + for (TileVectorType::iterator it = m_LoadedTiles.begin(); it!=m_LoadedTiles.end(); ++it) @@ -298,7 +307,7 @@ void GlImageActor::UpdateData() ViewSettings::ConstPointer settings = GetSettings(); RegionType largest( m_FileReader->GetOutput()->GetLargestPossibleRegion() ); - + double ulx, uly, lrx, lry; settings->GetViewportExtent(ulx,uly,lrx,lry); @@ -311,7 +320,7 @@ void GlImageActor::UpdateData() if( !requested.Crop( largest ) ) return; - + // Now we have the requested part of image, we need to find the // corresponding tiles @@ -321,22 +330,22 @@ void GlImageActor::UpdateData() //unsigned int nbTilesY = std::ceil(static_cast(requested.GetSize()[1])/m_TileSize); unsigned int tileStartX = m_TileSize*(requested.GetIndex()[0]/m_TileSize); unsigned int tileStartY = m_TileSize*(requested.GetIndex()[1]/m_TileSize); - + SizeType tileSize; tileSize.Fill(m_TileSize); Tile newTile; - + for(unsigned int i = 0; i < nbTilesX; ++i) { for(unsigned int j = 0; j(tileStartX+i*m_TileSize); tileIndex[1] = static_cast(tileStartY+j*m_TileSize); - + newTile.m_ImageRegion.SetSize(tileSize); newTile.m_ImageRegion.SetIndex(tileIndex); @@ -400,13 +409,13 @@ void GlImageActor::Render() for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) { - + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D,it->m_TextureId); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if(m_CurrentResolution == 0) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -506,7 +515,7 @@ void GlImageActor::LoadTile(Tile& tile) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); #endif //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -// #if defined(GL_CLAMP_TO_BORDER) +// #if defined(GL_CLAMP_TO_BORDER) // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); // #elif defined (GL_CLAMP_TO_BORDER_EXT) @@ -519,7 +528,7 @@ void GlImageActor::LoadTile(Tile& tile) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], + extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], 0, GL_BGRA, GL_FLOAT, buffer); @@ -530,7 +539,7 @@ void GlImageActor::LoadTile(Tile& tile) // And push to loaded texture m_LoadedTiles.push_back(tile); } - + void GlImageActor::UnloadTile(Tile& tile) { // std::cout << std::hex << this << std::dec << "::UnloadTile()" << std::endl; @@ -559,13 +568,13 @@ void GlImageActor::CleanLoadedTiles() // Retrieve settings ViewSettings::ConstPointer settings = this->GetSettings(); - + double ulx, uly, lrx, lry; settings->GetViewportExtent(ulx,uly,lrx,lry); - + RegionType requested; - + this->ViewportExtentToImageRegion(ulx,uly,lrx,lry,requested); for(TileVectorType::iterator it = m_LoadedTiles.begin(); @@ -583,8 +592,8 @@ void GlImageActor::CleanLoadedTiles() // size might be smaller at images borders || it->m_TileSize!=m_TileSize) { - - + + // Tile will not be used anymore, unload it from GPU UnloadTile(*it); } @@ -614,7 +623,7 @@ void GlImageActor::ClearLoadedTiles() void GlImageActor::ImageRegionToViewportExtent(const RegionType& region, double & ulx, double & uly, double & lrx, double& lry) const { PointType tul,tur,tll,tlr; - + ImageRegionToViewportQuad(region,tul,tur,tll,tlr); // TODO: Take into account origin/scaling/rotation here ? @@ -630,9 +639,9 @@ void GlImageActor::ImageRegionToViewportQuad(const RegionType & region, PointTyp { // Retrieve settings ViewSettings::ConstPointer settings = this->GetSettings(); - + itk::ContinuousIndex cul,cur,cll,clr; - + cul[0] = region.GetIndex()[0]; cul[1] = region.GetIndex()[1]; cur = cul; @@ -659,7 +668,7 @@ void GlImageActor::ImageRegionToViewportQuad(const RegionType & region, PointTyp ill[1]+=0.5*spacing[1]; ilr[0]+=0.5*spacing[0]; ilr[1]+=0.5*spacing[1]; - + PointType pul = m_ImageToViewportTransform->TransformPoint(iul); PointType pur = m_ImageToViewportTransform->TransformPoint(iur); PointType pll = m_ImageToViewportTransform->TransformPoint(ill); @@ -672,7 +681,7 @@ void GlImageActor::ImageRegionToViewportQuad(const RegionType & region, PointTyp pll = m_ViewportBackwardRotationTransform->TransformPoint(pll); plr = m_ViewportBackwardRotationTransform->TransformPoint(plr); } - + ul[0] = pul[0]; ul[1] = pul[1]; ur[0] = pur[0]; @@ -691,7 +700,7 @@ void GlImageActor::ViewportExtentToImageRegion(const double& ulx, const double & RegionType largest = m_FileReader->GetOutput()->GetLargestPossibleRegion(); PointType ul,ur,ll,lr,tul,tur,tll,tlr; - + ul[0]=ulx; ul[1]=uly; ur[0]=lrx; @@ -700,7 +709,7 @@ void GlImageActor::ViewportExtentToImageRegion(const double& ulx, const double & ll[1]=lry; lr[0]=lrx; lr[1]=lry; - + tul = m_ViewportToImageTransform->TransformPoint(m_ViewportForwardRotationTransform->TransformPoint(ul)); tur = m_ViewportToImageTransform->TransformPoint(m_ViewportForwardRotationTransform->TransformPoint(ur)); tll = m_ViewportToImageTransform->TransformPoint(m_ViewportForwardRotationTransform->TransformPoint(ll)); @@ -712,7 +721,7 @@ void GlImageActor::ViewportExtentToImageRegion(const double& ulx, const double & m_FileReader->GetOutput()->TransformPhysicalPointToContinuousIndex(tur,cur); m_FileReader->GetOutput()->TransformPhysicalPointToContinuousIndex(tll,cll); m_FileReader->GetOutput()->TransformPhysicalPointToContinuousIndex(tlr,clr); - + // TODO: Take into account origin/scaling/rotation here ? // TODO: Screen to image / image to screen transform calls here ? @@ -721,21 +730,21 @@ void GlImageActor::ViewportExtentToImageRegion(const double& ulx, const double & iulx = std::max(std::min(std::min(cul[0],cur[0]),std::min(cll[0],clr[0])),0.); iuly = std::max(std::min(std::min(cul[1],cur[1]),std::min(cll[1],clr[1])),0.); ilrx = std::min(std::max(std::max(cul[0],cur[0]),std::max(cll[0],clr[0])),static_cast(largest.GetSize()[0])); - ilry = std::min(std::max(std::max(cul[1],cur[1]),std::max(cll[1],clr[1])),static_cast(largest.GetSize()[1])); + ilry = std::min(std::max(std::max(cul[1],cur[1]),std::max(cll[1],clr[1])),static_cast(largest.GetSize()[1])); // Now we have the requested part of image, we need to find the // corresponding tiles IndexType index; index[0] = static_cast(iulx); index[1] = static_cast(iuly); - + SizeType size; size[0] = static_cast(ilrx-iulx); size[1] = static_cast(ilry-iuly); - + region.SetSize(size); region.SetIndex(index); - + region.Crop(m_FileReader->GetOutput()->GetLargestPossibleRegion()); } @@ -765,7 +774,7 @@ GlImageActor::PointType GlImageActor::ImageToViewportTransform(const PointType & } PointType out = m_ImageToViewportTransform->TransformPoint(imgPoint); - + return m_ViewportBackwardRotationTransform->TransformPoint(out); } @@ -820,7 +829,7 @@ GlImageActor #else index[ 0 ] = static_cast< IndexType::IndexValueType >( - ( physical[ 0 ] + 0.5 * m_Spacing[0] - m_Origin[ 0 ] ) / + ( physical[ 0 ] + 0.5 * m_Spacing[0] - m_Origin[ 0 ] ) / m_Spacing[ 0 ] ); @@ -893,14 +902,14 @@ void GlImageActor::UpdateResolution() // Retrieve viewport spacing ViewSettings::SpacingType spacing = settings->GetSpacing(); - + // 100 screen pixels PointType pointA, pointB, pointC; pointA = settings->GetOrigin(); pointB = pointA; pointC = pointA; - + pointB[0]+=100*spacing[0]; pointC[1]+=100*spacing[1]; @@ -922,7 +931,7 @@ void GlImageActor::UpdateResolution() double distAB = std::sqrt((pointA[0]-pointB[0])*(pointA[0]-pointB[0])+(pointA[1]-pointB[1])*(pointA[1]-pointB[1])); double distAC = std::sqrt((pointA[0]-pointC[0])*(pointA[0]-pointC[0])+(pointA[1]-pointC[1])*(pointA[1]-pointC[1])); - + double resolution = std::min(100/distAB,100/distAC); // std::cout << std::endl; @@ -982,7 +991,7 @@ void GlImageActor::UpdateResolution() if(newResolution != m_CurrentResolution) { m_CurrentResolution = newResolution; - + std::ostringstream extFilename; extFilename<SetMeasurementVectorSize(3); - + if(full) { // Retrieve the lowest resolution @@ -1146,7 +1155,7 @@ void GlImageActor::AutoColorAdjustment( double & minRed, double & maxRed, extract->SetChannel(m_GreenIdx); extract->SetChannel(m_BlueIdx); extract->Update(); - + itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); for(it.GoToBegin();!it.IsAtEnd();++it) { @@ -1198,7 +1207,7 @@ void GlImageActor::AutoColorAdjustment( double & minRed, double & maxRed, minGreen = histogramsGenerator->GetOutput()->GetNthElement(1)->Quantile(0,lcp); maxGreen = histogramsGenerator->GetOutput()->GetNthElement(1)->Quantile(0,1-hcp); minBlue = histogramsGenerator->GetOutput()->GetNthElement(2)->Quantile(0,lcp); - maxBlue = histogramsGenerator->GetOutput()->GetNthElement(2)->Quantile(0,1-hcp); + maxBlue = histogramsGenerator->GetOutput()->GetNthElement(2)->Quantile(0,1-hcp); } -- GitLab From 17237a0c1d14210f303e5008355c5934a26754b4 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 19 Sep 2019 17:38:51 +0200 Subject: [PATCH 17/73] Added RAII capsules for OpenGL vertex-array-objects and buffer-objects. --- .../Ice/include/otbGlBufferObject.h | 218 ++++++++++++++++++ .../Visualization/Ice/include/otbGlError.h | 96 ++++++++ Modules/Visualization/Ice/include/otbGlMesh.h | 102 ++++++++ .../Ice/include/otbGlTypeTraits.h | 78 +++++++ .../Ice/include/otbGlVertexArrayObject.h | 76 ++++++ Modules/Visualization/Ice/src/CMakeLists.txt | 14 +- .../Ice/src/otbGlBufferObject.cxx | 28 +++ Modules/Visualization/Ice/src/otbGlError.cxx | 52 +++++ Modules/Visualization/Ice/src/otbGlMesh.cxx | 111 +++++++++ .../Visualization/Ice/src/otbGlTypeTraits.cxx | 28 +++ .../Ice/src/otbGlVertexArrayObject.cxx | 106 +++++++++ 11 files changed, 905 insertions(+), 4 deletions(-) create mode 100644 Modules/Visualization/Ice/include/otbGlBufferObject.h create mode 100644 Modules/Visualization/Ice/include/otbGlError.h create mode 100644 Modules/Visualization/Ice/include/otbGlMesh.h create mode 100644 Modules/Visualization/Ice/include/otbGlTypeTraits.h create mode 100644 Modules/Visualization/Ice/include/otbGlVertexArrayObject.h create mode 100644 Modules/Visualization/Ice/src/otbGlBufferObject.cxx create mode 100644 Modules/Visualization/Ice/src/otbGlError.cxx create mode 100644 Modules/Visualization/Ice/src/otbGlMesh.cxx create mode 100644 Modules/Visualization/Ice/src/otbGlTypeTraits.cxx create mode 100644 Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx diff --git a/Modules/Visualization/Ice/include/otbGlBufferObject.h b/Modules/Visualization/Ice/include/otbGlBufferObject.h new file mode 100644 index 0000000000..7fd04f798b --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlBufferObject.h @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlBufferObject_h +#define otb_GlBufferObject_h + +#include "OTBIceExport.h" + + +#include "otbGlError.h" +#include "otbGlTypeTraits.h" + + +#include + +#ifndef bool_str +# define bool_str( b ) ( ( b ) ? "true" : "false" ) +#endif + +namespace otb { namespace gl { + + +/** OpenGL element-type of buffer-object. + */ +enum class element : GLenum +{ + vertex = GL_ARRAY_BUFFER, + index = GL_ELEMENT_ARRAY_BUFFER, +}; + + +/** + * @class OpenGL object. + */ +template< element E > +struct BufferObject +{ + /** Buffer identifier type. */ + using Id_t = otb::gl::Id_t; + + /** @return element type. */ + static constexpr + element + Element() noexcept + { + return E; + } + + /** Default constructor. */ + BufferObject() + { + Generate(); + Bind(); + } + + /** Construct and fill. */ + template< typename T > + BufferObject( std::initializer_list< T > data, + std::size_t components = 1 ) : + m_Count( data.size() ), + m_Size( sizeof( T ) ), + m_Components( components ), + m_GlType( TypeTraits< T >::value() ) + { + assert( data.size() ); + assert( components ); + + Generate(); + + Bind(); + + std::cerr + << "BufferObject #" << m_Id << " " << TypeTraits< T >::name() + << std::endl; + + std::cout << data.size() << " " << sizeof( T ) << std::endl; + + glBufferData( + static_cast< GLenum >( E ), + data.size() * sizeof( T ), + data.begin(), + GL_STATIC_DRAW + ); + + CheckError(); + } + + ~BufferObject() + { + Release(); + } + + BufferObject( BufferObject && rhs ) : + m_Id( std::exchange( rhs.m_Id, GL_ZERO ) ) + {} + + BufferObject & + operator = ( BufferObject && rhs ) + + { + Release(); + + m_Id = std::exchange( rhs.m_Id, GL_ZERO ); + + return *this; + } + + void + Bind( bool isEnabled = true ) const + { + assert( m_Id ); + +#if OTB_DEBUG + std::cerr << "glBindBuffer(" << m_Id << ") " << bool_str( isEnabled ) << std::endl; +#endif // OTB_DEBUG + + glBindBuffer( static_cast< GLenum >( E ), isEnabled ? m_Id : GL_ZERO ); + CheckError(); + } + + GLenum + GlType() const noexcept + { + return m_GlType; + } + + std::size_t + Size() const noexcept + { + return m_Size; + } + + std::size_t + Stride( std::size_t components ) const noexcept + { + assert( m_Size>0 ); + assert( m_Components>0 ); + + assert( components<=m_Components ); + + return m_Size * ( m_Components - components ); + } + +private: + void + Generate() + { +#if OTB_DEBUG + std::cerr << "glGenBuffers()" << std::endl; +#endif // OTB_DEBUG + + glGenBuffers( 1, &m_Id ); + assert( m_Id ); + +#if OTB_DEBUG + std::cerr << "-> " << m_Id << std::endl; +#endif // OTB_DEBUG + + CheckError(); + } + + void + Release() + { + if( m_Id==GL_ZERO ) + return; + +#if OTB_DEBUG + std::cerr << "glDeleteBuffers(" << m_Id << ")" << std::endl; +#endif // OTB_DEBUG + + CheckError< error::clear >(); + + glDeleteBuffers( 1, &m_Id ); + CheckError(); + + m_Id = GL_ZERO; + } + + Id_t m_Id = GL_ZERO; + std::size_t m_Count = 0; + std::size_t m_Size = 0; + std::size_t m_Components = 0; + GLenum m_GlType = GL_ZERO; +}; + + +// template<> class BufferObject< element::vertex >; +// template<> class BufferObject< element::index >; + + +using VertexBufferObject = BufferObject< element::vertex >; +using IndexBufferObject = BufferObject< element::index >; + + +} // end namespace gl. + +} // end namespace otb. + + +#endif // otb_GlBufferObject_h diff --git a/Modules/Visualization/Ice/include/otbGlError.h b/Modules/Visualization/Ice/include/otbGlError.h new file mode 100644 index 0000000000..efd3691c6a --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlError.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlError_h +#define otb_GlError_h + + +#include "OTBIceExport.h" + +#ifdef _WIN32 +# include +#endif + +#include + +#include +#include +#include + + +namespace otb { namespace gl { + +/** + * @class OpenGL-specific exception. + */ +struct OTBIce_EXPORT Error : public std::runtime_error +{ + /** Construct an OpenGL exception related to the OpenGL error code. + */ + Error( GLenum code ); + +}; // End class GlError + +enum class error : int +{ + clear = 0, + trace, + assertion, + exception, +}; + + +template< error E = error::exception > +GLenum +CheckError() +{ + GLenum glError = glGetError(); + + if( E>=error::trace ) + if( glError!=GL_NO_ERROR ) + std::cerr + << "OPenGL error #" << glError << ": '" << gluErrorString( glError ) << "'" + << std::endl; + + if( E>=error::assertion ) + assert( glError==GL_NO_ERROR ); + + // When assert is removed (NDEBUG) and Throw is false, this function + // body is emtpy and the C++ compiler should optimize the call by + // removing it. + // + // N.B.: equivalent of a scoped (and breakpoint-friendly) macro. + + // Condition is splitted because first is determined at compile time + // and may be removed (see above) and second is determined at + // runtime. + if( E>=error::exception ) + if( glError!=GL_NO_ERROR ) + throw Error( glError ); + + return glError; +} + +} // End of namespace gl. + +} // End namespace otb. + + +#endif // otb_GlError_h diff --git a/Modules/Visualization/Ice/include/otbGlMesh.h b/Modules/Visualization/Ice/include/otbGlMesh.h new file mode 100644 index 0000000000..c4c2f829b2 --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlMesh.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlMesh_h +#define otb_GlMesh_h + +#include "OTBIceExport.h" + + +#include "otbGlVertexArrayObject.h" +#include "otbGlBufferObject.h" + + +namespace otb { namespace gl { + +/** + * @class OpenGL mesh. + */ +struct Mesh +{ + Mesh() = default; + + template< typename VT, + typename IT = GLuint > + Mesh( std::initializer_list< VT > vertices, + std::size_t components, + std::initializer_list< IT > indices ) : + m_VBO( vertices, components ), + m_IBO( indices, 3 ) + {} + + Mesh( Mesh && ) = default; + + // Mesh & operator = ( Mesh && ) = default; + + // Mesh( Mesh && m ) : + // m_VAO( std::move( m.m_VAO ) ), + // m_VBO( std::move( m.m_VBO ) ), + // m_IBO( std::move( m.m_IBO ) ) + // {} + + + void + Bind( bool isEnabled = true ) + { + m_VAO.Bind( isEnabled ); + m_VBO.Bind( isEnabled ); + m_IBO.Bind( isEnabled ); + } + + void + VertexAttribPointer( VertexBufferObject::Id_t id, + std::size_t components, + std::ptrdiff_t first = 0 ) const; + + VertexBufferObject const & + VBO() const noexcept + { + return m_VBO; + } + + IndexBufferObject const & + IBO() const + { + return m_IBO; + } + +private: + VertexArrayObject m_VAO; + VertexBufferObject m_VBO; + IndexBufferObject m_IBO; +}; + + +Mesh MakeTexturedQuad( Id_t xy, Id_t uv ); + +Mesh MakeInterleavedTexturedQuad( Id_t xy, Id_t uv ); + + +} // end namespace gl. + +} // end namespace otb. + + +#endif // otb_GlMesh_h diff --git a/Modules/Visualization/Ice/include/otbGlTypeTraits.h b/Modules/Visualization/Ice/include/otbGlTypeTraits.h new file mode 100644 index 0000000000..c9f9846cc4 --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlTypeTraits.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlTypeTraits_h +#define otb_GlTypeTraits_h + +#include "OTBIceExport.h" + + +#ifdef _WIN32 +# include +#endif + +#include + + +namespace otb { namespace gl { + + +using Id_t = GLuint; + + +/** + * @class traits to associate (OpenGL) type to its GLenum value. + */ +template< typename T > +struct TypeTraits +{ + /** OpenGL type */ + using Type = T; + + /** OpenGL type enum */ + static constexpr GLenum value() noexcept; + + static char const * name() noexcept; +}; + + +/** Define OpenGL type to its GLenum value */ +#define OTB_GL_TYPE_TRAITS( type, glenum, glname ) \ + /** OpenGL type to GLenum association. */ \ + template<> \ + struct TypeTraits< type > \ + { \ + static constexpr GLenum value() noexcept { return glenum; } \ + \ + static constexpr char const * name() noexcept { return glname; } \ + } + +OTB_GL_TYPE_TRAITS( GLfloat, GL_FLOAT, "GLfloat" ); +OTB_GL_TYPE_TRAITS( GLdouble, GL_DOUBLE, "GLdouble" ); +OTB_GL_TYPE_TRAITS( GLint, GL_INT, "GLint" ); +OTB_GL_TYPE_TRAITS( GLuint, GL_UNSIGNED_INT, "GLuint" ); + + +} // end namespace gl. + +} // end namespace otb. + + +#endif // otb_TypeTraits_h diff --git a/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h b/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h new file mode 100644 index 0000000000..73a193deaf --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlVertexArrayObject_h +#define otb_GlVertexArrayObject_h + +#include "OTBIceExport.h" + + +#include "otbGlError.h" +#include "otbGlTypeTraits.h" + + +#include + + +namespace otb { namespace gl { + + +/** + * @class OpenGL vertex-array object. + */ +struct OTBIce_EXPORT VertexArrayObject +{ + using Id_t = otb::gl::Id_t; + + /** Default constructor. */ + VertexArrayObject(); + + /** Destructor. */ + ~VertexArrayObject(); + + VertexArrayObject( VertexArrayObject const & ) = delete; + + VertexArrayObject & operator = ( VertexArrayObject const & ) = delete; + + VertexArrayObject( VertexArrayObject && rhs ) : + m_Id( std::exchange( rhs.m_Id, GL_ZERO ) ) + {} + + VertexArrayObject & operator = ( VertexArrayObject && rhs ); + + /** OpenGL binding. */ + void Bind( bool = true ) const; + +private: + void Release(); + + /** OpenGL resource identifier. */ + Id_t m_Id = GL_ZERO; +}; + + +} // end namespace gl. + +} // end namespace otb. + + +#endif // otb_GlVetexArrayObject_h diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index 2461c6d9cf..ff6dd7b365 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -19,19 +19,25 @@ # set(OTBICE_SRCS - otbShader.cxx - otbShaderRegistry.cxx otbGeoInterface.cxx otbGlActor.cxx + otbGlBufferObject.cxx + otbGlError.cxx otbGlImageActor.cxx + otbGlMesh.cxx + # otbGlObject.cxx otbGlROIActor.cxx + otbGlView.cxx otbGlVectorActor.cxx otbGlVersionChecker.cxx - otbGlView.cxx + otbGlTypeTraits.cxx + otbGlVertexArrayObject.cxx otbImageSettings.cxx + otbMinimalShader.cxx + otbShader.cxx + otbShaderRegistry.cxx otbStandardShader.cxx otbViewSettings.cxx - otbMinimalShader.cxx ) add_library(OTBIce ${OTBICE_SRCS}) diff --git a/Modules/Visualization/Ice/src/otbGlBufferObject.cxx b/Modules/Visualization/Ice/src/otbGlBufferObject.cxx new file mode 100644 index 0000000000..ccbbbd49ca --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlBufferObject.cxx @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlBufferObject.h" + + +namespace otb { namespace gl { + +} // End namespace 'gl'. + +} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlError.cxx b/Modules/Visualization/Ice/src/otbGlError.cxx new file mode 100644 index 0000000000..44c7bfdc5a --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlError.cxx @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlError.h" + +#include + + +// This +namespace otb +{ + +namespace gl +{ + +Error +::Error( GLenum code ) : + std::runtime_error( + [ code ]() + { + std::ostringstream oss; + + oss << "OpenGL error #" << code << ": '" << gluErrorString( code ) << "'"; + + return std::move( oss.str() ); + }() + ) +{ +} + + +} // End namespace 'gl'. + + +} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlMesh.cxx b/Modules/Visualization/Ice/src/otbGlMesh.cxx new file mode 100644 index 0000000000..bbf373d907 --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlMesh.cxx @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlMesh.h" + + +namespace otb { namespace gl { + +Mesh +MakeTexturedQuad( Id_t xy, + Id_t uv ) +{ + Mesh mesh( + { // vertices (x, y) + -1.0f, -1.0f, + +1.0f, -1.0f, + +1.0f, +1.0f, + -1.0f, +1.0f, + // texcoords (u, v) + 0.0f, 1.0f, + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f }, + // + // Components + 2, + // + // triangle indices + { 0u, 1u, 2u, + 2u, 3u, 0u } + ); + + mesh.VertexAttribPointer( xy, 2, 0 ); + mesh.VertexAttribPointer( uv, 2, 8 ); + + return std::move( mesh ); +} + + +Mesh +MakeInterleavedTexturedQuad( Id_t xy, + id_t uv ) +{ + Mesh mesh( + // + // vertices: (x, y, u, v ) + { -1.0f, -1.0f, 0.0f, 1.0f, + +1.0f, -1.0f, 1.0f, 1.0f, + +1.0f, +1.0f, 1.0f, 0.0f, + -1.0f, +1.0f, 0.0f, 0.0f }, + // + // Components + 4, + // + // triangle indices + { 0u, 1u, 2u, + 2u, 3u, 0u } + ); + + mesh.VertexAttribPointer( xy, 2, 0 ); + mesh.VertexAttribPointer( uv, 2, 2 ); + + return std::move( mesh ); +} + + +void +Mesh +::VertexAttribPointer( Id_t id, + std::size_t components, + std::ptrdiff_t first ) const +{ + assert( components ); + + glVertexAttribPointer( + id, + components, + m_VBO.GlType(), + GL_FALSE, + m_VBO.Stride( components ), + reinterpret_cast< GLvoid const * >( first * m_VBO.Size() ) + ); + + CheckError(); + + glEnableVertexAttribArray( id ); + + CheckError(); +} + + +} // End namespace 'gl'. + +} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx b/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx new file mode 100644 index 0000000000..d67b143fbd --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlTypeTraits.h" + + +namespace otb { namespace gl { + +} // End namespace 'gl'. + +} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx new file mode 100644 index 0000000000..a718867db8 --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlVertexArrayObject.h" + +#define bool_str( b ) ( ( b ) ? "true" : "false" ) + +namespace otb { namespace gl { + + +VertexArrayObject +::VertexArrayObject() +{ +#if OTB_DEBUG + std::cerr << "glGenVertexArrays()" << std::endl; +#endif // OTB_DEBUG + + glGenVertexArrays( 1, &m_Id ); + assert( m_Id ); + +#if OTB_DEBUG + std::cerr << "-> " << m_Id << std::endl; +#endif // OTB_DEBUG + + CheckError(); + + Bind(); +} + + +VertexArrayObject +::~VertexArrayObject() +{ + Release(); +} + + +VertexArrayObject & +VertexArrayObject +::operator = ( VertexArrayObject && rhs ) +{ + Release(); + + m_Id = std::exchange( rhs.m_Id, GL_ZERO ); + + return *this; +} + + +void +VertexArrayObject +::Bind( bool isEnabled ) const +{ + assert( m_Id ); + +#if OTB_DEBUG + std::cerr + << "glBindVertexArrays( " << m_Id << " ) " << bool_str( isEnabled ) << + std::endl; +#endif // OTB_DEBUG + + CheckError< error::clear >(); + + glBindVertexArray( isEnabled ? m_Id : GL_ZERO ); + CheckError(); +} + + +void +VertexArrayObject +::Release() +{ + if( m_Id==GL_ZERO ) + return; + +#if OTB_DEBUG + std::cerr << "glDeleteVertexArrays(" << m_Id << ")" << std::endl; +#endif // OTB_DEBUG + + glDeleteVertexArrays( 1, &m_Id ); + CheckError(); + + m_Id = GL_ZERO; +} + + +} // End namespace 'gl'. + +} // End namespace 'otb'. -- GitLab From 991c8ed7236ca9756efdf76b19b3f71d3ec2fcf0 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 19 Sep 2019 18:22:44 +0200 Subject: [PATCH 18/73] Factorized vertex-array and buffer objects RAII in policy-based otb::gl::Handle; --- .../Ice/include/otbGlBufferObject.h | 119 +++++---------- .../Visualization/Ice/include/otbGlHandle.h | 135 ++++++++++++++++++ .../Ice/include/otbGlVertexArrayObject.h | 41 ++---- Modules/Visualization/Ice/src/CMakeLists.txt | 2 +- Modules/Visualization/Ice/src/otbGlHandle.cxx | 28 ++++ .../Ice/src/otbGlVertexArrayObject.cxx | 74 ++-------- 6 files changed, 219 insertions(+), 180 deletions(-) create mode 100644 Modules/Visualization/Ice/include/otbGlHandle.h create mode 100644 Modules/Visualization/Ice/src/otbGlHandle.cxx diff --git a/Modules/Visualization/Ice/include/otbGlBufferObject.h b/Modules/Visualization/Ice/include/otbGlBufferObject.h index 7fd04f798b..73dc4472b4 100644 --- a/Modules/Visualization/Ice/include/otbGlBufferObject.h +++ b/Modules/Visualization/Ice/include/otbGlBufferObject.h @@ -24,16 +24,10 @@ #include "OTBIceExport.h" -#include "otbGlError.h" +#include "otbGlHandle.h" #include "otbGlTypeTraits.h" -#include - -#ifndef bool_str -# define bool_str( b ) ( ( b ) ? "true" : "false" ) -#endif - namespace otb { namespace gl { @@ -46,6 +40,34 @@ enum class element : GLenum }; +/** + */ +template< element E > +struct BufferObjectPolicy +{ + static + void + Generate( Id_t & id ) + { + glGenBuffers( 1, &id ); + } + + static + void + Bind( Id_t id ) + { + glBindBuffer( static_cast< GLenum >( E ), id ); + } + + static + void + Release( Id_t & id ) + { + glDeleteBuffers( 1, &id ); + } +}; + + /** * @class OpenGL object. */ @@ -64,16 +86,13 @@ struct BufferObject } /** Default constructor. */ - BufferObject() - { - Generate(); - Bind(); - } + BufferObject() = default; /** Construct and fill. */ template< typename T > BufferObject( std::initializer_list< T > data, std::size_t components = 1 ) : + m_Id(), m_Count( data.size() ), m_Size( sizeof( T ) ), m_Components( components ), @@ -82,16 +101,6 @@ struct BufferObject assert( data.size() ); assert( components ); - Generate(); - - Bind(); - - std::cerr - << "BufferObject #" << m_Id << " " << TypeTraits< T >::name() - << std::endl; - - std::cout << data.size() << " " << sizeof( T ) << std::endl; - glBufferData( static_cast< GLenum >( E ), data.size() * sizeof( T ), @@ -102,37 +111,16 @@ struct BufferObject CheckError(); } - ~BufferObject() - { - Release(); - } - - BufferObject( BufferObject && rhs ) : - m_Id( std::exchange( rhs.m_Id, GL_ZERO ) ) - {} + ~BufferObject() = default; - BufferObject & - operator = ( BufferObject && rhs ) + BufferObject( BufferObject && ) = default; - { - Release(); - - m_Id = std::exchange( rhs.m_Id, GL_ZERO ); - - return *this; - } + BufferObject & operator = ( BufferObject && ) = default; void Bind( bool isEnabled = true ) const { - assert( m_Id ); - -#if OTB_DEBUG - std::cerr << "glBindBuffer(" << m_Id << ") " << bool_str( isEnabled ) << std::endl; -#endif // OTB_DEBUG - - glBindBuffer( static_cast< GLenum >( E ), isEnabled ? m_Id : GL_ZERO ); - CheckError(); + m_Id.Bind( isEnabled ); } GLenum @@ -159,42 +147,7 @@ struct BufferObject } private: - void - Generate() - { -#if OTB_DEBUG - std::cerr << "glGenBuffers()" << std::endl; -#endif // OTB_DEBUG - - glGenBuffers( 1, &m_Id ); - assert( m_Id ); - -#if OTB_DEBUG - std::cerr << "-> " << m_Id << std::endl; -#endif // OTB_DEBUG - - CheckError(); - } - - void - Release() - { - if( m_Id==GL_ZERO ) - return; - -#if OTB_DEBUG - std::cerr << "glDeleteBuffers(" << m_Id << ")" << std::endl; -#endif // OTB_DEBUG - - CheckError< error::clear >(); - - glDeleteBuffers( 1, &m_Id ); - CheckError(); - - m_Id = GL_ZERO; - } - - Id_t m_Id = GL_ZERO; + Handle< BufferObjectPolicy< E > > m_Id; std::size_t m_Count = 0; std::size_t m_Size = 0; std::size_t m_Components = 0; diff --git a/Modules/Visualization/Ice/include/otbGlHandle.h b/Modules/Visualization/Ice/include/otbGlHandle.h new file mode 100644 index 0000000000..94f5c5be7c --- /dev/null +++ b/Modules/Visualization/Ice/include/otbGlHandle.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otb_GlHandle_h +#define otb_GlHandle_h + +#include "OTBIceExport.h" + + +#ifdef _WIN32 +# include +#endif + +#include +#include "otbGlError.h" + +#include +#include + + +namespace otb { namespace gl { + +using Id_t = GLuint; + +/** + * @class OpenGL handle. + */ +template< typename Policy > +class OTBIce_EXPORT Handle +{ + using Policy_t = Policy; + +public: + /** OpenGL handle identifier type */ + using Id_t = otb::gl::Id_t; + + /** Default constructor */ + Handle() + { + Policy::Generate( m_Id ); + assert( m_Id ); + + CheckError(); + + Policy::Bind( m_Id ); + + CheckError(); + } + + /** Destructor */ + ~Handle() + { + Release(); + } + + /** Copy constructor (disabled). */ + Handle( Handle const & ) = delete; + + /** Assignement operator (disabled). */ + Handle & operator = ( Handle const & ) = delete; + + /** Move constructor. */ + Handle( Handle && rhs ) noexcept : + m_Id( std::exchange( rhs.m_Id, 0 ) ) {} + + /** Move assignment operator. */ + Handle & + operator = ( Handle && rhs ) + { + Release(); + + m_Id = std::exchange( rhs.m_Id, GL_ZERO ); + + return *this; + } + + /** Cast operator. */ + operator Id_t() const noexcept + { + return m_Id; + } + + /** OpenGL handle binding */ + void + Bind( bool isEnabled = true ) const + { + assert( m_Id ); + + Policy::Bind( isEnabled ? m_Id : GL_ZERO ); + + CheckError(); + } + +protected: + /** OpenGL handle identifier (handler) */ + Id_t m_Id = GL_ZERO; + +private: + void + Release() + { + CheckError< error::clear >(); + + Policy::Release( m_Id ); + + m_Id = GL_ZERO; + + CheckError(); + } +}; + + +} // end namespace gl. + +} // end namespace otb. + + +#endif // otb_GlHandle_h diff --git a/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h b/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h index 73a193deaf..9eb49be8d5 100644 --- a/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h +++ b/Modules/Visualization/Ice/include/otbGlVertexArrayObject.h @@ -24,48 +24,25 @@ #include "OTBIceExport.h" -#include "otbGlError.h" +#include "otbGlHandle.h" #include "otbGlTypeTraits.h" -#include - - namespace otb { namespace gl { - /** - * @class OpenGL vertex-array object. + * @class OpenGL vertex-arary object handle policy. */ -struct OTBIce_EXPORT VertexArrayObject +struct OTBIce_EXPORT VertexArrayObjectPolicy { - using Id_t = otb::gl::Id_t; - - /** Default constructor. */ - VertexArrayObject(); - - /** Destructor. */ - ~VertexArrayObject(); - - VertexArrayObject( VertexArrayObject const & ) = delete; - - VertexArrayObject & operator = ( VertexArrayObject const & ) = delete; - - VertexArrayObject( VertexArrayObject && rhs ) : - m_Id( std::exchange( rhs.m_Id, GL_ZERO ) ) - {} - - VertexArrayObject & operator = ( VertexArrayObject && rhs ); - - /** OpenGL binding. */ - void Bind( bool = true ) const; + static void Generate( Id_t & ); + static void Bind( Id_t ); + static void Release( Id_t & ); +}; -private: - void Release(); - /** OpenGL resource identifier. */ - Id_t m_Id = GL_ZERO; -}; +/** VertexArrayObject type definition. */ +using VertexArrayObject = Handle< VertexArrayObjectPolicy >; } // end namespace gl. diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index ff6dd7b365..8d7419bcb0 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -23,9 +23,9 @@ set(OTBICE_SRCS otbGlActor.cxx otbGlBufferObject.cxx otbGlError.cxx + otbGlHandle.cxx otbGlImageActor.cxx otbGlMesh.cxx - # otbGlObject.cxx otbGlROIActor.cxx otbGlView.cxx otbGlVectorActor.cxx diff --git a/Modules/Visualization/Ice/src/otbGlHandle.cxx b/Modules/Visualization/Ice/src/otbGlHandle.cxx new file mode 100644 index 0000000000..a5bfcf51e8 --- /dev/null +++ b/Modules/Visualization/Ice/src/otbGlHandle.cxx @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbGlHandle.h" + + +namespace otb { namespace gl { + +} // End namespace 'gl'. + +} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx index a718867db8..230dad2eab 100644 --- a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx +++ b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx @@ -20,84 +20,30 @@ #include "otbGlVertexArrayObject.h" -#define bool_str( b ) ( ( b ) ? "true" : "false" ) - namespace otb { namespace gl { -VertexArrayObject -::VertexArrayObject() -{ -#if OTB_DEBUG - std::cerr << "glGenVertexArrays()" << std::endl; -#endif // OTB_DEBUG - - glGenVertexArrays( 1, &m_Id ); - assert( m_Id ); - -#if OTB_DEBUG - std::cerr << "-> " << m_Id << std::endl; -#endif // OTB_DEBUG - - CheckError(); - - Bind(); -} - - -VertexArrayObject -::~VertexArrayObject() -{ - Release(); -} - - -VertexArrayObject & -VertexArrayObject -::operator = ( VertexArrayObject && rhs ) +void +VertexArrayObjectPolicy +::Generate( Id_t & id ) { - Release(); - - m_Id = std::exchange( rhs.m_Id, GL_ZERO ); - - return *this; + glGenVertexArrays( 1, &id ); } void -VertexArrayObject -::Bind( bool isEnabled ) const +VertexArrayObjectPolicy +::Bind( Id_t id ) { - assert( m_Id ); - -#if OTB_DEBUG - std::cerr - << "glBindVertexArrays( " << m_Id << " ) " << bool_str( isEnabled ) << - std::endl; -#endif // OTB_DEBUG - - CheckError< error::clear >(); - - glBindVertexArray( isEnabled ? m_Id : GL_ZERO ); - CheckError(); + glBindVertexArray( id ); } void -VertexArrayObject -::Release() +VertexArrayObjectPolicy +::Release( Id_t & id ) { - if( m_Id==GL_ZERO ) - return; - -#if OTB_DEBUG - std::cerr << "glDeleteVertexArrays(" << m_Id << ")" << std::endl; -#endif // OTB_DEBUG - - glDeleteVertexArrays( 1, &m_Id ); - CheckError(); - - m_Id = GL_ZERO; + glDeleteVertexArrays( 1, &id ); } -- GitLab From df6aef0283031d8dd2c57d587eb85940b1f2c1e8 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 19 Sep 2019 18:23:34 +0200 Subject: [PATCH 19/73] Used otb::glMesh (code factorization) in otb::GlImageActor. --- .../Ice/include/otbGlImageActor.h | 42 +++++++----- .../Visualization/Ice/src/otbGlImageActor.cxx | 65 +++++++++++++++++-- 2 files changed, 88 insertions(+), 19 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 82fd1a377b..40f9af4742 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -37,10 +37,18 @@ #include +#define USE_GL_RAII 1 + namespace otb { -class OTBIce_EXPORT GlImageActor +namespace gl +{ +class Mesh; +} + + +class OTBIce_EXPORT GlImageActor : public GlActor, public GeoInterface { public: @@ -62,7 +70,7 @@ public: typedef VectorImageType::SpacingType SpacingType; typedef VectorImageType::PointType PointType; typedef VectorRescaleIntensityImageFilter RescaleFilterType; - + struct ResolutionAlgorithm { enum type @@ -75,7 +83,7 @@ public: ///performances, better quality) MAX__}; }; - + // Initialize with a new image void Initialize(const std::string & filename); @@ -139,7 +147,7 @@ public: virtual void SetRedIdx(const unsigned int idx) { if ( this->m_RedIdx != idx ) - { + { this->m_RedIdx = std::min(this->GetNumberOfComponents(),idx); this->Modified(); } @@ -148,25 +156,25 @@ public: virtual void SetGreenIdx(const unsigned int idx) { if ( this->m_GreenIdx != idx ) - { + { this->m_GreenIdx = std::min(this->GetNumberOfComponents(),idx); this->Modified(); } - } + } virtual void SetBlueIdx(const unsigned int idx) { if ( this->m_BlueIdx != idx ) - { + { this->m_BlueIdx = std::min(this->GetNumberOfComponents(),idx); - this->Modified(); + this->Modified(); } } PointType ViewportToImageTransform(const PointType & in, bool physical = true) const; PointType ImageToViewportTransform(const PointType & in, bool physical = true) const; - + bool GetPixelFromViewport( const PointType & in, PixelType & pixel ) const; bool GetPixelFromViewport( const PointType & view, @@ -195,7 +203,7 @@ public: protected: GlImageActor(); - + ~GlImageActor() override; typedef ImageFileReader ReaderType; @@ -246,8 +254,8 @@ protected: RescaleFilterType::Pointer m_RescaleFilter; }; - typedef std::vector TileVectorType; - + typedef std::vector TileVectorType; + private: // prevent implementation GlImageActor(const Self&); @@ -255,7 +263,7 @@ private: // Load tile to GPU void LoadTile(Tile& tile); - + // Unload tile from GPU void UnloadTile(Tile& tile); @@ -275,11 +283,11 @@ private: void ViewportExtentToImageRegion(const double& ulx, const double & uly, const double & lrx, const double & lry, RegionType & region) const; void UpdateResolution(); - + unsigned int m_TileSize; std::string m_FileName; - + ReaderType::Pointer m_FileReader; TileVectorType m_LoadedTiles; @@ -309,11 +317,15 @@ private: ResolutionAlgorithm::type m_ResolutionAlgorithm; +#if !USE_GL_RAII // index of Vertex Array Object unsigned int m_VAO; // index of Vector Buffer Object unsigned int m_VBO; +#else + std::unique_ptr< gl::Mesh > m_Mesh; +#endif }; // End class GlImageActor diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index bc727bf98a..3148ba7c7c 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -28,12 +28,40 @@ #include +// #include "otbGlBufferObject.h" +// #include "otbGlError.h" +#include "otbGlMesh.h" +// #include "otbGlObject.h" +// #include "otbGlTypeTraits.h" +// #include "otbGlVertexArrayObject.h" + #include "otbStandardShader.h" #include "itkListSample.h" #include "otbListSampleToHistogramListGenerator.h" #include "otbCast.h" +#include + + +namespace otb +{ + + +namespace gl +{ + + +// struct Dummy +// { +// virtual ~Dummy() = default; +// }; + + +} // end namespace 'gl'. + +} // end of namespace 'otb'. + namespace otb { @@ -58,8 +86,12 @@ GlImageActor::GlImageActor() m_ViewportForwardRotationTransform(RigidTransformType::New()), m_ViewportBackwardRotationTransform(RigidTransformType::New()), m_ResolutionAlgorithm(ResolutionAlgorithm::Nearest), +#if !USE_GL_RAII m_VAO(0), m_VBO(0) +#else + m_Mesh() +#endif {} GlImageActor @@ -86,6 +118,8 @@ GlImageActor shader->SetImageSettings( m_ImageSettings ); +#if !USE_GL_RAII + // Use a Vertex Array Object glGenVertexArrays(1, &m_VAO); glBindVertexArray(m_VAO); @@ -143,6 +177,21 @@ GlImageActor glVertexAttribPointer(texIdx, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *)sizeof(vertexPosition)); glEnableVertexAttribArray(texIdx); +#else + // Check previous OpenGL error and clear error flag. + gl::CheckError< gl::error::clear >(); + + m_Mesh = std::make_unique< gl::Mesh >( + gl::MakeTexturedQuad( + shader->GetAttribIdx()[ 0 ], + shader->GetAttribIdx()[ 1 ] + ) + ); + + // assert( m_Mesh ); + // m_Mesh->Bind( false ); +#endif + // Should be done last in order to ensure exception-safety of // invariant. m_Shader = shader; @@ -397,14 +446,22 @@ void GlImageActor::Render() m_Shader->SetupShader(); GLfloat vertexPosition[8] = { - -1.0, -1.0, - 1.0, -1.0, - 1.0, 1.0, - -1.0, 1.0 + -1.0f, -1.0f, + 1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, 1.0f }; +#if !USE_GL_RAII glBindVertexArray(m_VAO); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); +#else + // Check OpenGL error and clear error flag. + gl::CheckError< gl::error::clear >(); + + assert( m_Mesh ); + m_Mesh->Bind(); +#endif for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) -- GitLab From 29b33f591225eb456ab40de5caae5f7cb00d4e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Fri, 20 Sep 2019 10:06:45 +0200 Subject: [PATCH 20/73] ENH: update OTB version to 7.0.0 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bb9e347dd..c82978d00f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,8 +132,8 @@ set(main_project_name ${_OTBModuleMacros_DEFAULT_LABEL}) #----------------------------------------------------------------------------- # OTB version number. -set(OTB_VERSION_MAJOR "6") -set(OTB_VERSION_MINOR "7") +set(OTB_VERSION_MAJOR "7") +set(OTB_VERSION_MINOR "0") set(OTB_VERSION_PATCH "0") set(OTB_VERSION_STRING "${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}.${OTB_VERSION_PATCH}") -- GitLab From 0daf84c0117940a39b925d6f9b118ac9aee43c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Fri, 20 Sep 2019 10:15:31 +0200 Subject: [PATCH 21/73] DOC: update release notes for OTB 7.0.0 --- RELEASE_NOTES.txt | 443 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 443 insertions(+) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 1fe7839bcb..6338b82785 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,446 @@ +OTB-v.7.0.0 - Changes since version 6.6.0 (September 20th, 2019) +---------------------------------------------------------------- + +Features added: + + * !596: Move Mosaic in OTB by Rémi Cresson + * !586: Add a new metadata (azimuthAnxTime) to Sentinel 1 Model by Gaëlle USSEGLIO + * !566: Package Python wrappers sources by Guillaume Pasero + * !565: Application VectorRegression by Cédric Traizet + * !508: New mode (SpotLight) for Cosmo sensor model by Gaëlle USSEGLIO + * !487: Refactor XML parameters by Victor Poughon + * !470: KMeans input centroids by Cédric Traizet + * !468: Design improvements of applications Qt Wrapper by Victor Poughon + * !454: Filter mouse wheel event in QComboBox of app parameters by Victor Poughon + * !452: ENH: Improve errors messages when loading app fail by Luc Hermitte + * !426: ENH: add GeoJSON driver and simplify driver selection by Jordi Inglada + * !414: Qgis parameter by Antoine Regimbeau + * !405: Logging in python wrapper by Cédric Traizet + * !396: Fix issue on reduced OTB-data by Stéphane Albert + * !386: New SAR sensor Model (CosmoSkymed) by Gaëlle USSEGLIO + * !371: Specify the overlap area for two S1_IW Bursts by Gaëlle USSEGLIO + * !370: Add a solar distance parameter in the optical calibration module by Aurélie Emilien + * !355: Enhance SARConcatenateBursts by Gaëlle USSEGLIO + * !353: Local Rx detector by Cédric Traizet + * !344: Number of endmember estimation application by Cédric Traizet + * !331: Constexpr in otbMath.h by Manuel Grizonnet + * !327: Switch for application connections by Guillaume Pasero + * !315: Enhance SARDeburst by Gaëlle USSEGLIO + * !310: Add DefaultConstructibleFunctorImageFilter in OTBFunctor module by Julien Michel + * !299: Add Functor module with FunctorImageFilter by Julien Michel + * !298: ENH : Add metadata to Sentinel 1 Model by Gaëlle USSEGLIO + * !290: Named inputs in FunctorImageFilter by Julien Michel + * !289: enhance SarSensorModelAdapter by Gaëlle USSEGLIO + * !286: Add class probability output for RF classifiers by Jordi Inglada + * !241: Implementation of the raster output for Zonalstatistics by Jordi Inglada + * !240: ENH: add support for GDAL's ALL_TOUCHED mode by Laurențiu Nicola + * !227: REFAC: allow vector/xml/raster output regardless of the input type by Jordi Inglada + * !226: ENH: Add option to allow to always trigger otb build step from superbuild tree by Manuel Grizonnet + * !223: StreamingStatisticsMapFromLabelImageFilter no data support by Laurențiu Nicola + * !222: Zonalstatistics by Rémi Cresson + * !191: Parameter Refactoring : String Parameter by Antoine Regimbeau + * !184: Resolve "Move otbExternalModuleTemplate repository from GitHub to gitlab.orfeo-toolbox.org" by Manuel Grizonnet + * !179: Resolve "Display Pixel type of Image in ReadImageInfo application" by David Youssefi + * !176: Resolve "Output time of otbcli applications in minutes, seconds instead of scientific notation" by Emmanuelle Sarrazin + * !158: ENH: Add box kernel to morphological operations apps by Laurențiu Nicola + * !154: ENH: Allow to compute modulus and phase from 2 bands scalar image by Manuel Grizonnet + * !77: Nodata extended filename by @CSSI_OTB + +Bugs fixed: + + * !592: Fix StreamingWarpImageFilter issue with empty region by Julien Michel + * !585: Fix PCA in Dimensionality reduction by Cédric Traizet + * !583: Revert Merge branch 'bugfix-streamingwarpfilter-empty-region' into 'develop'" by Julien Michel + * !576: BUG: fix potential TopologyException in GDAL by Guillaume Pasero + * !575: Fix build with Ossim >= 2.8 by Guillaume Pasero + * !573: Remove cookbook pdf target by Victor Poughon + * !572: Remove CVFold parameter from decision tree classifier in OpenCV 3 by Cédric Traizet + * !571: BUG: fix parameter expansion in otbenv by Guillaume Pasero + * !570: Packaging tweaks by Guillaume Pasero + * !569: Better cleaning of logger objects in the Python Swig wrapper by Cédric Traizet + * !568: BUG: files missing to use ENABLE_SHARED in remote modules by Guillaume Pasero + * !567: Crash bandmathx by Antoine Regimbeau + * !562: Undefined variable in cmake by Antoine Regimbeau + * !561: Resolve "PROJ linking to GDAL in Superbuild" by Rashad Kanavath + * !557: Do not return empty requested region in case StreamingWarpImageFilter by Julien Michel + * !552: Remove false NCLS by Antoine Regimbeau + * !549: COMP: master branch of diapotb breaks on windows by Guillaume Pasero + * !545: BUG: fix URL in OSMDataToVectorDataGenerator by Victor Poughon + * !537: Bug in ExtractROI (radius and extent modes) by Cédric Traizet + * !534: DOC: fix missing import & clarify python doc example by Victor Poughon + * !530: Resolve "UpdateParameters has to be called manually from the python API" by Victor Poughon + * !527: BUG dltest not available on macOS by Guillaume Pasero + * !525: BUG #1920: fix Qt 5.10.1 broken link by Guillaume Pasero + * !515: Type assertion in OGRFieldWrapper GetValue() by Cédric Traizet + * !512: Fix error : Invalid index -1 by Cédric Traizet + * !497: Resolve "pipeline containing a BandMath failed" by Victor Poughon + * !494: Add virtual descructor to RadiometricIndex abstract base class by Victor Poughon + * !490: Missing include in otbStackIndiceFunctor.h by Cédric Traizet + * !482: Fix assert in new radiometric indices by Victor Poughon + * !480: BUG: remove .Fixup() for GDAL 2.5 compatibility (develop fix) by Victor Poughon + * !478: Resolve "Assertion error on Sentinel1 product in debug build" by Victor Poughon + * !469: Fix spinbox locale issue (force C locale) by Victor Poughon + * !457: COMP: fix parenthesis warning in debug mode by Victor Poughon + * !455: Fix name of USE_SYSTEM_QT5 cmake var by Victor Poughon + * !453: BUG: sort Shark labels before encoding so that we know the order for the probability image by Jordi Inglada + * !450: Patch for S1 localization problems by Gaëlle USSEGLIO + * !448: Update mosaic git tag to include the functorImageFilter fix by Cédric Traizet + * !444: Fix OTBApplicationOutputImageChanged and ExecutionDone slots not being called by Victor Poughon + * !437: Fix assert in DotProductImageFilter by Cédric Traizet + * !433: Fix missing braces warning on clang by Victor Poughon + * !428: Fix CookBook build inside a virtualenv & add "Compiling documentation" subsection by Victor Poughon + * !422: Fix doxygen test by Antoine Regimbeau + * !420: Warning on GetJacobian with GitlabCI by Guillaume Pasero + * !419: Bugs in Virtual Dimensionality by Cédric Traizet + * !417: COMP: fix build error (missing include) by Victor Poughon + * !412: Refactor application parameters dynamic_cast pattern by Victor Poughon + * !409: Test using numpy by Antoine Regimbeau + * !407: Fix typo in python error message by Victor Poughon + * !406: BUG: #1825: use GetParameterName to get real names on composite apps by Guillaume Pasero + * !404: Fix bug in extract roi by Antoine Regimbeau + * !403: FIX: correct a minor bug in Superimpose application by Rémi Cresson + * !400: Fix ImageFileReader error message & add back otb::Logger::BuildFormattedEntry by Victor Poughon + * !391: COMP: allow Qt5 to compile on old kernels by Guillaume Pasero + * !388: 1808: Fix error in solar distance test by Aurélie Emilien + * !382: Fix warnings on Windows for the Local Rx Filter by Cédric Traizet + * !381: Fix FastICA by Cédric Traizet + * !379: Logger bug by Antoine Regimbeau + * !378: Resolve "otb::TestHelper::RegressionTestOgrFile() always says Yes" by Guillaume Pasero + * !376: Resolve "Building cookbook fails with ninja" by Guillaume Pasero + * !364: No progress to file by Guillaume Pasero + * !358: Lower threshold even more for SIFTFast to make the test pass on raoul by Julien Michel + * !340: Revert Merge branch '1769_drop_support_gdal_1' into 'develop'" by Cédric Traizet + * !339: COMP: Set boost configure specific options when building with clang on unix systems by Julien Michel + * !335: Add Haralick features formulas in software guide by Manuel Grizonnet + * !333: Remove Version installation in build_dir by Antoine Regimbeau + * !313: BUG : clean fftw threads only if fftw is used by Cédric Traizet + * !308: BUG: fix verbosity of libsvm by Guillaume Pasero + * !305: BUG: compat of QgisDescriptor with old params by Guillaume Pasero + * !304: BUG: Quick fix for Mellin test by Antoine Regimbeau + * !303: BUG: missing ComplexImage params in QGis wrapper by Guillaume Pasero + * !302: TEST: use different test output names by Guillaume Pasero + * !297: COMP: fix compilation of examples with clang 7 by Guillaume Pasero + * !294: PKG: declare libomp as system lib in macOS package by Guillaume Pasero + * !293: COMP: fix OverlapSave filter on Windows by Guillaume Pasero + * !292: FFTW upgrade by Guillaume Pasero + * !288: BUG: #1761: make sure OpenMP runtime is loaded by the main executable by Guillaume Pasero + * !285: SuperBuild: the Ossim issue 2354 now affects all platforms by Guillaume Pasero + * !284: COMP: fix ossim to build with clang7 by Guillaume Pasero + * !283: OpenMP fixes by Guillaume Pasero + * !279: BUG: #1623: fix doxygen search bar by Guillaume Pasero + * !278: BUG #1757 fix installation of Siftfast by Guillaume Pasero + * !277: Resolve "Orthorectification regression in v6.6" by Julien Michel + * !274: BUG: #1734: warn users when producing an ENVI dataset with positive Y spacing by Guillaume Pasero + * !272: BUG: #1753: adding options OTB_USE_MPI and OTB_USE_SPTW for superbuild by Guillaume Pasero + * !271: Monteverdi: fix band numbering in color setup widget by Victor Poughon + * !266: BUG: #1734: replace envi format with TIF by Guillaume Pasero + * !265: Resolve "OTB QGIS plugin documentation is outdated" by Guillaume Pasero + * !263: BUG: update hdf5 url by Antoine Regimbeau + * !262: Composite application bugfix by Antoine Regimbeau + * !258: Add a BUILD_COOKBOOK cmake option to control cookbook build targets by Manuel Grizonnet + * !257: BUG: dict.iteritems() not supported in python 3 by Guillaume Pasero + * !253: BUG: clear temporary validation filename when validation ratio is set to 0 by Manuel Grizonnet + * !252: Resolve "error C2039: 'min': is not a member of 'std'" by Rashad Kanavath + * !250: BUG: fix ITK version number for packaging by Guillaume Pasero + * !249: Resolve "macros without proper semi-colon" by Rashad Kanavath + * !248: Resolve "undefined method GetResolutionsInfo in otbImageFileReader" by Rashad Kanavath + * !247: Resolve "update patch for opencv in superbuild" by Rashad Kanavath + * !239: ENH: Update superbuild to ITK 4.13.1 so that it builds with gcc 8 by Jordi Inglada + * !234: BUG: fix qt5 compilation on ubuntu 18.04 by Manuel Grizonnet + * !232: BUG: #1582: detect empty training data by Guillaume Pasero + * !231: BUG: fix markdown syntax in MR template by Guillaume Pasero + * !218: Resolve "Build fails on OtbQgisDescriptor usage if OTB_INSTALL_APP_DIR is set to lib64/otb/applications" by Guillaume Pasero + * !216: Resolve "OTB does not compile with GCC 8.1" by Manuel Grizonnet + * !210: #1652 Fine Registration correction to handle the warping option by Yannick TANGUY + * !205: Resolve "Orthorectification of Spot 6/7 raster sensor products leads to wrong output with lambert93 projection" by Guillaume Pasero + * !204: Resolve "Extract ROI extent mode produces wrong output" by Guillaume Pasero + * !203: Resolve "SampleAugmentation field list" by Guillaume Pasero + * !202: Metadata reading from compound datasets by Guillaume Pasero + * !201: Resolve "Fail computing KMeans Classification on image with NaN pixels" by Guillaume Pasero + * !198: Resolve "segfault in DEMConvert" by Antoine Regimbeau + * !196: Resolve "Module which generates QGIS descriptor is called Qgis while the source directory is QGIS (upper case)" by Manuel Grizonnet + * !195: Resolve "Monteverdi build error (superbuild)" by Manuel Grizonnet + * !188: Fix compilation GDALImageIO by Emmanuelle Sarrazin + * !187: Resolve "QLayout: Attempting to add QLayout "" to otb::Wrapper::QtWidgetParameterGroup "", which already has a layout" by Victor Poughon + * !186: PKG: install openCV libraries to lib by Guillaume Pasero + * !182: Resolve "VectorDataReprojection app does not output VectorData in physical space when using a reference image in sensor geometry" by Julien Michel + * !181: Resolve "OTB_APPLICATIONS_NAME_LIST is not updated when modules are activated/deactivated" by Rashad Kanavath + * !180: Resolve "Linux self extracting binary does not install correctly on Debian Stretch" by Rashad Kanavath + * !177: Remove mantis 1427 workaround by Victor Poughon + * !169: Resolve "apTvClMethodDTImageClassifierQB1 failing after SuperBuild OpenCV upgrade" by Victor Poughon + * !168: Resolve "Generation of Qgis plugin descriptors fails with latest develop" by Julien Michel + * !159: BUG: Improve Convert and DynamicConvert mask handling (fix #1647) by Victor Poughon + * !157: Resolve "install qgis descriptors into /share/ on all platforms" by Rashad Kanavath + * !156: BUG fix issue 1656 related to eratic behavior of cmake configuration by Manuel Grizonnet + * !155: BUG: Be compliant with new cmake policy CMP0072 with cmake > 3.11 by Manuel Grizonnet + * !142: BUG: fix issue #1639 Update UserValue flag in QtWidgetParameterList by Manuel Grizonnet + * !126: BUG: Remove workaround for QT bug 22829 by Victor Poughon + * !125: BUG: Fix missing QWidget parents by Victor Poughon + +Refactoring: + + * !595: Apply clang-format to the whole library by Cédric Traizet + * !593: Compatibility with OpenCV 4 by Cédric Traizet + * !587: Image regression application by Cédric Traizet + * !554: Upgrade boost by Antoine Regimbeau + * !551: Remove unused files in OssimPlugins by Julien Michel + * !548: Warning and Test fixes by Guillaume Pasero + * !544: Cmake 3.10.2 by Antoine Regimbeau + * !542: Fix some sonar qube issues by Victor Poughon + * !535: Remove spatial objects module by Cédric Traizet + * !531: Comment bfTvOverlapSaveConvolutionImageFilter on Win x86 by Guillaume Pasero + * !517: Fix Superbuild default OTB_DATA_ROOT by Cédric Traizet + * !511: Compatibility with gdal 3 by Cédric Traizet + * !510: Update libkml link in Superbuild by Cédric Traizet + * !506: Update Remote Module tags for Mosaic and SertitObject by Cédric Traizet + * !500: Upgrade gdal version in superbuild by Cédric Traizet + * !498: Prefer 'using' to 'typedef' in examples by Victor Poughon + * !496: Regression refactoring : Train images regression by Cédric Traizet + * !493: Remove java wrapping 2 by Cédric Traizet + * !488: Regression refactoring : TrainVectorRegression by Cédric Traizet + * !487: Refactor XML parameters by Victor Poughon + * !484: Remove docname by Victor Poughon + * !474: Fix sphinx warning on sphinx v1.4 by Victor Poughon + * !471: Clean-up of unused or low quality modules and filters by Julien Michel + * !464: Large refactoring of radiometric indices by Julien Michel + * !460: COMP: set remote module to follow master by Jordi Inglada + * !447: PERF: Improve convolution performances by Luc Hermitte + * !445: Improve build time of OTBApplicationEngine by Stéphane Albert + * !442: Remove complex image parameters by Cédric Traizet + * !441: Remove ApplicationHtmlDocGenerator by Victor Poughon + * !432: Remove the RAnd* family of filters by Julien Michel + * !427: Remove UnaryFunctorImageFilter by Cédric Traizet + * !424: REFAC: Drop swig/java support by Julien Michel + * !413: PERF: Improve FunctorImageFilter performances by Luc Hermitte + * !412: Refactor application parameters dynamic_cast pattern by Victor Poughon + * !410: PERF: Optimize compare image by Luc Hermitte + * !408: REFACT: Deprecate `auto_ptr` by Luc Hermitte + * !400: Fix ImageFileReader error message & add back otb::Logger::BuildFormattedEntry by Victor Poughon + * !398: Migrate developer's guide to the cookbook by Victor Poughon + * !395: Render examples in the CookBook by Victor Poughon + * !390: Catch otbImageFileReaderException in otbTestMain by Victor Poughon + * !387: Import OTB-Data test data under git lfs by Stéphane Albert + * !384: Remove stale examples by Victor Poughon + * !383: Move otb-data/Examples/* to otb-data/Input/ by Victor Poughon + * !380: Massive Software Guide clean-up by Julien Michel + * !377: Start usage of extern templates by Guillaume Pasero + * !373: Refactor FunctorImageFilter with neighborhood by Cédric Traizet + * !372: Make Shark Optional for the "OTBDimensionalityReductionLearning" module by Cédric Traizet + * !369: REFAC: 1778: Reduced input-data of MeanShiftSmoothingImageFilterQBRoad. by Stéphane Albert + * !366: REFAC: 1778: Reduced input-data of hyTvMDMDNMFImageFilterTest2. by Stéphane Albert + * !362: Remove GradientBoostedTree as done in OpenCV 3 by Guillaume Pasero + * !360: Faster segmentation tests by Guillaume Pasero + * !359: Update GIT_TAG for mosaic remote module by Rémi Cresson + * !357: Faster SampleAugmentation tests by Guillaume Pasero + * !356: WRG: Filter out remaining warnings on unknown pragmas by Julien Michel + * !354: REFAC: 1778: Reduced size of input-data for dmTvFineRegistrationImageFilterTestWithMeanSquare by Stéphane Albert + * !352: Drop python2 by Antoine Regimbeau + * !351: Increase default ram limit to 256MB by Victor Poughon + * !350: Remove const char* SetFilename overloads by Victor Poughon + * !349: owTvQtWidgetShow refactoring by Stéphane Albert + * !348: Update insource build error message by Victor Poughon + * !345: Refactor all keypoints tests into a single test by Julien Michel + * !343: Fix current warnings on dashboard by Julien Michel + * !342: Remove support for GDAL 1.X by Cédric Traizet + * !341: Updating superbuild GDAL configuration by Antoine Regimbeau + * !337: Update git tag for TemporalGapfilling module by Jordi Inglada + * !336: Remove CommandLineParser submodule by Antoine Regimbeau + * !335: Add Haralick features formulas in software guide by Manuel Grizonnet + * !334: Drop support for gdal 1.X by Cédric Traizet + * !331: Constexpr in otbMath.h by Manuel Grizonnet + * !329: Remove spurious UnaryFunctorImageFilter includes by Julien Michel + * !328: Rename Get/Set Variadic[Named]Input[s]() by Get/SetInput() for easier reading in FunctorImageFilter by Julien Michel + * !326: Replace use of TernaryFunctorImageFilter by use of FunctorImageFilter in ComplexImage by Julien Michel + * !325: Refactor PanSharpening module to use FunctorImageFilter everywhere by Julien Michel + * !324: Remove convert app by Cédric Traizet + * !323: ENH: declare constants in otbMath.h as constexpr by Manuel Grizonnet + * !321: Use FunctorImageFilter to refactor filters in MorphologicalProfiles module by Julien Michel + * !320: Remove OTB_USE_DEPRECATED, TileMapImageIO and VectorDataRendering by Victor Poughon + * !319: Use functor filter in app image utils by Yannick TANGUY + * !318: Refactor filters in Polarimetry module to use new FunctorFilter by Manuel Grizonnet + * !311: ENH: update cmake minimum required in tutorial by Victor Poughon + * !309: REFAC: use FunctorFilter in DomainTransform by Julien Michel + * !307: Remove ParameterType_Empty by Victor Poughon + * !301: ENH: initialize the number of openMP threads after any modification by command line by Guillaume Pasero + * !300: PKG: enable diapotb in SuperBuild with RemoteModules by Guillaume Pasero + * !299: Add Functor module with FunctorImageFilter by Julien Michel + * !296: Integrate diapotb as official remote module by Guillaume Pasero + * !295: Update deprecated cmake policies to NEW by Manuel Grizonnet + * !287: Filtering warnings for clang7 by Guillaume Pasero + * !275: Review applications parameter order by Victor Poughon + * !273: Update .clang-format by Victor Poughon + * !269: Remove LARGEINPUT dependency of SoftwareGuide build by Victor Poughon + * !264: Bug fixes and refactors from clang-tidy by Victor Poughon + * !245: ENH: update phenotb remote module git tag by Jordi Inglada + * !244: Deprecated TileMap and prTeCoordinateToNameExampleTest by Antoine Regimbeau + * !243: Remove `Modules/Adapters/OpenThreads` by Laurențiu Nicola + * !236: Deprecate mapnik in 7.0 by Guillaume Pasero + * !235: Make the CookBook a CMake target by Victor Poughon + * !233: Refactor small region merging by Cédric Traizet + * !230: REFAC: move code to functions so that DoExecute logic is readable by Jordi Inglada + * !229: ImageIOBase AsString functions should be static by Guillaume Pasero + * !227: REFAC: allow vector/xml/raster output regardless of the input type by Jordi Inglada + * !225: WRG: fix warnings declaration shadows a previous local seen with gcc 8 by Manuel Grizonnet + * !224: Change map projections backend to use Gdal instead of OSSIM by Julien Michel + * !221: Remove unused OSSIM based classes by Julien Michel + * !219: Warnings fixes (clang and OSSIM) by Guillaume Pasero + * !208: More warning fixes for Shark by Guillaume Pasero + * !206: Some warning fixes by Guillaume Pasero + * !199: Remove more c_str with itk::ExceptionObject string constructor by Victor Poughon + * !192: Revert Merge branch 'new_contributors' into 'develop'" by Manuel Grizonnet + * !190: WRG: fix unused parameter warning by Victor Poughon + * !189: Remove more c_str with SetFileName string overload by Victor Poughon + * !173: Remove all *New tests by Julien Michel + * !172: REFAC: remove unnecessary calls to c_str (2nd attempt) by Victor Poughon + * !171: fstream and iostream clean-up by Julien Michel + * !170: WRG: add missing overrides by Victor Poughon + * !167: Refactor WrapperParameter code to avoid method bodies in header by Julien Michel + * !163: ENH: Use std math instead of vcl by Laurențiu Nicola + * !162: Fix warnings on OTB develop branches by Manuel Grizonnet + * !161: Refactor in Modules/Wrappers/QtWidget by Victor Poughon + * !160: Merge release-6.6 into develop without the shark revert by Victor Poughon + * !152: rename files with txx extension to hxx by Manuel Grizonnet + * !150: Refactor of otbWrapperApplication.h by Victor Poughon + * !145: Resolve "Debug mode without try {} catch(...) in otbApplicationLauncherCommandLine" by Julien Michel + * !144: Resolve "Warn otbcli user about unused parameters" by Julien Michel + * !139: SuperBuild: Upgrade to OpenCV 3.4.1 by Victor Poughon + * !138: REFAC: include-what-you-use in Modules/Core/ by Victor Poughon + * !133: C++14: Replace comments by '= delete' by Victor Poughon + * !131: C++14: Replace ITK_OVERRIDE by override by Victor Poughon + * !130: C++14: Replace ITK_NULLPTR by nullptr by Victor Poughon + * !127: COMP: fix gcc 7 'defined' warnings by Victor Poughon + * !123: New custom widgets for Float and Int parameters by Victor Poughon + +CI: + + * !589: Mentions of copyright check by Sébastien Dinot + * !584: Fixes for NamespaceHandler by Guillaume Pasero + * !582: Script to setup a namespace for OTB imported targets by Guillaume Pasero + * !581: Contributors check by Sébastien Dinot + * !571: BUG: fix parameter expansion in otbenv by Guillaume Pasero + * !563: CI move Superbuild Artifact repository by Guillaume Pasero + * !559: DOC: add badges for CI and coverage by Guillaume Pasero + * !558: CI: fixing cdash links on forks by Guillaume Pasero + * !556: CI simple contributing by Guillaume Pasero + * !550: CI Artifacts by Guillaume Pasero + * !543: CI coverage by Guillaume Pasero + * !539: Add QA related jobs to CI pipeline by Sébastien Dinot + * !538: Ci contributing update by Guillaume Pasero + * !536: CI Fixes episode N by Guillaume Pasero + * !526: CI Fix CDash error report by Guillaume Pasero + * !524: CI Windows by Guillaume Pasero + * !523: CI: deploy by Antoine Regimbeau + * !522: CI: add large input test by Antoine Regimbeau + * !521: CI improvements for QA by Guillaume Pasero + * !520: CI: Pipelines for develop and release branches by Guillaume Pasero + * !519: Update HowToRelease by Guillaume Pasero + * !513: CI: Enable diapotb by Guillaume Pasero + * !507: CI Merge Ubuntus by Guillaume Pasero + * !505: CI: Enable ccache macos by Guillaume Pasero + * !504: CI: fix fast build by Guillaume Pasero + * !499: CI Add MacOS by Antoine Regimbeau + * !491: CI: packaging by Antoine Regimbeau + * !489: CI: change git and ssh setup by Guillaume Pasero + * !486: CI Use single token for API by Guillaume Pasero + * !483: CI: fixed architecture by Antoine Regimbeau + * !476: CI: fix image name to satisfy regexp by Guillaume Pasero + * !475: CI: use official registry by Guillaume Pasero + * !473: CI fixes for documentation by Guillaume Pasero + * !466: Superbuild CI on Centos 6 by Stéphane Albert + * !465: CI: add fast precheck step by Guillaume Pasero + * !463: Ci local builds by Guillaume Pasero + * !462: CI: only 1 bionic build needed by Guillaume Pasero + * !461: CI: enable documentation build by Guillaume Pasero + * !459: Superbuild CI by Antoine Regimbeau + * !456: Various CI fixes for a lighter dashboard by Guillaume Pasero + * !449: CI: change build name and export short SHA to cdash by Guillaume Pasero + * !443: Link with CDASH by Antoine Regimbeau + * !438: Fix CI failing fetch by Antoine Regimbeau + * !436: Add Debian to CI by Antoine Regimbeau + * !430: Improve Git LFS performances by Guilhem Bonnefille + * !429: Factorize build images specification by Guilhem Bonnefille + * !423: CI: need to simplify CI scripts by Guillaume Pasero + * !418: CI: enable ccache on ubuntu-llvm by Guillaume Pasero + * !416: CI setup all pipelines by Guillaume Pasero + * !399: CI: use lld linker on ubuntu by Guillaume Pasero + * !397: CI: use docker images from gbonnefille registry by Guillaume Pasero + * !394: CI: allow per site configuration by Guillaume Pasero + * !389: CI: use ninja by Guillaume Pasero + * !385: Allow CI to fail by Antoine Regimbeau + * !374: New CI for OTB by Antoine Regimbeau + +Documentation: + + * !594: Fix typo in ossimCosmoSkymedModel by Laurențiu Nicola + * !591: Fix non compliant headers by Cédric Traizet + * !590: Error in FunctorImageFilter.rst example by Julien Michel + * !588: MultivariateAlterationDetector: consistency between doc and code by Cédric Traizet + * !587: Image regression application by Cédric Traizet + * !580: Refactoring of the BandMathX documentation, and fix OpticalCalibration documentation by Cédric Traizet + * !578: DOC: fix documentation_changes template by Guillaume Pasero + * !577: Add a mailmap file by Sébastien Dinot + * !564: Simplify the QGIS documentation by Antoine Regimbeau + * !560: Add Agustin Lobo to PSC by Victor Poughon + * !547: Update version of compiler and add sb version by Antoine Regimbeau + * !538: Ci contributing update by Guillaume Pasero + * !534: DOC: fix missing import & clarify python doc example by Victor Poughon + * !532: DOC: updates to parts of the documentation within the apps by Daniel McInerney + * !514: DOC: review recipe residual registration by Victor Poughon + * !509: Update PSC.md to add Julien Radoux as a PSC member by Julien Michel + * !503: Small update in documentation of step parameter in BlockMatching application by Julien Michel + * !502: Remove Travis and Coverity badges from README.md by Julien Michel + * !501: Review change detection examples by Victor Poughon + * !495: Fix BandMathX documentation by Cédric Traizet + * !492: Display deprecation status in application wrappers by Cédric Traizet + * !485: Add Archlinux installation documentation by Victor Poughon + * !481: Add a section on functor filter in new C++ cookbook part by Julien Michel + * !477: Examples review (part 1) by Victor Poughon + * !472: Add clang-format-diff command line to MR checklist by Julien Michel + * !451: Documentation for atmoshperic correction parameters in OpticalCalibration by Cédric Traizet + * !441: Remove ApplicationHtmlDocGenerator by Victor Poughon + * !440: No data documentation in Segmentation by Cédric Traizet + * !439: DOC: use double quotes for string parameter examples by Victor Poughon + * !435: Remove Software Guide by Victor Poughon + * !431: Show alternative versions in the CookBook by Victor Poughon + * !428: Fix CookBook build inside a virtualenv & add "Compiling documentation" subsection by Victor Poughon + * !425: Hypserspectral image processing recipe by Cédric Traizet + * !415: Reorder cookbook sections and update style by Victor Poughon + * !411: DOC: remove the OTB-Data-Examples step from how-to-release by Guillaume Pasero + * !398: Migrate developer's guide to the cookbook by Victor Poughon + * !395: Render examples in the CookBook by Victor Poughon + * !380: Massive Software Guide clean-up by Julien Michel + * !375: Cookbook FAQ updates & Contributors section by Victor Poughon + * !363: Migrate 'Compiling from source' documentation to CookBook by Victor Poughon + * !347: Bump copyright date by Julien Michel + * !335: Add Haralick features formulas in software guide by Manuel Grizonnet + * !332: Fix cookbook warnings and formatting by Victor Poughon + * !322: DOC: improve documentation on how to pass multiple additional options to otb cmake cache by Manuel Grizonnet + * !316: Christmas CookBook by Victor Poughon + * !312: Add missing listview to doxygen by Victor Poughon + * !291: Qt-Qwt dependency in superbuild by Antoine Regimbeau + * !282: DOC: suggested changes to the documentation by Daniel McInerney + * !265: Resolve "OTB QGIS plugin documentation is outdated" by Guillaume Pasero + * !256: Small Typo by Jee Roen + * !254: ENH: Redispatch applications tagged as Misc to more user oriented tag available… by Manuel Grizonnet + * !246: Add install section to README.md by Victor Poughon + * !238: Typo in cookbook by Victor Poughon + * !228: Document output of training applications by Guillaume Pasero + * !217: DOC: dmci edits to cookbook and installation tex file by Daniel McInerney + * !207: DOC: add missing packages needed to compile otb with superbuild on ubuntu 18.04 by Manuel Grizonnet + * !200: Resolve "Possible confusion when using single-value-mode parameter-lists in CLI" by Victor Poughon + * !185: DOC: update list of contributors by Manuel Grizonnet + * !178: Resolve "Some ITK paths are wrong in the SoftwareGuide" by Yannick TANGUY + * !175: #1611 - Document ParameterType_Bool by Yannick TANGUY + * !174: Adopt SemVer for 7.0.0 and migrate release template to a gitlab issue template by Victor Poughon + * !153: ENH: Document that conversion applications in otb don't support complex pixel types as output by Manuel Grizonnet + * !149: ENH: display parameter description as tool tip for the QtWidgetBoolParameter by Manuel Grizonnet + * !140: DOC: Minor fixes in Software Guide by Victor Poughon + * !137: DOC: Set of proposed edits to the documentation by Daniel McInerney + * !136: DOC: add checklist to MR template by Victor Poughon + * !132: ENH: Add comments to MR template by Victor Poughon + * !129: Update screenshots in Monteverdi Cookbook section with wrong RGB color composition by Manuel Grizonnet + * !124: Document third party environment variables by Julien Michel + OTB-v.6.6.0 - Changes since version 6.4.0 (June 20th, 2018) ----------------------------------------------------------- -- GitLab From ea966060974d4bbcaf15331a4ee4de269ccc1433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Fri, 20 Sep 2019 10:55:58 +0200 Subject: [PATCH 22/73] DOC: run spelling checker --- CI/cdash_handler.py | 2 +- CI/check_twin_pipelines.py | 2 +- CI/configure_options.cmake | 2 +- CMakeLists.txt | 2 +- .../Cookbook/rst/C++/FunctorImageFilter.rst | 4 ++-- Documentation/Cookbook/rst/PythonAPI.rst | 2 +- Documentation/Cookbook/rst/QGISInterface.rst | 2 +- .../GdalAdapters/include/otbSpatialReference.h | 4 ++-- .../app/otbTrainImagesClassifier.cxx | 2 +- .../include/otbTrainSharkKMeans.hxx | 2 +- Modules/Applications/AppImageUtils/app/otbMosaic.cxx | 12 ++++++------ .../Applications/AppImageUtils/test/CMakeLists.txt | 2 +- .../AppMathParserX/test/otbBandMathXAppTests.cxx | 6 +++--- Modules/Core/Functor/include/otbFunctorImageFilter.h | 4 ++-- .../include/otbVariadicNamedInputsImageFilter.h | 2 +- Modules/Core/ImageBase/include/otbImage.h | 2 +- Modules/Core/ImageBase/include/otbVectorImage.h | 2 +- Modules/Core/ImageBase/src/otbImage.cxx | 2 +- Modules/Core/ImageBase/src/otbVectorImage.cxx | 2 +- .../Descriptors/test/otbKeyPointsAlgorithmsTest.cxx | 2 +- .../otbQuadraticallyConstrainedSimpleSolver.h | 2 +- .../Mosaic/include/otbStreamingMosaicFilterBase.h | 2 +- .../otbStreamingMultibandFeatherMosaicFilter.h | 2 +- ...otbStreamingStatisticsMapFromLabelImageFilter.hxx | 2 +- Modules/IO/ImageIO/include/otbImageFileReader.h | 2 +- Modules/IO/ImageIO/include/otbImageFileWriter.h | 2 +- Modules/IO/ImageIO/src/otbImageFileReader.cxx | 2 +- Modules/IO/ImageIO/src/otbImageFileWriter.cxx | 2 +- .../include/otbLabelImageSmallRegionMergingFilter.h | 4 ++-- 29 files changed, 40 insertions(+), 40 deletions(-) diff --git a/CI/cdash_handler.py b/CI/cdash_handler.py index 479bc7ba72..f5662a0d00 100644 --- a/CI/cdash_handler.py +++ b/CI/cdash_handler.py @@ -237,7 +237,7 @@ class Handler: K8S_SECRET_API_TOKEN -> Token for Gitlab API CI_MERGE_REQUEST_REF_PATH -> Ref name to push the status (only for merge request pipeline) CI_COMMIT_REF_NAME -> Ref name to push the status - They can be overriden by a full command line : + They can be overridden by a full command line : cdash_handler.py commit_sha1 project_id project_directory token ref_name """ if __name__ == "__main__": diff --git a/CI/check_twin_pipelines.py b/CI/check_twin_pipelines.py index 76e21a9abc..6276ec1bab 100644 --- a/CI/check_twin_pipelines.py +++ b/CI/check_twin_pipelines.py @@ -66,7 +66,7 @@ if __name__ == "__main__": # are we in a merge_request pipeline ? if 'CI_MERGE_REQUEST_IID' in env.keys(): if not CheckEnvParameters(['K8S_SECRET_API_TOKEN']): - print("WARNING: Make sure you have set a valid acces token for Gitlab API." \ + print("WARNING: Make sure you have set a valid access token for Gitlab API." \ + "The K8S_SECRET_API_TOKEN environment variable should be set in 'Settings -> CI/CD -> Variables'" \ + "Without this token, some feature of the CI platform will be disabled.") sys.exit(0) diff --git a/CI/configure_options.cmake b/CI/configure_options.cmake index 794105f5b9..d92a8c4707 100644 --- a/CI/configure_options.cmake +++ b/CI/configure_options.cmake @@ -56,7 +56,7 @@ OTB_USE_SIFTFAST:BOOL=ON OTB_USE_SPTW:BOOL=ON OTB_USE_SSE_FLAGS:BOOL=ON") -# Usefull if MPI is ON : OTB_MPIEXEC_OPT:STRING=--allow-run-as-root +# Useful if MPI is ON : OTB_MPIEXEC_OPT:STRING=--allow-run-as-root set (otb_wrap_option "OTB_WRAP_PYTHON:BOOL=ON") diff --git a/CMakeLists.txt b/CMakeLists.txt index c82978d00f..778003cf48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ reset_qt_i18n_sources() repository_status(${PROJECT_SOURCE_DIR} OTB_GIT_STATUS_MESSAGE) # Find python stuff -# Version 3 is prefered before 2 +# Version 3 is preferred before 2 set ( Python_ADDITIONAL_VERSIONS "3;2" ) set ( PythonInterp_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) set ( PythonLibs_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) diff --git a/Documentation/Cookbook/rst/C++/FunctorImageFilter.rst b/Documentation/Cookbook/rst/C++/FunctorImageFilter.rst index 9a9e736f00..8d79e59a57 100644 --- a/Documentation/Cookbook/rst/C++/FunctorImageFilter.rst +++ b/Documentation/Cookbook/rst/C++/FunctorImageFilter.rst @@ -116,7 +116,7 @@ Alternative prototype for performance Automatic type deduction will also work with the following signature: ``void (const R&, T1 t1, T2 t2 ..., TN tn)`` -This will be more efficient when ``R`` is of type ``itk::VariableLengthVector`` and should be prefered in this case. +This will be more efficient when ``R`` is of type ``itk::VariableLengthVector`` and should be preferred in this case. Automatic type deduction examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -125,7 +125,7 @@ Consider the following free function: .. code-block:: cpp - itk::VariableLenghtVector myFreeFunction(unsigned char a, + itk::VariableLengthVector myFreeFunction(unsigned char a, const std::complex& b, const itk::VariableLengthVector& c, const itk::ConstNeighborhoodIterator>& d) {...} diff --git a/Documentation/Cookbook/rst/PythonAPI.rst b/Documentation/Cookbook/rst/PythonAPI.rst index b299082dd8..f417ff4a40 100644 --- a/Documentation/Cookbook/rst/PythonAPI.rst +++ b/Documentation/Cookbook/rst/PythonAPI.rst @@ -224,7 +224,7 @@ Mixed in-memory / on-disk connection As an extension to the connection of OTB Applications (described in previous section), a mixed mode is also available to easily switch between: -- **in-memory**: if you want to avoid unecessary I/O between applications +- **in-memory**: if you want to avoid unnecessary I/O between applications - **on-disk**: if you want intermediate outputs on disk This mixed mode is based on the ``Application::ConnectImage()`` function. This diff --git a/Documentation/Cookbook/rst/QGISInterface.rst b/Documentation/Cookbook/rst/QGISInterface.rst index df569c32be..61c3765b99 100644 --- a/Documentation/Cookbook/rst/QGISInterface.rst +++ b/Documentation/Cookbook/rst/QGISInterface.rst @@ -13,7 +13,7 @@ With QGIS > 3.8, the plugin is in the QGIS core. So you just need install OTB an Download and Install OTB ^^^^^^^^^^^^^^^^^^^^^^^^ -OTB is not distributed with qgis-otb-plugin. It is a seperate project and has its own git repository. +OTB is not distributed with qgis-otb-plugin. It is a separate project and has its own git repository. Download latest OTB version: https://www.orfeo-toolbox.org/download/. Configure plugin in QGIS diff --git a/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h b/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h index aa3e94552c..2605ad12f0 100644 --- a/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h +++ b/Modules/Adapters/GdalAdapters/include/otbSpatialReference.h @@ -67,7 +67,7 @@ OTBGdalAdapters_EXPORT bool operator!=(const SpatialReference& sr1, const Spatia * either they fail or they provide a definitive, valid object. * * Building a SpatialReference requires to call one of the From*() - * method. There are no public constructors (appart from copy and + * method. There are no public constructors (apart from copy and * assignment) * * \ingroup OTBGdalAdapters @@ -167,7 +167,7 @@ public: * \pre -180<=lon<=180 * \pre -90<=lat<=90 * \param lon Point longitude - * \param lat Point lattitude + * \param lat Point latitude * \param zone Output UTM zone * \param hem output hemisphere */ diff --git a/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx b/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx index 573e3c7fbf..67ca2c21e2 100644 --- a/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx +++ b/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.cxx @@ -48,7 +48,7 @@ public: "The training vector data must contain polygons with a positive integer field " "representing the class label. The name of this field can be set using the *Class label field* parameter.\n\n" - "Training and validation sample lists are built such that each class is equally represented in both lists. One parameter controlls the ratio " + "Training and validation sample lists are built such that each class is equally represented in both lists. One parameter controls the ratio " "between the number of samples in training and validation sets. Two parameters manage the size of the training and " "validation sets per class and per image.\n\n" diff --git a/Modules/Applications/AppClassification/include/otbTrainSharkKMeans.hxx b/Modules/Applications/AppClassification/include/otbTrainSharkKMeans.hxx index 69a4e9106c..91347c7f7b 100644 --- a/Modules/Applications/AppClassification/include/otbTrainSharkKMeans.hxx +++ b/Modules/Applications/AppClassification/include/otbTrainSharkKMeans.hxx @@ -107,7 +107,7 @@ void LearningApplicationBase::TrainSharkKMeans(typena for (unsigned int i = 0; i < meanMeasurementVector.Size(); ++i) { scaleRV[i] = 1 / stddevMeasurementVector[i]; - // Substract the normalized mean + // Subtract the normalized mean offsetRV[i] = -meanMeasurementVector[i] / stddevMeasurementVector[i]; } diff --git a/Modules/Applications/AppImageUtils/app/otbMosaic.cxx b/Modules/Applications/AppImageUtils/app/otbMosaic.cxx index ea99fef775..a575dc182c 100644 --- a/Modules/Applications/AppImageUtils/app/otbMosaic.cxx +++ b/Modules/Applications/AppImageUtils/app/otbMosaic.cxx @@ -276,11 +276,11 @@ private: SetMinimumParameterFloatValue("comp.feather.slim.exponent", 0); MandatoryOff("comp.feather.slim.exponent"); - // comp.feather.slim.lenght (i.e. blending lenght) - AddParameter(ParameterType_Float, "comp.feather.slim.lenght", "Transition length (In cartographic units)"); - MandatoryOn("comp.feather.slim.lenght"); - SetMinimumParameterFloatValue("comp.feather.slim.lenght", 0); - MandatoryOff("comp.feather.slim.lenght"); + // comp.feather.slim.length (i.e. blending length) + AddParameter(ParameterType_Float, "comp.feather.slim.length", "Transition length (In cartographic units)"); + MandatoryOn("comp.feather.slim.length"); + SetMinimumParameterFloatValue("comp.feather.slim.length", 0); + MandatoryOff("comp.feather.slim.length"); // harmo (harmonization) AddParameter(ParameterType_Group, "harmo", "Spectral bands harmonization mode"); @@ -969,7 +969,7 @@ private: ComputeDistanceOffset(m_SlimFeatherMosaicFilter); // Set transition length and smoothness - m_SlimFeatherMosaicFilter->SetFeatheringTransitionDistance(GetParameterFloat("comp.feather.slim.lenght")); + m_SlimFeatherMosaicFilter->SetFeatheringTransitionDistance(GetParameterFloat("comp.feather.slim.length")); m_SlimFeatherMosaicFilter->SetFeatheringSmoothness(GetParameterFloat("comp.feather.slim.exponent")); mosaicFilter = static_cast(m_SlimFeatherMosaicFilter); diff --git a/Modules/Applications/AppImageUtils/test/CMakeLists.txt b/Modules/Applications/AppImageUtils/test/CMakeLists.txt index 052a21d063..19c2f257fb 100644 --- a/Modules/Applications/AppImageUtils/test/CMakeLists.txt +++ b/Modules/Applications/AppImageUtils/test/CMakeLists.txt @@ -472,7 +472,7 @@ otb_test_application(NAME MosaicTestSlimFeathering OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif -out ${TEMP}/apTvMosaicTestSlimFeathering.tif uint8 -comp.feather slim - -comp.feather.slim.lenght 100 + -comp.feather.slim.length 100 VALID --compare-image ${EPSILON_8} ${BASELINE}/apTvMosaicTestSlimFeathering.tif ${TEMP}/apTvMosaicTestSlimFeathering.tif) diff --git a/Modules/Applications/AppMathParserX/test/otbBandMathXAppTests.cxx b/Modules/Applications/AppMathParserX/test/otbBandMathXAppTests.cxx index 2f0fdfe725..0ebb533ac1 100644 --- a/Modules/Applications/AppMathParserX/test/otbBandMathXAppTests.cxx +++ b/Modules/Applications/AppMathParserX/test/otbBandMathXAppTests.cxx @@ -86,7 +86,7 @@ int main(int, char* argv[]) auto output = app->GetParameterImageBase("out"); output->Update(); float im_val = 0; - // We need to be carefull as we are taking the direct output of the underlying + // We need to be careful as we are taking the direct output of the underlying // filter in the application otb::VectorImage* output_int = nullptr; dyn_cast(output, output_int) im_val = output_int->GetPixel(index).GetElement(0); @@ -128,7 +128,7 @@ int main(int, char* argv[]) app->Execute(); output = app->GetParameterImageBase("out"); output->Update(); - // We need to be carefull as we are taking the direct output of the underlying + // We need to be careful as we are taking the direct output of the underlying // filter in the application dyn_cast(output, output_int) im_val = output_int->GetPixel(index).GetElement(0); if (im_val != 0) @@ -156,7 +156,7 @@ int main(int, char* argv[]) app->Execute(); output = app->GetParameterImageBase("out"); output->Update(); - // We need to be carefull as we are taking the direct output of the underlying + // We need to be careful as we are taking the direct output of the underlying // filter in the application dyn_cast(output, output_int) im_val = output_int->GetPixel(index).GetElement(0); if (im_val != 5) diff --git a/Modules/Core/Functor/include/otbFunctorImageFilter.h b/Modules/Core/Functor/include/otbFunctorImageFilter.h index 842f48cb13..27d8ac0fdf 100644 --- a/Modules/Core/Functor/include/otbFunctorImageFilter.h +++ b/Modules/Core/Functor/include/otbFunctorImageFilter.h @@ -179,7 +179,7 @@ struct RetrieveOperator * * Provides the following: * - OutputImageType : type of the output image -* - FilterType : correct instanciation of VariadicInputsImageFilter from +* - FilterType : correct instantiation of VariadicInputsImageFilter from * - the operator() prototype * - InputHasNeighborhood a tuple of N false_type or true_type to denote * - if Ith arg of operator() expects a neighborhood. @@ -443,7 +443,7 @@ auto NewFunctorFilter(Functor f, itk::Size<2> radius) * \brief This struct allows to forward the operator of template * parameter, while adding number of ouptut components service. * - * Its purpose is to enable the use of lambda or functor witht + * Its purpose is to enable the use of lambda or functor with * Outputsize() method with FunctorImageFilter. * * It is used internally in NewFunctorFilter version with diff --git a/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h b/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h index 7ecdf36222..19e993173c 100644 --- a/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h +++ b/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h @@ -33,7 +33,7 @@ namespace internal * \struct tuple_index * \brief retrieve index of a type in tuple if exists * - * This struct allows to retrieve the index of the first occurence of type + * This struct allows to retrieve the index of the first occurrence of type * Arg in tuple Tuple. If type Arg can not be found, compilation will * end with a static_assert failing. * diff --git a/Modules/Core/ImageBase/include/otbImage.h b/Modules/Core/ImageBase/include/otbImage.h index 0e4f765e93..29a338f3de 100644 --- a/Modules/Core/ImageBase/include/otbImage.h +++ b/Modules/Core/ImageBase/include/otbImage.h @@ -280,7 +280,7 @@ private: namespace otb { -// Prevent implicit instanciation of common types to improve build performance +// Prevent implicit instantiation of common types to improve build performance // Explicit instanciations are provided in the .cxx extern template class OTBImageBase_EXPORT_TEMPLATE Image; extern template class OTBImageBase_EXPORT_TEMPLATE Image; diff --git a/Modules/Core/ImageBase/include/otbVectorImage.h b/Modules/Core/ImageBase/include/otbVectorImage.h index 482b7983df..cd771f7924 100644 --- a/Modules/Core/ImageBase/include/otbVectorImage.h +++ b/Modules/Core/ImageBase/include/otbVectorImage.h @@ -221,7 +221,7 @@ private: namespace otb { -// Prevent implicit instanciation of common types to improve build performance +// Prevent implicit instantiation of common types to improve build performance // Explicit instanciations are provided in the .cxx extern template class OTBImageBase_EXPORT_TEMPLATE VectorImage; extern template class OTBImageBase_EXPORT_TEMPLATE VectorImage; diff --git a/Modules/Core/ImageBase/src/otbImage.cxx b/Modules/Core/ImageBase/src/otbImage.cxx index eef3a2a70f..f28a3170f9 100644 --- a/Modules/Core/ImageBase/src/otbImage.cxx +++ b/Modules/Core/ImageBase/src/otbImage.cxx @@ -23,7 +23,7 @@ namespace otb { -// Explicit instanciation of common types +// Explicit instantiation of common types template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE Image; template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE Image; template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE Image; diff --git a/Modules/Core/ImageBase/src/otbVectorImage.cxx b/Modules/Core/ImageBase/src/otbVectorImage.cxx index 92fc817d81..0673b295ab 100644 --- a/Modules/Core/ImageBase/src/otbVectorImage.cxx +++ b/Modules/Core/ImageBase/src/otbVectorImage.cxx @@ -23,7 +23,7 @@ namespace otb { -// Explicit instanciation of common types +// Explicit instantiation of common types template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE VectorImage; template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE VectorImage; template class OTBImageBase_EXPORT_EXPLICIT_TEMPLATE VectorImage; diff --git a/Modules/Feature/Descriptors/test/otbKeyPointsAlgorithmsTest.cxx b/Modules/Feature/Descriptors/test/otbKeyPointsAlgorithmsTest.cxx index 1803436fd3..fca23e0fc2 100644 --- a/Modules/Feature/Descriptors/test/otbKeyPointsAlgorithmsTest.cxx +++ b/Modules/Feature/Descriptors/test/otbKeyPointsAlgorithmsTest.cxx @@ -159,7 +159,7 @@ bool testMatchingFilter() } -/** Generate a pair of images, one beeing slightly warped wrt the +/** Generate a pair of images, one being slightly warped wrt the * other */ auto generateImagePair(const std::string& infname, double rotation, double scaling) { diff --git a/Modules/Filtering/Mosaic/include/otbQuadraticallyConstrainedSimpleSolver.h b/Modules/Filtering/Mosaic/include/otbQuadraticallyConstrainedSimpleSolver.h index f51a180e00..4f370338b4 100644 --- a/Modules/Filtering/Mosaic/include/otbQuadraticallyConstrainedSimpleSolver.h +++ b/Modules/Filtering/Mosaic/include/otbQuadraticallyConstrainedSimpleSolver.h @@ -206,7 +206,7 @@ private: // Output correction models RealVectorType m_OutputCorrectionModel; - // objective funciton type (enum) + // objective function type (enum) ObjectiveFunctionType oft; }; diff --git a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h index 0521f0c26d..8e423d247e 100644 --- a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h +++ b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h @@ -39,7 +39,7 @@ namespace otb * The otb::StreamingMosaicFilterBase allows to compute what the final * mosaic of multiple input of otb::VectorImage is, and provide the requested * regions of input images. There is a shift-scale mode which allows - * to shift-scale input images, which can be usefull e.g. color or + * to shift-scale input images, which can be useful e.g. color or * radiometric harmonization of input set of images. The output * spacing (SetOuputSpacing()), the start index (SetOutputIndex()) and * the interpolator (SetInterpolator()) and the origin (SetOrigin()) diff --git a/Modules/Filtering/Mosaic/include/otbStreamingMultibandFeatherMosaicFilter.h b/Modules/Filtering/Mosaic/include/otbStreamingMultibandFeatherMosaicFilter.h index 42e7ade7b3..85bae42365 100644 --- a/Modules/Filtering/Mosaic/include/otbStreamingMultibandFeatherMosaicFilter.h +++ b/Modules/Filtering/Mosaic/include/otbStreamingMultibandFeatherMosaicFilter.h @@ -42,7 +42,7 @@ namespace otb * * The filter implements the multiband blending strategy. Laplacian * of input images is computed, then each frequency is mosaiced using - * a StreamingFeatherMosaicFilter. Finaly the summing of all frequencies + * a StreamingFeatherMosaicFilter. Finally the summing of all frequencies * is performed to get the final mosaic image. * * Mandatory inputs : images to mosaic + alpha channels diff --git a/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.hxx b/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.hxx index 17c4b1f1ca..69487ec76e 100644 --- a/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.hxx +++ b/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.hxx @@ -175,7 +175,7 @@ void PersistentStreamingStatisticsMapFromLabelImageFilter>; extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileReader>; diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.h b/Modules/IO/ImageIO/include/otbImageFileWriter.h index ca32f531f6..c1e5fffbda 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.h +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.h @@ -297,7 +297,7 @@ private: namespace otb { -// Prevent implicit instanciation of common types to improve build performance +// Prevent implicit instantiation of common types to improve build performance // Explicit instanciations are provided in the .cxx extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter>; extern template class OTBImageIO_EXPORT_TEMPLATE ImageFileWriter>; diff --git a/Modules/IO/ImageIO/src/otbImageFileReader.cxx b/Modules/IO/ImageIO/src/otbImageFileReader.cxx index b65c2902c1..465d8607bd 100644 --- a/Modules/IO/ImageIO/src/otbImageFileReader.cxx +++ b/Modules/IO/ImageIO/src/otbImageFileReader.cxx @@ -23,7 +23,7 @@ namespace otb { -// Explicit instanciation of common types +// Explicit instantiation of common types template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileReader>; template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileReader>; template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileReader>; diff --git a/Modules/IO/ImageIO/src/otbImageFileWriter.cxx b/Modules/IO/ImageIO/src/otbImageFileWriter.cxx index 9b83c31ea3..763f4c1567 100644 --- a/Modules/IO/ImageIO/src/otbImageFileWriter.cxx +++ b/Modules/IO/ImageIO/src/otbImageFileWriter.cxx @@ -23,7 +23,7 @@ namespace otb { -// Explicit instanciation of common types +// Explicit instantiation of common types template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileWriter>; template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileWriter>; template class OTBImageIO_EXPORT_EXPLICIT_TEMPLATE ImageFileWriter>; diff --git a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h index c5c5465074..e65e88369d 100644 --- a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h +++ b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h @@ -102,7 +102,7 @@ public: protected: /** The input requested region should be padded by a radius of 1 to use the - * neigbourhood iterator */ + * neighbourhood iterator */ void GenerateInputRequestedRegion() override; /** Threaded Generate Data : find the neighbours of each segments of size @@ -136,7 +136,7 @@ private: /** Map containing at key i the mean of element of the segment labelled i */ LabelStatisticType m_LabelStatistic; - /** Neigbours maps for each thread */ + /** Neighbours maps for each thread */ std::vector m_NeighboursMapsTmp; /** LUT giving correspondance between labels in the original segmentation -- GitLab From 9a4ab4e6fb5fb5d5a2ceb1ef1bb471961bbcc1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Fri, 20 Sep 2019 11:08:15 +0200 Subject: [PATCH 23/73] ENH: apply shellcheck --- Utilities/Maintenance/SuperbuildDownloadList.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities/Maintenance/SuperbuildDownloadList.sh b/Utilities/Maintenance/SuperbuildDownloadList.sh index 0297395c03..c436e2c5c7 100755 --- a/Utilities/Maintenance/SuperbuildDownloadList.sh +++ b/Utilities/Maintenance/SuperbuildDownloadList.sh @@ -79,6 +79,6 @@ ARCHIVE_NAME="SuperBuild-archives-$VERSION" echo "Creating archive ${OUTPUT_DIR}/$ARCHIVE_NAME.tar.bz2" cd "${OUTPUT_DIR}" || echo "cannot cd to OUTPUT_DIR" touch "${DOWNLOAD_DIR}/OTBSuperBuild.readme" -tar -cjf "$ARCHIVE_NAME.tar.bz2" -C "${DOWNLOAD_DIR}" ${DOWNLOAD_NAMES} OTBSuperBuild.readme +tar -cjf "$ARCHIVE_NAME.tar.bz2" -C "${DOWNLOAD_DIR}" "${DOWNLOAD_NAMES}" OTBSuperBuild.readme echo "Saving md5sum to ${OUTPUT_DIR}/$ARCHIVE_NAME.md5" md5sum "$ARCHIVE_NAME.tar.bz2" > "$ARCHIVE_NAME.md5" -- GitLab From c40402ab6dca05971421e255d3ce2af26273da08 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Fri, 20 Sep 2019 12:32:01 +0200 Subject: [PATCH 24/73] Removed obsolete code. --- .../Ice/include/otbGlImageActor.h | 11 +-- .../Visualization/Ice/src/otbGlImageActor.cxx | 79 +------------------ 2 files changed, 3 insertions(+), 87 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 40f9af4742..d8f15976c1 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -37,8 +37,6 @@ #include -#define USE_GL_RAII 1 - namespace otb { @@ -317,15 +315,8 @@ private: ResolutionAlgorithm::type m_ResolutionAlgorithm; -#if !USE_GL_RAII - // index of Vertex Array Object - unsigned int m_VAO; - - // index of Vector Buffer Object - unsigned int m_VBO; -#else + /** OpenGL quad. */ std::unique_ptr< gl::Mesh > m_Mesh; -#endif }; // End class GlImageActor diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 3148ba7c7c..2cf0e70276 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -86,12 +86,7 @@ GlImageActor::GlImageActor() m_ViewportForwardRotationTransform(RigidTransformType::New()), m_ViewportBackwardRotationTransform(RigidTransformType::New()), m_ResolutionAlgorithm(ResolutionAlgorithm::Nearest), -#if !USE_GL_RAII - m_VAO(0), - m_VBO(0) -#else m_Mesh() -#endif {} GlImageActor @@ -118,66 +113,6 @@ GlImageActor shader->SetImageSettings( m_ImageSettings ); -#if !USE_GL_RAII - - // Use a Vertex Array Object - glGenVertexArrays(1, &m_VAO); - glBindVertexArray(m_VAO); - - // 1 square (made by 2 triangles) to be rendered - GLfloat vertexPosition[8] = { - -1.0, -1.0, - 1.0, -1.0, - 1.0, 1.0, - -1.0, 1.0 - }; - - GLfloat texCoord[8] = { - 0.0, 1.0, - 1.0, 1.0, - 1.0, 0.0, - 0.0, 0.0, - }; - - GLuint indices[6] = { - 0, 1, 2, - 2, 3, 0 - }; - - // Create a Vector Buffer Object that will store the vertices on video memory - glGenBuffers(1, &m_VBO); - - // Allocate space for vertex positions and texture coordinates - glBindBuffer(GL_ARRAY_BUFFER, m_VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPosition) + sizeof(texCoord), NULL, GL_STATIC_DRAW); - - // Transfer the vertex positions: - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); - - // Transfer the texture coordinates: - glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertexPosition), sizeof(texCoord), texCoord); - - // Create an Element Array Buffer that will store the indices array: - GLuint eab; - glGenBuffers(1, &eab); - - // Transfer the data from indices to eab - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eab); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); - - // get attribute position for position and in_coord - int posIdx = shader->GetAttribIdx()[0]; - int texIdx = shader->GetAttribIdx()[1]; - - // Specify how the data for position can be accessed - glVertexAttribPointer(posIdx, 2, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(posIdx); - - // Texture coord attribute - glVertexAttribPointer(texIdx, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid *)sizeof(vertexPosition)); - glEnableVertexAttribArray(texIdx); - -#else // Check previous OpenGL error and clear error flag. gl::CheckError< gl::error::clear >(); @@ -188,10 +123,6 @@ GlImageActor ) ); - // assert( m_Mesh ); - // m_Mesh->Bind( false ); -#endif - // Should be done last in order to ensure exception-safety of // invariant. m_Shader = shader; @@ -452,16 +383,11 @@ void GlImageActor::Render() -1.0f, 1.0f }; -#if !USE_GL_RAII - glBindVertexArray(m_VAO); - glBindBuffer(GL_ARRAY_BUFFER, m_VBO); -#else // Check OpenGL error and clear error flag. gl::CheckError< gl::error::clear >(); assert( m_Mesh ); m_Mesh->Bind(); -#endif for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) @@ -502,7 +428,6 @@ void GlImageActor::Render() } m_Shader->UnloadShader(); - } void GlImageActor::LoadTile(Tile& tile) @@ -541,7 +466,7 @@ void GlImageActor::LoadTile(Tile& tile) unsigned int idx = 0; for(it.GoToBegin();!it.IsAtEnd();++it) - { + { buffer[idx] = static_cast(it.Get()[2]); ++idx; buffer[idx] = static_cast(it.Get()[1]); @@ -550,7 +475,7 @@ void GlImageActor::LoadTile(Tile& tile) ++idx; buffer[idx] = 255.; ++idx; - } + } // Now load the texture assert( tile.m_TextureId==0 ); -- GitLab From 7e46b5f719699d46842caa8acbdd0b6b32c2b2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Fri, 20 Sep 2019 15:37:31 +0200 Subject: [PATCH 25/73] DOC: update french translation for release 7.0 --- i18n/fr_FR.ts | 85 +++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/i18n/fr_FR.ts b/i18n/fr_FR.ts index 21539d9b95..4ca42ee6ab 100644 --- a/i18n/fr_FR.ts +++ b/i18n/fr_FR.ts @@ -1,6 +1,6 @@ - + ColorSetupController @@ -136,11 +136,11 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. QObject Execute - Exécuter + Exécuter Quit - Quitter + Quitter @@ -455,7 +455,7 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. Title - Titre + Titre Name @@ -692,7 +692,7 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. Form - + <html><head/><body><p align="center">Image bands<br/>↓</p></body></html> <html><head/><body><p align="center">Bandes<br/>↓</p></body></html> @@ -731,7 +731,7 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. BAND %1 - BANDE %1 + BANDE %1 Red @@ -1205,25 +1205,10 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. Necessary for lupdate to be aware of C++ namespaces. Context comment for translator. - - WARNG> %s - - - - - ERROR> %s - - - Error: Erreur : - - FATAL> %s - - - Fatal error: Erreur fatale : @@ -1314,11 +1299,11 @@ Veuillez, s'il vous plait, supprimer votre répertoire de cache Monteverdi. Cannot access settings file. - Impossible d'accéder au fichiers des paramètres + Impossible d'accéder au fichiers des paramètres Bad settings file format. - Mauvais format pour le fichier de paramètres + Mauvais format pour le fichier de paramètres An error occurred while loading the geoid file, no geoid file will be used: @@ -1633,7 +1618,7 @@ Si vous exécutez cette application via une système d'écran déporté, le Version M.m.pl (codename) Version M.m.pl (codename) - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } @@ -2620,7 +2605,7 @@ p, li { white-space: pre-wrap; } Necessary for lupdate to be aware of C++ namespaces. Context comment for translator. - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } @@ -3964,11 +3949,11 @@ Voulez-vous sauvegarder avant de quitter ? Image view - Vue image + Vue image Tab cannot be closed while OTB application is running. - L'onglet de l'application OTB ne peut pas être fermé lors de l'exécution de l'application OTB. + L'onglet de l'application OTB ne peut pas être fermé lors de l'exécution de l'application OTB. Welcome new Montevedi2 user ! @@ -4152,6 +4137,14 @@ Charger '%1' provoquera l'affichage des couches dans une vue non Use OpenGL Shading Language (GLSL) Utiliser OpenGL Shading Language (GLSL) + + Documentation + Documentation + + + F1 + F1 + mvd::MainWindowTitleLoader @@ -4243,6 +4236,14 @@ Charger '%1' provoquera l'affichage des couches dans une vue non Enable OTB_USE_QT preprocessor definition at compile time! Activer la définition de pré-processeur OTB_USE_QT lors de la compilation ! + + Documentation + Documentation + + + F1 + F1 + mvd::Math @@ -4405,12 +4406,16 @@ Charger '%1' provoquera l'affichage des couches dans une vue non Generting overviews for file %1/%2 '%3'. - Génération des Overview pour le fichier %1/%2 '%3'. + Génération des Overview pour le fichier %1/%2 '%3'. Preparing to build GDAL overviews... Préparation à la construction des Overview GDAL... + + Generating overviews for file %1/%2 '%3'. + Génération des Overview pour le fichier %1/%2 '%3'. + mvd::PixelDescriptionWidget @@ -5091,11 +5096,11 @@ Le(s) résultat(s) vont être importés en tant que jeu de données. Warning! - Avertissement ! + Avertissement ! OTB-Application '%1' cannot be closed while running! - Impossible de fermer l'OTB-Application '%1' pendant sont exécution ! + Impossible de fermer l'OTB-Application '%1' pendant sont exécution ! Following files will be overwritten. Are you sure you want to continue? @@ -5104,43 +5109,43 @@ Le(s) résultat(s) vont être importés en tant que jeu de données. File '%1' is being viewed in - Le fichier '%1' est en cours de visualisation dans + Le fichier '%1' est en cours de visualisation dans Following files are being viewed in - Les fichiers suivants sont en cours de visualisation dans + Les fichiers suivants sont en cours de visualisation dans Running - En cours + En cours Done - Terminé + Terminé Failed - Echec + Echec Ready to run - Prêt à démarrer + Prêt à démarrer Select parameters - Choix des paramètres + Choix des paramètres Parameters - Paramètres + Paramètres Documentation - Documentation + Documentation Logs - Logs + Logs -- GitLab From 666afba758fbb29a6fc9450e68cdc42fc661e35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 24 Sep 2019 14:34:05 +0200 Subject: [PATCH 26/73] CI: add legal check job to release pipelines --- .gitlab-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b688cca53c..c4bc886168 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -119,7 +119,10 @@ fast-build: legal-check: extends: .common - only: [merge_requests, develop, headers_check] + only: + - merge_requests + - develop + - /^release-[0-9]+\.[0-9]+$/ stage: precheck image: $BUILD_IMAGE_REGISTRY/otb-alpine:3.7 variables: -- GitLab From 504f620597e5264724e188f4dd00e26ff94fbd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 24 Sep 2019 14:38:02 +0200 Subject: [PATCH 27/73] CI: remove diapotb while it doesn't compile --- CI/configure_options.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI/configure_options.cmake b/CI/configure_options.cmake index d92a8c4707..ad344a182a 100644 --- a/CI/configure_options.cmake +++ b/CI/configure_options.cmake @@ -70,7 +70,7 @@ if(XDK_PATH) set(cmake_configure_option "${cmake_configure_option} CMAKE_PREFIX_PATH=${XDK_PATH}") -foreach(remote_module OTBTemporalGapFilling SertitObject DiapOTBModule)#otbGRM +foreach(remote_module OTBTemporalGapFilling SertitObject)#otbGRM DiapOTBModule set(cmake_configure_option "${cmake_configure_option} Module_${remote_module}:BOOL=ON") -- GitLab From e99d83e95fb089d701b7c013b458e8720f1d5aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 24 Sep 2019 17:25:30 +0200 Subject: [PATCH 28/73] COMP: update tag for otbGRM remote module --- Modules/Remote/otbGRM.remote.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Remote/otbGRM.remote.cmake b/Modules/Remote/otbGRM.remote.cmake index 5224df15d1..f768e8eaf8 100644 --- a/Modules/Remote/otbGRM.remote.cmake +++ b/Modules/Remote/otbGRM.remote.cmake @@ -32,5 +32,5 @@ A more detailed description can be found on the project website: http://tully.ups-tlse.fr/lassallep/grm " GIT_REPOSITORY https://github.com/orfeotoolbox/GRM - GIT_TAG 209161cc0b3fadad7999e80b83838868f430289e + GIT_TAG 75ffa60a382de74ae7a66328919d7da543eaf013 ) -- GitLab From a83c2bbdb994f48c76e061fe34ca701bb3f0ddd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 24 Sep 2019 17:25:51 +0200 Subject: [PATCH 29/73] CI: enable otbGRM in CI --- CI/configure_options.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI/configure_options.cmake b/CI/configure_options.cmake index ad344a182a..256c794cbf 100644 --- a/CI/configure_options.cmake +++ b/CI/configure_options.cmake @@ -70,7 +70,7 @@ if(XDK_PATH) set(cmake_configure_option "${cmake_configure_option} CMAKE_PREFIX_PATH=${XDK_PATH}") -foreach(remote_module OTBTemporalGapFilling SertitObject)#otbGRM DiapOTBModule +foreach(remote_module OTBTemporalGapFilling SertitObject otbGRM)# DiapOTBModule set(cmake_configure_option "${cmake_configure_option} Module_${remote_module}:BOOL=ON") -- GitLab From e4e7b1fdf5b7b2d80b23f39b7d5b4c8c893e4142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Wed, 25 Sep 2019 10:55:49 +0200 Subject: [PATCH 30/73] ENH: update tag for otbGRM remote module --- Modules/Remote/otbGRM.remote.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Remote/otbGRM.remote.cmake b/Modules/Remote/otbGRM.remote.cmake index f768e8eaf8..20da8b0332 100644 --- a/Modules/Remote/otbGRM.remote.cmake +++ b/Modules/Remote/otbGRM.remote.cmake @@ -32,5 +32,5 @@ A more detailed description can be found on the project website: http://tully.ups-tlse.fr/lassallep/grm " GIT_REPOSITORY https://github.com/orfeotoolbox/GRM - GIT_TAG 75ffa60a382de74ae7a66328919d7da543eaf013 + GIT_TAG 043c523df522dd31fb2dfc460ef292e6a679a81f ) -- GitLab From 5eaf875d0b88fb3ca17aad7ac3290a1e20111e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Wed, 25 Sep 2019 10:44:50 +0200 Subject: [PATCH 31/73] CI: update diapotb branch --- Modules/Remote/diapotb.remote.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Remote/diapotb.remote.cmake b/Modules/Remote/diapotb.remote.cmake index 71cc6f2d5c..f4b1e54025 100644 --- a/Modules/Remote/diapotb.remote.cmake +++ b/Modules/Remote/diapotb.remote.cmake @@ -22,5 +22,5 @@ otb_fetch_module(DiapOTBModule "OTB module for SAR processing in Diapason." GIT_REPOSITORY https://gitlab.orfeo-toolbox.org/remote_modules/diapotb.git - GIT_TAG d38457a019d2ef15a47d04c21f235c9e9fe4acd5 + GIT_TAG ec5970752f44dc0b2e7357d1b223f5825d1ec5ab ) -- GitLab From 6db26de0d3aabf3593d2436ce185c7ce0cd378f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Wed, 25 Sep 2019 13:19:05 +0200 Subject: [PATCH 32/73] CI: enable diapotb --- CI/configure_options.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI/configure_options.cmake b/CI/configure_options.cmake index 256c794cbf..2de6844a26 100644 --- a/CI/configure_options.cmake +++ b/CI/configure_options.cmake @@ -70,7 +70,7 @@ if(XDK_PATH) set(cmake_configure_option "${cmake_configure_option} CMAKE_PREFIX_PATH=${XDK_PATH}") -foreach(remote_module OTBTemporalGapFilling SertitObject otbGRM)# DiapOTBModule +foreach(remote_module OTBTemporalGapFilling SertitObject otbGRM DiapOTBModule) set(cmake_configure_option "${cmake_configure_option} Module_${remote_module}:BOOL=ON") -- GitLab From 49150d43f26fd8609f43c6f64494bc29cec559be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Thu, 26 Sep 2019 11:15:55 +0200 Subject: [PATCH 33/73] DOC: add 7.0 to available Cookbook versions --- Documentation/Cookbook/_static/html/versions.html | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/Cookbook/_static/html/versions.html b/Documentation/Cookbook/_static/html/versions.html index 1b3fb09d13..0900284559 100644 --- a/Documentation/Cookbook/_static/html/versions.html +++ b/Documentation/Cookbook/_static/html/versions.html @@ -10,6 +10,7 @@
6.2.0
6.4.0
6.6.1
+
7.0.0
develop
-- GitLab From 8e5ff603572e3bc677b536e0d863bee201dde3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Mon, 30 Sep 2019 17:37:05 +0200 Subject: [PATCH 34/73] BUG: OTB_ADDITIONAL_CACHE description cannot be written on several lines --- SuperBuild/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index f4a9ffd6c0..d2b8b27e5a 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -54,9 +54,8 @@ mark_as_advanced(BUILD_GEOS_STATIC_LIBS) option(BUILD_ALWAYS "Always build or install OTB." ON) option(WITH_REMOTE_MODULES "Build with specific list of remote modules." OFF) option(OTB_USE_OPENMP "use openmp" OFF) -set(OTB_ADDITIONAL_CACHE "" CACHE STRING "Additional cmake options for OTB with " - "the syntax (semi-colon used as a separator): " - "-D:=;-D:=") +set(OTB_ADDITIONAL_CACHE "" CACHE STRING "Additional cmake options for OTB with the syntax (semi-colon used as a separator): -D:=;-D:=") + if(APPLE) set(CMAKE_MACOSX_RPATH TRUE) -- GitLab From ab0715c81bf45a52ad4abf63dc36a8487333d2a3 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Tue, 1 Oct 2019 16:10:06 +0200 Subject: [PATCH 35/73] Synchronized OpenGL and GLSL requirements with shader code version. --- .../Ice/src/otbGlVersionChecker.cxx | 5 +- .../Ice/src/otbShaderRegistry.cxx | 7 +- .../Ice/src/otbStandardShader.cxx | 79 ++++++++----------- .../MonteverdiGui/src/mvdImageViewWidget.cxx | 38 ++++++--- 4 files changed, 72 insertions(+), 57 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx b/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx index bf96abcbfc..e6e430c056 100644 --- a/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx +++ b/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx @@ -35,8 +35,8 @@ namespace otb { -const char * GlVersionChecker::REQUIRED_GL_VERSION = "2.0.0"; -const char * GlVersionChecker::REQUIRED_GLSL_VERSION = "1.20"; +const char * GlVersionChecker::REQUIRED_GL_VERSION = "3.0.0"; +const char * GlVersionChecker::REQUIRED_GLSL_VERSION = "1.30"; const char * GlVersionChecker @@ -231,4 +231,3 @@ GlVersionChecker } // End namespace otb - diff --git a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx index 9e4a088988..0072fecbfc 100644 --- a/Modules/Visualization/Ice/src/otbShaderRegistry.cxx +++ b/Modules/Visualization/Ice/src/otbShaderRegistry.cxx @@ -180,7 +180,12 @@ unsigned int ShaderRegistry::CompileShader(int stype, const std::string& name, c glDeleteShader( shader ); shader = 0; - itkExceptionMacro(<<"Shader "< // // System includes (sorted by alphabetic order) @@ -998,6 +999,25 @@ ImageViewWidget .toLatin1() .constData(); + switch( format().profile() ) + { + case QGLFormat::NoProfile: + qWarning() << "QGLFormat::NoProfile"; + break; + + case QGLFormat::CoreProfile: + qWarning() << "QGLFormat::CoreProfile"; + break; + + case QGLFormat::CompatibilityProfile: + qWarning() << "QGLFormat::CompatibilityProfile"; + break; + + default: + assert( false && "Unexpected QGLFormat::profile()." ); + break; + } + QGLFormat::OpenGLVersionFlags glVersionFlags( QGLFormat::openGLVersionFlags() ); @@ -1010,7 +1030,7 @@ ImageViewWidget if( glVersionFlags & QGLFormat::OpenGL_Version_4_0 ) qWarning() << "QGLFormat::OpenGL_Version_4_0"; - + // if( glVersionFlags & QGLFormat::OpenGL_Version_3_3 ) qWarning() << "- QGLFormat::OpenGL_Version_3_3"; if( glVersionFlags & QGLFormat::OpenGL_Version_3_2 ) @@ -1019,12 +1039,12 @@ ImageViewWidget qWarning() << "- QGLFormat::OpenGL_Version_3_1"; if( glVersionFlags & QGLFormat::OpenGL_Version_3_0 ) qWarning() << "- QGLFormat::OpenGL_Version_3_0"; - + // if( glVersionFlags & QGLFormat::OpenGL_Version_2_1 ) qWarning() << "- QGLFormat::OpenGL_Version_2_1"; if( glVersionFlags & QGLFormat::OpenGL_Version_2_0 ) qWarning() << "- QGLFormat::OpenGL_Version_2_0"; - + // if( glVersionFlags & QGLFormat::OpenGL_Version_1_5 ) qWarning() << "- QGLFormat::OpenGL_Version_1_5"; if( glVersionFlags & QGLFormat::OpenGL_Version_1_4 ) @@ -1407,7 +1427,7 @@ ImageViewWidget // qDebug() << this << "::OnClearProjectionRequested()"; assert( m_Manipulator!=NULL ); - + m_Manipulator->SetWkt( std::string() ); m_Manipulator->SetKeywordList( otb::ViewSettings::KeywordListType() ); @@ -1753,7 +1773,7 @@ ImageViewWidget double sy = ( spacing[ 1 ]>0.0 ? 1.0 : -1.0 ) / spacing[ 1 ]; #endif - + // qDebug() << "sx:" << sx << "; sy:" << sy; // qDebug() << "rsx:" << rsx << "; rsy:" << rsy; @@ -2152,7 +2172,7 @@ ImageViewWidget } // RGB else - { + { // Get color-setup. VectorImageSettings::ChannelVector channels( settings.GetRgbChannels() ); @@ -2228,8 +2248,8 @@ ImageViewWidget filename+=".tif"; } } - - + + assert( m_Renderer!=NULL ); try @@ -2287,7 +2307,7 @@ ImageViewWidget assert( m_Renderer!=NULL ); - + StackedLayerModel * stackedLayerModel = m_Renderer->GetLayerStack(); assert( stackedLayerModel!=NULL ); -- GitLab From 2d86e713bc8935df56528b57d487d62e513aa08b Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 11:53:47 +0200 Subject: [PATCH 36/73] Removed otb::GlActor constructor and assignment operator. --- Modules/Visualization/Ice/include/otbGlActor.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlActor.h b/Modules/Visualization/Ice/include/otbGlActor.h index b1f8f000b5..55aa76084f 100644 --- a/Modules/Visualization/Ice/include/otbGlActor.h +++ b/Modules/Visualization/Ice/include/otbGlActor.h @@ -31,7 +31,7 @@ namespace otb { -class OTBIce_EXPORT GlActor +class OTBIce_EXPORT GlActor : public itk::Object { public: @@ -43,7 +43,7 @@ public: itkSetObjectMacro(Settings,ViewSettings); itkGetObjectMacro(Settings,ViewSettings); itkGetConstObjectMacro(Settings,ViewSettings); - + itkSetMacro(Visible,bool); itkGetMacro(Visible,bool); itkBooleanMacro(Visible); @@ -59,8 +59,8 @@ public: itkGetMacro( Overlay, bool ); itkBooleanMacro( Overlay ); - itkGetObjectMacro(Shader,Shader); - itkSetObjectMacro(Shader,Shader); + itkGetObjectMacro( Shader, Shader ); + itkSetObjectMacro( Shader, Shader ); // Retrieve the full extent of the actor virtual void GetExtent(double & ulx, double & uly, double & lrx, double & lry) const = 0; @@ -86,8 +86,8 @@ protected: private: // prevent implementation - GlActor(const Self&); - void operator=(const Self&); + GlActor( const Self & ) = delete; + void operator=( const Self & ) = delete; ViewSettings::Pointer m_Settings; -- GitLab From c5914080d2b418ecde769144533fbef560f5a07b Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 11:54:33 +0200 Subject: [PATCH 37/73] Added cast operator & debug traces to otb::GlBufferObject. --- .../Ice/include/otbGlBufferObject.h | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Modules/Visualization/Ice/include/otbGlBufferObject.h b/Modules/Visualization/Ice/include/otbGlBufferObject.h index 73dc4472b4..3dc3e44417 100644 --- a/Modules/Visualization/Ice/include/otbGlBufferObject.h +++ b/Modules/Visualization/Ice/include/otbGlBufferObject.h @@ -49,13 +49,25 @@ struct BufferObjectPolicy void Generate( Id_t & id ) { +#if OTB_DEBUG + std::cout << "glGenBuffers()" << std::endl; +#endif + glGenBuffers( 1, &id ); + +#if OTB_DEBUG + std::cout << "-> " << id << std::endl; +#endif } static void Bind( Id_t id ) { +#if OTB_DEBUG + std::cout << "glBindBuffer( " << id << " )" << std::endl; +#endif + glBindBuffer( static_cast< GLenum >( E ), id ); } @@ -63,6 +75,10 @@ struct BufferObjectPolicy void Release( Id_t & id ) { +#if OTB_DEBUG + std::cout << "glDeleteBuffers( " << id << " )" << std::endl; +#endif + glDeleteBuffers( 1, &id ); } }; @@ -117,6 +133,12 @@ struct BufferObject BufferObject & operator = ( BufferObject && ) = default; + /** Cast operator. */ + operator Id_t() const noexcept + { + return m_Id; + } + void Bind( bool isEnabled = true ) const { -- GitLab From acd6d0d5c118b2057ff8c25429fe50301e94dc52 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 11:58:15 +0200 Subject: [PATCH 38/73] Added assertions. --- Modules/Visualization/Ice/include/otbGlMesh.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Modules/Visualization/Ice/include/otbGlMesh.h b/Modules/Visualization/Ice/include/otbGlMesh.h index c4c2f829b2..21f6f2e007 100644 --- a/Modules/Visualization/Ice/include/otbGlMesh.h +++ b/Modules/Visualization/Ice/include/otbGlMesh.h @@ -60,6 +60,11 @@ struct Mesh void Bind( bool isEnabled = true ) { + assert( glIsBuffer( m_VBO ) ); + assert( glIsBuffer( m_IBO ) ); + + assert( glIsVertexArray( m_VAO ) ); + m_VAO.Bind( isEnabled ); m_VBO.Bind( isEnabled ); m_IBO.Bind( isEnabled ); -- GitLab From 01a07895e5ddf8de47f7d9487491b77d6ff9c7e9 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 11:59:57 +0200 Subject: [PATCH 39/73] Improved otb::GlVersionChecker. --- .../Ice/include/otbGlVersionChecker.h | 32 ++++++++++++------- Modules/Visualization/Ice/src/CMakeLists.txt | 1 + .../Ice/src/otbGlVersionChecker.cxx | 21 +++++++++--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlVersionChecker.h b/Modules/Visualization/Ice/include/otbGlVersionChecker.h index 75f15bf85e..56345e4204 100644 --- a/Modules/Visualization/Ice/include/otbGlVersionChecker.h +++ b/Modules/Visualization/Ice/include/otbGlVersionChecker.h @@ -48,7 +48,7 @@ public: * std::runtime_error() is thrown when glGetError() is different * than GL_NO_ERROR. */ - static const char * GLVersion(); + static const char * GLVersion() noexcept; /** * \return The OpenGL Shading-Language version used at runtime. The @@ -59,7 +59,15 @@ public: * 2.0. (@see * http://www.opengl.org/sdk/docs/man2/xhtml/glGetString.xml). */ - static const char * GLSLVersion(); + static const char * GLSLVersion() noexcept; + + /** + * \brief Check that OpenGL required capabilities have been reached. + * + * \return true if OpengGL capabilities of running platform meets + * the needs of the library. + */ + static bool CheckGLCapabilities() noexcept; /** * \brief Check that OpenGL required capabilities have been reached. @@ -74,7 +82,7 @@ public: * the needs of the library. */ static bool CheckGLCapabilities( const char * & glVersion, - const char * & glslVersion ); + const char * & glslVersion ) noexcept; /** * \brief Compares to version-strings on the model of strcmp(). @@ -90,14 +98,7 @@ public: * \return -1 if version0 if * version==required; +1 if version>=required. */ - static int VerCmp( const char * version, const char * required ); - -private: - // Prevent instantiation - GlVersionChecker(); - ~GlVersionChecker(); - GlVersionChecker(const GlVersionChecker&); - void operator=(const GlVersionChecker&); + static int VerCmp( const char * version, const char * required ) noexcept; /** * \brief Split version string into Major.minor.release triplet. @@ -114,7 +115,14 @@ private: static bool SplitVersion( const char * version, int& major, int& minor, - int& release ); + int& release ) noexcept; + +private: + // Prevent instantiation + GlVersionChecker() = delete; + ~GlVersionChecker() = delete; + GlVersionChecker( const GlVersionChecker & ) = delete; + void operator = ( const GlVersionChecker & ) = delete; }; } // End namespace otb diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index 8d7419bcb0..86f4fbcb79 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(OTBICE_SRCS otbGlVectorActor.cxx otbGlVersionChecker.cxx otbGlTypeTraits.cxx + otbGlVersionChecker.cxx otbGlVertexArrayObject.cxx otbImageSettings.cxx otbMinimalShader.cxx diff --git a/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx b/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx index e6e430c056..6387d9fbad 100644 --- a/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx +++ b/Modules/Visualization/Ice/src/otbGlVersionChecker.cxx @@ -40,7 +40,7 @@ const char * GlVersionChecker::REQUIRED_GLSL_VERSION = "1.30"; const char * GlVersionChecker -::GLVersion() +::GLVersion() noexcept { const GLubyte * glVersionStr = glGetString( GL_VERSION ); @@ -61,7 +61,7 @@ GlVersionChecker const char * GlVersionChecker -::GLSLVersion() +::GLSLVersion() noexcept { const GLubyte * slVersionStr = glGetString( GL_SHADING_LANGUAGE_VERSION ); @@ -82,7 +82,18 @@ GlVersionChecker bool GlVersionChecker -::CheckGLCapabilities( const char * & glVersion, const char * & glslVersion ) +::CheckGLCapabilities() noexcept +{ + char const * glVersion = nullptr; + char const * glslVersion = nullptr; + + return GlVersionChecker::CheckGLCapabilities( glVersion, glslVersion ); +} + + +bool +GlVersionChecker +::CheckGLCapabilities( const char * & glVersion, const char * & glslVersion ) noexcept { // Get OpenGL version. glVersion = GlVersionChecker::GLVersion(); @@ -114,7 +125,7 @@ GlVersionChecker ::SplitVersion( const char * version, int& major, int& minor, - int& release ) + int& release ) noexcept { // // Special case: empty strings returns 0.0.0 and true. @@ -174,7 +185,7 @@ GlVersionChecker int GlVersionChecker -::VerCmp( const char * version, const char * required ) +::VerCmp( const char * version, const char * required ) noexcept { // // Split version. -- GitLab From 8a0d0105fec4e70fefe1a23df53adf0d61c34141 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 12:01:02 +0200 Subject: [PATCH 40/73] Added debug traces to otb::GlVertexArrayObject. --- .../Ice/src/otbGlVertexArrayObject.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx index 230dad2eab..a78a85d8ad 100644 --- a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx +++ b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx @@ -27,7 +27,15 @@ void VertexArrayObjectPolicy ::Generate( Id_t & id ) { +#if OTB_DEBUG + std::cout << "glGenVertexArrays()" << std::endl; +#endif + glGenVertexArrays( 1, &id ); + +#if OTB_DEBUG + std::cout << "-> " << id << std::endl; +#endif } @@ -35,6 +43,11 @@ void VertexArrayObjectPolicy ::Bind( Id_t id ) { + +#if OTB_DEBUG + std::cout << "glBindVertexArray( " << id << " )" << std::endl; +#endif + glBindVertexArray( id ); } @@ -43,6 +56,10 @@ void VertexArrayObjectPolicy ::Release( Id_t & id ) { +#if OTB_DEBUG + std::cout << "glDeleteArrays( " << id << " )" << std::endl; +#endif + glDeleteVertexArrays( 1, &id ); } -- GitLab From f4a5ecbe9d2a5cf92983c2a26ecfc9ae0065cc65 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 12:04:42 +0200 Subject: [PATCH 41/73] Restored Ice textured renderingg (no GLSL mode) and added per otb::GlView GL capabilities checking. --- .../Ice/include/otbGlImageActor.h | 6 + Modules/Visualization/Ice/include/otbGlView.h | 55 +++- .../Visualization/Ice/src/otbGlImageActor.cxx | 286 +++++++++++++----- Modules/Visualization/Ice/src/otbGlView.cxx | 251 ++++++++++----- 4 files changed, 425 insertions(+), 173 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index d8f15976c1..77215f6034 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -130,6 +130,10 @@ public: itkSetMacro(TileSize,unsigned int); itkGetMacro(TileSize,unsigned int); + itkBooleanMacro(SoftwareRendering ); + itkSetMacro(SoftwareRendering, bool ); + itkGetMacro(SoftwareRendering, bool ); + void CreateShader() override; void SetResolutionAlgorithm(ResolutionAlgorithm::type alg) @@ -318,6 +322,8 @@ private: /** OpenGL quad. */ std::unique_ptr< gl::Mesh > m_Mesh; + bool m_SoftwareRendering = false; + }; // End class GlImageActor } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbGlView.h b/Modules/Visualization/Ice/include/otbGlView.h index d40905245e..15a85e31dd 100644 --- a/Modules/Visualization/Ice/include/otbGlView.h +++ b/Modules/Visualization/Ice/include/otbGlView.h @@ -66,7 +66,7 @@ assert_NaN( T val ) ((void)val); } -/** +/** * The GlView class acts like an OpenGl scene where actors deriving * from the GlActor class can be rendered. The GlView class contains the * OpenGl viewport and manages: @@ -75,11 +75,11 @@ assert_NaN( T val ) * all actors and all OpenGl specific stuff needed before and after * the actors update, * - The actors stack (order in which actors are rendered). - * + * * All parameters related to scene description (origin, spacing, angle * ...) are stored and managed by the ViewSettings class. */ -class OTBIce_EXPORT GlView +class OTBIce_EXPORT GlView : public itk::Object { public: @@ -99,20 +99,32 @@ public: itkNewMacro(Self); + /** + * @return Same value as GLSL #version, or 0 if minimum + * requirements are not met. + */ + std::size_t CheckGLCapabilities( char const * & glVersion, + char const * & glslVersion ); + /** * The Initialize method will reset the OpenGl viewport to the given * size, clear view settings and remove any existing actor. * \param sx Width of the viewport * \param sy Height of the viewport - */ - void Initialize(unsigned int sx, unsigned int sy); + */ + void Initialize( unsigned int sx, unsigned int sy ) noexcept; + + /** + * @return true there is no actor in view. + */ + bool IsEmpty() const noexcept { return m_Actors.empty(); } /** * This method allows adding a new actor (deriving from GlActor) to * the GlView. The actor can be identified by an optional key. If * not provided, and the default value is used, the method will * generate a key to identify the actor. In both case, the key is - * returned by the method. + * returned by the method. * \param actor The actor to be added * \param key The key to be used to identify the actor (default to * empty string) @@ -121,7 +133,7 @@ public: */ std::string AddActor(ActorType * actor, const std::string & key = ""); - /** + /** * This method will try to remove the actor identified by the given * key. * \param key The key identifying the actor to remove @@ -133,7 +145,7 @@ public: /** * This method will remove all existing actors at once. */ - void ClearActors(); + void ClearActors() noexcept; /** * This method allows retrieving a pointer to the actor identified @@ -141,7 +153,7 @@ public: * \param key The key identifying the actor to retrieve * \return A pointer to the retrieved actor. This pointer will be * null if no actor could be found with this key. - */ + */ ActorType::Pointer GetActor(const std::string & key) const; /** @@ -157,7 +169,7 @@ public: * This method will return a vector containing the keys of all * actors. * \return A vector of string containing the keys of all actors. - */ + */ std::vector GetActorsKeys() const; /** @@ -189,12 +201,23 @@ public: void HeavyRender(); // Resize viewport - void Resize(unsigned int sx, unsigned int sy); + void Resize( unsigned int sx, unsigned int sy ) noexcept; itkSetObjectMacro(Settings,ViewSettings); itkGetObjectMacro(Settings,ViewSettings); itkGetConstObjectMacro(Settings,ViewSettings); + /** @return true OpenGL driver has required GLSL capability. */ + bool IsGLSLAvailable() const noexcept { return m_IsGLSLAvailable; } + + /** + * Enable/Disable GLSL-mode. + */ + void SetGLSLEnabled( bool ); + + /** @return true if GLSL-mode is enabled. */ + bool IsGLSLEnabled() const noexcept { return m_IsGLSLEnabled; } + //comment this macro (not compiling with OTB 3.X) // Get Rendering order const StringVectorType & GetRenderingOrder() const @@ -298,6 +321,8 @@ private: float m_ModelViewMatrix[16]; + bool m_IsGLSLAvailable : 1; + bool m_IsGLSLEnabled : 1; }; // End class GlView @@ -336,7 +361,7 @@ GlView return false; const otb::GeoInterface::Spacing2 nativeReferenceSpacing = geo->GetSpacing(); - + // // Compute transform origin. if( !geo->TransformFromViewport( center, vcenter, true ) ) @@ -346,7 +371,7 @@ GlView // Compute transformed X-axis extremity. GeoInterface::Point2d x( vcenter ); - x[ 0 ] += norm * vspacing[ 0 ]; + x[ 0 ] += norm * vspacing[ 0 ]; // std::cout << "X {" << std::endl; @@ -369,7 +394,7 @@ GlView // std::cout << "Y {" << std::endl; if( !geo->TransformFromViewport( y, y, true ) ) - return false; + return false; // std::cout << "y: " << y[ 0 ] << ", " << y[ 1 ] << std::endl; @@ -399,7 +424,7 @@ GlView spacing[ 1 ] = std::sqrt( y[ 0 ] * y[ 0 ] + y[ 1 ] * y[ 1 ] ) / norm; // New spacing signs should match signs of the reference image spacing - + if( nativeReferenceSpacing[0]<0.0 ) spacing[ 0 ] = -spacing[ 0 ]; diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 2cf0e70276..448e04ff7b 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -101,6 +101,7 @@ GlImageActor m_LoadedTiles.clear(); } + void GlImageActor ::CreateShader() @@ -373,61 +374,195 @@ void GlImageActor::Render() // << "\tresolution: " << m_ResolutionAlgorithm << std::endl // << "\ttile: " << m_TileSize << std::endl; - m_Shader->LoadShader(); - m_Shader->SetupShader(); - - GLfloat vertexPosition[8] = { - -1.0f, -1.0f, - 1.0f, -1.0f, - 1.0f, 1.0f, - -1.0f, 1.0f - }; + bool isShaderMode = !m_SoftwareRendering && !m_Shader.IsNull(); - // Check OpenGL error and clear error flag. - gl::CheckError< gl::error::clear >(); + if( isShaderMode ) + { + m_Shader->LoadShader(); + m_Shader->SetupShader(); - assert( m_Mesh ); - m_Mesh->Bind(); + // Check OpenGL error and clear error flag. + gl::CheckError< gl::error::clear >(); - for(TileVectorType::iterator it = m_LoadedTiles.begin(); - it != m_LoadedTiles.end(); ++it) + assert( m_Mesh ); + m_Mesh->Bind(); + } + else + { + for(TileVectorType::iterator it = m_LoadedTiles.begin(); + it != m_LoadedTiles.end(); ++it) { + if(!it->m_RescaleFilter) + { + it->m_RescaleFilter = RescaleFilterType::New(); + it->m_RescaleFilter->AutomaticInputMinMaxComputationOff(); + it->m_RescaleFilter->SetInput(it->m_Image); + } - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + VectorImageType::PixelType mins(3),maxs(3),omins(3),omaxs(3); + mins.Fill(0); + maxs.Fill(255); - glBindTexture(GL_TEXTURE_2D,it->m_TextureId); + double noData(0.); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if(m_CurrentResolution == 0) + assert( !m_ImageSettings.IsNull() ); + + mins[ 0 ] = m_ImageSettings->GetMinRed(); + mins[ 1 ] = m_ImageSettings->GetMinGreen(); + mins[ 2 ] = m_ImageSettings->GetMinBlue(); + + maxs[ 0 ] = m_ImageSettings->GetMaxRed(); + maxs[ 1 ] = m_ImageSettings->GetMaxGreen(); + maxs[ 2 ] = m_ImageSettings->GetMaxBlue(); + + // MANTIS-1204 + // { + double gamma = m_ImageSettings->GetGamma(); + + gamma = + gamma == 0.0 + ? std::numeric_limits< double >::max() + : 1.0 / gamma; + // } + + + if( m_ImageSettings->GetUseNoData() ) + noData = m_ImageSettings->GetNoData(); + + + omins.Fill( 0 ); + omaxs.Fill( 255 ); + + it->m_RescaleFilter->SetInputMinimum(mins); + it->m_RescaleFilter->SetInputMaximum(maxs); + it->m_RescaleFilter->SetOutputMinimum(omins); + it->m_RescaleFilter->SetOutputMaximum(omaxs); + it->m_RescaleFilter->SetGamma(gamma); + + it->m_RescaleFilter->Update(); + + + itk::ImageRegionConstIterator imIt(it->m_RescaleFilter->GetOutput(),it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator inIt(it->m_Image,it->m_Image->GetLargestPossibleRegion()); + + auto buffer = + std::make_unique< GLubyte[] >( + 4 * it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels() + ); + + unsigned int idx = 0; + + for(imIt.GoToBegin(),inIt.GoToBegin();!imIt.IsAtEnd()&&!inIt.IsAtEnd();++imIt,++inIt) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + buffer[idx] = static_cast(imIt.Get()[2]); + ++idx; + buffer[idx] = static_cast(imIt.Get()[1]); + ++idx; + buffer[idx] = static_cast(imIt.Get()[0]); + ++idx; + buffer[idx] = 255; + + if(m_ImageSettings->GetUseNoData() && (inIt.Get()[0] == noData ||inIt.Get()[1] == noData ||inIt.Get()[2] == noData)) + { + buffer[idx] = 0; + } + + ++idx; } - else + + if(!it->m_TextureId) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glGenTextures(1, &(it->m_TextureId)); } + glBindTexture(GL_TEXTURE_2D, it->m_TextureId); +#if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); +#endif + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); +// #if defined(GL_CLAMP_TO_BORDER) +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); +// #elif defined (GL_CLAMP_TO_BORDER_EXT) +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); +// #elif defined (GL_MIRRORED_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); +// #endif + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA8, + it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0], + it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[1], + 0, GL_BGRA, GL_UNSIGNED_BYTE, + buffer.get() + ); + + it->m_Loaded = true; + } + } - // Reset color before rendering - //glColor4d(1.0f,1.0f,1.0f, m_ImageSettings->GetAlpha()); + for(TileVectorType::iterator it = m_LoadedTiles.begin(); + it != m_LoadedTiles.end(); ++it) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - vertexPosition[0] = it->m_LL[0]; - vertexPosition[1] = it->m_LL[1]; - vertexPosition[2] = it->m_LR[0]; - vertexPosition[3] = it->m_LR[1]; - vertexPosition[4] = it->m_UR[0]; - vertexPosition[5] = it->m_UR[1]; - vertexPosition[6] = it->m_UL[0]; - vertexPosition[7] = it->m_UL[1]; + glBindTexture(GL_TEXTURE_2D,it->m_TextureId); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + glTexParameteri( + GL_TEXTURE_2D, + GL_TEXTURE_MAG_FILTER, + m_CurrentResolution ? GL_LINEAR : GL_NEAREST + ); - glDisable(GL_BLEND); + if( isShaderMode ) + { + GLfloat vertexPosition[ 8 ] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, 1.0f + }; + + vertexPosition[0] = it->m_LL[0]; + vertexPosition[1] = it->m_LL[1]; + vertexPosition[2] = it->m_LR[0]; + vertexPosition[3] = it->m_LR[1]; + vertexPosition[4] = it->m_UR[0]; + vertexPosition[5] = it->m_UR[1]; + vertexPosition[6] = it->m_UL[0]; + vertexPosition[7] = it->m_UL[1]; + + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + + glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); } + else + { + // Reset color before rendering + glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); + + glBegin( GL_QUADS ); + { + glTexCoord2f( 0.0, 1.0 ); glVertex2f( it->m_LL[ 0 ], it->m_LL[ 1 ] ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( it->m_LR[ 0 ], it->m_LR[ 1 ] ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( it->m_UR[ 0 ], it->m_UR[ 1 ] ); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( it->m_UL[ 0 ], it->m_UL[ 1 ] ); + } + glEnd (); + } + + glDisable( GL_TEXTURE_2D ); + glDisable( GL_BLEND ); + } - m_Shader->UnloadShader(); + if( isShaderMode ) + m_Shader->UnloadShader(); } void GlImageActor::LoadTile(Tile& tile) @@ -459,44 +594,46 @@ void GlImageActor::LoadTile(Tile& tile) tile.m_Image = extract->GetOutput(); - itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); + if( !m_SoftwareRendering ) + { + itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); - float * buffer = new float[4*extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; + float * buffer = new float[4*extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; - unsigned int idx = 0; + unsigned int idx = 0; - for(it.GoToBegin();!it.IsAtEnd();++it) - { - buffer[idx] = static_cast(it.Get()[2]); - ++idx; - buffer[idx] = static_cast(it.Get()[1]); - ++idx; - buffer[idx] = static_cast(it.Get()[0]); - ++idx; - buffer[idx] = 255.; - ++idx; - } + for(it.GoToBegin();!it.IsAtEnd();++it) + { + buffer[idx] = static_cast(it.Get()[2]); + ++idx; + buffer[idx] = static_cast(it.Get()[1]); + ++idx; + buffer[idx] = static_cast(it.Get()[0]); + ++idx; + buffer[idx] = 255.; + ++idx; + } - // Now load the texture - assert( tile.m_TextureId==0 ); + // Now load the texture + assert( tile.m_TextureId==0 ); - glGenTextures( 1, &tile.m_TextureId ); + glGenTextures( 1, &tile.m_TextureId ); - // Following assert is sometimes false on some OpenGL systems for - // some unknown reason even though the glGenTexture() call has - // succeeded. - // assert( glGetError()==GL_NO_ERROR ); + // Following assert is sometimes false on some OpenGL systems for + // some unknown reason even though the glGenTexture() call has + // succeeded. + // assert( glGetError()==GL_NO_ERROR ); - assert( tile.m_TextureId!=0 ); + assert( tile.m_TextureId!=0 ); - // std::cout << "Generated texture #" << tile.m_TextureId << std::endl; + // std::cout << "Generated texture #" << tile.m_TextureId << std::endl; - glBindTexture(GL_TEXTURE_2D, tile.m_TextureId); + glBindTexture(GL_TEXTURE_2D, tile.m_TextureId); #if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); #endif - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); // #if defined(GL_CLAMP_TO_BORDER) // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); @@ -504,19 +641,20 @@ void GlImageActor::LoadTile(Tile& tile) // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); // #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); // #endif - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGB32F, - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], - 0, GL_BGRA, GL_FLOAT, - buffer); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGB32F, + extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], + extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], + 0, GL_BGRA, GL_FLOAT, + buffer); - tile.m_Loaded = true; + tile.m_Loaded = true; - delete [] buffer; + delete [] buffer; + } // And push to loaded texture m_LoadedTiles.push_back(tile); diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index ad94cacc71..8486a0d341 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -34,6 +34,7 @@ #include "itkRGBAPixel.h" #include "otbGeoInterface.h" +#include "otbGlVersionChecker.h" #include "otbImage.h" #include "otbImageFileWriter.h" #include "otbImportImageFilter.h" @@ -42,59 +43,118 @@ namespace otb { -GlView::GlView() - : m_Settings(ViewSettings::New()) - , m_Actors() - , m_RenderingOrder() - , m_ProjMatrix{ +GlView::GlView() : + m_Settings( ViewSettings::New() ), + m_Actors(), + m_RenderingOrder(), + m_ProjMatrix{ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0} - , m_ModelViewMatrix{ + 0.0, 0.0, 0.0, 1.0 }, + m_ModelViewMatrix{ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0} + 0.0, 0.0, 0.0, 1.0 }, + m_IsGLSLAvailable( false ), + m_IsGLSLEnabled( false ) {} + GlView::~GlView() {} -void GlView::Initialize(unsigned int sx, unsigned int sy) + +std::size_t +GlView +::CheckGLCapabilities( char const * & glVersion, + char const * & glslVersion ) +{ + m_IsGLSLEnabled = m_IsGLSLAvailable = + GlVersionChecker::CheckGLCapabilities( glVersion, glslVersion ); + + if( !m_IsGLSLAvailable ) + return 0; + + assert( glVersion ); + assert( glslVersion ); + + int major = 0; + int minor = 0; + int release = 0; + + GlVersionChecker::SplitVersion( glslVersion, major, minor, release ); + + assert( major>0 ); + assert( minor>0 ); + assert( release>=0 ); + + return 100 * major + minor; +} + + +void +GlView +::Initialize( unsigned int sx, unsigned int sy ) noexcept { m_Settings = ViewSettings::New(); - - this->ClearActors(); - this->Resize(sx,sy); + ClearActors(); + + Resize( sx,sy ); +} + + +void +GlView +::SetGLSLEnabled( bool isEnabled ) +{ + assert( m_Actors.empty() ); + + if( !m_Actors.empty() ) + throw std::runtime_error( + "Failed to change GLSL activation state (view must be cleared before)." + ); + + m_IsGLSLEnabled = isEnabled; } -void GlView::Resize(unsigned int sx, unsigned int sy) + +void +GlView +::Resize( unsigned int sx, unsigned int sy ) noexcept { - ViewSettings::SizeType size; - size[0] = sx; - size[1] = sy; - m_Settings->SetViewportSize(size); + ViewSettings::SizeType size; + + size[ 0 ] = sx; + size[ 1 ] = sy; + + m_Settings->SetViewportSize( size ); } -void GlView::BeforeRendering() + +void +GlView +::BeforeRendering() { // First, get all actors informed of new settings for(ActorMapType::iterator it = m_Actors.begin(); it!=m_Actors.end();++it) - { + { if(it->second->GetVisible()) - { + { it->second->ProcessViewSettings(); + Shader* shader = it->second->GetShader(); - if (shader) - { + + if( shader ) + { shader->m_ProjMatrix = m_ProjMatrix; shader->m_ModelViewMatrix = m_ModelViewMatrix; - } } } + } // Second, get opengl ready @@ -109,71 +169,92 @@ void GlView::BeforeRendering() double uly = -1.0; double lrx = 1.0; double lry = 1.0; - + m_Settings->GetViewportExtent(ulx,uly,lrx,lry); - m_ProjMatrix[0] = 2.0/(lrx-ulx); - m_ProjMatrix[1] = 0.0; - m_ProjMatrix[2] = 0.0; - m_ProjMatrix[3] = 0.0; - m_ProjMatrix[4] = 0.0; - m_ProjMatrix[5] = 2.0/(uly-lry); - m_ProjMatrix[6] = 0.0; - m_ProjMatrix[7] = 0.0; - m_ProjMatrix[8] = 0.0; - m_ProjMatrix[9] = 0.0; - m_ProjMatrix[10] = -1.0; - m_ProjMatrix[11] = 0.0; - m_ProjMatrix[12] = -(lrx+ulx)/(lrx-ulx); - m_ProjMatrix[13] = -(uly+lry)/(uly-lry); - m_ProjMatrix[14] = 0.0; - m_ProjMatrix[15] = 1.0; - - double ra = -m_Settings->GetRotationAngle(); - if(ra == 0.0) + if( m_IsGLSLAvailable && m_IsGLSLEnabled ) + { + m_ProjMatrix[0] = 2.0/(lrx-ulx); + m_ProjMatrix[1] = 0.0; + m_ProjMatrix[2] = 0.0; + m_ProjMatrix[3] = 0.0; + m_ProjMatrix[4] = 0.0; + m_ProjMatrix[5] = 2.0/(uly-lry); + m_ProjMatrix[6] = 0.0; + m_ProjMatrix[7] = 0.0; + m_ProjMatrix[8] = 0.0; + m_ProjMatrix[9] = 0.0; + m_ProjMatrix[10] = -1.0; + m_ProjMatrix[11] = 0.0; + m_ProjMatrix[12] = -(lrx+ulx)/(lrx-ulx); + m_ProjMatrix[13] = -(uly+lry)/(uly-lry); + m_ProjMatrix[14] = 0.0; + m_ProjMatrix[15] = 1.0; + + double ra = -m_Settings->GetRotationAngle(); + if(ra == 0.0) { - m_ModelViewMatrix[0] = 1.0; - m_ModelViewMatrix[1] = 0.0; - m_ModelViewMatrix[2] = 0.0; - m_ModelViewMatrix[3] = 0.0; - m_ModelViewMatrix[4] = 0.0; - m_ModelViewMatrix[5] = 1.0; - m_ModelViewMatrix[6] = 0.0; - m_ModelViewMatrix[7] = 0.0; - m_ModelViewMatrix[8] = 0.0; - m_ModelViewMatrix[9] = 0.0; - m_ModelViewMatrix[10] = 1.0; - m_ModelViewMatrix[11] = 0.0; - m_ModelViewMatrix[12] = 0.0; - m_ModelViewMatrix[13] = 0.0; - m_ModelViewMatrix[14] = 0.0; - m_ModelViewMatrix[15] = 1.0; + m_ModelViewMatrix[0] = 1.0; + m_ModelViewMatrix[1] = 0.0; + m_ModelViewMatrix[2] = 0.0; + m_ModelViewMatrix[3] = 0.0; + m_ModelViewMatrix[4] = 0.0; + m_ModelViewMatrix[5] = 1.0; + m_ModelViewMatrix[6] = 0.0; + m_ModelViewMatrix[7] = 0.0; + m_ModelViewMatrix[8] = 0.0; + m_ModelViewMatrix[9] = 0.0; + m_ModelViewMatrix[10] = 1.0; + m_ModelViewMatrix[11] = 0.0; + m_ModelViewMatrix[12] = 0.0; + m_ModelViewMatrix[13] = 0.0; + m_ModelViewMatrix[14] = 0.0; + m_ModelViewMatrix[15] = 1.0; } - else + else { - double rcx = m_Settings->GetRotationCenter()[0]; - double rcy = m_Settings->GetRotationCenter()[1]; - double cos_a = cos(ra); - double sin_a = sin(ra); - m_ModelViewMatrix[0] = cos_a; - m_ModelViewMatrix[1] = sin_a; - m_ModelViewMatrix[2] = 0.0; - m_ModelViewMatrix[3] = 0.0; - m_ModelViewMatrix[4] = -sin_a; - m_ModelViewMatrix[5] = cos_a; - m_ModelViewMatrix[6] = 0.0; - m_ModelViewMatrix[7] = 0.0; - m_ModelViewMatrix[8] = 0.0; - m_ModelViewMatrix[9] = 0.0; - m_ModelViewMatrix[10] = 1.0; - m_ModelViewMatrix[11] = 0.0; - m_ModelViewMatrix[12] = rcx * (1.0 - cos_a) + rcy * sin_a; - m_ModelViewMatrix[13] = -rcx * sin_a + rcy * (1.0 - cos_a); - m_ModelViewMatrix[14] = 0.0; - m_ModelViewMatrix[15] = 1.0; + double rcx = m_Settings->GetRotationCenter()[0]; + double rcy = m_Settings->GetRotationCenter()[1]; + double cos_a = cos(ra); + double sin_a = sin(ra); + m_ModelViewMatrix[0] = cos_a; + m_ModelViewMatrix[1] = sin_a; + m_ModelViewMatrix[2] = 0.0; + m_ModelViewMatrix[3] = 0.0; + m_ModelViewMatrix[4] = -sin_a; + m_ModelViewMatrix[5] = cos_a; + m_ModelViewMatrix[6] = 0.0; + m_ModelViewMatrix[7] = 0.0; + m_ModelViewMatrix[8] = 0.0; + m_ModelViewMatrix[9] = 0.0; + m_ModelViewMatrix[10] = 1.0; + m_ModelViewMatrix[11] = 0.0; + m_ModelViewMatrix[12] = rcx * (1.0 - cos_a) + rcy * sin_a; + m_ModelViewMatrix[13] = -rcx * sin_a + rcy * (1.0 - cos_a); + m_ModelViewMatrix[14] = 0.0; + m_ModelViewMatrix[15] = 1.0; } + } + else + { + glOrtho(ulx, lrx, lry, uly, -1, 1); + + // std::cout + // << "glOrtho( " + // << ulx << ", " << lrx << ", " + // << lry << ", " << uly + // << ", -1, 1 )" + // << std::endl; + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); - // glScalef(m_Settings->GetSpacing()[0],m_Settings->GetSpacing()[1],1); + glPushMatrix(); + + glTranslatef(m_Settings->GetRotationCenter()[0],m_Settings->GetRotationCenter()[1],0); + glRotatef(-m_Settings->GetRotationAngle()*180/M_PI,0,0,1); + glTranslatef(-m_Settings->GetRotationCenter()[0],-m_Settings->GetRotationCenter()[1],0); + } } void GlView::AfterRendering() @@ -225,7 +306,9 @@ bool GlView::RemoveActor(const std::string & key) return true; } -void GlView::ClearActors() +void +GlView +::ClearActors() noexcept { m_Actors.clear(); m_RenderingOrder.clear(); @@ -419,7 +502,7 @@ GlView front ? m_RenderingOrder.end() : m_RenderingOrder.begin(), - thisKeys.begin(), + thisKeys.begin(), thisKeys.end() ); } @@ -477,7 +560,7 @@ GlView RgbPixel::ValueType * glBuffer = new RgbPixel::ValueType[ RgbPixel::Length * count ]; assert( glBuffer!=NULL ); - glReadPixels( + glReadPixels( 0, 0, size[ 0 ], size[ 1 ], GL_RGB, GL_UNSIGNED_BYTE, -- GitLab From 10e495697fa5a8139661d17f62dcc3f18d05c858 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 12:09:53 +0200 Subject: [PATCH 42/73] Added debug traces into Monteverdi main(). --- Modules/Visualization/Monteverdi/src/main.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/Visualization/Monteverdi/src/main.cxx b/Modules/Visualization/Monteverdi/src/main.cxx index db5e46ee0e..925043187f 100644 --- a/Modules/Visualization/Monteverdi/src/main.cxx +++ b/Modules/Visualization/Monteverdi/src/main.cxx @@ -229,6 +229,9 @@ main( int argc, char * argv[] ) // // 4. Check OpenGL capabilities +#if OTB_DEBUG + std::cout << "mainWindow.CheckGLCapabilities();" << std::endl; +#endif if( !mainWindow.CheckGLCapabilities( flags.forceNoGLSL ) ) return ERROR_CODE_GL_VERSION; @@ -245,10 +248,16 @@ main( int argc, char * argv[] ) // 6. Load command-line filenames. args.pop_front(); +#if OTB_DEBUG + std::cout << "mainWindow.ImportImages();" << std::endl; +#endif mainWindow.ImportImages( args, !flags.forceNoOverviews ); // // 6. Let's go: run the application and return exit code. +#if OTB_DEBUG + std::cout << "QCoreApplication::instance()->exec();" << std::endl; +#endif int result = QCoreApplication::instance()->exec(); // Coverity-14835 -- GitLab From 0adb8506f55a89e0fc34dd5c71b8008e92fe14ab Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 12:12:41 +0200 Subject: [PATCH 43/73] Upgraded to per otb::GlView GL-capabilities checking; Rationalized mvd::ImageViewWidget::makeCurrent() calls; Improved no GLSL ON/OFF switching. --- .../Monteverdi/include/mvdMainWindow.h | 2 +- .../Monteverdi/src/mvdMainWindow.cxx | 92 ++++++------- .../include/mvdAbstractImageViewRenderer.h | 51 ++++---- .../include/mvdImageViewRenderer.h | 12 +- .../include/mvdImageViewWidget.h | 10 ++ .../src/mvdImageViewRenderer.cxx | 121 ++++++++++++------ .../MonteverdiGui/src/mvdImageViewWidget.cxx | 87 +++++++++++-- 7 files changed, 243 insertions(+), 132 deletions(-) diff --git a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h index 87a8a5d7c7..4f3a5e6c77 100644 --- a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h +++ b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h @@ -426,7 +426,7 @@ private: /** */ - bool m_isGLSLAvailable : 1; + // bool m_isGLSLAvailable : 1; bool m_ForceNoGLSL : 1; /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ diff --git a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx index 9f0fe90836..d01de901dd 100644 --- a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx +++ b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx @@ -104,7 +104,6 @@ namespace mvd Context comment for translator. */ - /*****************************************************************************/ /* CONSTANTS */ @@ -144,7 +143,7 @@ MainWindow m_KeymapDialog( NULL ), m_ProjectionBarWidget( NULL ), m_GLSL140( -2 ), - m_isGLSLAvailable( false ), + // m_isGLSLAvailable( false ), m_ForceNoGLSL( false ) { m_UI->setupUi( this ); @@ -179,8 +178,8 @@ bool MainWindow ::CheckGLCapabilities( bool forceNoGLSL ) { - assert( m_ImageView!=NULL ); - assert( m_ImageView->GetRenderer()!=NULL ); + assert( m_ImageView ); + assert( m_ImageView->GetRenderer() ); // Coverity-19845 // @@ -188,8 +187,17 @@ MainWindow // m_ImageView->GetRenderer()==NULL ) // return false; - m_isGLSLAvailable = - m_ImageView->GetRenderer()->CheckGLCapabilities( &m_GLSL140 ); + int glsl140 = 0; + + bool isGLSLAvailable = + m_ImageView->CheckGLCapabilities( &glsl140 ); + + assert( GetQuicklookView() ); + + int glsl140QL = 0; + + bool isGLSLAvailableQL = + GetQuicklookView()->CheckGLCapabilities( &glsl140QL ); #if FORCE_NO_GLSL qWarning() << "No-GLSL is always forced in this build!"; @@ -201,7 +209,9 @@ MainWindow #endif // FORCE_NO_GLSL - bool isGLSL = m_isGLSLAvailable && !m_ForceNoGLSL; + bool isAvailable = isGLSLAvailable && isGLSLAvailableQL; + + bool isEnabled = isAvailable && !m_ForceNoGLSL; { assert( m_UI!=NULL ); @@ -209,15 +219,15 @@ MainWindow bool isBlocked = m_UI->action_GLSL->blockSignals( true ); - m_UI->action_GLSL->setEnabled( m_isGLSLAvailable ); - m_UI->action_GLSL->setChecked( isGLSL ); + m_UI->action_GLSL->setEnabled( isAvailable ); + m_UI->action_GLSL->setChecked( isEnabled ); m_UI->action_GLSL->blockSignals( isBlocked ); } - SetGLSLEnabled( isGLSL ); + SetGLSLEnabled( isEnabled ); - return ( !m_isGLSLAvailable || m_ForceNoGLSL ) || m_isGLSLAvailable; + return ( !isAvailable || m_ForceNoGLSL ) || isGLSLAvailable; } /*****************************************************************************/ @@ -225,60 +235,38 @@ void MainWindow ::SetGLSLEnabled( bool enabled ) { +#if OTB_DEBUG + std::cout << "MainWindow::SetGLSLEnabled( " << enabled << " )" << std::endl; +#endif + // // Image view - { - assert( m_ImageView!=NULL ); + assert( m_ImageView ); - AbstractImageViewRenderer * renderer = m_ImageView->GetRenderer(); + bool glslEnabled = + m_ImageView->SetGLSLEnabled( !m_ForceNoGLSL && enabled ); - assert( renderer!=NULL ); - - if( renderer->SetGLSLEnabled( enabled )!=enabled ) - { - renderer->ClearScene( true ); - renderer->UpdateScene(); - - m_ImageView->updateGL(); - } - } - - { - ImageViewWidget * quicklookView = GetQuicklookView(); - assert( quicklookView!=NULL ); - - // MANTIS-1204 - // { - // - // Forward GLSL state to quicklook view. - assert( GetQuicklookView()->GetRenderer()!=NULL ); - - AbstractImageViewRenderer * renderer = quicklookView->GetRenderer(); - - assert( renderer!=NULL ); - - if( renderer->SetGLSLEnabled( enabled )!=enabled ) - { - renderer->ClearScene( true ); - renderer->UpdateScene(); + // MANTIS-1204 + // { + // + // Forward GLSL state to quicklook view. + assert( GetQuicklookView() ); - quicklookView->updateGL(); - } - // } - } + glslEnabled = + GetQuicklookView()->SetGLSLEnabled( glslEnabled ); // // Shader widget - assert( m_ShaderWidget!=NULL ); + assert( m_ShaderWidget ); - m_ShaderWidget->SetGLSLEnabled( enabled ); + m_ShaderWidget->SetGLSLEnabled( glslEnabled ); m_ShaderWidget->SetGLSL140Enabled( m_GLSL140>=0 ); // // Status bar widget. - assert( m_StatusBarWidget!=NULL ); + assert( m_StatusBarWidget ); - m_StatusBarWidget->SetGLSLEnabled( enabled ); + m_StatusBarWidget->SetGLSLEnabled( glslEnabled ); // // Paint @@ -1684,7 +1672,7 @@ MainWindow { // qDebug() << this << "::on_action_GLSL_triggered(" << checked << ")"; - SetGLSLEnabled( m_isGLSLAvailable && !m_ForceNoGLSL && checked ); + SetGLSLEnabled( /* m_isGLSLAvailable && !m_ForceNoGLSL && */ checked ); } /*****************************************************************************/ diff --git a/Modules/Visualization/MonteverdiGui/include/mvdAbstractImageViewRenderer.h b/Modules/Visualization/MonteverdiGui/include/mvdAbstractImageViewRenderer.h index 717f37d8be..b74a743bd5 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdAbstractImageViewRenderer.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdAbstractImageViewRenderer.h @@ -138,7 +138,7 @@ public: /** */ - virtual bool CheckGLCapabilities( int * ) =0; + virtual bool CheckGLCapabilities( int * ) const =0; template< typename T > const T * GetReferenceModel() const; @@ -221,10 +221,13 @@ public: inline bool IsBypassRenderingEnabled() const; /** */ - inline bool SetGLSLEnabled( bool ); + virtual bool IsGLSLAvailable() const noexcept = 0; /** */ - inline bool IsGLSLEnabled() const; + virtual bool SetGLSLEnabled( bool ) = 0; + /** + */ + virtual bool IsGLSLEnabled() const noexcept = 0; /** */ virtual bool IsEffectsEnabled() const = 0; @@ -278,8 +281,7 @@ protected: AbstractImageViewRenderer( QObject* p = NULL ) : QObject( p ), m_StackedLayerModel( NULL ), - m_BypassRenderingEnabled( false ), - m_GLSLEnabled( true ) + m_BypassRenderingEnabled( false ) { } @@ -318,16 +320,19 @@ private: PointType &, SpacingType & ) const { return false; } + /** */ virtual bool virtual_ZoomToExtent( PointType &, SpacingType & ) const { return false; } + /** */ virtual bool virtual_ZoomToLayer( const StackedLayerModel::KeyType &, PointType &, SpacingType & ) const { return false; } + /** */ virtual bool virtual_ZoomToFull( const StackedLayerModel::KeyType &, @@ -346,7 +351,7 @@ private: bool m_BypassRenderingEnabled: 1; /** */ - bool m_GLSLEnabled: 1; + // bool m_GLSLEnabled: 1; /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ @@ -437,26 +442,28 @@ AbstractImageViewRenderer } /*****************************************************************************/ -inline -bool -AbstractImageViewRenderer -::IsGLSLEnabled() const -{ - return m_GLSLEnabled; -} +// inline +// bool +// AbstractImageViewRenderer +// ::IsGLSLEnabled() const +// { +// return m_GLSLEnabled; +// } /*****************************************************************************/ -inline -bool -AbstractImageViewRenderer -::SetGLSLEnabled( bool isEnabled ) -{ - bool wasEnabled = m_GLSLEnabled; +// inline +// bool +// AbstractImageViewRenderer +// ::SetGLSLEnabled( bool isEnabled ) +// { +// bool wasEnabled = m_GLSLEnabled; - m_GLSLEnabled = isEnabled; +// virtual_SetGLSLEnabled( isEnabled ); - return wasEnabled; -} +// m_GLSLEnabled = isEnabled; + +// return wasEnabled; +// } /*****************************************************************************/ inline diff --git a/Modules/Visualization/MonteverdiGui/include/mvdImageViewRenderer.h b/Modules/Visualization/MonteverdiGui/include/mvdImageViewRenderer.h index 00854a835c..b5747cde49 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdImageViewRenderer.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdImageViewRenderer.h @@ -140,7 +140,7 @@ public: /** */ - bool CheckGLCapabilities( int * ) override; + bool CheckGLCapabilities( int * ) const override; /** */ @@ -170,14 +170,14 @@ public: void GetViewExtent( PointType& origin, PointType& extent ) const override; - + AbstractImageViewRenderer::RenderingContext* NewRenderingContext() const override; void InitializeGL() override; void ResizeGL( int width, int height ) override; - + void PaintGL( const AbstractImageViewRenderer::RenderingContext* context ) override; void Pick( const PointType & view, @@ -200,6 +200,12 @@ public: bool IsEffectsEnabled() const override; + bool IsGLSLAvailable() const noexcept override; + + bool SetGLSLEnabled( bool ) override; + + bool IsGLSLEnabled() const noexcept override; + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ // public slots diff --git a/Modules/Visualization/MonteverdiGui/include/mvdImageViewWidget.h b/Modules/Visualization/MonteverdiGui/include/mvdImageViewWidget.h index 8a71ba2315..191cb35387 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdImageViewWidget.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdImageViewWidget.h @@ -171,11 +171,21 @@ public: */ bool IsPickingEnabled() const; + /** + */ + bool CheckGLCapabilities( int * ); + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ // // Public SLOTS. public slots: + /** + */ + bool SetGLSLEnabled( bool ) noexcept; + /** + */ + void ClearScene( bool ); /** */ void UpdateScene(); diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx index 8afb7309f1..8e8f9a0407 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx @@ -151,7 +151,7 @@ ImageViewRenderer /*****************************************************************************/ bool ImageViewRenderer -::CheckGLCapabilities( int * glsl140 ) +::CheckGLCapabilities( int * glsl140 ) const { #if USE_REMOTE_DESKTOP_DISABLED_RENDERING return true; @@ -165,7 +165,7 @@ ImageViewRenderer tr( "Required OpenGL version '%1' with GLSL version '%2'." ) .arg( otb::GlVersionChecker::REQUIRED_GL_VERSION ) .arg( otb::GlVersionChecker::REQUIRED_GLSL_VERSION ) - ).c_str(); + ).c_str(); // // Get and check OpenGL and GLSL versions. @@ -173,11 +173,15 @@ ImageViewRenderer const char * glVersion = NULL; const char * glslVersion = NULL; + assert( !m_GlView.IsNull() ); + bool isOk = false; try - { - isOk = otb::GlVersionChecker::CheckGLCapabilities( glVersion, glslVersion ); + { + std::size_t glslVer = m_GlView->CheckGLCapabilities( glVersion, glslVersion ); + + isOk = glslVer>0; if( glsl140!=NULL ) *glsl140 = otb::GlVersionChecker::VerCmp( glslVersion, "1.40" ); @@ -185,24 +189,24 @@ ImageViewRenderer // // Trace runtime OpenGL and GLSL versions. qWarning() << - ToStdString( - tr( "Runtime OpenGL version '%1' with GLSL version '%2'." ) - .arg( glVersion ) - .arg( glslVersion ) - ).c_str(); - } + ToStdString( + tr( "Runtime OpenGL version '%1' with GLSL version '%2'." ) + .arg( glVersion ) + .arg( glslVersion ) + ).c_str(); + } catch( std::exception& exc ) - { + { QMessageBox::critical( qobject_cast< QWidget* >( parent() ), tr( "Critical error!"), ToQString( exc.what() ) - ); - } + ); + } // // Set GLSL effects state. - SetGLSLEnabled( isOk ); + // SetGLSLEnabled( isOk ); // // Return if check has succeeded. @@ -217,7 +221,7 @@ ImageViewRenderer .arg( glslVersion ) .arg( otb::GlVersionChecker::REQUIRED_GL_VERSION ) .arg( otb::GlVersionChecker::REQUIRED_GLSL_VERSION ) - ); + ); // // Warn user is check has failed. @@ -228,7 +232,7 @@ ImageViewRenderer qobject_cast< QWidget* >( parent() ), tr( "Critical error!" ), message - ); + ); #endif // @@ -795,18 +799,18 @@ ImageViewRenderer case EFFECT_LUT_JET: shader->SetShaderType(otb::SHADER_LUT_JET); break; - + case EFFECT_LUT_LOCAL_JET: shader->SetShaderType(otb::SHADER_LUT_LOCAL_JET); shader->SetRadius( settings.GetSize() ); shader->SetLocalContrastRange(settings.GetValue()); - + break; - + case EFFECT_LUT_HOT: shader->SetShaderType(otb::SHADER_LUT_HOT); break; - + case EFFECT_LUT_LOCAL_HOT: shader->SetShaderType(otb::SHADER_LUT_LOCAL_HOT); shader->SetRadius( settings.GetSize() ); @@ -817,18 +821,18 @@ ImageViewRenderer case EFFECT_LUT_SUMMER: shader->SetShaderType(otb::SHADER_LUT_SUMMER); break; - + case EFFECT_LUT_LOCAL_SUMMER: shader->SetShaderType(otb::SHADER_LUT_LOCAL_SUMMER); shader->SetRadius( settings.GetSize() ); shader->SetLocalContrastRange(settings.GetValue()); break; - + case EFFECT_LUT_WINTER: shader->SetShaderType(otb::SHADER_LUT_WINTER); break; - + case EFFECT_LUT_LOCAL_WINTER: shader->SetShaderType(otb::SHADER_LUT_LOCAL_WINTER); shader->SetRadius( settings.GetSize() ); @@ -839,7 +843,7 @@ ImageViewRenderer case EFFECT_LUT_COOL: shader->SetShaderType(otb::SHADER_LUT_COOL); break; - + case EFFECT_LUT_LOCAL_COOL: shader->SetShaderType(otb::SHADER_LUT_LOCAL_COOL); shader->SetRadius( settings.GetSize() ); @@ -850,7 +854,7 @@ ImageViewRenderer - + default: assert( false && "Unhandled mvd::Effect value!" ); break; @@ -919,22 +923,21 @@ ImageViewRenderer ClearScene(); else + { { - { otb::GlView::StringVectorType keys( m_GlView->GetActorsKeys() ); for( otb::GlView::StringVectorType::const_iterator it( keys.begin() ); it!=keys.end(); ++it ) if( !stackedLayerModel->Contains( *it ) ) - { + { // qDebug() // << QString( "Removing image-actor '%1'..." ).arg( it->c_str() ); m_GlView->RemoveActor( *it ); - } - } - + } + } #if USE_REMOTE_DESKTOP_DISABLED_RENDERING #else // USE_REMOTE_DESKTOP_DISABLED_RENDERING @@ -943,11 +946,11 @@ ImageViewRenderer it!=stackedLayerModel->End(); ++it ) if( !m_GlView->ContainsActor( it->first ) ) - { + { assert( it->second!=NULL ); if( it->second->inherits( VectorImageModel::staticMetaObject.className())) - { + { otb::GlImageActor::Pointer glImageActor( otb::GlImageActor::New() ); // Should all AbstractLayerModel have a ::GetFilename() @@ -972,18 +975,18 @@ ImageViewRenderer // << "\tstd::string" << QFile::encodeName( vectorImageModel->GetFilename() ); if( IsGLSLEnabled() ) - { + { // qDebug() << "Created shader for" << FromStdString( it->first ); glImageActor->CreateShader(); - } + } glImageActor->Initialize( QFile::encodeName( vectorImageModel->GetFilename() - ) + ) .constData() - ); + ); m_GlView->AddActor( glImageActor, it->first ); @@ -991,15 +994,15 @@ ImageViewRenderer // QString( "Added image-actor '%1' from file '%2'" ) // .arg( FromStdString( it->first ) ) // .arg( vectorImageModel->GetFilename() ); - } + } else - { + { assert( false && "Unhandled AbstractLayerModel derived type." ); - } - } + } + } #endif // USE_REMOTE_DESKTOP_DISABLED_RENDERING - } + } RefreshScene(); } @@ -1373,5 +1376,41 @@ ImageViewRenderer return m_GlView->ZoomToFull( key, center, spacing ); } +/******************************************************************************/ +bool +ImageViewRenderer +::IsGLSLAvailable() const noexcept +{ + assert( !m_GlView.IsNull() ); + + return m_GlView->IsGLSLAvailable(); +} + +/******************************************************************************/ +bool +ImageViewRenderer +::IsGLSLEnabled() const noexcept +{ + assert( !m_GlView.IsNull() ); + + return m_GlView->IsGLSLEnabled(); +} + +/******************************************************************************/ +bool +ImageViewRenderer +::SetGLSLEnabled( bool isEnabled ) +{ + assert( !m_GlView.IsNull() ); + + bool wasGLSLEnabled = m_GlView->IsGLSLEnabled(); + + assert( m_GlView->IsEmpty() ); + + m_GlView->SetGLSLEnabled( isEnabled ); + + return wasGLSLEnabled; +} + /******************************************************************************/ } // end namespace 'mvd' diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx index 7128dc0caa..6d94b58e08 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx @@ -1397,24 +1397,26 @@ ImageViewWidget } } -void ImageViewWidget +/******************************************************************************/ +void +ImageViewWidget ::OnResetEffectsRequested() { - StackedLayerModel * layerStack = m_Renderer->GetLayerStack(); + StackedLayerModel * layerStack = m_Renderer->GetLayerStack(); - for( StackedLayerModel::ConstIterator it( layerStack->Begin() ); - it!=layerStack->End(); - ++it ) + for( StackedLayerModel::ConstIterator it( layerStack->Begin() ); + it!=layerStack->End(); + ++it ) + { + if( it->second->inherits( VectorImageModel::staticMetaObject.className() ) ) { - if( it->second->inherits( VectorImageModel::staticMetaObject.className() ) ) - { - VectorImageModel * imageModel = - qobject_cast< VectorImageModel * >( it->second ); - - VectorImageSettings & settings = imageModel->GetSettings(); - settings.SetEffect( EFFECT_NORMAL ); - } + VectorImageModel * imageModel = + qobject_cast< VectorImageModel * >( it->second ); + + VectorImageSettings & settings = imageModel->GetSettings(); + settings.SetEffect( EFFECT_NORMAL ); } + } emit ModelUpdated(); } @@ -1453,6 +1455,8 @@ ImageViewWidget { // qDebug() << this << "::OnContentChanged()"; + makeCurrent(); + UpdateScene(); if( !ApplyFixedZoomType() ) @@ -1466,6 +1470,8 @@ ImageViewWidget { // qDebug() << this << "::OnContentReset()"; + makeCurrent(); + UpdateScene(); if( !ApplyFixedZoomType() ) @@ -2249,6 +2255,7 @@ ImageViewWidget } } + makeCurrent(); assert( m_Renderer!=NULL ); @@ -2400,6 +2407,60 @@ ImageViewWidget m_Manipulator->CenterOn( center ); } +/******************************************************************************/ +bool +ImageViewWidget +::CheckGLCapabilities( int * glsl140 ) +{ + assert( m_Renderer ); + + makeCurrent(); + + return m_Renderer->CheckGLCapabilities( glsl140 ); +} + +/******************************************************************************/ +bool +ImageViewWidget +::SetGLSLEnabled( bool isEnabled ) noexcept +{ + assert( m_Renderer ); + + bool glslEnabled = m_Renderer->IsGLSLAvailable() && isEnabled; + + if( m_Renderer->IsGLSLEnabled()==glslEnabled ) + return m_Renderer->IsGLSLEnabled(); + + makeCurrent(); + + ClearScene( true ); + +#if OTB_DEBUG + std::cout + << "ImageViewRenderer( 0x" << std::hex << m_Renderer << std::dec + << " )::SetGLSLEnabled( " << glslEnabled << " )" + << std::endl; +#endif + + m_Renderer->SetGLSLEnabled( glslEnabled ); + + UpdateScene(); + + updateGL(); + + return glslEnabled; +} + +/******************************************************************************/ +void +ImageViewWidget +::ClearScene( bool keepViewport ) +{ + assert( m_Renderer!=NULL ); + + m_Renderer->ClearScene( keepViewport ); +} + /******************************************************************************/ void ImageViewWidget -- GitLab From 24086820c665601f0b08e373c2a8659997899a74 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 12:26:08 +0200 Subject: [PATCH 44/73] Improved memory-allocation exception-safety in otb::GlView. --- Modules/Visualization/Ice/src/otbGlView.cxx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index 8486a0d341..cd64152ba0 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -557,14 +557,14 @@ GlView assert( RgbPixel::Length==3 ); assert( sizeof( GLubyte )==1 ); - RgbPixel::ValueType * glBuffer = new RgbPixel::ValueType[ RgbPixel::Length * count ]; + auto glBuffer = std::make_unique< RgbPixel::ValueType[] >( RgbPixel::Length * count ); assert( glBuffer!=NULL ); glReadPixels( 0, 0, size[ 0 ], size[ 1 ], GL_RGB, GL_UNSIGNED_BYTE, - glBuffer + glBuffer.get() ); // @@ -584,7 +584,7 @@ GlView // // Copy & flip OpenGL pixel buffer into itk::RGBAPixel<> buffer. - RgbPixel * itkBuffer = new RgbPixel[ count ]; + auto itkBuffer = std::make_unique< RgbPixel[] >( count ); assert( itkBuffer ); for( unsigned long j=0; jSetImportPointer( - itkBuffer, + itkBuffer.release(), count, true ); -- GitLab From 3d16e144f6c8e49f0c891c9d4784abef20be131f Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 15:32:40 +0200 Subject: [PATCH 45/73] Improved memory-allocation exception safety in otb::GlImageActor. --- Modules/Visualization/Ice/src/otbGlImageActor.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 448e04ff7b..d744039d10 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -598,7 +598,12 @@ void GlImageActor::LoadTile(Tile& tile) { itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); - float * buffer = new float[4*extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels()]; + auto buffer = + std::make_unique< float[] >( + 4 * extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels() + ); + + assert( buffer ); unsigned int idx = 0; @@ -649,11 +654,10 @@ void GlImageActor::LoadTile(Tile& tile) extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], 0, GL_BGRA, GL_FLOAT, - buffer); + buffer.get() + ); tile.m_Loaded = true; - - delete [] buffer; } // And push to loaded texture -- GitLab From 6cb5fdaaeffc4e449c04822c77ed531f55dc7ab6 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 17:02:08 +0200 Subject: [PATCH 46/73] Restored projection matrix in no GLSL mode. --- .../Visualization/Ice/src/otbGlImageActor.cxx | 18 +++++++++++ Modules/Visualization/Ice/src/otbGlView.cxx | 31 ++++++++++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index d744039d10..18d64d2426 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -507,6 +507,24 @@ void GlImageActor::Render() for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) { + // std::cout << it->m_LL[ 0 ] << ", " << it->m_LL[ 1 ] << std::endl; + // std::cout << it->m_LR[ 0 ] << ", " << it->m_LR[ 1 ] << std::endl; + // std::cout << it->m_UR[ 0 ] << ", " << it->m_UR[ 1 ] << std::endl; + // std::cout << it->m_UL[ 0 ] << ", " << it->m_UL[ 1 ] << std::endl; + + // glDisable( GL_BLEND ); + + // glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); + + // glBegin( GL_QUADS ); + // { + // glVertex2f( it->m_LL[ 0 ], it->m_LL[ 1 ] ); + // glVertex2f( it->m_LR[ 0 ], it->m_LR[ 1 ] ); + // glVertex2f( it->m_UR[ 0 ], it->m_UR[ 1 ] ); + // glVertex2f( it->m_UL[ 0 ], it->m_UL[ 1 ] ); + // } + // glEnd(); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index cd64152ba0..7219e1984e 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -164,16 +164,20 @@ GlView // Clear back-buffer(s) before rendering glClear( GL_COLOR_BUFFER_BIT ); - // Setup projection according to view settings double ulx = -1.0; double uly = -1.0; double lrx = 1.0; double lry = 1.0; + assert( !m_Settings.IsNull() ); + m_Settings->GetViewportExtent(ulx,uly,lrx,lry); if( m_IsGLSLAvailable && m_IsGLSLEnabled ) { + // TODO: Use GLM [1] for OpenGL linear algebra. + // [1]: https://glm.g-truc.net/0.9.9/index.html + m_ProjMatrix[0] = 2.0/(lrx-ulx); m_ProjMatrix[1] = 0.0; m_ProjMatrix[2] = 0.0; @@ -237,7 +241,9 @@ GlView } else { - glOrtho(ulx, lrx, lry, uly, -1, 1); + // Setup projection according to view settings + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); // std::cout // << "glOrtho( " @@ -246,14 +252,24 @@ GlView // << ", -1, 1 )" // << std::endl; + glOrtho(ulx, lrx, lry, uly, -1, 1); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glPushMatrix(); + // glPushMatrix(); + + glTranslatef( + m_Settings->GetRotationCenter()[ 0 ], + m_Settings->GetRotationCenter()[ 1 ], 0 + ); - glTranslatef(m_Settings->GetRotationCenter()[0],m_Settings->GetRotationCenter()[1],0); - glRotatef(-m_Settings->GetRotationAngle()*180/M_PI,0,0,1); - glTranslatef(-m_Settings->GetRotationCenter()[0],-m_Settings->GetRotationCenter()[1],0); + glRotatef( -m_Settings->GetRotationAngle() * 180.0 / M_PI, 0, 0, 1 ); + + glTranslatef( + -m_Settings->GetRotationCenter()[ 0 ], + -m_Settings->GetRotationCenter()[ 1 ], + 0); } } @@ -262,7 +278,8 @@ void GlView::AfterRendering() // std::cout << "geometry-changed: FALSE" << std::endl; m_Settings->SetGeometryChanged(false); - glPopMatrix(); + + // glPopMatrix(); } std::string GlView::AddActor(ActorType * actor, const std::string& key) -- GitLab From c7b4429f7d917bf66f0c7f7b78333b9b0603ec95 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Wed, 2 Oct 2019 17:50:26 +0200 Subject: [PATCH 47/73] Restored GL texture enabling. --- .../Visualization/Ice/src/otbGlImageActor.cxx | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 18d64d2426..5263c17692 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -454,26 +454,23 @@ void GlImageActor::Render() for(imIt.GoToBegin(),inIt.GoToBegin();!imIt.IsAtEnd()&&!inIt.IsAtEnd();++imIt,++inIt) { - buffer[idx] = static_cast(imIt.Get()[2]); - ++idx; - buffer[idx] = static_cast(imIt.Get()[1]); - ++idx; - buffer[idx] = static_cast(imIt.Get()[0]); - ++idx; - buffer[idx] = 255; - - if(m_ImageSettings->GetUseNoData() && (inIt.Get()[0] == noData ||inIt.Get()[1] == noData ||inIt.Get()[2] == noData)) - { - buffer[idx] = 0; - } - - ++idx; + buffer[ idx++ ] = static_cast< GLubyte >(imIt.Get()[2]); + buffer[ idx++ ] = static_cast< GLubyte >(imIt.Get()[1]); + buffer[ idx++ ] = static_cast< GLubyte >(imIt.Get()[0]); + buffer[ idx++ ] = + ( m_ImageSettings->GetUseNoData() && + ( inIt.Get()[ 0 ] == noData || + inIt.Get()[ 1 ] == noData || + inIt.Get()[ 2 ] == noData ) ) + ? 0 + : 255; } - if(!it->m_TextureId) - { - glGenTextures(1, &(it->m_TextureId)); - } + assert( it->m_TextureId ); + + // if(!it->m_TextureId) + // glGenTextures(1, &(it->m_TextureId)); + glBindTexture(GL_TEXTURE_2D, it->m_TextureId); #if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); @@ -528,6 +525,7 @@ void GlImageActor::Render() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable( GL_TEXTURE_2D ); glBindTexture(GL_TEXTURE_2D,it->m_TextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -563,7 +561,7 @@ void GlImageActor::Render() else { // Reset color before rendering - glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); + // glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); glBegin( GL_QUADS ); { -- GitLab From d6225a384afdd4dbf843c3f73d3a5e619b06e9f1 Mon Sep 17 00:00:00 2001 From: Bas Couwenberg Date: Fri, 27 Sep 2019 14:39:32 +0200 Subject: [PATCH 48/73] Fix spelling errors. * catched -> caught * ouput -> output * allows to -> allows ing --- .../apTvPrOrthorectifTest_UTM_OutXML1.xml | 2 +- .../AppImageUtils/app/otbMosaic.cxx | 2 +- .../AppMathParserX/app/otbBandMathX.cxx | 2 +- .../AppStereo/app/otbFineRegistration.cxx | 2 +- .../Functor/include/otbFunctorImageFilter.h | 2 +- .../otbVariadicNamedInputsImageFilter.h | 2 +- .../Functor/test/otbFunctorImageFilter.cxx | 2 +- .../include/otbStreamingMosaicFilterBase.h | 2 +- ...otbStreamingMosaicFilterWithBlendingBase.h | 2 +- .../include/otbWrapperApplication.h | 22 +++++++++---------- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Data/Input/apTvPrOrthorectifTest_UTM_OutXML1.xml b/Data/Input/apTvPrOrthorectifTest_UTM_OutXML1.xml index 02a6df6f8d..19e9433dc8 100644 --- a/Data/Input/apTvPrOrthorectifTest_UTM_OutXML1.xml +++ b/Data/Input/apTvPrOrthorectifTest_UTM_OutXML1.xml @@ -5,7 +5,7 @@ Linux OrthoRectification - This application allows to ortho-rectify optical images from supported sensors. + This application allows ortho-rectifying optical images from supported sensors. Ortho-rectification An inverse sensor model is built from the input image metadata to convert geographical to raw geometry coordinates. This inverse sensor model is then combined with the chosen map projection to build a global coordinate mapping grid. Last, this grid is used to resample using the chosen interpolation algorithm. A Digital Elevation Model can be specified to account for terrain deformations. In case of SPOT5 images, the sensor model can be approximated by an RPC model in order to speed-up computation. diff --git a/Modules/Applications/AppImageUtils/app/otbMosaic.cxx b/Modules/Applications/AppImageUtils/app/otbMosaic.cxx index a575dc182c..ba3e400800 100644 --- a/Modules/Applications/AppImageUtils/app/otbMosaic.cxx +++ b/Modules/Applications/AppImageUtils/app/otbMosaic.cxx @@ -315,7 +315,7 @@ private: // Interpolators AddParameter(ParameterType_Choice, "interpolator", "Interpolation"); - SetParameterDescription("interpolator", "This group of parameters allows to define how the input image will be interpolated during resampling."); + SetParameterDescription("interpolator", "This group of parameters allows defining how the input image will be interpolated during resampling."); MandatoryOff("interpolator"); // NN diff --git a/Modules/Applications/AppMathParserX/app/otbBandMathX.cxx b/Modules/Applications/AppMathParserX/app/otbBandMathX.cxx index 31625f85a2..b4354037a3 100644 --- a/Modules/Applications/AppMathParserX/app/otbBandMathX.cxx +++ b/Modules/Applications/AppMathParserX/app/otbBandMathX.cxx @@ -302,7 +302,7 @@ private: } catch (...) { - SetParameterDescription("exp", "Other exception catched"); + SetParameterDescription("exp", "Other exception caught"); } } diff --git a/Modules/Applications/AppStereo/app/otbFineRegistration.cxx b/Modules/Applications/AppStereo/app/otbFineRegistration.cxx index 8ff49766c3..03d3c70364 100644 --- a/Modules/Applications/AppStereo/app/otbFineRegistration.cxx +++ b/Modules/Applications/AppStereo/app/otbFineRegistration.cxx @@ -488,7 +488,7 @@ private: // in this case, the pipeline cannot be resolved : the output image (wo) // won't be computed and a segfault can occur. otbAppLogFATAL( - "w option has not been set : the ouput image cannot be produced." + "w option has not been set : the output image cannot be produced." "Stop execution because the pipeline cannot be resolved"); } diff --git a/Modules/Core/Functor/include/otbFunctorImageFilter.h b/Modules/Core/Functor/include/otbFunctorImageFilter.h index 27d8ac0fdf..052d8a4431 100644 --- a/Modules/Core/Functor/include/otbFunctorImageFilter.h +++ b/Modules/Core/Functor/include/otbFunctorImageFilter.h @@ -440,7 +440,7 @@ auto NewFunctorFilter(Functor f, itk::Size<2> radius) /** * \struct NumberOfOutputBandsDecorator - * \brief This struct allows to forward the operator of template + * \brief This struct allows forwarding the operator of template * parameter, while adding number of ouptut components service. * * Its purpose is to enable the use of lambda or functor with diff --git a/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h b/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h index 19e993173c..27dfaea0d0 100644 --- a/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h +++ b/Modules/Core/Functor/include/otbVariadicNamedInputsImageFilter.h @@ -67,7 +67,7 @@ struct tuple_index> * used as a tag to set/get the corresponding input and thus should be * unique in tuple. * - * This allows to add semantic to inputs and remove the need for the + * This allows adding semantic to inputs and remove the need for the * user to know input orders and set them by their index. * * Example of use: diff --git a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx index d94d5226eb..b0fcf645f4 100644 --- a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx +++ b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx @@ -424,7 +424,7 @@ int otbFunctorImageFilter(int itkNotUsed(argc), char* itkNotUsed(argv)[]) return out; }; - // In this case, we use the helper function which allows to specify + // In this case, we use the helper function which allows specifying // the number of outputs auto filterLambda2 = NewFunctorFilter(Lambda2, vimage->GetNumberOfComponentsPerPixel(), {{3, 3}}); filterLambda2->SetInputs(image); diff --git a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h index 8e423d247e..82903b5e05 100644 --- a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h +++ b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.h @@ -41,7 +41,7 @@ namespace otb * regions of input images. There is a shift-scale mode which allows * to shift-scale input images, which can be useful e.g. color or * radiometric harmonization of input set of images. The output - * spacing (SetOuputSpacing()), the start index (SetOutputIndex()) and + * spacing (SetOutputSpacing()), the start index (SetOutputIndex()) and * the interpolator (SetInterpolator()) and the origin (SetOrigin()) * can be set using the method between brackets. * diff --git a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterWithBlendingBase.h b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterWithBlendingBase.h index 7b3a47c989..5f78bc120b 100644 --- a/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterWithBlendingBase.h +++ b/Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterWithBlendingBase.h @@ -38,7 +38,7 @@ namespace otb * Two parameters can be set: * -Distance image interpolator: explicit * -Distance image offset: this value is added to the interpolated distance image - * value, which allows to create a margin around the edges + * value, which allows creating a margin around the edges * of the image (i.e. around the 0-value distance image contour) * * Support streaming diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index 38dceb6ef2..726055b9cf 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -696,16 +696,16 @@ public: * to select the image in an InputImageList. */ ImageBaseType::PointType GetImageOrigin(const std::string& key, unsigned int idx = 0); - /** Get the spacing of the image parameter 'key'. The optional 'idx' allows to - * select the image in an InputImageList. We use the signed spacing convention. */ + /** Get the spacing of the image parameter 'key'. The optional 'idx' allows + * selecting the image in an InputImageList. We use the signed spacing convention. */ ImageBaseType::SpacingType GetImageSpacing(const std::string& key, unsigned int idx = 0); - /** Get the size of the image parameter 'key'. The optional 'idx' allows to - * select the image in an InputImageList. It corresponds to the size of LargestPossibleRegion*/ + /** Get the size of the image parameter 'key'. The optional 'idx' allows + * selecting the image in an InputImageList. It corresponds to the size of LargestPossibleRegion*/ ImageBaseType::SizeType GetImageSize(const std::string& key, unsigned int idx = 0); /** Get the number of bands in the image parameter 'key'. The optional 'idx' - * allows to select the image in an InputImageList.*/ + * allows selecting the image in an InputImageList.*/ unsigned int GetImageNbBands(const std::string& key, unsigned int idx = 0); /** Get the projection of the image parameter 'key'. The optional 'idx' allows @@ -713,18 +713,18 @@ public: std::string GetImageProjection(const std::string& key, unsigned int idx = 0); /** Get the keywordlist of the image parameter 'key'. The optional 'idx' - * allows to select the image in an InputImageList.*/ + * allows selecting the image in an InputImageList.*/ otb::ImageKeywordlist GetImageKeywordlist(const std::string& key, unsigned int idx = 0); /** Set the requested region on the image parameter 'key' and propagate it. * The returned value is an estimate of the RAM usage (in Bytes) to process * this region. It should be assumed that the index of the largest possible - * region starts at (0,0). The optional 'idx' allows to select the image in + * region starts at (0,0). The optional 'idx' allows selecting the image in * an InputImageList*/ unsigned long PropagateRequestedRegion(const std::string& key, ImageBaseType::RegionType region, unsigned int idx = 0); /** Get the requested region of the image parameter 'key'. The optional 'idx' - * allows to select the image in an InputImageList. It should be assumed that + * allows selecting the image in an InputImageList. It should be assumed that * the index of the largest possible region starts at (0,0).*/ ImageBaseType::RegionType GetImageRequestedRegion(const std::string& key, unsigned int idx = 0); @@ -733,12 +733,12 @@ public: /** Find out what is the pixel type from an image parameter * This function assumes that the underlying object is either an otb::Image - * or an otb::VectorImage. The optional 'idx' allows to access InputImageList. + * or an otb::VectorImage. The optional 'idx' allows accessing InputImageList. */ ImagePixelType GetImageBasePixelType(const std::string& key, unsigned int idx = 0); /** Return the image from parameter 'key' as a base type. The optional 'idx' - * allows to access InputImageList. + * allows accessing InputImageList. * * Works on parameters: * \li ParameterType_InputImage @@ -748,7 +748,7 @@ public: ImageBaseType* GetParameterImageBase(const std::string& key, unsigned int idx = 0); /** Set the image in parameter 'key' as a base type. The optional 'idx' - * allows to access InputImageList. + * allows accessing InputImageList. * * Works on parameters: * \li ParameterType_InputImage -- GitLab From e65efa4fc0370007944b57c82406f750b32fd16c Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 3 Oct 2019 11:49:39 +0200 Subject: [PATCH 49/73] Factorized extract-roi code from otb::glImageActor into otb::GlImageActor::Tile. --- .../Ice/include/otbGlImageActor.h | 18 ++- .../Visualization/Ice/src/otbGlImageActor.cxx | 114 +++++++++++++----- 2 files changed, 100 insertions(+), 32 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 77215f6034..e28cc3238c 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -223,7 +223,6 @@ protected: m_TextureId(0), m_ImageRegion(), m_TileSize(0), - m_Image(), m_UL(), m_UR(), m_LL(), @@ -240,11 +239,20 @@ protected: m_LR.Fill(0); } + ~Tile(); + + void Link( ReaderType::OutputImageType * ); + + ReaderType::OutputImageType::Pointer const & + Image() const noexcept + { return m_Image; } + + void Release(); + bool m_Loaded; unsigned int m_TextureId; RegionType m_ImageRegion; unsigned int m_TileSize; - VectorImageType::Pointer m_Image; PointType m_UL; PointType m_UR; PointType m_LL; @@ -254,9 +262,13 @@ protected: unsigned int m_GreenIdx; unsigned int m_BlueIdx; RescaleFilterType::Pointer m_RescaleFilter; + + private: + VectorImageType::Pointer m_Image; + }; - typedef std::vector TileVectorType; + typedef std::vector< Tile > TileVectorType; private: // prevent implementation diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 5263c17692..a9d71a422c 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -67,6 +67,64 @@ namespace otb { +GlImageActor::Tile +::~Tile() +{ + // Release(); +} + + +void +GlImageActor::Tile +::Release() +{ + assert( m_TextureId ); + + glDeleteTextures( 1, &m_TextureId ); + + // std::cout << "Deleted texture #" << m_TextureId << std::endl; + + m_TextureId = GL_ZERO; + +#if 0 + tile.m_Image = VectorImageType::Pointer(); + + tile.m_RescaleFilter = RescaleFilterType::Pointer(); + + tile.m_Loaded = false; +#endif +} + + +void +GlImageActor::Tile +::Link( GlImageActor::ReaderType::OutputImageType * i ) +{ + assert( i ); + + assert( !m_Loaded ); + assert( m_Image.IsNull() ); + + auto extract = ExtractROIFilterType::New(); + + assert( extract ); + + extract->SetInput( i ); + + extract->SetExtractionRegion( m_ImageRegion ); + + extract->SetChannel( m_RedIdx ); + extract->SetChannel( m_GreenIdx ); + extract->SetChannel( m_BlueIdx ); + + // std::cout << "ExtractROIFilter::Update()..."; + extract->Update(); + // std::cout << "\tDONE\n"; + + m_Image = extract->GetOutput(); +} + + GlImageActor::GlImageActor() : m_TileSize(256), m_FileName(), @@ -396,7 +454,7 @@ void GlImageActor::Render() { it->m_RescaleFilter = RescaleFilterType::New(); it->m_RescaleFilter->AutomaticInputMinMaxComputationOff(); - it->m_RescaleFilter->SetInput(it->m_Image); + it->m_RescaleFilter->SetInput( it->Image() ); } VectorImageType::PixelType mins(3),maxs(3),omins(3),omaxs(3); @@ -443,7 +501,7 @@ void GlImageActor::Render() itk::ImageRegionConstIterator imIt(it->m_RescaleFilter->GetOutput(),it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion()); - itk::ImageRegionConstIterator inIt(it->m_Image,it->m_Image->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator inIt(it->Image(),it->Image()->GetLargestPossibleRegion()); auto buffer = std::make_unique< GLubyte[] >( @@ -596,6 +654,9 @@ void GlImageActor::LoadTile(Tile& tile) // << "]" // << std::endl; + assert( !m_FileReader.IsNull() ); + +#if 0 ExtractROIFilterType::Pointer extract = ExtractROIFilterType::New(); extract->SetInput(m_FileReader->GetOutput()); @@ -609,14 +670,21 @@ void GlImageActor::LoadTile(Tile& tile) // std::cout << "\tDONE\n"; tile.m_Image = extract->GetOutput(); +#else + tile.Link( m_FileReader->GetOutput() ); +#endif + + assert( tile.Image() ); if( !m_SoftwareRendering ) { - itk::ImageRegionConstIterator it(extract->GetOutput(),extract->GetOutput()->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator< VectorImageType > it( + tile.Image(), + tile.Image()->GetLargestPossibleRegion()); auto buffer = std::make_unique< float[] >( - 4 * extract->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels() + 4 * tile.Image()->GetLargestPossibleRegion().GetNumberOfPixels() ); assert( buffer ); @@ -667,8 +735,8 @@ void GlImageActor::LoadTile(Tile& tile) // #endif glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[0], - extract->GetOutput()->GetLargestPossibleRegion().GetSize()[1], + tile.Image()->GetLargestPossibleRegion().GetSize()[ 0 ], + tile.Image()->GetLargestPossibleRegion().GetSize()[ 1 ], 0, GL_BGRA, GL_FLOAT, buffer.get() ); @@ -684,22 +752,7 @@ void GlImageActor::UnloadTile(Tile& tile) { // std::cout << std::hex << this << std::dec << "::UnloadTile()" << std::endl; - if( tile.m_Loaded ) - { - assert( tile.m_TextureId>0 ); - - glDeleteTextures( 1, &tile.m_TextureId ); - - // std::cout << "Deleted texture #" << tile.m_TextureId << std::endl; - - tile.m_TextureId = 0; - - tile.m_Image = VectorImageType::Pointer(); - - tile.m_RescaleFilter = RescaleFilterType::Pointer(); - - tile.m_Loaded = false; - } + tile.Release(); } void GlImageActor::CleanLoadedTiles() @@ -715,10 +768,11 @@ void GlImageActor::CleanLoadedTiles() RegionType requested; - this->ViewportExtentToImageRegion(ulx,uly,lrx,lry,requested); + ViewportExtentToImageRegion( ulx, uly, lrx, lry, requested ); - for(TileVectorType::iterator it = m_LoadedTiles.begin(); - it!=m_LoadedTiles.end();++it) + for( TileVectorType::iterator it = m_LoadedTiles.begin(); + it!=m_LoadedTiles.end(); + ++it ) { RegionType tileRegion = it->m_ImageRegion; @@ -746,8 +800,6 @@ void GlImageActor::CleanLoadedTiles() // std::cout<<"GPU memory cleanup: removing "<m_Image->GetPixel( idx ); + pixel = it->Image()->GetPixel( idx ); return true; } @@ -1317,7 +1369,11 @@ void GlImageActor::AutoColorAdjustment( double & minRed, double & maxRed, // Retrieve all tiles for(TileVectorType::iterator it = m_LoadedTiles.begin();it!=m_LoadedTiles.end();++it) { - itk::ImageRegionConstIterator imIt(it->m_Image,it->m_Image->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator< VectorImageType > imIt( + it->Image(), + it->Image()->GetLargestPossibleRegion() + ); + for(imIt.GoToBegin();!imIt.IsAtEnd();++imIt) { bool nonan = true; -- GitLab From 47c72e6bcb76cffb7b0bd75834c939d2b70f718e Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 3 Oct 2019 11:50:22 +0200 Subject: [PATCH 50/73] Removed obsolete code. --- .../Visualization/Ice/src/otbGlImageActor.cxx | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index a9d71a422c..5e104f88b0 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -656,23 +656,7 @@ void GlImageActor::LoadTile(Tile& tile) assert( !m_FileReader.IsNull() ); -#if 0 - ExtractROIFilterType::Pointer extract = ExtractROIFilterType::New(); - - extract->SetInput(m_FileReader->GetOutput()); - extract->SetExtractionRegion(tile.m_ImageRegion); - extract->SetChannel(tile.m_RedIdx); - extract->SetChannel(tile.m_GreenIdx); - extract->SetChannel(tile.m_BlueIdx); - - // std::cout << "ExtractROIFilter::Update()..."; - extract->Update(); - // std::cout << "\tDONE\n"; - - tile.m_Image = extract->GetOutput(); -#else tile.Link( m_FileReader->GetOutput() ); -#endif assert( tile.Image() ); -- GitLab From df9eebdddd482970df5493423ba1f2e650401ec1 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 3 Oct 2019 13:05:04 +0200 Subject: [PATCH 51/73] Factorized GL texture resource acquisition in otb::GlImageActor::Tile. --- .../Ice/include/otbGlImageActor.h | 4 +- .../Visualization/Ice/src/otbGlImageActor.cxx | 65 ++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index e28cc3238c..ec15eb7baf 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -34,6 +34,7 @@ #include "otbMultiChannelExtractROI.h" #include "otbVectorRescaleIntensityImageFilter.h" #include "otbVectorImage.h" + #include @@ -247,6 +248,7 @@ protected: Image() const noexcept { return m_Image; } + void Acquire() noexcept; void Release(); bool m_Loaded; @@ -268,7 +270,7 @@ protected: }; - typedef std::vector< Tile > TileVectorType; + typedef std::list< Tile > TileVectorType; private: // prevent implementation diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 5e104f88b0..d9f6ef66ba 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -74,6 +74,54 @@ GlImageActor::Tile } +void +GlImageActor::Tile +::Acquire() noexcept +{ + // Now load the texture + assert( m_TextureId==0 ); + + glGenTextures( 1, &m_TextureId ); + + // Following assert is sometimes false on some OpenGL systems for + // some unknown reason even though the glGenTexture() call has + // succeeded. + // assert( glGetError()==GL_NO_ERROR ); + + assert( m_TextureId!=0 ); + + // std::cout << "Generated texture #" << m_TextureId << std::endl; + + glBindTexture( GL_TEXTURE_2D, m_TextureId ); + +#if defined( GL_TEXTURE_BASE_LEVEL ) && defined( GL_TEXTURE_MAX_LEVEL ) + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0 ); +#endif + +#if 0 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#endif + + //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + +// #if defined(GL_CLAMP_TO_BORDER) +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); + +// #elif defined (GL_CLAMP_TO_BORDER_EXT) +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); + +// #elif defined (GL_MIRRORED_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); + +// #endif +} + + void GlImageActor::Tile ::Release() @@ -526,8 +574,9 @@ void GlImageActor::Render() assert( it->m_TextureId ); - // if(!it->m_TextureId) - // glGenTextures(1, &(it->m_TextureId)); +#if 0 + if(!it->m_TextureId) + glGenTextures(1, &(it->m_TextureId)); glBindTexture(GL_TEXTURE_2D, it->m_TextureId); #if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) @@ -547,6 +596,9 @@ void GlImageActor::Render() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); // #endif + +#endif + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0], @@ -687,6 +739,7 @@ void GlImageActor::LoadTile(Tile& tile) ++idx; } +#if 0 // Now load the texture assert( tile.m_TextureId==0 ); @@ -717,6 +770,12 @@ void GlImageActor::LoadTile(Tile& tile) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); // #endif + +#else + tile.Acquire(); + +#endif + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, tile.Image()->GetLargestPossibleRegion().GetSize()[ 0 ], @@ -729,7 +788,7 @@ void GlImageActor::LoadTile(Tile& tile) } // And push to loaded texture - m_LoadedTiles.push_back(tile); + m_LoadedTiles.push_back( tile ); } void GlImageActor::UnloadTile(Tile& tile) -- GitLab From 76625814598accfbbdb751e73e5f8ec01d3be769 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT Date: Thu, 3 Oct 2019 13:22:25 +0200 Subject: [PATCH 52/73] Removed needless code. --- .../Visualization/Ice/src/otbGlImageActor.cxx | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index d9f6ef66ba..079913c15c 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -574,31 +574,6 @@ void GlImageActor::Render() assert( it->m_TextureId ); -#if 0 - if(!it->m_TextureId) - glGenTextures(1, &(it->m_TextureId)); - - glBindTexture(GL_TEXTURE_2D, it->m_TextureId); -#if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); -#endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -// #if defined(GL_CLAMP_TO_BORDER) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); -// #elif defined (GL_CLAMP_TO_BORDER_EXT) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); -// #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); -// #endif - -#endif - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0], -- GitLab From c0acf04b1bac7d7ea1c24b28d1fa3691f8dc7422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Mon, 7 Oct 2019 17:57:42 +0200 Subject: [PATCH 53/73] BUG: disable non relevant output parameters in zonal statistics depending on the output type chosen --- .../AppClassification/app/otbZonalStatistics.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx b/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx index 5715746e7d..d8e29fb346 100644 --- a/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx +++ b/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx @@ -452,15 +452,30 @@ public: RemoveNoDataEntry(); // Generate output if (GetParameterAsString("out") == "xml") + { + DisableParameter("out.vector.filename"); + DisableParameter("out.raster.filename"); + EnableParameter("out.xml.filename"); WriteXMLStatsFile(); + } else // vector or raster { if (m_FromLabelImage) GenerateVectorDataFromLabelImage(); if (GetParameterAsString("out") == "vector") + { + EnableParameter("out.vector.filename"); + DisableParameter("out.raster.filename"); + DisableParameter("out.xml.filename"); WriteVectorData(); + } else if (GetParameterAsString("out") == "raster") + { + DisableParameter("out.vector.filename"); + EnableParameter("out.raster.filename"); + DisableParameter("out.xml.filename"); WriteRasterData(); + } else otbAppLogFATAL("Unknown output mode"); } -- GitLab From c3bbdf97074a21bcc72d1cf16a450ad5322486f2 Mon Sep 17 00:00:00 2001 From: Julien Michel Date: Wed, 9 Oct 2019 07:06:23 +0000 Subject: [PATCH 54/73] BUG: Properly take into account nodata value in accumulator --- .../include/otbStreamingStatisticsMapFromLabelImageFilter.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.h b/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.h index 8e6a6e4049..da21bc99b1 100644 --- a/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.h +++ b/Modules/Filtering/Statistics/include/otbStreamingStatisticsMapFromLabelImageFilter.h @@ -97,8 +97,11 @@ public: const RealValueType value = pixel[band]; const RealValueType sqValue = value * value; - UpdateValues(!m_UseNoDataValue || value != m_NoDataValue, value, sqValue, value, value, m_BandCount[band], m_Sum[band], m_SqSum[band], m_Min[band], + if(!m_UseNoDataValue || value != m_NoDataValue) + { + UpdateValues(1, value, sqValue, value, value, m_BandCount[band], m_Sum[band], m_SqSum[band], m_Min[band], m_Max[band]); + } } } -- GitLab From 795fa3b13aa86aeb061694de913bf0c0c43a2c92 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:02:28 +0200 Subject: [PATCH 55/73] REFAC: #1930: reduce verbosity --- .../Visualization/Ice/include/otbGlBufferObject.h | 14 +++----------- .../Ice/src/otbGlVertexArrayObject.cxx | 11 +---------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlBufferObject.h b/Modules/Visualization/Ice/include/otbGlBufferObject.h index 3dc3e44417..0eeb248b17 100644 --- a/Modules/Visualization/Ice/include/otbGlBufferObject.h +++ b/Modules/Visualization/Ice/include/otbGlBufferObject.h @@ -49,14 +49,10 @@ struct BufferObjectPolicy void Generate( Id_t & id ) { -#if OTB_DEBUG - std::cout << "glGenBuffers()" << std::endl; -#endif - - glGenBuffers( 1, &id ); + glGenBuffers( 1, &id ); #if OTB_DEBUG - std::cout << "-> " << id << std::endl; + std::cout << "glGenBuffers() -> " << id << std::endl; #endif } @@ -64,11 +60,7 @@ struct BufferObjectPolicy void Bind( Id_t id ) { -#if OTB_DEBUG - std::cout << "glBindBuffer( " << id << " )" << std::endl; -#endif - - glBindBuffer( static_cast< GLenum >( E ), id ); + glBindBuffer( static_cast< GLenum >( E ), id ); } static diff --git a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx index a78a85d8ad..73d8d95491 100644 --- a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx +++ b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx @@ -27,14 +27,10 @@ void VertexArrayObjectPolicy ::Generate( Id_t & id ) { -#if OTB_DEBUG - std::cout << "glGenVertexArrays()" << std::endl; -#endif - glGenVertexArrays( 1, &id ); #if OTB_DEBUG - std::cout << "-> " << id << std::endl; + std::cout << "glGenVertexArrays() -> " << id << std::endl; #endif } @@ -43,11 +39,6 @@ void VertexArrayObjectPolicy ::Bind( Id_t id ) { - -#if OTB_DEBUG - std::cout << "glBindVertexArray( " << id << " )" << std::endl; -#endif - glBindVertexArray( id ); } -- GitLab From 3c8e0e3579998d797f17b0f1bda1f0d6e0aa5310 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:24:47 +0200 Subject: [PATCH 56/73] REFAC: #1930: create simple quad --- .../Ice/include/otbGlImageActor.h | 2 +- Modules/Visualization/Ice/include/otbGlMesh.h | 1 + Modules/Visualization/Ice/src/otbGlMesh.cxx | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index ec15eb7baf..af6319f79d 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -43,7 +43,7 @@ namespace otb namespace gl { -class Mesh; +struct Mesh; } diff --git a/Modules/Visualization/Ice/include/otbGlMesh.h b/Modules/Visualization/Ice/include/otbGlMesh.h index 21f6f2e007..3d64d73368 100644 --- a/Modules/Visualization/Ice/include/otbGlMesh.h +++ b/Modules/Visualization/Ice/include/otbGlMesh.h @@ -98,6 +98,7 @@ Mesh MakeTexturedQuad( Id_t xy, Id_t uv ); Mesh MakeInterleavedTexturedQuad( Id_t xy, Id_t uv ); +Mesh MakeQuad( Id_t xy); } // end namespace gl. diff --git a/Modules/Visualization/Ice/src/otbGlMesh.cxx b/Modules/Visualization/Ice/src/otbGlMesh.cxx index bbf373d907..ff11a95913 100644 --- a/Modules/Visualization/Ice/src/otbGlMesh.cxx +++ b/Modules/Visualization/Ice/src/otbGlMesh.cxx @@ -80,6 +80,29 @@ MakeInterleavedTexturedQuad( Id_t xy, return std::move( mesh ); } +Mesh +MakeQuad( Id_t xy) +{ + Mesh mesh( + // + // vertices: (x, y ) + { -1.0f, -1.0f, + +1.0f, -1.0f, + +1.0f, +1.0f, + -1.0f, +1.0f}, + // + // Components + 2, + // + // indices compatible with triangles and line loop modes + { 0u, 1u, 2u, + 3u, 0u, 2u } + ); + + mesh.VertexAttribPointer( xy, 2, 0 ); + + return std::move( mesh ); +} void Mesh -- GitLab From 0f7b2dd9adf22d5cb2fcdbf35f89c4fe76de6a95 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:26:08 +0200 Subject: [PATCH 57/73] REFAC: #1930: color set with a uniform in MinimalShader --- .../Ice/include/otbMinimalShader.h | 8 +++--- .../Ice/src/otbMinimalShader.cxx | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbMinimalShader.h b/Modules/Visualization/Ice/include/otbMinimalShader.h index d9cf0e9fb6..536b9779de 100644 --- a/Modules/Visualization/Ice/include/otbMinimalShader.h +++ b/Modules/Visualization/Ice/include/otbMinimalShader.h @@ -43,7 +43,7 @@ public: itkNewMacro(Self); - itkGetMacro(ColorIdx, int); + void SetColor(const double *rgb, const double *a); protected: MinimalShader(); @@ -61,15 +61,17 @@ private: MinimalShader(const Self&); void operator=(const Self&); + const double *m_ColorRGB; + const double *m_ColorA; + struct UniformLocs { int proj; int modelview; + int color; }; UniformLocs m_Loc; - - int m_ColorIdx; }; // End class MinimalShader } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbMinimalShader.cxx b/Modules/Visualization/Ice/src/otbMinimalShader.cxx index e95c1e9661..b09a8d9a63 100644 --- a/Modules/Visualization/Ice/src/otbMinimalShader.cxx +++ b/Modules/Visualization/Ice/src/otbMinimalShader.cxx @@ -29,6 +29,8 @@ namespace otb { MinimalShader::MinimalShader() + : m_ColorRGB(nullptr) + , m_ColorA(nullptr) { // Register the shader in the ShaderRegistry BuildShader(); @@ -38,8 +40,9 @@ MinimalShader::MinimalShader() m_Loc.proj = glGetUniformLocation(m_Program, "in_proj"); m_Loc.modelview = glGetUniformLocation(m_Program, "in_mv"); // - for fragment shader + m_Loc.color = glGetUniformLocation(m_Program, "in_color"); - m_ColorIdx = glGetAttribLocation(m_Program , "in_color"); + m_AttribIdx.push_back( glGetAttribLocation(m_Program, "position") ); } MinimalShader::~MinimalShader() @@ -49,14 +52,12 @@ std::string MinimalShader::GetVertexSource() const { std::string shader_source = "#version 130 \n" \ - "in vec4 in_color;\n" \ - "out vec4 v_color;\n" \ + "in vec4 position;\n" \ "uniform mat4 in_proj;\n" \ "uniform mat4 in_mv;\n" \ "void main()\n" \ "{\n" \ - "v_color = in_color;\n" \ - "gl_Position = in_proj * in_mv * gl_Vertex;\n" \ + "gl_Position = in_proj * in_mv * position;\n" \ "}"; return shader_source; @@ -66,10 +67,10 @@ std::string MinimalShader::GetFragmentSource() const { std::string shader_source = "#version 130 \n" \ - "in vec4 v_color;\n" \ + "uniform vec4 in_color;\n" \ "out vec4 out_color;\n" \ "void main (void) {\n" \ - "out_color = v_color;\n" \ + "out_color = in_color;\n" \ "}"; return shader_source; @@ -84,6 +85,17 @@ void MinimalShader::SetupShader() { glUniformMatrix4fv(m_Loc.proj,1, GL_FALSE, m_ProjMatrix); glUniformMatrix4fv(m_Loc.modelview,1, GL_FALSE, m_ModelViewMatrix); + + assert(m_ColorRGB); + assert(m_ColorA); + + glUniform4f(m_Loc.color, m_ColorRGB[0], m_ColorRGB[1], m_ColorRGB[2], (*m_ColorA)); +} + +void MinimalShader::SetColor(const double *rgb, const double *a) +{ + m_ColorRGB = rgb; + m_ColorA = a; } } // End namespace otb -- GitLab From fcb9f1995f8a0fee30320d77dfbb65246c46f498 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:28:35 +0200 Subject: [PATCH 58/73] REFAC: #1930: fix Tile loading in GlImageActor --- .../Visualization/Ice/src/otbGlImageActor.cxx | 55 +++++-------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index 079913c15c..dac9423180 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -134,12 +134,12 @@ GlImageActor::Tile m_TextureId = GL_ZERO; -#if 0 - tile.m_Image = VectorImageType::Pointer(); +#if 1 + m_Image = VectorImageType::Pointer(); - tile.m_RescaleFilter = RescaleFilterType::Pointer(); + m_RescaleFilter = RescaleFilterType::Pointer(); - tile.m_Loaded = false; + m_Loaded = false; #endif } @@ -420,13 +420,12 @@ void GlImageActor::UpdateData() SizeType tileSize; tileSize.Fill(m_TileSize); - Tile newTile; for(unsigned int i = 0; i < nbTilesX; ++i) { for(unsigned int j = 0; jm_TextureId ); + glBindTexture(GL_TEXTURE_2D, it->m_TextureId); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0], @@ -646,7 +647,7 @@ void GlImageActor::Render() else { // Reset color before rendering - // glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); + glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); glBegin( GL_QUADS ); { @@ -687,7 +688,7 @@ void GlImageActor::LoadTile(Tile& tile) assert( tile.Image() ); - if( !m_SoftwareRendering ) + if( !m_SoftwareRendering && !m_Shader.IsNull()) { itk::ImageRegionConstIterator< VectorImageType > it( tile.Image(), @@ -714,43 +715,9 @@ void GlImageActor::LoadTile(Tile& tile) ++idx; } -#if 0 - // Now load the texture - assert( tile.m_TextureId==0 ); - - glGenTextures( 1, &tile.m_TextureId ); - - // Following assert is sometimes false on some OpenGL systems for - // some unknown reason even though the glGenTexture() call has - // succeeded. - // assert( glGetError()==GL_NO_ERROR ); - - assert( tile.m_TextureId!=0 ); - // std::cout << "Generated texture #" << tile.m_TextureId << std::endl; - - glBindTexture(GL_TEXTURE_2D, tile.m_TextureId); -#if defined(GL_TEXTURE_BASE_LEVEL) && defined(GL_TEXTURE_MAX_LEVEL) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); -#endif - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -// #if defined(GL_CLAMP_TO_BORDER) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); -// #elif defined (GL_CLAMP_TO_BORDER_EXT) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); -// #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); -// #endif - -#else tile.Acquire(); -#endif - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, tile.Image()->GetLargestPossibleRegion().GetSize()[ 0 ], @@ -761,6 +728,10 @@ void GlImageActor::LoadTile(Tile& tile) tile.m_Loaded = true; } + else + { + tile.Acquire(); + } // And push to loaded texture m_LoadedTiles.push_back( tile ); -- GitLab From 337992a30e7e10c59f4787ab74cf98eb1314915d Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:31:52 +0200 Subject: [PATCH 59/73] REFAC: #1930: implement VA/VBO for GlROIActor --- .../Visualization/Ice/include/otbGlROIActor.h | 9 ++ .../Visualization/Ice/src/otbGlROIActor.cxx | 110 +++++++++++++----- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlROIActor.h b/Modules/Visualization/Ice/include/otbGlROIActor.h index bddc9913a5..691792804a 100644 --- a/Modules/Visualization/Ice/include/otbGlROIActor.h +++ b/Modules/Visualization/Ice/include/otbGlROIActor.h @@ -32,6 +32,11 @@ namespace otb { +namespace gl +{ +struct Mesh; +} + class OTBIce_EXPORT GlROIActor : public GlActor { @@ -106,6 +111,7 @@ private: ColorType m_Color; double m_Alpha; + double m_CurrentAlpha; bool m_Fill; RSTransformType::Pointer m_ViewportToImageTransform; @@ -116,6 +122,9 @@ private: PointType m_VpLL; PointType m_VpLR; + /** OpenGL quad. */ + std::unique_ptr< gl::Mesh > m_Mesh; + }; // End class GlROIActor } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlROIActor.cxx b/Modules/Visualization/Ice/src/otbGlROIActor.cxx index 7506449f7b..fdb9fea053 100644 --- a/Modules/Visualization/Ice/src/otbGlROIActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlROIActor.cxx @@ -19,6 +19,7 @@ */ #include "otbGlROIActor.h" +#include "otbGlMesh.h" #include "otbViewSettings.h" #include "otbMinimalShader.h" #include "otbCast.h" @@ -38,13 +39,15 @@ GlROIActor::GlROIActor() m_Kwl(), m_Color(), m_Alpha(1.0), + m_CurrentAlpha(1.0), m_Fill(false), m_ViewportToImageTransform(), m_ImageToViewportTransform(), m_VpUL(), m_VpUR(), m_VpLL(), - m_VpLR() + m_VpLR(), + m_Mesh() { m_UL.Fill( 0 ); m_LR.Fill( 0 ); @@ -137,45 +140,94 @@ void GlROIActor::UpdateData() void GlROIActor::Render() { - m_Shader->LoadShader(); - m_Shader->SetupShader(); - - otb::MinimalShader::Pointer shader = - otb::DynamicCast< otb::MinimalShader >(m_Shader); - int colorIdx = shader->GetColorIdx(); - - glBegin(GL_LINE_LOOP); - glVertexAttrib4f(colorIdx, m_Color[0],m_Color[1],m_Color[2], 1.0); - glVertex2d(m_VpUL[0],m_VpUL[1]); - glVertex2d(m_VpUR[0],m_VpUR[1]); - glVertex2d(m_VpLR[0],m_VpLR[1]); - glVertex2d(m_VpLL[0],m_VpLL[1]); - glEnd(); - - if(m_Fill) + bool useShader = !m_Shader.IsNull(); + + if (useShader) + { + m_CurrentAlpha = 1.0; + m_Shader->LoadShader(); + m_Shader->SetupShader(); + + assert( m_Mesh ); + m_Mesh->Bind(); + + GLfloat vertexPosition[ 8 ] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, 1.0f + }; + + vertexPosition[0] = m_VpUL[0]; + vertexPosition[1] = m_VpUL[1]; + vertexPosition[2] = m_VpUR[0]; + vertexPosition[3] = m_VpUR[1]; + vertexPosition[4] = m_VpLR[0]; + vertexPosition[5] = m_VpLR[1]; + vertexPosition[6] = m_VpLL[0]; + vertexPosition[7] = m_VpLL[1]; + + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexPosition), vertexPosition); + + glDrawElements( GL_LINE_LOOP, 4, GL_UNSIGNED_INT, 0); + + if(m_Fill) + { + m_CurrentAlpha = m_Alpha; + m_Shader->SetupShader(); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + + glDisable(GL_BLEND); + } + + m_Shader->UnloadShader(); + } + else { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBegin(GL_QUADS); - glVertexAttrib4f(colorIdx, m_Color[0],m_Color[1],m_Color[2], m_Alpha); + glColor3d(m_Color[0],m_Color[1],m_Color[2]); + + glBegin(GL_LINE_LOOP); glVertex2d(m_VpUL[0],m_VpUL[1]); glVertex2d(m_VpUR[0],m_VpUR[1]); glVertex2d(m_VpLR[0],m_VpLR[1]); glVertex2d(m_VpLL[0],m_VpLL[1]); glEnd(); - glDisable(GL_BLEND); + + if(m_Fill) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4d(m_Color[0],m_Color[1],m_Color[2],m_Alpha); + glBegin(GL_QUADS); + glVertex2d(m_VpUL[0],m_VpUL[1]); + glVertex2d(m_VpUR[0],m_VpUR[1]); + glVertex2d(m_VpLR[0],m_VpLR[1]); + glVertex2d(m_VpLL[0],m_VpLL[1]); + glEnd(); + glDisable(GL_BLEND); + } } - - m_Shader->UnloadShader(); } void GlROIActor::CreateShader() { - if (m_Shader.IsNull()) - { - MinimalShader::Pointer shader( MinimalShader::New() ); - m_Shader = shader; - } + MinimalShader::Pointer shader( MinimalShader::New() ); + m_Shader = shader; + + // Check previous OpenGL error and clear error flag. + gl::CheckError< gl::error::clear >(); + + m_Mesh = std::make_unique< gl::Mesh >( + gl::MakeQuad( + shader->GetAttribIdx()[ 0 ] + ) + ); + + shader->SetColor(m_Color.GetDataPointer(), &m_CurrentAlpha); } void GlROIActor::UpdateTransforms() -- GitLab From 6df1030f6635bf7b35eedc43edf54ad0787fe8d9 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:32:59 +0200 Subject: [PATCH 60/73] REFAC: #1930: fix GlVectorActor --- Modules/Visualization/Ice/src/otbGlVectorActor.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx index 26532807db..acd61d3584 100644 --- a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx @@ -145,7 +145,7 @@ void GlVectorActor::CreateShader() { MinimalShader::Pointer shader( MinimalShader::New() ); m_Shader = shader; - m_ColorIdx = shader->GetColorIdx(); + shader->SetColor(m_Color.GetDataPointer(), &m_Alpha); } } @@ -643,7 +643,6 @@ void GlVectorActor::Render() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glLineWidth(m_LineWidth); - glVertexAttrib4f(m_ColorIdx, m_Color[0],m_Color[1],m_Color[2], m_Alpha); glCallList(m_DisplayList); -- GitLab From 0fade5e91b1f387553ea48f674b1b090a6de5a23 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:34:01 +0200 Subject: [PATCH 61/73] REFAC: #1930: switch between GL modes for ROIActor --- .../MonteverdiGui/src/mvdQuicklookViewRenderer.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx b/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx index 82c48ae732..b9d99768c6 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdQuicklookViewRenderer.cxx @@ -163,7 +163,10 @@ QuicklookViewRenderer return; #endif - m_GlRoiActor->CreateShader(); + if( IsGLSLEnabled() ) + { + m_GlRoiActor->CreateShader(); + } std::string key( m_GlView->AddActor( m_GlRoiActor, "ROI" ) ); -- GitLab From a8569ad92ccbeca037c88737781dbd61bf225c1d Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Thu, 10 Oct 2019 16:39:03 +0200 Subject: [PATCH 62/73] REFAC: #1930: switch between GL modes in iceViewer --- .../IceViewer/include/otbIceViewer.h | 1 + .../Visualization/IceViewer/src/otbIceViewer.cxx | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Modules/Visualization/IceViewer/include/otbIceViewer.h b/Modules/Visualization/IceViewer/include/otbIceViewer.h index e2f52a4993..7fb8e65326 100644 --- a/Modules/Visualization/IceViewer/include/otbIceViewer.h +++ b/Modules/Visualization/IceViewer/include/otbIceViewer.h @@ -147,6 +147,7 @@ private: std::map m_ColorMap; std::map::const_iterator m_ColorMapIterator; + bool m_UseGLSL; }; // End class IceViewer } // End namespace otb diff --git a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx index c63a92b32f..6914310260 100644 --- a/Modules/Visualization/IceViewer/src/otbIceViewer.cxx +++ b/Modules/Visualization/IceViewer/src/otbIceViewer.cxx @@ -55,7 +55,8 @@ IceViewer::IceViewer() m_DisplayHud(true), m_DisplayHelp(false), m_ColorMap(), - m_ColorMapIterator() + m_ColorMapIterator(), + m_UseGLSL(false) { // Fill color map // Sources for some colors value: http://prideout.net/archive/colors.php" @@ -91,11 +92,7 @@ void IceViewer::AddImage(const std::string & fname, const std::string & key, con otb::GlImageActor::Pointer actor = otb::GlImageActor::New(); - const char * glVersion = nullptr; - const char * glslVersion = nullptr; - - if( GlVersionChecker::CheckGLCapabilities( glVersion, - glslVersion ) ) + if( m_UseGLSL) actor->CreateShader(); actor->Initialize(fname); @@ -262,6 +259,10 @@ void IceViewer::Initialize(unsigned int w, unsigned int h, const std::string & n // Create view m_View = GlView::New(); m_View->Initialize(w,h); + + const char * glVersion = nullptr; + const char * glslVersion = nullptr; + m_UseGLSL = m_View->CheckGLCapabilities(glVersion, glslVersion); } void IceViewer::Refresh() @@ -1226,7 +1227,8 @@ void IceViewer::key_callback(GLFWwindow* window, int key, int scancode, int acti roiActor->SetFill(true); roiActor->SetAlpha(0.2); - roiActor->CreateShader(); + if (m_UseGLSL) + roiActor->CreateShader(); m_View->AddActor(roiActor,tmpKey); m_View->MoveActorToEndOfRenderingOrder(tmpKey,true); -- GitLab From ec7c25e6e5aca32e7f68df50a9a94550c132cfbe Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 11:34:33 +0200 Subject: [PATCH 63/73] COMP: fix merge issues --- .../MonteverdiGui/src/mvdImageViewWidget.cxx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx index 504b63b2c8..933c90af54 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx @@ -754,8 +754,7 @@ void ImageViewWidget::ListGlVersions() const if (glVersionFlags & QGLFormat::OpenGL_Version_4_0) qWarning() << "QGLFormat::OpenGL_Version_4_0"; - // - if( glVersionFlags & QGLFormat::OpenGL_Version_3_3 ) + if(glVersionFlags & QGLFormat::OpenGL_Version_3_3) qWarning() << "- QGLFormat::OpenGL_Version_3_3"; if (glVersionFlags & QGLFormat::OpenGL_Version_3_2) qWarning() << "- QGLFormat::OpenGL_Version_3_2"; @@ -763,13 +762,11 @@ void ImageViewWidget::ListGlVersions() const qWarning() << "- QGLFormat::OpenGL_Version_3_1"; if (glVersionFlags & QGLFormat::OpenGL_Version_3_0) qWarning() << "- QGLFormat::OpenGL_Version_3_0"; - // - if( glVersionFlags & QGLFormat::OpenGL_Version_2_1 ) + if(glVersionFlags & QGLFormat::OpenGL_Version_2_1) qWarning() << "- QGLFormat::OpenGL_Version_2_1"; if (glVersionFlags & QGLFormat::OpenGL_Version_2_0) qWarning() << "- QGLFormat::OpenGL_Version_2_0"; - // - if( glVersionFlags & QGLFormat::OpenGL_Version_1_5 ) + if(glVersionFlags & QGLFormat::OpenGL_Version_1_5) qWarning() << "- QGLFormat::OpenGL_Version_1_5"; if (glVersionFlags & QGLFormat::OpenGL_Version_1_4) qWarning() << "- QGLFormat::OpenGL_Version_1_4"; @@ -1072,7 +1069,7 @@ void ImageViewWidget ::OnResetEffectsRequested() { - StackedLayerModel * layerStack = m_Renderer->GetLayerStack(); + StackedLayerModel* layerStack = m_Renderer->GetLayerStack(); for( StackedLayerModel::ConstIterator it( layerStack->Begin() ); it!=layerStack->End(); @@ -1083,8 +1080,8 @@ ImageViewWidget VectorImageModel * imageModel = qobject_cast< VectorImageModel * >( it->second ); - VectorImageSettings & settings = imageModel->GetSettings(); - settings.SetEffect( EFFECT_NORMAL ); + VectorImageSettings& settings = imageModel->GetSettings(); + settings.SetEffect(EFFECT_NORMAL); } } @@ -1096,10 +1093,10 @@ void ImageViewWidget::OnClearProjectionRequired() { // qDebug() << this << "::OnClearProjectionRequested()"; - assert( m_Manipulator!=NULL ); + assert(m_Manipulator!=NULL); - m_Manipulator->SetWkt( std::string() ); - m_Manipulator->SetKeywordList( otb::ViewSettings::KeywordListType() ); + m_Manipulator->SetWkt(std::string()); + m_Manipulator->SetKeywordList(otb::ViewSettings::KeywordListType()); // m_Manipulator->SetOrigin( imageModel->GetOrigin() ); // m_Manipulator->SetSpacing( imageModel->GetSpacing() ); -- GitLab From f6b5caeb08454f327696f60191b4db939ae16dcd Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 11:42:04 +0200 Subject: [PATCH 64/73] REFAC: #1930: remove unused flag --- Modules/Visualization/Ice/include/otbGlImageActor.h | 6 ------ Modules/Visualization/Ice/src/otbGlImageActor.cxx | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index af6319f79d..6591cabc33 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -131,10 +131,6 @@ public: itkSetMacro(TileSize,unsigned int); itkGetMacro(TileSize,unsigned int); - itkBooleanMacro(SoftwareRendering ); - itkSetMacro(SoftwareRendering, bool ); - itkGetMacro(SoftwareRendering, bool ); - void CreateShader() override; void SetResolutionAlgorithm(ResolutionAlgorithm::type alg) @@ -336,8 +332,6 @@ private: /** OpenGL quad. */ std::unique_ptr< gl::Mesh > m_Mesh; - bool m_SoftwareRendering = false; - }; // End class GlImageActor } // End namespace otb diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index dac9423180..d569be4adf 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -479,7 +479,7 @@ void GlImageActor::Render() // << "\tresolution: " << m_ResolutionAlgorithm << std::endl // << "\ttile: " << m_TileSize << std::endl; - bool isShaderMode = !m_SoftwareRendering && !m_Shader.IsNull(); + bool isShaderMode = !m_Shader.IsNull(); if( isShaderMode ) { @@ -688,7 +688,7 @@ void GlImageActor::LoadTile(Tile& tile) assert( tile.Image() ); - if( !m_SoftwareRendering && !m_Shader.IsNull()) + if(!m_Shader.IsNull()) { itk::ImageRegionConstIterator< VectorImageType > it( tile.Image(), -- GitLab From a695eabba4d5599bed35a40b0ca8c0c5bb38fa96 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 14:54:25 +0200 Subject: [PATCH 65/73] STYLE: #1930: remove commented code, fix style --- .../Ice/include/otbGlImageActor.h | 21 +- .../Ice/include/otbGlVectorActor.h | 2 - Modules/Visualization/Ice/include/otbShader.h | 16 +- .../Ice/include/otbStandardShader.h | 2 +- Modules/Visualization/Ice/src/CMakeLists.txt | 3 - .../Ice/src/otbGlBufferObject.cxx | 28 -- Modules/Visualization/Ice/src/otbGlHandle.cxx | 28 -- .../Visualization/Ice/src/otbGlImageActor.cxx | 289 ++++++------------ .../Visualization/Ice/src/otbGlTypeTraits.cxx | 28 -- 9 files changed, 88 insertions(+), 329 deletions(-) delete mode 100644 Modules/Visualization/Ice/src/otbGlBufferObject.cxx delete mode 100644 Modules/Visualization/Ice/src/otbGlHandle.cxx delete mode 100644 Modules/Visualization/Ice/src/otbGlTypeTraits.cxx diff --git a/Modules/Visualization/Ice/include/otbGlImageActor.h b/Modules/Visualization/Ice/include/otbGlImageActor.h index 6591cabc33..40b9c6d839 100644 --- a/Modules/Visualization/Ice/include/otbGlImageActor.h +++ b/Modules/Visualization/Ice/include/otbGlImageActor.h @@ -215,26 +215,7 @@ protected: class Tile { public: - Tile() - : m_Loaded(false), - m_TextureId(0), - m_ImageRegion(), - m_TileSize(0), - m_UL(), - m_UR(), - m_LL(), - m_LR(), - m_Resolution(1), - m_RedIdx(1), - m_GreenIdx(2), - m_BlueIdx(3), - m_RescaleFilter(nullptr) - { - m_UL.Fill(0); - m_UR.Fill(0); - m_LL.Fill(0); - m_LR.Fill(0); - } + Tile(); ~Tile(); diff --git a/Modules/Visualization/Ice/include/otbGlVectorActor.h b/Modules/Visualization/Ice/include/otbGlVectorActor.h index 21803dd76e..6fdbd3bd08 100644 --- a/Modules/Visualization/Ice/include/otbGlVectorActor.h +++ b/Modules/Visualization/Ice/include/otbGlVectorActor.h @@ -182,8 +182,6 @@ private: RigidTransformType::Pointer m_ViewportForwardRotationTransform; RigidTransformType::Pointer m_ViewportBackwardRotationTransform; - int m_ColorIdx; - }; // End class GlVectorActor } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbShader.h b/Modules/Visualization/Ice/include/otbShader.h index 7bbfc5b1ef..68e7baa2bf 100644 --- a/Modules/Visualization/Ice/include/otbShader.h +++ b/Modules/Visualization/Ice/include/otbShader.h @@ -36,7 +36,7 @@ class OTBIce_EXPORT Shader { friend class GlView; public: - typedef Shader Self; + typedef Shader Self; typedef itk::Object Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; @@ -49,15 +49,6 @@ public: void UnloadShader(); - //~ itkSetMacro(UL,PointType); - //~ itkSetMacro(UR,PointType); - //~ itkSetMacro(LL,PointType); - //~ itkSetMacro(LR,PointType); - //~ itkGetConstReferenceMacro(UL,PointType); - //~ itkGetConstReferenceMacro(UR,PointType); - //~ itkGetConstReferenceMacro(LL,PointType); - //~ itkGetConstReferenceMacro(LR,PointType); - const std::vector & GetAttribIdx(); protected: @@ -90,11 +81,6 @@ private: Shader(const Self&); void operator=(const Self&); - //~ PointType m_UL; - //~ PointType m_UR; - //~ PointType m_LL; - //~ PointType m_LR; - }; // End class Shader } // End namespace otb diff --git a/Modules/Visualization/Ice/include/otbStandardShader.h b/Modules/Visualization/Ice/include/otbStandardShader.h index 6974adc488..790ea965bd 100644 --- a/Modules/Visualization/Ice/include/otbStandardShader.h +++ b/Modules/Visualization/Ice/include/otbStandardShader.h @@ -56,7 +56,7 @@ class OTBIce_EXPORT StandardShader { public: typedef StandardShader Self; - typedef Shader Superclass; + typedef Shader Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; diff --git a/Modules/Visualization/Ice/src/CMakeLists.txt b/Modules/Visualization/Ice/src/CMakeLists.txt index 86f4fbcb79..3a1d4abe40 100644 --- a/Modules/Visualization/Ice/src/CMakeLists.txt +++ b/Modules/Visualization/Ice/src/CMakeLists.txt @@ -21,16 +21,13 @@ set(OTBICE_SRCS otbGeoInterface.cxx otbGlActor.cxx - otbGlBufferObject.cxx otbGlError.cxx - otbGlHandle.cxx otbGlImageActor.cxx otbGlMesh.cxx otbGlROIActor.cxx otbGlView.cxx otbGlVectorActor.cxx otbGlVersionChecker.cxx - otbGlTypeTraits.cxx otbGlVersionChecker.cxx otbGlVertexArrayObject.cxx otbImageSettings.cxx diff --git a/Modules/Visualization/Ice/src/otbGlBufferObject.cxx b/Modules/Visualization/Ice/src/otbGlBufferObject.cxx deleted file mode 100644 index ccbbbd49ca..0000000000 --- a/Modules/Visualization/Ice/src/otbGlBufferObject.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbGlBufferObject.h" - - -namespace otb { namespace gl { - -} // End namespace 'gl'. - -} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlHandle.cxx b/Modules/Visualization/Ice/src/otbGlHandle.cxx deleted file mode 100644 index a5bfcf51e8..0000000000 --- a/Modules/Visualization/Ice/src/otbGlHandle.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbGlHandle.h" - - -namespace otb { namespace gl { - -} // End namespace 'gl'. - -} // End namespace 'otb'. diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index d569be4adf..ed79d111dd 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -28,12 +28,7 @@ #include -// #include "otbGlBufferObject.h" -// #include "otbGlError.h" #include "otbGlMesh.h" -// #include "otbGlObject.h" -// #include "otbGlTypeTraits.h" -// #include "otbGlVertexArrayObject.h" #include "otbStandardShader.h" @@ -43,35 +38,33 @@ #include - namespace otb { - -namespace gl -{ - - -// struct Dummy -// { -// virtual ~Dummy() = default; -// }; - - -} // end namespace 'gl'. - -} // end of namespace 'otb'. - - -namespace otb +GlImageActor::Tile() + : m_Loaded(false) + , m_TextureId(0) + , m_ImageRegion() + , m_TileSize(0) + , m_UL() + , m_UR() + , m_LL() + , m_LR() + , m_Resolution(1) + , m_RedIdx(1) + , m_GreenIdx(2) + , m_BlueIdx(3) + , m_RescaleFilter(nullptr) { - + m_UL.Fill(0); + m_UR.Fill(0); + m_LL.Fill(0); + m_LR.Fill(0); +} GlImageActor::Tile ::~Tile() -{ - // Release(); -} +{} void @@ -104,21 +97,8 @@ GlImageActor::Tile glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); #endif - //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - -// #if defined(GL_CLAMP_TO_BORDER) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); - -// #elif defined (GL_CLAMP_TO_BORDER_EXT) -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER_EXT); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER_EXT); - -// #elif defined (GL_MIRRORED_REPEAT) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); - -// #endif + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); } @@ -133,14 +113,9 @@ GlImageActor::Tile // std::cout << "Deleted texture #" << m_TextureId << std::endl; m_TextureId = GL_ZERO; - -#if 1 m_Image = VectorImageType::Pointer(); - m_RescaleFilter = RescaleFilterType::Pointer(); - m_Loaded = false; -#endif } @@ -165,9 +140,7 @@ GlImageActor::Tile extract->SetChannel( m_GreenIdx ); extract->SetChannel( m_BlueIdx ); - // std::cout << "ExtractROIFilter::Update()..."; extract->Update(); - // std::cout << "\tDONE\n"; m_Image = extract->GetOutput(); } @@ -214,8 +187,6 @@ GlImageActor { assert( m_Shader.IsNull() ); - std::cerr << "GlImageActor::CreateShader()" << std::endl; - StandardShader::Pointer shader( StandardShader::New() ); shader->SetImageSettings( m_ImageSettings ); @@ -314,23 +285,8 @@ void GlImageActor::Initialize(const std::string & filename) unsigned int ovrCount = m_FileReader->GetOverviewsCount(); - // std::cout << "overview-count: " << ovrCount << std::endl; - assert( ovrCount>0 ); - // { - // typedef std::vector< std::string > StringVector; - - // StringVector info( - // m_FileReader->GetOverviewsInfo() - // ); - - // for( StringVector::const_iterator it( info.begin() ); - // it!=info.end(); - // ++it ) - // std::cout << *it << std::endl; - // } - m_AvailableResolutions.clear(); for( unsigned int i=0; im_RescaleFilter = RescaleFilterType::New(); it->m_RescaleFilter->AutomaticInputMinMaxComputationOff(); - it->m_RescaleFilter->SetInput( it->Image() ); + it->m_RescaleFilter->SetInput(it->Image()); } VectorImageType::PixelType mins(3),maxs(3),omins(3),omaxs(3); @@ -525,7 +479,7 @@ void GlImageActor::Render() double gamma = m_ImageSettings->GetGamma(); gamma = - gamma == 0.0 + gamma == 0.0 ? std::numeric_limits< double >::max() : 1.0 / gamma; // } @@ -551,9 +505,9 @@ void GlImageActor::Render() itk::ImageRegionConstIterator inIt(it->Image(),it->Image()->GetLargestPossibleRegion()); auto buffer = - std::make_unique< GLubyte[] >( - 4 * it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels() - ); + std::make_unique< GLubyte[] >( + 4 * it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels() + ); unsigned int idx = 0; @@ -563,12 +517,12 @@ void GlImageActor::Render() buffer[ idx++ ] = static_cast< GLubyte >(imIt.Get()[1]); buffer[ idx++ ] = static_cast< GLubyte >(imIt.Get()[0]); buffer[ idx++ ] = - ( m_ImageSettings->GetUseNoData() && - ( inIt.Get()[ 0 ] == noData || - inIt.Get()[ 1 ] == noData || - inIt.Get()[ 2 ] == noData ) ) - ? 0 - : 255; + ( m_ImageSettings->GetUseNoData() && + ( inIt.Get()[ 0 ] == noData || + inIt.Get()[ 1 ] == noData || + inIt.Get()[ 2 ] == noData ) ) + ? 0 + : 255; } assert( it->m_TextureId ); @@ -581,7 +535,7 @@ void GlImageActor::Render() it->m_RescaleFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[1], 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer.get() - ); + ); it->m_Loaded = true; } @@ -590,24 +544,6 @@ void GlImageActor::Render() for(TileVectorType::iterator it = m_LoadedTiles.begin(); it != m_LoadedTiles.end(); ++it) { - // std::cout << it->m_LL[ 0 ] << ", " << it->m_LL[ 1 ] << std::endl; - // std::cout << it->m_LR[ 0 ] << ", " << it->m_LR[ 1 ] << std::endl; - // std::cout << it->m_UR[ 0 ] << ", " << it->m_UR[ 1 ] << std::endl; - // std::cout << it->m_UL[ 0 ] << ", " << it->m_UL[ 1 ] << std::endl; - - // glDisable( GL_BLEND ); - - // glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); - - // glBegin( GL_QUADS ); - // { - // glVertex2f( it->m_LL[ 0 ], it->m_LL[ 1 ] ); - // glVertex2f( it->m_LR[ 0 ], it->m_LR[ 1 ] ); - // glVertex2f( it->m_UR[ 0 ], it->m_UR[ 1 ] ); - // glVertex2f( it->m_UL[ 0 ], it->m_UL[ 1 ] ); - // } - // glEnd(); - glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -646,6 +582,7 @@ void GlImageActor::Render() } else { + // Compatibility mode // Reset color before rendering glColor4d( 1.0f, 1.0f, 1.0f, m_ImageSettings->GetAlpha() ); @@ -664,24 +601,13 @@ void GlImageActor::Render() } if( isShaderMode ) + { m_Shader->UnloadShader(); + } } void GlImageActor::LoadTile(Tile& tile) { - // std::cout - // << std::hex << this - // << "::LoadTile(" << &tile << ")" - // << std::dec << std::endl; - - // std::cout - // << "[ " << tile.m_ImageRegion.GetIndex()[ 0 ] - // << ", " << tile.m_ImageRegion.GetIndex()[ 1 ] - // << " ]-[ " << tile.m_ImageRegion.GetSize()[ 0 ] - // << ", " << tile.m_ImageRegion.GetSize()[ 1 ] - // << "]" - // << std::endl; - assert( !m_FileReader.IsNull() ); tile.Link( m_FileReader->GetOutput() ); @@ -696,8 +622,8 @@ void GlImageActor::LoadTile(Tile& tile) auto buffer = std::make_unique< float[] >( - 4 * tile.Image()->GetLargestPossibleRegion().GetNumberOfPixels() - ); + 4 * tile.Image()->GetLargestPossibleRegion().GetNumberOfPixels() + ); assert( buffer ); @@ -964,7 +890,7 @@ GlImageActor::PointType GlImageActor::ImageToViewportTransform(const PointType & bool GlImageActor ::GetPixelFromViewport( const PointType & in, - PixelType & pixel ) const + PixelType & pixel ) const { PointType p; IndexType i; @@ -976,9 +902,9 @@ GlImageActor bool GlImageActor ::GetPixelFromViewport( const PointType & ptView, - PixelType & pixel, - PointType & ptPhysical, - IndexType & index ) const + PixelType & pixel, + PointType & ptPhysical, + IndexType & index ) const { ptPhysical = ViewportToImageTransform( ptView ); @@ -989,25 +915,10 @@ GlImageActor bool GlImageActor ::GetPixel( const PointType & physical, - PixelType & pixel, - IndexType & index ) const + PixelType & pixel, + IndexType & index ) const { - - // std::cout << std::endl; - - // std::cout << "O: (" << m_Origin[ 0 ] << ", " << m_Origin[ 1 ] << ")"; - // std::cout << "\tS: (" << m_Spacing[ 1 ] << ", " << m_Spacing[ 1 ] << ")"; - // std::cout << std::endl; - - // std::cout << "P: (" << physical[ 0 ] << ", " << physical[ 1 ] << ")"; - // std::cout << std::endl; - // First, we need to return index in full img (not in overviews) -#if 0 - index[ 0 ] = static_cast((physical[0]-m_Origin[0])/m_Spacing[0]); - index[ 1 ] = static_cast((physical[1]-m_Origin[1])/m_Spacing[1]); - -#else index[ 0 ] = static_cast< IndexType::IndexValueType >( ( physical[ 0 ] + 0.5 * m_Spacing[0] - m_Origin[ 0 ] ) / @@ -1020,40 +931,15 @@ GlImageActor m_Spacing[ 1 ] ); -#endif - - // std::cout << "I: (" << index[ 0 ] << ", " << index[ 1 ] << ")"; - // std::cout - // << "\tI: (" - // << ( ( physical[ 0 ] - m_Origin[ 0 ] ) / m_Spacing[ 0 ] ) - // << ", " - // << ( ( physical[ 1 ] - m_Origin[ 1 ] ) / m_Spacing[ 1 ] ) - // << ")"; - // std::cout << std::endl; - // Then, we need to find the index in the currently loaded overview IndexType ovrIndex; m_FileReader->GetOutput()->TransformPhysicalPointToIndex( physical, ovrIndex ); - // std::cout << "O: (" << ovrIndex[ 0 ] << ", " << ovrIndex[ 1 ] << ")"; - // std::cout << std::endl; - // And look it up in loaded tiles for (TileVectorType::const_iterator it = m_LoadedTiles.begin(); it!=m_LoadedTiles.end(); ++it) { - // std::cout - // << "R: (" - // << it->m_ImageRegion.GetIndex()[ 0 ] - // << ", " - // << it->m_ImageRegion.GetIndex()[ 1 ] - // << ")-(" - // << it->m_ImageRegion.GetSize()[ 0 ] - // << ", " - // << it->m_ImageRegion.GetSize()[ 1 ] - // << ")"; - if(it->m_ImageRegion.IsInside(ovrIndex)) { IndexType idx; @@ -1061,21 +947,16 @@ GlImageActor idx[ 0 ] = ovrIndex[ 0 ] - it->m_ImageRegion.GetIndex()[ 0 ]; idx[ 1 ] = ovrIndex[ 1 ] - it->m_ImageRegion.GetIndex()[ 1 ]; - // std::cout << "\tIr: (" << idx[ 0 ] << ", " << idx[ 1 ] << ")"; - pixel = it->Image()->GetPixel( idx ); return true; } - - // std::cout << std::endl; } return false; } - void GlImageActor::UpdateResolution() { // Retrieve settings @@ -1115,7 +996,6 @@ void GlImageActor::UpdateResolution() double resolution = std::min(100/distAB,100/distAC); - // std::cout << std::endl; // std::cout << "resolution: " << resolution << std::endl; // Arbitrary higher than any distance we will compute here @@ -1133,29 +1013,29 @@ void GlImageActor::UpdateResolution() // Compute the diff and keep the index that minimize the distance for (ResolutionVectorType::iterator it = m_AvailableResolutions.begin(); - it != m_AvailableResolutions.end(); ++it) + it != m_AvailableResolutions.end(); ++it) { double diff = 1/((double)(1<<(*it))) - resolution; // std::cout << "diff: " << diff << std::endl; if( ( ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Lower && - diff <= 0 ) - || - ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Upper && - diff >= 0 ) - || - ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest ) ) - && - std::abs(diff) < minDist ) - { - isFound = true; - - minDist = std::abs(diff); - newResolution = std::distance(m_AvailableResolutions.begin(),it); - - // std::cout << "found: " << newResolution << std::endl; - } + diff <= 0 ) + || + ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest_Upper && + diff >= 0 ) + || + ( m_ResolutionAlgorithm == ResolutionAlgorithm::Nearest ) ) + && + std::abs(diff) < minDist ) + { + isFound = true; + + minDist = std::abs(diff); + newResolution = std::distance(m_AvailableResolutions.begin(),it); + + // std::cout << "found: " << newResolution << std::endl; + } } // MANTIS-1147: Cap current-resolution. @@ -1272,12 +1152,13 @@ void GlImageActor::UpdateTransforms() // std::cout << "}" << std::endl; } -void GlImageActor::AutoColorAdjustment( double & minRed, double & maxRed, - double & minGreen, double & maxGreen, - double & minBlue, double & maxBlue, - bool full, - unsigned int refSize, - double lcp, double hcp ) +void GlImageActor::AutoColorAdjustment( + double & minRed, double & maxRed, + double & minGreen, double & maxGreen, + double & minBlue, double & maxBlue, + bool full, + unsigned int refSize, + double lcp, double hcp ) { typedef itk::Statistics::ListSample ListSampleType; typedef itk::Statistics::DenseFrequencyContainer2 DFContainerType; @@ -1357,28 +1238,28 @@ void GlImageActor::AutoColorAdjustment( double & minRed, double & maxRed, { // Retrieve all tiles for(TileVectorType::iterator it = m_LoadedTiles.begin();it!=m_LoadedTiles.end();++it) - { - itk::ImageRegionConstIterator< VectorImageType > imIt( - it->Image(), - it->Image()->GetLargestPossibleRegion() - ); - - for(imIt.GoToBegin();!imIt.IsAtEnd();++imIt) { - bool nonan = true; - - for(unsigned int i = 0; i < imIt.Get().Size();++i) - { - nonan = nonan && !vnl_math_isnan(imIt.Get()[i]); - } + itk::ImageRegionConstIterator< VectorImageType > imIt( + it->Image(), + it->Image()->GetLargestPossibleRegion() + ); - if(nonan) + for(imIt.GoToBegin();!imIt.IsAtEnd();++imIt) { - listSample->PushBack(imIt.Get()); + bool nonan = true; + + for(unsigned int i = 0; i < imIt.Get().Size();++i) + { + nonan = nonan && !vnl_math_isnan(imIt.Get()[i]); + } + + if(nonan) + { + listSample->PushBack(imIt.Get()); + } } } } - } // Compute the histogram HistogramsGeneratorType::Pointer histogramsGenerator = HistogramsGeneratorType::New(); diff --git a/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx b/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx deleted file mode 100644 index d67b143fbd..0000000000 --- a/Modules/Visualization/Ice/src/otbGlTypeTraits.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbGlTypeTraits.h" - - -namespace otb { namespace gl { - -} // End namespace 'gl'. - -} // End namespace 'otb'. -- GitLab From 90b391db467e3f88ce05654ac2685cbfd256feb7 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 15:26:34 +0200 Subject: [PATCH 66/73] COMP: fix typos --- Modules/Visualization/Ice/src/otbGlImageActor.cxx | 3 ++- Modules/Visualization/Ice/src/otbGlVectorActor.cxx | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx index ed79d111dd..179343db26 100644 --- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx @@ -41,7 +41,8 @@ namespace otb { -GlImageActor::Tile() +GlImageActor::Tile +::Tile() : m_Loaded(false) , m_TextureId(0) , m_ImageRegion() diff --git a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx index acd61d3584..58615f7820 100644 --- a/Modules/Visualization/Ice/src/otbGlVectorActor.cxx +++ b/Modules/Visualization/Ice/src/otbGlVectorActor.cxx @@ -108,8 +108,7 @@ GlVectorActor::GlVectorActor() m_OptimizedRenderingActive(false), m_PointMarkerSize(5), m_ViewportForwardRotationTransform(RigidTransformType::New()), - m_ViewportBackwardRotationTransform(RigidTransformType::New()), - m_ColorIdx(0) + m_ViewportBackwardRotationTransform(RigidTransformType::New()) { m_Color.Fill(0); m_Color[0]=1.0; -- GitLab From b3711f668ac5feda23ebc512f507df96e0070758 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 15:27:49 +0200 Subject: [PATCH 67/73] STYLE: remove commented code Conflicts: Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx --- .../Ice/src/otbGlVertexArrayObject.cxx | 8 -- Modules/Visualization/Ice/src/otbGlView.cxx | 33 ++----- Modules/Visualization/Ice/src/otbShader.cxx | 13 +-- .../Monteverdi/include/mvdMainWindow.h | 1 - Modules/Visualization/Monteverdi/src/main.cxx | 3 - .../Monteverdi/src/mvdMainWindow.cxx | 6 +- .../src/mvdImageViewRenderer.cxx | 97 ++++++++++--------- 7 files changed, 63 insertions(+), 98 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx index 73d8d95491..230dad2eab 100644 --- a/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx +++ b/Modules/Visualization/Ice/src/otbGlVertexArrayObject.cxx @@ -28,10 +28,6 @@ VertexArrayObjectPolicy ::Generate( Id_t & id ) { glGenVertexArrays( 1, &id ); - -#if OTB_DEBUG - std::cout << "glGenVertexArrays() -> " << id << std::endl; -#endif } @@ -47,10 +43,6 @@ void VertexArrayObjectPolicy ::Release( Id_t & id ) { -#if OTB_DEBUG - std::cout << "glDeleteArrays( " << id << " )" << std::endl; -#endif - glDeleteVertexArrays( 1, &id ); } diff --git a/Modules/Visualization/Ice/src/otbGlView.cxx b/Modules/Visualization/Ice/src/otbGlView.cxx index 7219e1984e..d5a020d704 100644 --- a/Modules/Visualization/Ice/src/otbGlView.cxx +++ b/Modules/Visualization/Ice/src/otbGlView.cxx @@ -245,13 +245,6 @@ GlView glMatrixMode(GL_PROJECTION); glLoadIdentity(); - // std::cout - // << "glOrtho( " - // << ulx << ", " << lrx << ", " - // << lry << ", " << uly - // << ", -1, 1 )" - // << std::endl; - glOrtho(ulx, lrx, lry, uly, -1, 1); glMatrixMode(GL_MODELVIEW); @@ -559,11 +552,11 @@ GlView if( glGetError()!=GL_NO_ERROR ) throw std::runtime_error( std::string( - reinterpret_cast< const char * >( - gluErrorString( - glGetError() - ) - ) + reinterpret_cast< const char * >( + gluErrorString( + glGetError() + ) + ) ) ); @@ -591,11 +584,11 @@ GlView if( glGetError()!=GL_NO_ERROR ) throw std::runtime_error( std::string( - reinterpret_cast< const char * >( - gluErrorString( - glGetError() - ) - ) + reinterpret_cast< const char * >( + gluErrorString( + glGetError() + ) + ) ) ); @@ -654,10 +647,4 @@ GlView // itkBuffer = NULL; } - - //~ m_Settings->m_VertexShader = vShader; - //~ m_Settings->m_TextureCoordIdx = glGetAttribLocation(m_VertexProgram , "in_coord"); - - - } diff --git a/Modules/Visualization/Ice/src/otbShader.cxx b/Modules/Visualization/Ice/src/otbShader.cxx index ea444ba04b..7f4492a1f8 100644 --- a/Modules/Visualization/Ice/src/otbShader.cxx +++ b/Modules/Visualization/Ice/src/otbShader.cxx @@ -66,18 +66,7 @@ void Shader::UnloadShader() void Shader::SetupShader() { - // // Default always report corners - // GLint shader_ul = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ul"); - - // glUniform2f(shader_ul,m_UL[0],m_UL[1]); - // GLint shader_ur = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ur"); - // glUniform2f(shader_ur,m_UR[0],m_UR[1]); - - // GLint shader_ll = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_ll"); - // glUniform2f(shader_ll,m_LL[0],m_LL[1]); - - // GLint shader_lr = glGetUniformLocation(otb::ShaderRegistry::Instance()->GetShaderProgram("StandardShader"), "shader_lr"); - // glUniform2f(shader_lr,m_LR[0],m_LR[1]); + // Default does nothing } const std::vector & diff --git a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h index 0671fce4f0..07d822831f 100644 --- a/Modules/Visualization/Monteverdi/include/mvdMainWindow.h +++ b/Modules/Visualization/Monteverdi/include/mvdMainWindow.h @@ -415,7 +415,6 @@ private: /** */ - // bool m_isGLSLAvailable : 1; bool m_ForceNoGLSL : 1; /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ diff --git a/Modules/Visualization/Monteverdi/src/main.cxx b/Modules/Visualization/Monteverdi/src/main.cxx index f6ff231acf..54ace4cd35 100644 --- a/Modules/Visualization/Monteverdi/src/main.cxx +++ b/Modules/Visualization/Monteverdi/src/main.cxx @@ -233,9 +233,6 @@ int main(int argc, char* argv[]) // // 6. Let's go: run the application and return exit code. -#if OTB_DEBUG - std::cout << "QCoreApplication::instance()->exec();" << std::endl; -#endif int result = QCoreApplication::instance()->exec(); // Coverity-14835 diff --git a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx index 4af07c1660..04da028379 100644 --- a/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx +++ b/Modules/Visualization/Monteverdi/src/mvdMainWindow.cxx @@ -225,10 +225,6 @@ bool MainWindow::CheckGLCapabilities(bool forceNoGLSL) /*****************************************************************************/ void MainWindow::SetGLSLEnabled(bool enabled) { -#if OTB_DEBUG - std::cout << "MainWindow::SetGLSLEnabled( " << enabled << " )" << std::endl; -#endif - // // Image view assert( m_ImageView ); @@ -1204,7 +1200,7 @@ void MainWindow::on_action_GLSL_triggered(bool checked) { // qDebug() << this << "::on_action_GLSL_triggered(" << checked << ")"; - SetGLSLEnabled( /* m_isGLSLAvailable && !m_ForceNoGLSL && */ checked ); + SetGLSLEnabled(checked); } /*****************************************************************************/ diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx index 0959544d2e..3a30083d3c 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewRenderer.cxx @@ -188,7 +188,13 @@ ImageViewRenderer // // Construct message. QString message( - tr( "Current OpenGL version is '%1' supporting OpenGL Shading-Language (GLSL) version '%2'.\nTo run at best performances, this application needs, at least, OpenGL version '%3' with GLSL version '%4'.\nThe application will automatically switch to a rendering mode which does not make use of OpenGL shaders and GLSL.\nIf you are running this application under some remote-desktop service, runtime OpenGL and GLSL versions may differ from those running directly on remote platform." ) + tr( "Current OpenGL version is '%1' supporting OpenGL Shading-Language " + "(GLSL) version '%2'.\nTo run at best performances, this application " + "needs, at least, OpenGL version '%3' with GLSL version '%4'.\nThe " + "application will automatically switch to a rendering mode which does " + "not make use of OpenGL shaders and GLSL.\nIf you are running this " + "application under some remote-desktop service, runtime OpenGL and GLSL " + "versions may differ from those running directly on remote platform." ) .arg( glVersion ) .arg( glslVersion ) .arg( otb::GlVersionChecker::REQUIRED_GL_VERSION ) @@ -870,12 +876,12 @@ void ImageViewRenderer::virtual_UpdateScene() // << "\tQString:" << vectorImageModel->GetFilename() // << "\tstd::string" << QFile::encodeName( vectorImageModel->GetFilename() ); - if( IsGLSLEnabled() ) - { - // qDebug() << "Created shader for" << FromStdString( it->first ); - - glImageActor->CreateShader(); - } + if(IsGLSLEnabled()) + { + // qDebug() << "Created shader for" << FromStdString( it->first ); + + glImageActor->CreateShader(); + } glImageActor->Initialize( QFile::encodeName( @@ -892,9 +898,9 @@ void ImageViewRenderer::virtual_UpdateScene() // .arg( vectorImageModel->GetFilename() ); } else - { - assert( false && "Unhandled AbstractLayerModel derived type." ); - } + { + assert(false && "Unhandled AbstractLayerModel derived type."); + } } #endif // USE_REMOTE_DESKTOP_DISABLED_RENDERING @@ -1101,42 +1107,41 @@ void ImageViewRenderer::UpdatePixelInfo(const QPoint& screen, const PointType& / // Get shader. otb::Shader::Pointer ishader( glImageActor->GetShader() ); - if( !ishader.IsNull() ) - { - otb::StandardShader::Pointer shader( - otb::DynamicCast< otb::StandardShader >( - ishader - ) - ); - - assert( !shader.IsNull() ); - - // - // Update cursor position of shader. - PointType p_screen; - - assert( m_GlView->GetSettings()!=NULL ); - - p_screen[ 0 ] = screen.x(); - p_screen[ 1 ] = - m_GlView->GetSettings()->GetViewportSize()[ 1 ] - screen.y(); - - // qDebug() - // << "otb::StandardShader::SetCenter(" - // << p_screen[ 0 ] << "," << p_screen[ 1 ] - // << ")"; - - shader->SetCenter( p_screen ); - - if( shader->GetShaderType()==otb::SHADER_ALPHA_SLIDER ) - shader->SetSliderPosition( - p_screen[ - shader->GetVerticalSlider() - ? 1 - : 0 - ] - ); - } + if(!ishader.IsNull()) + { + otb::StandardShader::Pointer shader( + otb::DynamicCast< otb::StandardShader >( + ishader + ) + ); + + assert( !shader.IsNull() ); + + // + // Update cursor position of shader. + PointType p_screen; + + assert( m_GlView->GetSettings()!=NULL ); + + p_screen[ 0 ] = screen.x(); + p_screen[ 1 ] = + m_GlView->GetSettings()->GetViewportSize()[ 1 ] - screen.y(); + + // qDebug() + // << "otb::StandardShader::SetCenter(" + // << p_screen[ 0 ] << "," << p_screen[ 1 ] + // << ")"; + + shader->SetCenter( p_screen ); + + if( shader->GetShaderType()==otb::SHADER_ALPHA_SLIDER ) + shader->SetSliderPosition( + p_screen[ + shader->GetVerticalSlider() + ? 1 + : 0 + ] + ); } } } -- GitLab From f45eab4b1e555163ff1560b6ec5b78d860555c71 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 15:32:28 +0200 Subject: [PATCH 68/73] STYLE: remove logs --- .../Visualization/Ice/include/otbGlBufferObject.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Modules/Visualization/Ice/include/otbGlBufferObject.h b/Modules/Visualization/Ice/include/otbGlBufferObject.h index 0eeb248b17..74cf7ca310 100644 --- a/Modules/Visualization/Ice/include/otbGlBufferObject.h +++ b/Modules/Visualization/Ice/include/otbGlBufferObject.h @@ -50,10 +50,6 @@ struct BufferObjectPolicy Generate( Id_t & id ) { glGenBuffers( 1, &id ); - -#if OTB_DEBUG - std::cout << "glGenBuffers() -> " << id << std::endl; -#endif } static @@ -67,11 +63,7 @@ struct BufferObjectPolicy void Release( Id_t & id ) { -#if OTB_DEBUG - std::cout << "glDeleteBuffers( " << id << " )" << std::endl; -#endif - - glDeleteBuffers( 1, &id ); + glDeleteBuffers( 1, &id ); } }; @@ -169,10 +161,6 @@ private: }; -// template<> class BufferObject< element::vertex >; -// template<> class BufferObject< element::index >; - - using VertexBufferObject = BufferObject< element::vertex >; using IndexBufferObject = BufferObject< element::index >; -- GitLab From a9cbb40eb92e206795c2ecf645fb8b7305362d64 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Mon, 14 Oct 2019 17:02:07 +0200 Subject: [PATCH 69/73] COMP: fix wrong type --- Modules/Visualization/Ice/src/otbGlMesh.cxx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Modules/Visualization/Ice/src/otbGlMesh.cxx b/Modules/Visualization/Ice/src/otbGlMesh.cxx index ff11a95913..0899d83a1b 100644 --- a/Modules/Visualization/Ice/src/otbGlMesh.cxx +++ b/Modules/Visualization/Ice/src/otbGlMesh.cxx @@ -24,8 +24,7 @@ namespace otb { namespace gl { Mesh -MakeTexturedQuad( Id_t xy, - Id_t uv ) +MakeTexturedQuad( Id_t xy, Id_t uv ) { Mesh mesh( { // vertices (x, y) @@ -55,8 +54,7 @@ MakeTexturedQuad( Id_t xy, Mesh -MakeInterleavedTexturedQuad( Id_t xy, - id_t uv ) +MakeInterleavedTexturedQuad( Id_t xy, Id_t uv ) { Mesh mesh( // -- GitLab From 630ed082013cf6769c8c7c30baf1a0036777d2a3 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Tue, 15 Oct 2019 10:59:45 +0200 Subject: [PATCH 70/73] COMP: fix merge fuzz --- Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx | 3 --- 1 file changed, 3 deletions(-) diff --git a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx index 933c90af54..02c9efce19 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdImageViewWidget.cxx @@ -1880,9 +1880,6 @@ void ImageViewWidget::OnUpdateGammaRequested(double factor) assert(m_Renderer != NULL); - StackedLayerModel * stackedLayerModel = m_Renderer->GetLayerStack(); - assert( stackedLayerModel!=NULL ); - StackedLayerModel* stackedLayerModel = m_Renderer->GetLayerStack(); assert(stackedLayerModel != NULL); -- GitLab From 365f21cbf61329f32c816958ae1cdaf85ddad2a6 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero Date: Wed, 16 Oct 2019 10:44:39 +0200 Subject: [PATCH 71/73] CI: fix contribs check, take one side of the diff --- CI/contributors_check.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CI/contributors_check.sh b/CI/contributors_check.sh index d9a6328d46..70c3e8f5c4 100755 --- a/CI/contributors_check.sh +++ b/CI/contributors_check.sh @@ -38,8 +38,8 @@ git shortlog -es HEAD | cut -f 2- \ curl -s ${GITLAB_PROJECT_URL}/raw/master/CI/contributors/known-contributors.txt \ | sort -u > ${KNOWN_CONTRIBUTORS} -diff ${KNOWN_CONTRIBUTORS} ${GIT_CONTRIBUTORS} > ${UNKNOWN_CONTRIBUTORS} -if [ "$?" -ne "0" ] ; then +diff ${KNOWN_CONTRIBUTORS} ${GIT_CONTRIBUTORS} | grep '^>' > ${UNKNOWN_CONTRIBUTORS} +if [ -s "${UNKNOWN_CONTRIBUTORS}" ] ; then echo "" echo "WARNING: ***************************************************************" echo "WARNING: Unknown contributors found:" -- GitLab From 57c5349eaa9cd60edb86767fe063f5acac82a099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 29 Oct 2019 10:10:19 +0100 Subject: [PATCH 72/73] DOC: Update release notes for 7.0 --- RELEASE_NOTES.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 6338b82785..2e6e80d92c 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -48,6 +48,11 @@ Features added: Bugs fixed: + * !612: Ice OpenGL refactoring by Guillaume Pasero & Stéphane Albert + * !605: Resolve "ZonalStatistics app inbv parameter is not taken into account in stats filter" by Julien Michel + * !603: BUG: disable non relevant output parameters in zonal statistics depending on the output type chosen by Cédric Traizet + * !601: Fix OTB_ADDITIONAL_CACHE by Cédric Traizet + * !597: Fix the diapotb remote module by Cédric Traizet * !592: Fix StreamingWarpImageFilter issue with empty region by Julien Michel * !585: Fix PCA in Dimensionality reduction by Cédric Traizet * !583: Revert Merge branch 'bugfix-streamingwarpfilter-empty-region' into 'develop'" by Julien Michel @@ -313,6 +318,7 @@ Refactoring: CI: + * !598: Fix the otbGRM remote module by Cédric Traizet * !589: Mentions of copyright check by Sébastien Dinot * !584: Fixes for NamespaceHandler by Guillaume Pasero * !582: Script to setup a namespace for OTB imported targets by Guillaume Pasero @@ -371,6 +377,7 @@ CI: Documentation: + * !599: Fix spelling errors by Bas Couwenberg * !594: Fix typo in ossimCosmoSkymedModel by Laurențiu Nicola * !591: Fix non compliant headers by Cédric Traizet * !590: Error in FunctorImageFilter.rst example by Julien Michel -- GitLab From 1475a236b68921c7e544a72aed39494325d2bb70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= Date: Tue, 29 Oct 2019 10:11:39 +0100 Subject: [PATCH 73/73] DOC: update date in RELEASE_NOTES.txt --- RELEASE_NOTES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 2e6e80d92c..5752f9d093 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,4 +1,4 @@ -OTB-v.7.0.0 - Changes since version 6.6.0 (September 20th, 2019) +OTB-v.7.0.0 - Changes since version 6.6.0 (October 29th, 2019) ---------------------------------------------------------------- Features added: -- GitLab