1 // Copyright (C) 2010-2013 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.
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"
21 #include "vtkInformation.h"
22 #include "vtkInformationVector.h"
23 #include "vtkObjectFactory.h"
24 #include "vtkCellArray.h"
25 #include "vtkPointData.h"
26 #include "vtkDataSet.h"
32 //vtkCxxRevisionMacro(vtkScaleVectorFilter, "$Revision$");
33 vtkStandardNewMacro(vtkScaleVectorFilter);
35 vtkScaleVectorFilter::vtkScaleVectorFilter()
37 this->ScaleFactor = 0.5;
40 vtkScaleVectorFilter::~vtkScaleVectorFilter()
44 //----------------------------------------------------------------------------
45 int vtkScaleVectorFilter::FillInputPortInformation(
46 int vtkNotUsed(port), vtkInformation* info)
49 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
54 int vtkScaleVectorFilter::RequestData(vtkInformation *vtkNotUsed(request),
55 vtkInformationVector **input, vtkInformationVector *output)
57 vtkDataSet *dsIn = vtkDataSet::SafeDownCast(
58 input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
60 vtkDataSet *dsOut = vtkDataSet::SafeDownCast(
61 output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
63 vtkDataArray* array = this->GetInputArrayToProcess(0, input);
65 if(dsIn == NULL || array == NULL || dsOut == NULL
66 || array->GetNumberOfComponents() != 3 ||
67 this->GetInputArrayAssociation(0, input) != vtkDataObject::FIELD_ASSOCIATION_POINTS)
69 vtkDebugMacro("vtkScaleVectorFilter no correctly configured");
73 dsOut->ShallowCopy(dsIn);
75 vtkPointData* inPD = dsIn->GetPointData();
76 vtkPointData* outPD = dsOut->GetPointData();
78 outPD->RemoveArray(array->GetName());
80 vtkDataArray* outArray = array->NewInstance();
81 outArray->SetName(array->GetName());
83 string name = array->GetName();
84 size_t pos1 = name.find_last_of("[");
85 if(pos1 != string::npos)
87 string name1 = name.substr(0, pos1);
88 size_t noblankpos = name1.find_last_not_of(" ");
89 name1 = name1.substr(0, noblankpos+1);
91 outArray->SetName(name1.c_str());
93 for(int arrayId = 0; arrayId < inPD->GetNumberOfArrays(); arrayId++)
95 vtkDataArray* thearray = inPD->GetArray(arrayId);
99 if(strncmp(name1.c_str(), thearray->GetName(), name1.size()) == 0)
101 outPD->RemoveArray(thearray->GetName());
106 outPD->AddArray(outArray);
109 outArray->SetNumberOfComponents(array->GetNumberOfComponents());
110 outArray->SetNumberOfTuples(array->GetNumberOfTuples());
112 if(array->HasAComponentName())
114 outArray->CopyComponentNames(array);
117 if(array->HasInformation())
119 outArray->CopyInformation(array->GetInformation());
122 for(vtkIdType id=0; id < outArray->GetNumberOfTuples(); id++)
125 array->GetTuple(id, tuple);
126 tuple[0] *= this->ScaleFactor;
127 tuple[1] *= this->ScaleFactor;
128 tuple[2] *= this->ScaleFactor;
129 outArray->SetTuple(id, tuple);
131 // fix the range keys to match the full range, so that the
132 // gui automatically sets the range.
134 vtkInformation* info = outArray->GetInformation();
136 array->GetRange(range, -1);
138 info->Set(vtkDataArray::L2_NORM_RANGE(), range, 2);
140 if(!outArray->GetInformation()->Has(vtkDataArray::PER_COMPONENT()))
142 vtkInformationVector* infoVec = vtkInformationVector::New();
143 info->Set( vtkDataArray::PER_COMPONENT(), infoVec );
144 infoVec->FastDelete();
146 vtkInformationVector* per_comp = info->Get(vtkDataArray::PER_COMPONENT());
147 per_comp->SetNumberOfInformationObjects(outArray->GetNumberOfComponents());
148 for(int comp = 0; comp < outArray->GetNumberOfComponents(); comp++)
150 array->GetRange(range, comp);
151 range[0] = fabs(range[0]);
152 range[1] = fabs(range[1]);
153 double r = (range[0] > range[1] ? range[0] : range[1]);
156 per_comp->GetInformationObject(comp)->Set(
157 vtkDataArray::COMPONENT_RANGE(), range, 2 );
160 outPD->SetActiveVectors(outArray->GetName());
165 void vtkScaleVectorFilter::PrintSelf(ostream& os, vtkIndent indent)
167 this->Superclass::PrintSelf(os, indent);
169 os << indent << "ScaleFactor : " << this->ScaleFactor << endl;