TestHyperTreeGridBinary2DMaterial.cxx 4.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*==================================================================

  Program:   Visualization Toolkit
  Module:    TestHyperTreeGridBinary2DMaterial.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

===================================================================*/
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware 2012
17
18
// This test was revised by Philippe Pebay, 2016
// This work was supported by Commissariat a l'Energie Atomique (CEA/DIF)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include "vtkHyperTreeGridGeometry.h"
#include "vtkHyperTreeGridSource.h"

#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkContourFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

int TestHyperTreeGridBinary2DMaterial( int argc, char* argv[] )
{
  // Hyper tree grid
  vtkNew<vtkHyperTreeGridSource> htGrid;
  int maxLevel = 6;
  htGrid->SetMaximumLevel( maxLevel );
  htGrid->SetDimension( 2 );
42
  htGrid->SetOrientation( 2 ); // in xy plane
43
44
  htGrid->SetGridSize( 2, 3, 1 );
  htGrid->SetGridScale( 1.5, 1., 10. );  // this is to test that orientation fixes scale
45
46
47
48
49
50
51
52
53
  htGrid->SetBranchFactor( 2 );
  htGrid->UseMaterialMaskOn();
  htGrid->SetDescriptor( "RRRRR.|.... .R.. RRRR R... R...|.R.. ...R ..RR .R.. R... .... ....|.... ...R ..R. .... .R.. R...|.... .... .R.. ....|...." );
  htGrid->SetMaterialMask( "111111|0000 1111 1111 1111 1111|1111 0001 0111 0101 1011 1111 0111|1111 0111 1111 1111 1111 1111|1111 1111 1111 1111|1111" );

  // Geometry
  vtkNew<vtkHyperTreeGridGeometry> geometry;
  geometry->SetInputConnection( htGrid->GetOutputPort() );
  geometry->Update();
54
  vtkPolyData* pd = geometry->GetPolyDataOutput();
55
56
57
58
59
60
61
62
63

  // Contour
  vtkNew<vtkContourFilter> contour;
  int nContours = 3;
  contour->SetNumberOfContours( nContours );
  contour->SetInputConnection( htGrid->GetOutputPort() );
  double resolution = ( maxLevel - 1 ) / ( nContours + 1. );
  double isovalue = resolution;
  for ( int i = 0; i < nContours; ++ i, isovalue += resolution )
64
  {
65
    contour->SetValue( i, isovalue );
66
  }
67
68

  // Mappers
69
  vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
70
71
72
73
74
75
  vtkNew<vtkPolyDataMapper> mapper1;
  mapper1->SetInputConnection( geometry->GetOutputPort() );
  mapper1->SetScalarRange( pd->GetCellData()->GetScalars()->GetRange() );
  vtkNew<vtkPolyDataMapper> mapper2;
  mapper2->SetInputConnection( geometry->GetOutputPort() );
  mapper2->ScalarVisibilityOff();
76
77
  vtkNew<vtkPolyDataMapper> mapper3;
  mapper3->SetInputConnection( contour->GetOutputPort() );
78
  mapper3->ScalarVisibilityOff();
79
80
81
  vtkNew<vtkDataSetMapper> mapper4;
  mapper4->SetInputConnection( htGrid->GetOutputPort() );
  mapper4->ScalarVisibilityOff();
82
83
84

  // Actors
  vtkNew<vtkActor> actor1;
85
  actor1->SetMapper( mapper1 );
86
  vtkNew<vtkActor> actor2;
87
  actor2->SetMapper( mapper2 );
88
89
90
  actor2->GetProperty()->SetRepresentationToWireframe();
  actor2->GetProperty()->SetColor( .7, .7, .7 );
  vtkNew<vtkActor> actor3;
91
  actor3->SetMapper( mapper3 );
92
93
94
  actor3->GetProperty()->SetColor( .8, .4, .3 );
  actor3->GetProperty()->SetLineWidth( 3 );
  vtkNew<vtkActor> actor4;
95
  actor4->SetMapper( mapper4 );
96
97
  actor4->GetProperty()->SetRepresentationToWireframe();
  actor4->GetProperty()->SetColor( .0, .0, .0 );
98
99
100
101
102
103
104

  // Camera
  double bd[6];
  pd->GetBounds( bd );
  vtkNew<vtkCamera> camera;
  camera->SetClippingRange( 1., 100. );
  camera->SetFocalPoint( pd->GetCenter() );
105
  camera->SetPosition( .5 * bd[1], .5 * bd[3], 6. );
106
107
108

  // Renderer
  vtkNew<vtkRenderer> renderer;
109
  renderer->SetActiveCamera( camera );
110
  renderer->SetBackground( 1., 1., 1. );
111
112
113
114
  renderer->AddActor( actor1 );
  renderer->AddActor( actor2 );
  renderer->AddActor( actor3 );
  renderer->AddActor( actor4 );
115
116
117

  // Render window
  vtkNew<vtkRenderWindow> renWin;
118
  renWin->AddRenderer( renderer );
119
120
121
122
123
  renWin->SetSize( 400, 400 );
  renWin->SetMultiSamples( 0 );

  // Interactor
  vtkNew<vtkRenderWindowInteractor> iren;
124
  iren->SetRenderWindow( renWin );
125
126
127

  // Render and test
  renWin->Render();
Ken Martin's avatar
Ken Martin committed
128

129
  int retVal = vtkRegressionTestImageThreshold( renWin, 70 );
130
  if ( retVal == vtkRegressionTester::DO_INTERACTOR )
131
  {
132
    iren->Start();
133
  }
134
135
136

  return !retVal;
}