Переглянути джерело

Added example files but no CMakeLists.txt yet. Testing branching.

iss2
Trevor Irons 8 роки тому
джерело
коміт
5e3f64b97d

+ 493
- 0
examples/utFEM4EllipticPDE.cpp Переглянути файл

@@ -0,0 +1,493 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utFEM4EllipticPDE.cpp
4
+//
5
+//        Created:  08/16/12 19:49:10
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     08/16/12
34
+  @version   0.0
35
+ **/
36
+
37
+#include "FEM4EllipticPDE.h"
38
+#include "vtkSphere.h"
39
+#include "vtkRectilinearGrid.h"
40
+#include "vtkFloatArray.h"
41
+#include <vtkIdList.h>
42
+#include <vtkIdTypeArray.h>
43
+#include <vtkCell.h>
44
+#include <vtkTriangleFilter.h>
45
+#include <vtkDataSetSurfaceFilter.h>
46
+#include <vtkExtractCells.h>
47
+#include <vtkGeometryFilter.h>
48
+#include <vtkUnstructuredGrid.h>
49
+#include <vtkExtractEdges.h>
50
+#include <vtkImplicitDataSet.h>
51
+
52
+// debugging stuff
53
+#include <vtkDataSetMapper.h>
54
+#include <vtkSelectionNode.h>
55
+#include <vtkExtractSelection.h>
56
+#include <vtkSelection.h>
57
+#include <vtkVertexGlyphFilter.h>
58
+
59
+#define RENDERTEST
60
+//#define CONNECTTEST
61
+
62
+#ifdef RENDERTEST
63
+#include "vtkRectilinearGridGeometryFilter.h"
64
+#include "vtkRectilinearGridOutlineFilter.h"
65
+#include "vtkPolyDataMapper.h"
66
+#include "vtkActor.h"
67
+#include "vtkRenderWindowInteractor.h"
68
+#include "vtkRenderer.h"
69
+#include "vtkRenderWindow.h"
70
+#include "vtkCamera.h"
71
+#include "vtkProperty.h"
72
+#include <vtkDataSetMapper.h>
73
+#include <vtkSelectionNode.h>
74
+#include <vtkSelection.h>
75
+#include <vtkExtractSelection.h>
76
+#include <vtkExtractEdges.h>
77
+#include <vtkVertexGlyphFilter.h>
78
+#include <vtkTriangleFilter.h>
79
+#include <vtkImplicitHalo.h>
80
+#endif
81
+
82
+#ifdef CONNECTTEST
83
+#include <vtkVersion.h>
84
+#include <vtkSmartPointer.h>
85
+#include <vtkPolyData.h>
86
+#include <vtkCellData.h>
87
+#include <vtkDoubleArray.h>
88
+#include <vtkDataSet.h>
89
+#include <vtkSphereSource.h>
90
+#include <vtkTriangleFilter.h>
91
+#include <vtkExtractEdges.h>
92
+#include <vtkDataSetMapper.h>
93
+#include <vtkActor.h>
94
+#include <vtkRenderWindow.h>
95
+#include <vtkRenderer.h>
96
+#include <vtkRenderWindowInteractor.h>
97
+#include <vtkSelectionNode.h>
98
+#include <vtkSelection.h>
99
+#include <vtkExtractSelection.h>
100
+#include <vtkProperty.h>
101
+#include <vtkVertexGlyphFilter.h>
102
+#endif
103
+
104
+vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkDataSet> mesh, int id);
105
+vtkSmartPointer<vtkIdList> GetConnectedVertices2(vtkSmartPointer<vtkPolyData> mesh, int id);
106
+
107
+// This function is copyright (C) 2012 Joeseph Cappriotti
108
+vtkSmartPointer<vtkIdList> GetConnectedPoints(int id0, vtkSmartPointer<vtkDataSet> grid);
109
+
110
+using namespace Lemma;
111
+
112
+int main() {
113
+
114
+    // Define Sigma term
115
+    // Defaults to 1, (Poisson equation)
116
+
117
+    // Define source (G) term
118
+    //vtkSphere *Sphere = vtkSphere::New();
119
+    vtkImplicitHalo *Sphere = vtkImplicitHalo::New();
120
+        Sphere->SetCenter (0, 0, 0);
121
+        Sphere->SetRadius (60);
122
+        Sphere->SetFadeOut(.95);
123
+
124
+    ////////////////////////////////////////////
125
+    // Define solution mesh
126
+
127
+    // Create a rectilinear grid by defining three arrays specifying the
128
+    // coordinates in the x-y-z directions.
129
+
130
+    int    nx = 160;
131
+    double dx = 2.5;
132
+    double ox = -200;
133
+    vtkFloatArray *xCoords = vtkFloatArray::New();
134
+    for (int i=0; i<nx+1; i++) xCoords->InsertNextValue(ox + i*dx);
135
+
136
+    int    ny = 160;
137
+    double dy = 2.5;
138
+    double oy = -200;
139
+    vtkFloatArray *yCoords = vtkFloatArray::New();
140
+    for (int i=0; i<ny+1; i++) yCoords->InsertNextValue(oy + i*dy);
141
+
142
+    int    nz = 160;
143
+    double dz = 2.5;
144
+    double oz = -200;
145
+    vtkFloatArray *zCoords = vtkFloatArray::New();
146
+    for (int i=0; i<nz+1; i++) zCoords->InsertNextValue(oz + i*dz);
147
+
148
+    vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
149
+        rGrid->SetDimensions(nx+1, ny+1, nz+1);
150
+        rGrid->SetExtent(0, nx, 0, ny, 0,  nz);
151
+        rGrid->SetXCoordinates(xCoords);
152
+        rGrid->SetYCoordinates(yCoords);
153
+        rGrid->SetZCoordinates(zCoords);
154
+
155
+    vtkRectilinearGrid *sigGrid = vtkRectilinearGrid::New();
156
+        sigGrid->SetDimensions(nx+1, ny+1, nz+1);
157
+        sigGrid->SetExtent(0, nx, 0, ny, 0, nz);
158
+        sigGrid->SetXCoordinates(xCoords);
159
+        sigGrid->SetYCoordinates(yCoords);
160
+        sigGrid->SetZCoordinates(zCoords);
161
+        vtkDoubleArray *sigArray = vtkDoubleArray::New();
162
+        sigArray->SetNumberOfComponents(1);
163
+        for (int ii=0; ii<(nx+1)*(ny+1)*(nz+1); ++ii) {
164
+            sigArray->InsertTuple1(ii, 1.);
165
+        }
166
+        sigArray->SetName("sigma");
167
+        sigGrid->GetPointData()->AddArray(sigArray);
168
+        sigGrid->GetPointData()->SetScalars(sigArray);
169
+
170
+    vtkImplicitDataSet* implSigma = vtkImplicitDataSet::New();
171
+        implSigma->SetDataSet(sigGrid);
172
+        implSigma->SetOutValue(0.);
173
+        implSigma->SetOutGradient(0., 0., 0.);
174
+
175
+    FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
176
+        Solver->SetGFunction(Sphere);
177
+        //Solver->SetSigmaFunction(implSigma);
178
+        Solver->SetBoundaryStep(.5);
179
+        Solver->SetGrid(rGrid);
180
+        Solver->Solve("FEM_results.vtr");
181
+
182
+    vtkXMLDataSetWriter *Writer = vtkXMLDataSetWriter::New();
183
+        Writer->SetInputData(sigGrid);
184
+        std::string fname("sigma.vtr");
185
+        //Writer->Update();
186
+        //fname.append( Writer->GetDefaultFileExtension() );
187
+        Writer->SetFileName(fname.c_str());
188
+        Writer->Write();
189
+        Writer->Delete();
190
+
191
+    // Clean up
192
+    Sphere->Delete();
193
+    Solver->Delete();
194
+    rGrid->Delete();
195
+    xCoords->Delete();
196
+    yCoords->Delete();
197
+    zCoords->Delete();
198
+
199
+}
200
+
201
+// This function is copyright (C) 2012 Joeseph Cappriotti
202
+vtkSmartPointer<vtkIdList> GetConnectedPoints(int id0, vtkSmartPointer<vtkDataSet> grid){
203
+    vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
204
+    vtkSmartPointer<vtkIdList> cellList = vtkSmartPointer<vtkIdList>::New();
205
+    grid->GetPointCells(id0, cellList);
206
+    for(int i=0;i<cellList->GetNumberOfIds();++i){
207
+        vtkCell* cell = grid->GetCell(cellList->GetId(i));
208
+        if(cell->GetNumberOfEdges() > 0){
209
+            for(int j=0; j<cell->GetNumberOfEdges(); ++j){
210
+                vtkCell* edge = cell->GetEdge(j);
211
+                vtkIdList* edgePoints=edge->GetPointIds();
212
+                if(edgePoints->GetId(0)==id0){
213
+                    pointIds->InsertUniqueId(edgePoints->GetId(1));
214
+                }else if(edgePoints->GetId(1)==id0){
215
+                    pointIds->InsertUniqueId(edgePoints->GetId(0));
216
+                }
217
+            }
218
+        }
219
+    }
220
+    return pointIds;
221
+}
222
+
223
+vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkDataSet> mesh, int id) {
224
+
225
+    std::cout << "number of points " << mesh->GetNumberOfPoints() << std::endl;
226
+    std::cout << "number of cells " << mesh->GetNumberOfCells() << std::endl;
227
+
228
+    vtkSmartPointer<vtkIdList> connectedVertices = vtkSmartPointer<vtkIdList>::New();
229
+
230
+    //get all cells that vertex 'id' is a part of
231
+    vtkSmartPointer<vtkIdList> cellIdList = vtkSmartPointer<vtkIdList>::New();
232
+    mesh->GetPointCells(id, cellIdList);   // cells using point
233
+    //mesh->GetCellPoints(id, cellIdList); // points defining cell
234
+
235
+    cout << "Vertex " << id << " is used in cell(s) ";
236
+    for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
237
+        cout << cellIdList->GetId(i) << ", ";
238
+    }
239
+    cout << endl;
240
+
241
+    // TODO this is where things don't work
242
+    // for each cell, figure out what vertices are connected
243
+    for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
244
+
245
+        cout << "\tcell id " << i << " : " << cellIdList->GetId(i) << endl;
246
+        std::cout << "\tcell has " << mesh->GetCell(i)->GetNumberOfPoints() << " points\n";
247
+
248
+        vtkExtractCells *Cell = vtkExtractCells::New();
249
+            Cell->SetInputData(mesh);
250
+            Cell->AddCellRange(i, i);
251
+            Cell->Update();
252
+
253
+        //std::cout << *Cell->GetOutput() << std::endl;
254
+
255
+        // extract surface
256
+        vtkDataSetSurfaceFilter *surf = vtkDataSetSurfaceFilter::New();
257
+            surf->UseStripsOn();
258
+            surf->SetInputData(Cell->GetOutput());
259
+            surf->Update();
260
+
261
+        //std::cout << *surf->GetOutput() << std::endl;
262
+
263
+        vtkSmartPointer<vtkTriangleFilter> triangleFilter =
264
+             vtkSmartPointer<vtkTriangleFilter>::New();
265
+        triangleFilter->SetInputData( surf->GetOutput() );
266
+            triangleFilter->Update();
267
+
268
+        vtkSmartPointer<vtkExtractEdges> extractEdges =
269
+            vtkSmartPointer<vtkExtractEdges>::New();
270
+        extractEdges->SetInputConnection(triangleFilter->GetOutputPort());
271
+            extractEdges->Update();
272
+
273
+        vtkSmartPointer<vtkPolyData> pmesh = extractEdges->GetOutput();
274
+        //vtkSmartPointer<vtkPolyData> pmesh = triangleFilter->GetOutput();
275
+        //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(surf->GetOutput(), id);
276
+//
277
+//         //vtkSmartPointer<vtkIdTypeArray> ids =
278
+//         //vtkSmartPointer<vtkIdTypeArray>::New();
279
+//         //ids->SetNumberOfComponents(1);
280
+//
281
+        vtkSmartPointer<vtkIdList> pointIdList = vtkSmartPointer<vtkIdList>::New();
282
+        //mesh->GetPointCells(cellIdList->GetId(i), pointIdList); // returns cells using point
283
+        mesh->GetCellPoints(cellIdList->GetId(i), pointIdList);   // points defining cell
284
+
285
+        //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(pmesh, id);
286
+        vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(surf->GetOutput(), id);
287
+        //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(triangleFilter->GetOutput(), 1);
288
+        std::cout << "\tPoly Connected vertices: ";
289
+        for(vtkIdType ip = 0; ip < pconnectedVertices->GetNumberOfIds(); ip++) {
290
+            std::cout << pconnectedVertices->GetId(ip) << " ";
291
+            //ids->InsertNextValue(connectedVertices->GetId(i));
292
+            connectedVertices->InsertNextId( pointIdList->GetId( pconnectedVertices->GetId(ip) ) );
293
+        }
294
+        std::cout << std::endl;
295
+
296
+
297
+        cout << "\tcell " << i << " contains these points ";
298
+        for(vtkIdType ii = 0; ii < pointIdList->GetNumberOfIds(); ii++) {
299
+            cout << pointIdList->GetId(ii) << ", ";
300
+        }
301
+        cout << endl;
302
+
303
+        /*
304
+        cout << "\tEnd points are " << pointIdList->GetId(0) << " and " << pointIdList->GetId(1) << endl;
305
+
306
+        if(pointIdList->GetId(0) != id) {
307
+            //cout << "Connected to " << pointIdList->GetId(0) << endl;
308
+            connectedVertices->InsertNextId(pointIdList->GetId(0));
309
+        } else {
310
+            //cout << "Connected to " << pointIdList->GetId(1) << endl;
311
+            connectedVertices->InsertNextId(pointIdList->GetId(1));
312
+        }
313
+        */
314
+
315
+
316
+        #ifdef RENDERTEST
317
+        vtkSmartPointer<vtkDataSetMapper> sphereMapper =
318
+        vtkSmartPointer<vtkDataSetMapper>::New();
319
+            sphereMapper->SetInputConnection(extractEdges->GetOutputPort());
320
+        vtkSmartPointer<vtkActor> sphereActor =
321
+            vtkSmartPointer<vtkActor>::New();
322
+            sphereActor->SetMapper(sphereMapper);
323
+
324
+
325
+        vtkSmartPointer<vtkIdTypeArray> ids =
326
+            vtkSmartPointer<vtkIdTypeArray>::New();
327
+        ids->SetNumberOfComponents(1);
328
+
329
+        std::cout << "RENDERTEST Connected vertices: ";
330
+        for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); i++) {
331
+            std::cout << connectedVertices->GetId(i) << " ";
332
+            ids->InsertNextValue(connectedVertices->GetId(i));
333
+        }
334
+        std::cout << std::endl;
335
+
336
+        vtkSmartPointer<vtkDataSetMapper> connectedVertexMapper =
337
+        vtkSmartPointer<vtkDataSetMapper>::New();
338
+
339
+        {
340
+            vtkSmartPointer<vtkSelectionNode> selectionNode =
341
+                vtkSmartPointer<vtkSelectionNode>::New();
342
+            selectionNode->SetFieldType(vtkSelectionNode::POINT);
343
+            selectionNode->SetContentType(vtkSelectionNode::INDICES);
344
+            selectionNode->SetSelectionList(ids);
345
+
346
+            vtkSmartPointer<vtkSelection> selection =
347
+                vtkSmartPointer<vtkSelection>::New();
348
+            selection->AddNode(selectionNode);
349
+
350
+            vtkSmartPointer<vtkExtractSelection> extractSelection =
351
+                vtkSmartPointer<vtkExtractSelection>::New();
352
+
353
+            extractSelection->SetInputConnection(0, extractEdges->GetOutputPort());
354
+            extractSelection->SetInputData(1, selection);
355
+            extractSelection->Update();
356
+
357
+            vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
358
+                vtkSmartPointer<vtkVertexGlyphFilter>::New();
359
+            glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
360
+            glyphFilter->Update();
361
+
362
+            connectedVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
363
+        }
364
+
365
+        vtkSmartPointer<vtkActor> connectedVertexActor =
366
+            vtkSmartPointer<vtkActor>::New();
367
+        connectedVertexActor->SetMapper(connectedVertexMapper);
368
+        connectedVertexActor->GetProperty()->SetColor(1,0,0);
369
+        connectedVertexActor->GetProperty()->SetPointSize(5);
370
+
371
+        vtkSmartPointer<vtkDataSetMapper> queryVertexMapper =
372
+            vtkSmartPointer<vtkDataSetMapper>::New();
373
+
374
+        {
375
+            vtkSmartPointer<vtkIdTypeArray> ids =
376
+                vtkSmartPointer<vtkIdTypeArray>::New();
377
+            ids->SetNumberOfComponents(1);
378
+            ids->InsertNextValue(id);
379
+
380
+            vtkSmartPointer<vtkSelectionNode> selectionNode =
381
+                vtkSmartPointer<vtkSelectionNode>::New();
382
+            selectionNode->SetFieldType(vtkSelectionNode::POINT);
383
+            selectionNode->SetContentType(vtkSelectionNode::INDICES);
384
+            selectionNode->SetSelectionList(ids);
385
+
386
+            vtkSmartPointer<vtkSelection> selection =
387
+                vtkSmartPointer<vtkSelection>::New();
388
+            selection->AddNode(selectionNode);
389
+
390
+            vtkSmartPointer<vtkExtractSelection> extractSelection =
391
+                vtkSmartPointer<vtkExtractSelection>::New();
392
+
393
+            extractSelection->SetInputConnection(0, extractEdges->GetOutputPort());
394
+            extractSelection->SetInputData(1, selection);
395
+            extractSelection->Update();
396
+
397
+            vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
398
+                vtkSmartPointer<vtkVertexGlyphFilter>::New();
399
+            glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
400
+            glyphFilter->Update();
401
+
402
+            queryVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
403
+        }
404
+
405
+        vtkSmartPointer<vtkActor> queryVertexActor =
406
+            vtkSmartPointer<vtkActor>::New();
407
+        queryVertexActor->SetMapper(queryVertexMapper);
408
+        queryVertexActor->GetProperty()->SetColor(0,1,0);
409
+        queryVertexActor->GetProperty()->SetPointSize(5);
410
+
411
+        // Create the usual rendering stuff.
412
+        vtkRenderer *renderer = vtkRenderer::New();
413
+        vtkRenderWindow *renWin = vtkRenderWindow::New();
414
+        renWin->AddRenderer(renderer);
415
+        vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
416
+        iren->SetRenderWindow(renWin);
417
+
418
+        renderer->AddActor(queryVertexActor);
419
+        renderer->AddActor(connectedVertexActor);
420
+        renderer->AddActor(sphereActor);
421
+
422
+        //renderer->AddActor(wireActor);
423
+        //renderer->AddActor(owireActor);
424
+        renderer->SetBackground(.3,.2,.1);
425
+        renderer->ResetCamera();
426
+        renderer->GetActiveCamera()->Elevation(-150.0);
427
+        renderer->GetActiveCamera()->Azimuth(0.0);
428
+        renderer->GetActiveCamera()->Roll(0.0);
429
+        //renderer->GetActiveCamera()->Pitch(-45.0);
430
+        renderer->GetActiveCamera()->Zoom(1.0);
431
+
432
+        renWin->SetSize(300,300);
433
+
434
+        // interact with data
435
+        renWin->Render();
436
+        iren->Start();
437
+
438
+        // clean up rendering stuff
439
+        //plane->Delete();
440
+        //rgridMapper->Delete();
441
+        //wireActor->Delete();
442
+        //owireActor->Delete();
443
+        //outline->Delete();
444
+        //outlineMapper->Delete();
445
+        renderer->Delete();
446
+        renWin->Delete();
447
+        iren->Delete();
448
+        #endif // RENDERTEST
449
+
450
+        surf->Delete();
451
+        Cell->Delete();
452
+    }
453
+
454
+    return connectedVertices;
455
+}
456
+
457
+// from http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity
458
+vtkSmartPointer<vtkIdList> GetConnectedVertices2(vtkSmartPointer<vtkPolyData> mesh, int id) {
459
+
460
+    std::cout << "mesh points " << mesh->GetNumberOfPoints() << std::endl;
461
+
462
+    vtkSmartPointer<vtkIdList> connectedVertices =
463
+        vtkSmartPointer<vtkIdList>::New();
464
+
465
+    //get all cells that vertex 'id' is a part of
466
+    vtkSmartPointer<vtkIdList> cellIdList =
467
+        vtkSmartPointer<vtkIdList>::New();
468
+    mesh->GetPointCells(id, cellIdList);
469
+
470
+    /*
471
+    for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
472
+        cout << cellIdList->GetId(i) << ", ";
473
+    }
474
+    cout << endl;
475
+    */
476
+
477
+    for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
478
+        //cout << "id " << i << " : " << cellIdList->GetId(i) << endl;
479
+
480
+        vtkSmartPointer<vtkIdList> pointIdList =
481
+            vtkSmartPointer<vtkIdList>::New();
482
+        mesh->GetCellPoints(cellIdList->GetId(i), pointIdList);
483
+        //cout << "End points are " << pointIdList->GetId(0) << " and " << pointIdList->GetId(1) << endl;
484
+        if(pointIdList->GetId(0) != id) {
485
+            //cout << "Connected to " << pointIdList->GetId(0) << endl;
486
+            connectedVertices->InsertNextId(pointIdList->GetId(0));
487
+        } else {
488
+            //cout << "Connected to " << pointIdList->GetId(1) << endl;
489
+            connectedVertices->InsertNextId(pointIdList->GetId(1));
490
+        }
491
+    }
492
+    return connectedVertices;
493
+}

