File: TestThreadedCopy.cxx

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (87 lines) | stat: -rw-r--r-- 2,110 bytes parent folder | download | duplicates (4)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

// This Test validates that we can do a threaded copy of an imagedata
// and helps to evaluate the performance of doing so.

#include "vtkDataSetWriter.h"
#include "vtkImageData.h"
#include "vtkSMPTools.h"
#include "vtkSmartPointer.h"

#include <cmath>

int TestThreadedCopy(int ac, char* av[])
{
  double GB = 0.01;
  bool write = false;

  for (int i = 0; i < ac; ++i)
  {
    if (i < ac - 1 && !strcmp(av[i], "--numThreads"))
    {
      vtkSMPTools::Initialize(atoi(av[i + 1]));
    }
    if (i < ac - 1 && !strcmp(av[i], "--GB"))
    {
      GB = atof(av[i + 1]);
    }
    if (!strcmp(av[i], "--write"))
    {
      write = true;
    }
  }

  vtkImageData* hugeImage = vtkImageData::New();
  int edge = static_cast<int>(pow((1024l * 1024 * 1024 * GB) / (3 * VTK_SIZEOF_INT), 1 / 3.));
  hugeImage->SetDimensions(edge, edge, edge);
  hugeImage->AllocateScalars(VTK_INT, 3);

  if (write)
  {
    cout << "Populate it." << endl;
    int* ptr = static_cast<int*>(hugeImage->GetScalarPointer());
    for (int k = 0; k < edge; ++k)
    {
      double z = (double)k / edge - 0.5;
      if (k % (edge / 10) == 0)
      {
        cout << (z + 0.5) * 100 << "% done" << endl;
      }
      for (int j = 0; j < edge; ++j)
      {
        double y = (double)j / edge - 0.5;
        for (int i = 0; i < edge; ++i)
        {
          double x = (double)i / edge - 0.5;
          *ptr = 42;
          ++ptr;
          *ptr = (int)((x * y * z + 0.125) * 4.0 * VTK_INT_MAX);
          ++ptr;
          *ptr = (int)x;
          ++ptr;
        }
      }
    }
  }

  vtkImageData* d = vtkImageData::New();
  d->DeepCopy(hugeImage);

  vtkSmartPointer<vtkDataSetWriter> dsw = vtkSmartPointer<vtkDataSetWriter>::New();
  dsw->SetInputData(hugeImage);
  dsw->SetFileName("source.vtk");
  dsw->SetInputData(d);
  dsw->SetFileName("dest.vtk");
  if (write)
  {
    cout << "Write them." << endl;
    dsw->Write();
    dsw->Write();
  }

  hugeImage->Delete();
  d->Delete();

  return EXIT_SUCCESS;
}