Salome HOME
9c23634f1219a223f22390d095dba381f14feedf
[modules/gui.git] / src / VTKViewer / VTKViewer_TransformFilter.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME FILTER : interactive object for VISU entities implementation
24 //  File   : SALOME_TransformFilter.h
25 //  Author : Laurent CORNABE with help of Nicolas REJNERI
26 //  Module : SALOME
27 //
28 #include "VTKViewer_TransformFilter.h"
29 #include "VTKViewer_Transform.h"
30
31 #include <vtkObjectFactory.h>
32 #include <vtkPointSet.h>
33 #include <vtkPointData.h>
34 #include <vtkCellData.h>
35 #include <vtkPoints.h>
36 #include <vtkInformation.h>
37 #include <vtkInformationVector.h>
38
39 vtkStandardNewMacro(VTKViewer_TransformFilter)
40
41 /*!Execution method. Calculate output.*/
42 int VTKViewer_TransformFilter::RequestData(
43   vtkInformation *vtkNotUsed(request),
44   vtkInformationVector **inputVector,
45   vtkInformationVector *outputVector)
46 {
47   // get the info objects
48   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
49   vtkInformation *outInfo = outputVector->GetInformationObject(0);
50
51   // get the input and ouptut
52   vtkPointSet *input = vtkPointSet::SafeDownCast(
53     inInfo->Get(vtkDataObject::DATA_OBJECT()));
54   vtkPointSet *output = vtkPointSet::SafeDownCast(
55     outInfo->Get(vtkDataObject::DATA_OBJECT()));
56
57   vtkPoints *inPts;
58   vtkPoints *newPts;
59   int numPts/*, numCells*/;
60   vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData();
61   vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData();
62   output->CopyStructure( input );
63   if(Transform){
64     bool anIsIdentity = true;
65     if(VTKViewer_Transform* aTransform = dynamic_cast<VTKViewer_Transform*>(Transform))
66       anIsIdentity = aTransform->IsIdentity() != 0;
67     inPts = input->GetPoints();
68     if(!anIsIdentity && inPts){
69       numPts = inPts->GetNumberOfPoints();
70       // numCells = input->GetNumberOfCells();
71       newPts = vtkPoints::New();
72       newPts->Allocate(numPts);
73       this->UpdateProgress(.2);
74       this->Transform->TransformPoints(inPts,newPts);
75       this->UpdateProgress(.8);
76       output->SetPoints(newPts);
77       newPts->Delete();
78     }
79   }
80   outPD->PassData(pd);
81   outCD->PassData(cd);
82   InvokeEvent("VTKViewer_TransformFilter::TransformationFinished");
83   
84   return 1;
85 }