1 /*=========================================================================
3 Program: Visualization Toolkit
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
15 This file is a part of VTK library
16 It has been renamed and modified for SALOME project
18 =========================================================================*/
20 #include "VISU_CellDataToPointData.hxx"
22 #include <vtkCellData.h>
23 #include <vtkDataSet.h>
24 #include <vtkIdList.h>
25 #include <vtkInformation.h>
26 #include <vtkInformationVector.h>
27 #include <vtkObjectFactory.h>
28 #include <vtkPointData.h>
30 vtkCxxRevisionMacro(VISU_CellDataToPointData, "$Revision$");
31 vtkStandardNewMacro(VISU_CellDataToPointData);
33 //----------------------------------------------------------------------------
34 // Instantiate object so that cell data is not passed to output.
35 VISU_CellDataToPointData::VISU_CellDataToPointData()
37 this->PassCellData = 0;
40 #define VTK_MAX_CELLS_PER_POINT 4096
42 //----------------------------------------------------------------------------
43 int VISU_CellDataToPointData::RequestData(
45 vtkInformationVector** inputVector,
46 vtkInformationVector* outputVector)
48 vtkInformation* info = outputVector->GetInformationObject(0);
49 vtkDataSet *output = vtkDataSet::SafeDownCast(
50 info->Get(vtkDataObject::DATA_OBJECT()));
52 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
53 vtkDataSet *input = vtkDataSet::SafeDownCast(
54 inInfo->Get(vtkDataObject::DATA_OBJECT()));
56 vtkIdType cellId, ptId;
57 vtkIdType numCells, numPts;
58 vtkCellData *inPD=input->GetCellData();
59 vtkPointData *outPD=output->GetPointData();
64 vtkDebugMacro(<<"Mapping cell data to point data");
66 // First, copy the input to the output as a starting point
67 output->CopyStructure( input );
69 cellIds = vtkIdList::New();
70 cellIds->Allocate(VTK_MAX_CELLS_PER_POINT);
72 if ( (numPts=input->GetNumberOfPoints()) < 1 )
74 vtkDebugMacro(<<"No input point data!");
78 weights = new double[VTK_MAX_CELLS_PER_POINT];
80 // Pass the point data first. The fields and attributes
81 // which also exist in the cell data of the input will
82 // be over-written during CopyAllocate
83 output->GetPointData()->CopyGlobalIdsOff();
84 output->GetPointData()->PassData(input->GetPointData());
85 output->GetPointData()->CopyFieldOff("vtkGhostLevels");
87 // notice that inPD and outPD are vtkCellData and vtkPointData; respectively.
88 // It's weird, but it works.
89 outPD->InterpolateAllocate(inPD,numPts);
92 vtkIdType progressInterval=numPts/20 + 1;
93 for (ptId=0; ptId < numPts && !abort; ptId++)
95 if ( !(ptId % progressInterval) )
97 this->UpdateProgress(static_cast<double>(ptId)/numPts);
98 abort = GetAbortExecute();
101 input->GetPointCells(ptId, cellIds);
102 numCells = cellIds->GetNumberOfIds();
105 weight = 1.0 / numCells;
106 for (cellId=0; cellId < numCells; cellId++)
108 weights[cellId] = weight;
110 outPD->InterpolatePoint(inPD, ptId, cellIds, weights);
114 outPD->NullPoint(ptId);
118 if ( !this->PassCellData )
120 output->GetCellData()->CopyAllOff();
121 output->GetCellData()->CopyFieldOn("vtkGhostLevels");
123 output->GetCellData()->PassData(input->GetCellData());
131 //----------------------------------------------------------------------------
132 void VISU_CellDataToPointData::PrintSelf(ostream& os, vtkIndent indent)
134 this->Superclass::PrintSelf(os,indent);
136 os << indent << "Pass Cell Data: " << (this->PassCellData ? "On\n" : "Off\n");