Salome HOME
NRI : Merge from V1_2.
[modules/kernel.git] / src / OBJECT / SALOME_Transform.cxx
1 // File:        SALOME_Transform.cxx
2 // Created:     Wed Jun  4 09:46:59 2003
3 // Author:      Alexey PETROV
4 //              <apo@ivanox.nnov.matra-dtv.fr>
5
6
7 #include "SALOME_Transform.h"
8 #include "VTKViewer_Common.h"
9 #include <vtkObjectFactory.h>
10 #include <vtkGeometryFilter.h>
11 #include <vtkMatrix4x4.h>
12 using namespace std;
13
14 //=======================================================================
15
16 SALOME_Transform* SALOME_Transform::New(){
17   vtkObject* ret = vtkObjectFactory::CreateInstance("SALOME_Transform");
18   if(ret) return (SALOME_Transform*)ret;
19   return new SALOME_Transform;
20 }
21
22 void SALOME_Transform::SetScale(float theScaleX, float theScaleY, float theScaleZ){ 
23   double aMatrix[16] = {theScaleX,0,0,0, 
24                         0,theScaleY,0,0, 
25                         0,0,theScaleZ,0, 
26                         0,0,0,1.0000000};
27   vtkTransform::SetMatrix(aMatrix);
28   //vtkTransform::Pop();
29   //vtkTransform::Scale(theScale);
30 }
31
32 int SALOME_Transform::IsIdentity(){ 
33   float* aScale = GetScale();
34   return (aScale[0] == 1.0 && aScale[1] == 1.0 && aScale[2] == 1.0);
35 }
36
37 //=======================================================================
38
39 SALOME_TransformFilter* SALOME_TransformFilter::New(){
40   vtkObject* ret = vtkObjectFactory::CreateInstance("SALOME_TransformFilter");
41   if(ret) return (SALOME_TransformFilter*)ret;
42   return new SALOME_TransformFilter;
43 }
44
45 void SALOME_TransformFilter::Execute(){
46   vtkPoints *inPts;
47   vtkPoints *newPts;
48   int numPts, numCells;
49   vtkPointSet *input = this->GetInput();
50   vtkPointSet *output = this->GetOutput();
51   vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData();
52   vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData();
53   output->CopyStructure( input );
54   int anIdentity = 0;
55   if(SALOME_Transform* aTransform = dynamic_cast<SALOME_Transform*>(this->Transform))
56     anIdentity = aTransform->IsIdentity();
57   if(!anIdentity && this->Transform != NULL){
58     inPts = input->GetPoints();
59     if(!inPts){
60       vtkErrorMacro(<<"No input data");
61       return;
62     }
63     numPts = inPts->GetNumberOfPoints();
64     numCells = input->GetNumberOfCells();
65     newPts = vtkPoints::New();
66     newPts->Allocate(numPts);
67     this->UpdateProgress(.2);
68     this->Transform->TransformPoints(inPts,newPts);
69     this->UpdateProgress(.8);
70     output->SetPoints(newPts);
71     newPts->Delete();
72   }
73   outPD->PassData(pd);
74   outCD->PassData(cd);
75 }
76
77 //=======================================================================
78
79 SALOME_PassThroughFilter* SALOME_PassThroughFilter::New(){
80   vtkObject* ret = vtkObjectFactory::CreateInstance("SALOME_PassThroughFilter");
81   if(ret) return (SALOME_PassThroughFilter*)ret;
82   return new SALOME_PassThroughFilter;
83 }
84
85 SALOME_PassThroughFilter::SALOME_PassThroughFilter(){
86   myGeomFilter = vtkGeometryFilter::New();
87 }
88
89 SALOME_PassThroughFilter::~SALOME_PassThroughFilter(){
90   myGeomFilter->Delete();
91 }
92
93 void SALOME_PassThroughFilter::Execute(){
94   vtkDataSet *input = static_cast<vtkDataSet*>(this->GetInput());
95   vtkDataSet *output = static_cast<vtkDataSet*>(this->GetOutput());
96   output->CopyStructure( input );
97   output->GetPointData()->PassData( input->GetPointData() );
98   output->GetCellData()->PassData( input->GetCellData() );
99 }
100
101 void SALOME_PassThroughFilter::SetInput(vtkDataSet *input){
102   myGeomFilter->SetInput(input);
103   vtkDataSet *oldInput = this->GetInput();
104   if(oldInput != NULL)
105     if(input == NULL || oldInput->GetDataObjectType() != input->GetDataObjectType()){
106       vtkWarningMacro("Changing input type.  Deleting output");
107       this->SetOutput(NULL);
108     }
109   if (input != NULL && this->vtkSource::GetOutput(0) == NULL){
110     this->vtkSource::SetNthOutput(0, input->NewInstance());
111     this->Outputs[0]->ReleaseData();
112     this->Outputs[0]->Delete();
113   }
114   this->vtkProcessObject::SetNthInput(0, input);
115 }
116
117 vtkPolyData *SALOME_PassThroughFilter::GetPolyDataOutput() {
118   vtkDataSet *ds = this->GetOutput();
119   if(!ds) return NULL;
120   if(ds->GetDataObjectType() == VTK_POLY_DATA) return (vtkPolyData *)ds;
121   myGeomFilter->SetInput(this->GetOutput());
122   return myGeomFilter->GetOutput();
123 }