Polygon Selection

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/11/2009 at 10:25, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   11 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hello,

I would like to be able to automatically select specific polygons and then hide those polygons.   Could someone help me get started doing this.

I am sure i need to use BaseSelect.. just not sure how.

Thanks,

~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/11/2009 at 14:11, xxxxxxxx wrote:

You should use a PolygonSelection tag (Tpolygonselection). Or you could store them in a BaseSelect and use the Hide Selected command (in the Selection menu) but this may not work well - especially if the user does otherwise. If you don't mind the tag, I'd go that way myself.

For the PolygonSelection tag, you would get its BaseSelect and do your selection on it. Then you can send a command message:

// Emulate the Hide Polygons button on the PolygonSelection tag
DescriptionCommand dc;
dc.id = POLYGONSELECTIONTAG_COMMAND5;
pstag->Message(MSG_DESCRIPTION_COMMAND, dc);

(see tpolygonselection.res in Resource/res/description)

If you go with a direct BaseSelect then you'll need to copy this selection to the polygon selection and call the Selection->Hide Selected command using CallCommand();

BaseSelect* bs = polyObj->GetPolygonS();
if (!bs) return FALSE;
// Apply your selected polygons to the selection state on the polygon object
yourBS->CopyTo(bs);
polyObj->Message(MSG_UPDATE);
// Hide Selected
CallCommand(12473L);

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/11/2009 at 20:37, xxxxxxxx wrote:

Here's what I have so far.. for some reason, the SendModelingCommand(MCOMMAND_HIDESELECTED, mdat); is not working..

However, when in C4D, if I manually hide those selections and then uncheck the box, it unhides them like it is supposed to.

Any thoughts on as to why the first SMC is not doing what it is supposed to?

  
  
Bool TrueSymmetry::HideSide(BaseObject* obj, BaseContainer* data)   
{   
     GePrint("HideSideFunction");   
  
     PolygonObject* objPoly;   
     objPoly=(PolygonObject* )obj;   
     if (!objPoly->IsInstanceOf(Opolygon))   
          return false;   
  
     ModelingCommandData mdat;   
  
     BaseSelect *selected = objPoly->GetPolygonS();   
     if (!selected) return FALSE;   
  
     BaseDocument * doc=obj->GetDocument();   
        
     LONG lngI=0;   
     LONG lngPolygonCount=objPoly->GetPolygonCount();   
     LONG lngSymPlane = data->GetReal(SYMMETRY_PLANE);   
     LONG lngMirroredSide = data->GetReal(MIRRORED_SIDE);   
  
     Vector * arrPoints=objPoly->GetPointW();   
     CPolygon * arrPolygons=objPoly->GetPolygonW();   
     CPolygon * hiddenPolygons=objPoly->GetPolygonW();   
        
     mdat.mode = MODIFY_ALL;   
     mdat.doc = doc;   
     mdat.bc = data;   
     mdat.op = objPoly;   
        
     if (data->GetBool(HIDE_SIDE))   
  
     {   
          GePrint("SELECTED");   
             
          selected->DeselectAll();   
     for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                  
                       
                    selected->Select(lngI);   
  
                    GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    GePrint("Polys selected =" + LongToString(selected->GetCount()));   
                       
               }   
          }   
  
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
          return TRUE;   
     }   
     else   
     {   
          GePrint ("NOT SELECTED");   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          selected->DeselectAll();   
          return TRUE;   
     }   
}   
  
  

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/11/2009 at 22:24, xxxxxxxx wrote:

Try this. Note that MODIFY_ALL will do all despite the selection. MODIFY_POLYGONSELECTION works on the currently selected polygons and MODIFY_POINTSELECTION works on the currently selected points. As you surmized, MCOMMAND_UNHIDE works on all of what is set (polygon, point, or edge selection according to mdat.mode).

Bool TrueSymmetry::HideSide(BaseObject* obj, BaseContainer* data)   
{   
     GePrint("HideSideFunction");   
     if (!obj->IsInstanceOf(Opolygon))   
          return false;   
     PolygonObject* objPoly =     ToPoly(obj);   
  
     BaseSelect* selected = objPoly->GetPolygonS();   
     if (!selected) return FALSE;   
     BaseDocument* doc =     objPoly->GetDocument();   
  
     LONG lngI=0;   
     LONG lngPolygonCount = objPoly->GetPolygonCount();   
     LONG lngSymPlane = data->GetReal(SYMMETRY_PLANE);   
     LONG lngMirroredSide = data->GetReal(MIRRORED_SIDE);   
  
     Vector* arrPoints = objPoly->GetPointW();   
     CPolygon* arrPolygons = objPoly->GetPolygonW();   
     if (!(arrPoints && arrPolygons))     return FALSE;   
     CPolygon* hiddenPolygons = arrPolygons;   
  
     ModelingCommandData mdat;   
     mdat.mode = MODIFY_POLYGONSELECTION;   
     mdat.doc =     doc;   
     mdat.op =     objPoly;   
     if (data->GetBool(HIDE_SIDE))   
     {   
          GePrint("SELECTED");   
          selected->DeselectAll();   
          for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                    selected->Select(lngI);   
                    GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    GePrint("Polys selected =" + LongToString(selected->GetCount()));   
               }   
          }   
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
     }   
     else   
     {   
          GePrint ("NOT SELECTED");   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          selected->DeselectAll();   
     }   
     return TRUE;   
}

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 16/11/2009 at 15:58, xxxxxxxx wrote:

