31 #ifndef __TCLMATRIX_H__
32 #define __TCLMATRIX_H__
51 #define MAX_ARRAY_DIM 3
55 #define I3D( i, j, k ) k + matPtr->n[2] * ( I2D( i, j ) )
56 #define I2D( i, j ) j + matPtr->n[1] * ( I1D( i ) )
78 void ( *put )( ClientData clientData, Tcl_Interp*
interp,
int index,
const char *string );
79 void ( *
get )( ClientData clientData, Tcl_Interp*
interp,
int index,
char *string );
102 #if defined ( __GNUC__ ) || defined ( __lucid ) || defined ( __CENTERLINE__ ) \
103 || defined ( CENTERLINE_CLPP )
113 { cerr << "THROW: " << # a << " from " << __FILE__ \
114 << " line " << __LINE__ << endl << flush; abort(); }
115 #define catch( a ) if ( 0 )
122 #define tMat_Assert( a, b ) if ( !( a ) ) \
123 { using namespace std; \
124 cerr << "Assertion " << # a << " failed in " << __FILE__ \
125 << " at line " << __LINE__ << endl << flush; \
142 tMat_Assert( matPtr->type ==
TYPE_FLOAT,
"Type mismatch" );
145 int Dimensions()
const
150 int dim_size(
int d )
const
152 tMat_Assert( d < matPtr->dim,
"Range error." );
158 free( matPtr->fdata );
162 matPtr->fdata = (
Mat_float *) malloc( matPtr->len *
166 void redim(
int nx,
int ny )
168 free( matPtr->fdata );
172 matPtr->len = nx * ny;
173 matPtr->fdata = (
Mat_float *) malloc( matPtr->len *
177 void redim(
int nx,
int ny,
int nz )
179 free( matPtr->fdata );
184 matPtr->len = nx * ny * nz;
185 matPtr->fdata = (
Mat_float *) malloc( matPtr->len *
191 tMat_Assert( matPtr->dim == 1,
"Wrong number of indicies." );
192 tMat_Assert( i >= 0 && i < matPtr->n[0],
193 "Out of bounds reference" );
195 return matPtr->fdata[i];
200 tMat_Assert( matPtr->dim == 2,
"Wrong number of indicies." );
201 tMat_Assert( i >= 0 && i < matPtr->n[0] &&
202 j >= 0 && j < matPtr->n[1],
203 "Out of bounds reference" );
205 return matPtr->fdata[
I2D( i, j )];
208 Mat_float& operator() (
int i,
int j,
int k )
210 tMat_Assert( matPtr->dim == 3,
"Wrong number of indicies." );
211 tMat_Assert( i >= 0 && i < matPtr->n[0] &&
212 j >= 0 && j < matPtr->n[1] &&
213 k >= 0 && k < matPtr->n[2],
214 "Out of bounds reference" );
216 return matPtr->fdata[
I3D( i, j, k )];
234 tMat_Assert( matPtr->type ==
TYPE_INT,
"Type mismatch" );
237 int Dimensions()
const
242 int dim_size(
int d )
const
244 tMat_Assert( d < matPtr->dim,
"Range error." );
250 free( matPtr->idata );
254 matPtr->idata = (
Mat_int *) malloc( matPtr->len * sizeof (
Mat_int ) );
257 void redim(
int nx,
int ny )
259 free( matPtr->idata );
263 matPtr->len = nx * ny;
264 matPtr->idata = (
Mat_int *) malloc( matPtr->len * sizeof (
Mat_int ) );
267 void redim(
int nx,
int ny,
int nz )
269 free( matPtr->idata );
274 matPtr->len = nx * ny * nz;
275 matPtr->idata = (
Mat_int *) malloc( matPtr->len * sizeof (
Mat_int ) );
280 tMat_Assert( matPtr->dim == 1,
"Wrong number of indicies." );
281 tMat_Assert( i >= 0 && i < matPtr->n[0],
282 "Out of bounds reference" );
284 return matPtr->idata[i];
287 Mat_int& operator() (
int i,
int j )
289 tMat_Assert( matPtr->dim == 2,
"Wrong number of indicies." );
290 tMat_Assert( i >= 0 && i < matPtr->n[0] &&
291 j >= 0 && j < matPtr->n[1],
292 "Out of bounds reference" );
294 return matPtr->idata[
I2D( i, j )];
297 Mat_int& operator() (
int i,
int j,
int k )
299 tMat_Assert( matPtr->dim == 3,
"Wrong number of indicies." );
300 tMat_Assert( i >= 0 && i < matPtr->n[0] &&
301 j >= 0 && j < matPtr->n[1] &&
302 k >= 0 && k < matPtr->n[2],
303 "Out of bounds reference" );
305 return matPtr->idata[
I3D( i, j, k )];
360 #endif // __TCLMATRIX_H__