]> OCCT Git - occt.git/commitdiff
0032118: Visualization, Graphic3d_MarkerImage::StandardMarker() - return marker with...
authorkgv <kgv@opencascade.com>
Fri, 5 Feb 2021 17:40:26 +0000 (20:40 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 10 Feb 2021 17:42:57 +0000 (20:42 +0300)
src/Graphic3d/Graphic3d_MarkerImage.cxx
src/Graphic3d/Graphic3d_MarkerImage.hxx

index b56ff81b6266c3e4530939ce93b4bfe38a389ed8..e78aa460ff5a23e0c0988c9dcc0c09880742dcdd 100755 (executable)
@@ -27,6 +27,24 @@ namespace
 {
   static volatile Standard_Integer THE_MARKER_IMAGE_COUNTER = 0;
 
+  //! Names of built-in markers
+  static const char* THE_MARKER_NAMES[Aspect_TOM_USERDEFINED] =
+  {
+    ".",     // Aspect_TOM_POINT
+    "+",     // Aspect_TOM_PLUS
+    "*",     // Aspect_TOM_STAR
+    "x",     // Aspect_TOM_X
+    "o",     // Aspect_TOM_O
+    "o.",    // Aspect_TOM_O_POINT
+    "o+",    // Aspect_TOM_O_PLUS
+    "o*",    // Aspect_TOM_O_STAR
+    "ox",    // Aspect_TOM_O_X
+    "ring1", // Aspect_TOM_RING1
+    "ring2", // Aspect_TOM_RING2
+    "ring3", // Aspect_TOM_RING3
+    "ball"   // Aspect_TOM_BALL
+  };
+
   //! Returns a parameters for the marker of the specified type and scale.
   static void getMarkerBitMapParam (const Aspect_TypeOfMarker theMarkerType,
                                     const Standard_ShortReal theScale,
@@ -184,6 +202,37 @@ Graphic3d_MarkerImage::Graphic3d_MarkerImage (const Handle(Image_PixMap)& theIma
   }
 }
 
+// =======================================================================
+// function : Graphic3d_MarkerImage
+// purpose  :
+// =======================================================================
+Graphic3d_MarkerImage::Graphic3d_MarkerImage (const TCollection_AsciiString& theId,
+                                              const TCollection_AsciiString& theAlphaId,
+                                              const Handle(Image_PixMap)& theImage,
+                                              const Handle(Image_PixMap)& theImageAlpha)
+: myImageId (theId),
+  myImageAlphaId (theAlphaId),
+  myImage  (theImage),
+  myImageAlpha (theImageAlpha),
+  myMargin (1),
+  myWidth  ((Standard_Integer )theImage->Width()),
+  myHeight ((Standard_Integer )theImage->Height())
+{
+  if (!theImageAlpha.IsNull())
+  {
+    if (theImageAlpha->Format() != Image_Format_Alpha
+     && theImageAlpha->Format() != Image_Format_Gray)
+    {
+      throw Standard_ProgramError ("Graphic3d_MarkerImage, wrong color format of alpha image");
+    }
+    if (theImageAlpha->SizeX() != theImage->SizeX()
+     || theImageAlpha->SizeY() != theImage->SizeY())
+    {
+      throw Standard_ProgramError ("Graphic3d_MarkerImage, wrong dimensions of alpha image");
+    }
+  }
+}
+
 // =======================================================================
 // function : Graphic3d_MarkerImage
 // purpose  :
@@ -369,6 +418,29 @@ Handle(Graphic3d_MarkerImage) Graphic3d_MarkerImage::StandardMarker (const Aspec
                                                                      const Standard_ShortReal theScale,
                                                                      const Graphic3d_Vec4& theColor)
 {
+  if (theMarkerType == Aspect_TOM_USERDEFINED
+   || theMarkerType == Aspect_TOM_EMPTY)
+  {
+    return Handle(Graphic3d_MarkerImage)();
+  }
+
+  // predefined markers are defined with 0.5 step
+  const Standard_Integer aScaleInt = Standard_Integer(theScale * 10.0f + 0.5f);
+  TCollection_AsciiString aKey  = TCollection_AsciiString ("Graphic3d_MarkerImage_")      + THE_MARKER_NAMES[theMarkerType] + "_" + aScaleInt;
+  TCollection_AsciiString aKeyA = TCollection_AsciiString ("Graphic3d_MarkerImageAlpha_") + THE_MARKER_NAMES[theMarkerType] + "_" + aScaleInt;
+  if (theMarkerType == Aspect_TOM_BALL)
+  {
+    unsigned int aColor[3] =
+    {
+      (unsigned int )(255.0f * theColor.r()),
+      (unsigned int )(255.0f * theColor.g()),
+      (unsigned int )(255.0f * theColor.b())
+    };
+    char aBytes[8];
+    sprintf (aBytes, "%02X%02X%02X", aColor[0], aColor[1], aColor[2]);
+    aKey += aBytes;
+  }
+
   switch (theMarkerType)
   {
     case Aspect_TOM_O_POINT:
@@ -392,7 +464,7 @@ Handle(Graphic3d_MarkerImage) Graphic3d_MarkerImage::StandardMarker (const Aspec
         aMarkerImage2 = getTextureImage (Aspect_TypeOfMarker(theMarkerType - Aspect_TOM_O_POINT), theScale);
       }
       Handle(Image_PixMap) anImage = mergeImages (aMarkerImage1->GetImage(), aMarkerImage2->GetImage());
-      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (anImage);
+      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (aKey, aKey, anImage);
       return aNewMarkerImage;
     }
     case Aspect_TOM_RING1:
@@ -420,7 +492,7 @@ Handle(Graphic3d_MarkerImage) Graphic3d_MarkerImage::StandardMarker (const Aspec
       {
         anImage = mergeImages (anImage, getTextureImage (Aspect_TOM_O, aScale)->GetImage());
       }
-      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (anImage);
+      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (aKey, aKey, anImage);
       return aNewMarkerImage;
     }
     case Aspect_TOM_BALL:
@@ -470,12 +542,15 @@ Handle(Graphic3d_MarkerImage) Graphic3d_MarkerImage::StandardMarker (const Aspec
         }
         aScale -= aDelta;
       }
-      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (anImage, anImageA);
+      Handle(Graphic3d_MarkerImage) aNewMarkerImage = new Graphic3d_MarkerImage (aKey, aKeyA, anImage, anImageA);
       return aNewMarkerImage;
     }
     default:
     {
-      return getTextureImage (theMarkerType, theScale);
+      Handle(Graphic3d_MarkerImage) aNewMarkerImage = getTextureImage (theMarkerType, theScale);
+      aNewMarkerImage->myImageId = aKey;
+      aNewMarkerImage->myImageAlphaId = aKey;
+      return aNewMarkerImage;
     }
   }
 }
index c492ecd06b656cfcee2f2dc24b73403a93a76521..eb69696618b4a64232d3297d491cd8faceef574e 100755 (executable)
@@ -85,6 +85,14 @@ public:
   Standard_EXPORT Handle(TColStd_HArray1OfByte) GetBitMapArray (const Standard_Real theAlphaValue = 0.5,
                                                                 const Standard_Boolean theIsTopDown = false) const;
 
+protected:
+
+  //! Constructor from existing pixmap with predefined ids.
+  Standard_EXPORT Graphic3d_MarkerImage (const TCollection_AsciiString& theId,
+                                         const TCollection_AsciiString& theAlphaId,
+                                         const Handle(Image_PixMap)& theImage,
+                                         const Handle(Image_PixMap)& theImageAlpha = Handle(Image_PixMap)());
+
 private:
 
   TCollection_AsciiString       myImageId;      //!< resource identifier