Thanks for your reply Robert.

I have successfully created a function that hides one side of the object.. the problem I am having is that I would like to store any current selection that exists and return that selection when the user shows the hidden side again. The reason I want this to happen is that I do not want users to even be aware that a selection was made to hide half of the model. Here's what I have so far:

  
  
PolygonObject* objPoly;   
     objPoly=(PolygonObject* )obj;   
     if (!objPoly->IsInstanceOf(Opolygon))   
          return false;   
  
     ModelingCommandData mdat;   
  
     BaseSelect *selected = objPoly->GetPolygonS();   
     if (!selected) return FALSE;   
  
     BaseSelect *currentSel = objPoly->GetPolygonS();   
     if (!currentSel) return FALSE;   
        
     BaseDocument * doc=obj->GetDocument();   
        
     LONG lngI=0, lngJ=0, lngK=0, lngL=0;   
  
     LONG lngPolygonCount=objPoly->GetPolygonCount();   
     LONG lngSymPlane = data->GetReal(SYMMETRY_PLANE);   
     LONG lngMirroredSide = data->GetReal(MIRRORED_SIDE);   
  
        
     LONG lngSize=sizeof(LONG)*lngPolygonCount;   
     LONG * selectionIndex;   
     selectionIndex = (LONG* )GeAlloc(lngSize);   
  
     Vector * arrPoints=objPoly->GetPointW();   
     CPolygon * arrPolygons=objPoly->GetPolygonW();   
     CPolygon * hiddenPolygons=objPoly->GetPolygonW();   
        
     mdat.mode = MODIFY_POLYGONSELECTION;   
     mdat.doc = doc;   
     mdat.bc = data;   
     mdat.op = objPoly;   
        
     // Find currently selected polygons.   
     for (lngJ=0; lngJ<lngPolygonCount; lngJ++)   
     {   
          if (currentSel->IsSelected(lngJ))   
          {   
               selectionIndex[lngK]= lngJ;   
               GePrint("selectionIndex[" + LongToString(lngK) + "] =" + LongToString(lngJ));   
  
               lngK++;   
          }   
          else   
          {   
               return TRUE;   
          }   
     }   
  
  
     if (data->GetBool(HIDE_SIDE) && data->GetLong(SIDE_HIDDEN)==HIDE_A)   
     {   
          //Check to see which polys will be hidden   
          selected->DeselectAll();   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                    selected->Select(lngI);   
                    //GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    //GePrint("Polys selected =" + LongToString(selected->GetCount()));        
               }   
          }   
  
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
          return TRUE;   
     }   
  
     else if (data->GetBool(HIDE_SIDE) && data->GetLong(SIDE_HIDDEN)==HIDE_B)   
     {   
  
          //Check to see which polys will be hidden   
          selected->DeselectAll();   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (!PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                    selected->Select(lngI);   
                    //GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    //GePrint("Polys selected =" + LongToString(selected->GetCount()));        
               }   
          }   
  
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
          return TRUE;   
     }   
  
     else   
     {   
          //GePrint("i = " + LongToString(i));   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          selected->DeselectAll();   
          for (lngL=0;lngL<lngK; lngL++)   
          {   
          currentSel->Select(selectionIndex[lngL]);   
          GePrint("Selecting Polygon: " + LongToString(selectionIndex[lngL]));   
          }   
  
          return TRUE;   
     }   
  
  
  

as you can see below the      // Find currently selected polygons.

I search through all of the polygons and determine which ones are selected, then at the bottom when the UNHIDE is enabled,

I attempt to recreate the selection that was stored. For some reason, lngK is coming out 0. I think that this is because the function is called from the Message() and is called again after the new selection is hidden and thus no polygons are selected. I think this is why lngK keeps returning 0..   but I can't figure out how to get around this.

I know that was a mouthful but can anyone please help me. 🙂

Thanks
~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 16/11/2009 at 22:18, xxxxxxxx wrote:

This line:

LONG* selectionIndex = (LONG* )GeAlloc(lngSize);

