Combine 2 Polygon Selections into one.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/03/2003 at 21:46, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.012
Platform: Windows ;
Language(s) : C++ ;---------
So far, the best approach that I can think of is to get each Array from the SelectionTags' BaseSelects and combine them into a buffer large enough for both then use FromArray to set that (into the first - the first being used as a collector for any duplicates), but it doesn't seem to be working:if (stag->GetName() == stag2->GetName()) { BaseSelect* bSelect1 = stag->GetBaseSelect(); BaseSelect* bSelect2 = stag2->GetBaseSelect(); if ((bSelect1 == NULL) || (bSelect2 == NULL)) throw ErrorException(ERROR_MODELINGCOMMAND, "Combine Selections"); LONG count1 = bSelect1->GetCount(); LONG count2 = bSelect2->GetCount(); UCHAR* combined, *off; if ((combined = (UCHAR* )GeAlloc(count1 + count2)) == NULL) throw ErrorException(ERROR_MEMORY, NULL); UCHAR* array1 = bSelect1->ToArray(count1); UCHAR* array2 = bSelect2->ToArray(count2); if ((array1 == NULL) || (array2 == NULL)) throw ErrorException(ERROR_MODELINGCOMMAND, "Combine Selections"); CopyMem(array1, combined, count1); off = combined+count1; CopyMem(array2, off, count2); bSelect1->FromArray(combined, count1+count2); //GeFree(combined); GeFree(array1); GeFree(array2); stag2->Remove(); }
Not sure if this is the expected way to move do this.
Thanks,
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/03/2003 at 09:48, xxxxxxxx wrote:
I think you'll find it easier to just loop through the second selection's segments with GetRange(i,&a,&b) and then set these in the first one with SelectAll(a,b).
Btw, note that exception handling isn't as easy in C++ as in Java, since there's no garbage collection. If your last throw is executed the allocation prior to it will leak. The exception safe way to handle this is with RAII (resource allocation is initialization), for example the AutoAlloc and Autonew class. (There's no AutoGeAlloc though, you'd have to adopt the existing classes.) Then you would have something like:{ AutoX<T> myMemory; throw Exception; } // myMemory's destructor frees the memory when it goes out of scope
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/03/2003 at 11:20, xxxxxxxx wrote:
Good point. I usually go through the code and look for these after getting sections working. My approach is to get implementations working then clean up and verify that everything is flowing properly. Bad for my system, but corruption during development is a given. Luckily, it's Win2000Pro, so it can sustain it for a while.
One question about things inserted into documents and then removed. If I insert, for instance, a BaseObject or Tag and then remove it later on, is my code still responsible for freeing the memory or will C4D do it during garbage collection? I ask since once it is inserted into a document, it is owned by C4D (i.e.: the document).
Thanks again,
Robert
P.S: Installed the new update and compiled the api libs without errors or warnings. Notice that the gNew fix has been integrated (since I got errors about it being already defined with the fix included in my code - easily solved). Most excellent! -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/03/2003 at 11:53, xxxxxxxx wrote:
Once you remove an object from its list the list no longer owns the object. I'll add a note to GeListNode::Remove().
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/03/2003 at 12:32, xxxxxxxx wrote:
Okay, will make a note of that and make sure to gDelete() my added-then-removed document items.
Back to selection combining. GetRange()+SelectAll() doesn't do it. Even with the added loop to select the first tag's segments (added to see if it would help retain them), it still ends up with just the second tag's segments:if (stag->GetName() == stag2->GetName()) { BaseSelect* bSelect1 = stag->GetBaseSelect(); BaseSelect* bSelect2 = stag2->GetBaseSelect(); if ((bSelect1 == NULL) || (bSelect2 == NULL)) throw ErrorException(ERROR_MODELINGCOMMAND, "Combine Selections"); LONG seg=0,a,b; String str; while (bSelect1->GetRange(seg++,&a,&b)) { if (a==b) str += LongToString(a)+" "; else str += LongToString(a)+"-"+LongToString(b)+" "; GePrint("Selection1: "+str); bSelect1->SelectAll(a,b); } seg = 0; str = ""; while (bSelect2->GetRange(seg++,&a,&b)) { if (a==b) str += LongToString(a)+" "; else str += LongToString(a)+"-"+LongToString(b)+" "; GePrint("Selection2: "+str); bSelect1->SelectAll(a,b); } // check the resulting segments: seg = 0; str = ""; while (bSelect1->GetRange(seg++,&a,&b)) { if (a==b) str += LongToString(a)+" "; else str += LongToString(a)+"-"+LongToString(b)+" "; GePrint("New Selection1: "+str); } }
Maybe segments have to added to the first before it will accept more (? - wouldn't know how) or something?
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/03/2003 at 07:14, xxxxxxxx wrote:
Any ideas? I've had no electricity since Tuesday due to a crippling blizzard, so have been unable to do anything (almost literally). Will continue to look for alternatives, but the code above only results in the second BaseSelect's selections being added and the original being lost.
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/03/2003 at 08:00, xxxxxxxx wrote:
Anything yet? Hate to be a proper PITA, but since these selection tags are for textures and texture tags don't accept multiple restriction selections (no information to contradict that), I need to combine all selection tags that use the same texture. I will not duplicate texture tags - will not make a something very complicated even more complicated for the user.
I have one more thing to try then must throw up my hands...
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/03/2003 at 14:37, xxxxxxxx wrote:
C++ SDK 8.100
Okay, this works:if (stag1->GetName() == stag2->GetName()) { BaseSelect* bSelect1 = stag1->GetBaseSelect(); BaseSelect* bSelect2 = stag2->GetBaseSelect(); if ((bSelect1 == NULL) || (bSelect2 == NULL)) throw ErrorException(ERROR_MODELINGCOMMAND, "Combine Selections"); LONG seg=0,a,b,i; while (bSelect2->GetRange(seg++,&a,&b)) { for (i = a; i <= b; i++) bSelect1->Select(i); } stag2->Remove(); }
and this doesn't:
if (stag1->GetName() == stag2->GetName()) { BaseSelect* bSelect1 = stag1->GetBaseSelect(); BaseSelect* bSelect2 = stag2->GetBaseSelect(); if ((bSelect1 == NULL) || (bSelect2 == NULL)) throw ErrorException(ERROR_MODELINGCOMMAND, "Combine Selections"); LONG seg=0,a,b; while (bSelect2->GetRange(seg++,&a,&b)) { bSelect1->SelectAll(a,b); } stag2->Remove(); }
Either SelectAll() doesn't work in the same way that Select() does or it is broken. Can someone verify this?
Thanks,
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/03/2003 at 11:42, xxxxxxxx wrote:
Confirmed. I'll report this.