-
Notifications
You must be signed in to change notification settings - Fork 9
/
colormapper.cpp
executable file
·144 lines (116 loc) · 3.6 KB
/
colormapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
*
* 2014
* Author: Giulia Picciau - DIBRIS, Università degli studi di Genova
* Supervisors: Leila De Floriani - DIBRIS, Università degli studi di Genova
* Patricio Simari - Department of Electrical Engineering and Computer Science, The Catholic University of America
*
* Title: Fast and scalable mesh superfacets
* Submission to Pacific Graphics 2014
*
*
**/
#include "colormapper.h"
ColorMapper::ColorMapper()
{
}
/**
* @brief ColorMapper::ColorMapper creates a subdivision of the hsv cone depending on the number of segments
* @param totalC: number of segments in which the mesh is divided
*/
ColorMapper::ColorMapper(int num){
numColors=num;
saturation=1.0;
value=1.0;
stepHue=360.0/numColors;
}
ColorMapper::ColorMapper(float max, int count){
numColors=count;
saturation=1.0;
value=1.0;
stepHue=360.0/numColors;
}
/**
* @brief ColorMapper::setRed assigns a value for the red channel
* @param region: the index of the segment to which the triangle belongs
*/
void ColorMapper::setRed(int region){
hue=region*stepHue;
//std::cout<<"Hue "<<hue<<" reg "<<region<<std::endl;
float hueSixty=hue/60.0;
float X =(1.0-fabs(fmod(hueSixty,2.0)-1.0));
if((hueSixty >=0.0 && hueSixty < 1.0) || (hueSixty >= 5.0 && hueSixty <6.0))
red=saturation*value;
else if((hueSixty >= 1.0 && hueSixty < 2.0) || (hueSixty >= 4.0 && hueSixty <5.0)){
red=X;
}
else{
red=0.0;
}
}
void ColorMapper::setRed(float value){
hue=value*stepHue;
//std::cout<<"Hue "<<hue<<" reg "<<region<<std::endl;
float hueSixty=hue/60.0;
float X =(1.0-fabs(fmod(hueSixty,2.0)-1.0));
if((hueSixty >=0.0 && hueSixty < 1.0) || (hueSixty >= 5.0 && hueSixty <6.0))
red=saturation*value;
else if((hueSixty >= 1.0 && hueSixty < 2.0) || (hueSixty >= 4.0 && hueSixty <5.0)){
red=X;
}
else{
red=0.0;
}
}
/**
* @brief ColorMapper::setGreen assigns a value for the green channel
* @param region: the index of the segment to which the triangle belongs
*/
void ColorMapper::setGreen(int region){
hue=region*stepHue;
float hueSixty=hue/60.0;
float X=(saturation*value) * (1.0-fabs(fmod(hueSixty,2.0)-1.0));
if((hueSixty>=0.0 && hueSixty < 1.0) || (hueSixty >=3.0 && hueSixty < 4.0))
green=X;
else if(hueSixty >= 1.0 && hueSixty < 3.0)
green=saturation*value;
else
green=0.0;
}
void ColorMapper::setGreen(float region){
hue=region*stepHue;
float hueSixty=hue/60.0;
float X=(saturation*value) * (1.0-fabs(fmod(hueSixty,2.0)-1.0));
if((hueSixty>=0.0 && hueSixty < 1.0) || (hueSixty >=3.0 && hueSixty < 4.0))
green=X;
else if(hueSixty >= 1.0 && hueSixty < 3.0)
green=saturation*value;
else
green=0.0;
}
/**
* @brief ColorMapper::setBlue assigns a value for the blue channel
* @param region: the index of the segment to which the triangle belongs
*/
void ColorMapper::setBlue(int region){
hue=region*stepHue;
float hueSixty=hue/60.0;
float X=(saturation*value) * (1.0-fabs(fmod(hueSixty,2.0)-1.0));
if(hueSixty >= 0.0 && hueSixty < 2.0)
blue=0.0;
else if(hueSixty >= 3.0 && hueSixty < 5.0)
blue=saturation*value;
else
blue=X;
}
void ColorMapper::setBlue(float region){
hue=region*stepHue;
float hueSixty=hue/60.0;
float X=(saturation*value) * (1.0-fabs(fmod(hueSixty,2.0)-1.0));
if(hueSixty >= 0.0 && hueSixty < 2.0)
blue=0.0;
else if(hueSixty >= 3.0 && hueSixty < 5.0)
blue=saturation*value;
else
blue=X;
}