TMC3.cpp 19.6 KB
Newer Older
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1
/* The copyright in this software is being made available under the BSD
David Flynn's avatar
David Flynn committed
2
3
4
 * Licence, included below.  This software may be subject to other third
 * party and contributor rights, including patent rights, and no such
 * rights are granted under this licence.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
5
 *
David Flynn's avatar
David Flynn committed
6
 * Copyright (c) 2017-2018, ISO/IEC
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
7
8
9
10
11
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
David Flynn's avatar
David Flynn committed
12
13
14
15
16
17
18
19
20
21
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of the ISO/IEC nor the names of its contributors
 *   may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
22
23
24
25
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
David Flynn's avatar
David Flynn committed
26
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
28
29
30
31
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
David Flynn's avatar
David Flynn committed
32
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
34
35
36
 */

#include "TMC3.h"
37
#include "program_options_lite.h"
38
#include "version.h"
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
39
40
41
42
43

using namespace std;
using namespace pcc;

int main(int argc, char *argv[]) {
44
  cout << "MPEG PCC tmc3 version " << ::pcc::version << endl;
45

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
46
47
48
49
  Parameters params;
  if (!ParseParameters(argc, argv, params)) {
    return -1;
  }
50
51
52
53
54
55
56

  // Timers to count elapsed wall/user time
  pcc::chrono::Stopwatch<std::chrono::steady_clock> clock_wall;
  pcc::chrono::Stopwatch<pcc::chrono::utime_inc_children_clock> clock_user;

  clock_wall.start();

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
57
  int ret = 0;
58
59
  if (params.mode == CODEC_MODE_ENCODE || params.mode == CODEC_MODE_ENCODE_LOSSLESS_GEOMETRY ||
      params.mode == CODEC_MODE_ENCODE_TRISOUP_GEOMETRY) {
60
    ret = Compress(params, clock_user);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
61
  } else {
62
    ret = Decompress(params, clock_user);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
63
64
  }

65
66
67
68
69
70
71
72
  clock_wall.stop();

  using namespace std::chrono;
  auto total_wall = duration_cast<milliseconds>(clock_wall.count()).count();
  auto total_user = duration_cast<milliseconds>(clock_user.count()).count();
  std::cout << "Processing time (wall): " << total_wall / 1000.0 << " s\n";
  std::cout << "Processing time (user): " << total_user / 1000.0 << " s\n";

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
73
74
75
  return ret;
}

76
77
78
79
80
81
82
83
84
85
86
87
88
//---------------------------------------------------------------------------
// :: Command line / config parsing helpers

template <typename T>
static std::istream& readUInt(std::istream &in, T &val) {
  unsigned int tmp;
  in >> tmp;
  val = T(tmp);
  return in;
}

static std::istream& operator>>(std::istream &in, CodecMode &val) {
  return readUInt(in, val);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
89
90
}

91
92
93
94
static std::istream& operator>>(std::istream &in, ColorTransform &val) {
  return readUInt(in, val);
}

95
96
97
98
99
100
101
102
103
104
105
106
107
108
namespace pcc {
static std::istream& operator>>(std::istream &in, TransformType &val) {
  return readUInt(in, val);
}}

namespace pcc {
static std::ostream& operator<<(std::ostream &out, const TransformType &val) {
  switch (val) {
  case TransformType::kIntegerLift: out << "0 (IntegerLifting)"; break;
  case TransformType::kRAHT:        out << "1 (RAHT)"; break;
  }
  return out;
}}

