|
@@ -0,0 +1,142 @@
|
|
1
|
+/* This file is part of Lemma, a geophysical modelling and inversion API.
|
|
2
|
+ * More information is available at http://lemmasoftware.org
|
|
3
|
+ */
|
|
4
|
+
|
|
5
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
6
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
8
|
+ */
|
|
9
|
+
|
|
10
|
+/**
|
|
11
|
+ * @file
|
|
12
|
+ * @date 07/28/18 18:05:24
|
|
13
|
+ * @version $Id$
|
|
14
|
+ * @author Trevor Irons (ti)
|
|
15
|
+ * @email Trevor.Irons@utah.edu
|
|
16
|
+ * @copyright Copyright (c) 2018, University of Utah
|
|
17
|
+ * @copyright Copyright (c) 2018, Lemma Software, LLC
|
|
18
|
+ */
|
|
19
|
+
|
|
20
|
+#include "RectilinearGridVTKImporter.h"
|
|
21
|
+
|
|
22
|
+namespace Lemma {
|
|
23
|
+
|
|
24
|
+ // ==================== FRIEND METHODS =====================
|
|
25
|
+
|
|
26
|
+ std::ostream &operator << (std::ostream &stream, const RectilinearGridVTKImporter &ob) {
|
|
27
|
+ stream << ob.Serialize() << "\n";
|
|
28
|
+ return stream;
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ // ==================== LIFECYCLE =======================
|
|
32
|
+
|
|
33
|
+ //--------------------------------------------------------------------------------------
|
|
34
|
+ // Class: RectilinearGridVTKImporter
|
|
35
|
+ // Method: RectilinearGridVTKImporter
|
|
36
|
+ // Description: constructor (locked)
|
|
37
|
+ //--------------------------------------------------------------------------------------
|
|
38
|
+ RectilinearGridVTKImporter::RectilinearGridVTKImporter (const ctor_key&) : LemmaObject( LemmaObject::ctor_key() ) {
|
|
39
|
+
|
|
40
|
+ } // ----- end of method RectilinearGridVTKImporter::RectilinearGridVTKImporter (constructor) -----
|
|
41
|
+
|
|
42
|
+ //--------------------------------------------------------------------------------------
|
|
43
|
+ // Class: RectilinearGridVTKImporter
|
|
44
|
+ // Method: RectilinearGridVTKImporter
|
|
45
|
+ // Description: DeSerializing constructor (locked)
|
|
46
|
+ //--------------------------------------------------------------------------------------
|
|
47
|
+ RectilinearGridVTKImporter::RectilinearGridVTKImporter (const YAML::Node& node, const ctor_key&) : LemmaObject(node, LemmaObject::ctor_key()) {
|
|
48
|
+
|
|
49
|
+ } // ----- end of method RectilinearGridVTKImporter::RectilinearGridVTKImporter (constructor) -----
|
|
50
|
+
|
|
51
|
+ //--------------------------------------------------------------------------------------
|
|
52
|
+ // Class: RectilinearGridVTKImporter
|
|
53
|
+ // Method: NewSP()
|
|
54
|
+ // Description: public constructor returing a shared_ptr
|
|
55
|
+ //--------------------------------------------------------------------------------------
|
|
56
|
+ std::shared_ptr< RectilinearGridVTKImporter > RectilinearGridVTKImporter::NewSP() {
|
|
57
|
+ return std::make_shared< RectilinearGridVTKImporter >( ctor_key() );
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ //--------------------------------------------------------------------------------------
|
|
61
|
+ // Class: RectilinearGridVTKImporter
|
|
62
|
+ // Method: ~RectilinearGridVTKImporter
|
|
63
|
+ // Description: destructor (protected)
|
|
64
|
+ //--------------------------------------------------------------------------------------
|
|
65
|
+ RectilinearGridVTKImporter::~RectilinearGridVTKImporter () {
|
|
66
|
+
|
|
67
|
+ } // ----- end of method RectilinearGridVTKImporter::~RectilinearGridVTKImporter (destructor) -----
|
|
68
|
+
|
|
69
|
+ //--------------------------------------------------------------------------------------
|
|
70
|
+ // Class: RectilinearGridVTKImporter
|
|
71
|
+ // Method: Serialize
|
|
72
|
+ //--------------------------------------------------------------------------------------
|
|
73
|
+ YAML::Node RectilinearGridVTKImporter::Serialize ( ) const {
|
|
74
|
+ YAML::Node node = LemmaObject::Serialize();
|
|
75
|
+ node.SetTag( GetName() );
|
|
76
|
+ // FILL IN CLASS SPECIFICS HERE
|
|
77
|
+ return node;
|
|
78
|
+ } // ----- end of method RectilinearGridVTKImporter::Serialize -----
|
|
79
|
+
|
|
80
|
+ //--------------------------------------------------------------------------------------
|
|
81
|
+ // Class: RectilinearGridVTKImporter
|
|
82
|
+ // Method: DeSerialize
|
|
83
|
+ //--------------------------------------------------------------------------------------
|
|
84
|
+ std::shared_ptr<RectilinearGridVTKImporter> RectilinearGridVTKImporter::DeSerialize ( const YAML::Node& node ) {
|
|
85
|
+ if (node.Tag() != "RectilinearGridVTKImporter" ) {
|
|
86
|
+ throw DeSerializeTypeMismatch( "RectilinearGridVTKImporter", node.Tag());
|
|
87
|
+ }
|
|
88
|
+ return std::make_shared< RectilinearGridVTKImporter > ( node, ctor_key() );
|
|
89
|
+ } // ----- end of method RectilinearGridVTKImporter::DeSerialize -----
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+ //--------------------------------------------------------------------------------------
|
|
93
|
+ // Class: RectilinearGridVTKImporter
|
|
94
|
+ // Method: set_SetVTKInput
|
|
95
|
+ //--------------------------------------------------------------------------------------
|
|
96
|
+ void RectilinearGridVTKImporter::SetVTKInput ( vtkSmartPointer<vtkRectilinearGrid> vgrid ) {
|
|
97
|
+ vtkGrid = vgrid;
|
|
98
|
+
|
|
99
|
+ return ;
|
|
100
|
+ } // ----- end of method RectilinearGridVTKImporter::set_SetVTKInput -----
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+ //--------------------------------------------------------------------------------------
|
|
104
|
+ // Class: RectilinearGridVTKImporter
|
|
105
|
+ // Method: ConvertGrid
|
|
106
|
+ //--------------------------------------------------------------------------------------
|
|
107
|
+ void RectilinearGridVTKImporter::ConvertGrid ( ) {
|
|
108
|
+ rGrid = RectilinearGrid::NewSP();
|
|
109
|
+
|
|
110
|
+ int dims[3];
|
|
111
|
+ vtkGrid->GetDimensions( dims );
|
|
112
|
+ auto xcoords = vtkGrid->GetXCoordinates( );
|
|
113
|
+ auto ycoords = vtkGrid->GetYCoordinates( );
|
|
114
|
+ auto zcoords = vtkGrid->GetZCoordinates( );
|
|
115
|
+
|
|
116
|
+ VectorXr dx = VectorXr(dims[0]-1);
|
|
117
|
+ VectorXr dy = VectorXr(dims[1]-1);
|
|
118
|
+ VectorXr dz = VectorXr(dims[2]-1);
|
|
119
|
+
|
|
120
|
+ for (int ix=1; ix<dims[0]; ++ix) {
|
|
121
|
+ dx(ix-1) = xcoords->GetTuple1(ix) - xcoords->GetTuple1(ix-1);
|
|
122
|
+ }
|
|
123
|
+ for (int iy=1; iy<dims[1]; ++iy) {
|
|
124
|
+ dy(iy-1) = ycoords->GetTuple1(iy) - ycoords->GetTuple1(iy-1);
|
|
125
|
+ }
|
|
126
|
+ for (int iz=1; iz<dims[2]; ++iz) {
|
|
127
|
+ dz(iz-1) = zcoords->GetTuple1(iz) - zcoords->GetTuple1(iz-1);
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ rGrid->SetDimensions( dims[0], dims[1], dims[2] );
|
|
131
|
+ rGrid->SetOffset( xcoords->GetTuple1(0), ycoords->GetTuple1(0), zcoords->GetTuple1(0) );
|
|
132
|
+ rGrid->SetSpacing( dx, dy, dz );
|
|
133
|
+
|
|
134
|
+ return ;
|
|
135
|
+ } // ----- end of method RectilinearGridVTKImporter::ConvertGrid -----
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+} // ---- end of namespace Lemma ----
|
|
139
|
+
|
|
140
|
+/* vim: set tabstop=4 expandtab: */
|
|
141
|
+/* vim: set filetype=cpp: */
|
|
142
|
+
|