Leptonica  1.73
Image processing and image analysis suite
Functions | Variables
ptabasic.c File Reference
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 ptaExtendArrays (PTA *pta)
 
static l_int32 ptaaExtendArray (PTAA *ptaa)
 
PTAptaCreate (l_int32 n)
 
PTAptaCreateFromNuma (NUMA *nax, NUMA *nay)
 
void ptaDestroy (PTA **ppta)
 
PTAptaCopy (PTA *pta)
 
PTAptaCopyRange (PTA *ptas, l_int32 istart, l_int32 iend)
 
PTAptaClone (PTA *pta)
 
l_int32 ptaEmpty (PTA *pta)
 
l_int32 ptaAddPt (PTA *pta, l_float32 x, l_float32 y)
 
l_int32 ptaInsertPt (PTA *pta, l_int32 index, l_int32 x, l_int32 y)
 
l_int32 ptaRemovePt (PTA *pta, l_int32 index)
 
l_int32 ptaGetRefcount (PTA *pta)
 
l_int32 ptaChangeRefcount (PTA *pta, l_int32 delta)
 
l_int32 ptaGetCount (PTA *pta)
 
l_int32 ptaGetPt (PTA *pta, l_int32 index, l_float32 *px, l_float32 *py)
 
l_int32 ptaGetIPt (PTA *pta, l_int32 index, l_int32 *px, l_int32 *py)
 
l_int32 ptaSetPt (PTA *pta, l_int32 index, l_float32 x, l_float32 y)
 
l_int32 ptaGetArrays (PTA *pta, NUMA **pnax, NUMA **pnay)
 
PTAptaRead (const char *filename)
 
PTAptaReadStream (FILE *fp)
 
PTAptaReadMem (const l_uint8 *data, size_t size)
 
l_int32 ptaWrite (const char *filename, PTA *pta, l_int32 type)
 
l_int32 ptaWriteStream (FILE *fp, PTA *pta, l_int32 type)
 
l_int32 ptaWriteMem (l_uint8 **pdata, size_t *psize, PTA *pta, l_int32 type)
 
PTAAptaaCreate (l_int32 n)
 
void ptaaDestroy (PTAA **pptaa)
 
l_int32 ptaaAddPta (PTAA *ptaa, PTA *pta, l_int32 copyflag)
 
l_int32 ptaaGetCount (PTAA *ptaa)
 
PTAptaaGetPta (PTAA *ptaa, l_int32 index, l_int32 accessflag)
 
l_int32 ptaaGetPt (PTAA *ptaa, l_int32 ipta, l_int32 jpt, l_float32 *px, l_float32 *py)
 
l_int32 ptaaInitFull (PTAA *ptaa, PTA *pta)
 
l_int32 ptaaReplacePta (PTAA *ptaa, l_int32 index, PTA *pta)
 
l_int32 ptaaAddPt (PTAA *ptaa, l_int32 ipta, l_float32 x, l_float32 y)
 
l_int32 ptaaTruncate (PTAA *ptaa)
 
PTAAptaaRead (const char *filename)
 
PTAAptaaReadStream (FILE *fp)
 
PTAAptaaReadMem (const l_uint8 *data, size_t size)
 
l_int32 ptaaWrite (const char *filename, PTAA *ptaa, l_int32 type)
 
l_int32 ptaaWriteStream (FILE *fp, PTAA *ptaa, l_int32 type)
 
l_int32 ptaaWriteMem (l_uint8 **pdata, size_t *psize, PTAA *ptaa, l_int32 type)
 

Variables

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20
 

Detailed Description

 Pta creation, destruction, copy, clone, empty
      PTA            *ptaCreate()
      PTA            *ptaCreateFromNuma()
      void            ptaDestroy()
      PTA            *ptaCopy()
      PTA            *ptaCopyRange()
      PTA            *ptaClone()
      l_int32         ptaEmpty()

 Pta array extension
      l_int32         ptaAddPt()
      static l_int32  ptaExtendArrays()

 Pta insertion and removal
      l_int32         ptaInsertPt()
      l_int32         ptaRemovePt()

 Pta accessors
      l_int32         ptaGetRefcount()
      l_int32         ptaChangeRefcount()
      l_int32         ptaGetCount()
      l_int32         ptaGetPt()
      l_int32         ptaGetIPt()
      l_int32         ptaSetPt()
      l_int32         ptaGetArrays()

 Pta serialized for I/O
      PTA            *ptaRead()
      PTA            *ptaReadStream()
      PTA            *ptaReadMem()
      l_int32         ptaWrite()
      l_int32         ptaWriteStream()
      l_int32         ptaWriteMem()

 Ptaa creation, destruction
      PTAA           *ptaaCreate()
      void            ptaaDestroy()

 Ptaa array extension
      l_int32         ptaaAddPta()
      static l_int32  ptaaExtendArray()

 Ptaa accessors
      l_int32         ptaaGetCount()
      l_int32         ptaaGetPta()
      l_int32         ptaaGetPt()

 Ptaa array modifiers
      l_int32         ptaaInitFull()
      l_int32         ptaaReplacePta()
      l_int32         ptaaAddPt()
      l_int32         ptaaTruncate()

 Ptaa serialized for I/O
      PTAA           *ptaaRead()
      PTAA           *ptaaReadStream()
      PTAA           *ptaaReadMem()
      l_int32         ptaaWrite()
      l_int32         ptaaWriteStream()
      l_int32         ptaaWriteMem()