+ 173
- 0
examples/utFEM4EllipticPDE_bhmag.cpp Переглянути файл

@@ -0,0 +1,173 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utFEM4EllipticPDE.cpp
4
+//
5
+//        Created:  08/16/12 19:49:10
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     08/16/12
34
+  @version   0.0
35
+ **/
36
+
37
+#include "FEM4EllipticPDE.h"
38
+#include "vtkSphere.h"
39
+#include "vtkRectilinearGrid.h"
40
+#include "vtkFloatArray.h"
41
+#include <vtkIdList.h>
42
+#include <vtkIdTypeArray.h>
43
+#include <vtkCell.h>
44
+#include <vtkTriangleFilter.h>
45
+#include <vtkDataSetSurfaceFilter.h>
46
+#include <vtkExtractCells.h>
47
+#include <vtkGeometryFilter.h>
48
+#include <vtkUnstructuredGrid.h>
49
+#include <vtkExtractEdges.h>
50
+#include <vtkImplicitDataSet.h>
51
+#include <vtkXMLUnstructuredGridReader.h>
52
+
53
+// debugging stuff
54
+#include <vtkDataSetMapper.h>
55
+#include <vtkSelectionNode.h>
56
+#include <vtkExtractSelection.h>
57
+#include <vtkSelection.h>
58
+#include <vtkVertexGlyphFilter.h>
59
+
60
+#define RENDERTEST
61
+//#define CONNECTTEST
62
+
63
+#ifdef RENDERTEST
64
+#include "vtkRectilinearGridGeometryFilter.h"
65
+#include "vtkRectilinearGridOutlineFilter.h"
66
+#include "vtkPolyDataMapper.h"
67
+#include "vtkActor.h"
68
+#include "vtkRenderWindowInteractor.h"
69
+#include "vtkRenderer.h"
70
+#include "vtkRenderWindow.h"
71
+#include "vtkCamera.h"
72
+#include "vtkProperty.h"
73
+#include <vtkDataSetMapper.h>
74
+#include <vtkSelectionNode.h>
75
+#include <vtkSelection.h>
76
+#include <vtkExtractSelection.h>
77
+#include <vtkExtractEdges.h>
78
+#include <vtkVertexGlyphFilter.h>
79
+#include <vtkTriangleFilter.h>
80
+#include <vtkImplicitHalo.h>
81
+#endif
82
+
83
+using namespace Lemma;
84
+
85
+Real Magnet(const Real& x, const Real& y, const Real& z);
86
+
87
+int main(int argc, char**argv) {
88
+
89
+    if (argc < 4) {
90
+        std::cout << "usage: ./utFEMEllipticPDE_bhmag  <g.vtu>  <mesh.vtu>  <results.vtu>" << std::endl;
91
+        //std::cout << "usage: ./utFEMEllipticPDE_bhmag   <mesh.vtu>  <results.vtu>" << std::endl;
92
+        exit(EXIT_SUCCESS);
93
+    }
94
+
95
+    int    nx = 80;
96
+    //double dx =  .0021875 ; // 160
97
+    double dx =  .004375 ; // 160
98
+    double ox = -.175;
99
+    vtkFloatArray *xCoords = vtkFloatArray::New();
100
+    for (int i=0; i<nx+1; i++) xCoords->InsertNextValue(ox + i*dx);
101
+
102
+    int    ny = 80;
103
+    double dy =  .004375;
104
+    double oy = -.175;
105
+    vtkFloatArray *yCoords = vtkFloatArray::New();
106
+    for (int i=0; i<ny+1; i++) yCoords->InsertNextValue(oy + i*dy);
107
+
108
+    int    nz = 343; // 685; // 160
109
+    double dz = .004375;
110
+    double oz = 9.75;
111
+    vtkFloatArray *zCoords = vtkFloatArray::New();
112
+    for (int i=0; i<nz+1; i++) zCoords->InsertNextValue(oz + i*dz);
113
+
114
+    vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
115
+        rGrid->SetDimensions(nx+1, ny+1, nz+1);
116
+        rGrid->SetExtent(0, nx, 0, ny, 0,  nz);
117
+        rGrid->SetXCoordinates(xCoords);
118
+        rGrid->SetYCoordinates(yCoords);
119
+        rGrid->SetZCoordinates(zCoords);
120
+
121
+    ////////////////////////////////////////////
122
+    // Define Sigma/mu term
123
+    // TODO
124
+
125
+    ////////////////////////////////////////////
126
+    // Define source (G) term
127
+    vtkXMLUnstructuredGridReader* GReader = vtkXMLUnstructuredGridReader::New();
128
+        std::cout << "Reading G file " << argv[1] << std::endl;
129
+        GReader->SetFileName(argv[1]);
130
+        GReader->Update();
131
+
132
+    vtkImplicitDataSet* implG = vtkImplicitDataSet::New();
133
+        implG->SetDataSet(GReader->GetOutput());
134
+        implG->SetOutValue(0.);
135
+        implG->SetOutGradient(0., 0., 0.);
136
+
137
+    ////////////////////////////////////////////
138
+    // Define solution mesh
139
+    vtkXMLUnstructuredGridReader* MeshReader = vtkXMLUnstructuredGridReader::New();
140
+        std::cout << "Reading Mesh file " << argv[2] << std::endl;
141
+        MeshReader->SetFileName(argv[2]);
142
+        MeshReader->Update();
143
+
144
+    ////////////////////////////////////////////
145
+    // Solve
146
+    FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
147
+        Solver->SetGFunction(implG);
148
+        //Solver->SetGFunction(Magnet);
149
+        //Solver->SetSigmaFunction(implSigma);
150
+        Solver->SetBoundaryStep(.05);
151
+        Solver->SetGrid(MeshReader->GetOutput());
152
+        //Solver->SetGrid(rGrid);
153
+        Solver->Solve(argv[3]);
154
+
155
+    // Clean up
156
+    Solver->Delete();
157
+    GReader->Delete();
158
+    implG->Delete();
159
+
160
+    exit(EXIT_SUCCESS);
161
+}
162
+
163
+Real Magnet(const Real& x, const Real& y, const Real& z) {
164
+
165
+    if (z < 10 || z > 11 ) {
166
+        return 0.;
167
+    } else if ( std::sqrt(x*x + y*y) <= 0.05 ) {
168
+        if (x>0.) return  1.;
169
+        if (x<0.) return -1.;
170
+    }
171
+    return 0.;
172
+}
173
+

