Galerkin FEM for elliptic PDEs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utmerge.cpp 3.9KB

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