| Bsoft 2.0.5 Bernard's software package

model_color.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_poly.h"
11 #include "model_shell.h"
12 #include "model_views.h"
13 #include "model_util.h"
14 #include "Color.h"
15 #include "utilities.h"
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
29 int model_color_uniformly(Bmodel* model, RGBA<float> color)
30 {
31 Bmodel* m;
32 Bcomponent* comp;
33 Blink* link;
34
35 if ( verbose & VERB_PROCESS )
36 cout << "Coloring components uniformly: " << color[0] << " " <<
37 color[1] << " " << color[2] << " " << color[3] << endl << endl;
38
39 for ( m = model; m; m = m->next ) {
40 for ( comp = m->comp; comp; comp = comp->next )
41 comp->color = color;
42 for ( link = m->link; link; link = link->next )
43 link->color = color;
44 }
45
46 return 0;
47 }
48
55 int model_color_selected(Bmodel* model, RGBA<float> color)
56 {
57 Bmodel* m;
58 Bcomponent* comp;
59 Blink* link;
60
61 if ( verbose & VERB_PROCESS )
62 cout << "Coloring components by selection: " << color[0] << " " <<
63 color[1] << " " << color[2] << " " << color[3] << endl << endl;
64
65 for ( m = model; m; m = m->next ) if ( m->sel ) {
66 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel )
67 comp->color = color;
68 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
69 if ( link->comp[0]->sel && link->comp[1]->sel )
70 link->color = (link->comp[0]->color + link->comp[1]->color)/2;
71 }
72 }
73
74 return 0;
75 }
76
82 int model_color_by_order(Bmodel* model)
83 {
84 int i, ncomp;
85 Bmodel* m;
86 Bcomponent* comp;
87 Blink* link;
88
89 if ( verbose & VERB_PROCESS )
90 cout << "Coloring components by order" << endl << endl;
91
92 for ( m = model; m; m = m->next ) if ( m->sel ) {
93 for ( ncomp = 0, comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) ncomp++;
94 for ( i=0, comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
95 comp->color.spectrum(i, 0, ncomp);
96 comp->color[3] = 1;
97 i++;
98 }
99 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
100 link->color = (link->comp[0]->color + link->comp[1]->color)/2;
101 }
102 }
103
104 return 0;
105 }
106
118 int model_color_by_density(Bmodel* model)
119 {
120 double dmin = 1e30, dmax = -1e30;
121 Bmodel* m;
122 Bcomponent* comp;
123 Blink* link;
124
125 for ( m = model; m; m = m->next ) if ( m->sel ) {
126 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
127 if ( dmin > comp->density ) dmin = comp->density;
128 if ( dmax < comp->density ) dmax = comp->density;
129 }
130 }
131
132 if ( verbose & VERB_PROCESS )
133 cout << "Coloring components by density (" << dmin << " - " << dmax << ")" << endl << endl;
134
135 for ( m = model; m; m = m->next ) if ( m->sel ) {
136 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
137 comp->color.spectrum(comp->density, dmin, dmax);
138 comp->color[3] = 1;
139 }
140 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
141 link->color = (link->comp[0]->color + link->comp[1]->color)/2;
142 }
143 }
144
145 return 0;
146 }
147
159 int model_color_by_fom(Bmodel* model)
160 {
161 double fmin = 1e30, fmax = -1e30;
162 Bmodel* m;
163 Bcomponent* comp;
164 Blink* link;
165
166 for ( m = model; m; m = m->next ) if ( m->sel ) {
167 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
168 if ( fmin > comp->fom ) fmin = comp->fom;
169 if ( fmax < comp->fom ) fmax = comp->fom;
170 }
171 }
172
173 if ( verbose & VERB_PROCESS )
174 cout << "Coloring components by FOM (" << fmin << " - " << fmax << ")" << endl;
175
176 for ( m = model; m; m = m->next ) if ( m->sel ) {
177 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
178 comp->color.spectrum(comp->fom, fmin, fmax);
179 comp->color[3] = 1;
180 }
181 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
182 link->color = (link->comp[0]->color + link->comp[1]->color)/2;
183 }
184 }
185
186 return 0;
187 }
188
201 int model_color_selected_types(Bmodel* model, RGBA<float> rgba)
202 {
203 Bmodel* m;
204 Bcomponent* comp;
205 Blink* link;
206
207 if ( verbose & VERB_PROCESS )
208 cout << "Coloring selected component types" << endl << endl;
209
210 for ( m = model; m; m = m->next ) if ( m->sel ) {
211 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
212 if ( comp->type->sel )
213 comp->color = rgba;
214 }
215 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
216 link->color = (link->comp[0]->color + link->comp[1]->color)/2;
217 }
218 }
219
220 return 0;
221 }
222
228 int model_color_curvature(Bmodel* model)
229 {
230 Bmodel* m;
231 Bcomponent* comp;
232 Blink* link;
233
234 model_curvature(model);
235
236 if ( verbose & VERB_PROCESS )
237 cout << "Coloring based on curvature" << endl << endl;
238
239 for ( m = model; m; m = m->next ) if ( m->sel ) {
240 for ( link = m->link; link; link = link->next ) if ( link->sel ) {
241 link->color.spectrum(link->fom, 0, M_PI_4);
242 }
243 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
244 comp->color.spectrum(comp->fom, 0, M_PI_4);
245 }
246 }
247
248 return 0;
249 }
250
259 int model_color_chiral_vertices(Bmodel* model)
260 {
261 int h, n(0);
262 RGBA<float> red(1.0,0.0,0.0,1.0);
263 RGBA<float> blu(0.0,0.0,1.0,1.0);
264 Bmodel* m;
265 Bcomponent* comp;
266
267 model_extended_vertex_types(model);
268
269 if ( verbose & VERB_PROCESS )
270 cout << "Coloring based on chirality." << endl;
271
272 for ( m = model; m; m = m->next ) if ( m->sel ) {
273 for ( comp = m->comp; comp; comp = comp->next ) if ( comp->sel ) {
274 h = component_hand(comp->type->id);
275 if ( h > 0 ) comp->color = blu;
276 else if ( h < 0 ) comp->color = red;
277 if ( h ) n++;
278 }
279 }
280
281 if ( verbose )
282 cout << "Number of chiral vertices: " << n << endl << endl;
283
284 return n;
285 }
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
Blink
Definition: rwmodel.h:82
model_views.h
Library routines used for analysing model component views.
utilities.h
Header file for general utilities.
Blink::color
RGBA< float > color
Definition: rwmodel.h:88
model_util.h
Library routines used for model processing.
model_shell.h
Library routines used for shell model processing.
model_color_by_fom
int model_color_by_fom(Bmodel *model)
Colors model components by fom.
Definition: model_color.cpp:159
component_hand
int component_hand(Bstring &s)
Determines the hand of a component.
Definition: model_views.cpp:466
RGBA< float >
Blink::sel
int sel
Definition: rwmodel.h:90
model_extended_vertex_types
int model_extended_vertex_types(Bmodel *model)
Determines the vertex type based on adjacent and opposed polygons.
Definition: model_poly.cpp:396
Bmodel::sel
int sel
Definition: rwmodel.h:129
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
model_curvature
int model_curvature(Bmodel *model)
Calculates the curvature associated with each link.
Definition: model_shell.cpp:279
Bcomptype::sel
int sel
Definition: rwmodel.h:34
Blink::comp
Bcomponent * comp[2]
Definition: rwmodel.h:84
M_PI_4
#define M_PI_4
Definition: utilities.h:65
Blink::next
Blink * next
Definition: rwmodel.h:83
Bcomponent::fom
float fom
Definition: rwmodel.h:65
model_color_selected
int model_color_selected(Bmodel *model, RGBA< float > color)
Colors selected model components.
Definition: model_color.cpp:55
model_color_uniformly
int model_color_uniformly(Bmodel *model, RGBA< float > color)
Colors model components uniformly.
Definition: model_color.cpp:29
Bcomponent::density
float density
Definition: rwmodel.h:64
RGBA::spectrum
void spectrum(double value, double cmin, double cmax)
Definition: Color.h:221
model_color_curvature
int model_color_curvature(Bmodel *model)
Colors model vertices and links as a function of curvature.
Definition: model_color.cpp:228
model_color_chiral_vertices
int model_color_chiral_vertices(Bmodel *model)
Colors model vertices as a function of chirality.
Definition: model_color.cpp:259
model_poly.h
Functions to manipulate polyhedral coordinate files.
model_color_by_density
int model_color_by_density(Bmodel *model)
Colors model components by density.
Definition: model_color.cpp:118
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
Bcomponent::sel
int sel
Definition: rwmodel.h:66
model
Bmodel * model
Definition: bshow.cpp:32
verbose
int verbose
model_color_by_order
int model_color_by_order(Bmodel *model)
Colors model components in order from red to blue.
Definition: model_color.cpp:82
Bmodel::link
Blink * link
Definition: rwmodel.h:133
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
rwmodel.h
Header file for reading and writing atomic model files.
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
Color.h
Classes for color objects.
Bmodel
Definition: rwmodel.h:119
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
model_color_selected_types
int model_color_selected_types(Bmodel *model, RGBA< float > rgba)
Colors model components by fom.
Definition: model_color.cpp:201
Blink::fom
float fom
Definition: rwmodel.h:89
Bcomponent::color
RGBA< float > color
Definition: rwmodel.h:63
Bcomponent
Definition: rwmodel.h:51