+ 104
- 0
examples/utVTKDC.cpp Переглянути файл

@@ -0,0 +1,104 @@
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      08/07/2014 04:16:25 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include <vtkUnstructuredGrid.h>
21
+
22
+#include <vtkUnstructuredGridReader.h>
23
+#include <vtkUnstructuredGridWriter.h>
24
+
25
+#include <vtkGenericDataObjectReader.h>
26
+
27
+#include <vtkXMLUnstructuredGridReader.h>
28
+#include <vtkXMLUnstructuredGridWriter.h>
29
+#include <vtkDoubleArray.h>
30
+#include <vtkPointData.h>
31
+
32
+#include <cmath>
33
+#include <Eigen/Core>
34
+
35
+#include "DCSurvey.h"
36
+#include "FEM4EllipticPDE.h"
37
+
38
+#ifdef HAVE_YAMLCPP
39
+#include "yaml-cpp/yaml.h"
40
+#endif
41
+
42
+using namespace Lemma;
43
+
44
+int main(int argc, char**argv) {
45
+
46
+    std::cout << "Mesh processing routine\n";
47
+    if (argc<4) {
48
+        std::cout << "usage:\n" << "./utVTKEdge  mesh.vtu  input.yaml   results.vtu"  << std::endl;
49
+        exit(EXIT_SUCCESS);
50
+    }
51
+
52
+    vtkUnstructuredGrid* uGrid = vtkUnstructuredGrid::New();
53
+
54
+    std::string fn = argv[1];
55
+    if(fn.substr(fn.find_last_of(".") + 1) == "vtk") {
56
+        vtkGenericDataObjectReader* Reader = vtkGenericDataObjectReader::New();
57
+            Reader->SetFileName(argv[1]);
58
+            Reader->Update();
59
+        if(Reader->IsFileUnstructuredGrid()) {
60
+            std::cout << "Found Unstructured grid legacy file" << std::endl;
61
+            uGrid = Reader->GetUnstructuredGridOutput();
62
+        } else {
63
+            std::cerr << "Unknown legacy format";
64
+            exit(EXIT_FAILURE);
65
+        }
66
+
67
+    } else {
68
+        vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
69
+            std::cout << "Reading" << argv[1] << std::endl;
70
+            Reader->SetFileName(argv[1]);
71
+            Reader->Update();
72
+            uGrid = Reader->GetOutput();
73
+    }
74
+    int nc = uGrid->GetNumberOfCells()  ;
75
+    int nn = uGrid->GetNumberOfPoints()  ;
76
+
77
+    std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
78
+
79
+    std::ifstream ifstr(argv[2]);
80
+    //std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
81
+    YAML::Node nodes = YAML::Load(ifstr);
82
+    DCSurvey* Survey = DCSurvey::DeSerialize(nodes);
83
+    //std::cout << *Survey << std::endl;
84
+
85
+
86
+    ////////////////////////////////////////////
87
+    // Solve
88
+    FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
89
+        //Solver->SetGFunction(implG);
90
+        //Solver->SetGFunction(Magnet);
91
+        //Solver->SetSigmaFunction(implSigma);
92
+        //Solver->SetBoundaryStep(.05);
93
+
94
+        Solver->SetGrid(uGrid);
95
+        Solver->SetupDC(Survey, 0);
96
+        Solver->Solve( argv[3] );
97
+        //Solver->SetGrid(rGrid);
98
+        //Solver->Solve(argv[3]);
99
+
100
+    Survey->Delete();
101
+    Solver->Delete();
102
+
103
+    exit(EXIT_SUCCESS);
104
+}

