v0.14.0
Public Member Functions | Public Attributes | List of all members
CellEngineering::DataFromFiles Struct Reference

#include <users_modules/cell_engineering/src/DispMap.hpp>

Collaboration diagram for CellEngineering::DataFromFiles:
[legend]

Public Member Functions

 DataFromFiles (string &file)
 
MoFEMErrorCode loadFileData ()
 
MoFEMErrorCode fromOptions ()
 
double getDataForGivenCoordinate (const double x, const double y, vector< vector< double >> &main_vector, const double sCale, const double cUbe_size)
 

Public Attributes

string & fIle
 
double sCale
 
double cUbe_size
 
vector< vector< double > > main_vector
 
double lAmbda
 

Detailed Description

Definition at line 29 of file DispMap.hpp.

Constructor & Destructor Documentation

◆ DataFromFiles()

CellEngineering::DataFromFiles::DataFromFiles ( string &  file)
inline

Definition at line 38 of file DispMap.hpp.

38 : fIle(file) {}

Member Function Documentation

◆ fromOptions()

MoFEMErrorCode CellEngineering::DataFromFiles::fromOptions ( )
inline

Definition at line 68 of file DispMap.hpp.

68  {
70  CHKERR PetscOptionsBegin(PETSC_COMM_WORLD, "", "Get parameters", "none");
71 
72  cUbe_size = 4;
73  CHKERR PetscOptionsScalar("-cube_size", "get cube size for the averaging",
74  "", 0, &cUbe_size, PETSC_NULL);
75 
76  sCale = 1;
77  CHKERR PetscOptionsScalar(
78  "-scale", "scale the distance between voxels (eg. from mm to m)", "",
79  sCale, &sCale, PETSC_NULL);
80 
81  ierr = PetscOptionsEnd();
82  CHKERRQ(ierr);
83 
85  }

◆ getDataForGivenCoordinate()

double CellEngineering::DataFromFiles::getDataForGivenCoordinate ( const double  x,
const double  y,
vector< vector< double >> &  main_vector,
const double  sCale,
const double  cUbe_size 
)
inline

returns vertors of data for given index of the point

Parameters
vec_idxreference vector of indices
vec_datareference vector of data (colors)
Returns
error code

Definition at line 94 of file DispMap.hpp.

96  {
97 
98  const int size_y = main_vector.size(); // flip
99  const int size_x = main_vector.begin()->size();
100  double data = 0;
101 
102  vector<int> vec_ix;
103  vector<int> vec_iy;
104  vector<double> vec_data;
105  vector<double> vec_dist;
106 
107  int nx = ceil(cUbe_size);
108  int ny = ceil(cUbe_size);
109 
110  int ix = ceil(x / sCale);
111  int iy = ceil(y / sCale);
112 
113  vec_ix.resize(2 * nx);
114  vec_iy.resize(2 * ny);
115 
116  int ii = 0;
117  for (int i = 0; i < 2 * nx; i++) {
118  int idx = ix - nx + i;
119  if (idx >= size_x / 2 || idx < -size_x / 2)
120  continue;
121  vec_ix[ii++] = idx;
122  }
123  vec_ix.resize(ii);
124  ii = 0;
125  for (int i = 0; i < 2 * ny; i++) {
126  int idx = iy - ny + i;
127  if (idx >= size_y / 2 || idx < -size_y / 2)
128  continue;
129  vec_iy[ii++] = idx;
130  }
131  vec_iy.resize(ii);
132  ii = 0;
133 
134  vec_data.resize(vec_iy.size() * vec_ix.size());
135  vec_dist.resize(vec_iy.size() * vec_ix.size());
136 
137  for (vector<int>::iterator it_iy = vec_iy.begin(); it_iy != vec_iy.end();
138  it_iy++) {
139  for (vector<int>::iterator it_ix = vec_ix.begin(); it_ix != vec_ix.end();
140  it_ix++) {
141  vec_data[ii] =
142  main_vector[*it_iy + size_y / 2][*it_ix + size_x / 2]; // flip
143  vec_dist[ii] = ((*it_iy * sCale - y) * (*it_iy * sCale - y) +
144  (*it_ix * sCale - x) * (*it_ix * sCale - x));
145 
146  ii++;
147  }
148  }
149 
150  // gaussian smoothing
151  vector<double> kernel;
152  kernel.resize(vec_data.size());
153  int i = 0;
154  double sigma = 10;
155  double sum = 0;
156  const double m = (1 / sqrt(M_PI * 2 * sigma * sigma));
157  for (int ii = 0; ii < vec_dist.size(); ii++) {
158  kernel[i] = m * exp(-(vec_dist[ii]) /
159  (2 * sigma * sigma)); // distance is already squared
160  sum += kernel[i++];
161  }
162  ii = 0;
163  for (vector<double>::iterator vec_itr = vec_data.begin();
164  vec_itr != vec_data.end(); vec_itr++) {
165  kernel[ii] /= sum;
166  data += (*vec_itr) * kernel[ii++];
167  }
168  return data;
169  }

◆ loadFileData()

MoFEMErrorCode CellEngineering::DataFromFiles::loadFileData ( )
inline

Definition at line 40 of file DispMap.hpp.

40  {
42  ifstream in(fIle.c_str());
43  if (!in.is_open()) {
44  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
45  "file with data points not found");
46  // cout << ">> couldn't read the file <<"<< endl;
47  }
48 
49  typedef boost::tokenizer<boost::escaped_list_separator<char>> Tokenizer;
50 
51  string line;
52 
53  main_vector.clear();
54  while (getline(in, line)) {
55  vector<double> vec;
56  Tokenizer tok(line);
57  for (Tokenizer::iterator it(tok.begin()), end(tok.end()); it != end;
58  ++it) {
59  vec.push_back(atof(it->c_str()));
60  }
61 
62  main_vector.push_back(vec);
63  }
64  reverse(main_vector.begin(), main_vector.end());
66  }

Member Data Documentation

◆ cUbe_size

double CellEngineering::DataFromFiles::cUbe_size

Definition at line 34 of file DispMap.hpp.

◆ fIle

string& CellEngineering::DataFromFiles::fIle

Definition at line 31 of file DispMap.hpp.

◆ lAmbda

double CellEngineering::DataFromFiles::lAmbda

Definition at line 36 of file DispMap.hpp.

◆ main_vector

vector<vector<double> > CellEngineering::DataFromFiles::main_vector

Definition at line 35 of file DispMap.hpp.

◆ sCale

double CellEngineering::DataFromFiles::sCale

Definition at line 33 of file DispMap.hpp.


The documentation for this struct was generated from the following file:
CellEngineering::DataFromFiles::cUbe_size
double cUbe_size
Definition: DispMap.hpp:34
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
CellEngineering::DataFromFiles::main_vector
vector< vector< double > > main_vector
Definition: DispMap.hpp:35
CellEngineering::DataFromFiles::fIle
string & fIle
Definition: DispMap.hpp:31
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
CellEngineering::DataFromFiles::sCale
double sCale
Definition: DispMap.hpp:33
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359