109
110
111
//---------------------------------------------------------------------------
// :: Command line / config parsing

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
112
bool ParseParameters(int argc, char *argv[], Parameters &params) {
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

  namespace po = df::program_options_lite;

  PCCAttributeEncodeParamaters params_attr;
  bool print_help = false;

  // a helper to set the attribute
  std::function<po::OptionFunc::Func> attribute_setter =
    [&](po::Options&, const std::string& name, po::ErrorReporter) {
      // copy the current state of parsed attribute parameters
      //
      // NB: this does not cause the default values of attr to be restored
      // for the next attribute block.  A side-effect of this is that the
      // following is allowed leading to attribute foo having both X=1 and
      // Y=2:
      //   "--attr.X=1 --attribute foo --attr.Y=2 --attribute foo"
      //
      params.encodeParameters.attributeEncodeParameters[name] = params_attr;
    };

  // The definition of the program/config options, along with default values.
  //
  // NB: when updating the following tables:
  //      (a) please keep to 80-columns for easier reading at a glance,
  //      (b) do not vertically align values -- it breaks quickly
  //
  po::Options opts;
  opts.addOptions()
  ("help", print_help, false, "this help text")
  ("config,c", po::parseConfigFile, "configuration file name")

  ("mode", params.mode, CODEC_MODE_ENCODE,
     "The encoding/decoding mode:\n"
     "  0: encode\n"
     "  1: decode\n"
     "  2: encode with lossless geometry\n"
149
150
151
     "  3: decode with lossless geometry\n"
     "  4: encode with trisoup geometry\n"
     "  5: decode with trisoup geoemtry")
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

  // i/o parameters
  ("reconstructedDataPath",
     params.reconstructedDataPath, {},
     "The ouput reconstructed pointcloud file path (decoder only)")

  ("uncompressedDataPath",
     params.uncompressedDataPath, {},
     "The input pointcloud file path")

  ("compressedStreamPath",
     params.compressedStreamPath, {},
     "The compressed bitstream path (encoder=output, decoder=input)")

  // general
  ("colorTransform",
     params.colorTransform, COLOR_TRANSFORM_RGB_TO_YCBCR,
     "The colour transform to be applied:\n"
     "  0: none\n"
     "  1: RGB to YCbCr (Rec.709)")

  ("positionQuantizationScale",
     params.encodeParameters.positionQuantizationScale, 1.,
     "Scale factor to be applied to point positions during quantization process")

  ("mergeDuplicatedPoints",
     params.encodeParameters.mergeDuplicatedPoints, true,
     "Enables removal of duplicated points")

  ("roundOutputPositions",
     params.roundOutputPositions, false,
     "todo(kmammou)")

185
186
187
188
189
  // tools
  ("neighbourContextualisation",
     params.encodeParameters.neighbourContextsEnabled, true,
     "Contextualise geometry octree occupancy based on neighbour patterns")

190
191
192
193
  ("inferredDirectCodingMode",
     params.encodeParameters.inferredDirectCodingModeEnabled, true,
     "Permits early termination of the geometry octree for isolated points")

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  // (trisoup) geometry parameters
  ("triSoupDepth",  // log2(maxBB+1), where maxBB+1 is analogous to image width
     params.encodeParameters.triSoup.depth, 10,
     "Depth of voxels (reconstructed points) in trisoup geometry")

  ("triSoupLevel",
     params.encodeParameters.triSoup.level, 7,
     "Level of triangles (reconstructed surface) in trisoup geometry")

  ("triSoupIntToOrigScale",  // reciprocal of positionQuantizationScale
     params.encodeParameters.triSoup.intToOrigScale, 1.,
     "orig_coords = integer_coords * intToOrigScale + intToOrigTranslation")

  ("triSoupIntToOrigTranslation",
     params.encodeParameters.triSoup.intToOrigTranslation, {0., 0., 0.},
     "orig_coords = integer_coords * intToOrigScale + intToOrigTranslation")

211
212
213
214
215
216
217
218
  // attribute processing
  //   NB: Attribute options are special in the way they are applied (see above)
  ("attribute",
     attribute_setter,
     "Encode the given attribute (NB, must appear after the"
     "following attribute parameters)")

  ("searchRange",
219
     params_attr.searchRange, size_t(0),
220
221
     "Attribute's todo(kmammou)")

222
223
224
225
226
227
  ("transformType",
     params_attr.transformType, TransformType::kIntegerLift,
     "Coding method to use for attribute:\n"
     "  0: Nearest neighbour prediction with integer lifting transform\n"
     "  1: Region Adaptive Hierarchical Transform (RAHT)")

228
229
230
231
232
  ("rahtLeafDecimationDepth",
     params_attr.binaryLevelThresholdRaht, 3,
     "Sets coefficients to zero in the bottom n levels of RAHT tree. "
     "Used for chroma-subsampling in attribute=color only.")

233
234
235
236
237
238
239
240
241
  ("rahtQuantizationStep",
     params_attr.quantizationStepRaht, 1,
     "Quantization step size used in RAHT")

  ("rahtDepth",
     params_attr.depthRaht, 21,
     "Number of bits for morton representation of an RAHT co-ordinate"
     "component")

242
  ("numberOfNearestNeighborsInPrediction",
243
     params_attr.numberOfNearestNeighborsInPrediction, size_t(4),
244
245
246
247
248
249
250
251
252
253
254
255
256
257
     "Attribute's maximum number of nearest neighbors to be used for prediction")

  ("levelOfDetailCount",
     params_attr.levelOfDetailCount, size_t(6),
     "Attribute's number of levels of detail")

  ("quantizationSteps",
     params_attr.quantizationSteps, {},
     "Attribute's list of quantization step sizes (one for each LoD)")

  ("dist2", params_attr.dist2, {},
     "Attribute's list of squared distances (one for each LoD)")
  ;

258

259
260
261
262
263
264
265
266
267
268
269
270
271
272
  po::setDefaults(opts);
  po::ErrorReporter err;
  const list<const char*>& argv_unhandled =
    po::scanArgv(opts, argc, (const char**)argv, err);

  for (const auto arg : argv_unhandled) {
    err.warn() << "Unhandled argument ignored: " << arg << "\n";
  }

  if (argc == 1 || print_help) {
    po::doHelp(std::cout, opts, 78);
    return false;
  }

273
274
275
276
277
278
279
280
  // For trisoup, ensure that positionQuantizationScale is the exact inverse of intToOrigScale.
  if (params.mode == 4 &&
      params.encodeParameters.positionQuantizationScale !=
          1.0 / params.encodeParameters.triSoup.intToOrigScale) {
    params.encodeParameters.positionQuantizationScale =
        1.0 / params.encodeParameters.triSoup.intToOrigScale;
  }

281
282
283
284
285
286
287
  // For RAHT, ensure that the unused lod count = 0 (prevents mishaps)
  for (auto &attr : params.encodeParameters.attributeEncodeParameters) {
    if (attr.second.transformType != TransformType::kIntegerLift) {
      attr.second.levelOfDetailCount = 0;
    }
  }

288
  // sanity checks
289
  //  - validate that quantizationSteps, dist2
290
291
  //    of each attribute contain levelOfDetailCount elements.
  for (const auto &attr : params.encodeParameters.attributeEncodeParameters) {
292
293
    if (attr.second.transformType == TransformType::kIntegerLift) {
      int lod = attr.second.levelOfDetailCount;
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
      if (lod > 255) {
        err.error() << attr.first
          << ".levelOfDetailCount must be less than 256\n";
      }
      if (attr.second.dist2.size() != lod) {
        err.error() << attr.first << ".dist2 does not have " << lod << " entries\n";
      }
      if (attr.second.quantizationSteps.size() != lod) {
        err.error() << attr.first << ".quantizationSteps does not have " << lod << " entries\n";
      }
      if (attr.second.numberOfNearestNeighborsInPrediction >
          PCCTMC3MaxPredictionNearestNeighborCount)
      {
        err.error() << attr.first
          << ".numberOfNearestNeighborsInPrediction must be less than "
          << PCCTMC3MaxPredictionNearestNeighborCount << "\n";
      }
312
    }
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
313
314
  }

315
316
  // check required arguments are specified

317
  const bool encode =
318
      params.mode == CODEC_MODE_ENCODE
319
320
      || params.mode == CODEC_MODE_ENCODE_LOSSLESS_GEOMETRY
      || params.mode == CODEC_MODE_ENCODE_TRISOUP_GEOMETRY;
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

  if (encode && params.uncompressedDataPath.empty())
    err.error() << "uncompressedDataPath not set\n";

  if (!encode && params.reconstructedDataPath.empty())
    err.error() << "reconstructedDataPath not set\n";

  if (params.compressedStreamPath.empty())
    err.error() << "compressedStreamPath not set\n";

  // currently the attributes with lossless geometry require the source data
  // todo(?): remove this dependency by improving reporting
  if (params.mode == CODEC_MODE_DECODE_LOSSLESS_GEOMETRY
   && params.uncompressedDataPath.empty())
    err.error() << "uncompressedDataPath not set\n";

  // report the current configuration (only in the absence of errors so
  // that errors/warnings are more obvious and in the same place).
  if (err.is_errored)
    return false;

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
342
  cout << "+ Parameters" << endl;
343
344
345
346
347
  cout << "\t mode                        ";
  if (params.mode == CODEC_MODE_ENCODE) {
    cout << "encode" << endl;
  } else if (params.mode == CODEC_MODE_ENCODE_LOSSLESS_GEOMETRY) {
    cout << "encode with lossless geometry" << endl;
348
349
  } else if (params.mode == CODEC_MODE_ENCODE_TRISOUP_GEOMETRY) {
    cout << "encode with trisoup geometry" << endl;
350
351
352
353
  } else if (params.mode == CODEC_MODE_DECODE) {
    cout << "decode" << endl;
  } else if (params.mode == CODEC_MODE_DECODE_LOSSLESS_GEOMETRY) {
    cout << "decode with lossless geometry" << endl;
354
355
  } else if (params.mode == CODEC_MODE_DECODE_TRISOUP_GEOMETRY) {
    cout << "decode with trisoup geometry" << endl;
356
  }
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
357
358
359
360
  cout << "\t uncompressedDataPath        " << params.uncompressedDataPath << endl;
  cout << "\t compressedStreamPath        " << params.compressedStreamPath << endl;
  cout << "\t reconstructedDataPath       " << params.reconstructedDataPath << endl;
  cout << "\t colorTransform              " << params.colorTransform << endl;
361
  if (encode) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
362
363
364
365
    cout << "\t mergeDuplicatedPoints       " << params.encodeParameters.mergeDuplicatedPoints
         << endl;
    cout << "\t positionQuantizationScale   " << params.encodeParameters.positionQuantizationScale
         << endl;
366
367
    cout << "\t neighbourContextualisation  " << params.encodeParameters.neighbourContextsEnabled
         << endl;
368
369
370
371
372
373
374
375
376
377
    if (params.mode == CODEC_MODE_ENCODE_TRISOUP_GEOMETRY) {
      cout << "\t triSoupDepth                " << params.encodeParameters.triSoup.depth << endl;
      cout << "\t triSoupLevel                " << params.encodeParameters.triSoup.level << endl;
      cout << "\t triSoupIntToOrigScale       " << params.encodeParameters.triSoup.intToOrigScale << endl;
      cout << "\t triSoupIntToOrigTranslation ";
      for (const auto tr : params.encodeParameters.triSoup.intToOrigTranslation) {
        cout << tr << " ";
      }
      cout << endl;
    }
378
    for (const auto & attributeEncodeParameters : params.encodeParameters.attributeEncodeParameters) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
379
      cout << "\t " << attributeEncodeParameters.first << endl;
380
381
      cout << "\t\t transformType                          "
           << attributeEncodeParameters.second.transformType << endl;
382
383
384
385
386
387

      if (attributeEncodeParameters.second.transformType == TransformType::kRAHT) {
        cout << "\t\t rahtQuantizationStep                   "
             << attributeEncodeParameters.second.quantizationStepRaht << endl;
        cout << "\t\t rahtDepth                              "
             << attributeEncodeParameters.second.depthRaht << endl;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
388
      }
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

      if (attributeEncodeParameters.second.transformType == TransformType::kIntegerLift) {
        cout << "\t\t numberOfNearestNeighborsInPrediction   "
             << attributeEncodeParameters.second.numberOfNearestNeighborsInPrediction << endl;
        cout << "\t\t searchRange                            "
             << attributeEncodeParameters.second.searchRange << endl;
        cout << "\t\t levelOfDetailCount                     "
             << attributeEncodeParameters.second.levelOfDetailCount << endl;
        cout << "\t\t dist2                                  ";
        for (const auto qs : attributeEncodeParameters.second.dist2) {
          cout << qs << " ";
        }
        cout << endl;
        cout << "\t\t quantizationSteps                      ";
        for (const auto qs : attributeEncodeParameters.second.quantizationSteps) {
          cout << qs << " ";
        }
        cout << endl;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
407
408
409
      }
    }
    cout << endl;