+ 95
- 0
examples/utVTKEdgeG.cpp Переглянути файл

@@ -0,0 +1,95 @@
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      08/07/2014 04:16:25 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include <vtkUnstructuredGrid.h>
21
+
22
+#include <vtkUnstructuredGridReader.h>
23
+#include <vtkUnstructuredGridWriter.h>
24
+
25
+#include <vtkXMLUnstructuredGridReader.h>
26
+#include <vtkXMLUnstructuredGridWriter.h>
27
+#include <vtkDoubleArray.h>
28
+#include <vtkPointData.h>
29
+
30
+#include <cmath>
31
+
32
+
33
+int main(int argc, char**argv) {
34
+
35
+    std::cout << "Mesh processing routine\n";
36
+    if (argc<3) {
37
+        std::cout << "usage:\n" << "./utVTKEdge  inMesh.vtu outG.vtu" << std::endl;
38
+    }
39
+
40
+    vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
41
+        std::cout << "Reading" << argv[1] << std::endl;
42
+        Reader->SetFileName(argv[1]);
43
+        Reader->Update();
44
+
45
+        int nc = Reader->GetOutput()->GetNumberOfCells()  ;
46
+        int nn = Reader->GetOutput()->GetNumberOfPoints()  ;
47
+
48
+    std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
49
+
50
+    // Input magnet size TODO get from file or .geo file even?
51
+    double R = .25;          // radius of magnet
52
+    double D0 = 10;          // Top of magnet
53
+    double D1 = 11;          // Bottom of magnet
54
+    double eps = 1e-2;       // epsilon for on the point
55
+    // Pol = double[3];
56
+
57
+    // Declare new array for the data
58
+    vtkDoubleArray* G = vtkDoubleArray::New();
59
+        G->SetNumberOfComponents(1);
60
+        G->SetNumberOfTuples(nn);
61
+        G->SetName("G");
62
+
63
+    // Loop over nodes, look at position, set with G if on boundary
64
+    double point[3];
65
+    for (int in=0; in<nn; ++in) {
66
+        Reader->GetOutput()->GetPoint(in, &point[0]);
67
+        //std::cout << point[0] << "\t" <<point[1] << "\t" << point[2] << std::endl;
68
+        double raddist = sqrt( point[0]*point[0] + point[1]*point[1] );
69
+        if ( raddist > R - eps && raddist < R + eps && point[2] < D1 && point[2] > D0 ) {
70
+            if ( point[1] < 0 ) {
71
+                G->InsertTuple1( in,   1 );
72
+            } else if (point[1] > 0) {
73
+                G->InsertTuple1( in,  -1 );
74
+            } else {
75
+                G->InsertTuple1( in, 0 );
76
+            }
77
+        } else {
78
+            G->InsertTuple1( in, 0 );
79
+        }
80
+
81
+    }
82
+
83
+    // Add new data
84
+    Reader->GetOutput()->GetPointData()->SetScalars( G );
85
+
86
+    // Write out new file
87
+    vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
88
+        Writer->SetInputConnection(Reader->GetOutputPort());
89
+        Writer->SetFileName( argv[2] );
90
+        Writer->Write();
91
+
92
+    Reader->Delete();
93
+
94
+
95
+}

