[vtkusers] how to stop invoked events , if i invoked event in RequestData ?

ysa0829 ysa0829 at gmail.com
Thu Nov 24 05:35:14 EST 2011


this is a function in vtkCollisionDetectionFilter::RequestData();

int vtkCollisionDetectionFilter::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  // get the info objects
  vtkDebugMacro(<< "Beginning execution...");

  // inputs and outputs
  vtkPolyData *input[2];
  vtkPolyData *output[3];

  // copy inputs to outputs
  vtkInformation *inInfo, *outInfo;
  for (int i=0; i<2; i++)
    {
    inInfo = inputVector[i]->GetInformationObject(0);
    input[i] = vtkPolyData::SafeDownCast(
      inInfo->Get(vtkDataObject::DATA_OBJECT()));

    outInfo = outputVector->GetInformationObject(i);
    output[i] = vtkPolyData::SafeDownCast(
      outInfo->Get(vtkDataObject::DATA_OBJECT()));

    output[i]->CopyStructure(input[i]);
    output[i]->GetPointData()->PassData(input[i]->GetPointData());
    output[i]->GetCellData()->PassData(input[i]->GetCellData());
    output[i]->GetFieldData()->PassData(input[i]->GetFieldData());
    }
  
  // set up the contacts polydata output on port index 2
  outInfo = outputVector->GetInformationObject(2);
  output[2] = vtkPolyData::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkPoints *contactsPoints = vtkPoints::New();
  output[2]->SetPoints(contactsPoints);
  contactsPoints->Delete();

  if (this->CollisionMode == vtkCollisionDetectionFilter::VTK_ALL_CONTACTS)
    {//then create a lines cell array
    vtkCellArray *lines = vtkCellArray::New();
    output[2]->SetLines(lines);
    lines->Delete();
    }
  else
    {//else create a verts cell array
    vtkCellArray *verts = vtkCellArray::New();
    output[2]->SetVerts(verts);
    verts->Delete();
    }

  //Allocate arrays for the contact cells lists
  vtkSmartPointer<vtkIdTypeArray> contactcells0 =
    vtkSmartPointer<vtkIdTypeArray>::New();
  contactcells0->SetName("ContactCells");
  output[0]->GetFieldData()->AddArray(contactcells0);

  vtkSmartPointer<vtkIdTypeArray> contactcells1 =
    vtkSmartPointer<vtkIdTypeArray>::New();
  contactcells1->SetName("ContactCells");
  output[1]->GetFieldData()->AddArray(contactcells1);

  // make sure input is available
  if ( ! input[0] )
    {
    vtkWarningMacro(<< "Input 1 hasn't been added... can't execute!");
    return 1;
    }

  // make sure input is available
  if ( ! input[1] )
    {
    vtkWarningMacro(<< "Input 2 hasn't been added... can't execute!");
    return 1;
    }
    
  // The transformations...
  vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
  vtkMatrix4x4 *tmpMatrix = vtkMatrix4x4::New();

  if (this->Transform[0] != NULL || this->Transform[1] != NULL)
    {
    vtkMatrix4x4::Invert(this->Transform[0]->GetMatrix(), tmpMatrix);
    // the sequence of multiplication is significant
    vtkMatrix4x4::Multiply4x4(tmpMatrix, this->Transform[1]->GetMatrix(),
matrix);
    }
   else
    {
     vtkWarningMacro(<< "Set two transforms or two matrices");
     return 1;
    }



  this->InvokeEvent(vtkCommand::StartEvent, NULL);
  

  // rebuild the obb trees... they do their own mtime checking with input
data
  tree0->SetDataSet(input[0]);
  tree0->AutomaticOn();
  tree0->SetNumberOfCellsPerNode(this->NumberOfCellsPerNode);
  tree0->BuildLocator();

  tree1->SetDataSet(input[1]);
  tree1->AutomaticOn();
  tree1->SetNumberOfCellsPerNode(this->NumberOfCellsPerNode);
  tree1->BuildLocator();
    
  // Set the Box Tolerance
  tree0->SetTolerance(this->BoxTolerance);
  tree1->SetTolerance(this->BoxTolerance);




  // Do the collision detection...
  vtkIdType BoxTests = 
    tree0->IntersectWithOBBTree(tree1,  matrix, ComputeCollisions, this);

  matrix->Delete();
  tmpMatrix->Delete();

  vtkDebugMacro(<< "Collision detection finished");
  this->NumberOfBoxTests = abs(BoxTests);
  
  // Generate the scalars if needed
  if (GenerateScalars)
    {

    for (int idx =0; idx < 2; idx++)
      {

      vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New();
      output[idx]->GetCellData()->SetScalars(scalars);
      vtkIdType numCells = input[idx]->GetNumberOfCells();
      scalars->SetNumberOfComponents(4);
      scalars->SetNumberOfTuples(numCells);
      vtkIdTypeArray *contactcells = this->GetContactCells(idx);
      vtkIdType numContacts = this->GetNumberOfContacts();
      
      // Fill the array with blanks...
      // Maybe this should change, to alpha set to Opacity
      // regardless if there are contact or not.
      float alpha;
      if (numContacts > 0)
        {
        alpha = this->Opacity*255.0;
        }
      else
        {
        alpha = 255.0;
        }
      float blank[4] = {255.0,255.0,255.0,alpha};

      for (vtkIdType i = 0; i < numCells; i++)
        {
        scalars->SetTuple(i, blank);
        }

      // Now color the intersecting cells 
      vtkLookupTable *lut = vtkLookupTable::New();
      if (numContacts>0)
        {
        if (this->CollisionMode == VTK_ALL_CONTACTS)
          {
          lut->SetTableRange(0, numContacts-1);
          lut->SetNumberOfTableValues(numContacts);
          }
        else // VTK_FIRST_CONTACT
          {
          lut->SetTableRange(0, 1);
          lut->SetNumberOfTableValues(numContacts+1);
          }
        lut->Build();
        }
      double *RGBA;
      float RGB[4];

      for (vtkIdType id, i = 0; i < numContacts; i++)	//this is where to
change contact color
        {
        id = contactcells->GetValue(i);
        RGBA = lut->GetTableValue(i);
        RGB[0] = 255.0*RGBA[0];
        RGB[1] = 255.0*RGBA[1];
        RGB[2] = 255.0*RGBA[2];
        RGB[3] = 255.0;
        scalars->SetTuple(id, RGB);
        }

      lut->Delete();
      scalars->Delete();
      vtkDebugMacro(<< "Created scalars on output " << idx);
      }
    }
    
  this->InvokeEvent(vtkCommand::EndEvent, NULL);

  return 1;

}

in the function , i do that InvokeEvent(vtkCommand::StartEvent, NULL) and
InvokeEvent(vtkCommand::EndEvent,NULL);

Then,I do this->RemoveAllObservers();.
But I cant remove this event.

Some one know how to stop invoked event?

please help me thx.






--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-stop-invoked-events-if-i-invoked-event-in-RequestData-tp5019812p5019812.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list