Pārlūkot izejas kodu

BUG: Visual studio doesn't implement round()

Danielle Pace 14 gadi atpakaļ
vecāks
revīzija
f883314e00

+ 7 - 6
Libs/Visualization/VTK/Widgets/ctkVTKMagnifyView.cpp

@@ -31,6 +31,7 @@
 
 
 // VTK includes
 // VTK includes
 #include <QVTKWidget.h>
 #include <QVTKWidget.h>
+#include <vtkMath.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindow.h>
 #include <vtkUnsignedCharArray.h>
 #include <vtkUnsignedCharArray.h>
 
 
@@ -386,16 +387,16 @@ void ctkVTKMagnifyViewPrivate::updatePixmap()
 
 
   // When cropping the Qt image, the 'adjust' variables are in Qt coordinates,
   // When cropping the Qt image, the 'adjust' variables are in Qt coordinates,
   // not render window coordinates (bottom and top switch).
   // not render window coordinates (bottom and top switch).
-  int cropIndexLeft = round(errorLeft);
-  int cropIndexRight = imageSize.width() - round(errorRight) - 1;
-  int cropIndexTop = round(errorTop);
-  int cropIndexBottom = imageSize.height() - round(errorBottom) - 1;
+  int cropIndexLeft = vtkMath::Round(errorLeft);
+  int cropIndexRight = imageSize.width() - vtkMath::Round(errorRight) - 1;
+  int cropIndexTop = vtkMath::Round(errorTop);
+  int cropIndexBottom = imageSize.height() - vtkMath::Round(errorBottom) - 1;
 
 
   // Handle case when label size and magnification are not both even or odd
   // Handle case when label size and magnification are not both even or odd
   // (errorLeft/errorRight/errorBottom/errorTop will have fractional component,
   // (errorLeft/errorRight/errorBottom/errorTop will have fractional component,
   // so cropped image wouldn't be the correct size unless we adjust further).
   // so cropped image wouldn't be the correct size unless we adjust further).
-  int requiredWidth = round((posRight - posLeft + 1) * this->Magnification);
-  int requiredHeight = round((posTop - posBottom + 1) * this->Magnification);
+  int requiredWidth = vtkMath::Round((posRight - posLeft + 1) * this->Magnification);
+  int requiredHeight = vtkMath::Round((posTop - posBottom + 1) * this->Magnification);
   int actualWidth = cropIndexRight - cropIndexLeft + 1;
   int actualWidth = cropIndexRight - cropIndexLeft + 1;
   int actualHeight = cropIndexBottom - cropIndexTop + 1;
   int actualHeight = cropIndexBottom - cropIndexTop + 1;
   int diffWidth = requiredWidth - actualWidth;
   int diffWidth = requiredWidth - actualWidth;

+ 5 - 2
Libs/Widgets/ctkCrosshairLabel.cpp

@@ -50,6 +50,9 @@ public:
   void drawSimpleCrosshair(QPainter& painter);
   void drawSimpleCrosshair(QPainter& painter);
   void drawBullsEyeCrosshair(QPainter& painter);
   void drawBullsEyeCrosshair(QPainter& painter);
 
 
+  static int round(double f)
+    { return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
+
   bool      ShowCrosshair;
   bool      ShowCrosshair;
   QPen      CrosshairPen;
   QPen      CrosshairPen;
   ctkCrosshairLabel::CrosshairTypes CrosshairType;
   ctkCrosshairLabel::CrosshairTypes CrosshairType;
@@ -148,8 +151,8 @@ void ctkCrosshairLabelPrivate::drawBullsEyeCrosshair(QPainter& painter)
   // Draw the lines
   // Draw the lines
   double halfWidth = (size.width()-1.0) / 2.0;
   double halfWidth = (size.width()-1.0) / 2.0;
   double halfHeight = (size.height()-1.0) / 2.0;
   double halfHeight = (size.height()-1.0) / 2.0;
-  double blank = round(std::min(halfWidth, halfHeight)
-                       * this->BULLS_EYE_BLANK_FRACTION);
+  double blank = ctkCrosshairLabelPrivate::round(
+        std::min(halfWidth, halfHeight) * this->BULLS_EYE_BLANK_FRACTION);
 
 
   painter.drawLine(QPointF(0, halfHeight), QPointF(x-blank-1.0, halfHeight));
   painter.drawLine(QPointF(0, halfHeight), QPointF(x-blank-1.0, halfHeight));
   painter.drawLine(QPointF(x+bullsEye+blank, halfHeight),
   painter.drawLine(QPointF(x+bullsEye+blank, halfHeight),