changeset 693:9a474e90e832

Fixed a bunch of truncation warnings in various parts of the library
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 17 May 2019 08:49:55 +0200
parents 10910827f235
children 7c6197d9acc9 7bf91c4ebd65 5c551f078c18
files Framework/Fonts/FontRenderer.cpp Framework/Fonts/GlyphTextureAlphabet.cpp Framework/Fonts/OpenGLTextCoordinates.cpp Framework/Scene2D/Internals/OpenGLLinesProgram.cpp Framework/Scene2D/Internals/OpenGLTextProgram.cpp Framework/Toolbox/DownloadStack.cpp Framework/Toolbox/FiniteProjectiveCamera.cpp Framework/Toolbox/OrthancSlicesLoader.cpp Framework/Toolbox/ParallelSlicesCursor.cpp Framework/Toolbox/ShearWarpProjectiveTransform.cpp Framework/Toolbox/ViewportGeometry.cpp Framework/Volumes/ImageBuffer3D.cpp Framework/Widgets/SliceViewerWidget.cpp Framework/Widgets/WorldSceneWidget.cpp
diffstat 14 files changed, 133 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Fonts/FontRenderer.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Fonts/FontRenderer.cpp	Fri May 17 08:49:55 2019 +0200
@@ -101,7 +101,9 @@
       
       const FT_Byte* data = reinterpret_cast<const FT_Byte*>(fontContent_.c_str());
 
