Advertisement
Guest User

kitchenas seni

a guest
May 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.07 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 <vtkStreamTracer.h>
  12. #include <vtkStructuredGrid.h>
  13. #include <vtkStructuredGridGeometryFilter.h>
  14. #include <vtkStructuredGridOutlineFilter.h>
  15. #include <vtkStructuredGridReader.h>
  16. #include <array>
  17. // PASIKEISK VISKA
  18. int main( int argc, char *argv[] )
  19. {
  20.   double range[2];
  21.   double maxVelocity = 0.0, maxTime = 0.0;
  22.  
  23.   vtkSmartPointer<vtkNamedColors> colors = vtkSmartPointer<vtkNamedColors>::New();
  24.  
  25.   vtkSmartPointer<vtkRenderer> aren = vtkSmartPointer<vtkRenderer>::New();
  26.   vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
  27.   renWin->AddRenderer(aren);
  28.  
  29.   vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  30.   iren->SetRenderWindow(renWin);
  31. //
  32. // Read data
  33. //
  34.   vtkSmartPointer<vtkStructuredGridReader> reader = vtkSmartPointer<vtkStructuredGridReader>::New();
  35.   reader->SetFileName("../kitchen.vtk");
  36.   reader->Update(); //force a read to occur
  37.   reader->GetOutput()->GetLength();
  38.  
  39.   if ( reader->GetOutput()->GetPointData()->GetScalars() )
  40.   {
  41.     reader->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
  42.   }
  43.   if ( reader->GetOutput()->GetPointData()->GetVectors() )
  44.   {
  45.     maxVelocity = reader->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
  46.     maxTime = 4.0*reader->GetOutput()->GetLength()/maxVelocity ;
  47.   }
  48. //
  49. // Outline around data
  50. //
  51.   vtkSmartPointer<vtkStructuredGridOutlineFilter> outlineF = vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
  52.   outlineF->SetInputConnection(reader->GetOutputPort());
  53.   vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  54.   outlineMapper->SetInputConnection(outlineF->GetOutputPort());
  55.   vtkSmartPointer<vtkActor> outline = vtkSmartPointer<vtkActor>::New();
  56.   outline->SetMapper(outlineMapper);
  57.   outline->GetProperty()->SetColor(colors->GetColor3d("LampBlack").GetData());
  58. //
  59. // regular streamlines
  60. //
  61.   vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
  62.   line->SetResolution(39);
  63.   line->SetPoint1(0.08, 2.50, 0.71);
  64.   line->SetPoint2(0.08, 4.50, 0.71);
  65.   vtkSmartPointer<vtkPolyDataMapper> rakeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  66.   rakeMapper->SetInputConnection(line->GetOutputPort());
  67.   vtkSmartPointer<vtkActor> rake = vtkSmartPointer<vtkActor>::New();
  68.   rake->SetMapper(rakeMapper);
  69.  
  70.   vtkSmartPointer<vtkStreamTracer> streamers = vtkSmartPointer<vtkStreamTracer>::New();
  71.   streamers->SetInputConnection(reader->GetOutputPort());
  72.   streamers->SetSourceConnection(line->GetOutputPort());
  73.   streamers->SetMaximumPropagation(maxTime);
  74.   streamers->SetInitialIntegrationStep(.5);
  75.   streamers->SetMinimumIntegrationStep(.1);
  76.   streamers->SetIntegratorType(2);
  77.   streamers->Update();
  78.  
  79.   vtkSmartPointer<vtkPolyDataMapper> streamersMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  80.   streamersMapper->SetInputConnection(streamers->GetOutputPort());
  81.   streamersMapper->SetScalarRange(range);
  82.  
  83.   vtkSmartPointer<vtkActor> lines = vtkSmartPointer<vtkActor>::New();
  84.   lines->SetMapper(streamersMapper);
  85.   lines->GetProperty()->SetColor(colors->GetColor3d("Black").GetData());
  86.  
  87.   aren->TwoSidedLightingOn();
  88.  
  89.   aren->AddActor(outline);
  90.   aren->AddActor(lines);
  91.   aren->AddActor(rake);
  92.  
  93.   aren->SetBackground(colors->GetColor3d("SlateGray").GetData());
  94.  
  95.   vtkSmartPointer<vtkCamera> aCamera = vtkSmartPointer<vtkCamera>::New();
  96.   aren->SetActiveCamera(aCamera);
  97.   aren->ResetCamera();
  98.  
  99.   aCamera->SetFocalPoint(3.505, 2.505, 1.255);
  100.   aCamera->SetPosition(3.505, 24.6196, 1.255);
  101.   aCamera->SetViewUp(0,0,1);
  102.   aCamera->Azimuth(60);
  103.   aCamera->Elevation(30);
  104.   aCamera->Dolly(1.5);
  105.   aren->ResetCameraClippingRange();
  106.  
  107.   renWin->SetSize(640, 512);
  108.   renWin->Render();
  109.  
  110.   // interact with data
  111.   iren->Start();
  112.  
  113.   return EXIT_SUCCESS;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement