Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi Everyone!

I´m working in an aerial mapping application which tries to determine what part of the terrain is viewed from an aerial camera. First I have rendered DEM (Digital Elevation Model) from existing .tif file, generating all the triangles of the mesh by .tif positions and values. I found a solution using RayMeshGeometry3DHitTestResult, and sending different rays from the camera. The problem is that performance is very low because the hit test needs to be repeated thousands of times and it becomes too slow:


private static RayMeshGeometry3DHitTestResult rayHit;
       public static RayMeshGeometry3DHitTestResult SurfaceRayHit(Point3D p, Vector3D v)
       {
           RayHitTestParameters hitParams = new RayHitTestParameters(p,v);
           VisualTreeHelper.HitTest(App.AppDemModel, null, new HitTestResultCallback(MainDemHitPoint), hitParams);
           return rayHit;
       }

       public static HitTestResultBehavior MainDemHitPoint(HitTestResult result)
       {

           if (result.VisualHit == App.AppDemModel)
           {
               rayHit = (RayMeshGeometry3DHitTestResult)result;
               //rList.Add(hit);
               return HitTestResultBehavior.Stop;
           }


           return HitTestResultBehavior.Continue;
       }


What I have tried:

I think it must be internally implemented by ViewPort3D (HelixViewport in my case) since lights are hitting only certain triangles in a Geometry3D, but I couldn´t find a way to obtain the list of triangles(Vertices) affected by light.

Thanks in advance, any help will be really apreciated.
Posted
Updated 8-Feb-18 12:54pm

1 solution

There are tons of research papers written on this topic or relatives of it and there are several tactics used. One of the most common is subdividing the mesh and checking each division. Generally this is done by dividing the mesh in quarters and doing a hit check on each quarter and then for the sections hit, repeat the process which means dividing each of them in quarters and testing each of those.

Another way is to determine the area being viewed by camera first instead of the ray tracing method. Then you can just check if triangles are in that region. Subdivision can be used also. It might be easier to check the mesh in its quadrilateral form, if you keep that data around.

If you use distance checking by computing the magnitude of a vector one easy performance optimization you can do there is don't compute the square root because it is usually a slow operation. You can compare the square of the magnitude (without the square root) and get the same results quicker. Only take the square root when you need the actual distance and for comparison purposes you do not need it.
 
Share this answer
 
Comments
Member 11733943 9-Feb-18 8:05am    
Thanks a lot Rick! I think the camera contents approach is the better one, the problem is, how can I get the triangles shown in a camera? I also think that something related with light hit should be interesting as well since there must be some information (internal) that represents the triangles where the light is shown, removing directly the ones thar are hidden.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900