Definition in file ptabasic.c.

Function Documentation

◆ ptaaAddPt()

l_int32 ptaaAddPt ( PTAA ptaa,
l_int32  ipta,
l_float32  x,
l_float32  y 
)

ptaaAddPt()

Parameters
[in]ptaa
[in]iptato the i-th pta
[in]x,ypoint coordinates
Returns
0 if OK; 1 on error

Definition at line 1201 of file ptabasic.c.

References L_CLONE, Ptaa::n, ptaAddPt(), ptaaGetPta(), and ptaDestroy().

Referenced by recogTrainingFinished().

◆ ptaaAddPta()

l_int32 ptaaAddPta ( PTAA ptaa,
PTA pta,
l_int32  copyflag 
)

ptaaAddPta()

Parameters
[in]ptaa
[in]ptato be added
[in]copyflagL_INSERT, L_COPY, L_CLONE
Returns
0 if OK, 1 on error

Definition at line 970 of file ptabasic.c.

References L_CLONE, L_COPY, L_INSERT, Ptaa::n, Ptaa::nalloc, Ptaa::pta, ptaaExtendArray(), ptaaGetCount(), ptaClone(), and ptaCopy().

Referenced by ccbaGenerateGlobalLocs(), dewarpFindVertDisparity(), generatePtaaBoxa(), generatePtaaHashBoxa(), pixGetHoleBorder(), pixGetOuterBorder(), ptaaJoin(), ptaaReadStream(), and ptaaSortByIndex().

◆ ptaaCreate()

PTAA* ptaaCreate ( l_int32  n)

ptaaCreate()

Parameters
[in]ninitial number of ptrs
Returns
ptaa, or NULL on error

Definition at line 905 of file ptabasic.c.

Referenced by ccbaGenerateGlobalLocs(), dewarpFindVertDisparity(), generatePtaaBoxa(), generatePtaaHashBoxa(), ptaaReadStream(), ptaaSortByIndex(), and recogTrainingFinished().

◆ ptaAddPt()

l_int32 ptaAddPt ( PTA pta,
l_float32  x,
l_float32  y 
)

◆ ptaaDestroy()

void ptaaDestroy ( PTAA **  pptaa)

ptaaDestroy()

Parameters
[in,out]pptaato be nulled
Returns
void

Definition at line 933 of file ptabasic.c.

References Ptaa::n, Ptaa::pta, and ptaDestroy().

Referenced by ccbaGenerateGlobalLocs(), ccbDestroy(), ptaaReadStream(), recogDestroy(), and recogTrainingFinished().

◆ ptaaExtendArray()

static l_int32 ptaaExtendArray ( PTAA ptaa)
static

ptaaExtendArray()

Parameters
[in]ptaa
Returns
0 if OK, 1 on error

Definition at line 1013 of file ptabasic.c.

References Ptaa::nalloc, Ptaa::pta, and reallocNew().

Referenced by ptaaAddPta().

◆ ptaaGetCount()

l_int32 ptaaGetCount ( PTAA ptaa)

◆ ptaaGetPt()

l_int32 ptaaGetPt ( PTAA ptaa,
l_int32  ipta,
l_int32  jpt,
l_float32 *  px,
l_float32 *  py 
)

ptaaGetPt()

Parameters
[in]ptaa
[in]iptato the i-th pta
[in]jptindex to the j-th pt in the pta
[out]px[optional] float x value
[out]py[optional] float y value
Returns
0 if OK; 1 on error

Definition at line 1091 of file ptabasic.c.

References L_CLONE, Pta::n, Ptaa::n, ptaaGetPta(), ptaDestroy(), and ptaGetPt().

