anatomist  5.0.5
3D neuroimaging data viewer
objectPalette.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANA_COLOR_OBJECTPALETTE_H
36 #define ANA_COLOR_OBJECTPALETTE_H
37 
39 #include <aims/data/data.h>
40 #include <aims/rgb/rgb.h>
42 
43 class QImage;
44 
45 namespace anatomist
46 {
47 
49  {
50  public:
52  {
55  };
56 
57  typedef AimsRGBA (*MixMethod)( const AimsData<AimsRGBA> & map1,
58  const AimsData<AimsRGBA> *map2,
59  unsigned x, unsigned y,
60  const AObjectPalette & pal );
61 
63  AObjectPalette( const AObjectPalette & x );
64  virtual ~AObjectPalette();
65 
66  virtual AObjectPalette* clone() const;
67 
68  virtual AObjectPalette & operator = ( const AObjectPalette & x );
69 
73  { if( _refPal != pal ) { clearColors(); _refPal = pal; } }
75  const AimsData<AimsRGBA>* colors() const
76  { if( !_colors ) const_cast<AObjectPalette *>(this)->fill();
77  return _colors; }
78  AimsData<AimsRGBA>* colors() { if( !_colors ) fill(); return _colors; }
79  void create( unsigned dimx, unsigned dimy = 1, unsigned dimz = 1,
80  unsigned dimt = 1 );
81  virtual void fill();
82  float min1() const { return( _min ); }
83  float max1() const { return( _max ); }
84  float min2() const { return( _min2 ); }
85  float max2() const { return( _max2 ); }
86  int palette1DMapping() const { return (_palette1DMapping) ; }
87  std::string palette1DMappingName() const
88  { return (_palette1DMapping == 1 ? "Diagonal" : "FirstLine" ) ; }
89  void setMin1( float x ) { _min = x; }
90  void setMax1( float x ) { _max = x; }
91  void setMin2( float x ) { _min2 = x; }
92  void setMax2( float x ) { _max2 = x; }
96  { _palette1DMapping = ( palette1DMappingName == "FirstLine" ?
97  FIRSTLINE : DIAGONAL ) ; }
98  std::string mixMethodName() const { return( _mixMethodName ); }
99  void setMixMethod( const std::string & name );
100  float linearMixFactor() const { return( _linMixFactor ); }
101  void setLinearMixFactor( float x ) { _linMixFactor = x; }
102  bool is2dMode() const { return _mode2d; }
103  void set2dMode( bool x ) { _mode2d = x; }
104  bool isTransparent() const { return _transp; }
105  AimsRGBA normColor( float x, float y = 0 ) const;
106  AimsRGBA normColor( const Point2df & pos ) const;
107  bool zeroCenteredAxis1() const { return _zeroCentered1; }
108  bool zeroCenteredAxis2() const { return _zeroCentered2; }
109  void setZeroCenteredAxis1( bool x ) { _zeroCentered1 = x; }
110  void setZeroCenteredAxis2( bool x ) { _zeroCentered2 = x; }
111 
112  static AimsRGBA palette2DMixMethod( const AimsData<AimsRGBA> & map1,
113  const AimsData<AimsRGBA> *map2,
114  unsigned x, unsigned y,
115  const AObjectPalette & pal );
116  static AimsRGBA linearMixMethod( const AimsData<AimsRGBA> & map1,
117  const AimsData<AimsRGBA> *map2,
118  unsigned x, unsigned y,
119  const AObjectPalette & pal );
120  static AimsRGBA geometricMixMethod( const AimsData<AimsRGBA> & map1,
121  const AimsData<AimsRGBA> *map2,
122  unsigned x, unsigned y,
123  const AObjectPalette & pal );
124  bool set( const carto::GenericObject & );
131  int maxSizeX() const { return _maxSizeX; }
132  int maxSizeY() const { return _maxSizeY; }
133  void setMaxSize( int maxsizex, int maxsizey );
139  int glMaxSizeX() const { return _glMaxSizeX; }
140  int glMaxSizeY() const { return _glMaxSizeY; }
141  void glSetMaxSize( int glmaxsizex, int glmaxsizey );
142  void clearColors();
144  void copyColors( const AObjectPalette & pal );
146  void copyOrFillColors( const AObjectPalette & pal );
147 
148  static std::map<std::string, MixMethod> mixMethods;
149  QImage* toQImage( int w = 0, int h = 0 ) const;
150 
151  protected:
152  static std::map<std::string, MixMethod> defaultMixMethods();
153 
156  float _min;
157  float _max;
159  float _min2;
160  float _max2;
162  std::string _mixMethodName;
165  bool _mode2d;
166  bool _transp;
173  };
174 
175 }
176 
177 
178 #endif
std::string mixMethodName() const
Definition: objectPalette.h:98
bool zeroCenteredAxis1() const
AimsData< AimsRGBA > * colors()
Definition: objectPalette.h:78
carto::rc_ptr< APalette > _refPal2
void setMixMethod(const std::string &name)
int maxSizeX() const
Maximum size of the internal palette image.
QImage * toQImage(int w=0, int h=0) const
void setPalette1DMapping(Palette1DMapping palette1DMapping)
Definition: objectPalette.h:93
const AimsData< AimsRGBA > * colors() const
Definition: objectPalette.h:75
void setLinearMixFactor(float x)
void setMaxSize(int maxsizex, int maxsizey)
static AimsRGBA linearMixMethod(const AimsData< AimsRGBA > &map1, const AimsData< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
void setRefPalette(carto::rc_ptr< APalette > pal)
Definition: objectPalette.h:72
void setPalette1DMappingName(std::string palette1DMappingName)
Definition: objectPalette.h:95
float linearMixFactor() const
void setRefPalette2(carto::rc_ptr< APalette > pal)
Definition: objectPalette.h:74
AObjectPalette(carto::rc_ptr< APalette > pal)
carto::rc_ptr< APalette > refPalette2() const
Definition: objectPalette.h:71
virtual AObjectPalette * clone() const
void create(unsigned dimx, unsigned dimy=1, unsigned dimz=1, unsigned dimt=1)
void setZeroCenteredAxis2(bool x)
static AimsRGBA geometricMixMethod(const AimsData< AimsRGBA > &map1, const AimsData< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
Palette1DMapping _palette1DMapping
AimsRGBA(* MixMethod)(const AimsData< AimsRGBA > &map1, const AimsData< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
Definition: objectPalette.h:57
AimsRGBA normColor(float x, float y=0) const
void copyOrFillColors(const AObjectPalette &pal)
if pal colors size is compatible, just copy it; otherwise call fill()
void setZeroCenteredAxis1(bool x)
carto::rc_ptr< APalette > refPalette() const
Definition: objectPalette.h:70
carto::Object genericDescription() const
carto::rc_ptr< APalette > _refPal
AimsData< AimsRGBA > * _colors
int glMaxSizeX() const
Maximum size of the OpenGL palette image, after scaling.
bool zeroCenteredAxis2() const
void glSetMaxSize(int glmaxsizex, int glmaxsizey)
static std::map< std::string, MixMethod > defaultMixMethods()
static std::map< std::string, MixMethod > mixMethods
static AimsRGBA palette2DMixMethod(const AimsData< AimsRGBA > &map1, const AimsData< AimsRGBA > *map2, unsigned x, unsigned y, const AObjectPalette &pal)
std::string palette1DMappingName() const
Definition: objectPalette.h:87
virtual AObjectPalette & operator=(const AObjectPalette &x)
void copyColors(const AObjectPalette &pal)
if pal colors size is compatible, just copy it