-      CheckError(FT_New_Memory_Face(library_, data, fontContent_.size(), 0, &face_));
+      CheckError(FT_New_Memory_Face(
+        library_, data, static_cast<FT_Long>(fontContent_.size()), 0, &face_));
+
       CheckError(FT_Set_Char_Size(face_,         // handle to face object  
                                   0,             // char_width in 1/64th of points  
                                   fontSize * 64, // char_height in 1/64th of points 
--- a/Framework/Fonts/GlyphTextureAlphabet.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Fonts/GlyphTextureAlphabet.cpp	Fri May 17 08:49:55 2019 +0200
@@ -89,7 +89,7 @@
       column_(0),
       row_(0)
     {
-      int c = boost::math::iround<int>(sqrt(static_cast<float>(countGlyphs)));
+      int c = boost::math::iround<float>(sqrt(static_cast<float>(countGlyphs)));
 
       if (c <= 0)
       {
@@ -239,9 +239,9 @@
     sourceAlphabet.GetAlphabet().Apply(size);
 
     TextureGenerator generator(alphabet_,
-                               sourceAlphabet.GetAlphabet().GetSize(),
-                               size.GetMaxWidth(),
-                               size.GetMaxHeight());
+      static_cast<unsigned int>(sourceAlphabet.GetAlphabet().GetSize()),
+      size.GetMaxWidth(),
+      size.GetMaxHeight());
     sourceAlphabet.GetAlphabet().Apply(generator);
 
     texture_.reset(generator.ReleaseTexture());
--- a/Framework/Fonts/OpenGLTextCoordinates.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Fonts/OpenGLTextCoordinates.cpp	Fri May 17 08:49:55 2019 +0200
@@ -35,8 +35,8 @@
                                       const Orthanc::IDynamicObject* payload)
     {
       // Rendering coordinates
-      float rx1 = x - box_.GetLeft();
-      float ry1 = y - box_.GetTop();
+      float rx1 = static_cast<float>(x - box_.GetLeft());
+      float ry1 = static_cast<float>(y - box_.GetTop());
       float rx2 = rx1 + static_cast<float>(width);
       float ry2 = ry1 + static_cast<float>(height);
 
@@ -81,8 +81,8 @@
     OpenGLTextCoordinates::OpenGLTextCoordinates(const GlyphTextureAlphabet& alphabet,
                                                  const std::string& utf8) :
       box_(alphabet.GetAlphabet(), utf8),
-      textureWidth_(alphabet.GetTextureWidth()),
-      textureHeight_(alphabet.GetTextureHeight())
+      textureWidth_(static_cast<float>(alphabet.GetTextureWidth())),
+      textureHeight_(static_cast<float>(alphabet.GetTextureHeight()))
     {
       if (textureWidth_ <= 0 ||
           textureHeight_ <= 0)
--- a/Framework/Scene2D/Internals/OpenGLLinesProgram.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLLinesProgram.cpp	Fri May 17 08:49:55 2019 +0200
@@ -205,40 +205,40 @@
         }
 
         // First triangle
-        coords.push_back(x1_);
-        coords.push_back(y1_);
-        coords.push_back(1);
-        coords.push_back(x2_);
-        coords.push_back(y2_);
-        coords.push_back(-1);
-        coords.push_back(x2_);
-        coords.push_back(y2_);
-        coords.push_back(1);
+        coords.push_back(static_cast<float>(x1_));
+        coords.push_back(static_cast<float>(y1_));
+        coords.push_back(static_cast<float>(1));
+        coords.push_back(static_cast<float>(x2_));
+        coords.push_back(static_cast<float>(y2_));
+        coords.push_back(static_cast<float>(-1));
+        coords.push_back(static_cast<float>(x2_));
+        coords.push_back(static_cast<float>(y2_));
+        coords.push_back(static_cast<float>(1));
 
-        miterDirections.push_back(miterX1_);
-        miterDirections.push_back(miterY1_);
-        miterDirections.push_back(miterX2_);
-        miterDirections.push_back(miterY2_);
-        miterDirections.push_back(miterX2_);
-        miterDirections.push_back(miterY2_);
+        miterDirections.push_back(static_cast<float>(miterX1_));
+        miterDirections.push_back(static_cast<float>(miterY1_));
+        miterDirections.push_back(static_cast<float>(miterX2_));
+        miterDirections.push_back(static_cast<float>(miterY2_));
+        miterDirections.push_back(static_cast<float>(miterX2_));
+        miterDirections.push_back(static_cast<float>(miterY2_));
         
         // Second triangle
-        coords.push_back(x1_);
-        coords.push_back(y1_);
-        coords.push_back(1);
-        coords.push_back(x1_);
-        coords.push_back(y1_);
-        coords.push_back(-1);
-        coords.push_back(x2_);
-        coords.push_back(y2_);
-        coords.push_back(-1);
+        coords.push_back(static_cast<float>(x1_));
+        coords.push_back(static_cast<float>(y1_));
+        coords.push_back(static_cast<float>(1));
+        coords.push_back(static_cast<float>(x1_));
+        coords.push_back(static_cast<float>(y1_));
+        coords.push_back(static_cast<float>(-1));
+        coords.push_back(static_cast<float>(x2_));
+        coords.push_back(static_cast<float>(y2_));
+        coords.push_back(static_cast<float>(-1));
 
-        miterDirections.push_back(miterX1_);
-        miterDirections.push_back(miterY1_);
-        miterDirections.push_back(miterX1_);
-        miterDirections.push_back(miterY1_);
-        miterDirections.push_back(miterX2_);
-        miterDirections.push_back(miterY2_);
+        miterDirections.push_back(static_cast<float>(miterX1_));
+        miterDirections.push_back(static_cast<float>(miterY1_));
+        miterDirections.push_back(static_cast<float>(miterX1_));
+        miterDirections.push_back(static_cast<float>(miterY1_));
+        miterDirections.push_back(static_cast<float>(miterX2_));
+        miterDirections.push_back(static_cast<float>(miterY2_));
       }        
     };
 
@@ -247,7 +247,7 @@
                                    const PolylineSceneLayer& layer) :
       context_(context),
       verticesCount_(0),
-      thickness_(layer.GetThickness()),
+      thickness_(static_cast<float>(layer.GetThickness())),
       red_(layer.GetRedAsFloat()),
       green_(layer.GetGreenAsFloat()),
       blue_(layer.GetBlueAsFloat())
@@ -418,12 +418,15 @@
             double t1 = std::max(thickness, aliasingBorder);
             double t0 = std::max(0.0, thickness - aliasingBorder);
             