410
411
  } else {
      cout << "\t roundOutputPositions        " << params.roundOutputPositions << endl;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
412
413
414
415
  }

  return true;
}
416

417
int Compress(const Parameters &params, Stopwatch& clock) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
418
419
420
421
422
423
  PCCPointSet3 pointCloud;
  if (!pointCloud.read(params.uncompressedDataPath) || pointCloud.getPointCount() == 0) {
    cout << "Error: can't open input file!" << endl;
    return -1;
  }

424
425
  clock.start();

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
426
427
428
429
430
431
432
  if (params.colorTransform == COLOR_TRANSFORM_RGB_TO_YCBCR) {
    pointCloud.convertRGBToYUV();
  }
  PCCTMC3Encoder3 encoder;
  PCCBitstream bitstream = {};
  const size_t predictedBitstreamSize =
      encoder.estimateBitstreamSize(pointCloud, params.encodeParameters);
433
  std::unique_ptr<uint8_t[]> buffer(new uint8_t[predictedBitstreamSize]);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
434
435
436
437
438
439
440
441
442
  bitstream.buffer = buffer.get();
  bitstream.capacity = predictedBitstreamSize;
  bitstream.size = 0;

  std::unique_ptr<PCCPointSet3> reconstructedPointCloud;
  if (!params.reconstructedDataPath.empty()) {
    reconstructedPointCloud.reset(new PCCPointSet3);
  }

