Lemma is an Electromagnetics API
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TEMSurveyLineRecordData.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 03/03/2015 10:34:56
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2015, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2015, Trevor Irons
  16. */
  17. #include "TEMSurveyLineRecordData.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurveyLineRecordData &ob) {
  22. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  23. return stream;
  24. }
  25. #else
  26. std::ostream &operator<<(std::ostream &stream, const TEMSurveyLineRecordData& ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // ==================== LIFECYCLE =======================
  32. //--------------------------------------------------------------------------------------
  33. // Class: TEMSurveyLineRecordData
  34. // Method: TEMSurveyLineRecordData
  35. // Description: constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. TEMSurveyLineRecordData::TEMSurveyLineRecordData (const std::string& name) : LemmaObject(name) {
  38. } // ----- end of method TEMSurveyLineRecordData::TEMSurveyLineRecordData (constructor) -----
  39. #ifdef HAVE_YAMLCPP
  40. //--------------------------------------------------------------------------------------
  41. // Class: TEMSurveyLineRecordData
  42. // Method: TEMSurveyLineRecordData
  43. // Description: DeSerializing constructor (protected)
  44. //--------------------------------------------------------------------------------------
  45. TEMSurveyLineRecordData::TEMSurveyLineRecordData (const YAML::Node& node) : LemmaObject(node) {
  46. for (int ii=0; ii< node["numberOfSeries"].as<int>( ); ++ii) {
  47. DataSeries.push_back( node["DataSeries_" + to_string(ii)].as<VectorXr>() );
  48. GateCentres.push_back( node["GateCentres_" + to_string(ii)].as<VectorXr>() );
  49. }
  50. } // ----- end of method TEMSurveyLineRecordData::TEMSurveyLineRecordData (constructor) -----
  51. #endif
  52. //--------------------------------------------------------------------------------------
  53. // Class: TEMSurveyLineRecordData
  54. // Method: New()
  55. // Description: public constructor
  56. //--------------------------------------------------------------------------------------
  57. TEMSurveyLineRecordData* TEMSurveyLineRecordData::New() {
  58. TEMSurveyLineRecordData* Obj = new TEMSurveyLineRecordData("TEMSurveyLineRecordData");
  59. Obj->AttachTo(Obj);
  60. return Obj;
  61. }
  62. //--------------------------------------------------------------------------------------
  63. // Class: TEMSurveyLineRecordData
  64. // Method: Clone
  65. //--------------------------------------------------------------------------------------
  66. TEMSurveyLineRecordData* TEMSurveyLineRecordData::Clone ( ) {
  67. return DeSerialize( this->Serialize() ) ;
  68. } // ----- end of method TEMSurveyLineRecordData::Clone -----
  69. //--------------------------------------------------------------------------------------
  70. // Class: TEMSurveyLineRecordData
  71. // Method: ~TEMSurveyLineRecordData
  72. // Description: destructor (protected)
  73. //--------------------------------------------------------------------------------------
  74. TEMSurveyLineRecordData::~TEMSurveyLineRecordData () {
  75. } // ----- end of method TEMSurveyLineRecordData::~TEMSurveyLineRecordData (destructor) -----
  76. //--------------------------------------------------------------------------------------
  77. // Class: TEMSurveyLineRecordData
  78. // Method: Delete
  79. // Description: public destructor
  80. //--------------------------------------------------------------------------------------
  81. void TEMSurveyLineRecordData::Delete() {
  82. this->DetachFrom(this);
  83. }
  84. //--------------------------------------------------------------------------------------
  85. // Class: TEMSurveyLineRecordData
  86. // Method: Release
  87. // Description: destructor (protected)
  88. //--------------------------------------------------------------------------------------
  89. void TEMSurveyLineRecordData::Release() {
  90. delete this;
  91. }
  92. // ==================== OPERATORS =======================
  93. //--------------------------------------------------------------------------------------
  94. // Class: TEMSurveyLineRecordData
  95. // Method: operator +
  96. //--------------------------------------------------------------------------------------
  97. TEMSurveyLineRecordData* TEMSurveyLineRecordData::operator + ( const TEMSurveyLineRecordData& Survey ) {
  98. TEMSurveyLineRecordData* clone = this->Clone();
  99. for (unsigned int ir=0; ir<DataSeries.size(); ++ir) {
  100. clone->DataSeries[ir] += Survey.DataSeries[ir];
  101. }
  102. return clone;
  103. } // ----- end of method TEMSurveyLineRecordData::operator + -----
  104. //--------------------------------------------------------------------------------------
  105. // Class: TEMSurveyLineRecordData
  106. // Method: operator -
  107. //--------------------------------------------------------------------------------------
  108. TEMSurveyLineRecordData* TEMSurveyLineRecordData::operator - ( const TEMSurveyLineRecordData& Survey ) {
  109. TEMSurveyLineRecordData* clone = this->Clone();
  110. for (unsigned int ir=0; ir<DataSeries.size(); ++ir) {
  111. clone->DataSeries[ir] -= Survey.DataSeries[ir];
  112. }
  113. return clone;
  114. } // ----- end of method TEMSurveyLineRecordData::operator - -----
  115. //--------------------------------------------------------------------------------------
  116. // Class: TEMSurveyLineRecordData
  117. // Method: operator +=
  118. //--------------------------------------------------------------------------------------
  119. void TEMSurveyLineRecordData::operator += ( const TEMSurveyLineRecordData& Survey ) {
  120. if (DataSeries.size() != Survey.DataSeries.size()) {
  121. throw std::runtime_error("size mismatch in TEMSurveyLineRecordData::operator +=");
  122. }
  123. for (unsigned int ii=0; ii<DataSeries.size(); ++ii) {
  124. this->DataSeries[ii] += Survey.DataSeries[ii];
  125. }
  126. return ;
  127. } // ----- end of method TEMSurveyLineRecordData::operator += -----
  128. //--------------------------------------------------------------------------------------
  129. // Class: TEMSurveyLineRecordData
  130. // Method: operator -=
  131. //--------------------------------------------------------------------------------------
  132. void TEMSurveyLineRecordData::operator -= ( const TEMSurveyLineRecordData& Survey ) {
  133. if (DataSeries.size() != Survey.DataSeries.size()) {
  134. throw std::runtime_error("size mismatch in TEMSurveyLineRecordData::operator +=");
  135. }
  136. for (unsigned int ii=0; ii<DataSeries.size(); ++ii) {
  137. this->DataSeries[ii] -= Survey.DataSeries[ii];
  138. }
  139. return ;
  140. } // ----- end of method TEMSurveyLineRecordData::operator -= -----
  141. // ==================== ACCESS =======================
  142. //--------------------------------------------------------------------------------------
  143. // Class: TEMSurveyLineRecordData
  144. // Method: GetCombinedData
  145. //--------------------------------------------------------------------------------------
  146. VectorXr TEMSurveyLineRecordData::GetCombinedData ( ) {
  147. int nd = 0;
  148. for (unsigned int id=0; id<DataSeries.size(); ++id) {
  149. nd += DataSeries[id].size();
  150. }
  151. VectorXr combined = VectorXr(nd);
  152. nd = 0;
  153. for (unsigned int id=0; id<DataSeries.size(); ++id) {
  154. combined.segment(nd, DataSeries[id].size()) = DataSeries[id];
  155. nd += DataSeries[id].size();
  156. }
  157. return combined;
  158. } // ----- end of method TEMSurveyLineRecordData::GetCombinedData -----
  159. //--------------------------------------------------------------------------------------
  160. // Class: TEMSurveyLineRecordData
  161. // Method: GetCombinedGateCentres
  162. //--------------------------------------------------------------------------------------
  163. VectorXr TEMSurveyLineRecordData::GetCombinedGateCentres ( ) {
  164. int nd = 0;
  165. for (unsigned int id=0; id<GateCentres.size(); ++id) {
  166. nd += GateCentres[id].size();
  167. }
  168. VectorXr combined = VectorXr(nd);
  169. nd = 0;
  170. for (unsigned int id=0; id<GateCentres.size(); ++id) {
  171. combined.segment(nd, GateCentres[id].size()) = GateCentres[id];
  172. nd += GateCentres[id].size();
  173. }
  174. return combined;
  175. } // ----- end of method TEMSurveyLineRecordData::GetCombinedGateCentres -----
  176. #ifdef HAVE_YAMLCPP
  177. //--------------------------------------------------------------------------------------
  178. // Class: TEMSurveyLineRecordData
  179. // Method: Serialize
  180. //--------------------------------------------------------------------------------------
  181. YAML::Node TEMSurveyLineRecordData::Serialize ( ) const {
  182. YAML::Node node = LemmaObject::Serialize();;
  183. node.SetTag( this->Name );
  184. node["numberOfSeries"] = DataSeries.size();
  185. for (unsigned int is=0; is<DataSeries.size(); ++is) {
  186. node[std::string("DataSeries_") + to_string(is)] = DataSeries[is];
  187. node[std::string("GateCentres_") + to_string(is)] = GateCentres[is];
  188. }
  189. return node;
  190. } // ----- end of method TEMSurveyLineRecordData::Serialize -----
  191. //--------------------------------------------------------------------------------------
  192. // Class: TEMSurveyLineRecordData
  193. // Method: DeSerialize
  194. //--------------------------------------------------------------------------------------
  195. TEMSurveyLineRecordData* TEMSurveyLineRecordData::DeSerialize ( const YAML::Node& node ) {
  196. TEMSurveyLineRecordData* Object = new TEMSurveyLineRecordData(node);
  197. Object->AttachTo(Object);
  198. DESERIALIZECHECK( node, Object )
  199. return Object ;
  200. } // ----- end of method TEMSurveyLineRecordData::DeSerialize -----
  201. #endif
  202. } // ----- end of Lemma name -----