-            glUniform1f(program_->GetUniformLocation("u_thickness"), t1 / zoom);
-            glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), t0 / t1);
+            glUniform1f(program_->GetUniformLocation("u_thickness"), 
+              static_cast<GLfloat>(t1 / zoom));
+            glUniform1f(program_->GetUniformLocation("u_antialiasing_start"),
+              static_cast<GLfloat>(t0 / t1));
           }
           else
           {
-            glUniform1f(program_->GetUniformLocation("u_thickness"), thickness / zoom);
+            glUniform1f(program_->GetUniformLocation("u_thickness"),
+              static_cast<GLfloat>(thickness / zoom));
           }
         }
         else
@@ -433,12 +436,15 @@
             double t1 = std::max(thickness, aliasingBorder / zoom);
             double t0 = std::max(0.0, thickness - aliasingBorder / zoom);
 
-            glUniform1f(program_->GetUniformLocation("u_thickness"), t1);
-            glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), t0 / t1);
+            glUniform1f(program_->GetUniformLocation("u_thickness"),
+              static_cast<GLfloat>(t1));
+            glUniform1f(program_->GetUniformLocation("u_antialiasing_start"),
+              static_cast<GLfloat>(t0 / t1));
           }
           else
           {
-            glUniform1f(program_->GetUniformLocation("u_thickness"), thickness);
+            glUniform1f(program_->GetUniformLocation("u_thickness"),
+              static_cast<GLfloat>(thickness));
           }
         }
 
--- a/Framework/Scene2D/Internals/OpenGLTextProgram.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Scene2D/Internals/OpenGLTextProgram.cpp	Fri May 17 08:49:55 2019 +0200
@@ -156,7 +156,8 @@
 
         double dx, dy;  // In pixels
         ComputeAnchorTranslation(dx, dy, data.GetAnchor(), 
-                                 data.GetTextWidth(), data.GetTextHeight(), data.GetBorder());
+                                 data.GetTextWidth(), data.GetTextHeight(),
+                                 static_cast<unsigned int>(data.GetBorder()));
       
         double x = data.GetX();
         double y = data.GetY();
@@ -182,7 +183,8 @@
 
         glEnable(GL_BLEND);
         glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-        glDrawArrays(GL_TRIANGLES, 0, data.GetCoordinatesCount() / COMPONENTS);
+        glDrawArrays(GL_TRIANGLES, 0, 
+          static_cast<GLsizei>(data.GetCoordinatesCount() / COMPONENTS));
         glDisable(GL_BLEND);
 
         glDisableVertexAttribArray(positionLocation_);
--- a/Framework/Toolbox/DownloadStack.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/DownloadStack.cpp	Fri May 17 08:49:55 2019 +0200
@@ -77,8 +77,8 @@
     {
       for (size_t i = 0; i < size; i++)
       {
-        nodes_[i].prev_ = i - 1;
-        nodes_[i].next_ = i + 1;
+        nodes_[i].prev_ = static_cast<int>(i - 1);
+        nodes_[i].next_ = static_cast<int>(i + 1);
         nodes_[i].dequeued_ = false;
       }
 
--- a/Framework/Toolbox/FiniteProjectiveCamera.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/FiniteProjectiveCamera.cpp	Fri May 17 08:49:55 2019 +0200
@@ -360,7 +360,8 @@
 
             // Read and accumulate the value of the pixel
             float pixel;
-            if (pixelReader.GetFloatValue(pixel, ix, iy))
+            if (pixelReader.GetFloatValue(
+              pixel, static_cast<float>(ix), static_cast<float>(iy)))
             {
               if (MIP)
               {
--- a/Framework/Toolbox/OrthancSlicesLoader.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/OrthancSlicesLoader.cpp	Fri May 17 08:49:55 2019 +0200
@@ -771,16 +771,22 @@
     }
     
     orthanc_.GetBinaryAsync(uri, "image/png",
-                            new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePng),
-                            new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
-                            Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng));
-  }
+      new Callable<OrthancSlicesLoader, 
+        OrthancApiClient::BinaryResponseReadyMessage>
+          (*this, &OrthancSlicesLoader::ParseSliceImagePng),
+      new Callable<OrthancSlicesLoader, 
+        IWebService::HttpRequestErrorMessage>
+          (*this, &OrthancSlicesLoader::OnSliceImageError),
+      Operation::DownloadSliceImage(
+        static_cast<unsigned int>(index), slice, SliceImageQuality_FullPng));
+}
   
   void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice,
                                                   size_t index)
   {
-    std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
-                       boost::lexical_cast<std::string>(slice.GetFrame()));
+    std::string uri = 
+      ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
+      boost::lexical_cast<std::string>(slice.GetFrame()));
 
     switch (slice.GetConverter().GetExpectedPixelFormat())
     {
@@ -801,9 +807,14 @@
     }
 
     orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap",
