Hit testing

I'm trying to implement client area hit testing in a MDI application. In my
document, I have a list of graphic objects (e.g. polygons) that are
displayed in the view. The list can get pretty long, so the hit test
algorithm needs to be fairly efficient.

My first attempt at this was to add HitTest(CPoint) function to the graphic
object class. In this function I created a Region and then tested it.
Something like...

int CPolygon::HitTest(CPoint Point)
{
        CRgn Rgn;
        Rgn.CreatePolygonRgn(PointList.GetData(), PointList.GetSize(),
WINDING);

        if (Rgn.PtInRegion(Point))
                return 1;
        else
                return 0;
}

This works but is EXTREMELY slow. I'm still working on clocking it, but it
seems like there is tremendous overhead in initializing the CRgn object.
Okay. So I tried adding a permanent CRgn member variable to the CPolygon
class that wouldbe initialized at the same time as the polygon (and
therefore would already exist during hit testing) but you can't modify the
CRgn object, only initialize it, which prevents me from modifying my
polygon.

I understand that CRgn encapsulates some GDI stuff, which probably explains
the overhead during initialization. I'd be happy to just create one, in the
CView::HitTest(CPoint) function for example, but since I can only initialize
it once, how do I use it to test all my graphic objects.

I assume there is a commonly used solution for this, but I don't know what
it is? And if there's a better strategy for hit testing, I'd be up for that
too.

Thanks for any help,
Chip


0
10/15/2003 2:49:10 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
646 Views

Similar Articles

[PageSpeed] 23

Chip Pulitzer wrote:

>I'm trying to implement client area hit testing in a MDI application. In my
>document, I have a list of graphic objects (e.g. polygons) that are
>displayed in the view. The list can get pretty long, so the hit test
>algorithm needs to be fairly efficient.
>
>My first attempt at this was to add HitTest(CPoint) function to the graphic
>object class. In this function I created a Region and then tested it.
>Something like...
>
>int CPolygon::HitTest(CPoint Point)
>{
>        CRgn Rgn;
>        Rgn.CreatePolygonRgn(PointList.GetData(), PointList.GetSize(),
>WINDING);
>
>        if (Rgn.PtInRegion(Point))
>                return 1;
>        else
>                return 0;
>}
>
>This works but is EXTREMELY slow. I'm still working on clocking it, but it
>seems like there is tremendous overhead in initializing the CRgn object.
>Okay. So I tried adding a permanent CRgn member variable to the CPolygon
>class that wouldbe initialized at the same time as the polygon (and
>therefore would already exist during hit testing) but you can't modify the
>CRgn object, only initialize it, which prevents me from modifying my
>polygon.
>
>I understand that CRgn encapsulates some GDI stuff, which probably explains
>the overhead during initialization. I'd be happy to just create one, in the
>CView::HitTest(CPoint) function for example, but since I can only initialize
>it once, how do I use it to test all my graphic objects.

You could say:

 rgn.DeleteObject();
 rgn.CreatePolygonRgn(...);

>I assume there is a commonly used solution for this, but I don't know what
>it is? And if there's a better strategy for hit testing, I'd be up for that
>too.

See the algorithm presented in this article:

http://support.microsoft.com/?kbid=121960

