Browse Source

Progress towards vtkHyperTreeGrid support

master
Trevor Irons 5 years ago
parent
commit
afb6bb645a
7 changed files with 93 additions and 45 deletions
  1. 1
    1
      examples/KernelV0.cpp
  2. 7
    4
      include/Coupling.h
  3. 9
    5
      include/KernelV0.h
  4. 4
    4
      include/LoopInteractions.h
  5. 1
    0
      include/MerlinObject.h
  6. 2
    2
      src/Coupling.cpp
  7. 69
    29
      src/KernelV0.cpp

+ 1
- 1
examples/KernelV0.cpp View File

@@ -82,7 +82,7 @@ int main(int argc, char** argv) {
82 82
     //std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
83 83
     std::vector<std::string> tx = {std::string("Coil 1")};  //, std::string("Coil 2") };
84 84
     std::vector<std::string> rx = {std::string("Coil 2")};
85
-    Kern->CalculateK0( tx, rx, false );
85
+    Kern->CalculateK0( tx, rx, true );
86 86
 
87 87
 /*
88 88
     std::ofstream dout = std::ofstream(std::string("k-Tx2coil-Rx1coil-offset-")+ std::string(argv[1])+ std::string(".dat"));

+ 7
- 4
include/Coupling.h View File

@@ -26,9 +26,12 @@
26 26
 #include "EMEarth1D.h"
27 27
 
28 28
 #ifdef LEMMAUSEVTK
29
-#include "vtkHyperOctree.h"
30
-#include "vtkHyperOctreeCursor.h"
31
-#include "vtkXMLHyperOctreeWriter.h"
29
+//#include "vtkHyperOctree.h"
30
+//#include "vtkHyperOctreeCursor.h"
31
+//#include "vtkXMLHyperOctreeWriter.h"
32
+#include "vtkHyperTreeGrid.h"
33
+#include "vtkHyperTreeCursor.h"
34
+#include "vtkXMLHyperTreeGridWriter.h"
32 35
 #include "vtkDoubleArray.h"
33 36
 #endif
34 37
 
@@ -200,7 +203,7 @@ namespace Lemma {
200 203
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
201 204
                             const Complex& parentVal );
202 205
 
203
-        #ifdef LEMMAUSEVTK
206
+        #ifdef LEMMAUSEVTK6
204 207
         /**
205 208
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
206 209
          *  HyperOctree, which is useful for visualization.

+ 9
- 5
include/KernelV0.h View File

@@ -26,9 +26,13 @@
26 26
 #include "EMEarth1D.h"
27 27
 
28 28
 #ifdef LEMMAUSEVTK
29
-#include "vtkHyperOctree.h"
30
-#include "vtkHyperOctreeCursor.h"
31
-#include "vtkXMLHyperOctreeWriter.h"
29
+//#include "vtkHyperOctree.h"
30
+//#include "vtkHyperOctreeCursor.h"
31
+//#include "vtkXMLHyperOctreeWriter.h"
32
+#include "vtkHyperTreeGrid.h"
33
+#include "vtkHyperTreeCursor.h"
34
+#include "vtkXMLHyperTreeGridWriter.h"
35
+//#include "vtkHyperTreeGridLevelEntry.h" VTK 9
32 36
 #include "vtkDoubleArray.h"
33 37
 #endif
34 38
 
@@ -299,9 +303,9 @@ namespace Lemma {
299 303
          *  HyperOctree, which is useful for visualization.
300 304
          */
301 305
         void EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
302
-                            const VectorXcr& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
306
+                            const VectorXcr& parentVal, vtkHyperTreeGrid* octree, vtkHyperTreeCursor* curse );
303 307
 
304
-        void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
308
+        void GetPosition( vtkHyperTreeCursor* Cursor, Real* p );
305 309
         #endif
306 310
 
307 311
         // ====================  DATA MEMBERS  =========================

+ 4
- 4
include/LoopInteractions.h View File

@@ -26,7 +26,7 @@
26 26
 #include "EMEarth1D.h"
27 27
 #include "FieldPoints.h"
28 28
 
29
-#ifdef LEMMAUSEVTK
29
+#ifdef LEMMAUSEVTK6
30 30
 #include "vtkHyperOctree.h"
31 31
 #include "vtkHyperOctreeCursor.h"
32 32
 #include "vtkXMLHyperOctreeWriter.h"
@@ -232,7 +232,7 @@ namespace Lemma {
232 232
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
233 233
                             const Complex& parentVal );
234 234
 
235
-        #ifdef LEMMAUSEVTK
235
+        #ifdef LEMMAUSEVTK6
236 236
         /**
237 237
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
238 238
          *  HyperOctree, which is useful for visualization.
@@ -358,7 +358,7 @@ namespace Lemma {
358 358
         if (!vtkOutput) {
359 359
             EvaluateKids( Size, 0, cpos, Complex(100.));
360 360
         } else {
361
-        #ifdef LEMMAUSEVTK
361
+        #ifdef LEMMAUSEVTK6
362 362
             vtkHyperOctree* oct = vtkHyperOctree::New();
363 363
                 oct->SetDimension(3);
364 364
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
@@ -521,7 +521,7 @@ namespace Lemma {
521 521
         return;     // is leaf
522 522
     }
523 523
 
524
-    #ifdef LEMMAUSEVTK
524
+    #ifdef LEMMAUSEVTK6
525 525
     //--------------------------------------------------------------------------------------
526 526
     //       Class:  LoopInteractions
527 527
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation

+ 1
- 0
include/MerlinObject.h View File

@@ -119,6 +119,7 @@ namespace Lemma {
119 119
         static constexpr auto CName = "MerlinObject";
120 120
 
121 121
     }; // -----  end of class  MerlinObject  -----
122
+
122 123
 }  // -----  end of namespace Lemma ----
123 124
 
124 125
 /* vim: set tabstop=4 expandtab: */

+ 2
- 2
src/Coupling.cpp View File