Referenced by dewarpIsLineCoverageValid().

◆ ptaaGetPta()

PTA* ptaaGetPta ( PTAA ptaa,
l_int32  index,
l_int32  accessflag 
)

◆ ptaaInitFull()

l_int32 ptaaInitFull ( PTAA ptaa,
PTA pta 
)

ptaaInitFull()

Parameters
[in]ptaacan have non-null ptrs in the ptr array
[in]ptato be replicated into the entire ptr array
Returns
0 if OK; 1 on error

Definition at line 1131 of file ptabasic.c.

References Ptaa::n, Ptaa::nalloc, ptaaReplacePta(), and ptaCopy().

Referenced by recogTrainingFinished().

◆ ptaaRead()

PTAA* ptaaRead ( const char *  filename)

ptaaRead()

Parameters
[in]filename
Returns
ptaa, or NULL on error

Definition at line 1276 of file ptabasic.c.

References fopenReadStream(), and ptaaReadStream().

◆ ptaaReadMem()

PTAA* ptaaReadMem ( const l_uint8 *  data,
size_t  size 
)

ptaaReadMem()

Parameters
[in]dataserialization in ascii
[in]sizeof data in bytes; can use strlen to get it
Returns
ptaa, or NULL on error

Definition at line 1343 of file ptabasic.c.

References fopenReadFromMemory(), and ptaaReadStream().

◆ ptaaReadStream()

PTAA* ptaaReadStream ( FILE *  fp)

ptaaReadStream()

Parameters
[in]fpfile stream
Returns
ptaa, or NULL on error

Definition at line 1303 of file ptabasic.c.

References L_INSERT, PTA_VERSION_NUMBER, ptaaAddPta(), ptaaCreate(), ptaaDestroy(), and ptaReadStream().

Referenced by ptaaRead(), and ptaaReadMem().

◆ ptaaReplacePta()

l_int32 ptaaReplacePta ( PTAA ptaa,
l_int32  index,
PTA pta 
)

ptaaReplacePta()

Parameters
[in]ptaa
[in]indexto the index-th pta
[in]ptainsert and replace any existing one
Returns
0 if OK, 1 on error
Notes:
     (1) Any existing pta is destroyed, and the input one
         is inserted in its place.
     (2) If the index is invalid, return 1 (error)

Definition at line 1170 of file ptabasic.c.

References Ptaa::pta, ptaaGetCount(), and ptaDestroy().

Referenced by ptaaInitFull().

◆ ptaaTruncate()

l_int32 ptaaTruncate ( PTAA ptaa)

ptaaTruncate()

Parameters
[in]ptaa
Returns
0 if OK, 1 on error
Notes:
     (1) This identifies the largest index containing a pta that
         has any points within it, destroys all pta above that index,
         and resets the count.

Definition at line 1236 of file ptabasic.c.

References L_CLONE, Ptaa::n, Ptaa::pta, ptaaGetCount(), ptaaGetPta(), ptaDestroy(), and ptaGetCount().

Referenced by recogTrainingFinished().

◆ ptaaWrite()

l_int32 ptaaWrite ( const char *  filename,
PTAA ptaa,
l_int32  type 
)

ptaaWrite()

Parameters
[in]filename
[in]ptaa
[in]type0 for float values; 1 for integer values
Returns
0 if OK, 1 on error

Definition at line 1372 of file ptabasic.c.

References fopenWriteStream(), and ptaaWriteStream().

◆ ptaaWriteMem()

l_int32 ptaaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PTAA ptaa,
l_int32  type 
)

ptaaWriteMem()

Parameters
[out]pdatadata of serialized ptaa; ascii
[out]psizesize of returned data
[in]ptaa
[in]type0 for float values; 1 for integer values
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a ptaa in memory and puts the result in a buffer.

Definition at line 1447 of file ptabasic.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), and ptaaWriteStream().

◆ ptaaWriteStream()

l_int32 ptaaWriteStream ( FILE *  fp,
PTAA ptaa,
l_int32  type 
)

ptaaWriteStream()

Parameters
[in]fpfile stream
[in]ptaa
[in]type0 for float values; 1 for integer values
Returns
0 if OK; 1 on error

Definition at line 1405 of file ptabasic.c.

References L_CLONE, PTA_VERSION_NUMBER, ptaaGetCount(), ptaaGetPta(), ptaDestroy(), and ptaWriteStream().

Referenced by ptaaWrite(), and ptaaWriteMem().

◆ ptaClone()

PTA* ptaClone ( PTA pta)

◆ ptaCopy()

