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>
7 #include "SALOME_Transform.h"
8 #include "VTKViewer_Common.h"
9 #include <vtkObjectFactory.h>
10 #include <vtkGeometryFilter.h>
11 #include <vtkMatrix4x4.h>
14 //=======================================================================
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;
22 void SALOME_Transform::SetScale(float theScaleX, float theScaleY, float theScaleZ){
23 double aMatrix[16] = {theScaleX,0,0,0,
27 vtkTransform::SetMatrix(aMatrix);
28 //vtkTransform::Pop();
29 //vtkTransform::Scale(theScale);
32 int SALOME_Transform::IsIdentity(){
33 float* aScale = GetScale();
34 return (aScale[0] == 1.0 && aScale[1] == 1.0 && aScale[2] == 1.0);
37 //=======================================================================
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;
45 void SALOME_TransformFilter::Execute(){
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 );
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();
60 vtkErrorMacro(<<"No input data");
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);
77 //=======================================================================
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;
85 SALOME_PassThroughFilter::SALOME_PassThroughFilter(){
86 myGeomFilter = vtkGeometryFilter::New();
89 SALOME_PassThroughFilter::~SALOME_PassThroughFilter(){
90 myGeomFilter->Delete();
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() );
101 void SALOME_PassThroughFilter::SetInput(vtkDataSet *input){
102 myGeomFilter->SetInput(input);
103 vtkDataSet *oldInput = this->GetInput();
105 if(input == NULL || oldInput->GetDataObjectType() != input->GetDataObjectType()){
106 vtkWarningMacro("Changing input type. Deleting output");
107 this->SetOutput(NULL);
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();
114 this->vtkProcessObject::SetNthInput(0, input);
117 vtkPolyData *SALOME_PassThroughFilter::GetPolyDataOutput() {
118 vtkDataSet *ds = this->GetOutput();
120 if(ds->GetDataObjectType() == VTK_POLY_DATA) return (vtkPolyData *)ds;
121 myGeomFilter->SetInput(this->GetOutput());
122 return myGeomFilter->GetOutput();