Home | History | Annotate | Download | only in b_TensorEm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef bts_CLUSTER2D_EM_H
     18 #define bts_CLUSTER2D_EM_H
     19 
     20 /* ---- includes ----------------------------------------------------------- */
     21 
     22 #include "b_BasicEm/Context.h"
     23 #include "b_BasicEm/MemSeg.h"
     24 #include "b_TensorEm/Int16Vec2D.h"
     25 #include "b_TensorEm/Flt16Vec2D.h"
     26 #include "b_TensorEm/Int16Rect.h"
     27 #include "b_TensorEm/Flt16Alt2D.h"
     28 #include "b_TensorEm/Functions.h"
     29 
     30 /* ---- related objects  --------------------------------------------------- */
     31 
     32 struct bts_RBFMap2D;
     33 
     34 /* ---- typedefs ----------------------------------------------------------- */
     35 
     36 /* data format version number */
     37 #define bts_CLUSTER2D_VERSION 100
     38 
     39 /* ---- constants ---------------------------------------------------------- */
     40 
     41 /* ---- object definition -------------------------------------------------- */
     42 
     43 /** 2d vector array */
     44 struct bts_Cluster2D
     45 {
     46 
     47 	/* ---- private data --------------------------------------------------- */
     48 
     49 	/* ---- public data ---------------------------------------------------- */
     50 
     51 	/** pointer to exclusive memory segment used for allocation */
     52 	struct bbs_MemSeg* mspE;
     53 
     54 	/** number of allocated vectors */
     55 	uint32 allocatedSizeE;
     56 
     57 	/** number of vectors */
     58 	uint32 sizeE;
     59 
     60 	/** format of vectors (bbpE always > 0) */
     61 	int32 bbpE;
     62 
     63 	/** array of int16 vectors */
     64 	struct bts_Int16Vec2D* vecArrE;
     65 
     66 };
     67 
     68 /* ---- associated objects ------------------------------------------------- */
     69 
     70 /* ---- external functions ------------------------------------------------- */
     71 
     72 /* ---- \ghd{ constructor/destructor } ------------------------------------- */
     73 
     74 /** initializes cluster */
     75 void bts_Cluster2D_init( struct bbs_Context* cpA,
     76 						 struct bts_Cluster2D* ptrA );
     77 
     78 /** destroys cluster */
     79 void bts_Cluster2D_exit( struct bbs_Context* cpA,
     80 						 struct bts_Cluster2D* ptrA );
     81 
     82 /* ---- \ghd{ operators } -------------------------------------------------- */
     83 
     84 /** copies cluster */
     85 void bts_Cluster2D_copy( struct bbs_Context* cpA,
     86 						 struct bts_Cluster2D* ptrA,
     87 						 const struct bts_Cluster2D* srcPtrA );
     88 
     89 /** compares cluster */
     90 flag bts_Cluster2D_equal( struct bbs_Context* cpA,
     91 						  const struct bts_Cluster2D* ptrA,
     92 						  const struct bts_Cluster2D* srcPtrA );
     93 
     94 /* ---- \ghd{ query functions } -------------------------------------------- */
     95 
     96 /** returns center of gravity */
     97 struct bts_Flt16Vec2D bts_Cluster2D_center( struct bbs_Context* cpA,
     98 										    const struct bts_Cluster2D* ptrA );
     99 
    100 /** returns check sum (for debugging purpose) */
    101 uint32 bts_Cluster2D_checkSum( struct bbs_Context* cpA,
    102 							   const struct bts_Cluster2D* ptrA );
    103 
    104 /** returns bounding box */
    105 struct bts_Int16Rect bts_Cluster2D_boundingBox( struct bbs_Context* cpA,
    106 											    const struct bts_Cluster2D* ptrA );
    107 
    108 /** returns int32 x-coordinate with given bbp at indexed position */
    109 int32 bts_Cluster2D_int32X( struct bbs_Context* cpA,
    110 						    const struct bts_Cluster2D* ptrA,
    111 							uint32 indexA, int32 bbpA );
    112 
    113 /** returns int32 y-coordinate with given bbp at indexed position */
    114 int32 bts_Cluster2D_int32Y( struct bbs_Context* cpA,
    115 						    const struct bts_Cluster2D* ptrA,
    116 							uint32 indexA,
    117 							int32 bbpA );
    118 
    119 /* ---- \ghd{ modify functions } ------------------------------------------- */
    120 
    121 /** allocates cluster */
    122 void bts_Cluster2D_create( struct bbs_Context* cpA,
    123 						   struct bts_Cluster2D* ptrA,
    124 						   uint32 sizeA,
    125 						   struct bbs_MemSeg* mspA );
    126 
    127 /** resize cluster (sizeA must be smaller or equal to allocated size)*/
    128 void bts_Cluster2D_size( struct bbs_Context* cpA,
    129 						 struct bts_Cluster2D* ptrA,
    130 						 uint32 sizeA );
    131 
    132 /** transforms cluster according to alt (function does not change bbp of cluster) */
    133 void bts_Cluster2D_transform( struct bbs_Context* cpA,
    134 							  struct bts_Cluster2D* ptrA,
    135 							  struct bts_Flt16Alt2D altA );
    136 
    137 /** transforms cluster according to alt and set bbp of output cluster */
    138 void bts_Cluster2D_transformBbp( struct bbs_Context* cpA,
    139 							     struct bts_Cluster2D* ptrA,
    140 							     struct bts_Flt16Alt2D altA,
    141 								 uint32 dstBbpA );
    142 
    143 /** transforms cluster with rbf map (function does not change bbp of cluster) */
    144 void bts_Cluster2D_rbfTransform( struct bbs_Context* cpA,
    145 								 struct bts_Cluster2D* ptrA,
    146 								 const struct bts_RBFMap2D* rbfMapPtrA );
    147 
    148 /** copies src cluster and simultaneously transforms vectors according to alt using dstBbpA as resulting cluster format */
    149 void bts_Cluster2D_copyTransform( struct bbs_Context* cpA,
    150 								  struct bts_Cluster2D* ptrA,
    151 								  const struct bts_Cluster2D* srcPtrA,
    152 								  struct bts_Flt16Alt2D altA,
    153 								  uint32 dstBbpA );
    154 
    155 /* ---- \ghd{ memory I/O } ------------------------------------------------- */
    156 
    157 /** size in words (16-bit) object needs when written to memory */
    158 uint32 bts_Cluster2D_memSize( struct bbs_Context* cpA,
    159 							  const struct bts_Cluster2D* ptrA );
    160 
    161 /** writes object to memory; returns number of words (16-bit) written */
    162 uint32 bts_Cluster2D_memWrite( struct bbs_Context* cpA,
    163 							   const struct bts_Cluster2D* ptrA,
    164 							   uint16* memPtrA );
    165 
    166 /** reads object from memory; returns number of words (16-bit) read */
    167 uint32 bts_Cluster2D_memRead( struct bbs_Context* cpA,
    168 							  struct bts_Cluster2D* ptrA,
    169 							  const uint16* memPtrA,
    170 						      struct bbs_MemSeg* mspA );
    171 
    172 /* ---- \ghd{ exec functions } --------------------------------------------- */
    173 
    174 /** Computes the best affine linear transformation from *srcPtrA to *dstPtrA.
    175  *  Constrains of trafo are given by altTypeA
    176  */
    177 struct bts_Flt16Alt2D bts_Cluster2D_alt( struct bbs_Context* cpA,
    178 										 const struct bts_Cluster2D* srcPtrA,
    179 										 const struct bts_Cluster2D* dstPtrA,
    180 										 enum bts_AltType altTypeA );
    181 
    182 #endif /* bts_CLUSTER2D_EM_H */
    183 
    184