PTA* ptaCopy ( PTA pta)

ptaCopy()

Parameters
[in]pta
Returns
copy of pta, or NULL on error

Definition at line 224 of file ptabasic.c.

References Pta::n, Pta::nalloc, ptaAddPt(), ptaCreate(), and ptaGetPt().

Referenced by ptaaAddPta(), ptaaGetPta(), ptaaInitFull(), ptaSelectByValue(), ptaSelectRange(), ptaUnionByAset(), and ptaUnionByHash().

◆ ptaCopyRange()

PTA* ptaCopyRange ( PTA ptas,
l_int32  istart,
l_int32  iend 
)

ptaCopyRange()

Parameters
[in]ptas
[in]istartstarting index in ptas
[in]iendending index in ptas; use 0 to copy to end
Returns
0 if OK, 1 on error

Definition at line 256 of file ptabasic.c.

References ptaAddPt(), ptaCreate(), ptaGetCount(), and ptaGetIPt().

◆ ptaCreate()

PTA* ptaCreate ( l_int32  n)

◆ ptaCreateFromNuma()

PTA* ptaCreateFromNuma ( NUMA nax,
NUMA nay 
)

ptaCreateFromNuma()

Parameters
[in]nax[optional] can be null
[in]nay
Returns
pta, or NULL on error.

Definition at line 148 of file ptabasic.c.

References numaGetCount(), numaGetFValue(), numaGetParameters(), ptaAddPt(), and ptaCreate().

Referenced by dewarpFindVertDisparity().

◆ ptaDestroy()

void ptaDestroy ( PTA **  ppta)

ptaDestroy()

Parameters
[in,out]pptato be nulled
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the pta.
     (2) Always nulls the input ptr.

Definition at line 191 of file ptabasic.c.

Referenced by boxaAffineTransform(), boxaConvertToPta(), boxaLinearFit(), boxaRotate(), boxaScale(), boxaTranslate(), boxIntersectByLine(), ccbaDisplayBorder(), ccbaDisplayImage1(), ccbaDisplayImage2(), ccbaGenerateGlobalLocs(), ccbaGenerateSinglePath(), ccbaGenerateSPGlobalLocs(), ccbaGenerateStepChains(), ccbDestroy(), dewarpFindVertDisparity(), fpixAffinePta(), fpixProjectivePta(), generatePtaBox(), generatePtaBoxa(), generatePtaHashBox(), generatePtaHashBoxa(), generatePtaPolyline(), generatePtaWideLine(), makePlotPtaFromNumaGen(), pixDisplayPtaa(), pixRenderBox(), pixRenderBoxa(), pixRenderBoxaArb(), pixRenderBoxaBlend(), pixRenderBoxArb(), pixRenderBoxBlend(), pixRenderGridArb(), pixRenderHashBox(), pixRenderHashBoxa(), pixRenderHashBoxaArb(), pixRenderHashBoxaBlend(), pixRenderHashBoxArb(), pixRenderHashBoxBlend(), pixRenderHorizEndPoints(), pixRenderLine(), pixRenderLineArb(), pixRenderLineBlend(), pixRenderPolygon(), pixRenderPolyline(), pixRenderPolylineArb(), pixRenderPolylineBlend(), pixRenderRandomCmapPtaa(), ptaaAddPt(), ptaaDestroy(), ptaaGetPt(), ptaaReplacePta(), ptaaTruncate(), ptaaWriteStream(), ptaGetRankValue(), ptaNoisyLinearLSF(), ptaNoisyQuadraticLSF(), ptaReadStream(), ptaReplicatePattern(), ptaUnionByAset(), ptaUnionByHash(), recogAverageSamples(), recogDestroy(), recogTrainingFinished(), selaAddCrossJunctions(), selaAddTJunctions(), and wshedDestroy().

◆ ptaEmpty()

l_int32 ptaEmpty ( PTA pta)

ptaEmpty()

Parameters
[in]pta
Returns
0 if OK, 1 on error
Notes:
     This only resets the Pta::n field, for reuse

Definition at line 319 of file ptabasic.c.

References Pta::n.

◆ ptaExtendArrays()

static l_int32 ptaExtendArrays ( PTA pta)
static

ptaExtendArrays()

Parameters
[in]pta
Returns
0 if OK; 1 on error

Definition at line 370 of file ptabasic.c.

References Pta::nalloc, reallocNew(), and Pta::y.

Referenced by ptaAddPt(), and ptaInsertPt().

◆ ptaGetArrays()

l_int32 ptaGetArrays ( PTA pta,
NUMA **  pnax,
NUMA **  pnay 
)