You can probably find multiple hit-testing algorithms for any geometric
object you can imagine.

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2499)
10/15/2003 4:30:28 PM
Excellent. Thanks, Doug.

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:kvsqovsao44og43e36e9h06g39h36k3qro@4ax.com...
> Chip Pulitzer wrote:
>
> >I'm trying to implement client area hit testing in a MDI application. In
my
> >document, I have a list of graphic objects (e.g. polygons) that are
> >displayed in the view. The list can get pretty long, so the hit test
> >algorithm needs to be fairly efficient.
> >
> >My first attempt at this was to add HitTest(CPoint) function to the
graphic
> >object class. In this function I created a Region and then tested it.
> >Something like...
> >
> >int CPolygon::HitTest(CPoint Point)
> >{
> >        CRgn Rgn;
> >        Rgn.CreatePolygonRgn(PointList.GetData(), PointList.GetSize(),
> >WINDING);
> >
> >        if (Rgn.PtInRegion(Point))
> >                return 1;
> >        else
> >                return 0;
> >}
> >
> >This works but is EXTREMELY slow. I'm still working on clocking it, but
it
> >seems like there is tremendous overhead in initializing the CRgn object.
> >Okay. So I tried adding a permanent CRgn member variable to the CPolygon
> >class that wouldbe initialized at the same time as the polygon (and
> >therefore would already exist during hit testing) but you can't modify
the
> >CRgn object, only initialize it, which prevents me from modifying my
> >polygon.
> >
> >I understand that CRgn encapsulates some GDI stuff, which probably
explains
> >the overhead during initialization. I'd be happy to just create one, in
the
> >CView::HitTest(CPoint) function for example, but since I can only
initialize
> >it once, how do I use it to test all my graphic objects.
>
> You could say:
>
>  rgn.DeleteObject();
>  rgn.CreatePolygonRgn(...);
>
> >I assume there is a commonly used solution for this, but I don't know
what
> >it is? And if there's a better strategy for hit testing, I'd be up for
that
> >too.
>
> See the algorithm presented in this article:
>
> http://support.microsoft.com/?kbid=121960
>
> You can probably find multiple hit-testing algorithms for any geometric
> object you can imagine.
>
> -- 
> Doug Harrison
> Microsoft MVP - Visual C++


0
10/15/2003 4:50:25 PM
Reply:

Similar Artilces:

Public Folder
I have a request I'm having trouble filling... Notes: - The idea is (and to stay) contained within our Exch Public Folder(s). - We have task and calendar objects in this location for the specified action described below. The goal: Assign a task and have it display for the user(s) in a calendar view. So far: - I've looked around at views of Tasks, nothing that comes close to a calendar layout. Is this an over-sight on my part? - I've tried making the new task object relate to the new calendar object, no luck. Is there something I pebcaked? - I know the SDK package ca...

Test post
Testing the filters to see if "ivory" is the word causing my posts to be filtered. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org It seems as if that word is not the issue, as your post is still visible. -- Stefan Blom Microsoft Word MVP "Suzanne S. Barnhill" <sbarnhill@mvps.org> wrote in message news:ODCEwqI5KHA.3292@TK2MSFTNGP06.phx.gbl... > Testing the filters to see if "ivory" is the word causing my posts to be > filtered. > > -- > Suzanne S. Barnh...

Frequency Plot
I am working on an assignment where we are given a bunch of data points representing medical tests taken to determine whether a person has a given disease. We have 200 test results (measuring some number from 1-50 which, at a certain cutoff value, indicates the disease is likely present): 100 for people who actually have the disease, and 100 for those who don't. Our mission is to plot the data in such a way as to evaluate the sensitivity and specificity of the test (accuracy, best cutoff point, etc.). What is the best way to plot this using Excel? G G wrote: > I am working...

Performance hit on sharing records
Hi, Can anybody tell me the performance hit on using sharing of records between teams? We are considering sharing of custom entities in terms of 10000s of records between 5-6 user teams. What would be the performance hit? Thanks, Hi, No it will not, if you are sharing with the teams, it's only 1 entry added to the principalobjectaccess table. It's not going to be a problem. I have client sharing to hundreds user with couple hundred thousands of records. Darren Liu Crowe http://www.crowecrm.com On Aug 7, 2:47 pm, sb <itssari...@gmail.com> wrote: > Hi, > Can anybody tell...

GP Certification Tests
We are a Microsoft Gold Partner, but we are NOT a Dynamics partner yet. In order to be a partner we have to pass the tests..... From reading in this community I see that there are manuals on partnersource to use to study for the tests, but you have to already be a partner to access them. How do you find the manuals to study for the exams if you are not a Dynamics partner yet? Cindy, I believe you should be able to download GP and all the manuals from MSDN. -- Victoria Yudin GP MVP "Cindy" <Cindy@discussions.microsoft.com> wrote in message news:48921BEB-9544-4E89-8...

