-
Notifications
You must be signed in to change notification settings - Fork 422
added Volume and Area to MeshMeasurements for simple requests #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dotnet8
Are you sure you want to change the base?
Conversation
|
this is quite old code you have copied from (the VolumeArea() function) and could be written much more concisely against DMesh3 directly...eg I think this is equivalent for the volume inner loop, maybe you could clean it up (and test that the output is unmodified)?: (and if it only actually needs N.x...) |
|
Thanks. I'll try this and test it. I was also thinking of upgrading it to lazy property on DMesh3, but backed off because I like the functional programming approach MeshMeasurements is using. Plus it felt more SOLID to modify MeshMEasurements than adding a complicated proeprty to DMesh3 |
|
Using this for a unit test. I don't see a test suite, so I didn't want to pollute the repo. All the tests pass. |
| Vector3d V2mV0 = v2 - v0; | ||
| Vector3d N = V1mV0.Cross(V2mV0); | ||
|
|
||
| mesh.GetTriVertices(tid, out Triangle3d tri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be more efficient to have the out reference Triangle3d tri declared before the for loop so it's not created in each loop?
Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
mesh.GetTriVerticies(tid, out tri);
....
| { | ||
| double mass_integral = 0.0; | ||
| double area_sum = 0; | ||
| foreach (int tid in mesh.TriangleIndices()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
mesh.GetTriVerticies(tid, out tri);
....
| double tmp0 = v0.x + v1.x; | ||
| double f1x = tmp0 + v2.x; | ||
| mass_integral += N.x * f1x; | ||
| mesh.GetTriVertices(tid, out Triangle3d tri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
mesh.GetTriVerticies(tid, out tri);
....
|
I am pretty sure it won't make a difference in optimized code, because in both cases the function will run the constructor internally. Conceivably this way involves a copy while 'out Triangle3D tri' might be fully RVO'd (but possibly the copy is optimized away too). But you would have to inspect the IL to find out, and I doubt there would be a difference in profiling. (personally I lean towards shorter code unless it really make a difference) If you want maximal performance then iterating from 0 to MaxTriID and checking if the tri is valid in the loop is usually faster than using the foreach/enumerable (but again hard to be certain it would matter w/o profiling in Release) |
Found getting volume and/or area to be a bit confusing at first. Added these methods to help less experienced users.
Wasn't abel to build for some reason, but this was a simple copy-and-paste.