Topography into object

48 views
Skip to first unread message

cedric penard

unread,
Aug 18, 2025, 12:27:35 PMAug 18
to basilisk-fr
Hello everyone,

What tool can I use to convert a GeoTiff DEM file into an STL object?
I tried this tool:
https://github.com/FilLTP89/dem2stl
But the generated STL file seems unreadable by Basilisk.
Or maybe I'm making a mistake?

Is there another way to integrate a terrain file into a 3D Navier Stokes simulation?

Below are capture from meshlab of the stl file and the code used to load the terrain (inspired by http://basilisk.fr/sandbox/Antoonvh/matter.c)

Thanks
Cédric


Capture_mesh.PNG

#include "grid/octree.h"
#include "distance.h"
#include "fractions.h"
#include "view.h"

int LEVEL = 9;
void fraction_from_stl (scalar f, FILE * fp, double eps, int maxlevel) {
  coord * p = input_stl (fp);
  coord min, max;
  bounding_box (p, &min, &max);
  // set the origin point
  origin ((max.x + min.x)/2. - L0/2,
          (max.y + min.y)/2. - L0/2,
          min.z);
  double sizex = -HUGE;
  foreach_dimension()
    if (max.x - min.x > sizex)
      sizex = max.x - min.x;
  // set domain size
  size (sizex);

  scalar d[];
  distance (d, p);
  while (adapt_wavelet ({d}, (double[]){eps*sizex}, maxlevel, 5).nf);
  vertex scalar phi[];
  foreach_vertex()
    phi[] = (d[] + d[-1] + d[0,-1] + d[-1,-1] +
             d[0,0,-1] + d[-1,0,-1] + d[0,-1,-1] + d[-1,-1,-1])/8.;
  boundary ({phi});
  fractions (phi, f);
}

scalar f[];

int main () {
  init_grid (64);
  f.refine = f.prolongation = fraction_refine;
  FILE * fp = fopen ("../aude_dem.stl", "r");
  fraction_from_stl (f, fp, 4e-4, LEVEL);
  fclose (fp);
  view (theta = pi/2, tx = 0.35);
  draw_vof("f");
  box();
  save ("f.png");

}


Morhaf Aljber

unread,
Aug 18, 2025, 8:35:14 PMAug 18
to cedric penard, basilisk-fr
Hi Cedric,

I think that you need to export your file as a *stl file from the meshlab.

take a look at this example: http://basilisk.fr/src/examples/distance.c.

Best regards,
Morhaf

cedric penard

unread,
Aug 20, 2025, 9:19:39 AMAug 20
to basilisk-fr
Hi Morhaf,
Thanks.
I found the problem :
My stl file has coordinates in EPSG:2154 coordinate system.
I had to translate the object in order to have the origin at the center.
For information I use this tool to do that :

Have a nice day
Cédric
Reply all
Reply to author
Forward
0 new messages