[Therion] More thoughts on Therion grids

A Gott alastairgott at gmail.com
Thu Apr 18 20:40:06 CEST 2024


HI Therion Mailing list,

I have spent a couple of days looking over a few options with getting a
grid onto the survey I sent around last week. below are the things I have
tried.

   1. Manipulating Freq of grid spacing
   2. Looking at C++ Therion code
   3. Creating a Grid.pdf plan file - To save reading, my take away was give
   up
   4. Drawing Gridlines on .th2 for inclusion


Two options now being considered:

   1. using microsoft excel to create grid.th file
   2. One for those with experience - Creating a script (Python?) to make
   the grid


My findings on 1-4 are:

   1. *Manipulating Freq of grid spacing*

I did this as this had been suggested to me and was a good solution, but at
the 40-50m spacing required to get the grid to show in full this left the
top right and bottom right corners with duplicate coordinates written over
each other. for a finished survey, this would not be an optimal solution to
the problem.


   2. *Looking at C++ Therion code*

I'm not a coder but I tried to look at the C++/Cxx code for therion to try
and make some amendments, but didn't realise when I tried to use it in the
thconfig file, that it doesn't work the same as "code metapost". but when
taking a look at it I found chunks of the code which I thought were
relevant, and include these below my signature.

3) *Creating a Grid.pdf plan file* - To save reading, my take away was give
up
As the Manipulation of the frequency of the Grid spacing went ok, I decided
I could potentially use this to create a background for the survey but
including it in the files, I didn't make a plan (and wouldn't repeat)
but this went along the lines of:

   1. screenshot Survey, include image of survey in th2 file, place survey
   points at TR (top right) and BL coordinates required of the th2 file, set
   scrap scale as per survey scale.
   2. create .th file which includes the two points as grid reference
   points, create .thconfig file to replicate the grid formation with no
   survey in it.
   3. export to pdf, use online pdf converter to create .jpg file, and then
   use paint to remove the overlapping coordinates in the top right and bottom
   right of the grid.
   4. use jpg as a background image in a .th2 file, include the coordinates
   etc in the main survey master .th file.
   5. attempt to use "sketches on" to import this grid into the lowest part
   of the survey to ensure it is shown on the bottom.
   6. give up waiting, as it was taking an age to 'warp' the sketch -
   abandon this as an idea.


4) *Drawing Gridlines on .th2 for inclusion*
I think I could have skipped some of the above steps and used John Stevens
example of drawing gridlines on a .th2 file earlier, advantages - get
gridlines where you want, disadvantages - time consuming and potential for
gridlines which don't look as polished as if a piece of software were doing
it for you.


I'm now considering

   1. *using microsoft excel to create grid.th <http://grid.th> file*

creating a microsoft excel file to create a grid.th file which will use one
scrap for each vertical gridline and one for each horizontal gridline.
something along the lines of:
survey gridlines
scrap Vert1
point 1 -1 station -name BotVert1
point 1 0 station -name TopVert1
line u:grid -clip off -place bottom
  1 -1
  1 0
endline
endscrap

scrap Vert2
point 2 -1 station -name BotVert2
point 2 0 station -name TopVert2
line u:grid -clip off -place bottom
  2 -1
  2 0
endline
endscrap

map scrap verticals
Vert1
Vert2
endmap

map grid
scrap verticals
scrap horizontals
scrap labels
endmap

centreline
  cs OSGB:SK
  station BotVert1
  fix BotVert1 realX realY 0
  station TopVert1
  fix TopVert1 realX realY1 0
...etc...
  endcentreline


   2. *One for those with experience - Creating a script (**Python?)** to
   make the grid*

If anyone has any experience of it could they make a small script (like
topparser is) that can make a .th file such as the above. My thoughts are
that with a few small options this could be a quick win for a few people
who are manually making their own grids.
 Therion already has an option to output coordinates for the bbox, these
could be inputted into the script and then an option selected for the
coordinate system, grid spacing, labeling frequency and placement


Regards,
Alastair Gott.
-------------------
Therion source code I thought was most closely aligned to the above problem.

