X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPIPELINE%2FVISU_Extractor.cxx;h=b6423a396f1b820848ad579c00e325613e3c7bae;hb=953451df51750a1d9910c0325f01d5ca7b6e0330;hp=0b3f78595054571e00556ba720df1e3483060dce;hpb=17b175ff4b710fc93421509ffa7583edd1678a5d;p=modules%2Fvisu.git diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index 0b3f7859..b6423a39 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -1,85 +1,96 @@ // VISU OBJECT : interactive object for VISU entities implementation // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // File : VISU_Extractor.cxx // Module : VISU -#include "VISU_Extractor.hxx" +#include "VISU_Extractor.hxx" +#include "VISU_PipeLineUtils.hxx" + +#include #include #include #include #include #include +#include using namespace std; -#ifdef DEBUG -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif - vtkStandardNewMacro(VISU_Extractor); -VISU_Extractor::VISU_Extractor(){ - myScalarMode = 0; +VISU_Extractor::VISU_Extractor() +{ + myScalarMode = 1; } -VISU_Extractor::~VISU_Extractor() {} +VISU_Extractor::~VISU_Extractor() +{} -void VISU_Extractor::SetScalarMode(int theScalarMode){ +void VISU_Extractor::SetScalarMode(int theScalarMode) +{ if(myScalarMode != theScalarMode){ myScalarMode = theScalarMode; Modified(); } } - template void -execute(int theNbComp, int theScalarMode, TypeData* theInputData, TypeData* theOutputData){ - vtkDataArray *inVectors = theInputData->GetVectors(); - if ( !inVectors || theNbComp < 1 ) - return; - vtkFloatArray *newScalars = vtkFloatArray::New(); - //newScalars->SetName(inVectors->GetName()); - newScalars->SetNumberOfComponents(1); - newScalars->SetNumberOfTuples(theNbComp); - for (int ptId = 0; ptId < theNbComp; ptId++) { - float v[3], s; - inVectors->GetTuple(ptId,v); - if ( theScalarMode < 1 || theScalarMode > 3) - s = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); - else - s = v[theScalarMode - 1]; - newScalars->SetTuple1(ptId, s); +execute(int theNbElems, + int theScalarMode, + TypeData* theInputData, + TypeData* theOutputData) +{ + if(theNbElems < 1 ) + return; + vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD"); + if(vtkFloatArray *aFloatArray = dynamic_cast(aFieldArray)){ + int aNbComp = aFloatArray->GetNumberOfComponents(); + std::vector anArray(aNbComp < 3? 3: aNbComp); + // + vtkFloatArray *aScalars = vtkFloatArray::New(); + aScalars->SetNumberOfTuples(theNbElems); + aScalars->SetNumberOfComponents(1); + // + if(!theScalarMode){ + for(int anId = 0; anId < theNbElems; anId++){ + aFloatArray->GetTuple(anId,&anArray[0]); + float aVector[3] = {anArray[0], anArray[1], anArray[2]}; + float aScalar = sqrt(aVector[0]*aVector[0] + aVector[1]*aVector[1] + aVector[2]*aVector[2]); + aScalars->SetTuple1(anId,aScalar); + } + }else{ + for(int anId = 0; anId < theNbElems; anId++){ + aFloatArray->GetTuple(anId,&anArray[0]); + aScalars->SetTuple1(anId,anArray[theScalarMode - 1]); + } + } + theOutputData->SetScalars(aScalars); + aScalars->Delete(); } - theOutputData->SetScalars(newScalars); - //theOutputData->SetActiveScalars(newScalars->GetName()); - newScalars->Delete(); } - void VISU_Extractor::Execute(){ vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); @@ -87,21 +98,23 @@ void VISU_Extractor::Execute(){ output->GetCellData()->CopyAllOff(); if(input->GetPointData()->GetNumberOfArrays()){ output->GetPointData()->CopyVectorsOn(); - int nbComp = input->GetNumberOfPoints(); + int aNbElems = input->GetNumberOfPoints(); vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(nbComp,myScalarMode,inData,outData); + execute(aNbElems,myScalarMode,inData,outData); else output->GetPointData()->CopyScalarsOn(); outData->PassData(inData); + outData->AddArray(inData->GetArray("VISU_FIELD")); }else{ output->GetCellData()->CopyVectorsOn(); - int nbComp = input->GetNumberOfCells(); + int aNbElems = input->GetNumberOfCells(); vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(nbComp,myScalarMode,inData,outData); + execute(aNbElems,myScalarMode,inData,outData); else output->GetCellData()->CopyScalarsOn(); outData->PassData(inData); + outData->AddArray(inData->GetArray("VISU_FIELD")); } }