Guest User

Untitled

a guest
Jun 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #include <vtkActor.h>
  2. #include <vtkCamera.h>
  3. #include <vtkLineSource.h>
  4. #include <vtkNamedColors.h>
  5. #include <vtkPointData.h>
  6. #include <vtkPolyDataMapper.h>
  7. #include <vtkProperty.h>
  8. #include <vtkRenderWindow.h>
  9. #include <vtkRenderWindowInteractor.h>
  10. #include <vtkRenderer.h>
  11. #include <vtkStructuredGrid.h>
  12. #include <vtkStructuredGridGeometryFilter.h>
  13. #include <vtkStructuredGridOutlineFilter.h>
  14. #include <vtkStructuredGridReader.h>
  15. #include <array>
  16. #include <vtkPointDataToCellData.h>
  17. #include<vtkWarpVector.h>
  18. #include <vtkThreshold.h>
  19. #include <vtkDataSetMapper.h>
  20. #include <vtkDataSetReader.h>
  21. #include <vtkDataSetSurfaceFilter.h>
  22. #include <vtkLookUpTable.h>
  23.  
  24.  
  25. int main(int argc, char* argv[])
  26. {
  27.  
  28. vtkSmartPointer<vtkNamedColors> colors = vtkSmartPointer<vtkNamedColors>::New();
  29.  
  30. vtkSmartPointer<vtkRenderer> aren = vtkSmartPointer<vtkRenderer>::New();
  31. vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
  32. renWin->AddRenderer(aren);
  33.  
  34. vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  35. iren->SetRenderWindow(renWin);
  36.  
  37. vtkSmartPointer<vtkDataSetReader> reader =
  38. vtkSmartPointer<vtkDataSetReader>::New();
  39. reader->SetFileName("../kitchen.vtk");
  40. reader->SetScalarsName("c13");
  41. reader->SetVectorsName("vectors");
  42. reader->Update();
  43. reader->Update(); //force a read to occur
  44. reader->GetOutput()->GetLength();
  45.  
  46. vtkSmartPointer<vtkLookupTable> grayScaleLut =
  47. vtkSmartPointer<vtkLookupTable>::New();
  48. grayScaleLut->SetHueRange(0, 0);
  49. grayScaleLut->SetSaturationRange(0, 0);
  50. grayScaleLut->SetValueRange(0.2, 1.0);
  51. grayScaleLut->SetNumberOfColors(256);
  52. grayScaleLut->SetHueRange(0.0, 0.667);
  53. grayScaleLut->Build();
  54. grayScaleLut->SetVectorModeToMagnitude();
  55. grayScaleLut->SetVectorMode(vtkScalarsToColors::MAGNITUDE);
  56.  
  57.  
  58.  
  59. vtkSmartPointer<vtkDataSetSurfaceFilter> surface = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
  60. surface->SetInputConnection(reader->GetOutputPort());
  61. vtkSmartPointer<vtkPolyDataMapper> surfaceMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  62. surfaceMapper->SetInputConnection(surface->GetOutputPort());
  63. surfaceMapper->SetLookupTable(grayScaleLut);
  64. vtkSmartPointer<vtkActor> surfaceactor = vtkSmartPointer<vtkActor>::New();
  65. surfaceactor->SetMapper(surfaceMapper);
  66. surfaceactor->GetProperty()->SetColor(colors->GetColor3d("LampBlack").GetData());
  67.  
  68.  
  69. vtkPointDataToCellData* p2c = vtkPointDataToCellData::New();
  70. p2c->SetInputConnection(reader->GetOutputPort());
  71. p2c->PassPointDataOn();
  72. vtkWarpVector* warp = vtkWarpVector::New();
  73. warp->SetInputConnection(p2c->GetOutputPort());
  74. vtkThreshold* thresh = vtkThreshold::New();
  75. thresh->SetInputConnection(warp->GetOutputPort());
  76. thresh->ThresholdBetween(0,1);
  77. thresh->SetInputArrayToProcess(0, 0, 0, 0, "c13");
  78. thresh->SetAllScalars(1);
  79.  
  80.  
  81. vtkDataSetMapper* mapper = vtkDataSetMapper::New();
  82. mapper->SetInputConnection(thresh->GetOutputPort());
  83. mapper->SetLookupTable(grayScaleLut);
  84.  
  85. vtkActor* readerActor = vtkActor::New();
  86. readerActor->SetMapper(mapper);
  87.  
  88.  
  89. //
  90. // linijų rezoliucija
  91. //
  92. vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
  93. line->SetResolution(8);
  94. vtkSmartPointer<vtkActor> lines = vtkSmartPointer<vtkActor>::New();
  95. lines->GetProperty()->SetColor(colors->GetColor3d("Black").GetData());
  96.  
  97. aren->TwoSidedLightingOn();
  98. // pridedamos linijos
  99. aren->AddActor(surfaceactor);
  100. // fono spalva
  101. aren->SetBackground(colors->GetColor3d("SlateGray").GetData());
  102.  
  103. vtkSmartPointer<vtkCamera> aCamera = vtkSmartPointer<vtkCamera>::New();
  104. aren->SetActiveCamera(aCamera);
  105. aren->ResetCamera();
  106. // kameros nustatymai
  107. aCamera->SetFocalPoint(3.505, 2.505, 1.255);
  108. aCamera->SetPosition(3.505, 24.6196, 1.255);
  109. aCamera->SetViewUp(0, 0, 1);
  110. aCamera->Azimuth(60);
  111. aCamera->Elevation(30);
  112. aCamera->Dolly(1.5);
  113. aren->ResetCameraClippingRange();
  114.  
  115. renWin->SetSize(640, 512);
  116. renWin->Render();
  117.  
  118. iren->Start();
  119.  
  120. return EXIT_SUCCESS;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment