TBC Macros and Extensions

View Only

what's the best way to test if an object is inside a rotated viewport Limitbox

• 1.  what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-03-2024 05:33

I mean a rotated limit box that you use inside a 3D view, that limits i.e. a point cloud.

I need to improve my ExplodeIFC macro. I've got Geotech rock IFC objects with millions of triangles. Exploding one of the big ones did created 3.5 million linestrings which did result in literally hour long loading of TBC. So, my solution is to just create linework where I really need it.

I do know the Trimble.Vce.Geometry.Limits3D. That one has a method IsPointInside, but that one is square to Easting/Northing and doesn't support 3D rotation.

I'd need the transformation matrix from the Limitbox to world coordinate system.

The Limitbox only provides the centerpoint and 3 rotations. I've been playing around with Matrix4D.BuildTransformMatrix but for some reason it only works if I rotate the Limitbox just around 1 axis. As soon as I use the BiVector with multiple rotations the result is off. Not a lot but slightly.

``````limitbox = self.currentProject.Concordance.Lookup(activeForm.View.LimitBoxSerial)

spinor = Spinor3D(BiVector3D(-limitbox.RotateX, -limitbox.RotateY, -limitbox.RotateZ))

transtotestlimit = Matrix4D.BuildTransformMatrix(Vector3D(limitbox.Origin), Vector3D(0.0,0.0,0.0), spinor, Vector3D(1.0,1.0,1.0))

l1 = Point3D(-limitbox.Length/2, -limitbox.Width/2, -limitbox.Height/2) + limitbox.Origin
l2 = Point3D(limitbox.Length/2, limitbox.Width/2, limitbox.Height/2) + limitbox.Origin

testlimit = Limits3D(l1, l2)

if testlimit.IsPointInside(transtotestlimit.TransformPoint(vertice1), True)[0] or \
testlimit.IsPointInside(transtotestlimit.TransformPoint(vertice2), True)[0]:

``````

just one rotation works fine

multiple rotations result in a slight rotation difference

------------------------------
Ronny Schneider
------------------------------

• 2.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-04-2024 07:16

Hi Ronny,

good to see you back in the group ! ;-)

I haven´t done anything with limit boxes yet, however not sure if something like the link below could help in case you have access to the needed information to geometrically define the cube corresponding to the 3D limit box (as I say, I don´t know yet if you can access to this data yet through the sdk):

How to determine a point is inside or outside a cube?

Stack Overflow remove preview
apple-touch-icon@2.png?v=73d79a89bded" width="200" height="200">  How to determine a point is inside or outside a cube? Given a cube with 8 vertex in 3D space. How could I determine the myPoint is inside or outside the cube? cube[0] = (x0, y0, z0); cube[1] = (x1, y1, z1); cube[2] = (x2, y2, z2); cube[3] = (x3, y3, ... View this on Stack Overflow >

.

Good luck !

Regards,

Fernando

------------------------------
Fernando Calvo
calvo@calvo-geospatial.com
------------------------------

• 3.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-05-2024 04:24
Thanks Fernando,

yes I'm back at work, Down Under again. Upgrading an existing water reservoir dam.

Thanks for the link. Something like that, programming it all myself would be the last resort. My hope was that it wouldn't be necessary.

And I'm trying to do something similar. I try to create a transformation from the Limitbox' coordinate system into a coordinate system that is square to Easting/Northing/Z which the Limit3D is using. Once I have that Matrix4D I can transform any point by the difference between those two systems. And then I can just use the Limit3D method IsPointInside.

As I mentioned, it works perfectly if I only use one rotation, around any axis, in the BiVector3D. But as soon as I use more than one rotation it starts to drift off.
With a super complicate approach I've got it meanwhile to a point where it works when using x and y axis only, as soon as I add z its off.
I just found out what the issue is and really wanna kick some butt. Bl**** h***.
In the Limitbox settings the rotation for x and y follows the local "moving" axis. The z rotation follows the world z!!!!! Why??????????????????????????? (({..}))

That simple idea did turn into quite a waste of time again. I knew the Limit3D.IsPointInside from before and I was expecting the Limitbox to have a similar method. Next problem was that the Limitbox doesn't provide a transform matrix. Biggest issue the unique, to say the least, usage of the rotations in the Limitbox.