443
444
445
446
447
  if ((params.mode == CODEC_MODE_ENCODE &&
       encoder.compress(pointCloud, params.encodeParameters, bitstream,
                        reconstructedPointCloud.get())) ||
      (params.mode == CODEC_MODE_ENCODE_LOSSLESS_GEOMETRY &&
       encoder.compressWithLosslessGeometry(pointCloud, params.encodeParameters, bitstream,
448
449
450
451
                                            reconstructedPointCloud.get())) ||
      (params.mode == CODEC_MODE_ENCODE_TRISOUP_GEOMETRY &&
       encoder.compressWithTrisoupGeometry(pointCloud, params.encodeParameters, bitstream,
                                           reconstructedPointCloud.get()))) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
452
453
454
    cout << "Error: can't compress point cloud!" << endl;
    return -1;
  }
455

456
457
  clock.stop();

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
  assert(bitstream.size <= bitstream.capacity);
  std::cout << "Total bitstream size " << bitstream.size << " B" << std::endl;
  ofstream fout(params.compressedStreamPath, ios::binary);
  if (!fout.is_open()) {
    return -1;
  }
  fout.write(reinterpret_cast<const char *>(bitstream.buffer), bitstream.size);
  fout.close();

  if (!params.reconstructedDataPath.empty()) {
    if (params.colorTransform == COLOR_TRANSFORM_RGB_TO_YCBCR) {
      reconstructedPointCloud->convertYUVToRGB();
    }
    reconstructedPointCloud->write(params.reconstructedDataPath, true);
  }

  return 0;
}
476
int Decompress(const Parameters &params, Stopwatch &clock) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  PCCBitstream bitstream = {};
  ifstream fin(params.compressedStreamPath, ios::binary);
  if (!fin.is_open()) {
    return -1;
  }
  fin.seekg(0, std::ios::end);
  uint64_t bitStreamSize = fin.tellg();
  fin.seekg(0, std::ios::beg);
  unique_ptr<uint8_t[]> buffer(new uint8_t[bitStreamSize]);
  bitstream.buffer = buffer.get();
  bitstream.capacity = bitStreamSize;
  bitstream.size = 0;
  fin.read(reinterpret_cast<char *>(bitstream.buffer), bitStreamSize);
  if (!fin) {
    return -1;
  }
  fin.close();

