1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <Image_ColorImage.ixx>
21 #include <Image_ColorPixelDataMap.hxx>
22 #include <Image_DataMapIteratorOfColorPixelDataMap.hxx>
23 #include <TColStd_Array1OfInteger.hxx>
24 #include <Quantity_Array1OfColor.hxx>
25 #include <Aspect_ColorMapEntry.hxx>
28 static int Verbose = 0 ;
31 Image_ColorImage::Image_ColorImage (
32 const Standard_Integer x,
33 const Standard_Integer y,
34 const Standard_Integer dx,
35 const Standard_Integer dy)
36 : Image_DColorImage( x, y, dx, dy,
37 Aspect_ColorPixel( Quantity_Color(0.,0.,0.,Quantity_TOC_RGB)) )
42 Image_ColorImage::Image_ColorImage (
43 const Standard_Integer x,
44 const Standard_Integer y,
45 const Standard_Integer dx,
46 const Standard_Integer dy,
47 const Aspect_ColorPixel& BackPixel )
48 : Image_DColorImage( x, y, dx, dy, BackPixel )
53 Handle(Image_Image) Image_ColorImage::Dup() const {
55 Handle(Image_ColorImage) aImage =
56 new Image_ColorImage( LowerX(), LowerY(), Width(), Height(),
59 aImage->InternalDup( this ) ;
64 Image_TypeOfImage Image_ColorImage::Type () const {
66 return Image_TOI_ColorImage ;
70 const Quantity_Color& Image_ColorImage::PixelColor(
71 const Standard_Integer x,
72 const Standard_Integer y ) const
74 { return( Pixel( x, y ).Value() ) ;
77 Handle(Aspect_GenericColorMap) Image_ColorImage::ChooseColorMap(
78 const Standard_Integer aSize ) const
80 { Handle(Aspect_GenericColorMap) TheColorMap = new Aspect_GenericColorMap() ;
81 Standard_Integer x,y,i,bblcount, UpX, UpY ;
82 Image_ColorPixelDataMap DataMap( 4000 ) ; // a Big DataMap !!!
83 Aspect_ColorPixel pix ;
88 for ( y = LowerY() ; y <= UpY ; y++ ) {
89 for ( x = LowerX() ; x <= UpX ; x++ ) {
91 if ( !DataMap.IsBound( pix ) ) DataMap.Bind( pix, 1 ) ;
92 else DataMap( pix )++ ;
97 Standard_Integer CheckSum = 0 ;
100 cout << "ChooseColorMap : Extent " << DataMap.Extent() << endl << flush ;
103 Image_DataMapIteratorOfColorPixelDataMap It( DataMap ) ;
104 TColStd_Array1OfInteger Tab( 1, aSize ) ; Tab.Init(0) ;
105 Quantity_Array1OfColor Col( 1, aSize) ; Col.Init(
106 Quantity_Color( 0.,0.,0., Quantity_TOC_RGB ) ) ;
107 Standard_Integer MaxOfTab = 0 ;
108 Standard_Integer MinOfTab = 0 ;
110 while ( It.More() ) {
111 bblcount = It.Value() ;
115 cout << CheckSum << "," << It.Key() << "," << bblcount << endl ;
117 CheckSum += bblcount ;
121 if ( bblcount > MinOfTab ) {
122 for ( i = 1 ; i <= aSize ; i++ ) {
123 if ( Tab( i ) == MinOfTab ) {
124 Tab( i ) = bblcount ;
125 Col( i ) = It.Key().Value() ;
130 for ( i = 1 ; i <= aSize ; i++ ) {
131 MaxOfTab = Max( MaxOfTab, Tab( i ) ) ;
132 MinOfTab = Min( MinOfTab, Tab( i ) ) ;
140 Aspect_ColorMapEntry aEntry ;
142 for ( i = 1, bblcount = 0 ; i <= aSize ; i++ ) {
143 if ( Tab( i ) != 0 ) {
144 aEntry.SetValue( bblcount++, Col( i ) ) ;
145 TheColorMap->AddEntry( aEntry ) ;
155 Handle(Standard_Transient) Image_ColorImage::ShallowCopy() const {
159 Handle(Standard_Transient) Image_ColorImage::DeepCopy() const {