test #16
test ...

How to test a dll
I was asked to maintain a dll and I couldn't find the app that is supposed to call this one to test. How can I test a dll written in VC++ 6.0? Thanks. Write a small app that calls the methods in the dll. AliR. <dbcuser@gmail.com> wrote in message news:1156887083.912973.62630@m79g2000cwm.googlegroups.com... > I was asked to maintain a dll and I couldn't find the app that is > supposed to call this one to test. How can I test a dll written in VC++ > 6.0? > Thanks. > http://www.codersource.net/mfc_dll_tutorial.html http://www.codeguru.com/cpp/cpp/cpp_mfc/tutor...

test #17
There are test newsgroups that do not impact newsgroup use. http://www.mvps.org/dmcritchie/excel/xlnews.htm#testposting Please use them to test. Or post your actual question here. "Oli North" <Onorth@sbc.com> wrote in message news:TANTe.77$QK2.55@trnddc03... > > ...

test
this is test news ...

Hit Counters on Every Page
I have a large web site hosted on http://www.freeservers.com They allow hit counters on every page - the stats being stored in one file - fpcount.js My site is over 10 years old, and many pages have hits in the thousands. However recently I've noticed that some counters have been reset to zero. I investigated and found that over the years the fpcount.js file has become corrupt. Although I pay Freeservers to host the site all enquiries to their Customer Service about the corruption of the hit counter feature are ignored. Therefore I am seeking a commensurate service. I have tried FP...

Moving Gmail Acct to Outlook? Passes Test but won't work Why/Fix?
I have followed the directions on the gmail page on moving my acct to outlook. It passes the test and yet does not work. What gives? How do I fix? Is this some weirdness between google and microsoft. Any suggestions? Help! Could you be a little more specific? What doesn't work? Does it send? Doesn't receive? Do you get any error messages? What version of Outlook? -- Aloha, -Ben- Ben M. Schorr, OneNote-MVP Roland Schorr & Tower http://www.rolandschorr.com Microsoft OneNote FAQ: http://www.factplace.com/onenotefaq.htm **I apologize but I am unable to respond to direct r...

