5 #include <QScriptValue>
9 #include "qcepdocumentationdictionary.h"
20 #define UNUSED __attribute__((unused))
25 char* args[] = {
"cctw",
"-n", 0};
27 if (getenv(
"VALGRIND") != NULL)
30 setvbuf(stdout, NULL, _IONBF, 0);
32 g_DebugLevel = QSharedPointer<CctwDebug>(
new CctwDebug());
33 gDocumentationDirectory =
new QcepDocumentationDictionary();
45 int Cctwtcl_Cmd(ClientData , Tcl_Interp *interp,
int objc, Tcl_Obj *
const objv[])
48 const char *cmd = Tcl_GetString(objv[1]);
50 printf(
"evaluating: {%s}\n", cmd);
52 QScriptValue val = g_Application->
evaluate(cmd);
54 QString valStr = val.toString();
56 printf(
"%s -> %s\n", cmd, qPrintable(valStr));
58 Tcl_Obj *result = Tcl_NewStringObj(qPrintable(valStr), -1);
62 Tcl_SetObjResult(interp, result);
74 Tcl_Obj *result = Tcl_NewStringObj(qPrintable(res), -1);
75 Tcl_SetObjResult(interp, result);
78 }
else if (objc == 2) {
79 const char *cmd = Tcl_GetString(objv[1]);
81 QScriptValue val = g_Application->
evaluate(cmd);
83 QString res = val.toString();
84 Tcl_Obj *result = Tcl_NewStringObj(qPrintable(res), -1);
85 Tcl_SetObjResult(interp, result);
89 Tcl_SetResult(interp,
"usage: cctw_parameters [params]", TCL_STATIC);
101 TCL_ARGS(2,
"usage: cctw_input <chunkid>");
106 rc = Tcl_GetIntFromObj(interp, objv[1], &chunkId);
108 Tcl_SetResult(interp,
"chunkid must be an integer!\n", TCL_STATIC);
115 Tcl_SetResult(interp,
"input chunk does not exist\n", TCL_STATIC);
121 Tcl_Obj *res = Tcl_NewListObj(0, NULL);
122 Tcl_ListObjAppendElement(interp, res, Tcl_NewWideIntObj((Tcl_WideInt)chunk->
dataPointer()));
123 Tcl_ListObjAppendElement(interp, res, Tcl_NewWideIntObj((Tcl_WideInt)chunk->
weightsPointer()));
124 Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(length));
129 Tcl_SetObjResult(interp, res);
140 TCL_ARGS(2,
"usage: cctw_transform <chunk id>");
144 rc = Tcl_GetIntFromObj(interp, objv[1], &chunkIndex);
146 Tcl_SetResult(interp,
"chunk index must be an integer!\n", TCL_STATIC);
152 if (chunkData == NULL) {
153 Tcl_SetResult(interp, (
char*)
"input chunk is not present\n", TCL_STATIC);
162 QMap<int,CctwDataChunk*> outputChunks;
166 printf(
"products: %i\n", outputChunks.size());
170 Tcl_Obj *result = Tcl_NewListObj(0, NULL);
178 Tcl_Obj *index = Tcl_NewIntObj(outputChunk->
index());
180 Tcl_Obj *blob_length_tcl = Tcl_NewIntObj(blob_length);
181 Tcl_Obj *data_pointer = Tcl_NewWideIntObj((Tcl_WideInt) outputChunk->
dataPointer());
182 Tcl_Obj *
const blob_data_array[] = { data_pointer, blob_length_tcl };
183 Tcl_Obj *blob_data = Tcl_NewListObj(2, blob_data_array);
184 Tcl_Obj *weights_pointer = Tcl_NewWideIntObj((Tcl_WideInt) outputChunk->
weightsPointer());
185 Tcl_Obj *
const blob_weights_array[] = { weights_pointer, blob_length_tcl };
186 Tcl_Obj *blob_weights = Tcl_NewListObj(2, blob_weights_array);
189 Tcl_Obj *
const tuple_array[] = { index, blob_data, blob_weights, blob_length_tcl };
190 Tcl_Obj *tuple = Tcl_NewListObj(4, tuple_array);
192 Tcl_ListObjAppendElement(interp, result, tuple);
202 Tcl_SetObjResult(interp, result);
214 TCL_ARGS(2,
"usage: cctw_merge { { <merge ID> <data-pointer> <weights-pointer> <length> } ... }");
220 rc = Tcl_ListObjGetElements(interp, objv[1], &nblobs, &blobs);
223 Tcl_SetResult(interp,
"Input argument should be a list\n", TCL_STATIC);
227 for (
int i=0; i<nblobs; i++) {
231 rc = Tcl_ListObjGetElements(interp, blobs[i], &nargs, &blobargs);
234 Tcl_SetResult(interp,
"Input list element should also be a list\n", TCL_STATIC);
239 Tcl_SetResult(interp,
"Input list element should be at least 4 elements long\n", TCL_STATIC);
244 Tcl_WideInt dataPointer, weightPointer;
247 rc = Tcl_GetIntFromObj(interp, blobargs[0], &chunkId);
250 Tcl_SetResult(interp,
"Blob ID should be an integer\n", TCL_STATIC);
254 rc = Tcl_GetWideIntFromObj(interp, blobargs[1], &dataPointer);
257 Tcl_SetResult(interp,
"Data Pointer should be wide integer\n", TCL_STATIC);
261 rc = Tcl_GetWideIntFromObj(interp, blobargs[2], &weightPointer);
264 Tcl_SetResult(interp,
"Weight Pointer should be wide integer\n", TCL_STATIC);
268 rc = Tcl_GetIntFromObj(interp, blobargs[3], &blobLength);
271 Tcl_SetResult(interp,
"Blob length should be an integer\n", TCL_STATIC);
282 printf(
"Output chunk %d does not exist, skipped\n", chunkId);
292 TCL_ARGS(2,
"usage: cctw_output <chunk-id>");
297 rc = Tcl_GetIntFromObj(interp, objv[1], &chunkId);
300 Tcl_SetResult(interp,
"chunk id should be an integer\n", TCL_STATIC);
CctwChunkedData * m_OutputData
int Cctwtcl_Input_Cmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void mergeData(CctwChunkedData::MergeDataType *id, CctwChunkedData::MergeDataType *iw, int n)
int Cctwtcl_Parameters_Cmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Cctwtcl_Cmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
static void initialize(void)
CctwChunkedData * m_InputData
CctwIntVector3D chunkSize()
CctwDataChunk * chunk(int n)
static CctwApplication * g_Application
CctwTransformer * m_Transformer
int Cctwtcl_Merge_Cmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
#define TCL_ARGS(count_expr, help)
CctwChunkedData::MergeDataType * weightsPointer()
QScriptValue evaluate(QString cmd)
int Cctwtcl_Output_Cmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Cctwtcl_Transform_Cmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
CctwChunkedData::MergeDataType * dataPointer()
CctwDataChunk * readChunk(int n)