+ 172
- 0
examples/utVTKEdgeGsphere.cpp Переглянути файл

@@ -0,0 +1,172 @@
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      08/07/2014 04:16:25 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include <vtkUnstructuredGrid.h>
21
+
22
+#include <vtkUnstructuredGridReader.h>
23
+#include <vtkUnstructuredGridWriter.h>
24
+
25
+#include <vtkGenericDataObjectReader.h>
26
+
27
+#include <vtkXMLUnstructuredGridReader.h>
28
+#include <vtkXMLUnstructuredGridWriter.h>
29
+#include <vtkDoubleArray.h>
30
+#include <vtkPointData.h>
31
+
32
+#include <cmath>
33
+#include <Eigen/Core>
34
+
35
+const double PI = 4.0*atan(1.0);
36
+
37
+int main(int argc, char**argv) {
38
+
39
+    std::cout << "Mesh processing routine\n";
40
+    if (argc<4) {
41
+        std::cout << "usage:\n" << "./utVTKEdge  inMesh.vtu  <radius> <problemType>  outG.vtu" << std::endl;
42
+        exit(EXIT_SUCCESS);
43
+    }
44
+
45
+    vtkUnstructuredGrid* uGrid = vtkUnstructuredGrid::New();
46
+
47
+    std::string fn = argv[1];
48
+    if(fn.substr(fn.find_last_of(".") + 1) == "vtk") {
49
+        vtkGenericDataObjectReader* Reader = vtkGenericDataObjectReader::New();
50
+            Reader->SetFileName(argv[1]);
51
+            Reader->Update();
52
+        if(Reader->IsFileUnstructuredGrid()) {
53
+            std::cout << "Found Unstructured grid legacy file" << std::endl;
54
+            uGrid = Reader->GetUnstructuredGridOutput();
55
+        } else {
56
+            std::cerr << "Unknown legacy format";
57
+            exit(EXIT_FAILURE);
58
+        }
59
+
60
+    } else {
61
+
62
+        vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
63
+            std::cout << "Reading" << argv[1] << std::endl;
64
+            Reader->SetFileName(argv[1]);
65
+            Reader->Update();
66
+            uGrid = Reader->GetOutput();
67
+    }
68
+
69
+
70
+        int nc = uGrid->GetNumberOfCells()  ;
71
+        int nn = uGrid->GetNumberOfPoints()  ;
72
+
73
+    std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
74
+
75
+    // Input magnet size TODO get from file or .geo file even?
76
+    double R =  atof(argv[2]); //.25;          // radius of magnet
77
+    double eps = 1e-4;       // epsilon for on the point
78
+    // Pol = double[3];
79
+
80
+    // Declare new array for the data
81
+    vtkDoubleArray* G = vtkDoubleArray::New();
82
+        G->SetNumberOfComponents(1);
83
+        G->SetNumberOfTuples(nn);
84
+        G->SetName("G");
85
+
86
+    vtkDoubleArray* phi = vtkDoubleArray::New();
87
+        phi->SetNumberOfComponents(1);
88
+        phi->SetNumberOfTuples(nn);
89
+        phi->SetName("analytic_phi");
90
+
91
+    // Loop over nodes, look at position, set with G if on boundary
92
+    double point[3];
93
+    Eigen::Vector3d M; M << 0,0,1;
94
+    for (int in=0; in<nn; ++in) {
95
+        uGrid->GetPoint(in, &point[0]);
96
+        //std::cout << point[0] << "\t" <<point[1] << "\t" << point[2] << std::endl;
97
+        double raddist = sqrt( point[0]*point[0] + point[1]*point[1] + point[2]*point[2] );
98
+
99
+        //double rho = sqrt( point[1]*point[1] + point[2]*point[2] );
100
+        // Calculate RHS
101
+        if ( std::string(argv[3]) == "gravity") {
102
+            if ( raddist < R + eps) {
103
+                G->InsertTuple1( in, 1 );
104
+            } else {
105
+                G->InsertTuple1( in, 0 );
106
+            }
107
+        }
108
+
109
+        else if ( std::string(argv[3]) == "magnet") {
110
+            if ( raddist > R - eps && raddist < R + eps ) {
111
+                // \rho = \nabla \cdot \mathbf{M}
112
+                //
113
+                if ( point[2] < -eps ) {
114
+                    G->InsertTuple1( in,   1 );
115
+                } else if (point[2] > eps) {
116
+                    G->InsertTuple1( in,  -1 );
117
+                } else {
118
+                    G->InsertTuple1( in, 0 );
119
+                }
120
+                //
121
+                // Above is inaccurate and unstable
122
+
123
+                // Use divergence theorm --> \mahtbf{M} \cdot \hat{n}
124
+                Eigen::Vector3d n;
125
+                n << point[0],point[1],point[2];
126
+                n.array() /= raddist;
127
+                //double sigma = n.dot(M);
128
+                G->InsertTuple1(in, n.dot(M) );
129
+            } else {
130
+                G->InsertTuple1( in, 0 );
131
+            }
132
+        }
133
+
134
+        // Insert analytic phi part
135
+        /* magnetics problem p. 198 Jackson */
136
+        if (std::string(argv[3]) == "magnet") {
137
+            if (raddist < R) {
138
+                phi->InsertTuple1( in, (1./3.)*point[2] );
139
+            } else {
140
+                phi->InsertTuple1( in, 0);
141
+                double costheta = point[2]/raddist ;
142
+                //phi->InsertTuple1( in, -(1./3.)*(R*R*R) * ( costheta / (rho*rho) )  );
143
+                phi->InsertTuple1( in, (1./3.) * (R*R*R) * (costheta / (raddist*raddist))  );
144
+            }
145
+        } else if (std::string(argv[3]) == "gravity") {
146
+            double mass = 4./3. * PI * (R*R*R);
147
+            if (raddist < R) {
148
+                phi->InsertTuple1( in, mass * ( 3*(R*R) - raddist*raddist )/(2*(R*R*R)) ); // (1./3.)*point[2] );
149
+            } else {
150
+                //phi->InsertTuple1( in, 0);
151
+                //double costheta = point[2]/raddist ;
152
+                //phi->InsertTuple1( in, -(1./3.)*(R*R*R) * ( costheta / (rho*rho) )  );
153
+                phi->InsertTuple1( in, mass/raddist );
154
+            }
155
+        }
156
+    }
157
+
158
+    // Add new data
159
+    uGrid->GetPointData()->AddArray( phi );
160
+    uGrid->GetPointData()->SetScalars( G );
161
+
162
+    // Write out new file
163
+    vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
164
+        //Writer->SetInputConnection(Reader->GetOutputPort());
165
+        Writer->SetInputData( uGrid );
166
+        Writer->SetFileName( argv[4] );
167
+        Writer->Write();
168
+
169
+    //Reader->Delete();
170
+
171
+
172
+}

