File: TestSurfaceLIC.h

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (216 lines) | stat: -rw-r--r-- 6,670 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestSurfaceLIC.h

  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.

=========================================================================*/
#ifndef __TestSurfaceLIC_h
#define __TestSurfaceLIC_h

#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkGenericDataObjectReader.h"
#include "vtkSurfaceLICPainter.h"
#include "vtkObjectFactory.h"
#include "vtkPainterPolyDataMapper.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkXMLPolyDataReader.h"

#include <vtksys/CommandLineArguments.hxx>
#include <vtksys/SystemTools.hxx>
#include <vector>
#include <string>

#define VTK_CREATE_NEW(var, class) vtkSmartPointer<class> var = vtkSmartPointer<class>::New();

// This example demonstrates the use of vtkSurfaceLICPainter for rendering
// geometry with LIC on the surface.

enum { SURFACE_LIC_DEMO = 0, SURFACE_LIC_TEST = 1 };

int RenderingMode = SURFACE_LIC_TEST;

int SurfaceLIC( int argc, char * argv[] )
{
  std::string filename;
  int num_steps = 40;
  double step_size = 0.4;
  double lic_intensity = 0.8;
  //std::string color_by;
  std::string vectors;

  vtksys::CommandLineArguments arg;
  arg.StoreUnusedArguments(1);
  arg.Initialize(argc, argv);

  // Fill up accepted arguments.
  typedef vtksys::CommandLineArguments argT;

  arg.AddArgument("--data", argT::EQUAL_ARGUMENT, &filename,
    "(required) Enter dataset to load (currently only *.[vtk|vtp] files are supported");
  arg.AddArgument("--num-steps", argT::EQUAL_ARGUMENT, &num_steps,
    "(optional: default 40) Number of steps in each direction");
  arg.AddArgument("--step-size", argT::EQUAL_ARGUMENT, &step_size,
    "(optional: default 0.4) Step size in pixels");
  arg.AddArgument("--lic-intensity", argT::EQUAL_ARGUMENT, &lic_intensity,
    "(optional: default 0.8) Contribution of LIC in the final image [1.0 == max contribution]");
  //arg.AddArgument("--color-by", argT::EQUAL_ARGUMENT, &color_by,
  //  "(optional: default active scalars) Name of the array to color by");
  arg.AddArgument("--vectors", argT::EQUAL_ARGUMENT, &vectors,
    "(optional: default active point vectors) Name of the vector field array");

  if (!arg.Parse() || filename == "")
    {
    cerr << "Usage: " << endl;
    cerr << arg.GetHelp() << endl;
    return 1;
    }

  vtkSmartPointer<vtkPolyData> polydata;
  std::string ext = vtksys::SystemTools::GetFilenameExtension(filename);
  if (ext == ".vtk")
    {
    vtkGenericDataObjectReader* reader = vtkGenericDataObjectReader::New();
    reader->SetFileName(filename.c_str());

    vtkDataSetSurfaceFilter* surface = vtkDataSetSurfaceFilter::New();
    surface->SetInputConnection(reader->GetOutputPort());
    surface->Update();

    polydata = surface->GetOutput();

    reader->Delete();
    surface->Delete();
    }
  else if (ext == ".vtp")
    {
    vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
    reader->SetFileName(filename.c_str());
    reader->Update();
    polydata = reader->GetOutput();
    reader->Delete();
    }
  else
    {
    cerr << "Error: Unknown extension: '" << ext << "'"<< endl;
    return 1;
    }

  if (!polydata || polydata->GetNumberOfPoints() == 0)
    {
    cerr << "Error reading file: '" << filename.c_str() << "'" << endl;
    return 1;
    }

  // Set up the render window, renderer, interactor.
  VTK_CREATE_NEW(renWin, vtkRenderWindow);
  VTK_CREATE_NEW(renderer, vtkRenderer);
  VTK_CREATE_NEW(iren, vtkRenderWindowInteractor);
  renWin->SetReportGraphicErrors(1);
  renWin->AddRenderer(renderer);
  renWin->SetSize(300,300);
  iren->SetRenderWindow(renWin);
  renWin->Render();
  if (!vtkSurfaceLICPainter::IsSupported(renWin))
    {
    cout << "WARNING: The rendering context does not support required "
      "extensions." << endl;
    return 0;
    }

  // Create a mapper and insert the vtkSurfaceLICPainter painter into the
  // painter chain. This is essential since the entire logic of performin the
  // LIC is present in the vtkSurfaceLICPainter.
  VTK_CREATE_NEW(mapper, vtkPainterPolyDataMapper);
  VTK_CREATE_NEW(painter, vtkSurfaceLICPainter);
  painter->SetDelegatePainter(mapper->GetPainter());
  mapper->SetPainter(painter);

  // If user chose a vector field, select it.
  if (vectors != "")
    {
    painter->SetInputArrayToProcess(
      vtkDataObject::FIELD_ASSOCIATION_POINTS_THEN_CELLS,
      vectors.c_str());
    }
  else if (!polydata->GetPointData()->GetVectors() &&
    !polydata->GetCellData()->GetVectors())
    {
    cerr << "ERROR: No active vectors are available." << endl<<
            "       Please select the vectors array using '--vectors'" << endl;
    return 1;
    }

  // Pass parameters.
  painter->SetLICIntensity(lic_intensity);
  painter->SetNumberOfSteps(num_steps);
  painter->SetStepSize(step_size);

  // Set the mapper input
  mapper->SetInputData(polydata);

  VTK_CREATE_NEW(actor, vtkActor);
  actor->SetMapper(mapper);
  renderer->AddActor(actor);
  renderer->SetBackground(0.3, 0.3, 0.3);

  if ( RenderingMode )
    {
    // Code used for regression testing.
    renderer->GetActiveCamera()->SetFocalPoint(-1.88, -0.98, -1.04);
    renderer->GetActiveCamera()->SetPosition(13.64, 4.27, -31.59);
    renderer->GetActiveCamera()->SetViewAngle(30);
    renderer->GetActiveCamera()->SetViewUp(0.41, 0.83, 0.35);
    renderer->ResetCamera();
    renWin->Render();
    if (  painter->GetLICSuccess() == 0 ||
          painter->GetRenderingPreparationSuccess() == 0 )
      {
      return 0;
      }

    int retVal = vtkTesting::Test(argc, argv, renWin, 75);
    if (retVal == vtkRegressionTester::DO_INTERACTOR)
      {
      iren->Start();
      }

    if ((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR))
      {
      return 0;
      }
    // failed.
    return 1;
    }
  else
    {
    renderer->ResetCamera();
    renWin->Render();
    if (  painter->GetLICSuccess() == 0 ||
          painter->GetRenderingPreparationSuccess() == 0 )
      {
      return 0;
      }
    iren->Start();
    }
  // failed.
  return 0;
}

#endif