ptaGetArrays()

Parameters
[in]pta
[out]pnax[optional] numa of x array
[out]pnay[optional] numa of y array
Returns
0 if OK; 1 on error or if pta is empty
Notes:
     (1) This copies the internal arrays into new Numas.

Definition at line 615 of file ptabasic.c.

References Numa::array, Numa::n, numaCreate(), ptaGetCount(), and Pta::y.

Referenced by dewarpFindVertDisparity().

◆ ptaGetCount()

l_int32 ptaGetCount ( PTA pta)

◆ ptaGetIPt()

l_int32 ptaGetIPt ( PTA pta,
l_int32  index,
l_int32 *  px,
l_int32 *  py 
)

◆ ptaGetPt()

l_int32 ptaGetPt ( PTA pta,
l_int32  index,
l_float32 *  px,
l_float32 *  py 
)

◆ ptaInsertPt()

l_int32 ptaInsertPt ( PTA pta,
l_int32  index,
l_int32  x,
l_int32  y 
)

ptaInsertPt()

Parameters
[in]pta
[in]indexat which pt is to be inserted
[in]x,ypoint values
Returns
0 if OK; 1 on error

Definition at line 403 of file ptabasic.c.

References Pta::n, Pta::nalloc, ptaExtendArrays(), ptaGetCount(), and Pta::y.

◆ ptaRead()

PTA* ptaRead ( const char *  filename)

ptaRead()

Parameters
[in]filename
Returns
pta, or NULL on error

Definition at line 663 of file ptabasic.c.

References fopenReadStream(), and ptaReadStream().

◆ ptaReadMem()

PTA* ptaReadMem ( const l_uint8 *  data,
size_t  size 
)

ptaReadMem()

Parameters
[in]dataserialization in ascii
[in]sizeof data in bytes; can use strlen to get it
Returns
pta, or NULL on error

Definition at line 743 of file ptabasic.c.

References fopenReadFromMemory(), and ptaReadStream().

◆ ptaReadStream()

PTA* ptaReadStream ( FILE *  fp)

ptaReadStream()

Parameters
[in]fpfile stream
Returns
pta, or NULL on error

Definition at line 690 of file ptabasic.c.

References PTA_VERSION_NUMBER, ptaAddPt(), ptaCreate(), and ptaDestroy().

Referenced by ptaaReadStream(), ptaRead(), and ptaReadMem().

◆ ptaRemovePt()

l_int32 ptaRemovePt ( PTA pta,
l_int32  index 
)

ptaRemovePt()

Parameters
[in]pta
[in]indexof point to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts pta[i] –> pta[i - 1] for all i > index.
     (2) It should not be used repeatedly on large arrays,
         because the function is O(n).

Definition at line 446 of file ptabasic.c.

References Pta::n, ptaGetCount(), and Pta::y.

◆ ptaSetPt()

l_int32 ptaSetPt ( PTA pta,
l_int32  index,
l_float32  x,
l_float32  y 
)

ptaSetPt()

Parameters
[in]pta
[in]indexinto arrays
[in]x,y
Returns
0 if OK; 1 on error

Definition at line 583 of file ptabasic.c.

References Pta::n, and Pta::y.

◆ ptaWrite()

l_int32 ptaWrite ( const char *  filename,
PTA pta,
l_int32  type 
)

ptaWrite()

Parameters
[in]filename
[in]pta
[in]type0 for float values; 1 for integer values
Returns
0 if OK, 1 on error

Definition at line 772 of file ptabasic.c.

References fopenWriteStream(), and ptaWriteStream().

Referenced by boxaLinearFit().

◆ ptaWriteMem()

l_int32 ptaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PTA pta,
l_int32  type 
)

ptaWriteMem()

Parameters
[out]pdatadata of serialized pta; ascii
[out]psizesize of returned data
[in]pta
[in]type0 for float values; 1 for integer values
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a pta in memory and puts the result in a buffer.

Definition at line 854 of file ptabasic.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), and ptaWriteStream().

◆ ptaWriteStream()

l_int32 ptaWriteStream ( FILE *  fp,
PTA pta,
l_int32  type 
)

ptaWriteStream()

Parameters
[in]fpfile stream
[in]pta
[in]type0 for float values; 1 for integer values
Returns
0 if OK; 1 on error

Definition at line 805 of file ptabasic.c.

References PTA_VERSION_NUMBER, ptaGetCount(), ptaGetIPt(), and ptaGetPt().

Referenced by ptaaWriteStream(), ptaWrite(), and ptaWriteMem().