Tests?
Why do so many individuals need to jump on someone who posts a test? A higher percentage than Ivory soap put a clear indicator in the Subject line it's a test message. Seems the least educated of us all could identify this to make the decision to go right on by, it's a test. But what happens is a deluge of messages are sent to criticize the individual who is trying to solve a problem. And many of the criticisms are "not on topic" (like the ng they're in has "and criticism" as part of the ng title. But what is allowed is the use of vomit vocabulary! Certainly...

Testing an Exchange backup
Hello everyone I have been backing up my Exchange database (SBS 2003) using an online backup with the NTBackup utility, and everything appears to be working fine: backup files created in the right place at the right time, and a log file saying that the backup was successful. However, I would like to make sure that the backup has worked by using it to restore data. My problem is I want to be absolutely sure that if everything goes wrong and I can't restore, that I won't lose any data. I wonder whether the following plan would work? 1. Dismount my databases. 2. Rename my priv1.e...

ANOVA procedures and t-test equal variance
In looking through Excel I see that it has both the ANOVA procedure and a t-test with equal variances and a t-test for unequal variances. One of the assumptions that is made in both the "standard t test" and ANOVA is that the variances are equal. Yet, Excel seems to have no test for homoscedasicity (oh what a cool word). How do you know these procedures are ok to use if you have not checked the assumption of equal variances? Noosa - > In looking through Excel I see that it has both the ANOVA procedure and a > t-test with equal variances and a t-test for unequal vari...

test of wizard
-- This posting is provided "AS IS" with no warranties, and confers no rights. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=f61980a5-9a9d-4399-8044-95f7dc1810...

Hit testing
I'm trying to implement client area hit testing in a MDI application. In my document, I have a list of graphic objects (e.g. polygons) that are displayed in the view. The list can get pretty long, so the hit test algorithm needs to be fairly efficient. My first attempt at this was to add HitTest(CPoint) function to the graphic object class. In this function I created a Region and then tested it. Something like... int CPolygon::HitTest(CPoint Point) { CRgn Rgn; Rgn.CreatePolygonRgn(PointList.GetData(), PointList.GetSize(), WINDING); if (Rgn.PtInRegion(Point)) ...

ignore -- testing
Haven't seen a posting in several NGs since 6/25. Just curious if GG is updating these NGs. I'm using the "old" user interface. Can't find these NGs using the new GG "experience". just testing "joeu2004" <joeu2004@hotmail.com> wrote in message news:812e733c-2d95-4174-8a3d-d08ecc672145@e17g2000prj.googlegroups.com... Haven't seen a posting in several NGs since 6/25. Just curious if GG is updating these NGs. I'm using the "old" user interface. Can't find these NGs using the new GG "experience". testing a...

Test on 1/14/2010 at 3.10 AM for the sync issue.
Test on 1/14/2010 at 3.10 AM for the sync issue. -- Ashawani Please use microsoft.public.test for doing your tests. -- Sylvain Lafontaine, ing. MVP - Windows Live Platform Blog/web site: http://coding-paparazzi.sylvainlafontaine.com Independent consultant and remote programming for Access and SQL-Server (French) "Ashawani_Dubey" <ashawani_dubey@hotmail.com> wrote in message news:BDBD85D0-56AA-495A-94F3-B0449BCA61A2@microsoft.com... > Test on 1/14/2010 at 3.10 AM for the sync issue. > -- > Ashawani > > > On Wed, 13 Jan ...

My window hangs after hitting the escape key .......
Hi, I have three classes derived from CFrameWnd, CDocument and CView respectively. I use the following code in a dialog button's handler to connect them and generate a window. My problem is that the window hangs after I hit the escape key. (It's ok if I hit alt-F4) The debugger shows it is stuck in COccManager::IsDialogMessageA() which is called by CDialog::PreTranslateMessage(). Do you have any solution? Thanks for your great help. Tony CMyDoc *pDoc = new CMyDoc; CMyFrame * pFrame = new CMyFrame(); pFrame->m_pDoc = pDoc; CCreateContext context; context.m_pNewViewCl...

IF NOT EXISTS and hit counter
I'm creating a web page hit counter sproc. I'm trying to prevent duplicate hits for the following: 1. If the session id is the same and web page name is the same. 2. If the session id is the same and web page name is "productdisplay.asp" and column "prodID" is the same. My below sproc is preventing duplicate entries for the special "productdisplay.asp" page when the "prodID" is the same. But it is allowing duplicate "mypage.htm" pages to be logged. The special "productdisplay.asp" page is the product display p...

test if a logical statement and use the answer within an if statem
How can I use the Find function within an array formula to check a column to locate evey occurence of a string and subsequently sum the corresponding numbers in a different column Something like this: =SUMPRODUCT(--(ISNUMBER(FIND("MyString",A2:A100))),B2:B100) or the non-case sensitive version: =SUMPRODUCT(--(ISNUMBER(SEARCH("MyString",A2:A100))),B2:B100) -- Best Regards, Luke M "BG Mark" <BGMark@discussions.microsoft.com> wrote in message news:767C1228-9339-46AA-8CDD-CD7A48489BB4@microsoft.com... > How can I use the Find functi...

testing news server
passed! ~Alan wrote: -- Dave Peterson ec35720@msn.com ...

Just a test 04-06-10
Just a quick test ... ...

Test Message
...

Stats- Mann Whitney Test
Is there a way of calculating the Mann whitney test in excel? alicemedic - http://www.lmgtfy.com/?q=Excel+Mann+Whitney - Mike http://www.MikeMiddleton.com "alicemedic" <alicemedic@discussions.microsoft.com> wrote in message news:5C2398AB-EB3B-44E5-ADE5-E1477B18C945@microsoft.com... > Is there a way of calculating the Mann whitney test in excel? ...