 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
34 if ( !
model )
return -1;
46 if ( i < comp->
id.integer() ) i = comp->
id.
integer();
48 for ( ncomp=0, comp =
model->
comp; comp; comp = comp->
next )
if ( comp->
sel ) {
50 if ( !comp_list ) comp_list = comp_new;
55 comp_new->
loc += vv * add_distance;
60 if ( comp ) comp->
next = comp_list;
63 cout <<
"Generated new shell" << endl;
64 cout <<
"New type: " << nutype << endl;
65 cout <<
"Distance added: " << add_distance <<
" A" << endl;
66 cout <<
"Components: " << ncomp << endl << endl;
87 if ( fraction < 1e-3 || fraction > 1 ) fraction = 1;
96 for ( n=0, gcomp = gmod->
comp; gcomp; gcomp = gcomp->
next, n++ )
102 cout <<
"Adjusting the model " <<
model->
id <<
" to the guide polyhedron " << gmod->
id << endl;
103 cout <<
"Fraction: " << fraction << endl;
104 cout <<
"Guide model center: " << center << endl << endl;
110 for ( gcomp = gmod->
comp; gcomp; gcomp = gcomp->
next )
116 if ( !
isfinite(d) ) cerr <<
"d not finite: " << d << endl;
141 if ( !
model )
return NULL;
145 if ( nutype.
length() < 1 ) nutype =
"VER";
148 cout <<
"Generating new shell models from components:" << endl;
150 cout <<
"New type: " << nutype << endl;
151 cout <<
"Distance between components: " <<
distance <<
" A" << endl;
152 if ( twod ) cout <<
"Generating plane models" << endl;
158 Bmodel* numod_list = NULL;
162 for ( comp = mp->
comp; comp; comp = comp->
next )
if ( comp->
sel ) {
168 numod->
id = mp->
id +
"_" + comp->
id;
180 cout <<
"New components: " << ncomp << endl << endl;
196 if ( !
model )
return 0;
200 double d, sph = 0, da = 0, ds = 0;
206 for ( ncomp=0, comp =
model->
comp; comp; comp = comp->
next, ncomp++ ) {
214 ds = ds/ncomp - da*da;
215 if ( ds > 0 ) sph = 1 - sqrt(ds)/da;
219 cout <<
"Sphericity: " << sph << endl << endl;
236 if ( !
model )
return 0;
244 for ( i=0; i<3; i++ ) axis[i].normalize();
250 for ( ncomp=0, comp =
model->
comp; comp; comp = comp->
next, ncomp++ ) {
252 for ( i=0; i<3; i++ ) c1[i] = c.
scalar(axis[i]);
258 ell = sqrt(1 - ell/ncomp);
261 cout <<
"Ellipsoidicity: " << ell << endl << endl;
288 cout <<
"Calculating curvature" << endl << endl;
291 cout <<
"Model\tAverage\tMaximum" << endl;
295 for ( comp = mp->
comp; comp; comp = comp->
next ) comp->
fom = 0;
296 for ( link = mp->
link; link; link = link->
next ) {
300 if ( amax < link->fom ) amax = link->
fom;
302 for ( ncomp=0, comp = mp->
comp; comp; comp = comp->
next, ncomp++ ) {
304 if ( i ) comp->
fom /= i;
307 if ( ncomp ) mp->
fom /= ncomp;
344 double testangle, d, angle[3] = {10,10,10};
353 for ( ib = 0, comp =
model->
comp; comp && ib < 3; comp = comp->next ) {
355 for ( i=ib=0; i<3; i++ )
if ( testangle < angle[i] ) {
356 testangle = angle[i];
360 if ( testangle < 1e-30 ) {
363 if ( angle[ib] > testangle ) {
364 angle[ib] = testangle;
365 tvec[ib] = comp->
vec;
369 for ( i=0; i<3; i++ ) {
370 for ( j=0; j<3; j++ )
371 mat[i][j] = tvec[j][i];
378 cerr <<
"Error in model_inside_outside_fast: vec=" << vec <<
" det=" << det << endl;
383 if ( w[0]<0 || w[1]<0 || w[2]<0 )
385 cerr <<
"Warning: Negative weights: " <<
386 w[0] <<
" " << w[1] <<
" " << w[2] <<
" " << vec << endl;
389 for ( i=0, d=0; i<3; i++ ) d += w[i];
392 if ( d )
for ( i=0; i<3; i++ ) w[i] /= d;
393 for ( i=0, d=0; i<3; i++ ) d += w[i] * tvec[i].
length();
406 double a, d, dmin = 1e30;
408 vector<double> w(3), wb(3,0);
418 cerr <<
"Vector not finite: " << vec <<
" length=" << vec_len << endl;
420 for ( ib = 0, a =
M_PI/16; ib < 3 && a <
M_PI + 0.1; a *= 2 ) {
422 tvec[0] = comp1->
vec;
423 if ( vec3.
angle(tvec[0]) < a ) {
424 for ( comp2 = comp1->
next; comp2; comp2 = comp2->
next ) {
425 tvec[1] = comp2->
vec;
426 if ( vec3.
angle(tvec[1]) < a ) {
427 for ( comp3 = comp2->
next; comp3; comp3 = comp3->
next ) {
428 tvec[2] = comp3->
vec;
429 if ( vec3.
angle(tvec[2]) < a ) {
430 for ( i=0; i<3; i++ ) {
432 for ( j=0; j<3; j++ )
433 mat[i][j] = tvec[j][i];
438 for ( i=iw=0; i<3; i++ )
if ( w[i] >= 0 ) iw++;
440 for ( i=0, d=0; i<3; i++ ) d += w[i];
444 for ( i=0; i<3; i++ ) {
462 cerr <<
"Warning: Non-finite weights: " << wb[0] <<
" " << wb[1] <<
" " << wb[2] << endl;
464 if ( wb[0]<0 || wb[1]<0 || wb[2]<0 )
465 cerr <<
"Warning: Negative weights: " << wb[0] <<
" " << wb[1] <<
" " << wb[2] << endl;
467 for ( i=0, d=0; i<3; i++ ) d += wb[i];
470 if ( d )
for ( i=0; i<3; i++ ) wb[i] /= d;
471 for ( i=0, d=0; i<3; i++ ) d += wb[i] * bvec[i].
length();
474 }
else cout <<
"Distance = " << d << endl;
477 cerr <<
"Weights and distance: " << wb[0] <<
" " << wb[1] <<
" " << wb[2] <<
" " << d << endl;
int check_for_singularity()
double model_ellipsoidicity(Bmodel *model)
Calculates how close the model is to an ellipsoid shape.
Vector3< double > model_principal_axes(Bmodel *model, Vector3< double > *eigenvec)
Calculates the principal axes of a model.
int model_component_count(Bmodel *model)
Counts the total number of components.
Bcomponent * component_add(Bcomponent **comp, Bstring &id)
Adds a component to a linked list.
Header file for functions for creating random images.
int model_adjust_shell_to_guide(Bmodel *model, Bmodel *gmod, double fraction, int curv_flag)
Adjusts a shell model to the faces of a polyhedral guide model.
Bmodel * model_create_circle(double radius, double z, double distance)
Creates a circle with the given radius, height, and component separation.
Vector3< double > model_center_of_mass(Bmodel *model)
double scalar(const Vector3 &v) const
double length(vector< T > v)
double singular_value_decomposition()
Singular value decomposition of a matrix .
long model_add_shell(Bmodel *model, double add_distance, Bstring &nutype)
Adds a shell to a model using selected components.
double model_inside_outside(Vector3< double > vec, Bmodel *model, int curv_flag, int fast)
Library routines used for model creation.
int model_color_uniformly(Bmodel *model, RGBA< float > color)
Colors model components uniformly.
Header file for reading and writing atomic model files.
Bmodel * model_components_to_shells(Bmodel *model, double distance, Bstring &nutype, int twod)
Generates a new set of models by vonverting each component to a shell model.
double LU_decomposition()
Matrix inversion by LU decomposition.
double model_inside_outside_fast(Vector3< double > vec, Bmodel *model, int curv_flag)
Determines if a vector is inside or outside model boundaries.
double distance(vector< T1 > &v1, vector< T2 > &v2)
Header file for general utilities.
ostream & tab(ostream &out)
bool isfinite(complex< T > &value)
double angle(Vector3< T2 > &v)
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Library routines used for model processing.
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
double model_sphericity(Bmodel *model)
Calculates how close the model is to a spherical shape.
int model_set_type(Bmodel *model, Bstring &set_type)
Reset the component types.
int component_copy(Bcomponent *fromcomp, Bcomponent *tocomp)
Copies all elements from one component to another.
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
int model_curvature(Bmodel *model)
Calculates the curvature associated with each link.
Bcomponent * link[MAXLINK]
Library routines used for shell model processing.
Functions to color models.
Bmodel * model_create_shell(long number, double radius, double distance)
Creates a sphere point model.