Esempio n. 1
0
wbBool wbSolution(char *expectedOutputFile, char *outputFile, char *type0,
                  void *data, int rows, int columns, int depth) {
  char *type;
  wbBool res;
  wbSolution_t sol;

  if (expectedOutputFile == NULL || data == NULL || type0 == NULL) {
    wbLog(ERROR, "Failed to grade solution");
    return wbFalse;
  }

  type = wbString_toLower(type0);

  if (_solution_correctQ != "") {
    _solution_correctQ = "";
  }

  wbSolution_setOutputFile(sol, outputFile);
  wbSolution_setId(sol, uuid());
  wbSolution_setSessionId(sol, sessionId());
  wbSolution_setType(sol, type);
  wbSolution_setData(sol, data);
  wbSolution_setRows(sol, rows);
  wbSolution_setColumns(sol, columns);
  wbSolution_setDepth(sol, depth);

  res = wbSolution_correctQ(expectedOutputFile, sol);

  if (outputFile != NULL) {
    if (wbString_sameQ(type, "image")) {
      wbImage_t inputImage = (wbImage_t)data;
      wbImage_t img        = wbImage_new(wbImage_getWidth(inputImage),
                                  wbImage_getHeight(inputImage),
                                  wbImage_getChannels(inputImage));
      memcpy(wbImage_getData(img), wbImage_getData(inputImage),
             rows * columns * wbImage_channels * sizeof(wbReal_t));
      wbExport(outputFile, img);
      wbImage_delete(img);
    } else if (wbString_sameQ(type, "integral_vector")) {
      wbExport(outputFile, (int *)data, rows, columns);
    } else if (wbString_sameQ(type, "vector") ||
               wbString_sameQ(type, "matrix")) {
      wbExport(outputFile, (wbReal_t *)data, rows, columns);
    } else if (wbString_sameQ(type, "histogram")) {
      wbExport(outputFile, (unsigned char *)data, rows, columns);
    } else if (wbString_sameQ(type, "text")) {
      wbExport_text(outputFile, (unsigned char *)data, rows * columns);
    }
  }

  wbFree(type);

  return res;
}
Esempio n. 2
0
wbBool wbSolution(char * expectedOutputFile,
                  char * outputFile, char * type0,
                  void * data, int rows, int columns) {
    char * type;
    wbBool res;
    wbSolution_t sol;

    if (expectedOutputFile == NULL ||
        //outputFile == NULL ||
        data == NULL ||
        type0 == NULL) {
        wbLog(ERROR, "Failed to grade solution");
        return wbFalse;
    }

    type = wbString_toLower(type0);

    if (_solution_correctQ != NULL) {
        json_delete(_solution_correctQ);
        _solution_correctQ = NULL;
    }

    wbSolution_setOutputFile(sol, outputFile);
    wbSolution_setType(sol, type);
    wbSolution_setData(sol, data);
    wbSolution_setRows(sol, rows);
    wbSolution_setColumns(sol, columns);

    res = wbSolution_correctQ(expectedOutputFile, sol);

/*
    if (wbString_sameQ(type, "image")) {
        wbImage_t img = wbImage_new(rows, columns);
        memcpy(wbImage_getData(img), data, rows*columns*wbImage_channels*sizeof(wbReal_t));
        wbExport(outputFile, img);
        wbImage_delete(img);
    } else if (wbString_sameQ(type, "vector") ||
               wbString_sameQ(type, "matrix")) {
        wbExport(outputFile, (wbReal_t *) data, rows, columns);
    }
*/

    wbFree(type);

    return res;
}