6typedef std::vector<double>
DblVec;
17 std::vector<double>& x_cuts,
18 std::vector<double>& y_cuts)
20 std::vector<IntVec> balance_matrix(x_cuts.size()+1,
21 IntVec(y_cuts.size()+1,0));
23 size_t num_points = points.size();
24 size_t num_x_cuts = x_cuts.size();
25 size_t num_y_cuts = y_cuts.size();
26 for (
size_t p=0; p<num_points; p++)
28 double xr = points[p].x;
29 double yr = points[p].y;
33 for (
int i=0; i<num_x_cuts; i++)
42 for (
int j=0; j<num_y_cuts; j++)
50 balance_matrix[ir][jr] += 1;
54 int max_points_per_bin = 0;
56 for (
int i=0; i<=num_x_cuts; i++)
58 for (
int j=0; j<=num_y_cuts; j++)
60 bin_sum += balance_matrix[i][j];
62 if (balance_matrix[i][j] > max_points_per_bin)
63 max_points_per_bin = balance_matrix[i][j];
66 double average = bin_sum/(num_x_cuts+1)/(num_y_cuts+1);
68 return max_points_per_bin/average;
78 std::vector<chi_mesh::Vector3> centroids(num_pfaces);
79 for (
int pf=0; pf<num_pfaces; pf++)
80 centroids[pf] = smesh.
GetPolygons()[pf]->face_centroid;
109 std::vector<chi_mesh::Vector3> centroids_sortedx;
110 std::vector<chi_mesh::Vector3> centroids_sortedy;
111 std::copy(centroids.begin(), centroids.end(),
112 std::back_inserter(centroids_sortedx));
115 std::stable_sort(centroids_sortedx.begin(),
116 centroids_sortedx.end(),
119 std::vector<IntPair> x_bins(px);
120 std::vector<double> x_cuts(px-1);
121 std::vector<DblVec> y_cuts_per_x_bin(px,
DblVec(py-1));
124 int dx = std::ceil(centroids.size()/(
double)px);
125 for (
int x=0; x<px; x++)
127 x_bins[x].first = x*dx;
128 x_bins[x].second = x*dx + dx - 1;
131 x_bins[x].second = centroids_sortedx.size()-1;
135 for (
int x=0; x<(px-1); x++)
137 int up_bounds_x = x*dx + dx - 1;
138 double a = centroids_sortedx[up_bounds_x].x;
139 double b = centroids_sortedx[up_bounds_x+1].x;
141 x_cuts[x] = (b+a)/2.0;
144 <<
"X-cut" << x <<
" " << x_cuts[x];
149 double min_lbf = 1000.0;
151 for (
int x=0; x<px; x++)
153 int bin_i = x_bins[x].first;
154 int bin_f = x_bins[x].second;
156 centroids_sortedy.clear();
157 for (
int i=bin_i; i<=bin_f; i++)
158 centroids_sortedy.push_back(centroids_sortedx[i]);
160 std::stable_sort(centroids_sortedy.begin(),
161 centroids_sortedy.end(),
164 int dy = std::ceil(centroids_sortedy.size()/(
double)py);
165 for (
int y=0; y<(py-1); y++)
167 int up_bounds_y = y*dy + dy - 1;
169 double a = centroids_sortedy[up_bounds_y].y;
170 double b = centroids_sortedy[up_bounds_y+1].y;
172 y_cuts_per_x_bin[x][y] = (b+a)/2.0;
174 double lbf =
ComputeLBF(centroids,x_cuts,y_cuts_per_x_bin[x]);
185 for (
int y=0; y<(py-1); y++)
188 <<
"Y-cut" << y <<
" " << y_cuts_per_x_bin[min_bin][y];
LogStream Log(LOG_LVL level=LOG_0)
const std::vector< chi_mesh::PolyFace * > & GetPolygons() const
std::vector< double > DblVec
std::vector< int > IntVec
std::pair< int, int > IntPair
double ComputeLBF(std::vector< Vector3 > &points, std::vector< double > &x_cuts, std::vector< double > &y_cuts)
void DecomposeSurfaceMeshPxPy(const SurfaceMesh &smesh, int Px, int Py)