From 27b6ce163eacc99c98188a15c2defcad4a473ed0 Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 25 May 2007 12:39:22 +0000 Subject: [PATCH] Fix for bug NPAL15942 (Creation of vectors on group is incorrect). --- src/CONVERTOR/Makefile.in | 6 +- src/CONVERTOR/VISU_UsedPointsFilter.cxx | 108 ++++++++++++++++++ src/CONVERTOR/VISU_UsedPointsFilter.hxx | 46 ++++++++ src/PIPELINE/Makefile.in | 4 +- ...tsFilter.cxx => VISU_MaskPointsFilter.cxx} | 10 +- ...tsFilter.hxx => VISU_MaskPointsFilter.hxx} | 18 +-- src/PIPELINE/VISU_PipeLineUtils.hxx | 14 --- src/PIPELINE/VISU_StreamLinesPL.cxx | 6 +- src/PIPELINE/VISU_StreamLinesPL.hxx | 4 +- src/PIPELINE/VISU_VectorsPL.cxx | 38 ++++-- src/PIPELINE/VISU_VectorsPL.hxx | 4 + 11 files changed, 214 insertions(+), 44 deletions(-) create mode 100644 src/CONVERTOR/VISU_UsedPointsFilter.cxx create mode 100644 src/CONVERTOR/VISU_UsedPointsFilter.hxx rename src/PIPELINE/{VISU_UsedPointsFilter.cxx => VISU_MaskPointsFilter.cxx} (90%) rename src/PIPELINE/{VISU_UsedPointsFilter.hxx => VISU_MaskPointsFilter.hxx} (75%) diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in index 66e57008..ded3486e 100644 --- a/src/CONVERTOR/Makefile.in +++ b/src/CONVERTOR/Makefile.in @@ -41,7 +41,8 @@ EXPORT_HEADERS = \ VISU_MergeFilter.hxx \ VISU_AppendFilter.hxx \ VISU_ExtractUnstructuredGrid.hxx \ - VISU_CommonCellsFilter.hxx + VISU_CommonCellsFilter.hxx \ + VISU_UsedPointsFilter.hxx # Libraries targets @@ -55,7 +56,8 @@ LIB_SRC = \ VISU_MergeFilter.cxx \ VISU_AppendFilter.cxx \ VISU_MedConvertor.cxx \ - VISU_CommonCellsFilter.cxx + VISU_CommonCellsFilter.cxx \ + VISU_UsedPointsFilter.cxx # Executables targets BIN = VISUConvertor diff --git a/src/CONVERTOR/VISU_UsedPointsFilter.cxx b/src/CONVERTOR/VISU_UsedPointsFilter.cxx new file mode 100644 index 00000000..8392385f --- /dev/null +++ b/src/CONVERTOR/VISU_UsedPointsFilter.cxx @@ -0,0 +1,108 @@ +// VISU CONVERTOR : +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : VISU_UsedPointsFilter.cxx +// Author : +// Module : VISU + + +#include "VISU_UsedPointsFilter.hxx" + +#include +#include +#include +#include +#include +#include + +#include + +vtkStandardNewMacro(VISU_UsedPointsFilter); + + +VISU_UsedPointsFilter::VISU_UsedPointsFilter() +{ +} + +VISU_UsedPointsFilter::~VISU_UsedPointsFilter() +{ +} + +void VISU_UsedPointsFilter::Execute(){ + vtkDataSet *anInput = this->GetInput(); + vtkUnstructuredGrid *anOutput = this->GetOutput(); + + typedef std::map TId2IdMap; + TId2IdMap aId2IdMap; + + vtkPointData *aPointData = anOutput->GetPointData(); + aPointData->CopyAllocate(anInput->GetPointData()); + + vtkPoints* aUsedPoints = vtkPoints::New(); + vtkIdList *anIdList = vtkIdList::New(); + vtkIdType iEnd = anInput->GetNumberOfPoints(); + for(vtkIdType aPointId = 0; aPointId < iEnd; aPointId++){ + anInput->GetPointCells(aPointId,anIdList); + if(anIdList->GetNumberOfIds() > 0){ + vtkIdType aNewPointId = aUsedPoints->InsertNextPoint(anInput->GetPoint(aPointId)); + aPointData->CopyData(anInput->GetPointData(), aPointId, aNewPointId); + aId2IdMap[aPointId] = aNewPointId; + } + } + aPointData->Squeeze(); + anOutput->SetPoints(aUsedPoints); + aUsedPoints->Delete(); + anIdList->Delete(); + + vtkCellData *aCellData = anOutput->GetCellData(); + aCellData->CopyAllocate(anInput->GetCellData()); + + anOutput->Allocate(anInput->GetNumberOfCells()); + vtkIdList *anOldPointsIds = vtkIdList::New(); + vtkIdList *aNewPointsIds = vtkIdList::New(); + aNewPointsIds->Allocate(VTK_CELL_SIZE); + iEnd = anInput->GetNumberOfCells(); + for(vtkIdType aCellId = 0; aCellId < iEnd; aCellId++){ + anInput->GetCellPoints(aCellId, anOldPointsIds); + vtkIdType aNbPointsInCell = anOldPointsIds->GetNumberOfIds(); + aNewPointsIds->Reset(); + for(vtkIdType i = 0; i < aNbPointsInCell; i++){ + vtkIdType anOldId = anOldPointsIds->GetId(i); + TId2IdMap::iterator anIter = aId2IdMap.find(anOldId); + if(anIter == aId2IdMap.end()) + goto NEXT_CELL; + vtkIdType aNewId = anIter->second; + aNewPointsIds->InsertNextId(aNewId); + } + { + vtkIdType aNewCellId = anOutput->InsertNextCell(anInput->GetCellType(aCellId), aNewPointsIds); + aCellData->CopyData(anInput->GetCellData(), aCellId, aNewCellId); + } + NEXT_CELL: + continue; + } + aCellData->Squeeze(); + anOldPointsIds->Delete(); + aNewPointsIds->Delete(); + anOutput->Squeeze(); +} + diff --git a/src/CONVERTOR/VISU_UsedPointsFilter.hxx b/src/CONVERTOR/VISU_UsedPointsFilter.hxx new file mode 100644 index 00000000..a6e082f2 --- /dev/null +++ b/src/CONVERTOR/VISU_UsedPointsFilter.hxx @@ -0,0 +1,46 @@ +// VISU CONVERTOR : +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : VISU_UsedPointsFilter.hxx +// Author : +// Module : VISU + +#ifndef VISU_UsedPointsFilter_HeaderFile +#define VISU_UsedPointsFilter_HeaderFile + +#include + +class VISU_UsedPointsFilter : public vtkDataSetToUnstructuredGridFilter +{ +public: + vtkTypeMacro(VISU_UsedPointsFilter,vtkDataSetToUnstructuredGridFilter); + static VISU_UsedPointsFilter *New(); + +protected: + VISU_UsedPointsFilter(); + ~VISU_UsedPointsFilter(); + + virtual void Execute(); +}; + +#endif + diff --git a/src/PIPELINE/Makefile.in b/src/PIPELINE/Makefile.in index 690882d6..ea47ffc3 100644 --- a/src/PIPELINE/Makefile.in +++ b/src/PIPELINE/Makefile.in @@ -47,7 +47,7 @@ EXPORT_HEADERS = \ VISU_ScalarBarActor.hxx \ VISU_Extractor.hxx \ VISU_FieldTransform.hxx \ - VISU_UsedPointsFilter.hxx \ + VISU_MaskPointsFilter.hxx \ VISU_GaussPointsPL.hxx \ VISU_Plot3DPL.hxx \ VISU_OpenGLPointSpriteMapper.hxx \ @@ -79,7 +79,7 @@ LIB_SRC = \ VISU_ScalarBarActor.cxx \ VISU_Extractor.cxx \ VISU_FieldTransform.cxx \ - VISU_UsedPointsFilter.cxx \ + VISU_MaskPointsFilter.cxx \ VISU_GaussPointsPL.cxx \ VISU_Plot3DPL.cxx \ SALOME_ExtractGeometry.cxx \ diff --git a/src/PIPELINE/VISU_UsedPointsFilter.cxx b/src/PIPELINE/VISU_MaskPointsFilter.cxx similarity index 90% rename from src/PIPELINE/VISU_UsedPointsFilter.cxx rename to src/PIPELINE/VISU_MaskPointsFilter.cxx index 9c49ea25..c879e29c 100644 --- a/src/PIPELINE/VISU_UsedPointsFilter.cxx +++ b/src/PIPELINE/VISU_MaskPointsFilter.cxx @@ -25,7 +25,7 @@ // Module : VISU -#include "VISU_UsedPointsFilter.hxx" +#include "VISU_MaskPointsFilter.hxx" #include #include @@ -34,15 +34,15 @@ #include #include -vtkStandardNewMacro(VISU_UsedPointsFilter); +vtkStandardNewMacro(VISU_MaskPointsFilter); -VISU_UsedPointsFilter::VISU_UsedPointsFilter(){ +VISU_MaskPointsFilter::VISU_MaskPointsFilter(){ PercentsOfUsedPoints = 1.0; } -VISU_UsedPointsFilter::~VISU_UsedPointsFilter(){} +VISU_MaskPointsFilter::~VISU_MaskPointsFilter(){} -void VISU_UsedPointsFilter::Execute(){ +void VISU_MaskPointsFilter::Execute(){ vtkPointSet *anInput = this->GetInput(), *anOutput = this->GetOutput(); anOutput->GetPointData()->CopyAllOff(); anOutput->GetCellData()->CopyAllOff(); diff --git a/src/PIPELINE/VISU_UsedPointsFilter.hxx b/src/PIPELINE/VISU_MaskPointsFilter.hxx similarity index 75% rename from src/PIPELINE/VISU_UsedPointsFilter.hxx rename to src/PIPELINE/VISU_MaskPointsFilter.hxx index dd20877a..38d87923 100644 --- a/src/PIPELINE/VISU_UsedPointsFilter.hxx +++ b/src/PIPELINE/VISU_MaskPointsFilter.hxx @@ -20,27 +20,27 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // -// File: VISU_UsedPointsFilter.hxx +// File: VISU_MaskPointsFilter.hxx // Author: Alexey PETROV // Module : VISU -#ifndef VISU_UsedPointsFilter_HeaderFile -#define VISU_UsedPointsFilter_HeaderFile +#ifndef VISU_MaskPointsFilter_HeaderFile +#define VISU_MaskPointsFilter_HeaderFile #include -class VISU_UsedPointsFilter : public vtkPointSetToPointSetFilter{ +class VISU_MaskPointsFilter : public vtkPointSetToPointSetFilter{ protected: - VISU_UsedPointsFilter(); - VISU_UsedPointsFilter(const VISU_UsedPointsFilter&); + VISU_MaskPointsFilter(); + VISU_MaskPointsFilter(const VISU_MaskPointsFilter&); virtual void Execute(); float PercentsOfUsedPoints; public: - vtkTypeMacro(VISU_UsedPointsFilter,vtkPointSetToPointSetFilter); - static VISU_UsedPointsFilter* New(); - virtual ~VISU_UsedPointsFilter(); + vtkTypeMacro(VISU_MaskPointsFilter,vtkPointSetToPointSetFilter); + static VISU_MaskPointsFilter* New(); + virtual ~VISU_MaskPointsFilter(); vtkSetMacro(PercentsOfUsedPoints,float); vtkGetMacro(PercentsOfUsedPoints,float); diff --git a/src/PIPELINE/VISU_PipeLineUtils.hxx b/src/PIPELINE/VISU_PipeLineUtils.hxx index 1056358d..a866171d 100644 --- a/src/PIPELINE/VISU_PipeLineUtils.hxx +++ b/src/PIPELINE/VISU_PipeLineUtils.hxx @@ -81,20 +81,6 @@ namespace VISU }else theOutputFilter->SetInput(theDataSet); } - - template - void - ToCellCenters(TOutputFilter* theOutputFilter, - vtkCellCenters *theCellCenters, - vtkPointSet* theDataSet) - { - if(VISU::IsDataOnCells(theDataSet)){ - theCellCenters->SetInput(theDataSet); - theCellCenters->VertexCellsOn(); - theOutputFilter->SetInput(theCellCenters->GetOutput()); - }else - theOutputFilter->SetInput(theDataSet); - } } #endif diff --git a/src/PIPELINE/VISU_StreamLinesPL.cxx b/src/PIPELINE/VISU_StreamLinesPL.cxx index 65d48171..42261300 100644 --- a/src/PIPELINE/VISU_StreamLinesPL.cxx +++ b/src/PIPELINE/VISU_StreamLinesPL.cxx @@ -27,7 +27,7 @@ #include "VISU_StreamLinesPL.hxx" #include "VISU_PipeLineUtils.hxx" -#include "VISU_UsedPointsFilter.hxx" +#include "VISU_MaskPointsFilter.hxx" #include "VTKViewer_GeometryFilter.h" #include @@ -55,7 +55,7 @@ VISU_StreamLinesPL::VISU_StreamLinesPL(){ myStream = vtkStreamLine::New(); myCenters = vtkCellCenters::New(); myGeomFilter = VTKViewer_GeometryFilter::New(); - myPointsFilter = VISU_UsedPointsFilter::New(); + myPointsFilter = VISU_MaskPointsFilter::New(); myPercents = 0.3; mySource = NULL; } @@ -246,7 +246,7 @@ VISU_StreamLinesPL { vtkFloatingPointType aStepLength = GetBaseStepLength(theDataSet); vtkFloatingPointType aBasePropTime = GetBasePropagationTime(theDataSet); - VISU_UsedPointsFilter *aPointsFilter = VISU_UsedPointsFilter::New(); + VISU_MaskPointsFilter *aPointsFilter = VISU_MaskPointsFilter::New(); aPointsFilter->SetInput(theDataSet); vtkPointSet* aDataSet = aPointsFilter->GetOutput(); aDataSet->Update(); diff --git a/src/PIPELINE/VISU_StreamLinesPL.hxx b/src/PIPELINE/VISU_StreamLinesPL.hxx index ed1bf9b2..e5f22208 100644 --- a/src/PIPELINE/VISU_StreamLinesPL.hxx +++ b/src/PIPELINE/VISU_StreamLinesPL.hxx @@ -35,7 +35,7 @@ using namespace std; class vtkPointSet; class vtkCellCenters; class VTKViewer_GeometryFilter; -class VISU_UsedPointsFilter; +class VISU_MaskPointsFilter; class VISU_StreamLinesPL : public VISU_DeformedShapePL { @@ -230,7 +230,7 @@ protected: vtkPointSet* mySource; vtkCellCenters* myCenters; VTKViewer_GeometryFilter *myGeomFilter; - VISU_UsedPointsFilter *myPointsFilter; + VISU_MaskPointsFilter *myPointsFilter; vtkFloatingPointType myPercents; }; diff --git a/src/PIPELINE/VISU_VectorsPL.cxx b/src/PIPELINE/VISU_VectorsPL.cxx index d772d9bd..4ba01227 100644 --- a/src/PIPELINE/VISU_VectorsPL.cxx +++ b/src/PIPELINE/VISU_VectorsPL.cxx @@ -27,6 +27,7 @@ #include "VISU_VectorsPL.hxx" #include "VISU_PipeLineUtils.hxx" +#include "VISU_UsedPointsFilter.hxx" #include "VTKViewer_TransformFilter.h" #include "VTKViewer_Transform.h" @@ -38,6 +39,23 @@ vtkStandardNewMacro(VISU_VectorsPL); +template +void ToCellCenters(TOutputFilter *theOutputFilter, + vtkCellCenters *theCellCenters, + vtkPointSet* theDataSet, + VISU_UsedPointsFilter* theUsedPointsFilter) +{ + if(VISU::IsDataOnCells(theDataSet)){ + theCellCenters->SetInput(theDataSet); + theCellCenters->VertexCellsOn(); + theOutputFilter->SetInput(theCellCenters->GetOutput()); + }else { + theUsedPointsFilter->SetInput(theDataSet); + theOutputFilter->SetInput(theUsedPointsFilter->GetOutput()); + } +} + + VISU_VectorsPL ::VISU_VectorsPL() { @@ -51,6 +69,8 @@ VISU_VectorsPL myCenters = vtkCellCenters::New(); myTransformFilter = VTKViewer_TransformFilter::New(); myIsShrinkable = false; + + myUsedPointsFilter = VISU_UsedPointsFilter::New(); } VISU_VectorsPL @@ -68,6 +88,8 @@ VISU_VectorsPL myLineSource->Delete(); myTransformFilter->Delete(); + + myUsedPointsFilter->Delete(); } void @@ -147,17 +169,19 @@ VISU_VectorsPL ::Build() { Superclass::Build(); - - VISU::ToCellCenters(myBaseGlyph, - myCenters, - GetMergedInput()); + + ToCellCenters(myBaseGlyph, + myCenters, + GetMergedInput(), + myUsedPointsFilter); myBaseGlyph->SetVectorModeToUseVector(); myBaseGlyph->SetScaleModeToScaleByVector(); myBaseGlyph->SetColorModeToColorByScalar(); - VISU::ToCellCenters(myTransformFilter, - myCenters, - GetMergedInput()); + ToCellCenters(myTransformFilter, + myCenters, + GetMergedInput(), + myUsedPointsFilter); myTransformedGlyph->SetInput(myTransformFilter->GetOutput()); myTransformedGlyph->SetVectorModeToUseVector(); myTransformedGlyph->SetScaleModeToScaleByVector(); diff --git a/src/PIPELINE/VISU_VectorsPL.hxx b/src/PIPELINE/VISU_VectorsPL.hxx index 5245650f..2130b3a3 100644 --- a/src/PIPELINE/VISU_VectorsPL.hxx +++ b/src/PIPELINE/VISU_VectorsPL.hxx @@ -39,6 +39,8 @@ class vtkLineSource; class vtkGlyph3D; +class VISU_UsedPointsFilter; + class VISU_VectorsPL : public VISU_DeformedShapePL { protected: @@ -143,6 +145,8 @@ protected: vtkCellCenters* myCenters; VTKViewer_TransformFilter *myTransformFilter; + + VISU_UsedPointsFilter* myUsedPointsFilter; }; -- 2.39.2