Author Topic: CHALLENGE: Block Elevations to Contours  (Read 1812 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 987
  • AKA Tim
Re: CHALLENGE: Block Elevations to Contours
« Reply #15 on: October 25, 2021, 04:04:27 PM »
@huiz: the intent was to end up with a command that would assign elevations from contours in an xref. The drawing was messy (twisted xrefs, etc) because I wanted to correctly work with messy drawings received from clients. Perhaps in the future I'll make more simple single pointed challenges.

@Daniel: I'll have to check out your code, looks like you got the gist of it! I'm curious to look at the delaunator code to see what speeded up the triangulation so much. Thanks for posting.

EDIT: Wow that second version is fast! Maybe I'll have to look at how to call C++ code from my .NET app..
« Last Edit: October 25, 2021, 04:17:09 PM by Atook »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #16 on: October 25, 2021, 06:16:12 PM »
Thereís a C# version https://github.com/nol1fe/delaunator-sharp
Not sure if itís the same behavior, the rest of my code should be easy to port to .net, I mean if what I have gives the correct behavior.
I donít know how to handle blocks that fall outside the TIN though.

Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #17 on: October 25, 2021, 08:45:36 PM »
I used the .net port in Acad and Bcad and its crazy fast too!
I've attached a solution. Delaunator is 2d, just save a container of the Zs to add back in.

Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #18 on: October 26, 2021, 12:14:00 AM »
Iíve ported everything except the command qualify. Some times for the race command in milliseconds. My C# is very rusty, so maybe someone can optimize it. Thereís still the issue of the edge cases that need to be solved.

C++ac = 21244
C#ac =   37463
C#bc =  36435
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #19 on: October 26, 2021, 05:41:27 AM »
Got the c++ version cooking, my C# still sucks,  I changed the method of finding the point on the triangle, seems it has much better accuracy ,
I need to do a QAULIFY command to test, but I did test with the C++ version

C++ac  =  6140ms
C#ac  =   16045ms
C#ac   = 14529ms
   
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #20 on: October 26, 2021, 08:49:21 AM »
Wrapped everything inside of parallel foreach, now the time is:
AcC# MgdTestAcad_04.dll = Total Time in Milliseconds = 2944;
BcC# MgdTestAcad_04.dll = Total Time in Milliseconds = 2862;

well need some sort of a unit test to make sure im not breaking stuff

« Last Edit: October 27, 2021, 08:17:54 AM by It's Alive! »
Retired

Atook

  • Swamp Rat
  • Posts: 987
  • AKA Tim
Re: CHALLENGE: Block Elevations to Contours
« Reply #21 on: October 26, 2021, 02:10:14 PM »
Daniel, thanks so much for posting and translating your solutions!

I've awarded you one of the 1st place ($400) prizes, which you kindly directed to be donated directly to the swamp.

Looking forward, if I run any future challenges, I'll work on breaking it down into single tasks to make participation easier.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9769
Re: CHALLENGE: Block Elevations to Contours
« Reply #22 on: October 26, 2021, 03:42:07 PM »
*shocked!* I'm speechless! Thank you very much you guys! We have this years bills for the swamp paid. Thank you, very much.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #23 on: October 27, 2021, 04:36:37 AM »
Moved function static pointInTriangle to a local function, which really helped. I think Iíve squeezed about all the performance out of it.

Race MgdTestBcad_06.dll, Total Time in Milliseconds = 1763

Iím not sure how nested XREFs store block transformations, Iíll look into this next, to easily handle drawings like QUALIFY.
Also, Iíll think of a way to catch these outside cases that are outside the TIN, maybe generate a convex hull and use the elevation of the nearest segment ..?..

edit, added method maketin, to create the triangles, for testing that the routine is correct

« Last Edit: October 27, 2021, 08:17:39 AM by It's Alive! »
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #24 on: October 27, 2021, 05:31:27 AM »
I don't think its correct now, testing, fixing
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #25 on: October 27, 2021, 07:15:43 AM »
I don't think its correct now, testing, fixing

whew, fixed it, projecting the point on to the triangle was wrong.. i'll post after more testing
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #26 on: October 27, 2021, 08:22:21 AM »
Fixed the projecting the point onto the triangle, so the math ďshouldĒ be correct.
Iíll work on the block transformations next, the interface should be, select the xref, select the blocks to move and letír rip. 
Retired

Atook

  • Swamp Rat
  • Posts: 987
  • AKA Tim
Re: CHALLENGE: Block Elevations to Contours
« Reply #27 on: October 27, 2021, 12:46:09 PM »
Also, Iíll think of a way to catch these outside cases that are outside the TIN, maybe generate a convex hull and use the elevation of the nearest segment ..?..

I was going to just interpolate the outside points to the nearest two points. My guess is the math works out close or equal to the convex hull approach..

Thanks for noodling into this Daniel, it's fun to watch you solve things way beyond my level.. :)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #28 on: October 27, 2021, 10:20:06 PM »
I have it running where, just select a polyline, select all the blocks to move and it will rip, the nested transformations seems correct on both race and qualify drawings.
But I found an issue. Drawing Civil base has extra geometry at a far different elevation, these polylines are included and screw up the math. So weíd need a way to filter.
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7160
  • AKA Daniel
Re: CHALLENGE: Block Elevations to Contours
« Reply #29 on: October 27, 2021, 10:47:02 PM »
This one should work on any drawing that has an xref that contains polylines.
the command are race and maketin.

race, select a polyline that's in the xref, window all the refs to move and press enter.

run race, then run maketin to verify the triangles are aligned, you can iterate the face vertexes in the properties panel.
Retired