Salome HOME
Copyright update 2022
[modules/gui.git] / src / VTKViewer / VTKViewer_MarkerUtils.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8b68004..c66e93f
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -72,7 +72,7 @@ namespace VTK
       aHeight++;
     }
 
-    if( theMarkerTexture.size() != aWidth * aHeight )
+    if( (int)theMarkerTexture.size() != aWidth * aHeight )
       return false;
 
     theMarkerTexture.push_front( aWidth );
@@ -92,9 +92,7 @@ namespace VTK
     anImageData->Delete();
 
     anImageData->SetExtent( 0, aWidth-1, 0, aHeight-1, 0, 0 );
-    anImageData->SetScalarTypeToUnsignedChar();
-    anImageData->SetNumberOfScalarComponents( 4 );
-    anImageData->AllocateScalars();
+    anImageData->AllocateScalars( VTK_UNSIGNED_CHAR, 4 );
 
     unsigned char* aDataPtr = (unsigned char*)anImageData->GetScalarPointer();
 
@@ -109,7 +107,6 @@ namespace VTK
       aDataPtr[ anId++ ] = aValue * aCoef;
       aDataPtr[ anId++ ] = aValue;
     }
-    anImageData->Update();
 
     return anImageData;
   }
@@ -123,17 +120,24 @@ namespace VTK
     theImageData->GetExtent( extent );
     int width = extent[1] - extent[0] + 1;
     int height = extent[3] - extent[2] + 1;
+
+    const int wmin = 20;
+    const int hmin = 20;
+
+    int xshift = width  < wmin ? (wmin-width)/2  : 0;
+    int yshift = height < hmin ? (hmin-height)/2 : 0;
   
-    QImage anImage(width, height, QImage::Format_ARGB32);
+    QImage anImage(width < wmin ? wmin : width, height < hmin ? hmin : height, QImage::Format_ARGB32);
+    anImage.fill(qRgba(255,255,255,0));
     for( int i = 0; i < height; i++ )
     {
-      QRgb* bits = reinterpret_cast<QRgb*>( anImage.scanLine(i) );
+      QRgb* bits = reinterpret_cast<QRgb*>( anImage.scanLine(i+yshift) );
       unsigned char* row = static_cast<unsigned char*>(
         theImageData->GetScalarPointer( extent[0], extent[2] + height - i - 1, extent[4] ) );
       for( int j = 0; j < width; j++ )
       {
         unsigned char* data = &row[ j*4 ];
-        bits[j] = qRgba( data[0], data[1], data[2], data[3] );
+        bits[j+xshift] = qRgba( data[0], data[1], data[2], data[3] );
       }
     }
     return anImage;