<commit_before>/*
  Teem: <NAME>'s research software
  Copyright (C) 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "ten.h"
#include "privateTen.h"

#define INFO "Generate postscript or ray-traced renderings of 3D glyphs"
char *_tend_glyphInfoL =
  (INFO
   ".  Whether the output is postscript or a ray-traced image is controlled "
   "by the initial \"rt\" flag (by default, the output is postscript). "
   "Because this is doing viz/graphics, many parameters need to be set. "
   "Use a response file to simplify giving the command-line options which "
   "aren't changing between invocations. "
   "The postscript output is an EPS file, suitable for including as a figure "
   "in LaTeX, or viewing with ghostview, or distilling into PDF. "
   "The ray-traced output is a 5 channel (R,G,B,A,T) float nrrd, suitable for "
   "\"unu crop -min 0 0 0 -max 2 M M \" followed by "
   "\"unu gamma\" and/or \"unu quantize -b 8\".");

#define _LIMNMAGIC "LIMN0000"

int
_tendGlyphReadCams(int imgSize[2], limnCamera **camP,
                   int *numCamsP, FILE *fin) {
  char me[]="_tendGlyphReadCams", err[AIR_STRLEN_MED];
  char line[AIR_STRLEN_HUGE];
  int ki;
  double di, dn, df, fr[3], at[3], up[3], va, dwell;
  airArray *mop, *camA;
  
  if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE)
         && !strcmp(_LIMNMAGIC, line) )) {
    sprintf(err, "%s: couldn't read first line or it wasn't \"%s\"",
            me, _LIMNMAGIC);
    biffAdd(TEN, err); return 1;
  }
  if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE)
         && 2 == (airStrtrans(airStrtrans(line, '{', ' '), '}', ' '),
                  sscanf(line, "imgSize %d %d", imgSize+0, imgSize+1)) )) {
    sprintf(err, "%s: couldn't read second line or it wasn't "
            "\"imgSize <sizeX> <sizeY>\"", me);
    biffAdd(TEN, err); return 1;
  }
  
  mop = airMopNew();
  camA = airArrayNew((void **)camP, numCamsP, sizeof(limnCamera), 1);
  airMopAdd(mop, camA, (airMopper)airArrayNix, airMopAlways);

  while ( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE) ) {
    airStrtrans(airStrtrans(line, '{', ' '), '}', ' ');
    ki = airArrayIncrLen(camA, 1);
    if (14 != sscanf(line, "cam.di %lg cam.at %lg %lg %lg "
                     "cam.up %lg %lg %lg cam.dn %lg cam.df %lg cam.va %lg "
                     "relDwell %lg cam.fr %lg %lg %lg",
                     &di, at+0, at+1, at+2,
                     up+0, up+1, up+2, &dn, &df, &va,
                     &dwell, fr+0, fr+1, fr+2)) {
      sprintf(err, "%s: trouble parsing line %d: \"%s\"", me, ki, line);
      biffAdd(TEN, err); airMopError(mop); return 1;
    }
    (*camP)[ki].neer = dn;
    (*camP)[ki].faar = df;
    (*camP)[ki].dist = di;
    ELL_3V_COPY((*camP)[ki].from, fr);
    ELL_3V_COPY((*camP)[ki].at, at);
    ELL_3V_COPY((*camP)[ki].up, up);
    (*camP)[ki].fov = va;
    (*camP)[ki].aspect = (double)imgSize[0]/imgSize[1];
    (*camP)[ki].atRelative = AIR_FALSE;
    (*camP)[ki].orthographic = AIR_FALSE;
    (*camP)[ki].rightHanded = AIR_TRUE;
  }

  airMopOkay(mop);
  return 0;
}

int
tend_glyphMain(int argc, char **argv, char *me, hestParm *hparm) {
  int pret, doRT = AIR_FALSE;
  hestOpt *hopt = NULL;
  char *perr, *err;
  airArray *mop;

  Nrrd *nten, *emap, *nraw, *npos, *nslc;
  char *outS;
  limnCamera *cam, *hackcams;
  limnObject *glyph;
  limnWindow *win;
  echoObject *rect=NULL;
  echoScene *scene;
  echoRTParm *eparm;
  echoGlobalState *gstate;
  tenGlyphParm *gparm;
  float bg[3], buvne[5], shadow;
  int ires[2], slice[2], nobg, hacknumcam, hackci,
    hackmin[3]={0,0,0}, hackmax[3]={2,0,0};
  char *hackFN, hackoutFN[AIR_STRLEN_SMALL];
  FILE *hackF;
  Nrrd *hacknpng, *hacknrgb;
  NrrdRange *hackrange;

  float v2w[9], ldir[3], edir[3], fdir[3], corn[3], len;

  /* so that command-line options can be read from file */
  hparm->respFileEnable = AIR_TRUE;
  hparm->elideSingleEmptyStringDefault = AIR_TRUE;

  mop = airMopNew();
  cam = limnCameraNew();
  airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways);
  glyph = limnObjectNew(1000, AIR_TRUE);
  airMopAdd(mop, glyph, (airMopper)limnObjectNix, airMopAlways);
  scene = echoSceneNew();
  airMopAdd(mop, scene, (airMopper)echoSceneNix, airMopAlways);
  win = limnWindowNew(limnDevicePS);
  airMopAdd(mop, win, (airMopper)limnWindowNix, airMopAlways);
  gparm = tenGlyphParmNew();
  airMopAdd(mop, gparm, (airMopper)tenGlyphParmNix, airMopAlways);
  eparm = echoRTParmNew();
  airMopAdd(mop, eparm, (airMopper)echoRTParmNix, airMopAlways);

  /* do postscript or ray-traced? */
  hestOptAdd(&hopt, "rt", NULL, airTypeFloat, 0, 0, &doRT, NULL,
             "generate ray-traced output.  By default (not using this "
             "option), postscript output is generated.");

  hestOptAdd(&hopt, "v", "level", airTypeInt, 1, 1, &(gparm->verbose), "0",
             "verbosity level");
  
  /* which points will rendered */
  hestOptAdd(&hopt, "ctr", "conf thresh", airTypeFloat, 1, 1,
             &(gparm->confThresh), "0.5",
             "Glyphs will be drawn only for tensors with confidence "
             "values greater than this threshold");
  hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1,
             &(gparm->anisoType), "fa",
             "Which anisotropy metric to use for thresholding the data "
             "points to be drawn", NULL, tenAniso);
  hestOptAdd(&hopt, "atr", "aniso thresh", airTypeFloat, 1, 1,
             &(gparm->anisoThresh), "0.5",
             "Glyphs will be drawn only for tensors with anisotropy "
             "greater than this threshold");
  hestOptAdd(&hopt, "p", "pos array", airTypeOther, 1, 1, &npos, "",
             "Instead of being on a grid, tensors are at arbitrary locations, "
             "as defined by this 3-by-N array of floats. Doing this makes "
             "various other options moot. ", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "m", "mask vol", airTypeOther, 1, 1, &(gparm->nmask), "",
             "Scalar volume (if any) for masking region in which glyphs are "
             "drawn, in conjunction with \"mtr\" flag. ", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "mtr", "mask thresh", airTypeFloat, 1, 1,
             &(gparm->maskThresh),
             "0.5", "Glyphs will be drawn only for tensors with mask "
             "value greater than this threshold");

  /* how glyphs will be shaped */
  hestOptAdd(&hopt, "g", "glyph shape", airTypeEnum, 1, 1,<commit_msg>cosmetic changes to usage info<commit_after>/*
  Teem: <NAME>'s research software
  Copyright (C) 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "ten.h"
#include "privateTen.h"

#define INFO "Generate postscript or ray-traced renderings of 3D glyphs"
char *_tend_glyphInfoL =
  (INFO
   ".  Whether the output is postscript or a ray-traced image is controlled "
   "by the initial \"rt\" flag (by default, the output is postscript). "
   "Because this is doing viz/graphics, many parameters need to be set. "
   "Use a response file to simplify giving the command-line options which "
   "aren't changing between invocations. "
   "The postscript output is an EPS file, suitable for including as a figure "
   "in LaTeX, or viewing with ghostview, or distilling into PDF. "
   "The ray-traced output is a 5 channel (R,G,B,A,T) float nrrd, suitable for "
   "\"unu crop -min 0 0 0 -max 2 M M \" followed by "
   "\"unu gamma\" and/or \"unu quantize -b 8\".");

#define _LIMNMAGIC "LIMN0000"

int
_tendGlyphReadCams(int imgSize[2], limnCamera **camP,
                   int *numCamsP, FILE *fin) {
  char me[]="_tendGlyphReadCams", err[AIR_STRLEN_MED];
  char line[AIR_STRLEN_HUGE];
  int ki;
  double di, dn, df, fr[3], at[3], up[3], va, dwell;
  airArray *mop, *camA;
  
  if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE)
         && !strcmp(_LIMNMAGIC, line) )) {
    sprintf(err, "%s: couldn't read first line or it wasn't \"%s\"",
            me, _LIMNMAGIC);
    biffAdd(TEN, err); return 1;
  }
  if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE)
         && 2 == (airStrtrans(airStrtrans(line, '{', ' '), '}', ' '),
                  sscanf(line, "imgSize %d %d", imgSize+0, imgSize+1)) )) {
    sprintf(err, "%s: couldn't read second line or it wasn't "
            "\"imgSize <sizeX> <sizeY>\"", me);
    biffAdd(TEN, err); return 1;
  }
  
  mop = airMopNew();
  camA = airArrayNew((void **)camP, numCamsP, sizeof(limnCamera), 1);
  airMopAdd(mop, camA, (airMopper)airArrayNix, airMopAlways);

  while ( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE) ) {
    airStrtrans(airStrtrans(line, '{', ' '), '}', ' ');
    ki = airArrayIncrLen(camA, 1);
    if (14 != sscanf(line, "cam.di %lg cam.at %lg %lg %lg "
                     "cam.up %lg %lg %lg cam.dn %lg cam.df %lg cam.va %lg "
                     "relDwell %lg cam.fr %lg %lg %lg",
                     &di, at+0, at+1, at+2,
                     up+0, up+1, up+2, &dn, &df, &va,
                     &dwell, fr+0, fr+1, fr+2)) {
      sprintf(err, "%s: trouble parsing line %d: \"%s\"", me, ki, line);
      biffAdd(TEN, err); airMopError(mop); return 1;
    }
    (*camP)[ki].neer = dn;
    (*camP)[ki].faar = df;
    (*camP)[ki].dist = di;
    ELL_3V_COPY((*camP)[ki].from, fr);
    ELL_3V_COPY((*camP)[ki].at, at);
    ELL_3V_COPY((*camP)[ki].up, up);
    (*camP)[ki].fov = va;
    (*camP)[ki].aspect = (double)imgSize[0]/imgSize[1];
    (*camP)[ki].atRelative = AIR_FALSE;
    (*camP)[ki].orthographic = AIR_FALSE;
    (*camP)[ki].rightHanded = AIR_TRUE;
  }

  airMopOkay(mop);
  return 0;
}

int
tend_glyphMain(int argc, char **argv, char *me, hestParm *hparm) {
  int pret, doRT = AIR_FALSE;
  hestOpt *hopt = NULL;
  char *perr, *err;
  airArray *mop;

  Nrrd *nten, *emap, *nraw, *npos, *nslc;
  char *outS;
  limnCamera *cam, *hackcams;
  limnObject *glyph;
  limnWindow *win;
  echoObject *rect=NULL;
  echoScene *scene;
  echoRTParm *eparm;
  echoGlobalState *gstate;
  tenGlyphParm *gparm;
  float bg[3], buvne[5], shadow;
  int ires[2], slice[2], nobg, hacknumcam, hackci,
    hackmin[3]={0,0,0}, hackmax[3]={2,0,0};
  char *hackFN, hackoutFN[AIR_STRLEN_SMALL];
  FILE *hackF;
  Nrrd *hacknpng, *hacknrgb;
  NrrdRange *hackrange;

  float v2w[9], ldir[3], edir[3], fdir[3], corn[3], len;

  /* so that command-line options can be read from file */
  hparm->respFileEnable = AIR_TRUE;
  hparm->elideSingleEmptyStringDefault = AIR_TRUE;

  mop = airMopNew();
  cam = limnCameraNew();
  airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways);
  glyph = limnObjectNew(1000, AIR_TRUE);
  airMopAdd(mop, glyph, (airMopper)limnObjectNix, airMopAlways);
  scene = echoSceneNew();
  airMopAdd(mop, scene, (airMopper)echoSceneNix, airMopAlways);
  win = limnWindowNew(limnDevicePS);
  airMopAdd(mop, win, (airMopper)limnWindowNix, airMopAlways);
  gparm = tenGlyphParmNew();
  airMopAdd(mop, gparm, (airMopper)tenGlyphParmNix, airMopAlways);
  eparm = echoRTParmNew();
  airMopAdd(mop, eparm, (airMopper)echoRTParmNix, airMopAlways);

  /* do postscript or ray-traced? */
  hestOptAdd(&hopt, "rt", NULL, airTypeFloat, 0, 0, &doRT, NULL,
             "generate ray-traced output.  By default (not using this "
             "option), postscript output is generated.");

  hestOptAdd(&hopt, "v", "level", airTypeInt, 1, 1, &(gparm->verbose), "0",
             "verbosity level");
  
  /* which points will rendered */
  hestOptAdd(&hopt, "ctr", "conf thresh", airTypeFloat, 1, 1,
             &(gparm->confThresh), "0.5",
             "Glyphs will be drawn only for tensors with confidence "
             "values greater than this threshold");
  hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1,
             &(gparm->anisoType), "fa",
             "Which anisotropy metric to use for thresholding the data "
             "points to be drawn", NULL, tenAniso);
  hestOptAdd(&hopt, "atr", "aniso thresh", airTypeFloat, 1, 1,
             &(gparm->anisoThresh), "0.5",
             "Glyphs will be drawn only for tensors with anisotropy "
             "greater than this threshold");
  hestOptAdd(&hopt, "p", "pos array", airTypeOther, 1, 1, &npos, "",
             "Instead of being on a grid, tensors are at arbitrary locations, "
             "as defined by this 3-by-N array of floats. Doing this makes "
             "various other options moot", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "m", "mask vol", airTypeOther, 1, 1, &(gparm->nmask), "",
             "Scalar volume (if any) for masking region in which glyphs are "
             "drawn, in conjunction with \"mtr\" flag. ", NULL, NULL,
             nrrdHestNrrd);
  hestOptAdd(&hopt, "mtr", "mask thresh", airTypeFloat, 1, 1,
             &(gparm->maskThresh),
             "0.5", "Glyphs will be drawn only for tensors with mask "
             "value greater than this threshold");

  /* how glyphs will be shaped */
  hestOptAdd(&hopt, "g", "glyph shape", airTypeEnum, 1, 1,
{'fraction_non_alphanumeric': 0.13958174112415758, 'fraction_numerical': 0.019314944764816232, 'mean_word_length': 3.1279036420992257, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6395578', 'n_tokens_mistral': 5517, 'n_tokens_neox': 5181, 'n_words': 1551}