]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_CellDataToPointData.cxx
Salome HOME
0021711: [CEA 579] Simplify Properties dialog accordingly to dimension of mesh
[modules/visu.git] / src / PIPELINE / VISU_CellDataToPointData.cxx
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile$
5
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
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.
13
14  Note from SALOME:
15  This file is a part of VTK library
16  It has been renamed and modified for SALOME project
17
18 =========================================================================*/
19
20 #include "VISU_CellDataToPointData.hxx"
21
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>
29
30 vtkCxxRevisionMacro(VISU_CellDataToPointData, "$Revision$");
31 vtkStandardNewMacro(VISU_CellDataToPointData);
32
33 //----------------------------------------------------------------------------
34 // Instantiate object so that cell data is not passed to output.
35 VISU_CellDataToPointData::VISU_CellDataToPointData()
36 {
37   this->PassCellData = 0;
38 }
39
40 #define VTK_MAX_CELLS_PER_POINT 4096
41
42 //----------------------------------------------------------------------------
43 int VISU_CellDataToPointData::RequestData(
44   vtkInformation*,
45   vtkInformationVector** inputVector,
46   vtkInformationVector* outputVector)
47 {
48   vtkInformation* info = outputVector->GetInformationObject(0);
49   vtkDataSet *output = vtkDataSet::SafeDownCast(
50     info->Get(vtkDataObject::DATA_OBJECT()));
51
52   vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
53   vtkDataSet *input = vtkDataSet::SafeDownCast(
54     inInfo->Get(vtkDataObject::DATA_OBJECT()));
55
56   vtkIdType cellId, ptId;
57   vtkIdType numCells, numPts;
58   vtkCellData *inPD=input->GetCellData();
59   vtkPointData *outPD=output->GetPointData();
60   vtkIdList *cellIds;
61   double weight;
62   double *weights;
63
64   vtkDebugMacro(<<"Mapping cell data to point data");
65
66   // First, copy the input to the output as a starting point
67   output->CopyStructure( input );
68
69   cellIds = vtkIdList::New();
70   cellIds->Allocate(VTK_MAX_CELLS_PER_POINT);
71
72   if ( (numPts=input->GetNumberOfPoints()) < 1 )
73     {
74     vtkDebugMacro(<<"No input point data!");
75     cellIds->Delete();
76     return 1;
77     }
78   weights = new double[VTK_MAX_CELLS_PER_POINT];
79   
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");
86
87   // notice that inPD and outPD are vtkCellData and vtkPointData; respectively.
88   // It's weird, but it works.
89   outPD->InterpolateAllocate(inPD,numPts);
90
91   int abort=0;
92   vtkIdType progressInterval=numPts/20 + 1;
93   for (ptId=0; ptId < numPts && !abort; ptId++)
94     {
95     if ( !(ptId % progressInterval) )
96       {
97       this->UpdateProgress(static_cast<double>(ptId)/numPts);
98       abort = GetAbortExecute();
99       }
100
101     input->GetPointCells(ptId, cellIds);
102     numCells = cellIds->GetNumberOfIds();
103     if ( numCells > 0 )
104       {
105       weight = 1.0 / numCells;
106       for (cellId=0; cellId < numCells; cellId++)
107         {
108         weights[cellId] = weight;
109         }
110       outPD->InterpolatePoint(inPD, ptId, cellIds, weights);
111       }
112     else
113       {
114       outPD->NullPoint(ptId);
115       }
116     }
117
118   if ( !this->PassCellData )
119     {
120     output->GetCellData()->CopyAllOff();
121     output->GetCellData()->CopyFieldOn("vtkGhostLevels");
122     }
123   output->GetCellData()->PassData(input->GetCellData());
124
125   cellIds->Delete();
126   delete [] weights;
127   
128   return 1;
129 }
130
131 //----------------------------------------------------------------------------
132 void VISU_CellDataToPointData::PrintSelf(ostream& os, vtkIndent indent)
133 {
134   this->Superclass::PrintSelf(os,indent);
135
136   os << indent << "Pass Cell Data: " << (this->PassCellData ? "On\n" : "Off\n");
137 }