Analasying type of an object. Faster way?



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

    On 05/01/2008 at 18:27, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.5 
    Platform:      
    Language(s) :   C.O.F.F.E.E  ;

    ---------
       Hi,

    I have a function which should only be executed if a Polygonobject or a Primitive (Cube, sphere, cyl, ...) is selected.

    So I created another function which analyses an object. Here it is:

    > _
    > AnalyseObject( obj ) {
    >      var arr = new(array, 17);
    >      
    >      arr[0] = 5159;    // Cube
    >      arr[1] = 5160;    // Sphere
    >      arr[2] = 5162;    // Cone
    >      arr[3] = 5170;    // Cylinder
    >      arr[4] = 5174;    // Polygon
    >      arr[5] = 5168;    // Plane
    >      arr[6] = 5164;    // ...
    >      arr[7] = 5167;
    >      arr[8] = 5171;
    >      arr[9] = 5172;
    >      arr[10] = 5161;
    >      arr[11] = 5163;
    >      arr[12] = 5165;
    >      arr[13] = 5169;
    >      arr[14] = 5166;
    >      arr[15] = 5173;
    >      arr[16] = 5100;    // PolygoneObject
    >      
    >      var i = 0;
    >      while (i < 17) {
    >           if (arr _== obj- >GetType()) return obj;
    >           i++;
    >      }
    >      println("NOT WHAT I WANT");
    >      return NULL;
    > }
    > _

    Now my question: Isn't there a faster way in COFFEE? :)



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

    On 05/01/2008 at 18:36, xxxxxxxx wrote:

    I think that's about it. There is no general categorization of object types (say, to see if an object is a primitive type). You can't even use class derivation to check a general category, say, of your own plugin objects all derived from your base plugin object:

    class MyPluginObject : ObjectData {} // ID_MYPLUGINOBJECT
    class DerivedObj1 : MyPluginObject {} // ID_DERIVEDOBJ1
    class DerivedObj2 : MyPluginObject {} // ID_DERIVEDOBJ2
    etc.

    To check if the object is any of these, you can't check:

    if (obj->IsInstanceOf(ID_MYPLUGINOBJECT)) ...

    or even

    if (obj->IsInstanceOf(Obase)) // surprise, your object isn't an object!

    This will fail for DerivedObj1 and DerivedObj2 - sad huh? So, you have to check for each case individually:

    if (obj->IsInstanceOf(ID_DERIVEDOBJ1) || obj->IsInstanceOf(ID_DERIVEDOBJ2) || etc.) ...

    This may be C++ but the situation is the same with COFFEE. Unfortunately, the way that C4D instances work, using C++ class derivation tactics can't be employed.



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

    On 06/01/2008 at 04:54, xxxxxxxx wrote:

    Oh, ok, yes this is sad...

    What would be a better approach? Iterrating through an array like in my example (supposing the array is already full), or writing all in a single if condition? Would there be a speed gain with the 'if'?



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

    On 06/01/2008 at 05:55, xxxxxxxx wrote:

    Quote: _What would be a better approach? Iterrating through an array like in my example (supposing the array is already full), or writing all in a single if condition? Would there be a speed gain with the 'if'?
    >
    > * * *
    _


    Just use the switch statement and GetType(). Little example:

    > _
    > var type = op- >GetType();
    >
    > switch(type)
    > {
    >      case Opolygon:
    >           println("polygon");
    >           break;
    >      case Ocube:
    >           println("cube");
    >           break;
    >      default:
    >           println("none of these");
    >           break;
    > }
    > _

    cheers,
    Matthias



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

    On 06/01/2008 at 09:00, xxxxxxxx wrote:

    I agree with Matthias that this is the best way to go. Simply replace the array/loop with the switch in your AnalyzeObject() method.

    The 'Oxxxx' types are delineated in the coffeesymbols.h file



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

    On 06/01/2008 at 18:07, xxxxxxxx wrote:

    Ok, thank you. I'm going to take a look into the coffeesymbols.h file.


Log in to reply