SHARE
TWEET

Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  17. #include <array>
  18.  
  19. int main( int argc, char *argv[] )
  20. {
  21.   if (argc < 2)
  22.   {
  23.     std::cout << "Usage: " << argv[0] << " kitchen.vtk" << std::endl;
  24.     return EXIT_FAILURE;
  25.   }
  26.   double range[2];
  27.   double maxVelocity = 0.0, maxTime = 0.0;
  28.  
  29.   vtkSmartPointer<vtkNamedColors> colors =
  30.     vtkSmartPointer<vtkNamedColors>::New();
  31.  
  32.   // Set the furniture colors.
  33.   std::array<unsigned char , 4> furnColor{{204, 204, 153, 255}};
  34.     colors->SetColor("Furniture", furnColor.data());
  35.  
  36.   vtkSmartPointer<vtkRenderer> aren =
  37.     vtkSmartPointer<vtkRenderer>::New();
  38.   vtkSmartPointer<vtkRenderWindow> renWin =
  39.     vtkSmartPointer<vtkRenderWindow>::New();
  40.   renWin->AddRenderer(aren);
  41.  
  42.   vtkSmartPointer<vtkRenderWindowInteractor> iren =
  43.     vtkSmartPointer<vtkRenderWindowInteractor>::New();
  44.   iren->SetRenderWindow(renWin);
  45. //
  46. // Read data
  47. //
  48.   vtkSmartPointer<vtkStructuredGridReader> reader =
  49.     vtkSmartPointer<vtkStructuredGridReader>::New();
  50.   reader->SetFileName(argv[1]);
  51.   reader->Update(); //force a read to occur
  52.   reader->GetOutput()->GetLength();
  53.  
  54.   if ( reader->GetOutput()->GetPointData()->GetScalars() )
  55.   {
  56.     reader->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
  57.   }
  58.   if ( reader->GetOutput()->GetPointData()->GetVectors() )
  59.   {
  60.     maxVelocity = reader->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
  61.     maxTime = 4.0*reader->GetOutput()->GetLength()/maxVelocity ;
  62.   }
  63. //
  64. // Outline around data
  65. //
  66.   vtkSmartPointer<vtkStructuredGridOutlineFilter> outlineF =
  67.     vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
  68.   outlineF->SetInputConnection(reader->GetOutputPort());
  69.   vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
  70.     vtkSmartPointer<vtkPolyDataMapper>::New();
  71.   outlineMapper->SetInputConnection(outlineF->GetOutputPort());
  72.   vtkSmartPointer<vtkActor> outline =
  73.     vtkSmartPointer<vtkActor>::New();
  74.   outline->SetMapper(outlineMapper);
  75.   outline->GetProperty()->SetColor(colors->GetColor3d("LampBlack").GetData());
  76. //
  77. // Set up shaded surfaces (i.e., supporting geometry)
  78. //
  79.   vtkSmartPointer<vtkStructuredGridGeometryFilter> doorGeom =
  80.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  81.   doorGeom->SetInputConnection(reader->GetOutputPort());
  82.   doorGeom->SetExtent(27,27,14,18,0,11);
  83.   vtkSmartPointer<vtkPolyDataMapper> mapDoor =
  84.     vtkSmartPointer<vtkPolyDataMapper>::New();
  85.   mapDoor->SetInputConnection(doorGeom->GetOutputPort());
  86.   mapDoor->ScalarVisibilityOff();
  87.   vtkSmartPointer<vtkActor> door =
  88.     vtkSmartPointer<vtkActor>::New();
  89.   door->SetMapper(mapDoor);
  90.   door->GetProperty()->SetColor(colors->GetColor3d("Burlywood").GetData());
  91.  
  92.   vtkSmartPointer<vtkStructuredGridGeometryFilter> window1Geom =
  93.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  94.   window1Geom->SetInputConnection(reader->GetOutputPort());
  95.   window1Geom->SetExtent(0,0,9,18,6,12);
  96.   vtkSmartPointer<vtkPolyDataMapper> mapWindow1 =
  97.     vtkSmartPointer<vtkPolyDataMapper>::New();
  98.   mapWindow1->SetInputConnection(window1Geom->GetOutputPort());
  99.   mapWindow1->ScalarVisibilityOff();
  100.   vtkSmartPointer<vtkActor> window1 =
  101.     vtkSmartPointer<vtkActor>::New();
  102.   window1->SetMapper(mapWindow1);
  103.   window1->GetProperty()->SetColor(colors->GetColor3d("SkyBlue").GetData());
  104.   window1->GetProperty()->SetOpacity(.6);
  105.  
  106.   vtkSmartPointer<vtkStructuredGridGeometryFilter> window2Geom =
  107.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  108.   window2Geom->SetInputConnection(reader->GetOutputPort());
  109.   window2Geom->SetExtent(5,12,23,23,6,12);
  110.   vtkSmartPointer<vtkPolyDataMapper> mapWindow2 =
  111.     vtkSmartPointer<vtkPolyDataMapper>::New();
  112.   mapWindow2->SetInputConnection(window2Geom->GetOutputPort());
  113.   mapWindow2->ScalarVisibilityOff();
  114.   vtkSmartPointer<vtkActor> window2 =
  115.     vtkSmartPointer<vtkActor>::New();
  116.   window2->SetMapper(mapWindow2);
  117.   window2->GetProperty()->SetColor(colors->GetColor3d("SkyBlue").GetData());
  118.   window2->GetProperty()->SetOpacity(.6);
  119.  
  120.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower1Geom =
  121.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  122.   klower1Geom->SetInputConnection(reader->GetOutputPort());
  123.   klower1Geom->SetExtent(17,17,0,11,0,6);
  124.   vtkSmartPointer<vtkPolyDataMapper> mapKlower1 =
  125.     vtkSmartPointer<vtkPolyDataMapper>::New();
  126.   mapKlower1->SetInputConnection(klower1Geom->GetOutputPort());
  127.   mapKlower1->ScalarVisibilityOff();
  128.   vtkSmartPointer<vtkActor> klower1 =
  129.     vtkSmartPointer<vtkActor>::New();
  130.   klower1->SetMapper(mapKlower1);
  131.   klower1->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  132.  
  133.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower2Geom =
  134.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  135.   klower2Geom->SetInputConnection(reader->GetOutputPort());
  136.   klower2Geom->SetExtent(19,19,0,11,0,6);
  137.   vtkSmartPointer<vtkPolyDataMapper> mapKlower2 =
  138.     vtkSmartPointer<vtkPolyDataMapper>::New();
  139.   mapKlower2->SetInputConnection(klower2Geom->GetOutputPort());
  140.   mapKlower2->ScalarVisibilityOff();
  141.   vtkSmartPointer<vtkActor> klower2 =
  142.     vtkSmartPointer<vtkActor>::New();
  143.   klower2->SetMapper(mapKlower2);
  144.   klower2->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  145.  
  146.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower3Geom =
  147.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  148.   klower3Geom->SetInputConnection(reader->GetOutputPort());
  149.   klower3Geom->SetExtent(17,19,0,0,0,6);
  150.   vtkSmartPointer<vtkPolyDataMapper> mapKlower3 =
  151.     vtkSmartPointer<vtkPolyDataMapper>::New();
  152.   mapKlower3->SetInputConnection(klower3Geom->GetOutputPort());
  153.   mapKlower3->ScalarVisibilityOff();
  154.   vtkSmartPointer<vtkActor> klower3 =
  155.     vtkSmartPointer<vtkActor>::New();
  156.   klower3->SetMapper(mapKlower3);
  157.   klower3->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  158.  
  159.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower4Geom =
  160.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  161.   klower4Geom->SetInputConnection(reader->GetOutputPort());
  162.   klower4Geom->SetExtent(17,19,11,11,0,6);
  163.   vtkSmartPointer<vtkPolyDataMapper> mapKlower4 =
  164.     vtkSmartPointer<vtkPolyDataMapper>::New();
  165.   mapKlower4->SetInputConnection(klower4Geom->GetOutputPort());
  166.   mapKlower4->ScalarVisibilityOff();
  167.   vtkSmartPointer<vtkActor> klower4 =
  168.     vtkSmartPointer<vtkActor>::New();
  169.   klower4->SetMapper(mapKlower4);
  170.   klower4->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  171.  
  172.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower5Geom =
  173.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  174.   klower5Geom->SetInputConnection(reader->GetOutputPort());
  175.   klower5Geom->SetExtent(17,19,0,11,0,0);
  176.   vtkSmartPointer<vtkPolyDataMapper> mapKlower5 =
  177.     vtkSmartPointer<vtkPolyDataMapper>::New();
  178.   mapKlower5->SetInputConnection(klower5Geom->GetOutputPort());
  179.   mapKlower5->ScalarVisibilityOff();
  180.   vtkSmartPointer<vtkActor> klower5 =
  181.     vtkSmartPointer<vtkActor>::New();
  182.   klower5->SetMapper(mapKlower5);
  183.   klower5->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  184.  
  185.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower6Geom =
  186.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  187.   klower6Geom->SetInputConnection(reader->GetOutputPort());
  188.   klower6Geom->SetExtent(17,19,0,7,6,6);
  189.   vtkSmartPointer<vtkPolyDataMapper> mapKlower6 =
  190.     vtkSmartPointer<vtkPolyDataMapper>::New();
  191.   mapKlower6->SetInputConnection(klower6Geom->GetOutputPort());
  192.   mapKlower6->ScalarVisibilityOff();
  193.   vtkSmartPointer<vtkActor> klower6 =
  194.     vtkSmartPointer<vtkActor>::New();
  195.   klower6->SetMapper(mapKlower6);
  196.   klower6->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  197.  
  198.   vtkSmartPointer<vtkStructuredGridGeometryFilter> klower7Geom =
  199.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  200.   klower7Geom->SetInputConnection(reader->GetOutputPort());
  201.   klower7Geom->SetExtent(17,19,9,11,6,6);
  202.   vtkSmartPointer<vtkPolyDataMapper> mapKlower7 =
  203.     vtkSmartPointer<vtkPolyDataMapper>::New();
  204.   mapKlower7->SetInputConnection(klower7Geom->GetOutputPort());
  205.   mapKlower7->ScalarVisibilityOff();
  206.   vtkSmartPointer<vtkActor> klower7 =
  207.     vtkSmartPointer<vtkActor>::New();
  208.   klower7->SetMapper(mapKlower7);
  209.   klower7->GetProperty()->SetColor(colors->GetColor3d("EggShell").GetData());
  210.  
  211.   vtkSmartPointer<vtkStructuredGridGeometryFilter> hood1Geom =
  212.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  213.   hood1Geom->SetInputConnection(reader->GetOutputPort());
  214.   hood1Geom->SetExtent(17,17,0,11,11,16);
  215.   vtkSmartPointer<vtkPolyDataMapper> mapHood1 =
  216.     vtkSmartPointer<vtkPolyDataMapper>::New();
  217.   mapHood1->SetInputConnection(hood1Geom->GetOutputPort());
  218.   mapHood1->ScalarVisibilityOff();
  219.   vtkSmartPointer<vtkActor> hood1 =
  220.     vtkSmartPointer<vtkActor>::New();
  221.   hood1->SetMapper(mapHood1);
  222.   hood1->GetProperty()->SetColor(colors->GetColor3d("Silver").GetData());
  223.  
  224.   vtkSmartPointer<vtkStructuredGridGeometryFilter> hood2Geom =
  225.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  226.   hood2Geom->SetInputConnection(reader->GetOutputPort());
  227.   hood2Geom->SetExtent(19,19,0,11,11,16);
  228.   vtkSmartPointer<vtkPolyDataMapper> mapHood2 =
  229.     vtkSmartPointer<vtkPolyDataMapper>::New();
  230.   mapHood2->SetInputConnection(hood2Geom->GetOutputPort());
  231.   mapHood2->ScalarVisibilityOff();
  232.   vtkSmartPointer<vtkActor> hood2 =
  233.     vtkSmartPointer<vtkActor>::New();
  234.   hood2->SetMapper(mapHood2);
  235.   hood2->GetProperty()->SetColor(colors->GetColor3d("Furniture").GetData());
  236.  
  237.   vtkSmartPointer<vtkStructuredGridGeometryFilter> hood3Geom =
  238.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  239.   hood3Geom->SetInputConnection(reader->GetOutputPort());
  240.   hood3Geom->SetExtent(17,19,0,0,11,16);
  241.   vtkSmartPointer<vtkPolyDataMapper> mapHood3 =
  242.     vtkSmartPointer<vtkPolyDataMapper>::New();
  243.   mapHood3->SetInputConnection(hood3Geom->GetOutputPort());
  244.   mapHood3->ScalarVisibilityOff();
  245.   vtkSmartPointer<vtkActor> hood3 =
  246.     vtkSmartPointer<vtkActor>::New();
  247.   hood3->SetMapper(mapHood3);
  248.   hood3->GetProperty()->SetColor(colors->GetColor3d("Furniture").GetData());
  249.  
  250.   vtkSmartPointer<vtkStructuredGridGeometryFilter> hood4Geom =
  251.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  252.   hood4Geom->SetInputConnection(reader->GetOutputPort());
  253.   hood4Geom->SetExtent(17,19,11,11,11,16);
  254.   vtkSmartPointer<vtkPolyDataMapper> mapHood4 =
  255.     vtkSmartPointer<vtkPolyDataMapper>::New();
  256.   mapHood4->SetInputConnection(hood4Geom->GetOutputPort());
  257.   mapHood4->ScalarVisibilityOff();
  258.   vtkSmartPointer<vtkActor> hood4 =
  259.     vtkSmartPointer<vtkActor>::New();
  260.   hood4->SetMapper(mapHood4);
  261.   hood4->GetProperty()->SetColor(colors->GetColor3d("Furniture").GetData());
  262.  
  263.   vtkSmartPointer<vtkStructuredGridGeometryFilter> hood6Geom =
  264.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  265.   hood6Geom->SetInputConnection(reader->GetOutputPort());
  266.   hood6Geom->SetExtent(17,19,0,11,16,16);
  267.   vtkSmartPointer<vtkPolyDataMapper> mapHood6 =
  268.     vtkSmartPointer<vtkPolyDataMapper>::New();
  269.   mapHood6->SetInputConnection(hood6Geom->GetOutputPort());
  270.   mapHood6->ScalarVisibilityOff();
  271.   vtkSmartPointer<vtkActor> hood6 =
  272.     vtkSmartPointer<vtkActor>::New();
  273.   hood6->SetMapper(mapHood6);
  274.   hood6->GetProperty()->SetColor(colors->GetColor3d("Furniture").GetData());
  275.  
  276.   vtkSmartPointer<vtkStructuredGridGeometryFilter> cookingPlateGeom =
  277.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  278.   cookingPlateGeom->SetInputConnection(reader->GetOutputPort());
  279.   cookingPlateGeom->SetExtent(17,19,7,9,6,6);
  280.   vtkSmartPointer<vtkPolyDataMapper> mapCookingPlate =
  281.     vtkSmartPointer<vtkPolyDataMapper>::New();
  282.   mapCookingPlate->SetInputConnection(cookingPlateGeom->GetOutputPort());
  283.   mapCookingPlate->ScalarVisibilityOff();
  284.   vtkSmartPointer<vtkActor> cookingPlate =
  285.     vtkSmartPointer<vtkActor>::New();
  286.   cookingPlate->SetMapper(mapCookingPlate);
  287.   cookingPlate->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());
  288.  
  289.   vtkSmartPointer<vtkStructuredGridGeometryFilter> filterGeom =
  290.     vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
  291.   filterGeom->SetInputConnection(reader->GetOutputPort());
  292.   filterGeom->SetExtent(17,19,7,9,11,11);
  293.   vtkSmartPointer<vtkPolyDataMapper> mapFilter =
  294.     vtkSmartPointer<vtkPolyDataMapper>::New();
  295.   mapFilter->SetInputConnection(filterGeom->GetOutputPort());
  296.   mapFilter->ScalarVisibilityOff();
  297.   vtkSmartPointer<vtkActor> filter =
  298.     vtkSmartPointer<vtkActor>::New();
  299.   filter->SetMapper(mapFilter);
  300.   filter->GetProperty()->SetColor(colors->GetColor3d("Furniture").GetData());
  301. //
  302. // regular streamlines
  303. //
  304.   vtkSmartPointer<vtkLineSource> line =
  305.     vtkSmartPointer<vtkLineSource>::New();
  306.   line->SetResolution(39);
  307.   line->SetPoint1(0.08, 2.50, 0.71);
  308.   line->SetPoint2(0.08, 4.50, 0.71);
  309.   vtkSmartPointer<vtkPolyDataMapper> rakeMapper =
  310.     vtkSmartPointer<vtkPolyDataMapper>::New();
  311.   rakeMapper->SetInputConnection(line->GetOutputPort());
  312.   vtkSmartPointer<vtkActor> rake =
  313.     vtkSmartPointer<vtkActor>::New();
  314.   rake->SetMapper(rakeMapper);
  315.  
  316.   vtkSmartPointer<vtkStreamTracer> streamers =
  317.     vtkSmartPointer<vtkStreamTracer>::New();
  318.   //streamers->DebugOn();
  319.   streamers->SetInputConnection(reader->GetOutputPort());
  320.   streamers->SetSourceConnection(line->GetOutputPort());
  321.   streamers->SetMaximumPropagation(maxTime);
  322.   streamers->SetInitialIntegrationStep(.5);
  323.   streamers->SetMinimumIntegrationStep(.1);
  324.   streamers->SetIntegratorType(2);
  325.   streamers->Update();
  326.  
  327.   vtkSmartPointer<vtkPolyDataMapper> streamersMapper =
  328.     vtkSmartPointer<vtkPolyDataMapper>::New();
  329.   streamersMapper->SetInputConnection(streamers->GetOutputPort());
  330.   streamersMapper->SetScalarRange(range);
  331.  
  332.   vtkSmartPointer<vtkActor> lines =
  333.     vtkSmartPointer<vtkActor>::New();
  334.   lines->SetMapper(streamersMapper);
  335.   lines->GetProperty()->SetColor(colors->GetColor3d("Black").GetData());
  336.  
  337.   aren->TwoSidedLightingOn();
  338.  
  339.   aren->AddActor(outline);
  340.   aren->AddActor(door);
  341.   aren->AddActor(window1);
  342.   aren->AddActor(window2);
  343.   aren->AddActor(klower1);
  344.   aren->AddActor(klower2);
  345.   aren->AddActor(klower3);
  346.   aren->AddActor(klower4);
  347.   aren->AddActor(klower5);
  348.   aren->AddActor(klower6);
  349.   aren->AddActor(klower7);
  350.   aren->AddActor(hood1);
  351.   aren->AddActor(hood2);
  352.   aren->AddActor(hood3);
  353.   aren->AddActor(hood4);
  354.   aren->AddActor(hood6);
  355.   aren->AddActor(cookingPlate);
  356.   aren->AddActor(filter);
  357.   aren->AddActor(lines);
  358.   aren->AddActor(rake);
  359.  
  360.   aren->SetBackground(colors->GetColor3d("SlateGray").GetData());
  361.  
  362.   vtkSmartPointer<vtkCamera> aCamera =
  363.     vtkSmartPointer<vtkCamera>::New();
  364.   aren->SetActiveCamera(aCamera);
  365.   aren->ResetCamera();
  366.  
  367.   aCamera->SetFocalPoint(3.505, 2.505, 1.255);
  368.   aCamera->SetPosition(3.505, 24.6196, 1.255);
  369.   aCamera->SetViewUp(0,0,1);
  370.   aCamera->Azimuth(60);
  371.   aCamera->Elevation(30);
  372.   aCamera->Dolly(1.5);
  373.   aren->ResetCameraClippingRange();
  374.  
  375.   renWin->SetSize(640, 512);
  376.   renWin->Render();
  377.  
  378.   // interact with data
  379.   iren->Start();
  380.  
  381.   return EXIT_SUCCESS;
  382. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top