+ 126
- 0
examples/utmerge.cpp Переглянути файл

@@ -0,0 +1,126 @@
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/29/2014 02:01:21 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include <vtkVersion.h>
21
+#include <vtkSmartPointer.h>
22
+#include <vtkPolyData.h>
23
+#include <vtkSphereSource.h>
24
+#include <vtkConeSource.h>
25
+#include <vtkXMLPolyDataReader.h>
26
+#include <vtkCleanPolyData.h>
27
+#include <vtkAppendPolyData.h>
28
+#include <vtkPolyDataMapper.h>
29
+#include <vtkActor.h>
30
+#include <vtkRenderWindow.h>
31
+#include <vtkRenderer.h>
32
+#include <vtkRenderWindowInteractor.h>
33
+
34
+int main(int argc, char *argv[])
35
+{
36
+  vtkSmartPointer<vtkPolyData> input1 =
37
+    vtkSmartPointer<vtkPolyData>::New();
38
+  vtkSmartPointer<vtkPolyData> input2 =
39
+    vtkSmartPointer<vtkPolyData>::New();
40
+
41
+  if(argc == 1) //command line arguments not specified
42
+    {
43
+    vtkSmartPointer<vtkSphereSource> sphereSource =
44
+      vtkSmartPointer<vtkSphereSource>::New();
45
+    sphereSource->SetCenter(5,0,0);
46
+    sphereSource->Update();
47
+
48
+    input1->ShallowCopy(sphereSource->GetOutput());
49
+
50
+    vtkSmartPointer<vtkConeSource> coneSource =
51
+      vtkSmartPointer<vtkConeSource>::New();
52
+    coneSource->Update();
53
+
54
+    input2->ShallowCopy(coneSource->GetOutput());
55
+    }
56
+  else
57
+  {
58
+    if(argc != 3)
59
+      {
60
+      std::cout << "argc = " << argc << std::endl;
61
+      std::cout << "Required arguments: File1 File2" << std::endl;
62
+      return EXIT_FAILURE;
63
+      }
64
+    std::string inputFilename1 = argv[1];
65
+    std::string inputFilename2 = argv[2];
66
+    vtkSmartPointer<vtkXMLPolyDataReader> reader1 =
67
+      vtkSmartPointer<vtkXMLPolyDataReader>::New();
68
+    reader1->SetFileName(inputFilename1.c_str());
69
+    reader1->Update();
70
+    input1->ShallowCopy(reader1->GetOutput());
71
+
72
+    vtkSmartPointer<vtkXMLPolyDataReader> reader2 =
73
+      vtkSmartPointer<vtkXMLPolyDataReader>::New();
74
+    reader2->SetFileName(inputFilename2.c_str());
75
+    reader2->Update();
76
+    input2->ShallowCopy(reader2->GetOutput());
77
+  }
78
+
79
+  //Append the two meshes
80
+  vtkSmartPointer<vtkAppendPolyData> appendFilter =
81
+    vtkSmartPointer<vtkAppendPolyData>::New();
82
+#if VTK_MAJOR_VERSION <= 5
83
+  appendFilter->AddInputConnection(input1->GetProducerPort());
84
+  appendFilter->AddInputConnection(input2->GetProducerPort());
85
+#else
86
+  appendFilter->AddInputData(input1);
87
+  appendFilter->AddInputData(input2);
88
+#endif
89
+  appendFilter->Update();
90
+
91
+  // Remove any duplicate points.
92
+  vtkSmartPointer<vtkCleanPolyData> cleanFilter =
93
+    vtkSmartPointer<vtkCleanPolyData>::New();
94
+  cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
95
+  cleanFilter->Update();
96
+
97
+  //Create a mapper and actor
98
+  vtkSmartPointer<vtkPolyDataMapper> mapper =
99
+    vtkSmartPointer<vtkPolyDataMapper>::New();
100
+  mapper->SetInputConnection(cleanFilter->GetOutputPort());
101
+
102
+  vtkSmartPointer<vtkActor> actor =
103
+    vtkSmartPointer<vtkActor>::New();
104
+  actor->SetMapper(mapper);
105
+
106
+  //Create a renderer, render window, and interactor
107
+  vtkSmartPointer<vtkRenderer> renderer =
108
+    vtkSmartPointer<vtkRenderer>::New();
109
+  vtkSmartPointer<vtkRenderWindow> renderWindow =
110
+    vtkSmartPointer<vtkRenderWindow>::New();
111
+  renderWindow->AddRenderer(renderer);
112
+  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
113
+    vtkSmartPointer<vtkRenderWindowInteractor>::New();
114
+  renderWindowInteractor->SetRenderWindow(renderWindow);
115
+
116
+  //Add the actors to the scene
117
+  renderer->AddActor(actor);
118
+  renderer->SetBackground(.3, .2, .1); // Background color dark red
119
+
120
+  //Render and interact
121
+  renderWindow->Render();
122
+  renderWindowInteractor->Start();
123
+
124
+  return EXIT_SUCCESS;
125
+}
126
+

Завантаження…
Відмінити
Зберегти