495
496
  clock.start();

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
497
498
  PCCTMC3Decoder3 decoder;
  PCCPointSet3 pointCloud;
499
500
501
502
503
504
505
506
507
  if (params.mode == CODEC_MODE_DECODE_LOSSLESS_GEOMETRY) {  // read geometry from input file
    if (!pointCloud.read(params.uncompressedDataPath) || pointCloud.getPointCount() == 0) {
      cout << "Error: can't open input file!" << endl;
      return -1;
    }
    pointCloud.removeReflectances();
    pointCloud.removeColors();
  }

508
  if ((params.mode == CODEC_MODE_DECODE && decoder.decompress(bitstream, pointCloud, params.roundOutputPositions)) ||
509
      (params.mode == CODEC_MODE_DECODE_LOSSLESS_GEOMETRY &&
510
511
512
       decoder.decompressWithLosslessGeometry(bitstream, pointCloud)) ||
      (params.mode == CODEC_MODE_DECODE_TRISOUP_GEOMETRY &&
       decoder.decompressWithTrisoupGeometry(bitstream, pointCloud, params.roundOutputPositions))) {
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
513
514
515
516
517
518
519
520
521
522
    cout << "Error: can't decompress point cloud!" << endl;
    return -1;
  }
  assert(bitstream.size <= bitstream.capacity);
  std::cout << "Total bitstream size " << bitstream.size << " B" << std::endl;

  if (params.colorTransform == COLOR_TRANSFORM_RGB_TO_YCBCR) {
    pointCloud.convertYUVToRGB();
  }

523
524
  clock.stop();

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
525
526
527
528
529
530
  if (!pointCloud.write(params.reconstructedDataPath, true)) {
    cout << "Error: can't open output file!" << endl;
    return -1;
  }
  return 0;
}