Browse Source

Addition of VTK import class

add-code-of-conduct-1
Trevor Irons 6 years ago
parent
commit
363b18a061

+ 1
- 1
Modules/LemmaCore/CMakeLists.txt View File

@@ -46,7 +46,7 @@ if (LEMMA_ENABLE_TESTING)
46 46
 endif()
47 47
 
48 48
 # Install
49
-install (  TARGETS lemmacore DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
49
+install ( TARGETS lemmacore        DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
50 50
 install ( FILES include/LemmaCore  DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma ) 
51 51
 install ( DIRECTORY include/       DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Lemma  FILES_MATCHING PATTERN "*.h" )
52 52
 

+ 1
- 0
Modules/LemmaCore/include/LemmaCore View File

@@ -31,6 +31,7 @@
31 31
 #include "RectilinearGrid.h"
32 32
 #include "RectilinearGridReader.h"
33 33
 #include "RectilinearGridVTKExporter.h"
34
+#include "RectilinearGridVTKImporter.h"
34 35
 #include "WindowFilter.h"
35 36
 // helpers and utilities
36 37
 #include "banner.h"

+ 2
- 2
Modules/LemmaCore/include/RectilinearGridVTKExporter.h View File

@@ -12,9 +12,9 @@
12 12
  * @date      09/25/2013 08:20:01 AM
13 13
  * @version   $Id$
14 14
  * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
15
+ * @email     Trevor.Irons@LemmaSoftware.org
16 16
  * @copyright Copyright (c) 2013, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2013, Trevor Irons
17
+ * @copyright Copyright (c) 2013,2017,2018 Trevor Irons
18 18
  */
19 19
 
20 20
 

+ 161
- 0
Modules/LemmaCore/include/RectilinearGridVTKImporter.h View File

@@ -0,0 +1,161 @@
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:04:54
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@LemmaSoftware.org
16
+ * @copyright Copyright (c) 2018, University of Utah
17
+ * @copyright Copyright (c) 2018, Lemma Software, LLC
18
+ */
19
+
20
+#pragma once
21
+
22
+#ifndef  RECTILINEARGRIDVTKIMPORTER_INC
23
+#define  RECTILINEARGRIDVTKIMPORTER_INC
24
+
25
+#ifdef  LEMMAUSEVTK
26
+
27
+#pragma once
28
+#include "LemmaObject.h"
29
+#include "RectilinearGrid.h"
30
+
31
+#include "vtkSmartPointer.h"
32
+#include "vtkRectilinearGrid.h"
33
+#include "vtkDataArray.h"
34
+
35
+namespace Lemma {
36
+
37
+    /**
38
+     * \ingroup LemmaCore
39
+     * \brief
40
+     * \details
41
+     */
42
+    class RectilinearGridVTKImporter : public LemmaObject {
43
+
44
+        friend std::ostream &operator<<(std::ostream &stream, const RectilinearGridVTKImporter &ob);
45
+
46
+        protected:
47
+        /*
48
+         *  This key is used to lock the constructor. It is protected so that inhereted
49
+         *  classes also have the key to contruct their base class.
50
+         */
51
+        struct ctor_key {};
52
+
53
+        public:
54
+
55
+        // ====================  LIFECYCLE     =======================
56
+
57
+        /**
58
+         * Default constructor.
59
+         * @note This method is locked, and cannot be called directly.
60
+         *       The reason that the method is public is to enable the use
61
+         *       of make_shared whilst enforcing the use of shared_ptr,
62
+         *       in c++-17, this curiosity may be resolved.
63
+         * @see RectilinearGridVTKImporter::NewSP
64
+         */
65
+        explicit RectilinearGridVTKImporter ( const ctor_key& );
66
+
67
+        /**
68
+         * DeSerializing constructor.
69
+         * @note This method is locked, and cannot be called directly.
70
+         *       The reason that the method is public is to enable the use
71
+         *       of make_shared whilst enforcing the use of shared_ptr,
72
+         *       in c++-17, this curiosity may be resolved.
73
+         * @see RectilinearGridVTKImporter::DeSerialize
74
+         */
75
+        RectilinearGridVTKImporter ( const YAML::Node& node, const ctor_key& );
76
+
77
+        /**
78
+         * Default destructor.
79
+         * @note This method should never be called due to the mandated
80
+         *       use of smart pointers. It is necessary to keep the method
81
+         *       public in order to allow for the use of the more efficient
82
+         *       make_shared constructor.
83
+         */
84
+        virtual ~RectilinearGridVTKImporter ();
85
+
86
+        /**
87
+         *  Uses YAML to serialize this object.
88
+         *  @return a YAML::Node
89
+         *  @see RectilinearGridVTKImporter::DeSerialize
90
+         */
91
+        virtual YAML::Node Serialize() const;
92
+
93
+        /*
94
+         *  Factory method for generating concrete class.
95
+         *  @return a std::shared_ptr of type RectilinearGridVTKImporter
96
+         */
97
+        static std::shared_ptr< RectilinearGridVTKImporter > NewSP();
98
+
99
+        /**
100
+         *   Constructs an RectilinearGridVTKImporter object from a YAML::Node.
101
+         *   @see RectilinearGridVTKImporter::Serialize
102
+         */
103
+        static std::shared_ptr<RectilinearGridVTKImporter> DeSerialize(const YAML::Node& node);
104
+
105
+        // ====================  OPERATORS     =======================
106
+
107
+        // ====================  OPERATIONS    =======================
108
+
109
+        // ====================  ACCESS        =======================
110
+
111
+        /**
112
+         *  Sets the name of the VTK file to convert
113
+         */
114
+        void SetVTKInput( vtkSmartPointer<vtkRectilinearGrid> vgrid );
115
+
116
+        /**
117
+         *  Performs the actual grid conversion
118
+         */
119
+        void ConvertGrid( );
120
+
121
+
122
+        // ====================  INQUIRY       =======================
123
+        /**
124
+         *  Returns the name of the underlying class, similiar to Python's type
125
+         *  @return string of class name
126
+         */
127
+        virtual inline std::string GetName() const {
128
+            return CName;
129
+        }
130
+
131
+        protected:
132
+
133
+        // ====================  LIFECYCLE     =======================
134
+
135
+        /** Copy is disabled */
136
+        RectilinearGridVTKImporter( const RectilinearGridVTKImporter& ) = delete;
137
+
138
+        // ====================  DATA MEMBERS  =========================
139
+
140
+        private:
141
+
142
+        /** ASCII string representation of the class name */
143
+        static constexpr auto CName = "RectilinearGridVTKImporter";
144
+
145
+        /** VTK file to import */
146
+        vtkSmartPointer<vtkRectilinearGrid> vtkGrid;
147
+
148
+        std::shared_ptr<RectilinearGrid>  rGrid;
149
+
150
+    }; // -----  end of class  RectilinearGridVTKImporter  -----
151
+
152
+}  // -----  end of namespace Lemma ----
153
+
154
+/* vim: set tabstop=4 expandtab: */
155
+/* vim: set filetype=cpp: */
156
+
157
+
158
+#endif      // -----  LEMMAUSEVTK  -----
159
+
160
+#endif   // ----- #ifndef RECTILINEARGRIDVTKIMPORTER_INC  -----
161
+

+ 7
- 6
Modules/LemmaCore/src/CMakeLists.txt View File

@@ -2,14 +2,15 @@ set (SOURCE
2 2
 	${SOURCE}
3 3
 	${CMAKE_CURRENT_SOURCE_DIR}/helper.cpp
4 4
 	${CMAKE_CURRENT_SOURCE_DIR}/LemmaObject.cpp
5
-	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp                # fixed, key 
6
-	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp    # fixed, key 
5
+	${CMAKE_CURRENT_SOURCE_DIR}/ASCIIParser.cpp                # key 
6
+	${CMAKE_CURRENT_SOURCE_DIR}/CubicSplineInterpolator.cpp    # key 
7 7
 	${CMAKE_CURRENT_SOURCE_DIR}/Grid.cpp                       # ABC, no key 
8
-	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp            # fixed, key
9
-	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp      # fixed, key
10
-	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridVTKExporter.cpp # fixed, key
8
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGrid.cpp            # key
9
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridReader.cpp      # key
10
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridVTKExporter.cpp # key
11
+	${CMAKE_CURRENT_SOURCE_DIR}/RectilinearGridVTKImporter.cpp # key
11 12
 	${CMAKE_CURRENT_SOURCE_DIR}/Filter.cpp                     # ABC, no key
12
-	${CMAKE_CURRENT_SOURCE_DIR}/WindowFilter.cpp			   # fixed, key
13
+	${CMAKE_CURRENT_SOURCE_DIR}/WindowFilter.cpp			   # key
13 14
 	${CMAKE_CURRENT_SOURCE_DIR}/EarthModel.cpp                 # ABC, no key
14 15
 	${CMAKE_CURRENT_SOURCE_DIR}/LayeredEarth.cpp			   # ABC, no key
15 16
 	${CMAKE_CURRENT_SOURCE_DIR}/Data.cpp                       # ABC, no key

+ 1
- 1
Modules/LemmaCore/src/RectilinearGrid.cpp View File

@@ -16,7 +16,7 @@
16 16
 namespace Lemma {
17 17
 
18 18
     std::ostream &operator << (std::ostream &stream, const RectilinearGrid &ob) {
19
-        stream << ob.Serialize()  << "\n"; 
19
+        stream << ob.Serialize()  << "\n";
20 20
         return stream;
21 21
     }
22 22
 

+ 142
- 0
Modules/LemmaCore/src/RectilinearGridVTKImporter.cpp View File

@@ -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
+

Loading…
Cancel
Save