-                            new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePam),
-                            new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
-                            Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam));
+      new Callable<OrthancSlicesLoader, 
+        OrthancApiClient::BinaryResponseReadyMessage>
+          (*this, &OrthancSlicesLoader::ParseSliceImagePam),
+      new Callable<OrthancSlicesLoader, 
+        IWebService::HttpRequestErrorMessage>
+          (*this, &OrthancSlicesLoader::OnSliceImageError),
+      Operation::DownloadSliceImage(static_cast<unsigned int>(index), 
+                                    slice, SliceImageQuality_FullPam));
   }
 
 
@@ -839,9 +850,14 @@
                        boost::lexical_cast<std::string>(slice.GetFrame()));
 
     orthanc_.GetJsonAsync(uri,
-                          new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImageJpeg),
-                          new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
-                          Operation::DownloadSliceImage(index, slice, quality));
+      new Callable<OrthancSlicesLoader, 
+        OrthancApiClient::JsonResponseReadyMessage>
+          (*this, &OrthancSlicesLoader::ParseSliceImageJpeg),
+      new Callable<OrthancSlicesLoader, 
+        IWebService::HttpRequestErrorMessage>
+          (*this, &OrthancSlicesLoader::OnSliceImageError),
+        Operation::DownloadSliceImage(
+          static_cast<unsigned int>(index), slice, quality));
   }
   
   
@@ -875,9 +891,14 @@
       std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
                          boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz");
       orthanc_.GetBinaryAsync(uri, IWebService::HttpHeaders(),
-                              new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceRawImage),
-                              new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
-                              Operation::DownloadSliceRawImage(index, slice));
+        new Callable<OrthancSlicesLoader, 
+          OrthancApiClient::BinaryResponseReadyMessage>
+            (*this, &OrthancSlicesLoader::ParseSliceRawImage),
+        new Callable<OrthancSlicesLoader,
+          IWebService::HttpRequestErrorMessage>
+            (*this, &OrthancSlicesLoader::OnSliceImageError),
+        Operation::DownloadSliceRawImage(
+          static_cast<unsigned int>(index), slice));
     }
   }
 }
--- a/Framework/Toolbox/ParallelSlicesCursor.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/ParallelSlicesCursor.cpp	Fri May 17 08:49:55 2019 +0200
@@ -110,7 +110,7 @@
       return false;
     }
 
-    int count = slices_->GetSliceCount();
+    int count = static_cast<int>(slices_->GetSliceCount());
     if (count == 0)
     {
       return false;
@@ -123,7 +123,7 @@
     }
     else
     {
-      slice = currentSlice_;
+      slice = static_cast<int>(currentSlice_);
     }
 
     switch (mode)
--- a/Framework/Toolbox/ShearWarpProjectiveTransform.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/ShearWarpProjectiveTransform.cpp	Fri May 17 08:49:55 2019 +0200
@@ -195,15 +195,20 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
     }
 
