From 2d7025b0576d4ed832a941a00164f4e74a451800 Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 4 Oct 2005 13:24:17 +0000 Subject: [PATCH] To fix vtk?MergeFilter bug - it does not pass cell fields --- src/CONVERTOR/Makefile.in | 2 + src/CONVERTOR/VISU_Convertor_impl.cxx | 50 ++- src/CONVERTOR/VISU_Convertor_impl.hxx | 36 ++- src/CONVERTOR/VISU_MergeFilter.cxx | 418 ++++++++++++++++++++++++++ src/CONVERTOR/VISU_MergeFilter.hxx | 99 ++++++ 5 files changed, 581 insertions(+), 24 deletions(-) create mode 100644 src/CONVERTOR/VISU_MergeFilter.cxx create mode 100644 src/CONVERTOR/VISU_MergeFilter.hxx diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in index e91a493e..5549610d 100644 --- a/src/CONVERTOR/Makefile.in +++ b/src/CONVERTOR/Makefile.in @@ -38,6 +38,7 @@ EXPORT_HEADERS = \ VISU_ConvertorDef.hxx \ VISU_Convertor_impl.hxx \ VISU_ConvertorUtils.hxx \ + VISU_MergeFilter.hxx \ VISU_ExtractUnstructuredGrid.hxx # Libraries targets @@ -49,6 +50,7 @@ LIB_SRC = \ VISU_Convertor_impl.cxx \ VISU_ConvertorUtils.cxx \ VISU_ExtractUnstructuredGrid.cxx \ + VISU_MergeFilter.cxx \ VISU_MedConvertor.cxx # Executables targets diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 8609f12f..3ce4bec0 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -27,6 +27,7 @@ #include "VISU_Convertor_impl.hxx" #include "VISU_ConvertorUtils.hxx" #include "VTKViewer_AppendFilter.h" +#include "VISU_MergeFilter.hxx" #include #include @@ -41,7 +42,6 @@ #include #include -#include #include #include @@ -57,8 +57,8 @@ static float ERR_SIZE_CALC = 1.00; static int MYVTKDEBUG = 0; #ifdef _DEBUG_ -static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; +static int MYDEBUG = 1; +static int MYDEBUGWITHFILES = 1; //#define _DEXCEPT_ #else static int MYDEBUG = 0; @@ -138,7 +138,7 @@ namespace VISU ::GetFilter() const { if(!myFilter.GetPointer()){ - myFilter = vtkMergeFilter::New(); + myFilter = VISU_MergeFilter::New(); myFilter->Delete(); } return myFilter; @@ -1282,7 +1282,6 @@ namespace { int aNbTuples = theField->myDataSize/theField->myNbComp; std::string aFieldName = GenerateFieldName(theField,theValForTime); - INITMSG(MYDEBUG,"GetTimeStampOnProfile - aNbTuples = "<myEntity){ @@ -1314,9 +1313,23 @@ namespace aDataArray->SetName("VISU_FIELD"); aDataSetAttributes->AddArray(aDataArray); + int aNbComp2 = aNbComp; + if(aNbComp == 4) + aNbComp2 = 2; + else if(aNbComp > 4) + aNbComp2 = 3; + + INITMSG(MYDEBUG,"GetTimeStampOnProfile "<< + "- aNbTuples = "<AddArray(aDataArray); + int aNbComp2 = aNbComp; + if(aNbComp == 4) + aNbComp2 = 2; + else if(aNbComp > 4) + aNbComp2 = 3; + + INITMSG(MYDEBUG,"GetTimeStampOnGaussMesh "<< + "- aNbTuples = "< TVTKSource; typedef vtkSmartPointer TVTKPoints; - typedef vtkSmartPointer TVTKMergeFilter; + typedef vtkSmartPointer TVTKMergeFilter; typedef vtkSmartPointer TVTKAppendFilter; diff --git a/src/CONVERTOR/VISU_MergeFilter.cxx b/src/CONVERTOR/VISU_MergeFilter.cxx new file mode 100644 index 00000000..aa48a46a --- /dev/null +++ b/src/CONVERTOR/VISU_MergeFilter.cxx @@ -0,0 +1,418 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#include "VISU_MergeFilter.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace VISU +{ + + class TFieldNode + { + public: + TFieldNode(const char* name, vtkDataSet* ptr=0) + { + int length = static_cast(strlen(name)); + if (length > 0) { + this->Name = new char[length+1]; + strcpy(this->Name, name); + } else { + this->Name = 0; + } + this->Ptr = ptr; + this->Next = 0; + } + ~TFieldNode() + { + delete[] this->Name; + } + + const char* GetName() + { + return Name; + } + vtkDataSet* Ptr; + TFieldNode* Next; + private: + TFieldNode(const TFieldNode&) {} + void operator=(const TFieldNode&) {} + char* Name; + }; + + class TFieldList + { + public: + TFieldList() + { + this->First = 0; + this->Last = 0; + } + ~TFieldList() + { + TFieldNode* node = this->First; + TFieldNode* next; + while(node){ + next = node->Next; + delete node; + node = next; + } + } + + + void Add(const char* name, vtkDataSet* ptr) + { + TFieldNode* newNode = new TFieldNode(name, ptr); + if (!this->First) { + this->First = newNode; + this->Last = newNode; + } else { + this->Last->Next = newNode; + this->Last = newNode; + } + } + + friend class TFieldListIterator; + + private: + TFieldNode* First; + TFieldNode* Last; + }; + + class TFieldListIterator + { + public: + TFieldListIterator(TFieldList* list) + { + this->List = list; + this->Position = 0; + } + void Begin() + { + this->Position = this->List->First; + } + void Next() + { + if (this->Position) { + this->Position = this->Position->Next; + } + } + int End() + { + return this->Position ? 0 : 1; + } + TFieldNode* Get() + { + return this->Position; + } + + private: + TFieldNode* Position; + TFieldList* List; + }; + +} + +//------------------------------------------------------------------------------ +vtkStandardNewMacro(VISU_MergeFilter); + +//------------------------------------------------------------------------------ + +// Create object with no input or output. +VISU_MergeFilter::VISU_MergeFilter() +{ + this->FieldList = new VISU::TFieldList; +} + +VISU_MergeFilter::~VISU_MergeFilter() +{ + delete this->FieldList; +} + +void VISU_MergeFilter::SetScalars(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(1, input); +} +vtkDataSet *VISU_MergeFilter::GetScalars() +{ + if (this->NumberOfInputs < 2) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[1]); +} + +void VISU_MergeFilter::SetVectors(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(2, input); +} +vtkDataSet *VISU_MergeFilter::GetVectors() +{ + if (this->NumberOfInputs < 3) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[2]); +} + +void VISU_MergeFilter::SetNormals(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(3, input); +} +vtkDataSet *VISU_MergeFilter::GetNormals() +{ + if (this->NumberOfInputs < 4) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[3]); +} + +void VISU_MergeFilter::SetTCoords(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(4, input); +} +vtkDataSet *VISU_MergeFilter::GetTCoords() +{ + if (this->NumberOfInputs < 5) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[4]); +} + +void VISU_MergeFilter::SetTensors(vtkDataSet *input) +{ + this->vtkProcessObject::SetNthInput(5, input); +} +vtkDataSet *VISU_MergeFilter::GetTensors() +{ + if (this->NumberOfInputs < 6) + { + return NULL; + } + return (vtkDataSet *)(this->Inputs[5]); +} + +void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input) +{ + this->FieldList->Add(name, input); +} + +void VISU_MergeFilter::Execute() +{ + vtkIdType numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0; + vtkIdType numTensors=0; + vtkIdType numCells, numCellScalars=0, numCellVectors=0, numCellNormals=0; + vtkIdType numCellTCoords=0, numCellTensors=0; + vtkPointData *pd; + vtkDataArray *scalars = NULL; + vtkDataArray *vectors = NULL; + vtkDataArray *normals = NULL; + vtkDataArray *tcoords = NULL; + vtkDataArray *tensors = NULL; + vtkCellData *cd; + vtkDataArray *cellScalars = NULL; + vtkDataArray *cellVectors = NULL; + vtkDataArray *cellNormals = NULL; + vtkDataArray *cellTCoords = NULL; + vtkDataArray *cellTensors = NULL; + vtkDataSet *output = this->GetOutput(); + vtkPointData *outputPD = output->GetPointData(); + vtkCellData *outputCD = output->GetCellData(); + + vtkDebugMacro(<<"Merging data!"); + + // geometry needs to be copied + output->CopyStructure(this->GetInput()); + if ( (numPts = this->GetInput()->GetNumberOfPoints()) < 1 ) + { + vtkWarningMacro(<<"Nothing to merge!"); + } + numCells = this->GetInput()->GetNumberOfCells(); + + if ( this->GetScalars() ) + { + pd = this->GetScalars()->GetPointData(); + scalars = pd->GetScalars(); + if ( scalars != NULL ) + { + numScalars = scalars->GetNumberOfTuples(); + } + cd = this->GetScalars()->GetCellData(); + cellScalars = cd->GetScalars(); + if ( cellScalars != NULL ) + { + numCellScalars = cellScalars->GetNumberOfTuples(); + } + } + + if ( this->GetVectors() ) + { + pd = this->GetVectors()->GetPointData(); + vectors = pd->GetVectors(); + if ( vectors != NULL ) + { + numVectors= vectors->GetNumberOfTuples(); + } + cd = this->GetVectors()->GetCellData(); + cellVectors = cd->GetVectors(); + if ( cellVectors != NULL ) + { + numCellVectors = cellVectors->GetNumberOfTuples(); + } + } + + if ( this->GetNormals() ) + { + pd = this->GetNormals()->GetPointData(); + normals = pd->GetNormals(); + if ( normals != NULL ) + { + numNormals= normals->GetNumberOfTuples(); + } + cd = this->GetNormals()->GetCellData(); + cellNormals = cd->GetNormals(); + if ( cellNormals != NULL ) + { + numCellNormals = cellNormals->GetNumberOfTuples(); + } + } + + if ( this->GetTCoords() ) + { + pd = this->GetTCoords()->GetPointData(); + tcoords = pd->GetTCoords(); + if ( tcoords != NULL ) + { + numTCoords= tcoords->GetNumberOfTuples(); + } + cd = this->GetTCoords()->GetCellData(); + cellTCoords = cd->GetTCoords(); + if ( cellTCoords != NULL ) + { + numCellTCoords = cellTCoords->GetNumberOfTuples(); + } + } + + if ( this->GetTensors() ) + { + pd = this->GetTensors()->GetPointData(); + tensors = pd->GetTensors(); + if ( tensors != NULL ) + { + numTensors = tensors->GetNumberOfTuples(); + } + cd = this->GetTensors()->GetCellData(); + cellTensors = cd->GetTensors(); + if ( cellTensors != NULL ) + { + numCellTensors = cellTensors->GetNumberOfTuples(); + } + } + + // merge data only if it is consistent + if ( numPts == numScalars ) + { + outputPD->SetScalars(scalars); + } + if ( numCells == numCellScalars ) + { + outputCD->SetScalars(cellScalars); + } + + if ( numPts == numVectors ) + { + outputPD->SetVectors(vectors); + } + if ( numCells == numCellVectors ) + { + outputCD->SetVectors(cellVectors); + } + + if ( numPts == numNormals ) + { + outputPD->SetNormals(normals); + } + if ( numCells == numCellNormals ) + { + outputCD->SetNormals(cellNormals); + } + + if ( numPts == numTCoords ) + { + outputPD->SetTCoords(tcoords); + } + if ( numCells == numCellTCoords ) + { + outputCD->SetTCoords(cellTCoords); + } + + if ( numPts == numTensors ) + { + outputPD->SetTensors(tensors); + } + if ( numCells == numCellTensors ) + { + outputCD->SetTensors(cellTensors); + } + + VISU::TFieldListIterator it(this->FieldList); + vtkDataArray* da; + const char* name; + vtkIdType num; + for(it.Begin(); !it.End() ; it.Next()) + { + pd = it.Get()->Ptr->GetPointData(); + cd = it.Get()->Ptr->GetCellData(); + name = it.Get()->GetName(); + if ( (da=pd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); + if (num == numPts) + { + outputPD->AddArray(da); + } + } + if ( (da=cd->GetArray(name)) ) + { + num = da->GetNumberOfTuples(); + if (num == numCells) // To fix a VTK bug + { + outputCD->AddArray(da); + } + } + } +} diff --git a/src/CONVERTOR/VISU_MergeFilter.hxx b/src/CONVERTOR/VISU_MergeFilter.hxx new file mode 100644 index 00000000..1d15cd3b --- /dev/null +++ b/src/CONVERTOR/VISU_MergeFilter.hxx @@ -0,0 +1,99 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// 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 +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef VISU_MergeFilter_H +#define VISU_MergeFilter_H + +#include + +namespace VISU +{ + class TFieldList; +} + +// Following class was redefined in order to fix VTK bug +// (see code for more details) + +class VISU_MergeFilter : public vtkDataSetToDataSetFilter +{ +public: + static VISU_MergeFilter *New(); + vtkTypeMacro(VISU_MergeFilter,vtkDataSetToDataSetFilter); + + // Description: + // Specify object from which to extract geometry information. + void SetGeometry(vtkDataSet *input) {this->SetInput(input);}; + vtkDataSet *GetGeometry() {return this->GetInput();}; + + // Description: + // Specify object from which to extract scalar information. + void SetScalars(vtkDataSet *); + vtkDataSet *GetScalars(); + + // Description: + // Set / get the object from which to extract vector information. + void SetVectors(vtkDataSet *); + vtkDataSet *GetVectors(); + + // Description: + // Set / get the object from which to extract normal information. + void SetNormals(vtkDataSet *); + vtkDataSet *GetNormals(); + + // Description: + // Set / get the object from which to extract texture coordinates + // information. + void SetTCoords(vtkDataSet *); + vtkDataSet *GetTCoords(); + + // Description: + // Set / get the object from which to extract tensor data. + void SetTensors(vtkDataSet *); + vtkDataSet *GetTensors(); + + // Description: + // Set the object from which to extract a field and the name + // of the field + void AddField(const char* name, vtkDataSet* input); + +protected: + VISU_MergeFilter(); + ~VISU_MergeFilter(); + + // Usual data generation method + void Execute(); + + VISU::TFieldList* FieldList; +private: + VISU_MergeFilter(const VISU_MergeFilter&); // Not implemented. + void operator=(const VISU_MergeFilter&); // Not implemented. +}; + +#endif + + -- 2.39.2