vtkIsTypeMacro

John Biddiscombe j.biddiscombe at rl.ac.uk
Fri Apr 7 06:28:50 EDT 2000


Apologies to Bill, the code snippet I sent DID contain RTTI stuff, I
mistakenly sent the wrong version but didn't actually look at it when pasting.

Here is an example of usage

    if (vtkCellLocator::IsType("vtkStructuredPoints")) {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkStructuredPoints\")
= true");
    } else {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkStructuredPoints\")
= false");
    }
FALSE
    //
    if (vtkCellLocator::IsType("vtkObject")) {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkObject\") = true");
    } else {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkObject\") = false");
    }
TRUE
    //
    if (vtkCellLocator::IsType("vtkLocator")) {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkLocator\") = true");
    } else {
        ShowMessage("vtkCellLocator::InheritsFrom(\"vtkLocator\") = false");
    }
TRUE
    //
    if (vtkObject::IsType("vtkLocator")) {
        ShowMessage("vtkObject::InheritsFrom(\"vtkLocator\") = true");
    } else {
        ShowMessage("vtkObject::InheritsFrom(\"vtkLocator\") = false");
    }
FALSE

The reason for it is because my old code for drag/drop testing looked a bit
like this snippet

// if pointer valid, use it, otherwise check type flag
case VTK_DATA_SET : 
  if (dragged_object) Accept = vtkIsTypeMacro(vtkDataSet, dragged_object);
  else Accept = ((DataType==dragged_type) ||
(dragged_type==VTK_UNSTRUCTURED_GRID) ||
    (dragged_type==VTK_STRUCTURED_GRID) || (dragged_type==VTK_POLY_DATA) ||
    (dragged_type==VTK_STRUCTURED_POINTS) ||
(dragged_type==VTK_RECTILINEAR_GRID) ||
    (dragged_type==VTK_IMAGE_DATA) || (dragged_type==VTK_POINT_SET)
  );
  break;
case VTK_POINT_SET :
  if (dragged_object) Accept = vtkIsTypeMacro(vtkPointSet, dragged_object);
  else Accept = ((DataType==dragged_type) ||
(dragged_type==VTK_UNSTRUCTURED_GRID) ||
    (dragged_type==VTK_STRUCTURED_GRID) || (dragged_type==VTK_POLY_DATA));
  break;
case VTK_DATA_TEXTURE :
  if (dragged_object) Accept = vtkIsTypeMacro(vtkTexture, dragged_object);
  else Accept = (DataType==dragged_type);
  break;

I think you can see that now that I've extended it to handle ALL vtk
objects, the rather tiresome checking for inheritance is just too much.
Literally thousands of possible checks (Really).

Instead, I can now create a drag point and pass
&vtkLocator::IsType
to the drag constructor, when testing for drop compatibility I can simply say
if  draggedIsTypefunc("vtkLocator")
then OK.
because I know that this drag zone must export a locator of sime kind, and
the receiving drop point must accept a locator of some type. But as the
output of the filter may be NULL when certain conditions are invalid I
can't simply pass a pointer and do a dynamic_cast

the macro is simple

static int IsType(const char *type) \
{ \
  if (!strcmp(#thisClass,type)) \
    { \
    return 1; \
    } \
  return superclass::IsType(type); \
} \

and in vtkObject an additional

int vtkObject::IsType(const char *type)
{
  if (!strcmp("vtkObject", type))
    {
    return 1;
    }
  return 0;
}

I can check in the changes if approved. (Oh go on, please say yes).

John B







More information about the vtk-developers mailing list