Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RectilinearGridVTKImporter.cpp 6.2KB

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