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.

RectilinearGridVTKExporter.cpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 09/25/2013 08:20:14 AM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2013, Trevor Irons
  15. */
  16. #if LEMMAUSEVTK
  17. #include "RectilinearGridVTKExporter.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. std::ostream &operator << (std::ostream &stream, const RectilinearGridVTKExporter &ob) {
  21. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  22. return stream;
  23. }
  24. // ==================== LIFECYCLE =======================
  25. //--------------------------------------------------------------------------------------
  26. // Class: RectilinearGridVTKExporter
  27. // Method: RectilinearGridVTKExporter
  28. // Description: constructor (protected)
  29. //--------------------------------------------------------------------------------------
  30. RectilinearGridVTKExporter::RectilinearGridVTKExporter ( ) : LemmaObject( ), Grid(nullptr), VTKGrid(nullptr) {
  31. } // ----- end of method RectilinearGridVTKExporter::RectilinearGridVTKExporter (constructor) -----
  32. //--------------------------------------------------------------------------------------
  33. // Class: RectilinearGridVTKExporter
  34. // Method: NewSP()
  35. // Description: public constructor
  36. //--------------------------------------------------------------------------------------
  37. std::shared_ptr< RectilinearGridVTKExporter > RectilinearGridVTKExporter::NewSP() {
  38. std::shared_ptr<RectilinearGridVTKExporter> sp(new RectilinearGridVTKExporter( ), LemmaObjectDeleter() );
  39. return sp;
  40. }
  41. //--------------------------------------------------------------------------------------
  42. // Class: RectilinearGridVTKExporter
  43. // Method: ~RectilinearGridVTKExporter
  44. // Description: destructor (protected)
  45. //--------------------------------------------------------------------------------------
  46. RectilinearGridVTKExporter::~RectilinearGridVTKExporter () {
  47. } // ----- end of method RectilinearGridVTKExporter::~RectilinearGridVTKExporter (destructor) -----
  48. //--------------------------------------------------------------------------------------
  49. // Class: RectilinearGridVTKExporter
  50. // Method: SetGrid
  51. //--------------------------------------------------------------------------------------
  52. void RectilinearGridVTKExporter::SetGrid ( std::shared_ptr<RectilinearGrid> GridIn ) {
  53. Grid = GridIn;
  54. // I see no harm in just doing this now.
  55. BuildVTKRectilinearGrid();
  56. return ;
  57. } // ----- end of method RectilinearGridVTKExporter::SetGrid -----
  58. //--------------------------------------------------------------------------------------
  59. // Class: RectilinearGridVTKExporter
  60. // Method: GetVTKRectilinearGrid
  61. //--------------------------------------------------------------------------------------
  62. vtkSmartPointer<vtkRectilinearGrid> RectilinearGridVTKExporter::GetVTKGrid ( ) {
  63. return VTKGrid;
  64. } // ----- end of method RectilinearGridVTKExporter::GetVTKRectilinearGrid -----
  65. //--------------------------------------------------------------------------------------
  66. // Class: RectilinearGridVTKExporter
  67. // Method: WriteVTKGrid
  68. //--------------------------------------------------------------------------------------
  69. void RectilinearGridVTKExporter::WriteVTKGrid ( const std::string& fname ) {
  70. vtkXMLRectilinearGridWriter *gridWrite = vtkXMLRectilinearGridWriter::New();
  71. gridWrite->SetInputData(VTKGrid);
  72. gridWrite->SetFileName( (fname+std::string(".vtr")).c_str() );
  73. gridWrite->Update();
  74. gridWrite->Write();
  75. gridWrite->Delete();
  76. return ;
  77. } // ----- end of method RectilinearGridVTKExporter::WriteVTKGrid -----
  78. //--------------------------------------------------------------------------------------
  79. // Class: RectilinearGridVTKExporter
  80. // Method: BuildVTKRectilinearGrid
  81. //--------------------------------------------------------------------------------------
  82. void RectilinearGridVTKExporter::BuildVTKRectilinearGrid ( ) {
  83. // Set Coordinate>s
  84. vtkDoubleArray *xCoords = vtkDoubleArray::New();
  85. xCoords->InsertNextValue(Grid->GetOx()-Grid->GetDx(0)/2.);
  86. double xm1 = Grid->GetOx() - Grid->GetDx(0)/2.;
  87. for (int ix=0; ix<Grid->GetNx(); ix++) {
  88. xCoords->InsertNextValue(xm1 + Grid->GetDx(ix));
  89. xm1 += Grid->GetDx(ix);
  90. }
  91. vtkDoubleArray *yCoords = vtkDoubleArray::New();
  92. yCoords->InsertNextValue(Grid->GetOy()-Grid->GetDy(0)/2.);
  93. double ym1 = Grid->GetOy()-Grid->GetDy(0)/2.;
  94. for (int iy=0; iy<Grid->GetNy(); iy++) {
  95. yCoords->InsertNextValue(ym1 + Grid->GetDy(iy));
  96. ym1 += Grid->GetDy(iy);
  97. }
  98. vtkDoubleArray *zCoords = vtkDoubleArray::New();
  99. zCoords->InsertNextValue(Grid->GetOz()-Grid->GetDz(0)/2.);
  100. double zm1 = Grid->GetOz()-Grid->GetDz(0)/2.;
  101. for (int iz=0; iz<Grid->GetNz(); iz++) {
  102. zCoords->InsertNextValue(zm1 + Grid->GetDz(iz));
  103. zm1 += Grid->GetDz(iz);
  104. }
  105. VTKGrid = vtkSmartPointer<vtkRectilinearGrid>::New();
  106. VTKGrid->SetDimensions(Grid->GetNx()+1, Grid->GetNy()+1, Grid->GetNz()+1);
  107. VTKGrid->SetXCoordinates(xCoords);
  108. VTKGrid->SetYCoordinates(yCoords);
  109. VTKGrid->SetZCoordinates(zCoords);
  110. // Clean up
  111. xCoords->Delete();
  112. yCoords->Delete();
  113. zCoords->Delete();
  114. return ;
  115. } // ----- end of method RectilinearGridVTKExporter::BuildVTKRectilinearGrid -----
  116. } // ----- end of Lemma name -----
  117. #endif // ----- not LEMMAUSEVTK -----