Main Lemma Repository
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TEMSurveyData.cpp 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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:00:22
  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 "TEMSurveyData.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurveyData &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 TEMSurveyData& ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // =================== OPERATORS ===============================
  32. TEMSurveyData* TEMSurveyData::operator + (const TEMSurveyData& d) {
  33. TEMSurveyData* clone = Clone();
  34. *clone += d;
  35. return clone;
  36. }
  37. void TEMSurveyData::operator += (const TEMSurveyData& rhs) {
  38. if ( this->GetNumberOfLines() != rhs.GetNumberOfLines() ) {
  39. throw std::runtime_error( "Line mismatch in TEMSurveyData +=" );
  40. }
  41. for (int iline=0; iline<this->GetNumberOfLines(); ++iline ) {
  42. *(*this)(iline) += *rhs(iline);
  43. //*LineData[iline] += *rhs(iline);
  44. //*LineData[iline] += *rhs.GetLine(iline);
  45. }
  46. }
  47. void TEMSurveyData::operator -= (const TEMSurveyData& rhs) {
  48. if ( this->GetNumberOfLines() != rhs.GetNumberOfLines() ) {
  49. throw std::runtime_error( "Line mismatch in TEMSurveyData +=" );
  50. }
  51. for (int iline=0; iline<this->GetNumberOfLines(); ++iline ) {
  52. *(*this)(iline) -= *rhs(iline);
  53. //*LineData[iline] -= *rhs(iline);
  54. //*LineData[iline] -= *rhs.GetLine(iline);
  55. }
  56. }
  57. TEMSurveyData* TEMSurveyData::operator - (const TEMSurveyData& d) {
  58. TEMSurveyData* clone = Clone();
  59. *clone -= d;
  60. return clone;
  61. }
  62. TEMSurveyLineData* TEMSurveyData::operator( ) ( const int& idx ) const {
  63. return LineData[ idx ];
  64. }
  65. TEMSurveyLineRecordData* TEMSurveyData::operator( ) ( const int& iline, const int& irec ) const {
  66. return LineData[ iline ]->GetRecord( irec );
  67. }
  68. // ==================== LIFECYCLE =======================
  69. //--------------------------------------------------------------------------------------
  70. // Class: TEMSurveyData
  71. // Method: TEMSurveyData
  72. // Description: constructor (protected)
  73. //--------------------------------------------------------------------------------------
  74. TEMSurveyData::TEMSurveyData (const std::string& name) : LemmaObject(name) {
  75. } // ----- end of method TEMSurveyData::TEMSurveyData (constructor) -----
  76. #ifdef HAVE_YAMLCPP
  77. //--------------------------------------------------------------------------------------
  78. // Class: TEMSurveyData
  79. // Method: TEMSurveyData
  80. // Description: DeSerializing constructor (protected)
  81. //--------------------------------------------------------------------------------------
  82. TEMSurveyData::TEMSurveyData (const YAML::Node& node) : LemmaObject(node) {
  83. //SetNumberOfLines( node["numberOfLines"].as<int>( ) );
  84. for (int ii=0; ii< node["numberOfLines"].as<int>( ); ++ii) {
  85. //LineData.push_back( new TEMSurveyLineData("TEMSurveyLineData") );
  86. LineData.push_back( TEMSurveyLineData::DeSerialize( node[ std::string("line_") + to_string(ii)] ) );
  87. LineData[ii]->AttachTo(this);
  88. }
  89. } // ----- end of method TEMSurveyData::TEMSurveyData (constructor) -----
  90. #endif
  91. //--------------------------------------------------------------------------------------
  92. // Class: TEMSurveyData
  93. // Method: New()
  94. // Description: public constructor
  95. //--------------------------------------------------------------------------------------
  96. TEMSurveyData* TEMSurveyData::New() {
  97. TEMSurveyData* Obj = new TEMSurveyData("TEMSurveyData");
  98. Obj->AttachTo(Obj);
  99. return Obj;
  100. }
  101. //--------------------------------------------------------------------------------------
  102. // Class: TEMSurveyData
  103. // Method: Clone
  104. //--------------------------------------------------------------------------------------
  105. TEMSurveyData* TEMSurveyData::Clone ( ) {
  106. return TEMSurveyData::DeSerialize( this->Serialize() ) ;
  107. } // ----- end of method TEMSurveyData::Clone -----
  108. //--------------------------------------------------------------------------------------
  109. // Class: TEMSurveyData
  110. // Method: ~TEMSurveyData
  111. // Description: destructor (protected)
  112. //--------------------------------------------------------------------------------------
  113. TEMSurveyData::~TEMSurveyData () {
  114. } // ----- end of method TEMSurveyData::~TEMSurveyData (destructor) -----
  115. //--------------------------------------------------------------------------------------
  116. // Class: TEMSurveyData
  117. // Method: Delete
  118. // Description: public destructor
  119. //--------------------------------------------------------------------------------------
  120. void TEMSurveyData::Delete() {
  121. this->DetachFrom(this);
  122. }
  123. //--------------------------------------------------------------------------------------
  124. // Class: TEMSurveyData
  125. // Method: Release
  126. // Description: destructor (protected)
  127. //--------------------------------------------------------------------------------------
  128. void TEMSurveyData::Release() {
  129. // clean up any old lines
  130. for (std::vector<TEMSurveyLineData*>::iterator it = LineData.begin() ; it != LineData.end(); ++it) {
  131. (*it)->DetachFrom(this);
  132. (*it)->Delete();
  133. }
  134. delete this;
  135. }
  136. //--------------------------------------------------------------------------------------
  137. // Class: TEMSurveyData
  138. // Method: SetNumberOfLines
  139. //--------------------------------------------------------------------------------------
  140. void TEMSurveyData::SetNumberOfLines ( const int& nlines ) {
  141. // clean up any old lines
  142. for (std::vector<TEMSurveyLineData*>::iterator it = LineData.begin() ; it != LineData.end(); ++it) {
  143. (*it)->DetachFrom(this);
  144. }
  145. LineData.clear();
  146. // Allocate these lines
  147. LineData.reserve(nlines);
  148. for (int il=0; il<nlines; ++il) {
  149. LineData.push_back( TEMSurveyLineData::New() );
  150. LineData[il]->AttachTo(this);
  151. }
  152. return ;
  153. } // ----- end of method TEMSurveyData::SetNumberOfLines -----
  154. //--------------------------------------------------------------------------------------
  155. // Class: TEMSurveyData
  156. // Method: GetLine
  157. //--------------------------------------------------------------------------------------
  158. TEMSurveyLineData* TEMSurveyData::GetLine ( const int& iline) const {
  159. return LineData[iline] ;
  160. } // ----- end of method TEMSurveyData::GetLine -----
  161. //--------------------------------------------------------------------------------------
  162. // Class: TEMSurveyData
  163. // Method: GetNumberOfLines
  164. //--------------------------------------------------------------------------------------
  165. int TEMSurveyData::GetNumberOfLines ( ) const {
  166. return LineData.size() ;
  167. } // ----- end of method TEMSurveyData::GetNumberOfLines -----
  168. #ifdef HAVE_YAMLCPP
  169. //--------------------------------------------------------------------------------------
  170. // Class: TEMSurveyData
  171. // Method: Serialize
  172. //--------------------------------------------------------------------------------------
  173. YAML::Node TEMSurveyData::Serialize ( ) const {
  174. YAML::Node node = LemmaObject::Serialize();;
  175. node.SetTag( this->Name );
  176. node["numberOfLines"] = LineData.size();
  177. for (unsigned int it = 0; it<LineData.size(); ++it) {
  178. node[std::string("line_") + to_string(it)] = LineData[it]->Serialize();
  179. }
  180. return node;
  181. } // ----- end of method TEMSurveyData::Serialize -----
  182. //--------------------------------------------------------------------------------------
  183. // Class: TEMSurveyData
  184. // Method: DeSerialize
  185. //--------------------------------------------------------------------------------------
  186. TEMSurveyData* TEMSurveyData::DeSerialize ( const YAML::Node& node ) {
  187. TEMSurveyData* Object = new TEMSurveyData(node);
  188. Object->AttachTo(Object);
  189. DESERIALIZECHECK( node, Object )
  190. return Object ;
  191. } // ----- end of method TEMSurveyData::DeSerialize -----
  192. #endif
  193. } // ----- end of Lemma name -----