That is your problem. You'll need to store the selection as a class member so that it stays around. Right now, you might notice your memory quickly filling up (unless you are calling GeFree(selectionIndex) somewhere at the end of that function).

Instead of doing that, you could simply use a BaseSelect* as a class member and copy the currentSel to it and use it to restore currentSel. This way you don't have to allocate/deallocate a LONG* array and just allocate the BaseSelect in Init() (or similar) and deallocate in Free() (or similar).

// To back up the current selection
// - I'd only do this if you are hiding
currentSel->CopyTo(backupSel);

...

// To restore the selection
backupSel->CopyTo(currentSel);

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/11/2009 at 05:21, xxxxxxxx wrote:

So are saying not to use LONG selectionIndex[] at all?

just to use the currentSel? how would you do this? can you show me a snippet of code?

Because when you use currenSel->Select()   it wants a LONG the in the Select();    LOL I am confused.

Thanks,

~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/11/2009 at 08:05, xxxxxxxx wrote:

The only problem you may need to consider is when switching from side A to B or vice versa wherein you'll get the incorrect backup polygon selection. In this case, you may want to track whether the side is being switched to retain the original backed up polygon selection.

class MyClass : SomeData   
{   
     BaseSelect*     backupSel;   
     Bool          backupSet;   
};   
  
Init()   
{   
     ...   
     backupSel =     BaseSelect::Alloc();   
     if (!backupSel)     return FALSE;   
     backupSet = FALSE;   
     ...   
}   
Free()   
{   
     ...   
     BaseSelect::Free(backupSel);   
     ...   
}   
HideUnhide()   
{   
     ...   
     PolygonObject* objPoly = (PolygonObject* )obj;   
     if (!objPoly->IsInstanceOf(Opolygon))     return false;   
     BaseSelect* selected = objPoly->GetPolygonS();   
     if (!selected) return FALSE;   
     BaseSelect* currentSel = objPoly->GetPolygonS();   
     if (!currentSel) return FALSE;   
     BaseDocument* doc = obj->GetDocument();   
     LONG lngI=0, lngJ=0, lngK=0, lngL=0;   
     LONG lngPolygonCount=objPoly->GetPolygonCount();   
     LONG lngSymPlane = data->GetReal(SYMMETRY_PLANE);   
     LONG lngMirroredSide = data->GetReal(MIRRORED_SIDE);   
     LONG lngSize=sizeof(LONG)*lngPolygonCount;   
     Vector * arrPoints=objPoly->GetPointW();   
     CPolygon * arrPolygons=objPoly->GetPolygonW();   
     CPolygon * hiddenPolygons=objPoly->GetPolygonW();   
  
     ModelingCommandData mdat;   
     mdat.mode = MODIFY_POLYGONSELECTION;   
     mdat.doc = doc;   
     mdat.bc = data;   
     mdat.op = objPoly;   
     if (data->GetBool(HIDE_SIDE) && data->GetLong(SIDE_HIDDEN)==HIDE_A)   
     {   
          // Save current polygon selection   
          currentSel->CopyTo(backupSel);   
          backupSet =     TRUE;   
  
          //Check to see which polys will be hidden   
          selected->DeselectAll();   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                    selected->Select(lngI);   
                    //GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    //GePrint("Polys selected =" + LongToString(selected->GetCount()));        
               }   
          }   
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
          return TRUE;   
     }   
     else if (data->GetBool(HIDE_SIDE) && data->GetLong(SIDE_HIDDEN)==HIDE_B)   
     {   
          // Save current polygon selection   
          currentSel->CopyTo(backupSel);   
          backupSet =     TRUE;   
  
          //Check to see which polys will be hidden   
          selected->DeselectAll();   
          SendModelingCommand(MCOMMAND_UNHIDE, mdat);   
          for (lngI=0;lngI<lngPolygonCount;lngI++)   
          {   
               if (!PolyOnEditableSide(arrPoints, arrPolygons, lngI, lngSymPlane, lngMirroredSide, lngOldPointCount, lngOldPolygonCount))   
               {   
                    selected->Select(lngI);   
                    //GePrint("Polygon " + LongToString(lngI) + " was selected.");   
                    //GePrint("Polys selected =" + LongToString(selected->GetCount()));        
               }   
          }   
          SendModelingCommand(MCOMMAND_HIDESELECTED, mdat);   
          return TRUE;   
     }   
     else if (backupSet)   
     {   
          // Restore previous polygon selection   
          backupSel->CopyTo(currentSel);   
          backupSet =     FALSE;   
          return TRUE;   
     }   
     ...   
     return TRUE;   
}

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/11/2009 at 11:06, xxxxxxxx wrote:

Great.. thank you very much this solved my problem,.   I will definitely need to track like you said because the original selection is removed when switching from A-B when the hide is enabled.

Thanks again!

~Shawn