@@ -165,7 +165,7 @@ namespace Lemma {
165 165
         if (!vtkOutput) {
166 166
             EvaluateKids( Size, 0, cpos, Complex(100.));
167 167
         } else {
168
-        #ifdef LEMMAUSEVTK
168
+        #ifdef LEMMAUSEVTK6
169 169
             vtkHyperOctree* oct = vtkHyperOctree::New();
170 170
                 oct->SetDimension(3);
171 171
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
@@ -336,7 +336,7 @@ namespace Lemma {
336 336
         return;     // is leaf
337 337
     }
338 338
 
339
-    #ifdef LEMMAUSEVTK
339
+    #ifdef LEMMAUSEVTK6
340 340
     //--------------------------------------------------------------------------------------
341 341
     //       Class:  Coupling
342 342
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation

+ 69
- 29
src/KernelV0.cpp View File

@@ -252,11 +252,37 @@ namespace Lemma {
252 252
             EvaluateKids( Size, 0, cpos, VectorXcr::Ones(PulseI.size()) );
253 253
         } else {
254 254
         #ifdef LEMMAUSEVTK
255
-            vtkHyperOctree* oct = vtkHyperOctree::New();
255
+            vtkHyperTreeGrid* oct = vtkHyperTreeGrid::New();
256
+
256 257
                 oct->SetDimension(3);
257
-                oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
258
-                oct->SetSize( Size(0), Size(1), Size(2) );
259
-            vtkHyperOctreeCursor* curse = oct->NewCellCursor();
258
+                vtkNew<vtkDoubleArray> xcoords;
259
+                    xcoords->SetNumberOfComponents(1);
260
+                    xcoords->SetNumberOfTuples(2);
261
+                    xcoords->SetTuple1( 0, Origin(0) );
262
+                    xcoords->SetTuple1( 1, Origin(0) + Size(0) );
263
+                    xcoords->SetName("northing (m)");
264
+                    oct->SetXCoordinates(xcoords);
265
+
266
+                vtkNew<vtkDoubleArray> ycoords;
267
+                    ycoords->SetNumberOfComponents(1);
268
+                    ycoords->SetNumberOfTuples(2);
269
+                    ycoords->SetTuple1( 0, Origin(1) );
270
+                    ycoords->SetTuple1( 1, Origin(1) + Size(1) );
271
+                    ycoords->SetName("easting (m)");
272
+                    oct->SetYCoordinates(ycoords);
273
+
274
+                vtkNew<vtkDoubleArray> zcoords;
275
+                    zcoords->SetNumberOfComponents(1);
276
+                    zcoords->SetNumberOfTuples(2);
277
+                    zcoords->SetTuple1( 0, Origin(2) );
278
+                    zcoords->SetTuple1( 1, Origin(2) + Size(2) );
279
+                    zcoords->SetName("depth (m)");
280
+                    oct->SetZCoordinates(zcoords);
281
+
282
+            //vtkHyperTreeGridLevelEntry* curse2 =  vtkHyperTreeGridLevelEntry::New(); // VTK 9
283
+            //std::cout << *oct << std::endl;
284
+            // TODO, check the index in NewCursor maybe points to which cell in the Rectilinear Grid?
285
+            vtkHyperTreeCursor* curse = oct->NewCursor(0, true); // true creates the cursor
260 286
                 curse->ToRoot();
261 287
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
262 288
 
@@ -322,26 +348,29 @@ namespace Lemma {
322 348
             for (auto leaf : LeafDictIdx) {
323 349
                 kerr->InsertTuple1( leaf.first, leaf.second );
324 350
             }
325
-
326
-            auto kri = oct->GetLeafData()->AddArray(kr);
327
-            auto kii = oct->GetLeafData()->AddArray(ki);
328
-            auto kmi = oct->GetLeafData()->AddArray(km);
329
-            auto kidi = oct->GetLeafData()->AddArray(kid);
330
-            auto keri = oct->GetLeafData()->AddArray(kerr);
331
-            auto khtr = oct->GetLeafData()->AddArray(htr);
332
-            auto khti = oct->GetLeafData()->AddArray(hti);
333
-            auto khrr = oct->GetLeafData()->AddArray(hrr);
334
-            auto khri = oct->GetLeafData()->AddArray(hri);
335
-
336
-            auto write = vtkXMLHyperOctreeWriter::New();
337
-                //write.SetDataModeToAscii()
338
-                write->SetInputData(oct);
351
+/* TODO fix
352
+            auto kri = oct->GetCellData()->AddArray(kr);
353
+            auto kii = oct->GetCellData()->AddArray(ki);
354
+            auto kmi = oct->GetCellData()->AddArray(km);
355
+            auto kidi = oct->GetCellData()->AddArray(kid);
356
+            auto keri = oct->GetCellData()->AddArray(kerr);
357
+            auto khtr = oct->GetCellData()->AddArray(htr);
358
+            auto khti = oct->GetCellData()->AddArray(hti);
359
+            auto khrr = oct->GetCellData()->AddArray(hrr);
360
+            auto khri = oct->GetCellData()->AddArray(hri);
361
+*/
362
+            std::cout << "Writing file...Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
363
+            auto write = vtkXMLHyperTreeGridWriter::New();
339 364
                 std::string fname = std::string("octree-") + to_string(ilay)
340
-                                  + std::string("-") + to_string(iq) + std::string(".vto");
365
+                                  + std::string("-") + to_string(iq) + std::string(".htg");
341 366
                 write->SetFileName(fname.c_str());
367
+                write->SetInputData(oct);
368
+                write->SetDataModeToBinary();
369
+                //write.SetDataModeToAscii()
370
+                //write->Update();
342 371
                 write->Write();
343 372
                 write->Delete();
344
-
373
+/*
345 374
             oct->GetLeafData()->RemoveArray( kri );
346 375
             oct->GetLeafData()->RemoveArray( kii );
347 376
             oct->GetLeafData()->RemoveArray( kmi );
@@ -361,7 +390,7 @@ namespace Lemma {
361 390
             hti->Delete();
362 391
             hrr->Delete();
363 392
             hri->Delete();
364
-
393
+*/
365 394
             }
366 395
             curse->Delete();
367 396
             oct->Delete();
@@ -568,7 +597,7 @@ namespace Lemma {
568 597
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
569 598
     //--------------------------------------------------------------------------------------
570 599
     void KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
571
-        const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
600
+        const VectorXcr& parentVal, vtkHyperTreeGrid* oct, vtkHyperTreeCursor* curse) {
572 601
 
573 602
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
574 603
         //std::cout.flush();
@@ -627,7 +656,9 @@ namespace Lemma {
627 656
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
628 657
         // Evaluate whether or not furthur splitting is needed
629 658
         if ( (((ksum - parentVal).array().abs() > tol).any() && level<maxLevel) || level < minLevel ) {
630
-            oct->SubdivideLeaf(curse);
659
+            // TODO Fix, 0 after curse is vtkIdType?
660
+            oct->SubdivideLeaf(curse, 0);
661
+            //std::cout << "Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
631 662
             for (int ichild=0; ichild<8; ++ichild) {
632 663
                 curse->ToChild(ichild);
633 664
                 Vector3r cp = pos; // Eigen complains about combining these
@@ -656,13 +687,19 @@ namespace Lemma {
656 687
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
657 688
          * visuals, but also 8x the storage...
658 689
          */
659
-        oct->SubdivideLeaf(curse);
690
+        // TODO Fix, 0 after curse is vtkIdType?
691
+        oct->SubdivideLeaf(curse, 0);
660 692
         for (int ichild=0; ichild<8; ++ichild) {
661 693
             curse->ToChild(ichild);
662
-            LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
663
-            LeafHt[curse->GetLeafId()] = Ht.col(ichild);
664
-            LeafHr[curse->GetLeafId()] = Hr.col(ichild);
665
-            LeafDictIdx[curse->GetLeafId()] = nleaves;
694
+            // TODO fix, GetLeafId to GetLevel??
695
+            //LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
696
+            //LeafHt[curse->GetLeafId()] = Ht.col(ichild);
697
+            //LeafHr[curse->GetLeafId()] = Hr.col(ichild);
698
+            //LeafDictIdx[curse->GetLeafId()] = nleaves;
699
+            LeafDict[curse->GetLevel()] = ksum/(8.*vol);
700
+            LeafHt[curse->GetLevel()] = Ht.col(ichild);
701
+            LeafHr[curse->GetLevel()] = Hr.col(ichild);
702
+            LeafDictIdx[curse->GetLevel()] = nleaves;
666 703
             curse->ToParent();
667 704
         }
668 705
 
@@ -676,12 +713,15 @@ namespace Lemma {
676 713
     //       Class:  KernelV0
677 714
     //      Method:  GetPosition
678 715
     //--------------------------------------------------------------------------------------
679
-    void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
716
+    void KernelV0::GetPosition( vtkHyperTreeCursor* Cursor, Real* p ) {
717
+        // TODO fix
718
+        /*
680 719
         Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
681 720
         //step  = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
682 721
         p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
683 722
         p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
684 723
         p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
724
+        */
685 725
     }
686 726
 
687 727
     #endif

Loading…
Cancel
Save