File: ospConvertRawToAMR.cpp

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (147 lines) | stat: -rw-r--r-- 5,528 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
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "rawToAMR.h"

static const std::string description = R"description(
Creates an adaptive mesh refinement (AMR) representation of the provided
structured volume data.

The input structured volume data is used as the highest refinement level
(i.e. the finest resolution data). From this level, data that does not meet
the user-provided variance threshold is discarded. The average of the
discarded block is used in the next level down.

This simulates the effect that an adaptive simulation would have created
regions of higher refinement in the highly varying portions of the volume.
)description";

static const std::string usage =
    R"usage([-h | --help] input_volume variable_type x_dim y_dim z_dim num_levels
    block_size refinement_factor threshold output_basename
)usage";

static const std::string help = R"help(
input_volume        Structured volume in binary brick-of-data format
                    (string filepath)
variable_type       Type of structured volume, must be exactly one of:
                        float
                    (string)
x_dim               X dimensions of the structured volume grid (int)
y_dim               Y dimensions of the structured volume grid (int)
z_dim               Z dimensions of the structured volume grid (int)
num_levels          Number of refinement levels to simulate (int)
block_size          Size of blocks at each level in terms of cells. Blocks
                    are defined as cubes with this number of cells per edge.
                    Note that refinement levels change the width of the
                    cells, NOT the width of the blocks. Blocks will always
                    be this provided size in cell extents, but the width of
                    the cells will be smaller/larger depending on level.
                    For example, a block of 4x4x4 cells at the highest
                    refinement level will be converted into a single cell
                    at the next lower level, which would be part of that
                    level's block of 4x4x4 cells. (int)
refinement_factor   How much larger/smaller, in terms of cell extents, each
                    level's grid will be. Note that this is independent of
                    block_size above! For example, if the input data is a
                    512^3 grid, and block_size is 4^3, the highest
                    refinement level will have a 128^3 block grid. If this
                    value is 2, the next level will have a 64^3 block grid,
                    but will still be comprised of 4^3 blocks. That is, the
                    number of cells decreases from 512^3 to 256^3, and the
                    cell width increases to accommodate. (int)
threshold           Variance threshold used to determine whether a block
                    belongs to a higher refinement level. If the variance
                    within a block is above this threshold, it remains at
                    the current level. Otherwise, if the variance is low,
                    this block would have not have been selected for mesh
                    refinement by a numerical simulation, so this block is
                    discarded at this level. (variable_type, converted to
                    float)
output_basename     Basename for the output files. This application creates
                    three files with different extensions, with this basename
                    in common. (string)
)help";

using namespace rkcommon::math;

static std::string inFileName;
static std::string format;
static vec3i inDims;
static int numLevels;
static int blockSize;
static int refinementLevel;
static float threshold;
static std::string outFileBase;

bool parseArguments(int argc, char **argv)
{
  if (argc != 11) {
    if (argc > 1
        && (std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help")) {
      std::cerr << description << std::endl;
      std::cerr << "Usage: " << argv[0] << " " << usage << std::endl;
      std::cerr << help << std::endl;
    } else {
      std::cerr << argc - 1 << " argument"
                << ((argc == 1 || argc > 2) ? "s " : " ");
      std::cerr << "provided, but 10 are needed" << std::endl;
      std::cerr << "Usage: " << argv[0] << " " << usage << std::endl;
    }
    return false;
  }

  inFileName = argv[1];
  format = argv[2];
  inDims.x = atoi(argv[3]);
  inDims.y = atoi(argv[4]);
  inDims.z = atoi(argv[5]);
  numLevels = atoi(argv[6]);
  blockSize = atoi(argv[7]);
  refinementLevel = atoi(argv[8]);
  threshold = atof(argv[9]);
  outFileBase = argv[10];

  return true;
}

int main(int argc, char **argv)
{
  bool parseSucceed = parseArguments(argc, argv);
  if (!parseSucceed) {
    return 1;
  }

  // ALOK: TODO:
  // support more than float
  std::vector<float> in;
  if (format == "float") {
    in = ospray::amr::mmapRAW<float>(inFileName, inDims);
  } else {
    throw std::runtime_error("unsupported input voxel format");
  }

  std::vector<box3i> blockBounds;
  std::vector<int> refinementLevels;
  std::vector<float> cellWidths;
  std::vector<std::vector<float>> brickData;

  ospray::amr::makeAMR(in,
      inDims,
      numLevels,
      blockSize,
      refinementLevel,
      threshold,
      blockBounds,
      refinementLevels,
      cellWidths,
      brickData);
  ospray::amr::outputAMR(outFileBase,
      blockBounds,
      refinementLevels,
      cellWidths,
      brickData,
      blockSize);

  return 0;
}