Just can't get GetPixelInfoPoint to work :-(



  • On 17/06/2014 at 12:53, xxxxxxxx wrote:

    It is not too much, Scott :-)
    Thank you very much.
    I'm eager to sift through it. But, damn!!! I have to go and have dinner now.
    And today is my wife's birthday.
    I guess I will only be able to deal with this later or tomorrow.



  • On 17/06/2014 at 15:09, xxxxxxxx wrote:

    Scott, I was able to use your code almost exactly as it is, without changes.
    But, ViewportPixel *pPixel = vps->GetPixelInfoPoint(i, j); always returns NULL :-(



  • On 17/06/2014 at 15:26, xxxxxxxx wrote:

    That's strange.
    I'm getting the object, and the object's point index#s from it just fine in R13.

        //Loop through the pixels in the screen in a matrix like fashion  
      //By getting the pixels using Rows & Columns using 2 for loops  
      for (LONG i = x1; i <= x2; i++)  
      {  
          for (LONG j = y1; j <= y2; j++)  
          {  
              Real rSqrDist = (i - mouseX)*(i - mouseX) + (j - mouseY)*(j - mouseY);  
              if (rSqrDist > radSqr) continue;  
      
              //Get the point of an object in the scene at this screen pixel location  
              ViewportPixel *pPixel = vps->GetPixelInfoPoint(i, j);  
              while (pPixel)  
              {  
                  //If the point found belongs to our desired target object  
                  if (pPixel->op == obj)  
                  {  
                      GePrint(pPixel->op->GetName());    //Prints the name of the object we're selecting points on  
                      GePrint(LongToString(pPixel->i));  //Prints the point's index#  
      
                      //This code will select the points on the object if they're within the radius range  
                      BaseSelect *bs = obj->GetPointS();  
                      bs->Select(pPixel->i);  
                  }  
                  pPixel = pPixel->next;  
              }  
          }  
      }
    

    I don't know why it's returning Null for you.
    If you want the plugin to play around with. Tell me where to e-mail it and I'll send it to you.

    -ScottA



  • On 17/06/2014 at 15:41, xxxxxxxx wrote:

    It is a real mystery :-(
    Well, I'm using R14 but it should work fine anyway.
    If you can, please send it over to: rui_mac@ruimac.com
    I'm on a Mac, remember?
    Thank you in advance.



  • On 17/06/2014 at 16:10, xxxxxxxx wrote:

    Oh yeah. I forgot you're on a Mac.
    Having the actual plugin won't help you any more than the code I posted.

    Have you looked at the "sculpting.cpp" example in the SDK examples?
    That one uses the GetPixelInfoPoint() function in it too.

    -ScottA



  • On 17/06/2014 at 16:17, xxxxxxxx wrote:

    Yes, I looked into it.
    And using the methods that are used there, I still get Null in the vps->GetPixelInfoPoint(x, y)



  • On 17/06/2014 at 18:02, xxxxxxxx wrote:

    I just can't figure out why is this happening :-(

      
    (...)   
    for (LONG i = x1; i <= x2; i++)   
    {   
        for (LONG j = y1; j <= y2; j++)   
        {   
            Real rSqrDist = (i - mouseX)*(i - mouseX) + (j - mouseY)*(j - mouseY);   
            if (rSqrDist > radSqr) continue;   
                      
            ViewportPixel *pPixel = vps->GetPixelInfoPoint(i, j);   
      
    // the code works fine until here. At this point, pPixel is NULL   
      
            while (pPixel)   
            {   
                if (pPixel->op == obj)   
                {   
             GePrint(LongToString(pPixel->i));   
                }   
            pPixel = pPixel->next;   
            }   
        }   
    }   
    (...)
    


  • On 18/06/2014 at 04:52, xxxxxxxx wrote:

    I tried it with python and it works fine. I just can't make it work with C++
    This is driving me crazy!!! :-(



  • On 18/06/2014 at 05:49, xxxxxxxx wrote:

    Howdy,

    Have you looked at ViewportPixel::GetNearestPoint()?

    That function may be easier to use because it has a radius parameter:

    ViewportPixel *vp = vps->GetNearestPoint(op,x,y,rad);
    

    Adios,
    Cactus Dan



  • On 18/06/2014 at 06:49, xxxxxxxx wrote:

    Even with GetNearestPoint I still get vp==NULL :-(



  • On 18/06/2014 at 07:46, xxxxxxxx wrote:

    Howdy,

    Try this sample code:

    #include "c4d.h"
    #include "c4d_symbols.h"
    #include "lib_collider.h"
      
    class TestTool : public ToolData
    {
    private:
    	Real mx, my;
    	Bool mDrag;
    	
    public:
    	virtual TOOLDRAW Draw(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, BaseDrawHelp* bh, BaseThread* bt, TOOLDRAWFLAGS flags);
    	virtual Bool MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg);
    };
      
    TOOLDRAW TestTool::Draw(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, BaseDrawHelp* bh, BaseThread* bt, TOOLDRAWFLAGS flags)
    {
    	BaseObject	*op = doc->GetActiveObject(); if(!op) return TOOLDRAW_0;
    	if(!(op->IsInstanceOf(Opoint) && ToPoint(op)->GetPointR())) return TOOLDRAW_0;
    	
    	Real rad = 10.0;
    	if(mDrag)
    	{
    		bd->SetPen(Vector(0,0,0));
    		bd->DrawCircle2D(LONG(mx),LONG(my),rad);
    	}
      
    	return TOOLDRAW_HANDLES|TOOLDRAW_AXIS|TOOLDRAW_HIGHLIGHTS;
    }
      
    Bool TestTool::MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd,EditorWindow *win, const BaseContainer &msg)
    {
    	BaseObject	*op = doc->GetActiveObject(); if(!op) return false;
    	if(!(op->IsInstanceOf(Opoint) && ToPoint(op)->GetPointR())) return false;
    		
    	mx = msg.GetReal(BFM_INPUT_X);
    	my = msg.GetReal(BFM_INPUT_Y);
    	LONG button;
    	
    	switch (msg.GetLong(BFM_INPUT_CHANNEL))
    	{
    		case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break;
    		case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break;
    		default: return TRUE;
    	}
    	
    	Real rad = 10.0;
    	Bool vOnly = true;
    	
    	AutoAlloc<ViewportSelect> vps; if(!vps) return false;
    	
    	LONG left, top, right, bottom, width, height;
    	bd->GetFrame(&left, &top, &right, &bottom);
    	width = right - left + 1;
    	height = bottom - top + 1;
    	
    	vps->Init(width,height,bd,op,Mpoints,vOnly,VIEWPORTSELECTFLAGS_USE_HN|VIEWPORTSELECTFLAGS_USE_DEFORMERS);
    	vps->SetBrushRadius(rad);
      
    	Real dx, dy;
    	mDrag = false;
    	BaseContainer bc, device;
    	win->MouseDragStart(button,mx,my,MOUSEDRAGFLAGS_DONTHIDEMOUSE|MOUSEDRAGFLAGS_NOMOVE);
    	while (win->MouseDrag(&dx,&dy,&device)==MOUSEDRAGRESULT_CONTINUE)
    	{
    		mx+=dx;
    		my+=dy;
    		mDrag = true;
    		LONG x = mx, y = my;
    		
    		ViewportPixel *vp = vps->GetNearestPoint(op,x,y,rad);
    		if(vp)
    		{
    			GePrint(LongToString(vp->i));
    		}
    		DrawViews(DRAWFLAGS_INDRAG|DRAWFLAGS_NO_REDUCTION|DRAWFLAGS_ONLY_ACTIVE_VIEW|DRAWFLAGS_NO_THREAD|DRAWFLAGS_NO_ANIMATION);
    	}
    	mDrag = false;
    	EventAdd(EVENT_FORCEREDRAW);
      
    	return TRUE;
    }
      
    #define ID_TOOLDATA_TEST		1000007
      
    Bool RegisterTestTool(void)
    {
    	return RegisterToolPlugin(ID_TOOLDATA_TEST,"Test Tool",0,AutoBitmap("Test.tif"),"Test Tool",gNew TestTool);
    }
    

    Adios,
    Cactus Dan



  • On 18/06/2014 at 08:37, xxxxxxxx wrote:

    I replaced all my code with your code and added the following:

    (...)
    ViewportPixel *vp = vps1->GetNearestPoint(op,x,y,rad);
    if(vp)
    {
         GePrint(LongToString(vp->i));
    }
    else
    {
         GePrint("vp is NULL");
    }
    (...)

    And all I got, as I dragged the cursor was "vp is NULL" in the Console :-(



  • On 18/06/2014 at 09:11, xxxxxxxx wrote:

    Howdy,

    OK, I added the line:

    else GePrint("vp is NULL");
    

    ... and it only prints that when the mouse is not over a point of the object and within the radius.

    Adios,
    Cactus Dan



  • On 18/06/2014 at 09:24, xxxxxxxx wrote:

    If the code works in Python. Then It's not a code problem.

    The simplest way to check it is to put this in the sculpting.cpp file's while loop: GePrint(pPixel->op->GetName());
    If this returns NULL and not the name of the object. Then there's got to be something wrong with your SDK installation.

    -ScottA



  • On 18/06/2014 at 09:33, xxxxxxxx wrote:

    So, why the hell is it not working for me?!?
    Would you guys be willing to check out my code?
    It is not much longer than the one posted above by Scott ;-)



  • On 18/06/2014 at 09:38, xxxxxxxx wrote:

    Howdy,

    Hehe, at this point that may be your only option. If you want to keep your code confidential, feel free to pm or email it to one of us.

    Adios,
    Cactus Dan



  • On 18/06/2014 at 09:38, xxxxxxxx wrote:

    Scott, I did what you said and the sculpt tool works fine and prints out the name of the object.



  • On 18/06/2014 at 09:44, xxxxxxxx wrote:

    Well, I will send it through pm just because I don't want to show my lame code to everyone ;-)
    Thank you very much in advance.



  • On 18/06/2014 at 09:50, xxxxxxxx wrote:

    I just sent you a PM with my code, Dan.
    I will only send it to Scott if he says it is OK to do so.
    Thank you very much in advance to both of you.



  • On 18/06/2014 at 10:29, xxxxxxxx wrote:

    If Dan's willing to help you out. There's no need to send it to me Rui.
    He can probably help you better than I can.
    Plus, he's a Mac user. So you can send files to each other. And I can't do that.

    -ScottA


Log in to reply