<commit_before>//
//  MultiLayerTileTexturizer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 08/08/12.
//
//

#include "MultiLayerTileTexturizer.hpp"
#include "Context.hpp"
#include "LayerSet.hpp"
#include "TilesRenderParameters.hpp"
#include "Tile.hpp"
#include "LeveledTexturedMesh.hpp"
#include "RectangleI.hpp"
#include "TexturesHandler.hpp"
#include "TextureBuilder.hpp"
#include "TileRenderer.hpp"
#include "TileTessellator.hpp"
#include "Geodetic3D.hpp"
#include "RCObject.hpp"
#include "ITimer.hpp"
#include "FrameTasksExecutor.hpp"
#include "IImageDownloadListener.hpp"
#include "IDownloader.hpp"
#include "Petition.hpp"
#include "GLConstants.hpp"
#include "IImageListener.hpp"

#define TILE_DOWNLOAD_PRIORITY 1000000000

enum PetitionStatus {
  STATUS_PENDING,
  STATUS_DOWNLOADED,
  STATUS_CANCELED
};


class BuilderDownloadStepDownloadListener : public IImageDownloadListener {
private:
  TileTextureBuilder* _builder;
  const int           _position;
public:
  BuilderDownloadStepDownloadListener(TileTextureBuilder* builder,
                                      int position);

  void onDownload(const URL& url,
                  const IImage* image);

  void onError(const URL& url);

  void onCanceledDownload(const URL& url,
                          const IImage* image) {
  }

  void onCancel(const URL& url);

  virtual ~BuilderDownloadStepDownloadListener();

};


class LTMInitializer : public LazyTextureMappingInitializer {
private:
  const Tile* _tile;
  const Tile* _ancestor;

  MutableVector2D _scale;
  MutableVector2D _translation;

  IFloatBuffer* _texCoords;

public:
  LTMInitializer(const Tile* tile,
                 const Tile* ancestor,
                 IFloatBuffer* texCoords) :
  _tile(tile),
  _ancestor(ancestor),
  _texCoords(texCoords),
  _scale(1,1),
  _translation(0,0)
  {

  }

  virtual ~LTMInitializer() {

  }

  void initialize() {
    // The default scale and translation are ok when (tile == _ancestor)
    if (_tile != _ancestor) {
      const Sector tileSector     = _tile->getSector();
      const Sector ancestorSector = _ancestor->getSector();

      _scale       = tileSector.getScaleFactor(ancestorSector).asMutableVector2D();
      _translation = tileSector.getTranslationFactor(ancestorSector).asMutableVector2D();
    }
  }

  const MutableVector2D getScale() const {
    return _scale;
  }

  const MutableVector2D getTranslation() const {
    return _translation;
  }

  IFloatBuffer* getTexCoords() const {
    return _texCoords;
  }

};


class TileTextureBuilderHolder : public ITexturizerData {
private:
  TileTextureBuilder* _builder;

public:
  TileTextureBuilderHolder(TileTextureBuilder* builder) :
  _builder(builder)
  {

  }

  TileTextureBuilder* get() const {
    return _builder;
  }

  virtual ~TileTextureBuilderHolder();

  bool isTexturizerData() const{
    return true;
  }
};


class TextureUploader : public IImageListener {
private:
  TileTextureBuilder* _builder;

  const std::vector<const RectangleI*> _rectangles;
  const std::string _textureId;

public:
  TextureUploader(TileTextureBuilder* builder,
                  std::vector<const RectangleI*> rectangles,
                  const std::string& textureId) :
  _builder(builder),
  _rectangles(rectangles),
  _textureId(textureId)
  {

  }

  void imageCreated(IImage* image);
};


class TileTextureBuilder : public RCObject {
private:
  MultiLayerTileTexturizer* _texturizer;
  Tile*                     _tile;

