0031458: Visualization - refine classes across Prs3d and StdPrs packages
[occt.git] / src / SelectMgr / SelectMgr_SelectionImageFiller.hxx
1 // Copyright (c) 2020 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _SelectMgr_SelectionImageFiller_HeaderFile
15 #define _SelectMgr_SelectionImageFiller_HeaderFile
16
17 #include <Image_PixMap.hxx>
18 #include <math_BullardGenerator.hxx>
19 #include <NCollection_Map.hxx>
20 #include <StdSelect_TypeOfSelectionImage.hxx>
21 #include <Quantity_ColorHasher.hxx>
22
23 class SelectMgr_ViewerSelector;
24
25 //! Abstract class for filling pixel with color.
26 //! This is internal tool for SelectMgr_ViewerSelector3d::ToPixMap().
27 class SelectMgr_SelectionImageFiller : public Standard_Transient
28 {
29 public:
30   //! Create filler of specified type.
31   static Handle(SelectMgr_SelectionImageFiller) CreateFiller (Image_PixMap& thePixMap,
32                                                               SelectMgr_ViewerSelector* theSelector,
33                                                               StdSelect_TypeOfSelectionImage theType);
34
35 public:
36
37   //! Main constructor.
38   SelectMgr_SelectionImageFiller (Image_PixMap& thePixMap,
39                                   SelectMgr_ViewerSelector* theSelector)
40   : myImage  (&thePixMap),
41     myMainSel(theSelector) {}
42
43   //! Fill pixel at specified position.
44   virtual void Fill (const Standard_Integer theCol,
45                      const Standard_Integer theRow,
46                      const Standard_Integer thePicked) = 0;
47
48   //! Flush results into final image.
49   virtual void Flush() {}
50
51 protected:
52
53   //! Find the new unique random color.
54   void randomPastelColor (Quantity_Color& theColor)
55   {
56     for (;;)
57     {
58       nextRandomPastelColor (theColor);
59       if (myUniqueColors.Add (theColor))
60       {
61         return;
62       }
63     }
64   }
65
66   //! Fills the given color as random.
67   void nextRandomPastelColor (Quantity_Color& theColor)
68   {
69     theColor = Quantity_Color (Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
70                                Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
71                                Standard_Real(myBullardGenerator.NextInt() % 256) / 255.0,
72                                Quantity_TOC_sRGB);
73   }
74
75 protected:
76   Image_PixMap*             myImage;
77   SelectMgr_ViewerSelector* myMainSel;
78   math_BullardGenerator     myBullardGenerator;
79   NCollection_Map<Quantity_Color, Quantity_ColorHasher> myUniqueColors;
80 };
81
82 #endif