Author Topic: PointMonitor troubles  (Read 8273 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
PointMonitor troubles
« on: August 03, 2014, 01:27:18 PM »
I have a command, for use in Civil3D, which utilizes the PointMonitor event to track whether the cursor is within a certain area of a corridor. A corridor can be made of one to many 'regions', at the onset of the command I loop through all of these regions and create a collection of Polylines and the C3D BaselineRegion objects. The polylines I create from the calculated boundaries of each of these BaselineRegions in order to use in a TransietGraphicsDisplay to give the user a visual indicator that they are within one of the corridor regions. (This mimics the native C3D selection process.)

All of that is working just dandy, as long as there are less than 10, or so, regions. As the number of regions increase, the cursor begins to slow to a crawl across the screen, finally unable to keep up and will jump around. What I'm asking here, I guess, is there a better way of going about this? I'm sure there must be, because doing the same thing with the native C3D commands is instantaneous & smooth.

Here's a snippet of what I'm using. Not showing how I acquire the Polylines, but that portion of code is plenty quick. Also, I use the Brep (BoundaryRepresention) methods to get the IsPointInside value.
Code - C#: [Select]
  1.        private void corridorPointMonitor(object sender, PointMonitorEventArgs e)
  2.         {
  3.             Point3d curpt = e.Context.RawPoint;
  4.  
  5.             foreach (KeyValuePair<Polyline, BaselineRegion> pair in regions)
  6.             {                
  7.                 if(pair.Key.IsPointInside(curpt))
  8.                 {
  9.                     foundRegion = pair.Key;
  10.                     if (previousRegion == null)
  11.                         previousRegion = foundRegion;
  12.                     else if (previousRegion == foundRegion)
  13.                         break;
  14.                     else
  15.                         previousRegion = foundRegion;
  16.                     foundBLRegion = pair.Value;
  17.                     HighlightRegion(pair.Key);
  18.                     break;
  19.                 }
  20.                 else
  21.                 {
  22.                     ClearMarkers();
  23.                     foundRegion = null;
  24.                     previousRegion = null;
  25.                     foundBLRegion = null;
  26.                 }
  27.             }
  28.  
  29.         }
  30.  
  31.         private void HighlightRegion(Polyline region)
  32.         {
  33.             ClearMarkers();          
  34.             region.ColorIndex = 5;
  35.             aGi.TransientManager.CurrentTransientManager.AddTransient(region, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
  36.             markers.Add(region);
  37.         }
  38.  

BlackBox

  • King Gator
  • Posts: 3770
Re: PointMonitor troubles
« Reply #1 on: August 03, 2014, 05:12:50 PM »
Perhaps instead of repeatedly determining which Polyline is to be highlighted, etc you instead highlight all from onset, and simply disable visibility of those not to be highlighted.

Also, curious to know if LINQ's OrderBy() Method would be of any help here?
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #2 on: August 03, 2014, 06:36:21 PM »
The polylines are not database resident, just temporary objects to use to determine if the cursor is within them and to pass to the TransientGraphics to display the boundary of a region. I just tested this using Linq, commenting out the code to display the transientgraphics, and it is still very sluggish. (Tested with the temp graphics, too, to insure it is getting the correct region.)
Code - C#: [Select]
  1.         private void corridorPointMonitor(object sender, PointMonitorEventArgs e)
  2.         {
  3.             Point3d curpt = e.Context.RawPoint;
  4.             KeyValuePair<Polyline, BaselineRegion> pair = regions.FirstOrDefault(region => region.Key.IsPointInside(curpt));
  5.             if (pair.Key != null)
  6.             {
  7.                 foundRegion = pair.Key;
  8.                 foundBLRegion = pair.Value;
  9.                 //HighlightRegion(pair.Key);
  10.             }
  11.             else
  12.             {
  13.                 //ClearMarkers();
  14.                 foundRegion = null;
  15.                 foundBLRegion = null;
  16.             }
  17.         }
  18.  
So all I can figure now is that my extension method IsPointInside is where the bottleneck is.

LE3

  • Guest
Re: PointMonitor troubles
« Reply #3 on: August 03, 2014, 06:50:39 PM »
I just tried some old code, and the same issue appears to happen when I have 2300+ closed polylines, (what it is the sysvar to turn off the automatic highlight that autocad does? maybe this has something todo no idea)

Code - C#: [Select]
  1.         private static void OnPointMonitor(object sender, PointMonitorEventArgs e)
  2.         {
  3.             var doc = AcadApp.DocumentManager.MdiActiveDocument;
  4.             _pPoly.Unhighlight();
  5.             _objTrackedPt = e.Context.RawPoint;
  6.             if (!VisCursor(_objTrackedPt)) return;
  7.             //using (doc.LockDocument())
  8.             //{
  9.                 using (var transaction = doc.TransactionManager.StartTransaction())
  10.                 {
  11.                     foreach (ObjectId id in ClosedPolys)
  12.                     {
  13.                         if (IsPointInside(_objTrackedPt, id))
  14.                         {
  15.                             _pPoly = transaction.GetObject(id, OpenMode.ForRead, false) as Polyline;
  16.                             if (_pPoly != null)
  17.                             {
  18.                                 _pPoly.Highlight();
  19.                                 var area = Converter.DistanceToString(_pPoly.Area);
  20.                                 e.AppendToolTipText(string.Format("Area: {0}\nSomething here: \nSomething more: \nAnd at the bottom: ", area));
  21.                             }
  22.                             break;
  23.                         }
  24.                         _pPoly.Unhighlight();
  25.                     }
  26.                     transaction.Commit();
  27.                 }
  28.             //}
  29.         }
  30.  
« Last Edit: August 03, 2014, 06:57:56 PM by LE »

Chumplybum

  • Newt
  • Posts: 97
Re: PointMonitor troubles
« Reply #4 on: August 03, 2014, 07:05:19 PM »
Not sure if this is the one, but PREVIEWFILTER 'excludes specified objects from selection previewing'... if you go to options, then the selection tab, and hover over the various options a tooltip shows up and this usually has the associated variable name. You might want to take a look at the SELECTIONPREVIEWLIMIT variable also

Cheers, Mark

LE3

  • Guest
Re: PointMonitor troubles
« Reply #5 on: August 03, 2014, 08:13:55 PM »
I think it will required the use of a KD-Tree or something similar...

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #6 on: August 03, 2014, 09:43:16 PM »
I think it will required the use of a KD-Tree or something similar...
I think you are right, Luis. Unfortunately, this is something I've tried to learn before and failed miserably...this old brain just struggles trying to comprehend it. I will, however, take another stab at it since the wife is away for a week. Perhaps the quietness around here will be conducive to learning.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #7 on: August 03, 2014, 10:09:19 PM »
Here's a Screencast showing how it is supposed to work, and then how mine does work, oh, so, slowly:

LE3

  • Guest
Re: PointMonitor troubles
« Reply #8 on: August 04, 2014, 09:56:47 AM »
I think it will required the use of a KD-Tree or something similar...
I think you are right, Luis. Unfortunately, this is something I've tried to learn before and failed miserably...this old brain just struggles trying to comprehend it. I will, however, take another stab at it since the wife is away for a week. Perhaps the quietness around here will be conducive to learning.

Yes, I recall seeing this in the past, and I end up using a kd-tree class but on a custom object (closedPolygon's) in arx by implementing an input point filter derived from AcEdInputPointFilter.

There is a kd-tree here at theswamp by Paul Kohut in C++ and I guess one by Gile (in C#) if I recall....


LE3

  • Guest
Re: PointMonitor troubles
« Reply #9 on: August 04, 2014, 11:54:03 AM »
Hi Jeff,
Try something like this (I got the chance to tested here on my lunch break and appears to work).

Add a variable for your class to hold the ids of your regions and the geo center point of the region.
Code - C#: [Select]
  1. public static Dictionary<ObjectId, Point3d> IdsAndPoints = new Dictionary<ObjectId, Point3d>();
  2.  


Here it is what I use to calculate the geo center
Code - C#: [Select]
  1.                     using (var transaction = db.TransactionManager.StartTransaction())
  2.                     {
  3.                         foreach (var id in ids)
  4.                         {
  5.                             var polyline = transaction.GetObject(id, OpenMode.ForRead, false) as Polyline;
  6.                             if (polyline == null || !polyline.Closed) continue;
  7.                             var extent = polyline.GeometricExtents;
  8.                             var minPoint = extent.MinPoint;
  9.                             var maxPoint = extent.MaxPoint;
  10.                             var vector = maxPoint - minPoint;
  11.                             var geoCenter = minPoint + vector / 2;
  12.                             IdsAndPoints.Add(id, geoCenter);
  13.                         }
  14.                         transaction.Commit();
  15.                     }
  16.  

Then add a new method to calculate the distance to the points
Code - C#: [Select]
  1.         private static double DistanceFromEachPoint(Point3d source, Point3d target)
  2.         {
  3.             return Math.Pow(target.X - source.X, 2) + Math.Pow(target.Y - source.Y, 2);
  4.         }
  5.  

Then on your point monitor event, add something like this (I did my test using 40 polylines to do the search around the point monitor tracked point, all the polylines in the drawing are 2300+ - all the command line works and also there is no speed down at all)
Code - C#: [Select]
  1.         private static void OnPointMonitor(object sender, PointMonitorEventArgs e)
  2.         {
  3.             var doc = AcadApp.DocumentManager.MdiActiveDocument;
  4.             _pPoly.Unhighlight();
  5.             _objTrackedPt = e.Context.ComputedPoint;
  6.             if (!VisCursor(_objTrackedPt)) return;
  7.             try
  8.             {
  9.                 using (var transaction = doc.TransactionManager.StartTransaction())
  10.                 {
  11.                     try
  12.                     {
  13.                         const int count = 40;
  14.                         var pairs =
  15.                             IdsAndPoints.Where(point => point.Value != _objTrackedPt)
  16.                                         .OrderBy(point => DistanceFromEachPoint(_objTrackedPt, point.Value))
  17.                                         .Take(count);
  18.                         foreach (var pair in pairs)
  19.                         {
  20.                             if (IsPointInside(_objTrackedPt, pair.Key))
  21.                             {
  22.                                 _pPoly = transaction.GetObject(pair.Key, OpenMode.ForRead, false) as Polyline;
  23.                                 if (_pPoly != null)
  24.                                 {
  25.                                     _pPoly.Highlight();
  26.                                     break;
  27.                                 }
  28.                             }
  29.                             else
  30.                             {
  31.                                 if (_pPoly != null)
  32.                                 {
  33.                                     _pPoly.Unhighlight();
  34.                                 }
  35.                             }
  36.                         }
  37.                         transaction.Commit();
  38.                     }
  39.                     finally
  40.                     {
  41.                         transaction.Dispose();
  42.                     }
  43.                 }
  44.             }
  45.             catch{}
  46.         }
  47.  

HTH
« Last Edit: August 04, 2014, 12:17:00 PM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #10 on: August 04, 2014, 02:00:49 PM »
Thanks, Luis! I'll give this a try tonight, or possibly during lunch.

LE3

  • Guest
Re: PointMonitor troubles
« Reply #11 on: August 04, 2014, 11:12:06 PM »
Thanks, Luis! I'll give this a try tonight, or possibly during lunch.

Also, you can try using parallelism, tested here and runs better.- just add the AsParallel extension for better performance.
Code - C#: [Select]
  1. var pairs =
  2.                     IdsAndPoints.AsParallel().Where(point => point.Value != _trackedPoint)
  3.                                 .OrderBy(point => DistanceFromEachPoint(_trackedPoint, point.Value))
  4.                                 .Take(countOfItemsOnSearch);
  5.  
« Last Edit: August 04, 2014, 11:15:43 PM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #12 on: August 04, 2014, 11:25:59 PM »
After some testing, head banging, testing, breaking things, testing some more, struggling to find out why some Linq methods are refusing to work, etc., I have found that this does help but is not quite working as needed...yet.

First, the Linq issue. using the .Take(count) as LE showed, never returned a Dictionary with a Count > 0. Commenting out the Take then returned all of the regions, in the OrderedBy format, items. In order to use the GeoCenter point and still pass both the Polyline and BaselineRegion objects in the Dictionary, I created a Class to hold those 2 objects. Perhaps the use of a Class object is causing this?

The next Linq issue is similar, in that I tried using this: var pair = pairs.FirstOrDefault(region => region.Value.polyline.IsPointInside(curpt));
which also never returns anything but an empty object.

Finally, after working through those issues and getting code which actually gets me a good KeyValuePair with the Polyline in which the cursor is located, it doesn't always get the one it is in. Due to the funky shaped nature of a Corridor and the regions that comprise it, sometimes the cursor may be close to 10 of the calculated Center points but none of those are the one linked to the polyline the cursor is actually in. Increasing the number of items in the Dictionary to loop through increases the chances of this always working, but also begins to impact the performance again. It is also still a bit slow when the cursor is not within any of the regions.

Since I am seeing a speed improvement with this approach, I think that going with the KD-Tree approach will likewise increase the performance. Off to try to figure out how to implement that.

gile

  • Gator
  • Posts: 2512
  • Marseille, France
Re: PointMonitor troubles
« Reply #13 on: August 05, 2014, 01:32:00 AM »
Hi Jeff,

If you're going with the Kd tree route, you can perhaps get some inspiration from this thread (the last C# version of Point3dTree in reply #26)
Speaking English as a French Frog

LE3

  • Guest
Re: PointMonitor troubles
« Reply #14 on: August 05, 2014, 09:01:01 AM »
That's strange.

Can you upload a test drawing with those funky shapes?

The OrderBy and Take will do the same or similar as in the Kd-Tree do the arrangement of points based on distances (neighbor's) and Take as the search radius.


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #15 on: August 05, 2014, 09:51:33 AM »
Thanks, gile, nice code! I just wish I could understand how it can help with this particular task.

Luis, I'll get a drawing for you later today. Must get ready for work and head to the office now.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #16 on: August 05, 2014, 10:41:14 AM »
Here is a drawing created from the extracted polylines which define the boundaries of the Corridor Regions. As you can see there are not all that many (107) polylines, but they vary greatly in size and shape.

LE3

  • Guest
Re: PointMonitor troubles
« Reply #17 on: August 05, 2014, 11:20:23 AM »
I just tested and yes, it blinks the cursor, I was able to highlight some of the areas, but some not. Also, noticed that these areas are made of tons of points, so guess we need a more efficient is inside point method and a form to do a better arrangement of closed areas and points to use. This goes more into the use of a kd-tree -- on my closed polygon custom object, that can have internal loops and big areas that form the object, maybe like these entities, where the user can pass the cursor and each of these areas that form the closed polygon are highlighted (via a solid hatch, and different color depending on the type of area)... anyway if I can will give it a try later today -- but at least we know what works or not.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: PointMonitor troubles
« Reply #18 on: August 05, 2014, 12:21:46 PM »
Maybe I am not understanding but are looping through all the polylines to see if you are inside one, and are all of these polylines closed?

If so...
Could you use a combination of GetPickedEntities(to see entities are being hovered over) and Raw Point?
-Use GetPickedEntities to see when your mouse moves over a polyline
-check to see if next point is inside that one polyline
-If inside store id of polyline and highlight then check GetPickedEntities for id o see if next point mouse moved out or stayed inside.


Maybe one way to see if they are using same or similar approach is to sling mouse as fast as possible to see if you can find hiccups where they are getting optimizations?

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #19 on: August 05, 2014, 12:58:39 PM »
Yes, Jeff, until Luis suggested his approach at minimizing the number of polylines to loop through. And yes, they are all closed polylines. But the GetPickedEntities won't work because the polylines are not Database resident, they are merely temporary objects created for the sole use in the TransientGraphics display

LE3

  • Guest
Re: PointMonitor troubles
« Reply #20 on: August 05, 2014, 05:04:54 PM »
See if this works, I tested here and all runs fine.

I changed the IsPointInside with the use of Brep:
Code - C#: [Select]
  1.         public static Boolean IsPointInside(Point3d internalPoint, ObjectId objid)
  2.         {
  3.             using (var transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  4.             {
  5.                 var polyline = transaction.GetObject(objid, OpenMode.ForRead, false) as Polyline;
  6.                 if (polyline != null)
  7.                 {
  8.                     var curves = new DBObjectCollection { polyline };
  9.                     using (var regions = Region.CreateFromCurves(curves))
  10.                     {
  11.                         if (regions != null && regions.Count == 1)
  12.                         {
  13.                             var region = regions.Cast<Region>().First();
  14.                             using (region)
  15.                             {
  16.                                 using (var brep = new Brep(region))
  17.                                 {
  18.                                     PointContainment ptContainment;
  19.                                     using (brep.GetPointContainment(internalPoint, out ptContainment))
  20.                                     {
  21.                                         return ptContainment == PointContainment.Inside ||
  22.                                                ptContainment == PointContainment.OnBoundary;
  23.                                     }
  24.                                 }
  25.                             }
  26.                         }
  27.                     }
  28.                 }
  29.                 transaction.Commit();
  30.             }
  31.             return false;
  32.         }
  33.  

And with this new method, I can do the highlight of any of the areas on your drawing Jeff.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PointMonitor troubles
« Reply #21 on: August 05, 2014, 05:11:28 PM »
Interesting usage of using statements Luis.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #22 on: August 05, 2014, 05:33:36 PM »
Luis, that is essentially identical code to what I was using when I started this thread. And was what I have determined to be the bottleneck. I created an extension method for regions thusly:
Code - C#: [Select]
  1.         public static bool IsPointInside(this Region region, Point3d pt)
  2.         {
  3.             bool retval = false;
  4.             PointContainment contain= PointContainment.Outside;
  5.             using (Brep brep = new Brep(region))
  6.             {
  7.                 if(brep!=null)
  8.                 {
  9.                     using(BrepEntity ent = brep.GetPointContainment(pt, out contain))
  10.                     {
  11.                         if (ent is Autodesk.AutoCAD.BoundaryRepresentation.Face)
  12.                         {
  13.                             retval = true;
  14.                         }
  15.                     }
  16.                 }
  17.             }
  18.             return retval;
  19.         }
  20.  
and another extension method to convert the polylines to regions:
Code - C#: [Select]
  1.         public static bool IsPointInside(this Curve crv, Point3d pt)
  2.         {
  3.             bool retval = false;
  4.             using (DBObjectCollection objCol = new DBObjectCollection())
  5.             {
  6.                 objCol.Add(crv);
  7.                 using (DBObjectCollection dbObjColl = Region.CreateFromCurves(objCol))
  8.                 {
  9.                     using (Region region = dbObjColl.Cast<Region>().First())
  10.                     {
  11.                         retval = region.IsPointInside(pt);
  12.                     }
  13.                 }
  14.             }
  15.             return retval;
  16.         }
  17.  

I've now tested with the old "cast a Ray and if it crosses the pline an odd # of times then the point lies inside the polygon" method and it is working quickly and only throws a hiccup about 0.2% of the time (I think this is when the ray passes through a single point on one of the other polylines). But this is every bit as fast as the native 3D selection process.

But now I'm confused as to why your implementation of the same code I was using is working ok for you, yet it was dreadfully slow for me.

LE3

  • Guest
Re: PointMonitor troubles
« Reply #23 on: August 05, 2014, 05:46:34 PM »
I tried also with the faces array and got some bad issues, so end up avoiding that approach, so that's why I jumped into the region point containment, I think Tony posted something some time ago here and also on the devblog of autodesk there are some sample usage of this too.

I think that could be a good idea if I post the whole solution on show your stuff section (is there now url link on one of my post after this one below...).
« Last Edit: August 05, 2014, 06:10:14 PM by LE »

LE3

  • Guest
Re: PointMonitor troubles
« Reply #24 on: August 05, 2014, 05:50:52 PM »
Interesting usage of using statements Luis.
Thanks, Kerry --- end up adding all of them, since the check for null did not work et-al --- this is a good exercise to go back into doing something for an autocad command :)

LE3

  • Guest
Re: PointMonitor troubles
« Reply #25 on: August 05, 2014, 06:09:11 PM »
Hi Jeff,
End up placing my whole class for this test here:

http://www.theswamp.org/index.php?topic=18383.msg525131#msg525131

Let me know if works.

Thanks,
Luis.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #26 on: August 05, 2014, 06:17:05 PM »
Luis, before I test yours I decided to go back and retest mine, replacing the bit of code where I checked for the Face object with the bool IsInside || Onboundary. It now is running quickly as well. So that one check for the Face seems to be where the slowdown occurred (I got that part of the code from one of Tony's posts here.)

Thanks for all the help on this, LE, really appreciate it!

LE3

  • Guest
Re: PointMonitor troubles
« Reply #27 on: August 05, 2014, 06:19:43 PM »
Luis, before I test yours I decided to go back and retest mine, replacing the bit of code where I checked for the Face object with the bool IsInside || Onboundary. It now is running quickly as well. So that one check for the Face seems to be where the slowdown occurred (I got that part of the code from one of Tony's posts here.)

Thanks for all the help on this, LE, really appreciate it!

That's good news, glad at least I was of some help my friend... Have fun !

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #28 on: August 06, 2014, 12:34:36 PM »
Well, after all of that, I still never got this working properly/quickly with my application. Something about using Brep just slows it down too much. I finally located an algorithm to check if a point is inside an array of points (i.e. a closed polyline) over at the CodeProject which is short, concise, and fast. This has sure been a learning experience for me, though. I've modified the code to suit my code by accepting a Point2dCollection and to return a bool:
Code - C#: [Select]
  1.         public static bool IsPointInside(this Polyline poly, Point2d testpt, Point2dCollection verts)
  2.         {
  3.             if (!poly.Closed)
  4.             {
  5.                 throw new System.ArgumentException("Polyline must be closed!");
  6.             }
  7.             int i, j = 0;
  8.             bool c = false;
  9.             int nvert = verts.Count;
  10.             double testx = testpt.X, testy = testpt.Y;
  11.             for (i = 0, j = nvert - 1; i < nvert; j = i++)
  12.             {
  13.                 double vertx = verts[i].X, verty = verts[i].Y;
  14.                 double prevx = verts[j].X, prevy = verts[j].Y;
  15.                 if (((verty > testy) != ( prevy> testy)) &&
  16.                  (testx < (prevx - vertx) * (testy - verty) / (prevy - verty) + vertx))
  17.                     c = !c;
  18.             }
  19.             return c;
  20.         }
  21.  

LE3

  • Guest
Re: PointMonitor troubles
« Reply #29 on: August 06, 2014, 01:16:55 PM »
^ that does not looks like takes into account curvatures, but at least you have something that works now - good.

To bad, there is no (at least that I am aware) avail the AcDbMPolygon wrapper in .NET ? with this you could avoid the use of Brep at all and work with these temp geometry objects...

In example from one of my arx stuff.... that could it be easy to port to c#.....
Code - C++: [Select]
  1. inline Location IsPointInEzone(AcGePoint3d p, AcDbPolyline *pPoly)
  2. {
  3.         double fuzz = AcGeContext::gTol.equalPoint();
  4.         AcGePoint3d pointOnCurve;
  5.         pPoly->getClosestPointTo(p, pointOnCurve);
  6.         if (p.distanceTo(pointOnCurve) <= fuzz) return On;
  7.         AcDbMPolygon mpol;
  8.         if (pPoly)
  9.         {
  10.                 if (mpol.appendLoopFromBoundary(pPoly, false) != Acad::eOk) return Error;
  11.         }
  12.         else
  13.                 return Error; // invalid entity
  14.         AcGeIntArray ar;
  15.         if (mpol.isPointInsideMPolygon(p, ar) > 0) return Inside;
  16.         else return Outside;
  17. }
  18.  

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: PointMonitor troubles
« Reply #30 on: August 06, 2014, 01:22:36 PM »
Correct, doesn't account for curves. But for what I'm using it for, all polylines will be straight segments only. I will need to make a comment in my code to that effect, though, in case I ever do need one to work with arcs as well.

n.yuan

  • Bull Frog
  • Posts: 348
Re: PointMonitor troubles
« Reply #31 on: August 06, 2014, 04:55:09 PM »
Yes, there is AcDbMPolygon .NET wrapper: "AcMPolygonMGD.dll" in Acad installation folder.

LE3

  • Guest
Re: PointMonitor troubles
« Reply #32 on: August 06, 2014, 04:58:39 PM »
Yes, there is AcDbMPolygon .NET wrapper: "AcMPolygonMGD.dll" in Acad installation folder.

doh!... I see is avail on my realdwg 2014 folder structure -- cool - thanks! n.yuan