mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 17:13:09 +08:00
Replace remaining GenericVector by std::vector for src/classify
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
7df1cb0bab
commit
a847e0f9b5
@ -356,6 +356,7 @@ void DENORM::LocalDenormTransform(const TPOINT &pt, TPOINT *original) const {
|
|||||||
original->x = IntCastRounded(float_result.x());
|
original->x = IntCastRounded(float_result.x());
|
||||||
original->y = IntCastRounded(float_result.y());
|
original->y = IntCastRounded(float_result.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DENORM::LocalDenormTransform(const FCOORD &pt, FCOORD *original) const {
|
void DENORM::LocalDenormTransform(const FCOORD &pt, FCOORD *original) const {
|
||||||
FCOORD rotated(pt.x() - final_xshift_, pt.y() - final_yshift_);
|
FCOORD rotated(pt.x() - final_xshift_, pt.y() - final_yshift_);
|
||||||
if (x_map_ != nullptr && y_map_ != nullptr) {
|
if (x_map_ != nullptr && y_map_ != nullptr) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <tesseract/export.h>
|
#include <tesseract/export.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct Pix;
|
struct Pix;
|
||||||
|
|
||||||
|
@ -29,7 +29,11 @@ IndexMap::~IndexMap() = default;
|
|||||||
// Uses a binary search to find the result. For faster speed use
|
// Uses a binary search to find the result. For faster speed use
|
||||||
// IndexMapBiDi, but that takes more memory.
|
// IndexMapBiDi, but that takes more memory.
|
||||||
int IndexMap::SparseToCompact(int sparse_index) const {
|
int IndexMap::SparseToCompact(int sparse_index) const {
|
||||||
int result = compact_map_.binary_search(sparse_index);
|
auto pos = std::upper_bound(compact_map_.begin(), compact_map_.end(), sparse_index);
|
||||||
|
if (pos > compact_map_.begin()) {
|
||||||
|
--pos;
|
||||||
|
}
|
||||||
|
auto result = pos - compact_map_.begin();
|
||||||
return compact_map_[result] == sparse_index ? result : -1;
|
return compact_map_[result] == sparse_index ? result : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +49,7 @@ void IndexMap::CopyFrom(const IndexMapBiDi &src) {
|
|||||||
|
|
||||||
// Writes to the given file. Returns false in case of error.
|
// Writes to the given file. Returns false in case of error.
|
||||||
bool IndexMap::Serialize(FILE *fp) const {
|
bool IndexMap::Serialize(FILE *fp) const {
|
||||||
return tesseract::Serialize(fp, &sparse_size_) && compact_map_.Serialize(fp);
|
return tesseract::Serialize(fp, &sparse_size_) && tesseract::Serialize(fp, compact_map_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads from the given file. Returns false in case of error.
|
// Reads from the given file. Returns false in case of error.
|
||||||
@ -60,7 +64,7 @@ bool IndexMap::DeSerialize(bool swap, FILE *fp) {
|
|||||||
if (sparse_size > UINT16_MAX)
|
if (sparse_size > UINT16_MAX)
|
||||||
return false;
|
return false;
|
||||||
sparse_size_ = sparse_size;
|
sparse_size_ = sparse_size;
|
||||||
return compact_map_.DeSerialize(swap, fp);
|
return tesseract::DeSerialize(swap, fp, compact_map_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor.
|
// Destructor.
|
||||||
@ -85,7 +89,7 @@ void IndexMapBiDi::InitAndSetupRange(int sparse_size, int start, int end) {
|
|||||||
// Call Setup immediately after, or make calls to SetMap first to adjust the
|
// Call Setup immediately after, or make calls to SetMap first to adjust the
|
||||||
// mapping and then call Setup before using the map.
|
// mapping and then call Setup before using the map.
|
||||||
void IndexMapBiDi::Init(int size, bool all_mapped) {
|
void IndexMapBiDi::Init(int size, bool all_mapped) {
|
||||||
sparse_map_.init_to_size(size, -1);
|
sparse_map_.resize(size, -1);
|
||||||
if (all_mapped) {
|
if (all_mapped) {
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
sparse_map_[i] = i;
|
sparse_map_[i] = i;
|
||||||
@ -107,7 +111,7 @@ void IndexMapBiDi::Setup() {
|
|||||||
sparse_map_[i] = compact_size++;
|
sparse_map_[i] = compact_size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compact_map_.init_to_size(compact_size, -1);
|
compact_map_.resize(compact_size, -1);
|
||||||
for (int i = 0; i < sparse_map_.size(); ++i) {
|
for (int i = 0; i < sparse_map_.size(); ++i) {
|
||||||
if (sparse_map_[i] >= 0) {
|
if (sparse_map_[i] >= 0) {
|
||||||
compact_map_[sparse_map_[i]] = i;
|
compact_map_[sparse_map_[i]] = i;
|
||||||
@ -168,7 +172,7 @@ void IndexMapBiDi::CompleteMerges() {
|
|||||||
compact_size = compact_index + 1;
|
compact_size = compact_index + 1;
|
||||||
}
|
}
|
||||||
// Re-generate the compact_map leaving holes for unused indices.
|
// Re-generate the compact_map leaving holes for unused indices.
|
||||||
compact_map_.init_to_size(compact_size, -1);
|
compact_map_.resize(compact_size, -1);
|
||||||
for (int i = 0; i < sparse_map_.size(); ++i) {
|
for (int i = 0; i < sparse_map_.size(); ++i) {
|
||||||
if (sparse_map_[i] >= 0) {
|
if (sparse_map_[i] >= 0) {
|
||||||
if (compact_map_[sparse_map_[i]] == -1)
|
if (compact_map_[sparse_map_[i]] == -1)
|
||||||
@ -177,8 +181,8 @@ void IndexMapBiDi::CompleteMerges() {
|
|||||||
}
|
}
|
||||||
// Compact the compact_map, leaving tmp_compact_map saying where each
|
// Compact the compact_map, leaving tmp_compact_map saying where each
|
||||||
// index went to in the compacted map.
|
// index went to in the compacted map.
|
||||||
GenericVector<int32_t> tmp_compact_map;
|
std::vector<int32_t> tmp_compact_map;
|
||||||
tmp_compact_map.init_to_size(compact_size, -1);
|
tmp_compact_map.resize(compact_size, -1);
|
||||||
compact_size = 0;
|
compact_size = 0;
|
||||||
for (int i = 0; i < compact_map_.size(); ++i) {
|
for (int i = 0; i < compact_map_.size(); ++i) {
|
||||||
if (compact_map_[i] >= 0) {
|
if (compact_map_[i] >= 0) {
|
||||||
@ -186,7 +190,7 @@ void IndexMapBiDi::CompleteMerges() {
|
|||||||
compact_map_[compact_size++] = compact_map_[i];
|
compact_map_[compact_size++] = compact_map_[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compact_map_.truncate(compact_size);
|
compact_map_.resize(compact_size);
|
||||||
// Now modify the entries in the sparse map to point to the new locations.
|
// Now modify the entries in the sparse map to point to the new locations.
|
||||||
for (int i = 0; i < sparse_map_.size(); ++i) {
|
for (int i = 0; i < sparse_map_.size(); ++i) {
|
||||||
if (sparse_map_[i] >= 0) {
|
if (sparse_map_[i] >= 0) {
|
||||||
@ -202,14 +206,14 @@ bool IndexMapBiDi::Serialize(FILE *fp) const {
|
|||||||
// Make a vector containing the rest of the map. If the map is many-to-one
|
// Make a vector containing the rest of the map. If the map is many-to-one
|
||||||
// then each additional sparse entry needs to be stored.
|
// then each additional sparse entry needs to be stored.
|
||||||
// Normally we store only the compact map to save space.
|
// Normally we store only the compact map to save space.
|
||||||
GenericVector<int32_t> remaining_pairs;
|
std::vector<int32_t> remaining_pairs;
|
||||||
for (int i = 0; i < sparse_map_.size(); ++i) {
|
for (int i = 0; i < sparse_map_.size(); ++i) {
|
||||||
if (sparse_map_[i] >= 0 && compact_map_[sparse_map_[i]] != i) {
|
if (sparse_map_[i] >= 0 && compact_map_[sparse_map_[i]] != i) {
|
||||||
remaining_pairs.push_back(i);
|
remaining_pairs.push_back(i);
|
||||||
remaining_pairs.push_back(sparse_map_[i]);
|
remaining_pairs.push_back(sparse_map_[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!remaining_pairs.Serialize(fp))
|
if (!tesseract::Serialize(fp, remaining_pairs))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -219,10 +223,10 @@ bool IndexMapBiDi::Serialize(FILE *fp) const {
|
|||||||
bool IndexMapBiDi::DeSerialize(bool swap, FILE *fp) {
|
bool IndexMapBiDi::DeSerialize(bool swap, FILE *fp) {
|
||||||
if (!IndexMap::DeSerialize(swap, fp))
|
if (!IndexMap::DeSerialize(swap, fp))
|
||||||
return false;
|
return false;
|
||||||
GenericVector<int32_t> remaining_pairs;
|
std::vector<int32_t> remaining_pairs;
|
||||||
if (!remaining_pairs.DeSerialize(swap, fp))
|
if (!tesseract::DeSerialize(swap, fp, remaining_pairs))
|
||||||
return false;
|
return false;
|
||||||
sparse_map_.init_to_size(sparse_size_, -1);
|
sparse_map_.resize(sparse_size_, -1);
|
||||||
for (int i = 0; i < compact_map_.size(); ++i) {
|
for (int i = 0; i < compact_map_.size(); ++i) {
|
||||||
sparse_map_[compact_map_[i]] = i;
|
sparse_map_[compact_map_[i]] = i;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// File: indexmapbidi.h
|
// File: indexmapbidi.h
|
||||||
// Description: Bi-directional mapping between a sparse and compact space.
|
// Description: Bi-directional mapping between a sparse and compact space.
|
||||||
// Author: rays@google.com (Ray Smith)
|
// Author: rays@google.com (Ray Smith)
|
||||||
// Created: Tue Apr 06 11:33:59 PDT 2010
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2010, Google Inc.
|
// (C) Copyright 2010, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -77,7 +76,7 @@ protected:
|
|||||||
int32_t sparse_size_;
|
int32_t sparse_size_;
|
||||||
// The compact space covers integers in the range [0, compact_map_.size()-1].
|
// The compact space covers integers in the range [0, compact_map_.size()-1].
|
||||||
// Each element contains the corresponding sparse index.
|
// Each element contains the corresponding sparse index.
|
||||||
GenericVector<int32_t> compact_map_;
|
std::vector<int32_t> compact_map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bidirectional many-to-one mapping between a sparse and a compact discrete
|
// Bidirectional many-to-one mapping between a sparse and a compact discrete
|
||||||
@ -170,7 +169,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Direct look-up of the compact index for each element in sparse space.
|
// Direct look-up of the compact index for each element in sparse space.
|
||||||
GenericVector<int32_t> sparse_map_;
|
std::vector<int32_t> sparse_map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tesseract.
|
} // namespace tesseract.
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// File: intfeaturemap.cpp
|
// File: intfeaturemap.cpp
|
||||||
// Description: Encapsulation of IntFeatureSpace with IndexMapBiDi
|
// Description: Encapsulation of IntFeatureSpace with IndexMapBiDi
|
||||||
// to provide a subspace mapping and fast feature lookup.
|
// to provide a subspace mapping and fast feature lookup.
|
||||||
// Created: Tue Oct 26 08:58:30 PDT 2010
|
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <allheaders.h>
|
#include <allheaders.h>
|
||||||
#include "boxread.h"
|
#include "boxread.h"
|
||||||
#include "fontinfo.h"
|
#include "fontinfo.h"
|
||||||
|
//#include "helpers.h"
|
||||||
#include "indexmapbidi.h"
|
#include "indexmapbidi.h"
|
||||||
#include "intfeaturedist.h"
|
#include "intfeaturedist.h"
|
||||||
#include "intfeaturemap.h"
|
#include "intfeaturemap.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user