1
0
Fork 0
mirror of https://github.com/cosmo-sims/MUSIC.git synced 2024-09-19 17:03:46 +02:00

fixed an issue with region types ellipsoid and convex_hull if the points in region_point_file intersected box boundaries

This commit is contained in:
Oliver Hahn 2016-04-15 14:20:14 +02:00
parent 20c68cc3e5
commit 87aea86e48
3 changed files with 67 additions and 13 deletions

View file

@ -32,6 +32,7 @@ struct convex_hull{
std::vector<real_t> x0_L_, x0_U_;
real_t centroid_[3], volume_;
real_t left_[3], right_[3];
real_t anchor_pt_[3];
inline double turn( cpr_ p, cpr_ q, cpr_ r ) const
{ return (q[0]-p[0])*(r[1]-p[1]) - (r[0]-p[0])*(q[1]-p[1]); }
@ -183,8 +184,8 @@ struct convex_hull{
xcp[2] += vol * xct[2];
}
volume_ = totvol;
centroid_[0] = xcp[0] / totvol;
centroid_[1] = xcp[1] / totvol;
centroid_[2] = xcp[2] / totvol;
@ -218,10 +219,19 @@ struct convex_hull{
}
template< typename T >
bool check_point( const T* x, double dist = 0.0 ) const
bool check_point( const T* xp, double dist = 0.0 ) const
{
dist *= -1.0;
// take care of possible periodic boundaries
T x[3];
for( size_t p=0; p<3; ++p )
{
T d = xp[p] - anchor_pt_[p];
if( d>0.5 ) x[p] = xp[p]-1.0; else if ( d<-0.5 ) x[p] = xp[p]+1.0; else x[p] = xp[p];
}
// check for inside vs. outside
for( size_t i=0; i<normals_L_.size()/3; ++i )
{
double xp[3] = {x[0]-x0_L_[3*i+0],x[1]-x0_L_[3*i+1],x[2]-x0_L_[3*i+2]};
@ -272,9 +282,13 @@ struct convex_hull{
unique.insert( faceidx_U_[i] );
}
convex_hull( cpr_ points, size_t npoints )
convex_hull( cpr_ points, size_t npoints, const double* anchor )
: npoints_( npoints )
{
anchor_pt_[0] = anchor[0];
anchor_pt_[1] = anchor[1];
anchor_pt_[2] = anchor[2];
faceidx_L_.reserve(npoints_*3);
faceidx_U_.reserve(npoints_*3);
normals_L_.reserve(npoints_*3);
@ -322,6 +336,14 @@ struct convex_hull{
left_[p] = points[3*q+p];
}
// make sure left point is inside box
for( size_t p=0; p<3; ++p )
if( left_[p] >= 1.0 ){
left_[p] -= 1.0; right_[p] -= 1.0;
}else if( left_[p] < 0.0 ){
left_[p] += 1.0; right_[p]+= 1.0;
}
}
};

View file

@ -31,6 +31,8 @@ private:
double vfac_;
bool do_extra_padding_;
double anchor_pt_[3];
std::vector<float> level_dist_;
void apply_shift( size_t Np, double *p, int *shift, int levelmin )
@ -72,8 +74,20 @@ public:
shift_level = point_levelmin;
}
// take care of possibly cutting across a periodic boundary
anchor_pt_[0] = pp[0];
anchor_pt_[1] = pp[1];
anchor_pt_[2] = pp[2];
for( size_t i = 0; i < pp.size(); ++i )
{
double d = pp[i] - anchor_pt_[i%3];
if( d > 0.5 ) pp[i] -= 1.0;
if( d < -0.5 ) pp[i] += 1.0;
}
// compute the convex hull
phull_ = new convex_hull<double>( &pp[0], pp.size()/3 );
phull_ = new convex_hull<double>( &pp[0], pp.size()/3, anchor_pt_ );
//expand the ellipsoid by one grid cell
unsigned levelmax = cf.getValue<unsigned>("setup","levelmax");

View file

@ -314,22 +314,29 @@ public:
int i3=3*i;
for( size_t j=0; j<3; ++j )
{
xcenter[j] += P[i3+j];
pmax = P[i3+j] > pmax ? P[i3+j] : pmax;
pmin = P[i3+j] < pmin ? P[i3+j] : pmin;
double d = P[i3+j] - P[j];
double p = (d>0.5)? P[i3+j]-1.0 : (d<-0.5)? P[i3+j]+1.0 : P[i3+j];
xcenter[j] += p;
pmax = p > pmax ? p : pmax;
pmin = p < pmin ? p : pmin;
}
}
double L = 2.0*(pmax - pmin);
xcenter[0] /= N;
xcenter[1] /= N;
xcenter[2] /= N;
xcenter[0] = fmod(xcenter[0]/N+1.0,1.0);
xcenter[1] = fmod(xcenter[1]/N+1.0,1.0);
xcenter[2] = fmod(xcenter[2]/N+1.0,1.0);
for( size_t i=0; i<N; ++i )
{
int i3=3*i;
for( size_t j=0; j<3; ++j )
P[i3+j] = (P[i3+j]-xcenter[j])/L + 0.5;
for( size_t j=0; j<3; ++j ){
double d = P[i3+j]-xcenter[j];
d = (d>0.5)? d-1.0 : (d<-0.5)? d+1.0 : d;
P[i3+j] = d/L + 0.5;
}
}
@ -441,10 +448,14 @@ public:
T q[3] = {x[0]-c[0],x[1]-c[1],x[2]-c[2]};
T r = 0.0;
for( int i=0; i<3; ++i )
q[i] = (q[i]>0.5)?q[i]-1.0:(q[i]<-0.5)?q[i]+1.0:q[i];
for( int i=0; i<3; ++i )
for( int j=0; j<3; ++j )
r += q[i]*A[3*j+i]*q[j];
return r <= 1.0;
}
@ -474,6 +485,9 @@ public:
{
left[i] = c[i] - sqrt(Ainv[3*i+i]);
right[i] = c[i] + sqrt(Ainv[3*i+i]);
if( left[i] < 0.0 ){ left[i] += 1.0; right[i] += 1.0; }
if( left[i] >= 1.0 ){ left[i] -= 1.0; right[i] -= 1.0; }
}
}
@ -529,7 +543,10 @@ public:
#include "point_file_reader.hh"
#if 0
#include "convex_hull.hh"
#endif
//! Minimum volume enclosing ellipsoid plugin
class region_ellipsoid_plugin : public region_generator_plugin{
@ -648,7 +665,7 @@ public:
}
#if 0
if( false )
{
// compute convex hull and use only hull points to speed things up
@ -675,6 +692,7 @@ public:
pphull.swap( pp );
}
#endif
// output the center