Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RectilinearGridVTKImporter.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 07/28/18 18:05:24
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@utah.edu
  14. * @copyright Copyright (c) 2018, University of Utah
  15. * @copyright Copyright (c) 2018, Lemma Software, LLC
  16. */
  17. #if LEMMAUSEVTK
  18. #include "RectilinearGridVTKImporter.h"
  19. namespace Lemma {
  20. // ==================== FRIEND METHODS =====================
  21. std::ostream &operator << (std::ostream &stream, const RectilinearGridVTKImporter &ob) {
  22. stream << ob.Serialize() << "\n";
  23. return stream;
  24. }
  25. // ==================== LIFECYCLE =======================
  26. //--------------------------------------------------------------------------------------
  27. // Class: RectilinearGridVTKImporter
  28. // Method: RectilinearGridVTKImporter
  29. // Description: constructor (locked)
  30. //--------------------------------------------------------------------------------------
  31. RectilinearGridVTKImporter::RectilinearGridVTKImporter (const ctor_key&) : LemmaObject( LemmaObject::ctor_key() ) {
  32. } // ----- end of method RectilinearGridVTKImporter::RectilinearGridVTKImporter (constructor) -----
  33. //--------------------------------------------------------------------------------------
  34. // Class: RectilinearGridVTKImporter
  35. // Method: RectilinearGridVTKImporter
  36. // Description: DeSerializing constructor (locked)
  37. //--------------------------------------------------------------------------------------
  38. RectilinearGridVTKImporter::RectilinearGridVTKImporter (const YAML::Node& node, const ctor_key&) : LemmaObject(node, LemmaObject::ctor_key()) {
  39. } // ----- end of method RectilinearGridVTKImporter::RectilinearGridVTKImporter (constructor) -----
  40. //--------------------------------------------------------------------------------------
  41. // Class: RectilinearGridVTKImporter
  42. // Method: NewSP()
  43. // Description: public constructor returing a shared_ptr
  44. //--------------------------------------------------------------------------------------
  45. std::shared_ptr< RectilinearGridVTKImporter > RectilinearGridVTKImporter::NewSP() {
  46. return std::make_shared< RectilinearGridVTKImporter >( ctor_key() );
  47. }
  48. //--------------------------------------------------------------------------------------
  49. // Class: RectilinearGridVTKImporter
  50. // Method: ~RectilinearGridVTKImporter
  51. // Description: destructor (protected)
  52. //--------------------------------------------------------------------------------------
  53. RectilinearGridVTKImporter::~RectilinearGridVTKImporter () {
  54. } // ----- end of method RectilinearGridVTKImporter::~RectilinearGridVTKImporter (destructor) -----
  55. //--------------------------------------------------------------------------------------
  56. // Class: RectilinearGridVTKImporter
  57. // Method: Serialize
  58. //--------------------------------------------------------------------------------------
  59. YAML::Node RectilinearGridVTKImporter::Serialize ( ) const {
  60. YAML::Node node = LemmaObject::Serialize();
  61. node.SetTag( GetName() );
  62. // FILL IN CLASS SPECIFICS HERE
  63. return node;
  64. } // ----- end of method RectilinearGridVTKImporter::Serialize -----
  65. //--------------------------------------------------------------------------------------
  66. // Class: RectilinearGridVTKImporter
  67. // Method: DeSerialize
  68. //--------------------------------------------------------------------------------------
  69. std::shared_ptr<RectilinearGridVTKImporter> RectilinearGridVTKImporter::DeSerialize ( const YAML::Node& node ) {
  70. if (node.Tag() != "RectilinearGridVTKImporter" ) {
  71. throw DeSerializeTypeMismatch( "RectilinearGridVTKImporter", node.Tag());
  72. }
  73. return std::make_shared< RectilinearGridVTKImporter > ( node, ctor_key() );
  74. } // ----- end of method RectilinearGridVTKImporter::DeSerialize -----
  75. //--------------------------------------------------------------------------------------
  76. // Class: RectilinearGridVTKImporter
  77. // Method: set_SetVTKInput
  78. //--------------------------------------------------------------------------------------
  79. void RectilinearGridVTKImporter::SetVTKInput ( vtkSmartPointer<vtkRectilinearGrid> vgrid ) {
  80. vtkGrid = vgrid;
  81. return ;
  82. } // ----- end of method RectilinearGridVTKImporter::set_SetVTKInput -----
  83. //--------------------------------------------------------------------------------------
  84. // Class: RectilinearGridVTKImporter
  85. // Method: ConvertGrid
  86. //--------------------------------------------------------------------------------------
  87. void RectilinearGridVTKImporter::ConvertGrid ( const Real& shiftx, const Real& shifty, const Real& shiftz ) {
  88. rGrid = RectilinearGrid::NewSP();
  89. int dims[3];
  90. vtkGrid->GetDimensions( dims );
  91. auto xcoords = vtkGrid->GetXCoordinates( );
  92. auto ycoords = vtkGrid->GetYCoordinates( );
  93. auto zcoords = vtkGrid->GetZCoordinates( );
  94. VectorXr dx = VectorXr(dims[0]-1);
  95. VectorXr dy = VectorXr(dims[1]-1);
  96. VectorXr dz = VectorXr(dims[2]-1);
  97. for (int ix=1; ix<dims[0]; ++ix) {
  98. dx(ix-1) = xcoords->GetTuple1(ix) - xcoords->GetTuple1(ix-1);
  99. }
  100. for (int iy=1; iy<dims[1]; ++iy) {
  101. dy(iy-1) = ycoords->GetTuple1(iy) - ycoords->GetTuple1(iy-1);
  102. }
  103. for (int iz=1; iz<dims[2]; ++iz) {
  104. dz(iz-1) = zcoords->GetTuple1(iz) - zcoords->GetTuple1(iz-1);
  105. }
  106. rGrid->SetDimensions( dims[0], dims[1], dims[2] );
  107. rGrid->SetOffset( xcoords->GetTuple1(0)+shiftx, ycoords->GetTuple1(0)+shifty, zcoords->GetTuple1(0)+shiftz );
  108. rGrid->SetSpacing( dx, dy, dz );
  109. return ;
  110. } // ----- end of method RectilinearGridVTKImporter::ConvertGrid -----
  111. } // ---- end of namespace Lemma ----
  112. /* vim: set tabstop=4 expandtab: */
  113. /* vim: set filetype=cpp: */
  114. #endif // ----- not LEMMAUSEVTK -----