Merge pull request #2677 from stweil/vecfuncs

Remove vecfuncs.cpp and vecfunc.h
This commit is contained in:
Egor Pugin 2019-09-25 23:33:01 +03:00 committed by GitHub
commit ac0190bfaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 167 deletions

View File

@ -32,7 +32,6 @@ noinst_HEADERS = \
if !DISABLED_LEGACY_ENGINE
noinst_HEADERS += fontinfo.h
noinst_HEADERS += params_training_featdef.h
noinst_HEADERS += vecfuncs.h
endif
noinst_LTLIBRARIES = libtesseract_ccstruct.la
@ -51,5 +50,4 @@ libtesseract_ccstruct_la_SOURCES = \
if !DISABLED_LEGACY_ENGINE
libtesseract_ccstruct_la_SOURCES += fontinfo.cpp
libtesseract_ccstruct_la_SOURCES += params_training_featdef.cpp
libtesseract_ccstruct_la_SOURCES += vecfuncs.cpp
endif

View File

@ -65,9 +65,6 @@ CLISTIZE(EDGEPT)
/* static */
bool TPOINT::IsCrossed(const TPOINT& a0, const TPOINT& a1, const TPOINT& b0,
const TPOINT& b1) {
int b0a1xb0b1, b0b1xb0a0;
int a1b1xa1a0, a1a0xa1b0;
TPOINT b0a1, b0a0, a1b1, b0b1, a1a0;
b0a1.x = a1.x - b0.x;
@ -81,12 +78,12 @@ bool TPOINT::IsCrossed(const TPOINT& a0, const TPOINT& a1, const TPOINT& b0,
b0b1.y = b1.y - b0.y;
a1a0.y = a0.y - a1.y;
b0a1xb0b1 = CROSS(b0a1, b0b1);
b0b1xb0a0 = CROSS(b0b1, b0a0);
a1b1xa1a0 = CROSS(a1b1, a1a0);
// For clarity, we want CROSS(a1a0,a1b0) here but we have b0a1 instead of a1b0
// so use -CROSS(a1b0,b0a1) instead, which is the same.
a1a0xa1b0 = -CROSS(a1a0, b0a1);
int b0a1xb0b1 = b0a1.cross(b0b1);
int b0b1xb0a0 = b0b1.cross(b0a0);
int a1b1xa1a0 = a1b1.cross(a1a0);
// For clarity, we want a1a0.cross(a1b0) here but we have b0a1 instead of a1b0
// so use -a1b0.cross(b0a1) instead, which is the same.
int a1a0xa1b0 = -a1a0.cross(b0a1);
return ((b0a1xb0b1 > 0 && b0b1xb0a0 > 0) ||
(b0a1xb0b1 < 0 && b0b1xb0a0 < 0)) &&
@ -250,7 +247,7 @@ void TESSLINE::MinMaxCrossProduct(const TPOINT vec, int* min_xp,
EDGEPT* this_edge = loop;
do {
if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
int product = CROSS(this_edge->pos, vec);
int product = this_edge->pos.cross(vec);
UpdateRange(product, min_xp, max_xp);
}
this_edge = this_edge->next;
@ -925,7 +922,7 @@ bool divisible_blob(TBLOB* blob, bool italic_blob, TPOINT* location) {
TPOINT mid_pt1(
static_cast<int16_t>((outline1->topleft.x + outline1->botright.x) / 2),
static_cast<int16_t>((outline1->topleft.y + outline1->botright.y) / 2));
int mid_prod1 = CROSS(mid_pt1, vertical);
int mid_prod1 = mid_pt1.cross(vertical);
int min_prod1, max_prod1;
outline1->MinMaxCrossProduct(vertical, &min_prod1, &max_prod1);
for (TESSLINE* outline2 = outline1->next; outline2 != nullptr;
@ -935,7 +932,7 @@ bool divisible_blob(TBLOB* blob, bool italic_blob, TPOINT* location) {
(outline2->topleft.x + outline2->botright.x) / 2),
static_cast<int16_t>(
(outline2->topleft.y + outline2->botright.y) / 2));
int mid_prod2 = CROSS(mid_pt2, vertical);
int mid_prod2 = mid_pt2.cross(vertical);
int min_prod2, max_prod2;
outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
int mid_gap = abs(mid_prod2 - mid_prod1);
@ -971,13 +968,13 @@ void divide_blobs(TBLOB* blob, TBLOB* other_blob, bool italic_blob,
TESSLINE* outline = blob->outlines;
blob->outlines = nullptr;
int location_prod = CROSS(location, vertical);
int location_prod = location.cross(vertical);
while (outline != nullptr) {
TPOINT mid_pt(
static_cast<int16_t>((outline->topleft.x + outline->botright.x) / 2),
static_cast<int16_t>((outline->topleft.y + outline->botright.y) / 2));
int mid_prod = CROSS(mid_pt, vertical);
int mid_prod = mid_pt.cross(vertical);
if (mid_prod < location_prod) {
// Outline is in left blob.
if (outline1)

View File

@ -33,7 +33,6 @@
#include "publictypes.h" // for OcrEngineMode
#include "rect.h" // for TBOX
#include "scrollview.h" // for ScrollView, ScrollView::Color
#include "vecfuncs.h" // for CROSS
class BLOCK;
class C_BLOB;
@ -70,9 +69,31 @@ struct TPOINT {
static bool IsCrossed(const TPOINT& a0, const TPOINT& a1, const TPOINT& b0,
const TPOINT& b1);
// Assign the difference from point p1 to point p2.
void diff(const TPOINT& p1, const TPOINT& p2) {
x = p1.x - p2.x;
y = p1.y - p2.y;
}
// Return cross product.
int cross(const TPOINT& other) const {
return x * other.y - y * other.x;
}
// Return scalar or dot product.
int dot(const TPOINT& other) const {
return x * other.x + y * other.y;
}
// Calculate length of vector.
int length() const {
return x * x + y * y;
}
int16_t x; // absolute x coord.
int16_t y; // absolute y coord.
};
using VECTOR = TPOINT; // structure for coordinates.
struct EDGEPT {
@ -126,7 +147,7 @@ struct EDGEPT {
const EDGEPT* pt = this->next;
do {
TPOINT origin_vec(pt->pos.x - pos.x, pt->pos.y - pos.y);
area += CROSS(origin_vec, pt->vec);
area += origin_vec.cross(pt->vec);
pt = pt->next;
} while (pt != end && pt != this);
return area;

View File

@ -26,7 +26,6 @@
#include "points.h" // for ICOORD
#include "rect.h" // for TBOX
#include "tprintf.h" // for tprintf
#include "vecfuncs.h" // for LENGTH, point_diff, CROSS
#define FASTEDGELENGTH 256
@ -351,18 +350,18 @@ void fix2( //polygonal approx
do {
if (fixed_count <= 3)
break; //already too few
point_diff (d12vec, edgefix1->pos, edgefix2->pos);
d12 = LENGTH (d12vec);
d12vec.diff(edgefix1->pos, edgefix2->pos);
d12 = d12vec.length();
// TODO(rays) investigate this change:
// Only unfix a point if it is part of a low-curvature section
// of outline and the total angle change of the outlines is
// less than 90 degrees, ie the scalar product is positive.
// if (d12 <= gapmin && SCALAR(edgefix0->vec, edgefix2->vec) > 0) {
// if (d12 <= gapmin && edgefix0->vec.dot(edgefix2->vec) > 0) {
if (d12 <= gapmin) {
point_diff (d01vec, edgefix0->pos, edgefix1->pos);
d01 = LENGTH (d01vec);
point_diff (d23vec, edgefix2->pos, edgefix3->pos);
d23 = LENGTH (d23vec);
d01vec.diff(edgefix0->pos, edgefix1->pos);
d01 = d01vec.length();
d23vec.diff(edgefix2->pos, edgefix3->pos);
d23 = d23vec.length();
if (d01 > d23) {
edgefix2->flags[FLAGS] &= ~FIXED;
fixed_count--;
@ -537,7 +536,7 @@ void cutline( //recursive refine
edge = edge->next; /*move to actual point */
maxpoint = edge; /*in case there isn't one */
do {
perp = CROSS (vec, vecsum); /*get perp distance */
perp = vec.cross(vecsum); // get perp distance
if (perp != 0) {
perp *= perp; /*squared deviation */
}
@ -555,7 +554,7 @@ void cutline( //recursive refine
}
while (edge != last); /*test all line */
perp = LENGTH (vecsum);
perp = vecsum.length();
ASSERT_HOST (perp != 0);
if (maxperp < 256 * INT16_MAX) {

View File

@ -1,58 +0,0 @@
/* -*-C-*-
********************************************************************************
*
* File: vecfuncs.cpp (Formerly vecfuncs.c)
* Description: Blob definition
* Author: Mark Seaman, OCR Technology
*
* (c) Copyright 1989, Hewlett-Packard Company.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*
********************************************************************************
* Revision 5.1 89/07/27 11:47:50 11:47:50 ray ()
* Added ratings access methods.
* This version ready for independent development.
*/
/*----------------------------------------------------------------------
I n c l u d e s
----------------------------------------------------------------------*/
#include "vecfuncs.h"
#include "blobs.h"
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
/**********************************************************************
* direction
*
* Show if the line is going in the positive or negative X direction.
**********************************************************************/
int direction(EDGEPT *point) {
int dir; /** direction to return **/
EDGEPT *prev; /** prev point **/
EDGEPT *next; /** next point **/
dir = 0;
prev = point->prev;
next = point->next;
if (((prev->pos.x <= point->pos.x) &&
(point->pos.x < next->pos.x)) ||
((prev->pos.x < point->pos.x) && (point->pos.x <= next->pos.x)))
dir = 1;
if (((prev->pos.x >= point->pos.x) &&
(point->pos.x > next->pos.x)) ||
((prev->pos.x > point->pos.x) && (point->pos.x >= next->pos.x)))
dir = -1;
return dir;
}

View File

@ -1,73 +0,0 @@
/* -*-C-*-
********************************************************************************
*
* File: vecfuncs.h
* Description: Vector calculations
* Author: Mark Seaman, OCR Technology
*
* (c) Copyright 1989, Hewlett-Packard Company.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*
*********************************************************************************/
#ifndef VECFUNCS_H
#define VECFUNCS_H
#include <cmath>
struct EDGEPT;
/*----------------------------------------------------------------------
M a c r o s
----------------------------------------------------------------------*/
/**********************************************************************
* point_diff
*
* Return the difference from point (p1) to point (p2). Put the value
* into point (p).
**********************************************************************/
#define point_diff(p,p1,p2) \
((p).x = (p1).x - (p2).x, \
(p).y = (p1).y - (p2).y)
/**********************************************************************
* CROSS
*
* cross product
**********************************************************************/
#define CROSS(a,b) \
((a).x * (b).y - (a).y * (b).x)
/**********************************************************************
* SCALAR
*
* scalar vector product
**********************************************************************/
#define SCALAR(a,b) \
((a).x * (b).x + (a).y * (b).y)
/**********************************************************************
* LENGTH
*
* length of vector
**********************************************************************/
#define LENGTH(a) \
((a).x * (a).x + (a).y * (a).y)
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
int direction(EDGEPT *point);
#endif

View File

@ -35,9 +35,28 @@
#endif
namespace tesseract {
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
// Show if the line is going in the positive or negative X direction.
static int direction(const EDGEPT* point) {
//* direction to return
int dir = 0;
//* prev point
const EDGEPT* prev = point->prev;
//* next point
const EDGEPT* next = point->next;
if (((prev->pos.x <= point->pos.x) && (point->pos.x < next->pos.x)) ||
((prev->pos.x < point->pos.x) && (point->pos.x <= next->pos.x))) {
dir = 1;
}
if (((prev->pos.x >= point->pos.x) && (point->pos.x > next->pos.x)) ||
((prev->pos.x > point->pos.x) && (point->pos.x >= next->pos.x))) {
dir = -1;
}
return dir;
}
/**
* @name point_priority
*
@ -90,14 +109,14 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) {
vector2.x = point3->pos.x - point2->pos.x;
vector2.y = point3->pos.y - point2->pos.y;
/* Use cross product */
float length = std::sqrt(static_cast<float>(LENGTH(vector1)) * LENGTH(vector2));
float length = std::sqrt(static_cast<float>(vector1.length()) * vector2.length());
if (static_cast<int>(length) == 0)
return (0);
angle = static_cast<int>(floor(asin(CROSS (vector1, vector2) /
angle = static_cast<int>(floor(asin(vector1.cross(vector2) /
length) / M_PI * 180.0 + 0.5));
/* Use dot product */
if (SCALAR (vector1, vector2) < 0)
if (vector1.dot(vector2) < 0)
angle = 180 - angle;
/* Adjust angle */
if (angle > 180)

View File

@ -22,8 +22,6 @@
#include <cmath>
#include "vecfuncs.h"
// Include automatically generated configuration file if running autoconf.
#ifdef HAVE_CONFIG_H
#include "config_auto.h"