Util.cpp (pymol-v2.1.0.tar.bz2) | : | Util.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 77 | skipping to change at line 77 | |||
double UtilGetSeconds(PyMOLGlobals *G) | double UtilGetSeconds(PyMOLGlobals *G) | |||
{ | { | |||
#ifndef _WIN32 | #ifndef _WIN32 | |||
/* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ | /* BEGIN PROPRIETARY CODE SEGMENT (see disclaimer in "os_proprietary.h") */ | |||
struct timeval tv; | struct timeval tv; | |||
gettimeofday(&tv,NULL); | gettimeofday(&tv,NULL); | |||
return((tv.tv_sec+(tv.tv_usec/((double)1000000.0)))-G->Util->StartSec); | return((tv.tv_sec+(tv.tv_usec/((double)1000000.0)))-G->Util->StartSec); | |||
/* END PROPRIETARY CODE SEGMENT */ | /* END PROPRIETARY CODE SEGMENT */ | |||
#else | #else | |||
struct _timeb timebuffer; | struct __timeb64 timebuffer; | |||
_ftime( &timebuffer ); | _ftime64( &timebuffer ); | |||
return((timebuffer.time+(timebuffer.millitm/((double)1000.0)))-G->Util->Start Sec); | return((timebuffer.time+(timebuffer.millitm/((double)1000.0)))-G->Util->Start Sec); | |||
#endif | #endif | |||
} | } | |||
char *UtilConcat(char *where,const char *what) | char *UtilConcat(char *where,const char *what) | |||
{ | { | |||
while(*what) | while(*what) | |||
*(where++)=*(what++); | *(where++)=*(what++); | |||
*where=0; | *where=0; | |||
return(where); | return(where); | |||
skipping to change at line 395 | skipping to change at line 395 | |||
} | } | |||
#define MAX_BIN = 100 | #define MAX_BIN = 100 | |||
#ifndef R_SMALL8 | #ifndef R_SMALL8 | |||
#define R_SMALL8 0.00000001F | #define R_SMALL8 0.00000001F | |||
#endif | #endif | |||
int UtilSemiSortFloatIndex(int n,float *array,int *x, int forward) | int UtilSemiSortFloatIndex(int n,float *array,int *x, int forward) | |||
{ | { | |||
return UtilSemiSortFloatIndexWithNBins(n, n, array, x, forward); | ||||
} | ||||
int UtilSemiSortFloatIndexWithNBins(int n, int nbins, float *array, int *destx, | ||||
int forward) | ||||
{ | ||||
int *start1 = Calloc(int,n + nbins); | ||||
int ret = UtilSemiSortFloatIndexWithNBinsImpl(start1, n, nbins, array, destx, | ||||
forward); | ||||
mfree(start1); | ||||
return ret; | ||||
} | ||||
int UtilSemiSortFloatIndexWithNBinsImpl(int *start1, int n, int nbins, float *ar | ||||
ray, int *destx, int forward) | ||||
{ | ||||
/* approximate sort, for quick handling of transparency values */ | /* approximate sort, for quick handling of transparency values */ | |||
/* this sort uses 2 arrays start1 and next1 to keep track of */ | /* this sort uses 2 arrays start1 and next1 to keep track of */ | |||
/* the indexes. The values in start1 are set to the index */ | /* the indexes. The values in start1 are set to the index */ | |||
/* relative to the array value within the min/max values. If */ | /* relative to the array value within the min/max values. If */ | |||
/* there is a collision, the value in next1 is set to the value */ | /* there is a collision, the value in next1 is set to the value */ | |||
/* that is collided, and start1[idx] is set to the index plus 1 (a+1) */ | /* that is collided, and start1[idx] is set to the index plus 1 (a+1) */ | |||
/* This makes it easy to go through the 2 arrays and write into the */ | /* This makes it easy to go through the 2 arrays and write into the */ | |||
/* x array the approximate order of the floating point values in array */ | /* x array the approximate order of the floating point values in array */ | |||
/* by indexes. */ | /* by indexes. */ | |||
/* Since there are two arrays of n length, this guarentees that there */ | /* Since there are two arrays, this guarentees that there */ | |||
/* will be enough memory to hold all indexes. If there are many collisions, * / | /* will be enough memory to hold all indexes. If there are many collisions, * / | |||
/* the next1 array will hold a link to most of the indexes, which are traverse d */ | /* the next1 array will hold a link to most of the indexes, which are traverse d */ | |||
/* when the first index is found in start1. If there are few collisions, then */ | /* when the first index is found in start1. If there are few collisions, then */ | |||
/* the majority of the start1 array is used. The total number of items used in */ | /* the majority of the start1 array is used. The total number of items used in */ | |||
/* both arrays will always be the number of values, i.e., n. */ | /* both arrays will always be the number of values, i.e., n. */ | |||
/* 9/9/14: BB - added start1 and nbins argument | ||||
start1 - pre-allocated memory | ||||
nbins - allows the first array to be controled as the number of bins, | ||||
to match how CGORenderGLAlpha() sorts its triangles. | ||||
*/ | ||||
int ok = true; | int ok = true; | |||
if(n>0) { | if(n>0) { | |||
float min,max,*f,v; | float min,max,*f,v; | |||
float range, scale; | float range, scale; | |||
int a; | int a; | |||
int *start1; | ||||
int *next1; | int *next1; | |||
int idx1; | int idx1; | |||
int n_minus_one; | ||||
start1 = Calloc(int,n*2); | ||||
CHECKOK(ok, start1); | CHECKOK(ok, start1); | |||
if (!ok){ | if (!ok){ | |||
return false; | return false; | |||
} | } | |||
next1 = start1 + n; | next1 = start1 + nbins; | |||
max = (min = array[0]); | max = (min = array[0]); | |||
f = array + 1; | f = array + 1; | |||
for(a=1;a<n;a++) { | for(a=1;a<n;a++) { | |||
v = *(f++); | v = *(f++); | |||
if(max<v) max=v; | if(max<v) max=v; | |||
if(min>v) min=v; | if(min>v) min=v; | |||
} | } | |||
range = (max-min)*1.0001F; /* for boundary conditions */ | range = (max-min)/.9999F; /* for boundary conditions */ | |||
if(range<R_SMALL8) { | if(range<R_SMALL8) { | |||
for(a=0;a<n;a++) | for(a=0;a<n;a++) | |||
x[a] = a; | destx[a] = a; | |||
} else { | } else { | |||
scale = n/range; | scale = nbins/range; | |||
f = array; | f = array; | |||
/* hash by value (actually binning) */ | /* hash by value (actually binning) */ | |||
if(forward) { | if(forward) { | |||
for(a=0;a<n;a++) { | for(a=0;a<n;a++) { | |||
idx1 = (int)((*(f++)-min)*scale); | idx1 = (int)((*(f++)-min)*scale); | |||
next1[a] = start1[idx1]; | next1[a] = start1[idx1]; | |||
start1[idx1] = a+1; | start1[idx1] = a+1; | |||
} | } | |||
} else { | } else { | |||
n_minus_one = n-1; | ||||
for(a=0;a<n;a++) { | for(a=0;a<n;a++) { | |||
idx1 = n_minus_one-(int)((*(f++)-min)*scale); | idx1 = (nbins-1) - (int)((*(f++)-min)*scale); | |||
next1[a] = start1[idx1]; | next1[a] = start1[idx1]; | |||
start1[idx1] = a+1; | start1[idx1] = a+1; | |||
} | } | |||
} | } | |||
/* now read out */ | /* now read out */ | |||
{ | { | |||
int c=0; | int c=0; | |||
int cur1; | int cur1; | |||
a=0; | a=0; | |||
while(a<n) { | while(a<nbins) { | |||
if( (cur1 = start1[a]) ) { | if( (cur1 = start1[a]) ) { | |||
idx1 = cur1 - 1; | idx1 = cur1 - 1; | |||
while(1) { | while(1) { | |||
x[c++] = idx1; | destx[c++] = idx1; | |||
if(! (cur1 = next1[idx1])) | if(! (cur1 = next1[idx1])) | |||
break; | break; | |||
idx1 = cur1 - 1; | idx1 = cur1 - 1; | |||
} | } | |||
} | } | |||
a++; | a++; | |||
} | } | |||
} | } | |||
} | } | |||
mfree(start1); | ||||
} | } | |||
return true; | return true; | |||
} | } | |||
void UtilSortInPlace(PyMOLGlobals *G,void *array,int nItem, | void UtilSortInPlace(PyMOLGlobals *G,void *array,int nItem, | |||
unsigned int itemSize, | unsigned int itemSize, | |||
UtilOrderFn *fOrdered) | UtilOrderFn *fOrdered) | |||
{ | { | |||
char *tmp; | char *tmp; | |||
End of changes. 16 change blocks. | ||||
15 lines changed or deleted | 31 lines changed or added |