TMC3.cpp 35 KB
Newer Older
1001
    if (params->colorTransform == COLOR_TRANSFORM_RGB_TO_YCBCR) {
1002
      convertYCbCrBt709ToGbr(*reconPointCloud);
1003
1004
    }

1005
    if (params->reflectanceScale > 1 && reconPointCloud->hasReflectances()) {
1006
1007
      const auto pointCount = reconPointCloud->getPointCount();
      for (size_t i = 0; i < pointCount; ++i) {
1008
1009
        int val =
          reconPointCloud->getReflectance(i) * params->reflectanceScale;
1010
1011
        reconPointCloud->setReflectance(i, val);
      }
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1012
    }
1013

1014
    std::string recName{expandNum(params->reconstructedDataPath, frameNum)};
1015
1016
    ply::write(
      *reconPointCloud, _plyAttrNames, recName, !params->outputBinaryPly);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1017
1018
1019
1020
  }

  return 0;
}
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

//----------------------------------------------------------------------------

void
SequenceEncoder::onOutputBuffer(const PayloadBuffer& buf)
{
  writeTlv(buf, bytestreamFile);
}

//----------------------------------------------------------------------------

void
SequenceEncoder::onPostRecolour(const PCCPointSet3& cloud)
{
  if (params->postRecolorPath.empty()) {
    return;
  }

  std::string plyName{expandNum(params->postRecolorPath, frameNum)};

  // todo(df): stop the clock
  if (params->colorTransform != COLOR_TRANSFORM_RGB_TO_YCBCR) {
1043
    ply::write(cloud, _plyAttrNames, plyName, !params->outputBinaryPly);
1044
1045
1046
1047
    return;
  }

  PCCPointSet3 tmpCloud(cloud);
1048
  convertYCbCrBt709ToGbr(tmpCloud);
1049
  ply::write(tmpCloud, _plyAttrNames, plyName, !params->outputBinaryPly);
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
}

//============================================================================

SequenceDecoder::SequenceDecoder(const Parameters* params)
  : params(params), decoder(params->decoder)
{}

//----------------------------------------------------------------------------

1060
int
1061
SequenceDecoder::decompress(Stopwatch* clock)
1062
{
1063
  ifstream fin(params->compressedStreamPath, ios::binary);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1064
1065
1066
1067
  if (!fin.is_open()) {
    return -1;
  }

1068
1069
  frameNum = params->firstFrameNum;
  this->clock = clock;
1070

1071
  PayloadBuffer buf;
1072
1073

  clock->start();
1074

1075
1076
1077
  while (true) {
    PayloadBuffer* buf_ptr = &buf;
    readTlv(fin, &buf);
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1078

1079
1080
1081
    // at end of file (or other error), flush decoder
    if (!fin)
      buf_ptr = nullptr;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1082

1083
    if (decoder.decompress(buf_ptr, this)) {
1084
1085
1086
1087
1088
1089
      cout << "Error: can't decompress point cloud!" << endl;
      return -1;
    }

    if (!buf_ptr)
      break;
Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1090
  }
1091

1092
1093
1094
1095
  fin.clear();
  fin.seekg(0, ios_base::end);
  std::cout << "Total bitstream size " << fin.tellg() << " B" << std::endl;

1096
  clock->stop();
1097

Khaled Mammou's avatar
TMC3v0  
Khaled Mammou committed
1098
1099
  return 0;
}
1100
1101
1102
1103

//----------------------------------------------------------------------------

void
1104
1105
SequenceDecoder::onOutputCloud(
  const SequenceParameterSet& sps, const PCCPointSet3& decodedPointCloud)
1106
1107
1108
1109
1110
{
  // copy the point cloud in order to modify it according to the output options
  PCCPointSet3 pointCloud(decodedPointCloud);

  if (params->colorTransform == COLOR_TRANSFORM_RGB_TO_YCBCR) {
1111
    convertYCbCrBt709ToGbr(pointCloud);
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
  }

  if (params->reflectanceScale > 1 && pointCloud.hasReflectances()) {
    const auto pointCount = pointCloud.getPointCount();
    for (size_t i = 0; i < pointCount; ++i) {
      int val = pointCloud.getReflectance(i) * params->reflectanceScale;
      pointCloud.setReflectance(i, val);
    }
  }

1122
1123
1124
1125
  // the order of the property names must be determined from the sps
  ply::PropertyNameMap attrNames;
  attrNames.position = axisOrderToPropertyNames(sps.geometry_axis_order);

1126
1127
1128
  // Dump the decoded colour using the pre inverse scaled geometry
  if (!params->preInvScalePath.empty()) {
    std::string filename{expandNum(params->preInvScalePath, frameNum)};
1129
1130
1131
    ply::write(
      pointCloud, attrNames, params->preInvScalePath,
      !params->outputBinaryPly);
1132
1133
1134
1135
1136
1137
1138
  }

  decoder.inverseQuantization(pointCloud);

  clock->stop();

  std::string decName{expandNum(params->reconstructedDataPath, frameNum)};
1139
  if (!ply::write(pointCloud, attrNames, decName, !params->outputBinaryPly)) {
1140
1141
1142
1143
1144
1145
1146
1147
    cout << "Error: can't open output file!" << endl;
  }

  clock->start();

  // todo(df): frame number should be derived from the bitstream
  frameNum++;
}
For faster browsing, not all history is shown. View entire blame