  //  const TileKey             _tileKey;<commit_msg>First version (core and iOS) of async image-creation<commit_after>//
//  MultiLayerTileTexturizer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 08/08/12.
//
//

#include "MultiLayerTileTexturizer.hpp"
#include "Context.hpp"
#include "LayerSet.hpp"
#include "TilesRenderParameters.hpp"
#include "Tile.hpp"
#include "LeveledTexturedMesh.hpp"
#include "RectangleI.hpp"
#include "TexturesHandler.hpp"
#include "TextureBuilder.hpp"
#include "TileRenderer.hpp"
#include "TileTessellator.hpp"
#include "Geodetic3D.hpp"
#include "RCObject.hpp"
#include "ITimer.hpp"
#include "FrameTasksExecutor.hpp"
#include "IImageDownloadListener.hpp"
#include "IDownloader.hpp"
#include "Petition.hpp"
#include "GLConstants.hpp"
#include "IImageListener.hpp"

#define TILE_DOWNLOAD_PRIORITY 1000000000

enum PetitionStatus {
  STATUS_PENDING,
  STATUS_DOWNLOADED,
  STATUS_CANCELED
};


class BuilderDownloadStepDownloadListener : public IImageDownloadListener {
private:
  TileTextureBuilder* _builder;
  const int           _position;
public:
  BuilderDownloadStepDownloadListener(TileTextureBuilder* builder,
                                      int position);

  void onDownload(const URL& url,
                  const IImage* image);

  void onError(const URL& url);

  void onCanceledDownload(const URL& url,
                          const IImage* image) {
  }

  void onCancel(const URL& url);

  virtual ~BuilderDownloadStepDownloadListener();

};


class LTMInitializer : public LazyTextureMappingInitializer {
private:
  const Tile* _tile;
  const Tile* _ancestor;

  MutableVector2D _scale;
  MutableVector2D _translation;

  IFloatBuffer* _texCoords;

public:
  LTMInitializer(const Tile* tile,
                 const Tile* ancestor,
                 IFloatBuffer* texCoords) :
  _tile(tile),
  _ancestor(ancestor),
  _texCoords(texCoords),
  _scale(1,1),
  _translation(0,0)
  {

  }

  virtual ~LTMInitializer() {

  }

  void initialize() {
    // The default scale and translation are ok when (tile == _ancestor)
    if (_tile != _ancestor) {
      const Sector tileSector     = _tile->getSector();
      const Sector ancestorSector = _ancestor->getSector();

      _scale       = tileSector.getScaleFactor(ancestorSector).asMutableVector2D();
      _translation = tileSector.getTranslationFactor(ancestorSector).asMutableVector2D();
    }
  }

  const MutableVector2D getScale() const {
    return _scale;
  }

  const MutableVector2D getTranslation() const {
    return _translation;
  }

  IFloatBuffer* getTexCoords() const {
    return _texCoords;
  }

};


class TileTextureBuilderHolder : public ITexturizerData {
private:
  TileTextureBuilder* _builder;

public:
  TileTextureBuilderHolder(TileTextureBuilder* builder) :
  _builder(builder)
  {

  }

  TileTextureBuilder* get() const {
    return _builder;
  }

  virtual ~TileTextureBuilderHolder();

  bool isTexturizerData() const{
    return true;
  }
};


class TextureUploader : public IImageListener {
private:
  TileTextureBuilder* _builder;

#ifdef C_CODE
  const std::vector<const RectangleI*> _rectangles;
#endif
#ifdef JAVA_CODE
  private final java.util.ArrayList<RectangleI> _rectangles = new java.util.ArrayList<RectangleI>();
#endif
  const std::string _textureId;

public:
  TextureUploader(TileTextureBuilder* builder,
                  std::vector<const RectangleI*> rectangles,
                  const std::string& textureId) :
  _builder(builder),
  _rectangles(rectangles),
  _textureId(textureId)
  {

  }

  void imageCreated(IImage* image);
};


class TileTextureBuilder : public RCObject {
private:
  MultiLayerTileTexturizer* _texturizer;
  Tile*                     _tile;

  //  const TileKey             _tileKey;
{'fraction_non_alphanumeric': 0.09663108276722585, 'fraction_numerical': 0.007763759877998059, 'mean_word_length': 3.660206718346253, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083885', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2247, 'n_words': 490}