*CXX to control grid formation and pattern*
from line 775 on therion/thpdf.cxx

  GRIDLIST.clear();
  if (LAYOUT.grid > 0) {
    converted_data scr;
    double a,b,c,d;
    parse_eps(LAYOUT.gridAA, "",0,0,a,b,c,d,scr,101);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[0].x = a;
    LAYOUT.gridcell[0].y = b;
    parse_eps(LAYOUT.gridAB, "",0,0,a,b,c,d,scr,102);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[1].x = a;
    LAYOUT.gridcell[1].y = b;
    parse_eps(LAYOUT.gridAC, "",0,0,a,b,c,d,scr,103);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[2].x = a;
    LAYOUT.gridcell[2].y = b;
    parse_eps(LAYOUT.gridBA, "",0,0,a,b,c,d,scr,104);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[3].x = a;
    LAYOUT.gridcell[3].y = b;
    parse_eps(LAYOUT.gridBB, "",0,0,a,b,c,d,scr,105);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[4].x = a;
    LAYOUT.gridcell[4].y = b;
    parse_eps(LAYOUT.gridBC, "",0,0,a,b,c,d,scr,106);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[5].x = a;
    LAYOUT.gridcell[5].y = b;
    parse_eps(LAYOUT.gridCA, "",0,0,a,b,c,d,scr,107);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[6].x = a;
    LAYOUT.gridcell[6].y = b;
    parse_eps(LAYOUT.gridCB, "",0,0,a,b,c,d,scr,108);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[7].x = a;
    LAYOUT.gridcell[7].y = b;
    parse_eps(LAYOUT.gridCC, "",0,0,a,b,c,d,scr,109);
GRIDLIST.push_back(scr);scr.clear();
    LAYOUT.gridcell[8].x = a;
    LAYOUT.gridcell[8].y = b;
  }

  PATTERNLIST.clear();

  std::ifstream P("patterns.dat");
  if(!P) therror(("Can't open patterns definition file!"));
  char buf[5000];
  char delim[] = ":";
  std::string line,num,pfile,bbox,xstep,ystep,matr;
  while(P.getline(buf,5000,'\n')) {
    num = strtok(buf,delim);
    pfile = strtok(NULL,delim);
    bbox = strtok(NULL,delim);
    xstep = strtok(NULL,delim);
    ystep = strtok(NULL,delim);
    matr = strtok(NULL,delim);
//    if (ALL_PATTERNS.count(num) > 0) {  // changed to patt.used flag
                                          // because thsymbolset.cxx
                                          // calls eps_parse after
                                          // this function is called
                                          // and patterns referenced
                                          // there would be missing in this
list
      pattern patt;
      patt.used = (ALL_PATTERNS.count(num) > 0);
      patt.name = num;

      matr.replace(matr.find("["),1,"");
      matr.replace(matr.find("]"),1,"");
      std::istringstream s1(matr);
      s1 >> patt.xx >> patt.xy >> patt.yx >> patt.yy >> patt.x >> patt.y;
      bbox.replace(bbox.find("["),1,"");
      bbox.replace(bbox.find("]"),1,"");
      std::istringstream s2(bbox);
      s2 >> patt.llx >> patt.lly >> patt.urx >> patt.ury;
//      F << "/Matrix " << matr << endl;
//      F << "/BBox " << bbox << endl;
      patt.xstep = atof(xstep.c_str());
      patt.ystep = atof(ystep.c_str());

      parse_eps(pfile , "", 0,0,
patt.llx1,patt.lly1,patt.urx1,patt.ury1,patt.data,0);
      PATTERNLIST.push_back(patt);
//    }  // patt.used
  }
  P.close();
}

*Cxx for Bounding control*
This was the first bit of code I noted down, before I kept proper refs of
them, think it was Located in xtherion/thepsparse.cxx/from line 1336

 if (J->second.minx > Llx) J->second.minx = Llx;
            if (J->second.miny > Lly) J->second.miny = Lly;
            if (J->second.maxx < Urx) J->second.maxx = Urx;
            if (J->second.maxy < Ury) J->second.maxy = Ury;

*Cxx for Layout Calibration*
two bits of code seem to be working together with the use of
LAYOUT.calibration_hdist


   1. code from Therion/thpdf.cxx/1620-1621

PAGEDEF << "\\pdfcatalog { /thCalibrate (HS=\\the\\adjustedHS,
VS=\\the\\adjustedVS, HD=" <<
               fmt::format("{}",thdouble(LAYOUT.calibration_hdist,10)) <<
")}";

2) code from therion/thexpmap.cxx/line 1862-1871
  calpoint(0, lim.min.x, lim.min.y);
  calpoint(1, (lim.min.x + lim.max.x) / 2.0,lim.min.y);
  calpoint(2, lim.max.x, lim.min.y);
  calpoint(3, lim.min.x, (lim.min.y + lim.max.y) / 2.0);
  calpoint(4, lim.max.x, (lim.min.y + lim.max.y) / 2.0);
  calpoint(5, lim.min.x, lim.max.y);
  calpoint(6, (lim.min.x + lim.max.x) / 2.0,lim.max.y);
  calpoint(7, lim.max.x, lim.max.y);
  calpoint(8, (lim.min.x + lim.max.x) / 2.0, (lim.min.y + lim.max.y) / 2.0);
  LAYOUT.calibration_hdist = lim.max.x - lim.min.x;

*Cxx for Adjustments*
code from Therion/thpdf.cxx/1598-1608

PAGEDEF << "\\adjustedHS=" << fmt::format("{}",thdouble(HS,prec_xy)) <<
"bp" <<
      "\\advance\\adjustedHS by \\extraE" <<
      "\\advance\\adjustedHS by \\extraW" <<
      "\\advance\\adjustedHS by \\overlap" <<
      "\\advance\\adjustedHS by \\overlap" <<  std::endl;

    PAGEDEF << "\\adjustedVS=" << fmt::format("{}",thdouble(VS,prec_xy)) <<
"bp" <<
      "\\advance\\adjustedVS by \\extraN" <<
      "\\advance\\adjustedVS by \\extraS" <<
      "\\advance\\adjustedVS by \\overlap" <<
      "\\advance\\adjustedVS by \\overlap" << std::endl;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20240418/9401516e/attachment-0001.htm>


More information about the Therion mailing list