gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
colourWheel.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef COLOURWHEEL_H_
18 #define COLOURWHEEL_H_
19 
20 #include <iostream>
21 #include <gtk/gtk.h>
22 #include "../3daudio/SDevices.H"
23 
24 //5/8 corresponds to -1,-1,0
25 #define MAXANGLE (5.0/8.0)*2.0*M_PI
26 //tan(-1/-1) corresponds to -1,-1,0
27 //#define MAXANGLE 1.557407725*2.0*M_PI
28 //#define MAXANGLE 2.0*M_PI-3.0/4.0*M_PI
29 #define DIFFUSIVITY 1.0
30 
31 class ColourWheel {
32  void allocColours(void){
33  // Use a 2D speaker panner to derive colours ....
34  // Set up your speakers ...
35  spk.add(1.0, 0.0, 0.0); // RED
36  spk.add(0.0, 1.0, 0.0); // GREEN
37  spk.add(-1.0,-1.0,0.0); // BLUE
38 
39  // Set up a source to scan the colour wheel
40  src.add(1.0, 0.0, 0.0);
41  src.current()->setSharpness(DIFFUSIVITY);
42 
43  // Add relevant sources to the speakers sources cluster ...
44  srcId=spk.addSources(&src);
45 
46  // Fill the colour map
47  // GdkColor tempC;
48  for (double i=0.0; i<MAXANGLE; i+=factor){
49  loc testLoc(-1.0, 0.0, 0.0), tempLoc;
50  tempLoc=testLoc.findVectorFromAngle(i);
51  *src.current()=source(tempLoc.x, tempLoc.y, tempLoc.z);
52  colourAlloc();
53  }
54  // std::cout<<"ColourMap size "<<rainbow->size<<std::endl;
55  }
56 
57  void colourAlloc(){
58  spk.activateNorm();
59  colour.red =(gushort)rint(spk.activations.current()[0]*65535.0);
60  colour.green=(gushort)rint(spk.activations.current()[1]*65535.0);
61  colour.blue =(gushort)rint(spk.activations.current()[2]*65535.0);
62  int res=gdk_colormap_alloc_color(rainbow, &colour, TRUE, FALSE);
63  if (res!=TRUE){
64  std::cerr<<"ColourWheel:: Colour map colour alloc Failed"<<std::endl;
65  exit(-1);
66  }
67  }
68 
69  speakers spk; // Colour plane in X-Y
70  sources src;
72  static double factor;
73 
74 public:
75  GdkColor colour; // Colour returned in colourFromHeight
76  GdkColormap *rainbow;
77 
78  ColourWheel(void){
79  //std::cout<<gdk_colormap_get_system_size()<<std::endl;
80  rainbow=gdk_colormap_new(gdk_visual_get_best_with_type(GDK_VISUAL_TRUE_COLOR), TRUE);
81  // rainbow=gdk_colormap_new(gdk_visual_get_best(), TRUE);
82  allocColours();
83 
84  //Mask sure black is there too ...
85  colour.red =(gushort)rint(0.0);
86  colour.green=(gushort)rint(0.0);
87  colour.blue =(gushort)rint(0.0);
88  int res=gdk_colormap_alloc_color(rainbow, &colour, TRUE, FALSE);
89  if (res!=TRUE){
90  std::cerr<<"ColourWheel:: Colour map black colour alloc Failed"<<std::endl;
91  exit(-1);
92  }
93  }
94 
95  ~ColourWheel(void){
96  spk.remSources(srcId); //Clean up
97  gdk_colormap_unref(rainbow);
98  }
99 
100  GdkColor* colourFromHeight(double height, double maxHeight){
101  double angle=-MAXANGLE*height/maxHeight;
102  //std::cout<<" angle "<<angle<<'\n';
103  loc testLoc(-1.0, -1.0, 0.0), tempLoc;
104  tempLoc=testLoc.findVectorFromAngle(angle);
105  // std::cout<<tempLoc<<'\t';
106  *src.current()=source(tempLoc.x, tempLoc.y, tempLoc.z);
107  colourAlloc();
108  //std::cout<<'\t'<<colour.red<<'\t'<<colour.green<<'\t'<<colour.blue<<std::endl;
109  return &colour;
110  }
111 
112  GdkColor* black(){
113  //Mask sure black is there too ...
114  colour.red =(gushort)rint(0.0);
115  colour.green=(gushort)rint(0.0);
116  colour.blue =(gushort)rint(0.0);
117  int res=gdk_colormap_alloc_color(rainbow, &colour, TRUE, FALSE);
118  if (res!=TRUE){
119  std::cerr<<"ColourWheel:: Colour map black colour alloc Failed"<<std::endl;
120  exit(-1);
121  }
122  return &colour;
123  }
124 
125  GdkColor* white(){
126  //Mask sure black is there too ...
127  colour.red =(gushort)rint(65535.0);
128  colour.green=(gushort)rint(65535.0);
129  colour.blue =(gushort)rint(65535.0);
130  int res=gdk_colormap_alloc_color(rainbow, &colour, TRUE, FALSE);
131  if (res!=TRUE){
132  std::cerr<<"ColourWheel:: Colour map white colour alloc Failed"<<std::endl;
133  exit(-1);
134  }
135  return &colour;
136  }
137 };
138 double ColourWheel::factor=MAXANGLE/65535.0;
139 #endif //COLOURWHEEL_H_
140 
141 
142 
143 
144 
145 
GdkColor colour
Definition: colourWheel.H:75
GdkColormap * rainbow
Definition: colourWheel.H:76
~ColourWheel(void)
Definition: colourWheel.H:95
double rint(double)
sources src
Definition: colourWheel.H:70
GdkColor * white()
Definition: colourWheel.H:125
void allocColours(void)
Definition: colourWheel.H:32
unsigned int uint
Definition: Box.H:28
GdkColor * colourFromHeight(double height, double maxHeight)
Definition: colourWheel.H:100
ColourWheel(void)
Definition: colourWheel.H:78
static double factor
Definition: colourWheel.H:72
#define MAXANGLE
Definition: colourWheel.H:25
#define DIFFUSIVITY
Definition: colourWheel.H:29
GdkColor * black()
Definition: colourWheel.H:112
void colourAlloc()
Definition: colourWheel.H:57
speakers spk
Definition: colourWheel.H:69
gtkIOStream: /tmp/gtkiostream/include/colourWheel.H Source File
GTK+ IOStream  Beta