24 #ifndef __DENSITY_MAPS_HPP__
25 #define __DENSITY_MAPS_HPP__
41 kdTree(&m_field.get_moab()) {
64 PetscFunctionReturn(0);
75 PetscFunctionReturn(0);
97 const double coords[] = {x,y,z};
98 double closest_point[3];
106 cblas_daxpy(3,-1,coords,1,closest_point,1);
107 dx = closest_point[0];
108 dy = closest_point[1];
109 dz = closest_point[2];
110 PetscFunctionReturn(0);
123 auto it = field_ents->lower_bound(
124 FieldEntity::getLoBitNumberUId(field_bit_number));
125 auto hi_it = field_ents->upper_bound(
126 FieldEntity::getHiBitNumberUId(field_bit_number));
128 for(;it!=hi_it;it++) {
129 EntityType
type = it->get()->getEntType();
143 dofs[0] = cblas_dnrm2(3,
delta,1);
146 it = field_ents->lower_bound(
147 FieldEntity::getLoBitNumberUId(field_bit_number));
148 for(;it!=hi_it;it++) {
149 EntityType
type = it->get()->getEntType();
157 double coords[3*num_ndodes];
159 cblas_daxpy(3,1,&coords[3],1,coords,1);
160 cblas_dscal(3,0.5,coords,1);
166 auto conn_it0 = field_ents->find(
167 FieldEntity::getLoLocalEntityBitNumber(field_bit_number, conn[0]));
168 auto conn_it1 = field_ents->find(
169 FieldEntity::getLoLocalEntityBitNumber(field_bit_number, conn[1]));
171 if(conn_it0==field_ents->end()) {
174 if (conn_it1 == field_ents->end()) {
178 VectorAdaptor vec_conn0 = conn_it0->get()->getEntFieldData();
179 VectorAdaptor vec_conn1 = conn_it1->get()->getEntFieldData();
181 double ave_delta = 0.5*(vec_conn0[0]+vec_conn1[0]);
182 double edge_shape_function_val = 0.25;
193 dofs[0] = (cblas_dnrm2(3,
delta,1)-ave_delta)/edge_shape_function_val;
195 PetscFunctionReturn(0);
225 ierr = PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Get parameters for DataFromMetaIO",
"none"); CHKERRQ(
ierr);
227 PetscBool flg = PETSC_TRUE;
230 ierr = PetscOptionsScalar(
231 "-density_map_sigma",
232 "get sigma for gauss weighted average",
"",
237 ierr = PetscOptionsScalar(
239 "get cube size for the averaging",
"",
244 ierr = PetscOptionsScalar(
246 "get distance tolerance from mesh surface",
"",
251 ierr = PetscOptionsScalar(
253 "scale the distance between voxels (eg. from mm to m)",
"",
258 ierr = PetscOptionsScalar(
260 "minimum value of ct threshold",
"",
265 ierr = PetscOptionsInt(
267 "number of the filter",
"",
272 ierr = PetscOptionsScalar(
274 "get lambda coefficient for smoothing",
"",
291 ierr = PetscOptionsEnd(); CHKERRQ(
ierr);
293 PetscFunctionReturn(0);
303 const vector<int> &vec_idx,
304 vector<double> &vec_data
307 int size_of_vec_idx = vec_idx.size();
308 vec_data.resize(size_of_vec_idx);
311 for(vector<int>::const_iterator vit = vec_idx.begin();vit!=vec_idx.end();vit++) {
312 vec_data[ii] =
metaFile.ElementData(*vit);
317 PetscFunctionReturn(0);
335 const double x,
const double y,
const double z,
336 const double dx,
const double dy,
const double dz,
340 vector<int> &vec_idx,
341 vector<double> &vec_dist
345 const double *elemet_size =
metaFile.ElementSize();
346 const int *dim_size =
metaFile.DimSize();
348 int nx = ceil(dx/ (elemet_size[0] *
sCale));
349 int ny = ceil(dy/ (elemet_size[1] *
sCale));
350 int nz = ceil(dz/ (elemet_size[2] *
sCale));
353 double x_befor_offset = x;
354 double y_befor_offset = y;
355 double z_befor_offset = z;
360 int ix = ceil(x_befor_offset/ (elemet_size[0] *
sCale));
361 int iy = ceil(y_befor_offset/ (elemet_size[1] *
sCale));
362 int iz = ceil(z_befor_offset/ (elemet_size[2] *
sCale));
369 for(
int i = 0;
i<2*nx;
i++) {
371 if(idx >= dim_size[0] || idx < 0)
continue;
376 for(
int i = 0;
i<2*ny;
i++) {
378 if(idx >= dim_size[1] || idx < 0)
continue;
383 for(
int i = 0;
i<2*nz;
i++) {
385 if(idx >= dim_size[2] || idx < 0)
continue;
393 vec_ix.push_back(round(x_befor_offset/ (elemet_size[0] *
sCale)));
397 vec_iy.push_back(round(y_befor_offset/ (elemet_size[1] *
sCale)));
401 vec_iz.push_back(round(z_befor_offset/ (elemet_size[2] *
sCale)));
406 vec_idx.resize(vec_iz.size() * vec_ix.size() * vec_iy.size());
407 vec_dist.resize(vec_iz.size() * vec_ix.size() * vec_iy.size());
408 int dm_size0_dim_size1 = dim_size[0] * dim_size[1];
431 for(vector<int>::iterator it_iz = vec_iz.begin(); it_iz != vec_iz.end();it_iz++) {
432 double a = (*it_iz) * dm_size0_dim_size1 ;
433 double dz2 = (*it_iz*(elemet_size[2]*
sCale) - z_befor_offset) * (*it_iz*(elemet_size[2]*
sCale) - z_befor_offset);
434 for(vector<int>::iterator it_iy = vec_iy.begin(); it_iy != vec_iy.end();it_iy++) {
435 double b = (*it_iy) * dim_size[0];
436 double dy2 = (*it_iy*(elemet_size[1]*
sCale) - y_befor_offset) * (*it_iy*(elemet_size[1]*
sCale) - y_befor_offset);
437 for(vector<int>::iterator it_ix = vec_ix.begin(); it_ix != vec_ix.end();it_ix++) {
438 vec_idx[ii] =
a + b + (*it_ix);
439 vec_dist[ii] = ( dz2 + dy2 + (*it_ix*(elemet_size[0]*
sCale) - x_befor_offset)
440 * (*it_ix*(elemet_size[0]*
sCale) - x_befor_offset) );
464 for(vector<int>::iterator it_iz = vec_iz.begin(); it_iz != vec_iz.end();it_iz++) {
465 double a = (*it_iz) * dm_size0_dim_size1 ;
466 for(vector<int>::iterator it_iy = vec_iy.begin(); it_iy != vec_iy.end();it_iy++) {
467 double b = (*it_iy) * dim_size[0];
468 for(vector<int>::iterator it_ix = vec_ix.begin(); it_ix != vec_ix.end();it_ix++) {
469 vec_idx[ii++] =
a + b + (*it_ix);
476 PetscFunctionReturn(0);
489 for(vector<double>::const_iterator vec_it = vec_data.begin();vec_it!=vec_data.end();vec_it++) {
510 const vector<double> &vec_data,
511 vector<double> &vec_density
514 vec_density.resize(vec_data.size());
516 for(vector<double>::const_iterator vec_it = vec_data.begin();vec_it!=vec_data.end();vec_it++) {
521 PetscFunctionReturn(0);
524 const vector<double> &vec_data,
525 vector<double> &vec_density
529 PetscFunctionReturn(0);
542 return param[1] * pow(
rho , param[0]);
554 vector<double> vec_copy;
555 vec_copy.resize(vec_density.size());
557 for(vector<double>::const_iterator vec_it = vec_density.begin();vec_it!=vec_density.end();vec_it++){
559 vec_copy[
i++] = *vec_it;
565 sort(vec_copy.begin(), vec_copy.end());
567 if (vec_copy.size() % 2 == 0) {
568 return (vec_copy[vec_copy.size() / 2 - 1] + vec_copy[vec_copy.size() / 2]) / 2.0;
570 return vec_copy[vec_copy.size() / 2];
583 const vector<double> &vec_density,
584 const vector<double> &vec_dist
588 kErnel.resize(vec_density.size());
592 const double k = 2 * sigma*sigma;
593 const double m = (1 / sqrt( M_PI *
k));
594 for(
int ii = 0; ii < vec_dist.size(); ii++) {
595 if (vec_density[ii] <
tHreshold)
continue;
596 kErnel[
i] =
m * exp(- (vec_dist[ii]) /
k);
603 double smooth_data = 0;
604 for(vector<double>::const_iterator vec_itr = vec_density.begin();vec_itr!=vec_density.end();vec_itr++) {
608 smooth_data += (*vec_itr) *
kErnel[ii++];
610 if (sum == 0)
return 0;
615 const vector<double> &vec_density,
616 const vector<double> &vec_dist
623 #endif // WITH_METAIO
651 if(row_type != MBTET) PetscFunctionReturn(0);
655 PetscFunctionReturn(0);
706 int row_side,
int col_side,
707 EntityType row_type,EntityType col_type,
714 int nb_rows = row_data.getIndices().size();
715 int nb_cols = col_data.getIndices().size();
716 if(nb_rows==0) PetscFunctionReturn(0);
717 if(nb_cols==0) PetscFunctionReturn(0);
721 int nb_gauss_pts = row_data.getN().size1();
722 for(
int gg = 0;gg<nb_gauss_pts;gg++) {
726 commonData.
locA += vol*outer_prod(row_base_function,col_base_function);
727 MatrixAdaptor row_diff_base_function = row_data.getDiffN(gg);
728 MatrixAdaptor col_diff_base_function = col_data.getDiffN(gg);
732 row_diff_base_function,trans(col_diff_base_function));
736 row_data.getIndices().size(),
737 &row_data.getIndices()[0],
738 col_data.getIndices().size(),
739 &col_data.getIndices()[0],
745 if(row_side!=col_side || row_type!=col_type) {
750 col_data.getIndices().size(),
751 &col_data.getIndices()[0],
752 row_data.getIndices().size(),
753 &row_data.getIndices()[0],
759 PetscFunctionReturn(0);
776 const string &row_field,
795 if(row_type!=MBVERTEX) PetscFunctionReturn(0);
797 int nb_rows = row_data.getIndices().size();
798 if(nb_rows == 0) PetscFunctionReturn(0);
806 vector<double> vecData;
807 vector<double> vecDensity;
808 vector<double> vecDist;
830 const int nb_gauss_pts = row_data.getN().size1();
832 for(
int gg = 0;gg<nb_gauss_pts;gg++) {
834 if(t0_dist<cube_size) {
835 const double nrm2_grad = sqrt(t1_grad(
i)*t1_grad(
i));
837 t1_delta(
i) = t1_grad(
i)/nrm2_grad;
838 t1_xyz(
i) -= (t0_dist-cube_size)*t1_delta(
i);
857 t1_xyz(0),t1_xyz(1),t1_xyz(2),
858 t1_dx(0),t1_dx(1),t1_dx(2),
859 vecIx,vecIy,vecIz,vecIdx, vecDist
888 PetscFunctionReturn(0);
907 const string &row_field,
922 int nb_rows = row_data.getIndices().size();
923 if(nb_rows == 0) PetscFunctionReturn(0);
927 int nb_gauss_pts = row_data.getN().size1();
928 for(
int gg = 0;gg<nb_gauss_pts;gg++) {
938 row_data.getIndices().size(),
939 &row_data.getIndices()[0],
944 PetscFunctionReturn(0);
986 if(row_type != MBVERTEX) PetscFunctionReturn(0);
993 int nb_gauss_pts = row_data.getN().size1();
994 for(
int gg = 0;gg<nb_gauss_pts;gg++) {
1032 double rho = data * vol;
1037 PetscFunctionReturn(0);
1068 int nb_rows = row_data.getIndices().size();
1070 PetscFunctionReturn(0);
1073 int nb_gauss_pts = row_data.getN().size1();
1075 for(
int gg = 0;gg<nb_gauss_pts;gg++) {
1081 rho = inner_prod(shape_function,row_data.getFieldData());
1084 double mass =
rho * vol;
1089 PetscFunctionReturn(0);
1093 #endif // WITH_METAIO
1098 #endif //__DENSITY_MAPS_HPP__