Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:53

0001 // Copyright (c) 2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _SelectMgr_SelectionImageFiller_HeaderFile
0015 #define _SelectMgr_SelectionImageFiller_HeaderFile
0016 
0017 #include <Image_PixMap.hxx>
0018 #include <math_BullardGenerator.hxx>
0019 #include <NCollection_Map.hxx>
0020 #include <StdSelect_TypeOfSelectionImage.hxx>
0021 
0022 class SelectMgr_ViewerSelector;
0023 
0024 //! Abstract class for filling pixel with color.
0025 //! This is internal tool for SelectMgr_ViewerSelector::ToPixMap().
0026 class SelectMgr_SelectionImageFiller : public Standard_Transient
0027 {
0028 public:
0029   //! Create filler of specified type.
0030   static Handle(SelectMgr_SelectionImageFiller) CreateFiller (Image_PixMap& thePixMap,
0031                                                               SelectMgr_ViewerSelector* theSelector,
0032                                                               StdSelect_TypeOfSelectionImage theType);
0033 
0034 public:
0035 
0036   //! Main constructor.
0037   SelectMgr_SelectionImageFiller (Image_PixMap& thePixMap,
0038                                   SelectMgr_ViewerSelector* theSelector)
0039   : myImage  (&thePixMap),
0040     myMainSel(theSelector) {}
0041 
0042   //! Fill pixel at specified position.
0043   virtual void Fill (const Standard_Integer theCol,
0044                      const Standard_Integer theRow,
0045                      const Standard_Integer thePicked) = 0;
0046 
0047   //! Flush results into final image.
0048   virtual void Flush() {}
0049 
0050 protected:
0051 
0052   //! Find the new unique random color.
0053   void randomPastelColor (Quantity_Color& theColor)
0054   {
0055     for (;;)
0056     {
0057       nextRandomPastelColor (theColor);
0058       if (myUniqueColors.Add (theColor))
0059       {
0060         return;
0061       }
0062     }
0063   }
0064 
0065   //! Fills the given color as random.
0066   void nextRandomPastelColor (Quantity_Color& theColor)
0067   {
0068     theColor = Quantity_Color (Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
0069                                Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
0070                                Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
0071                                Quantity_TOC_sRGB);
0072   }
0073 
0074 protected:
0075   Image_PixMap*             myImage;
0076   SelectMgr_ViewerSelector* myMainSel;
0077   math_BullardGenerator     myBullardGenerator;
0078   NCollection_Map<Quantity_Color> myUniqueColors;
0079 };
0080 
0081 #endif