source: sasview/src/sas/sascalc/simulation/pointsmodelpy/libpointsmodelpy/complex_model.cc @ 18da4a8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 18da4a8 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[aa639ea]1/** \file complex_model.cc */
2
3#include "complex_model.h"
4#include <algorithm>
5#include <stdexcept>
6
7using namespace std;
8
9ComplexModel::ComplexModel(){
10
11}
12
13void ComplexModel::Add(PointsModel *pm)
14{
15  models_.push_back(pm);
16}
17
18double ComplexModel::GetDimBound()
19{
20  //Get the vector of centers of pointsmodel instances
21  //and a vector of individual boundary
22  vector<PointsModel *>::iterator itr;
23  vector<Point3D> veccenter;
24  vector<double> bounds;
25
26  for(itr = models_.begin(); itr != models_.end(); ++itr){
27    if ((*itr)->GetDimBound() != 0){
28      Point3D pp((*itr)->GetCenter()[0],(*itr)->GetCenter()[1],(*itr)->GetCenter()[2]);
29      veccenter.push_back(pp);
30      bounds.push_back((*itr)->GetDimBound());
31    }
32  }
33
34  //max bound
35  double maxbound = *max_element(bounds.begin(),bounds.end());
36
37  //max distance
38  vector<double> vecdist;
39  size_t num = veccenter.size();
40
41  if (num > 1){
42    for (size_t i = 0; i != num; ++i){
43      for (size_t j= 1; j != num; ++j){
44        double dist = veccenter[i].distanceToPoint(veccenter[j]);
45        vecdist.push_back(dist);
46      }
47    }
48  }
49  else{
50    vecdist.push_back(maxbound);
51  }
52
53  double maxcenterdist = *max_element(vecdist.begin(),vecdist.end());
54
55  double finalbound = maxbound + maxcenterdist;
56
57  return finalbound;
58}
59
60vector<double> ComplexModel::GetCenter()
61{
62  double sumx = 0, sumy = 0, sumz = 0;
63  size_t num = 0;
64
65  vector<PointsModel *>::iterator itr;
66  for(itr = models_.begin(); itr != models_.end(); ++itr){
67    sumx += (*itr)->GetCenter()[0];
68    sumy += (*itr)->GetCenter()[1];
69    sumz += (*itr)->GetCenter()[2];
70    ++num;
71  }
72
73  vector<double> v(3);
74  v[0] = sumx/num;
75  v[1] = sumy/num;
76  v[2] = sumz/num;
77  center_ = v;
78  return center_;
79}
80
81int ComplexModel::GetPoints(Point3DVector &vp)
82{
83  if (vp.size() != 0){
84    throw runtime_error("GetPoints(Point3DVector &VP):VP has to be empty"); 
85  }
86
87  vector<PointsModel *>::iterator itr;
88
89  for(itr = models_.begin(); itr != models_.end(); ++itr){
90    vector<Point3D> temp;
91    (*itr)->GetPoints(temp);           
92    if (temp.size() != 0){
93      vp.insert(vp.end(),temp.begin(),temp.end());
94    }
95  }
96  return vp.size();
97}
Note: See TracBrowser for help on using the repository browser.