# HG changeset patch # User Benjamin Golinvaux # Date 1558075795 -7200 # Node ID 9a474e90e8321cfc5330d35ffecffa2a8daa5692 # Parent 10910827f2359d5c757458a9e2ae3db64d23e7c8 Fixed a bunch of truncation warnings in various parts of the library diff -r 10910827f235 -r 9a474e90e832 Framework/Fonts/FontRenderer.cpp --- 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(fontContent_.c_str()); - CheckError(FT_New_Memory_Face(library_, data, fontContent_.size(), 0, &face_)); + CheckError(FT_New_Memory_Face( + library_, data, static_cast(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 diff -r 10910827f235 -r 9a474e90e832 Framework/Fonts/GlyphTextureAlphabet.cpp --- 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(sqrt(static_cast(countGlyphs))); + int c = boost::math::iround(sqrt(static_cast(countGlyphs))); if (c <= 0) { @@ -239,9 +239,9 @@ sourceAlphabet.GetAlphabet().Apply(size); TextureGenerator generator(alphabet_, - sourceAlphabet.GetAlphabet().GetSize(), - size.GetMaxWidth(), - size.GetMaxHeight()); + static_cast(sourceAlphabet.GetAlphabet().GetSize()), + size.GetMaxWidth(), + size.GetMaxHeight()); sourceAlphabet.GetAlphabet().Apply(generator); texture_.reset(generator.ReleaseTexture()); diff -r 10910827f235 -r 9a474e90e832 Framework/Fonts/OpenGLTextCoordinates.cpp --- 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(x - box_.GetLeft()); + float ry1 = static_cast(y - box_.GetTop()); float rx2 = rx1 + static_cast(width); float ry2 = ry1 + static_cast(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(alphabet.GetTextureWidth())), + textureHeight_(static_cast(alphabet.GetTextureHeight())) { if (textureWidth_ <= 0 || textureHeight_ <= 0) diff -r 10910827f235 -r 9a474e90e832 Framework/Scene2D/Internals/OpenGLLinesProgram.cpp --- 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(x1_)); + coords.push_back(static_cast(y1_)); + coords.push_back(static_cast(1)); + coords.push_back(static_cast(x2_)); + coords.push_back(static_cast(y2_)); + coords.push_back(static_cast(-1)); + coords.push_back(static_cast(x2_)); + coords.push_back(static_cast(y2_)); + coords.push_back(static_cast(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(miterX1_)); + miterDirections.push_back(static_cast(miterY1_)); + miterDirections.push_back(static_cast(miterX2_)); + miterDirections.push_back(static_cast(miterY2_)); + miterDirections.push_back(static_cast(miterX2_)); + miterDirections.push_back(static_cast(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(x1_)); + coords.push_back(static_cast(y1_)); + coords.push_back(static_cast(1)); + coords.push_back(static_cast(x1_)); + coords.push_back(static_cast(y1_)); + coords.push_back(static_cast(-1)); + coords.push_back(static_cast(x2_)); + coords.push_back(static_cast(y2_)); + coords.push_back(static_cast(-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(miterX1_)); + miterDirections.push_back(static_cast(miterY1_)); + miterDirections.push_back(static_cast(miterX1_)); + miterDirections.push_back(static_cast(miterY1_)); + miterDirections.push_back(static_cast(miterX2_)); + miterDirections.push_back(static_cast(miterY2_)); } }; @@ -247,7 +247,7 @@ const PolylineSceneLayer& layer) : context_(context), verticesCount_(0), - thickness_(layer.GetThickness()), + thickness_(static_cast(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(t1 / zoom)); + glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), + static_cast(t0 / t1)); } else { - glUniform1f(program_->GetUniformLocation("u_thickness"), thickness / zoom); + glUniform1f(program_->GetUniformLocation("u_thickness"), + static_cast(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(t1)); + glUniform1f(program_->GetUniformLocation("u_antialiasing_start"), + static_cast(t0 / t1)); } else { - glUniform1f(program_->GetUniformLocation("u_thickness"), thickness); + glUniform1f(program_->GetUniformLocation("u_thickness"), + static_cast(thickness)); } } diff -r 10910827f235 -r 9a474e90e832 Framework/Scene2D/Internals/OpenGLTextProgram.cpp --- 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(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(data.GetCoordinatesCount() / COMPONENTS)); glDisable(GL_BLEND); glDisableVertexAttribArray(positionLocation_); diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/DownloadStack.cpp --- 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(i - 1); + nodes_[i].next_ = static_cast(i + 1); nodes_[i].dequeued_ = false; } diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/FiniteProjectiveCamera.cpp --- 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(ix), static_cast(iy))) { if (MIP) { diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/OrthancSlicesLoader.cpp --- 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(*this, &OrthancSlicesLoader::ParseSliceImagePng), - new Callable(*this, &OrthancSlicesLoader::OnSliceImageError), - Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); - } + new Callable + (*this, &OrthancSlicesLoader::ParseSliceImagePng), + new Callable + (*this, &OrthancSlicesLoader::OnSliceImageError), + Operation::DownloadSliceImage( + static_cast(index), slice, SliceImageQuality_FullPng)); +} void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice, size_t index) { - std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + - boost::lexical_cast(slice.GetFrame())); + std::string uri = + ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + + boost::lexical_cast(slice.GetFrame())); switch (slice.GetConverter().GetExpectedPixelFormat()) { @@ -801,9 +807,14 @@ } orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap", - new Callable(*this, &OrthancSlicesLoader::ParseSliceImagePam), - new Callable(*this, &OrthancSlicesLoader::OnSliceImageError), - Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); + new Callable + (*this, &OrthancSlicesLoader::ParseSliceImagePam), + new Callable + (*this, &OrthancSlicesLoader::OnSliceImageError), + Operation::DownloadSliceImage(static_cast(index), + slice, SliceImageQuality_FullPam)); } @@ -839,9 +850,14 @@ boost::lexical_cast(slice.GetFrame())); orthanc_.GetJsonAsync(uri, - new Callable(*this, &OrthancSlicesLoader::ParseSliceImageJpeg), - new Callable(*this, &OrthancSlicesLoader::OnSliceImageError), - Operation::DownloadSliceImage(index, slice, quality)); + new Callable + (*this, &OrthancSlicesLoader::ParseSliceImageJpeg), + new Callable + (*this, &OrthancSlicesLoader::OnSliceImageError), + Operation::DownloadSliceImage( + static_cast(index), slice, quality)); } @@ -875,9 +891,14 @@ std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" + boost::lexical_cast(slice.GetFrame()) + "/raw.gz"); orthanc_.GetBinaryAsync(uri, IWebService::HttpHeaders(), - new Callable(*this, &OrthancSlicesLoader::ParseSliceRawImage), - new Callable(*this, &OrthancSlicesLoader::OnSliceImageError), - Operation::DownloadSliceRawImage(index, slice)); + new Callable + (*this, &OrthancSlicesLoader::ParseSliceRawImage), + new Callable + (*this, &OrthancSlicesLoader::OnSliceImageError), + Operation::DownloadSliceRawImage( + static_cast(index), slice)); } } } diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/ParallelSlicesCursor.cpp --- 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(slices_->GetSliceCount()); if (count == 0) { return false; @@ -123,7 +123,7 @@ } else { - slice = currentSlice_; + slice = static_cast(currentSlice_); } switch (mode) diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/ShearWarpProjectiveTransform.cpp --- 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(std::ceil(extent.GetWidth() / maxScaling)); + intermediateHeight_ = + static_cast(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(intermediateWidth_) / 2.0, - static_cast(intermediateHeight_) / 2.0, 0), - GeometryToolbox::CreateScalingMatrix(1.0 / maxScaling, 1.0 / maxScaling, 1), - GeometryToolbox::CreateTranslationMatrix(-extent.GetCenterX(), -extent.GetCenterY(), 0)); + GeometryToolbox::CreateTranslationMatrix( + static_cast(intermediateWidth_) / 2.0, + static_cast(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 diff -r 10910827f235 -r 9a474e90e832 Framework/Toolbox/ViewportGeometry.cpp --- 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(displayTouches[t].x), + static_cast(displayTouches[t].y)); + sceneTouches.push_back(Touch((float)sceneX, (float)sceneY)); } } diff -r 10910827f235 -r 9a474e90e832 Framework/Volumes/ImageBuffer3D.cpp --- 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( + converter.Apply((static_cast(minValue_) + maxValue_) / 2.0)); + + style.customWindowWidth_ = static_cast( + converter.Apply(static_cast(maxValue_) - minValue_)); if (style.customWindowWidth_ > 1) { diff -r 10910827f235 -r 9a474e90e832 Framework/Widgets/SliceViewerWidget.cpp --- 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(countMissing_); } bool RenderScene(CairoContext& context, diff -r 10910827f235 -r 9a474e90e832 Framework/Widgets/WorldSceneWidget.cpp --- 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(sx), static_cast(sy))); } tracker_->MouseMove(x, y, sceneX, sceneY, displayTouches, sceneTouches); }