1 // Copyright (C) 2010-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkScaleVectorFilter.h"
22 #include <vtkCellArray.h>
23 #include <vtkDataSet.h>
24 #include <vtkInformation.h>
25 #include <vtkInformationVector.h>
26 #include <vtkObjectFactory.h>
27 #include <vtkPointData.h>
33 // vtkCxxRevisionMacro(vtkScaleVectorFilter, "$Revision$");
34 vtkStandardNewMacro(vtkScaleVectorFilter)
36 vtkScaleVectorFilter::vtkScaleVectorFilter()
38 this->ScaleFactor = 0.5;
41 vtkScaleVectorFilter::~vtkScaleVectorFilter()
45 //----------------------------------------------------------------------------
46 int vtkScaleVectorFilter::FillInputPortInformation(int vtkNotUsed(port), vtkInformation* info)
49 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
53 int vtkScaleVectorFilter::RequestData(
54 vtkInformation* vtkNotUsed(request), vtkInformationVector** input, vtkInformationVector* output)
57 vtkDataSet::SafeDownCast(input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
60 vtkDataSet::SafeDownCast(output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
62 vtkDataArray* array = this->GetInputArrayToProcess(0, input);
64 if (dsIn == NULL || array == NULL || dsOut == NULL || array->GetNumberOfComponents() != 3 ||
65 this->GetInputArrayAssociation(0, input) != vtkDataObject::FIELD_ASSOCIATION_POINTS)
67 vtkDebugMacro("vtkScaleVectorFilter no correctly configured");
71 dsOut->ShallowCopy(dsIn);
73 vtkPointData* inPD = dsIn->GetPointData();
74 vtkPointData* outPD = dsOut->GetPointData();
76 outPD->RemoveArray(array->GetName());
78 vtkDataArray* outArray = array->NewInstance();
79 outArray->SetName(array->GetName());
81 string name = array->GetName();
82 size_t pos1 = name.find_last_of("[");
83 if (pos1 != string::npos)
85 string name1 = name.substr(0, pos1);
86 size_t noblankpos = name1.find_last_not_of(" ");
87 name1 = name1.substr(0, noblankpos + 1);
89 outArray->SetName(name1.c_str());
91 for (int arrayId = 0; arrayId < inPD->GetNumberOfArrays(); arrayId++)
93 vtkDataArray* thearray = inPD->GetArray(arrayId);
97 if (strncmp(name1.c_str(), thearray->GetName(), name1.size()) == 0)
99 outPD->RemoveArray(thearray->GetName());
104 outPD->AddArray(outArray);
107 outArray->SetNumberOfComponents(array->GetNumberOfComponents());
108 outArray->SetNumberOfTuples(array->GetNumberOfTuples());
110 if (array->HasAComponentName())
112 outArray->CopyComponentNames(array);
115 if (array->HasInformation())
117 outArray->CopyInformation(array->GetInformation());
120 for (vtkIdType id = 0; id < outArray->GetNumberOfTuples(); id++)
123 array->GetTuple(id, tuple);
124 tuple[0] *= this->ScaleFactor;
125 tuple[1] *= this->ScaleFactor;
126 tuple[2] *= this->ScaleFactor;
127 outArray->SetTuple(id, tuple);
129 // fix the range keys to match the full range, so that the
130 // gui automatically sets the range.
132 vtkInformation* info = outArray->GetInformation();
134 array->GetRange(range, -1);
136 info->Set(vtkDataArray::L2_NORM_RANGE(), range, 2);
138 if (!outArray->GetInformation()->Has(vtkDataArray::PER_COMPONENT()))
140 vtkInformationVector* infoVec = vtkInformationVector::New();
141 info->Set(vtkDataArray::PER_COMPONENT(), infoVec);
142 infoVec->FastDelete();
144 vtkInformationVector* per_comp = info->Get(vtkDataArray::PER_COMPONENT());
145 per_comp->SetNumberOfInformationObjects(outArray->GetNumberOfComponents());
146 for (int comp = 0; comp < outArray->GetNumberOfComponents(); comp++)
148 array->GetRange(range, comp);
149 range[0] = fabs(range[0]);
150 range[1] = fabs(range[1]);
151 double r = (range[0] > range[1] ? range[0] : range[1]);
154 per_comp->GetInformationObject(comp)->Set(vtkDataArray::COMPONENT_RANGE(), range, 2);
157 outPD->SetActiveVectors(outArray->GetName());
162 void vtkScaleVectorFilter::PrintSelf(ostream& os, vtkIndent indent)
164 this->Superclass::PrintSelf(os, indent);
166 os << indent << "ScaleFactor : " << this->ScaleFactor << endl;