-    intermediateWidth_ = std::ceil(extent.GetWidth() / maxScaling);
-    intermediateHeight_ = std::ceil(extent.GetHeight() / maxScaling);
+    intermediateWidth_ = 
+      static_cast<unsigned int>(std::ceil(extent.GetWidth() / maxScaling));
+    intermediateHeight_ = 
+      static_cast<unsigned int>(std::ceil(extent.GetHeight() / maxScaling));
 
     // This is the product "T * S" in Equation (A.16) on page 209
     Matrix TS = LinearAlgebra::Product(
-      GeometryToolbox::CreateTranslationMatrix(static_cast<double>(intermediateWidth_) / 2.0,
-                                               static_cast<double>(intermediateHeight_) / 2.0, 0),
-      GeometryToolbox::CreateScalingMatrix(1.0 / maxScaling, 1.0 / maxScaling, 1),
-      GeometryToolbox::CreateTranslationMatrix(-extent.GetCenterX(), -extent.GetCenterY(), 0));
+      GeometryToolbox::CreateTranslationMatrix(
+        static_cast<double>(intermediateWidth_) / 2.0,
+        static_cast<double>(intermediateHeight_) / 2.0, 0),
+      GeometryToolbox::CreateScalingMatrix(
+        1.0 / maxScaling, 1.0 / maxScaling, 1),
+      GeometryToolbox::CreateTranslationMatrix(
+        -extent.GetCenterX(), -extent.GetCenterY(), 0));
     
     // This is Equation (A.16) on page 209. WARNING: There is an
     // error in Lacroute's thesis: "inv(MM_shear)" is used instead
--- a/Framework/Toolbox/ViewportGeometry.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Toolbox/ViewportGeometry.cpp	Fri May 17 08:49:55 2019 +0200
@@ -128,7 +128,12 @@
     sceneTouches.clear();
     for (size_t t = 0; t < displayTouches.size(); t++)
     {
-      MapPixelCenterToScene(sceneX, sceneY, displayTouches[t].x, displayTouches[t].y);
+      MapPixelCenterToScene(
+        sceneX,
+        sceneY, 
+        static_cast<int>(displayTouches[t].x), 
+        static_cast<int>(displayTouches[t].y));
+      
       sceneTouches.push_back(Touch((float)sceneX, (float)sceneY));
     }
   }
--- a/Framework/Volumes/ImageBuffer3D.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Volumes/ImageBuffer3D.cpp	Fri May 17 08:49:55 2019 +0200
@@ -264,8 +264,15 @@
     if (hasRange_)
     {
       style.windowing_ = ImageWindowing_Custom;
-      style.customWindowCenter_ = converter.Apply((minValue_ + maxValue_) / 2.0);
-      style.customWindowWidth_ = converter.Apply(maxValue_ - minValue_);
+      
+      // casting the narrower type to wider before calling the + operator
+      // will prevent overflowing (this is why the cast to double is only 
+      // done on the first operand)
+      style.customWindowCenter_ = static_cast<float>(
+        converter.Apply((static_cast<double>(minValue_) + maxValue_) / 2.0));
+      
+      style.customWindowWidth_ = static_cast<float>(
+        converter.Apply(static_cast<double>(maxValue_) - minValue_));
       
       if (style.customWindowWidth_ > 1)
       {
--- a/Framework/Widgets/SliceViewerWidget.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Widgets/SliceViewerWidget.cpp	Fri May 17 08:49:55 2019 +0200
@@ -115,7 +115,7 @@
 
     unsigned int GetCountMissing() const
     {
-      return countMissing_;
+      return static_cast<unsigned int>(countMissing_);
     }
 
     bool RenderScene(CairoContext& context,
--- a/Framework/Widgets/WorldSceneWidget.cpp	Thu May 16 20:39:30 2019 +0200
+++ b/Framework/Widgets/WorldSceneWidget.cpp	Fri May 17 08:49:55 2019 +0200
@@ -83,8 +83,12 @@
       for (size_t t = 0; t < displayTouches.size(); t++)
       {
         double sx, sy;
-        view_.MapPixelCenterToScene(sx, sy, (int)displayTouches[t].x, (int)displayTouches[t].y);
-        sceneTouches.push_back(Touch(sx, sy));
+        
+        view_.MapPixelCenterToScene(
+          sx, sy, (int)displayTouches[t].x, (int)displayTouches[t].y);
+        
+        sceneTouches.push_back(
+          Touch(static_cast<float>(sx), static_cast<float>(sy)));
       }
       tracker_->MouseMove(x, y, sceneX, sceneY, displayTouches, sceneTouches);
     }