[OpenSCAD] unit testing based on # of volumes

Revar Desmera revarbat at gmail.com
Wed May 8 19:06:42 EDT 2019


I believe the extra volume is that which is NOT bound by the part.  The perimeter of the part divides all space into 2 separate volumes.

- Revar


> On May 8, 2019, at 12:51 PM, Carsten Arnholm <arnholm at arnholm.org> wrote:
> 
> On 08.05.2019 19:01, AdrianSchlatter wrote:
>> My problem: OpenSCAD prints the number of volumes when run in GUI. I have
>> not found a way to make it print that info on cmd line. Any ideas?
> 
> The first problem seems to be that the number of volumes OpenSCAD prints is incorrect. For example
> 
> cubes.scad
> ---
> n=5;
> for(i=[1:n]) {
>  echo(i);
>  translate([i*20,0,0])cube(10);
> }
> ---
> 
> You get 5 echoes, but in the GUI console it says
> 
> Simple: yes
> Vertices: 40
> Halfedges: 120
> Edges: 60
> Halffacets: 60
> Facets: 30
> Volumes: 6
> Rendering finished.
> 
> So the number of volumes reported by OpenSCAD is off by one. Aside from that minor issue, you can use an external program to count the volumes in a machine-readable way if OpenSCAD can not do it.
> 
> Here is one way to do it:
> 
> Assuming the OS is Linux (similar for Windows), prepare 2 files in the same folder, a bash script and a minimal .as file.
> 
> Note that the term 'lump' below is equivalent to OpenSCAD 'volume'.
> 
> count_lumps.sh
> ---
> #!/bin/bash
> openscad -o temp_file.off $1
> as_csg ./count_lumps.as  > /dev/null
> xcsg --stl temp_file.xcsg | grep lump
> rm temp_file.*
> ---
> 
> count_lumps.as
> ---
> void main() {
>   polyhedron("temp_file.off").write_xcsg("temp_file");
> }
> ---
> 
> Run count_lumps.sh with OpenSCAD input
> 
> $ ./count_lumps.sh cubes.scad
> ECHO: 1
> ECHO: 2
> ECHO: 3
> ECHO: 4
> ECHO: 5
> ...result model contains 5 lumps.
> ...lump 1: 8 vertices, 12 polygon faces.
> ...lump 2: 8 vertices, 12 polygon faces.
> ...lump 3: 8 vertices, 12 polygon faces.
> ...lump 4: 8 vertices, 12 polygon faces.
> ...lump 5: 8 vertices, 12 polygon faces.
> 
> What happens in the script is
> 1. openscad generates .off file from .scad
> 2. as_csg converts .off to .xcsg (silently)
> 3. xcsg reads .xcsg and prints (filtered with grep here)
> 4. Temporary files are removed (silently)
> 
> If you skip piping to grep you get more detailed information. If you instead replace 'grep lump' with 'grep lumps' you get only the information you asked for:
> 
> ...result model contains 5 lumps.
> 
> as_csg and xcsg are installed with AngelCAD
> https://github.com/arnholm/angelcad/releases
> 
> Kind Regards
> Carsten Arnholm
> 
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org




More information about the Discuss mailing list