Still my current solution is super complicate. Taking some axis definition points (1,0,0 and 0,1,0) and rotate them step by step around each axis. Once that's done I can use Spinor3D.ComputeRotation to setup the transformation matrix between the Limitbox and a standard Limit3D.
I wonder how the Limitbox computes what should be visible on screen and what is being clipped. It can't possibly go that complicate way.

------------------------------
Ronny Schneider
------------------------------

• 4.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-05-2024 08:33

Hi Ronny,

It sounds like you're making your way through it (painfully). My understanding of the integration with how we calculate/create the limit box is the following (definitely not my area of expertise).

1.) Assemble the Matrix4d (using scale (l,w,h), rotate y, rotate x, rotate z, and then translate on origin)
2.) Generate 6 clips of planes for the cube, finding the Plane Origin and Global Origin (+/- .5 on axis, Zero Vector) from the assembled matrix, and then determining the Plane's Normal (Normalized Plane - Origin)
3.) From there, we create a new Plane3d, using the plane normal, and the plane origin

4.) Retrieve the general form equation values from the plane (ax + by + cz + d = 0).

This value is used by the visualizer to insert the cutting planes hiding/showing objects in the project.

I hope this helps some in the understanding of how this is being done.

------------------------------
Bryce Haire
------------------------------

• 5.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-05-2024 17:06

Hello Bryce,

I'm so glad to see that we finally have somebody from Trimble checking the forum regularly and giving us some proper insight.

Your explanation sounds understandable. I assume the visualizer then uses Plane3D.SideOfPoint on all six planes to determine if a point is inside or outside of the box. It must be Side.Back on all of them to be inside the box.

But how does the visualizer get the data handed over from the Limitbox, does it use PopulateGraphicsCache?

Is it possible to retrieve that data, like the plane definitions or the Matrix4D.

The main issue for using the Limitbox for anything else than the visualizer is that it doesn't provide much information, only the dimensions of the box, the origin and the 3 rotations.

If it could simply provide a Matrix4D everything would be so much easier. Thanks to your help I found now how to recreate that matrix on my own, but it's rather cumbersome. Plus, the mixed usage of the rotations is anything else than intuitive or standard. For me that appears like a bug that the Z rotation follows the world Z and not the Limitbox Z.

Need to perform some code cleanup now, looks like a mess from all the experimenting.

------------------------------
Ronny Schneider
------------------------------

• 6.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-08-2024 07:24
Edited by Bryce Haire 04-08-2024 09:18

Hey Ronny,

Your explanation sounds understandable. I assume the visualizer then uses Plane3D.SideOfPoint on all six planes to determine if a point is inside or outside of the box. It must be Side.Back on all of them to be inside the box.

- I'm fairly confident HOOPS just keeps track of everything themselves. TBC from my understanding doesn't actually explicit track the visibility of the objects in the project, we simply allow that to be done at the graphics level. So basically assemble the sides of the cutting planes, and hand it off from there to the graphics/visualizer to show/hide objects.

But how does the visualizer get the data handed over from the Limitbox, does it use PopulateGraphicsCache?
- Yes, we go through during the PopulateGraphicsCache to assemble the LimitBox

Is it possible to retrieve that data, like the plane definitions or the Matrix4D.

- Writing an enhancement to add support for retrieving this information from the LimitBox.

The main issue for using the Limitbox for anything else than the visualizer is that it doesn't provide much information, only the dimensions of the box, the origin and the 3 rotations.
- Yeah, not totally sure the LimitBox is tool that many thought of as usage outside of TBC current needs. There are bits of information (like the fact we only support a single limitbox) that make me think we got the functionality we required and moved to other areas.

Glad I could help some. I'll see if we can get in any of the changes before the next TBC release. Sorry for all your troubles doing this lol :)

------------------------------
Bryce Haire
------------------------------

• 7.  RE: what's the best way to test if an object is inside a rotated viewport Limitbox

Posted 04-04-2024 09:37

Hi Ronny,

Looking at our implementation of Limit Box rotation, TBC does an X rotation of the Limit Box, followed by the Y rotation, followed by the Z rotation.

As you have demonstrated, this is not the same as a rotation that does the X ,Y, Z changes within the same rotation.

I'm guessing if we added support for the Limit Box to do this type of rotation, that would allow you to do what you are looking for?

Bryce

------------------------------
Bryce Haire
------------------------------