unit testing based on # of volumes

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

unit testing based on # of volumes

AdrianSchlatter
I‘m looking for a way to render a .scad file and get the number of rendered
volumes in a machine-readable way - i.e. on the cmdline. Purpose: unit
testing. I‘m creating a library of threads (hundreds) and want to verify
that nuts and bolts are created as exactly one part each, and that a bolt
does not collide with its mating nut. Idea: render nut + bolt. Check number
of volumes:

1: what the Heck?!
2: collision
3: ok
>=4: Something is detached (e.g. thread not attached to bolt)

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?

Best regards, Adrian



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

cacb
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

RevarBat
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 <[hidden email]> 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
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

RevarBat
In reply to this post by AdrianSchlatter
Have you tried adding `--render` to the command-line?

- Revar


> On May 8, 2019, at 10:01 AM, AdrianSchlatter <[hidden email]> wrote:
>
> I‘m looking for a way to render a .scad file and get the number of rendered
> volumes in a machine-readable way - i.e. on the cmdline. Purpose: unit
> testing. I‘m creating a library of threads (hundreds) and want to verify
> that nuts and bolts are created as exactly one part each, and that a bolt
> does not collide with its mating nut. Idea: render nut + bolt. Check number
> of volumes:
>
> 1: what the Heck?!
> 2: collision
> 3: ok
>> =4: Something is detached (e.g. thread not attached to bolt)
>
> 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?
>
> Best regards, Adrian
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

AdrianSchlatter
Yep, tried that. OpenSCAD remains silent.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

AdrianSchlatter
In reply to this post by cacb
Carsten,

Sounds good to me, thanks for the help. Can I compile AngelCAD on MacOS?
Linux is ok for CI server, of course, but it would be nice to run the tests
locally as well.

Best regards,
Adrian



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

cacb
On 09.05.2019 20:53, AdrianSchlatter wrote:
> Carsten,
>
> Sounds good to me, thanks for the help. Can I compile AngelCAD on MacOS?
> Linux is ok for CI server, of course, but it would be nice to run the tests
> locally as well.

I don't see anything in principle for it not to work, but I have no
particular interest in or experience with MacOS, so I have done 'only'
Windows and Linux. It is possible on the Mac with some dedication, but
it would be a new os port. All the tools & components are available I think.

Alternatively install a virtual machine with Ubuntu on the Mac, or
simply get OpenSCAD to report to the console :-)

Regards
Carsten Arnholm




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

nophead
In reply to this post by AdrianSchlatter
The code that prints the volumes is part of the GUI so it doesn't happen when running without a GUI. It is here:  https://github.com/openscad/openscad/blob/master/src/mainwin.cc#L2276

I don't think it would be a big job to move it to openscad.cc and call it from mainwin.cc. Perhaps  a command line option to enable it as most people probably don't want the extra noise.

On Thu, 9 May 2019 at 19:54, AdrianSchlatter <[hidden email]> wrote:
Carsten,

Sounds good to me, thanks for the help. Can I compile AngelCAD on MacOS?
Linux is ok for CI server, of course, but it would be nice to run the tests
locally as well.

Best regards,
Adrian



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

thehans
In reply to this post by RevarBat
Yep.  The inside of your geometries define one volume each, and infinite void outside the geometry is the other volume.  That's just how CGAL represents volumes.  In other words, "It's not a bug, its a feature" ;)

Hans

On Wed, May 8, 2019 at 6:07 PM Revar Desmera <[hidden email]> wrote:
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 <[hidden email]> 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
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

AdrianSchlatter
In reply to this post by nophead
That clearly means it cannot be done with today’s openscad. It can be done by
changing openscad (as you outlined) or by using third party tools (as
outlined by Carsten). If this would be an urgent problem, I’d go for
Carsten’s AngelCAD. It’s not urgent, therefore I’ll avoid that extra
dependency for now.

Am I the only one interested in that feature? Or is this a use case others
have as well? Should the suggested command line option provide additional
information to be more useful for unit testing?

Regards, Adrian


nophead wrote
> The code that prints the volumes is part of the GUI so it doesn't happen
> when running without a GUI. It is here:
> https://github.com/openscad/openscad/blob/master/src/mainwin.cc#L2276
>
> I don't think it would be a big job to move it to openscad.cc and call it
> from mainwin.cc. Perhaps  a command line option to enable it as most
> people
> probably don't want the extra noise.





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: unit testing based on # of volumes

nophead
I am not sure how useful it is for unit testing as it is a very crude measure of correctness. The OpenSCAD automatic tests generate images or STL files, etc and compare them with what is expected.

On Tue, 14 May 2019 at 20:46, AdrianSchlatter <[hidden email]> wrote:
That clearly means it cannot be done with today’s openscad. It can be done by
changing openscad (as you outlined) or by using third party tools (as
outlined by Carsten). If this would be an urgent problem, I’d go for
Carsten’s AngelCAD. It’s not urgent, therefore I’ll avoid that extra
dependency for now.

Am I the only one interested in that feature? Or is this a use case others
have as well? Should the suggested command line option provide additional
information to be more useful for unit testing?

Regards, Adrian


nophead wrote
> The code that prints the volumes is part of the GUI so it doesn't happen
> when running without a GUI. It is here:
> https://github.com/openscad/openscad/blob/master/src/mainwin.cc#L2276
>
> I don't think it would be a big job to move it to openscad.cc and call it
> from mainwin.cc. Perhaps  a command line option to enable it as most
> people
> probably don't want the extra noise.





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org