bool MeshPyramidReader::loadMeshPyramid(string meshPath, string meshLevelFormat,
    int frame, IntegerContainerType& meshLevelList)
{
    // check if file exist or not first
    if(!existenceTest(meshPath, meshLevelFormat, frame, meshLevelList))
    return false;
    
    if(!trackerInitialized){
        currentMeshPyramid = std::move(PangaeaMeshPyramid(meshLoadingSettings.meshPath,
                meshLoadingSettings.meshLevelFormat, currentFrameNo,
                meshLoadingSettings.meshLevelList));
        if(meshLoadingSettings.loadProp)
        {
            propMeshPyramid = std::move(PangaeaMeshPyramid(meshLoadingSettings.meshPath,
                    meshLoadingSettings.propLevelFormat, currentFrameNo,
                    meshLoadingSettings.meshLevelList));
        }
    }else
    {
        currentMeshPyramid.updatePyramid(meshLoadingSettings.meshPath,
            meshLoadingSettings.meshLevelFormat, currentFrameNo,
            meshLoadingSettings.meshLevelList);
            if(meshLoadingSettings.loadProp)
            {
                propMeshPyramid.updatePyramid(meshLoadingSettings.meshPath,
                    meshLoadingSettings.propLevelFormat, currentFrameNo,
                    meshLoadingSettings.meshLevelList);
            }
    }
    return true;
}
MeshBufferReader::MeshBufferReader(MeshLoadingSettings& settings, int width,
                                   int height, double K[3][3], int startFrame, int numTrackingFrames): trackerInitialized(false)
{
  m_nWidth = width;
  m_nHeight = height;
  startFrameNo = startFrame;
  currentFrameNo = startFrame;

  pCurrentColorImageRGB = new unsigned char[3*width*height];
  // in this case camPose will always be zero
  for(int i = 0; i < 6; ++i)
    camPose[i] = 0;

  useVisibilityMask = settings.visibilityMask;

  setIntrinsicMatrix(K);

  nRenderingLevel = 0;
  m_nNumMeshLevels = settings.meshLevelList.size();

  // a bit ugly
  nFrameStep = imageSourceSettings.frameStep;

  // loading meshes into buffer
  // outputInfoPyramidBuffer.resize(numTrackingFrames);
  // outputPropPyramidBuffer.resize(numTrackingFrames);
  int bufferSize = (numTrackingFrames - startFrameNo)/nFrameStep + 1;
  outputInfoPyramidBuffer.resize(bufferSize);
  outputPropPyramidBuffer.resize(bufferSize);

  m_nGoodFrames = 0;

  TICK("loadingMeshBuffer");

  for(int i = startFrameNo; i <= numTrackingFrames; i = i + nFrameStep)
    {

      // TICK("loadingOneFrame");

      if(!existenceTest(settings.meshPath, settings.meshLevelFormat,
                        i, settings.meshLevelList))
        break;

      ++m_nGoodFrames;
      currentMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
                                                        settings.meshLevelFormat, i, settings.meshLevelList));

      // TOCK("loadingOneFrame");

      if(settings.loadProp)
        {
          propMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
                                                         settings.propLevelFormat, i, settings.meshLevelList));
        }
      if(!settings.fastLoading)
        propMeshPyramid = currentMeshPyramid;


      // TICK("setOneFrame");

      setMeshPyramid();

      int bufferPos = (i-startFrameNo)/nFrameStep;
      outputInfoPyramidBuffer[ bufferPos ] = std::move(outputInfoPyramid);
      outputPropPyramidBuffer[ bufferPos ] = std::move(outputPropPyramid);

      // TOCK("setOneFrame");

      cout << "loading frame " << i << endl;
    }

  TOCK("loadingMeshBuffer");

}