/** * $Id:$ * * \file vtkRibbonFilterFix.cc */ #include "vtkRibbonFilterFix.h" #include "vtkInformation.h" #include "vtkInformationVector.h" #include "vtkObjectFactory.h" #include "vtkPointData.h" #include "vtkPoints.h" #include "vtkPolyData.h" vtkCxxRevisionMacro(vtkRibbonFilterFix, "$Revision: 1.00 $"); vtkStandardNewMacro(vtkRibbonFilterFix); vtkRibbonFilterFix::vtkRibbonFilterFix() { } vtkRibbonFilterFix::~vtkRibbonFilterFix() { } int vtkRibbonFilterFix::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) { // The following few lines are stolen from the original // "vtkRibbonFilter.cxx" // get the info objects vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); vtkInformation *outInfo = outputVector->GetInformationObject(0); // get the input and ouptut vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT())); vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT())); vtkPointData *outPD; vtkPointData *tmpOutPD; vtkPoints *inPts; // Check input and initialize // vtkDebugMacro(<<"Fixing input poly data"); if ( !(inPts = input->GetPoints()) || inPts->GetNumberOfPoints() < 1 ) { return 1; } // Make a shallow copy of the input. This does not inspect data attribute // arrays, it just increments the reference counter. We get rid of corrput // arrays afterwards. // output->ShallowCopy(input); // I don't know how to explicitly delete data arrays (it seems that // vtkFieldData only exposes a method for removing an array by name, not by // index; the latter is declared as `protected'). // // To get rid of unwanted arrays, we now just make a temporary shallow copy, // reset the output point data and copy back required arrays explicitly // (scalars, normals and texture coordinates). Actual copying is done using // PassData(vtkFieldData*), and controlling which fields to copy is done by // setting copy attributes accordingly. // outPD = output->GetPointData(); tmpOutPD = vtkPointData::New(); tmpOutPD->ShallowCopy(outPD); outPD->Initialize(); // Reset point data (releases old data) outPD->CopyAllOff(); // disallow everything... outPD->CopyScalarsOn(); // ... and explicitly allow scalars... outPD->CopyNormalsOn(); // ... normals... outPD->CopyTCoordsOn(); // ... and texture coordinates. outPD->PassData(tmpOutPD); tmpOutPD->Delete(); // remove temporary copy return 1; }