From: rnv Date: Wed, 25 Jun 2008 10:16:58 +0000 (+0000) Subject: Implementation of the improvement 0016840 "EDF PAL 569: Cut plane on Deformed". X-Git-Tag: V4_1_0_maintainance_20080626~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17f10e0b2b9351439fa77ce397f58ecad60c1483;p=modules%2Fvisu.git Implementation of the improvement 0016840 "EDF PAL 569: Cut plane on Deformed". --- diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index f79261a4..36b383b4 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -874,6 +874,61 @@ module VISU { }; + //------------------------------------------------------- + /*! \brief Deformation interface + * + * This is base interface for building of the deformed presentations + */ + interface Deformation{ + /*! + * Sets the scale of the presentatable object. + * \param theScale Double value defining the scale of this presentable object. + */ + void SetScale(in double theScale); + + /*! + * Gets the scale of the presentatable object. + */ + double GetScale(); + + /*! + * Sets the vectorial field + * \param theEntity - entity of vectorial field + * \param theFieldName - the name of vectorial field + */ + void SetVectorialField(in Entity theEntity, + in string theFieldName); + + /*! + * Get vectorial entity + */ + Entity GetVectorialFieldEntity(); + + /*! + * Get scalar field name + */ + string GetVectorialFieldName(); + + }; + + //------------------------------------------------------- + /*! \brief OptionalDeformation interface + * + * This is interface for switch on/off of the deformation of the presentation + */ + interface OptionalDeformation : Deformation{ + + /*! + * Sets the deformation flag of the presentatable object. + * \param theFlag Boolean value defining the deformation flag of this presentable object. + */ + void UseDeformation(in boolean theFlag); + + /*! + * Gets the deformation flag of the presentatable object. + */ + boolean IsDeformed(); + }; //------------------------------------------------------- /*! \brief Scalar Map on Deformed shape presentation interface @@ -1090,7 +1145,7 @@ module VISU { * consists of cutting your initial mesh by a definite number of planes. As the * result you will see these planes which will be cutted by the borders of the mesh. */ - interface CutPlanes : ScalarMap { + interface CutPlanes : ScalarMap, OptionalDeformation { /*! * This enumeration contains a set of elements defining the type of orientation in 3D space * of the cut planes. diff --git a/src/CONVERTOR/VISU_MergeFilterUtilities.cxx b/src/CONVERTOR/VISU_MergeFilterUtilities.cxx index 48846369..2d1eafc2 100644 --- a/src/CONVERTOR/VISU_MergeFilterUtilities.cxx +++ b/src/CONVERTOR/VISU_MergeFilterUtilities.cxx @@ -81,6 +81,9 @@ namespace vtkCellData *anOutputCellData = theOutput->GetCellData(); anOutputCellData->CopyAllocate(aCellData); + if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet) + anOutputCellData->CopyVectorsOff(); + vtkIdType aNbTuples = anIntersection.size(); theOutput->Allocate(aNbTuples); vtkIdList *aCellIds = vtkIdList::New(); @@ -100,13 +103,68 @@ namespace aCellIds->Delete(); theOutput->SetPoints(theInput->GetPoints()); + }else{ theOutput->CopyStructure(theInput); theOutput->GetCellData()->ShallowCopy(theScalarsDataSet->GetCellData()); } theOutput->GetPointData()->ShallowCopy(theInput->GetPointData()); + + //If need, copy vectors data. + if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet){ + bool isVectorsOnCells = theVectorsDataSet->GetCellData()->GetVectors() != NULL; + bool isVectorsDataOnPoints = theVectorsDataSet->GetPointData()->GetVectors() != NULL; + if(isVectorsOnCells) { + CopyVectorsOnCells(theVectorsDataSet,theOutput); + } + else if(isVectorsDataOnPoints){ + CopyVectorsOnPoints(theVectorsDataSet,theOutput); + } + } } + void CopyVectorsOnCells(vtkDataSet *theVectorsDataSet, + vtkDataSet *theOutput) + { + vtkDataArray *anInputVectors = theVectorsDataSet->GetCellData()->GetVectors(); + vtkDataArray *anOutputVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType()); + + //Clear output vector data + theOutput->GetCellData()->SetVectors(NULL); + + //Copy vectors data + vtkIntArray* anOutputIDMapper = GetIDMapper(theOutput, + TGetCellData(), + "VISU_CELLS_MAPPER"); + + vtkIntArray* anInputIDMapper = GetIDMapper(theVectorsDataSet, + TGetCellData(), + "VISU_CELLS_MAPPER"); + + TObjectIdArray anIntersection; + GetIntersection(anOutputIDMapper, + anInputIDMapper, + anIntersection); + + vtkIdType aNbTuples = anIntersection.size(); + anOutputVectors->SetNumberOfComponents(anInputVectors->GetNumberOfComponents()); + anOutputVectors->SetNumberOfTuples(aNbTuples); + theOutput->GetCellData()->SetVectors(anOutputVectors); + anOutputVectors->Delete(); + + TObjectId2TupleIdMap anOutputObjectId2TupleIdMap; + GetObjectId2TupleIdMap(anOutputIDMapper, anOutputObjectId2TupleIdMap); + + TObjectId2TupleIdMap anInputObjectId2TupleIdMap; + GetObjectId2TupleIdMap(anInputIDMapper, anInputObjectId2TupleIdMap); + + for(vtkIdType iTupleId = 0; iTupleId < aNbTuples; iTupleId++ ){ + TObjectId &anObjectId = anIntersection[iTupleId]; + vtkIdType anOutputCellId = anOutputObjectId2TupleIdMap[anObjectId]; + vtkIdType anInputCellId = anInputObjectId2TupleIdMap[anObjectId]; + anOutputVectors->SetTuple(anOutputCellId,anInputVectors->GetTuple(anInputCellId)); + } + } //--------------------------------------------------------------- template @@ -200,7 +258,118 @@ namespace theOutput->GetCellData()->ShallowCopy(theInput->GetCellData()); } theOutput->GetPointData()->ShallowCopy(theScalarsDataSet->GetPointData()); + + //If need, copy vectors data. + if(theVectorsDataSet && theVectorsDataSet != theScalarsDataSet){ + bool isVectorsOnCells = theVectorsDataSet->GetCellData()->GetVectors() != NULL; + bool isVectorsDataOnPoints = theVectorsDataSet->GetPointData()->GetVectors() != NULL; + + //Merge cells if need + //rnv + if(!IsDifferent(theGeometryPointMapper, theDataPointMapper)){ + vtkIntArray* theGeometryCellMapper = GetIDMapper(theVectorsDataSet, + TGetCellData(), + "VISU_CELLS_MAPPER"); + + vtkIntArray* theDataCellMapper = GetIDMapper(theScalarsDataSet, + TGetCellData(), + "VISU_CELLS_MAPPER"); + + + if(IsDifferent(theGeometryCellMapper, theDataCellMapper)){ + TObjectIdArray anIntersection; + + GetIntersection(theGeometryCellMapper, + theDataCellMapper, + anIntersection); + + TObjectId2TupleIdMap aGeomObjectId2TupleIdMap; + GetObjectId2TupleIdMap(theGeometryCellMapper, aGeomObjectId2TupleIdMap); + + TObjectId2TupleIdMap aDataObjectId2TupleIdMap; + GetObjectId2TupleIdMap(theDataCellMapper, aDataObjectId2TupleIdMap); + + vtkCellData *aCellData = theScalarsDataSet->GetCellData(); + vtkCellData *anOutputCellData = theOutput->GetCellData(); + anOutputCellData->CopyAllocate(aCellData); + + vtkIdType aNbTuples = anIntersection.size(); + theOutput->Allocate(aNbTuples); + vtkIdList *aCellIds = vtkIdList::New(); + for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){ + TObjectId& anObjectId = anIntersection[aTupleId]; + vtkIdType aCellId = aGeomObjectId2TupleIdMap[anObjectId]; + vtkCell *aCell = theInput->GetCell(aCellId); + aCellIds->Reset(); + vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds(); + for(vtkIdType anId = 0; anId < aNbPointIds; anId++) + aCellIds->InsertNextId(aCell->GetPointIds()->GetId(anId)); + vtkIdType aCellType = theInput->GetCellType(aCellId); + vtkIdType aNewCellId = theOutput->InsertNextCell(aCellType, aCellIds); + vtkIdType aDataCellId = aDataObjectId2TupleIdMap[anObjectId]; + anOutputCellData->CopyData(aCellData, aDataCellId, aNewCellId); + } + aCellIds->Delete(); + + } + } + + if(isVectorsOnCells) { + CopyVectorsOnCells(theVectorsDataSet,theOutput); + } + else if(isVectorsDataOnPoints){ + CopyVectorsOnPoints(theVectorsDataSet,theOutput); + } + } } + + void CopyVectorsOnPoints(vtkDataSet *theVectorsDataSet, + vtkDataSet *theOutput) + { + vtkDataArray *anInputVectors = theVectorsDataSet->GetPointData()->GetVectors(); + + //Clear output vector data + theOutput->GetPointData()->SetVectors(NULL); + + vtkDataArray *anOutputVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType()); + + //Copy vectors data + vtkIntArray* anOutputIDMapper = GetIDMapper(theOutput, + TGetPointData(), + "VISU_POINTS_MAPPER"); + + vtkIntArray* anInputIDMapper = GetIDMapper(theVectorsDataSet, + TGetPointData(), + "VISU_POINTS_MAPPER"); + TObjectIdArray anIntersection; + + GetIntersection(anOutputIDMapper, + anInputIDMapper, + anIntersection); + + vtkIdType aNbTuples = anIntersection.size(); + anOutputVectors->SetNumberOfComponents(anInputVectors->GetNumberOfComponents()); + anOutputVectors->SetNumberOfTuples(aNbTuples); + + + + TObjectId2TupleIdMap anOutputObjectId2TupleIdMap; + GetObjectId2TupleIdMap(anOutputIDMapper, anOutputObjectId2TupleIdMap); + + TObjectId2TupleIdMap anInputObjectId2TupleIdMap; + GetObjectId2TupleIdMap(anInputIDMapper, anInputObjectId2TupleIdMap); + + for(vtkIdType iTupleId = 0; iTupleId < aNbTuples; iTupleId++ ){ + TObjectId& anObjectId = anIntersection[iTupleId]; + vtkIdType anOutputPointId = anOutputObjectId2TupleIdMap[anObjectId]; + vtkIdType anInputPointId = anInputObjectId2TupleIdMap[anObjectId]; + anOutputVectors->SetTuple(anOutputPointId,anInputVectors->GetTuple(anInputPointId)); + } + + theOutput->GetPointData()->SetVectors(anOutputVectors); + anOutputVectors->Delete(); + } + //--------------------------------------------------------------- typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)(); diff --git a/src/PIPELINE/Makefile.am b/src/PIPELINE/Makefile.am index 5a3a1308..9fe94fa0 100644 --- a/src/PIPELINE/Makefile.am +++ b/src/PIPELINE/Makefile.am @@ -67,7 +67,9 @@ salomeinclude_HEADERS= \ VISUPipeline.hxx \ VISU_LabelPointsFilter.hxx \ VISU_ElnoDisassembleFilter.hxx \ - VISU_ElnoAssembleFilter.hxx + VISU_ElnoAssembleFilter.hxx \ + VISU_DeformationPL.hxx \ + VISU_OptionalDeformationPL.hxx dist_libVisuPipeLine_la_SOURCES= \ VISU_MapperHolder.cxx \ @@ -107,7 +109,9 @@ dist_libVisuPipeLine_la_SOURCES= \ VISU_DeformedShapeAndScalarMapPL.cxx \ VISU_LabelPointsFilter.cxx \ VISU_ElnoDisassembleFilter.cxx \ - VISU_ElnoAssembleFilter.cxx + VISU_ElnoAssembleFilter.cxx \ + VISU_DeformationPL.cxx \ + VISU_OptionalDeformationPL.cxx libVisuPipeLine_la_CPPFLAGS= \ $(VTK_INCLUDES) \ diff --git a/src/PIPELINE/VISU_CutLinesPL.cxx b/src/PIPELINE/VISU_CutLinesPL.cxx index 3bad32d1..dbd2243a 100644 --- a/src/PIPELINE/VISU_CutLinesPL.cxx +++ b/src/PIPELINE/VISU_CutLinesPL.cxx @@ -100,6 +100,12 @@ VISU_CutLinesPL Modified(); } +vtkDataSet* +VISU_CutLinesPL +::InsertCustomPL() +{ + return myAppendPolyData->GetOutput(); +} //---------------------------------------------------------------------------- vtkFloatingPointType diff --git a/src/PIPELINE/VISU_CutLinesPL.hxx b/src/PIPELINE/VISU_CutLinesPL.hxx index 58116834..7ed0ecd8 100644 --- a/src/PIPELINE/VISU_CutLinesPL.hxx +++ b/src/PIPELINE/VISU_CutLinesPL.hxx @@ -64,6 +64,9 @@ public: void Init(); + vtkDataSet* + InsertCustomPL(); + virtual void Update(); diff --git a/src/PIPELINE/VISU_CutPlanesPL.cxx b/src/PIPELINE/VISU_CutPlanesPL.cxx index 6928b498..a8776eaf 100644 --- a/src/PIPELINE/VISU_CutPlanesPL.cxx +++ b/src/PIPELINE/VISU_CutPlanesPL.cxx @@ -29,13 +29,23 @@ #include "VISU_FieldTransform.hxx" #include "VISU_PipeLineUtils.hxx" #include "VTKViewer_GeometryFilter.h" +#include "VISU_MapperHolder.hxx" +#include "VISU_DeformationPL.hxx" #include #include #include +//#include + static vtkFloatingPointType EPS = 1.0E-3; +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + //---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_CutPlanesPL); @@ -43,8 +53,11 @@ vtkStandardNewMacro(VISU_CutPlanesPL); //---------------------------------------------------------------------------- VISU_CutPlanesPL -::VISU_CutPlanesPL() +::VISU_CutPlanesPL(): + VISU_OptionalDeformationPL() { + if(MYDEBUG) MESSAGE("VISU_CutPlanesPL()::VISU_CutPlanesPL() - "<Delete(); myAppendPolyData = NULL; } @@ -78,7 +93,11 @@ VISU_CutPlanesPL ::GetMTime() { unsigned long int aTime = Superclass::GetMTime(); - + + if(IsDeformed()) { + aTime = std::max(aTime, VISU_OptionalDeformationPL::GetMTime()); + } + aTime = std::max(aTime, myAppendPolyData->GetMTime()); return aTime; @@ -115,11 +134,11 @@ VISU_CutPlanesPL ::Init() { Superclass::Init(); - SetNbParts(10); myBasePlane[0] = YZ; myDisplacement[0] = 0.5; myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0; + SetScale(VISU_DeformationPL::GetDefaultScaleFactor(this)); } @@ -128,7 +147,7 @@ vtkDataSet* VISU_CutPlanesPL ::InsertCustomPL() { - return myAppendPolyData->GetOutput(); + return GetWarpVectorOutput(); } @@ -139,18 +158,32 @@ VISU_CutPlanesPL { ClearAppendPolyData(myAppendPolyData); - SetPartPosition(); + if(!myVectorialField || !IsDeformed()){ + SetMergeFilterInput(GetMergedInput(),GetMergedInput()); + } + + + if(VISU::IsDataOnCells(GetMergedInput())) + GetMapper()->SetScalarModeToUseCellData(); + else + GetMapper()->SetScalarModeToUsePointData(); + + SetPartPosition(); + vtkFloatingPointType aDir[3]; GetDir(aDir, myAng[0], myBasePlane[0]); - + vtkFloatingPointType aBounds[6]; - GetMergedInput()->GetBounds(aBounds); + + vtkDataSet* aFilterOutput = GetMergeFilterOutput(); + + aFilterOutput->GetBounds(aBounds); CutWithPlanes(myAppendPolyData, - GetMergedInput(), + aFilterOutput, myNbParts, aDir, aBounds, @@ -158,6 +191,9 @@ VISU_CutPlanesPL myPartCondition, myDisplacement[0]); + + + SetWarpVectorInput(myAppendPolyData->GetOutput()); Superclass::Update(); } @@ -414,7 +450,11 @@ VISU_CutPlanesPL vtkFloatingPointType aPosition = myPartPosition[thePartNumber]; if(myPartCondition[thePartNumber]){ vtkFloatingPointType aDir[3], aBounds[6], aBoundPrj[3]; - GetMergedInput()->GetBounds(aBounds); + if(!IsDeformed()) + GetMergedInput()->GetBounds(aBounds); + else + GetMergeFilterOutput()->GetBounds(aBounds); + GetDir(aDir, myAng[theNum], @@ -566,3 +606,33 @@ VISU_CutPlanesPL //---------------------------------------------------------------------------- +void +VISU_CutPlanesPL::SetVectorialField(VISU::PUnstructuredGridIDMapper theMapper) +{ + if(myVectorialField == theMapper) + return; + + if(CheckCanDeformate(theMapper->GetOutput())){ + myVectorialField = theMapper; + + SetMergeFilterInput(GetMergedInput(),theMapper->GetOutput()); + } + else + UseDeformation(false); + + Modified(); +} + +//---------------------------------------------------------------------------- +VISU::PUnstructuredGridIDMapper VISU_CutPlanesPL:: +getVectorialField() +{ + return myVectorialField; +} + +//---------------------------------------------------------------------------- +void VISU_CutPlanesPL::SetMapScale(vtkFloatingPointType theMapScale){ + Superclass::SetMapScale(theMapScale); + if(IsDeformed()) + VISU_OptionalDeformationPL::SetMapScale(theMapScale); +} diff --git a/src/PIPELINE/VISU_CutPlanesPL.hxx b/src/PIPELINE/VISU_CutPlanesPL.hxx index 27d377fd..054b8761 100644 --- a/src/PIPELINE/VISU_CutPlanesPL.hxx +++ b/src/PIPELINE/VISU_CutPlanesPL.hxx @@ -29,6 +29,8 @@ #include "VISUPipeline.hxx" #include "VISU_ScalarMapPL.hxx" +#include "VISU_OptionalDeformationPL.hxx" +#include "VISU_MapperHolder.hxx" #include @@ -36,7 +38,8 @@ class vtkAppendPolyData; //---------------------------------------------------------------------------- -class VISU_PIPELINE_EXPORT VISU_CutPlanesPL : public VISU_ScalarMapPL +class VISU_PIPELINE_EXPORT VISU_CutPlanesPL : public VISU_ScalarMapPL, + public VISU_OptionalDeformationPL { public: vtkTypeMacro(VISU_CutPlanesPL, VISU_ScalarMapPL); @@ -182,6 +185,14 @@ public: const std::vector& thePlaneCondition, vtkFloatingPointType theDisplacement); + virtual void SetVectorialField(VISU::PUnstructuredGridIDMapper); + VISU::PUnstructuredGridIDMapper getVectorialField(); + + virtual + void + SetMapScale(vtkFloatingPointType theMapScale = 1.0); + + protected: VISU_CutPlanesPL(); diff --git a/src/PIPELINE/VISU_DeformationPL.cxx b/src/PIPELINE/VISU_DeformationPL.cxx new file mode 100755 index 00000000..2189b228 --- /dev/null +++ b/src/PIPELINE/VISU_DeformationPL.cxx @@ -0,0 +1,163 @@ +// Copyright (C) 2008 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_ScalarMapPL.cxx +// Author: Roman NIKOLAEV +// Module : VISU + +//Salome includes +#include "VISU_DeformationPL.hxx" +#include "VISU_MergeFilter.hxx" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_PipeLineUtils.hxx" + +//VTK includes +#include +#include +#include +#include +#include +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//---------------------------------------------------------------------------- +VISU_DeformationPL::VISU_DeformationPL(): + myScaleFactor(1.0), + myMapScaleFactor(1.0) +{ + if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<SetScaleFactor(myScaleFactor); + + myVectorMergeFilter = VISU_MergeFilter::New(); + myVectorMergeFilter->SetMergingInputs(true); + myInputPassFilter = vtkPassThroughFilter::New(); + myOutputPassFiler = vtkPassThroughFilter::New(); + myCellDataToPointData = vtkCellDataToPointData::New(); + myCellDataToPointData->PassCellDataOn(); + + myInputPassFilter->SetInput(vtkUnstructuredGrid::New()); + + myCellDataToPointData->SetInput(myInputPassFilter->GetOutput()); + + myWarpVector->SetInput(myCellDataToPointData->GetOutput()); + + myOutputPassFiler->SetInput(myWarpVector->GetOutput()); +} + +//---------------------------------------------------------------------------- +VISU_DeformationPL::~VISU_DeformationPL() +{ + if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<Delete(); + myVectorMergeFilter->Delete(); + myInputPassFilter->Delete(); + myOutputPassFiler->Delete(); + myCellDataToPointData->Delete(); +} + + +//---------------------------------------------------------------------------- +unsigned long int +VISU_DeformationPL::GetMTime(){ + unsigned long int aTime = std::max(myWarpVector->GetMTime(), + myVectorMergeFilter->GetMTime()); + + aTime = std::max(aTime,myInputPassFilter->GetMTime()); + aTime = std::max(aTime,myOutputPassFiler->GetMTime()); + aTime = std::max(aTime,myCellDataToPointData->GetMTime()); +} + +//---------------------------------------------------------------------------- +void VISU_DeformationPL::SetScale(vtkFloatingPointType theScaleFactor) +{ + if(myScaleFactor == theScaleFactor) + return; + myScaleFactor = theScaleFactor; + myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor); +} + +void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor) +{ + if(myMapScaleFactor == theMapScaleFactor) + return; + myMapScaleFactor = theMapScaleFactor; + + myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor); +} + + +vtkFloatingPointType VISU_DeformationPL::GetScale() +{ + return myScaleFactor; +} + +//---------------------------------------------------------------------------- +void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput) +{ + myInputPassFilter->SetInput(theInput); +} + +//---------------------------------------------------------------------------- +vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput() +{ + return myOutputPassFiler->GetOutput(); +} + +//---------------------------------------------------------------------------- +void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput, + vtkDataSet* VectorialInput) +{ + myVectorMergeFilter->SetScalars(ScalarInput); + myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput); + myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput); + + myVectorMergeFilter->SetGeometry(VectorialInput); + myVectorMergeFilter->SetVectors(VectorialInput); +} + +//---------------------------------------------------------------------------- +vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){ + return myVectorMergeFilter->GetOutput(); +} + +//---------------------------------------------------------------------------- +vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine) +{ + if(!thePipeLine || !thePipeLine->GetMergeFilterOutput()) + return 0.0; + + vtkFloatingPointType aSourceRange[2]; + thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange); + + static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT; + if(fabs(aSourceRange[1]) > EPS){ + vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput(); + vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet); + return aScaleFactor / aSourceRange[1]; + } + return 0.0; +} + diff --git a/src/PIPELINE/VISU_DeformationPL.hxx b/src/PIPELINE/VISU_DeformationPL.hxx new file mode 100755 index 00000000..e18f43e3 --- /dev/null +++ b/src/PIPELINE/VISU_DeformationPL.hxx @@ -0,0 +1,87 @@ +// Copyright (C) 2008 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_DeformationPL.hxx +// Author : +// Module : SALOME + +#ifndef VISU_DeformationPL_HeaderFile +#define VISU_DeformationPL_HeaderFile + +#include "VISUPipeline.hxx" +#include "VISU_MapperHolder.hxx" +#include + +class vtkDataSet; +class VISU_MergeFilter; +class vtkPassThroughFilter; +class vtkWarpVector; +class vtkCellDataToPointData; + +class VISU_PIPELINE_EXPORT VISU_DeformationPL { + +public: + VISU_DeformationPL(); + virtual ~VISU_DeformationPL(); + + //----------------------------------------------------------- + virtual void SetScale(vtkFloatingPointType theScaleFactor); + virtual void SetMapScale(vtkFloatingPointType theMapScaleFactor); + virtual vtkFloatingPointType GetScale(); + + //----------------------------------------------------------- + virtual void SetVectorialField(VISU::PUnstructuredGridIDMapper theIdMapper) = 0; + virtual VISU::PUnstructuredGridIDMapper getVectorialField() = 0; + + + //----------------------------------------------------------- + virtual + unsigned + long int + GetMTime(); + + static vtkFloatingPointType GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine); + + void SetWarpVectorInput(vtkDataSet *theInput); + vtkDataSet* GetWarpVectorOutput(); + + //----------------------------------------------------------- + void SetMergeFilterInput(vtkDataSet* ScalarInput, + vtkDataSet* VectorialInput); + + vtkDataSet* GetMergeFilterOutput(); + +protected: + + VISU::PUnstructuredGridIDMapper myVectorialField; + vtkWarpVector *myWarpVector; + vtkSmartPointer myVectorMergeFilter; + vtkPassThroughFilter *myInputPassFilter; + vtkPassThroughFilter *myOutputPassFiler; + vtkCellDataToPointData *myCellDataToPointData; + +private: + vtkFloatingPointType myScaleFactor; + vtkFloatingPointType myMapScaleFactor; + +}; + +#endif diff --git a/src/PIPELINE/VISU_OptionalDeformationPL.cxx b/src/PIPELINE/VISU_OptionalDeformationPL.cxx new file mode 100755 index 00000000..a4bc4555 --- /dev/null +++ b/src/PIPELINE/VISU_OptionalDeformationPL.cxx @@ -0,0 +1,101 @@ +// Copyright (C) 2008 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_ScalarMapPL.cxx +// Author: Roman NIKOLAEV +// Module : VISU + +//Salome includes +#include "VISU_OptionalDeformationPL.hxx" +#include "VISU_PipeLineUtils.hxx" + +//VTK includes +#include +#include +#include +#include +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//---------------------------------------------------------------------------- +VISU_OptionalDeformationPL::VISU_OptionalDeformationPL(): + VISU_DeformationPL(), + myIsDeformed(true) +{ + if(MYDEBUG) MESSAGE("VISU_OptionalDeformationPL()::VISU_OptionalDeformationPL() - "<SetInput(myInputPassFilter->GetOutput()); + myWarpVector->SetInput(myCellDataToPointData->GetOutput()); + myOutputPassFiler->SetInput(myWarpVector->GetOutput()); +} + +//---------------------------------------------------------------------------- +void VISU_OptionalDeformationPL::OffDeformation(){ + myOutputPassFiler->SetInput(myInputPassFilter->GetOutput()); +} + + + +bool VISU_OptionalDeformationPL::CheckCanDeformate(vtkDataSet* theInput){ + if(theInput) { + if(VISU::IsDataOnCells(theInput)) + return theInput->GetCellData()->GetVectors() != NULL; + else if(VISU::IsDataOnPoints(theInput)) + return theInput->GetPointData()->GetVectors() != NULL; + } + return false; +} diff --git a/src/PIPELINE/VISU_OptionalDeformationPL.hxx b/src/PIPELINE/VISU_OptionalDeformationPL.hxx new file mode 100755 index 00000000..333da0cc --- /dev/null +++ b/src/PIPELINE/VISU_OptionalDeformationPL.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2008 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_OptionalDeformationPL.hxx +// Author : +// Module : SALOME + +#ifndef VISU_OptionalDeformationPL_HeaderFile +#define VISU_OptionalDeformationPL_HeaderFile + +#include "VISUPipeline.hxx" +#include "VISU_DeformationPL.hxx" + +class VISU_PIPELINE_EXPORT VISU_OptionalDeformationPL: public VISU_DeformationPL +{ +public: + VISU_OptionalDeformationPL(); + virtual ~VISU_OptionalDeformationPL(); + + typedef VISU_DeformationPL Superclass; + + void UseDeformation(bool flag); + bool IsDeformed(); + + virtual + unsigned + long int + GetMTime(); + +protected: + bool CheckCanDeformate(vtkDataSet* theInput); + +private: + void OnDeformation(); + void OffDeformation(); + +private: + bool myIsDeformed; +}; + +#endif diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 087b4d9b..d91aef28 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -669,6 +669,15 @@ msgstr "Rotation around Z (X to Y):" msgid "VisuGUI_CutPlanesPane::LBL_ROTATION" msgstr "Rotations" +msgid "VisuGUI_CutPlanesPane::LBL_DEFORMATION" +msgstr "Deformation" + +msgid "VisuGUI_CutPlanesPane::LBL_DEFROMATION_VECT" +msgstr "Vectors :" + +msgid "VisuGUI_CutPlanesPane::LBL_DEFROMATION_SCALE" +msgstr "Scale Factor :" + #: VisuGUI_DeformedShapeDlg.cxx diff --git a/src/VISUGUI/VisuGUI_CutPlanesDlg.cxx b/src/VISUGUI/VisuGUI_CutPlanesDlg.cxx index bcc04d68..1bb4f270 100644 --- a/src/VISUGUI/VisuGUI_CutPlanesDlg.cxx +++ b/src/VISUGUI/VisuGUI_CutPlanesDlg.cxx @@ -37,6 +37,7 @@ #include "VISU_ColoredPrs3dFactory.hh" #include "VISU_CutPlanes_i.hh" +#include "VISU_Result_i.hh" #include "VISU_CutPlanesPL.hxx" #include "OB_Browser.h" @@ -68,6 +69,7 @@ #include #include #include +#include using namespace std; @@ -145,6 +147,40 @@ VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent) QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this); myPosSpn = new QtxDblSpinBox( 0, 1, 0.1, this ); + GDeformation = new QGroupBox (tr("LBL_DEFORMATION"), this, "GDeformation"); + GDeformation->setCheckable(true); + GDeformation->setChecked(false); + GDeformation->setColumnLayout(0, Qt::Horizontal); + GDeformation->layout()->setSpacing( 0 ); + GDeformation->layout()->setMargin( 0 ); + QGridLayout* GDeformationLayout = new QGridLayout( GDeformation->layout() ); + GDeformationLayout->setAlignment( Qt::AlignTop ); + GDeformationLayout->setSpacing( 6 ); + GDeformationLayout->setMargin( 11 ); + connect(GDeformation, SIGNAL(toggled(bool)), this, SLOT(onDeformationCheck(bool))); + + QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation, "LabelDeformation1"); + GDeformationLayout->addWidget( LabelDeformation1, 0, 0 ); + + + myVectorialFieldCombo = new QComboBox (GDeformation,"myVectorialFieldCombo"); + GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 ); + + QLabel* LabelDeformation2 = new QLabel (tr("LBL_DEFROMATION_SCALE"), GDeformation, "LabelDeformation2"); + GDeformationLayout->addWidget( LabelDeformation2, 1, 0 ); + myScaleSpn = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, GDeformation); + myScaleSpn->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + GDeformationLayout->addWidget( myScaleSpn, 1, 1 ); + connect(myVectorialFieldCombo, SIGNAL(activated(int)), this, SLOT(onVectorialFieldChanged(int))); + connect(myScaleSpn, SIGNAL(valueChanged(double)), this, SLOT(onScaleFactorChanged(double))); + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 ); + + myScaleSpn->setPrecision( aPrecision*(-1) ); + myScaleSpn->setValue(0.1); + + myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this); myPreviewCheck->setChecked(false); connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) ); @@ -157,7 +193,8 @@ VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent) TopLayout->setRowStretch ( 3, 3 ); TopLayout->addWidget(aPosLbl, 4, 0 ); TopLayout->addWidget(myPosSpn, 4, 1 ); - TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 ); + TopLayout->addMultiCellWidget( GDeformation, 5, 5, 0, 1 ); + TopLayout->addMultiCellWidget( myPreviewCheck, 6, 6, 0, 1 ); // signals and slots connections connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) ); @@ -187,31 +224,102 @@ void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs) setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI); setPlanePos(thePrs->GetOrientationType()); myPosSpn->setValue(thePrs->GetDisplacement()); + InitEntity2VectorialFieldsMap(thePrs); + InsertAllVectorialFields(); + setScaleFactor(thePrs->GetScale()); + if(myEntity2VectorialFields.size() < 1) + GDeformation->setDisabled(true); + else{ + if(thePrs->IsDeformed()){ + GDeformation->setChecked(true); + myVectorialFieldCombo->setCurrentText(thePrs->GetVectorialFieldName()); + } + } + hasInit = true; // init table myCutPlanes = VISU::TSameAsFactory().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish); myCutPlanes->SameAs(thePrs); DrawTable(); - + // Draw Preview if (myPreviewCheck->isChecked()) { createPlanes(); } } + +void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){ + + VISU::Result_var theResult = thePrs->GetResultObject(); + VISU::Result_i* aResult = dynamic_cast(GetServant(theResult).in()); + VISU::Result::Entities_var aEntities = aResult->GetEntities(thePrs->GetMeshName()); + VISU::Result::TimeStampNumbers_var aScalarTimeStamp = aResult->GetTimeStampNumbers(thePrs->GetMeshName(), + thePrs->GetEntity(), + thePrs->GetFieldName()); + CORBA::Long aTimeStampNumber = aScalarTimeStamp->length(); + + for(size_t iEntity = 0; iEntity < aEntities->length(); iEntity++){ + VISU::Entity aEntity = aEntities[iEntity]; + VISU::Result::EntityNames_var aFields = aResult->GetFields(thePrs->GetMeshName(),aEntity); + for(size_t iField = 0; iField < aFields->length(); iField++){ + + TVectorialFieldsList aVectorialFields; + VISU::Result::TimeStampNumbers_var aTimeStamps = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] ); + + if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) && + (aTimeStamps->length() >= aTimeStampNumber)){ + aVectorialFields.push_back(QString(aFields[iField].in())); + } + if(aVectorialFields.size() > 0){ + myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields)); + } + } + } +} + +void VisuGUI_CutPlanesPane::InsertAllVectorialFields(){ + TEntity2VectorialFields::const_iterator aFieldIter = myEntity2VectorialFields.begin(); + for( ;aFieldIter != myEntity2VectorialFields.end();aFieldIter++ ){ + TVectorialFieldsList aVectorialFields = aFieldIter->second; + for(size_t iField = 0;iField < aVectorialFields.size(); iField++) + myVectorialFieldCombo->insertItem(aVectorialFields[iField]); + } +} + +double VisuGUI_CutPlanesPane::getScaleFactor(){ + return myScaleSpn->value(); +} + +void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor){ + double i=0.1; + while (1) { // Calculate Step & Precission + if ( int (theFactor/i) > 0) + break; + else { + i = i*0.1; + } + } + + myScaleSpn->setLineStep(i); + myScaleSpn->setValue(theFactor); + +} + + void VisuGUI_CutPlanesPane::createPlanes() { if (VISU::GetActiveViewWindow() == NULL) return; if (!myCutPlanes) return; if (myPreviewActor != 0) return; - vtkAppendPolyData* aPolyData = myCutPlanes->GetSpecificPL()->GetAppendPolyData(); - if (!aPolyData->GetOutput()->GetNumberOfCells()) { + vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput(); + if (!aDataSet->GetNumberOfCells()) { onPreviewCheck(false); return; } vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New(); - aPlaneMapper->SetInput(aPolyData->GetOutput()); + aPlaneMapper->SetInput(aDataSet); aPlaneMapper->ScalarVisibilityOff(); myPreviewActor = SALOME_Actor::New(); @@ -235,6 +343,31 @@ int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs) else thePrs->SetDefault(i); } + + thePrs->UseDeformation(GDeformation->isChecked()); + + if(GDeformation->isChecked()){ + TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin(); + VISU::Entity anEntity; + QString aFieldName; + bool isInited = false; + for(;anIter != myEntity2VectorialFields.end();anIter++){ + TVectorialFieldsList aFields = anIter->second; + for(int it = 0;it < aFields.size();it++) + if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){ + anEntity = anIter->first; + aFieldName = aFields[it]; + isInited = true; + break; + } + if(isInited) + break; + } + if(isInited) + thePrs->SetVectorialField(anEntity,aFieldName.latin1()); + + thePrs->SetScale(myScaleSpn->value()); + } return 1; } @@ -303,6 +436,45 @@ void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2) Rot2->setValue( r2 ); } +void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){ + DrawTable(); +} + +void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){ + InitVectorialField(); + DrawTable(); +} + +void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){ + if(!myCutPlanes || !hasInit) return; + myCutPlanes->UseDeformation(Flag); + InitVectorialField(); + DrawTable(); +} + +void VisuGUI_CutPlanesPane::InitVectorialField(){ + if(myCutPlanes->IsDeformed()){ + TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin(); + VISU::Entity anEntity; + QString aFieldName; + bool isInited = false; + for(;anIter != myEntity2VectorialFields.end();anIter++){ + TVectorialFieldsList aFields = anIter->second; + for(int it = 0;it < aFields.size();it++) + if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){ + anEntity = anIter->first; + aFieldName = aFields[it]; + isInited = true; + break; + } + if(isInited) + break; + } + if(isInited) + myCutPlanes->SetVectorialField(anEntity,aFieldName.latin1()); + } +} + /*! Draw the table of planes positions */ @@ -317,6 +489,7 @@ void VisuGUI_CutPlanesPane::DrawTable() myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.); myCutPlanes->SetNbPlanes(aNbPlanes); myCutPlanes->SetDisplacement(myPosSpn->value()); + myCutPlanes->SetScale(getScaleFactor()); if (aNbRows>0) for (int i = 0; i < aNbRows; ++i) { QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 ); @@ -537,7 +710,7 @@ void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs, VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit); myCutPane->initFromPrsObject(myPrsCopy); - + if( !theInit ) return; diff --git a/src/VISUGUI/VisuGUI_CutPlanesDlg.h b/src/VISUGUI/VisuGUI_CutPlanesDlg.h index 9b029d90..458433dd 100644 --- a/src/VISUGUI/VisuGUI_CutPlanesDlg.h +++ b/src/VISUGUI/VisuGUI_CutPlanesDlg.h @@ -37,15 +37,21 @@ #include #include #include +#include #include #include "SALOMEconfig.h" #include CORBA_CLIENT_HEADER(VISU_Gen) +#include +#include + + namespace VISU { class CutPlanes_i; + class Result_i; }; class SUIT_ViewWindow; @@ -53,6 +59,7 @@ class SUIT_ViewManager; class SalomeApp_Module; class VisuGUI_InputPane; + class VisuGUI_CutPlanesPane : public QFrame { Q_OBJECT @@ -69,15 +76,30 @@ public: double getRotation1() {return Rot1->value();} double getRotation2() {return Rot2->value();} + double getScaleFactor(); + void setScaleFactor(double factor); + void initFromPrsObject(VISU::CutPlanes_i* thePrs); int storeToPrsObject(VISU::CutPlanes_i* thePrs); private: + + typedef std::vector TVectorialFieldsList; + typedef std::map TEntity2VectorialFields; + typedef std::pair TEntVectPair; + TEntity2VectorialFields myEntity2VectorialFields; + void createPlanes(); void deletePlanes(); + void InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs); + void InsertAllVectorialFields(); + void InitVectorialField(); + + QLabel* LabelRot1; QLabel* LabelRot2; + QGroupBox* GDeformation; QSpinBox* nbPlan; QtxDblSpinBox* Rot1; QtxDblSpinBox* Rot2; @@ -88,6 +110,8 @@ private: QTable* myPosTable; SALOME::GenericObjPtr myCutPlanes; QCheckBox* myPreviewCheck; + QComboBox* myVectorialFieldCombo; + QtxDblSpinBox* myScaleSpn; double X1, X2; double Y1, Y2; double Z1, Z2; @@ -102,6 +126,9 @@ private slots: void onValueChanged(int theRow, int theCol); void onRotation(double theValue); void onPreviewCheck(bool thePreview); + void onScaleFactorChanged(double); + void onDeformationCheck(bool); + void onVectorialFieldChanged(int); }; diff --git a/src/VISU_I/Makefile.am b/src/VISU_I/Makefile.am index 4e2d5ffb..20bff318 100644 --- a/src/VISU_I/Makefile.am +++ b/src/VISU_I/Makefile.am @@ -53,8 +53,11 @@ salomeinclude_HEADERS = \ VISU_DeformedShapeAndScalarMap_i.hh \ VISU_ColoredPrs3dFactory.hh \ VISU_MonoColorPrs_i.hh \ + VISU_Deformation_i.hh \ + VISU_OptionalDeformation_i.hh \ SALOME_GenericObjPointer.hh + libVISUEngineImpl_la_SOURCES = \ VISUConfig.cc \ VISU_Result_i.cc \ @@ -87,6 +90,8 @@ libVISUEngineImpl_la_SOURCES = \ VISU_PointMap3d_i.cc \ VISU_DumpPython.cc \ VISU_MonoColorPrs_i.cc \ + VISU_Deformation_i.cc \ + VISU_OptionalDeformation_i.cc \ SALOME_GenericObjPointer.cc MOC_FILES = VISU_TimeAnimation_moc.cxx diff --git a/src/VISU_I/VISU_CutPlanes_i.cc b/src/VISU_I/VISU_CutPlanes_i.cc index a0f724b7..dfbb7d00 100644 --- a/src/VISU_I/VISU_CutPlanes_i.cc +++ b/src/VISU_I/VISU_CutPlanes_i.cc @@ -25,6 +25,7 @@ // Module : VISU #include "VISU_CutPlanesPL.hxx" +#include "VISU_Convertor.hxx" #include "VISU_Prs3dUtils.hh" #include "VISU_CutPlanes_i.hh" @@ -41,6 +42,7 @@ static int MYDEBUG = 0; #endif + //---------------------------------------------------------------------------- size_t VISU::CutPlanes_i @@ -95,8 +97,12 @@ VISU::CutPlanes_i ::CutPlanes_i(EPublishInStudyMode thePublishInStudyMode): ColoredPrs3d_i(thePublishInStudyMode), ScalarMap_i(thePublishInStudyMode), - myCutPlanesPL(NULL) -{} + myCutPlanesPL(NULL), + Deformation_i(this), + OptionalDeformation_i(this) +{ + if(MYDEBUG) MESSAGE("CutPlanes_i::CutPlanes_i()"); +} //---------------------------------------------------------------------------- @@ -131,6 +137,8 @@ VISU::CutPlanes_i if(aCondList[i].toInt() == 0) SetPlanePosition(i,aPosList[i].toDouble()); + OptionalDeformation_i::RestoreDeformation(theSObject,theMap); + return this; } @@ -152,6 +160,7 @@ void VISU::CutPlanes_i::ToStream(std::ostringstream& theStr){ } Storable::DataToStream( theStr, "myPlanePosition", aStrPos.latin1()); Storable::DataToStream( theStr, "myPlaneCondition", aStrCon.latin1()); + OptionalDeformation_i::DeformationToStream(theStr); } @@ -321,6 +330,7 @@ VISU::CutPlanes_i }else myCutPlanesPL = dynamic_cast(thePipeLine); + InitDeformedPipeLine(myCutPlanesPL); TSuperClass::CreatePipeLine(myCutPlanesPL); } @@ -348,3 +358,10 @@ VISU::CutPlanes_i return NULL; } +void +VISU::CutPlanes_i:: +SameAs(const Prs3d_i* theOrigin){ + if(MYDEBUG) MESSAGE("CutPlanes_i::SameAs()"); + TSuperClass::SameAs(theOrigin); + OptionalDeformation_i::SameAsDeformation(dynamic_cast(theOrigin)); +} diff --git a/src/VISU_I/VISU_CutPlanes_i.hh b/src/VISU_I/VISU_CutPlanes_i.hh index 9386f9f3..8a5f9355 100644 --- a/src/VISU_I/VISU_CutPlanes_i.hh +++ b/src/VISU_I/VISU_CutPlanes_i.hh @@ -28,6 +28,7 @@ #define VISU_CutPlanes_i_HeaderFile #include "VISU_ScalarMap_i.hh" +#include "VISU_OptionalDeformation_i.hh" class VISU_CutPlanesPL; @@ -35,7 +36,8 @@ namespace VISU { //---------------------------------------------------------------------------- class VISU_I_EXPORT CutPlanes_i : public virtual POA_VISU::CutPlanes, - public virtual ScalarMap_i + public virtual ScalarMap_i, + public virtual OptionalDeformation_i { static int myNbPresent; CutPlanes_i(const CutPlanes_i&); @@ -157,6 +159,10 @@ namespace VISU Restore(SALOMEDS::SObject_ptr theSObject, const Storable::TRestoringMap& theMap); + virtual + void + SameAs(const Prs3d_i* theOrigin); + //! Redefines VISU_ColoredPrs3d_i::CreateActor virtual VISU_Actor* diff --git a/src/VISU_I/VISU_Deformation_i.cc b/src/VISU_I/VISU_Deformation_i.cc new file mode 100755 index 00000000..8f4c05bc --- /dev/null +++ b/src/VISU_I/VISU_Deformation_i.cc @@ -0,0 +1,166 @@ +// Copyright (C) 2008 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_Deformation_i.cc +// Author : +// Module : VISU + +#include "VISU_Deformation_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_Prs3dUtils.hh" + +#include "VISU_DeformationPL.hxx" +#include "VISU_Convertor.hxx" +#include "VISU_DeformationPL.hxx" +#include "VISUConfig.hh" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//--------------------------------------------------------------- +VISU::Deformation_i::Deformation_i(VISU::ColoredPrs3d_i *thePrs3d): + myColoredPrs3d(thePrs3d) +{ + if(MYDEBUG) MESSAGE("Deformation_i::Deformation_i()"); +} + +//--------------------------------------------------------------- +VISU::Deformation_i::~Deformation_i() +{ + if(MYDEBUG) MESSAGE("Deformation_i::~Deformation_i()"); +} + +//--------------------------------------------------------------- +void VISU::Deformation_i::SetScale(CORBA::Double theScale) +{ + if(MYDEBUG) MESSAGE("Deformation_i::SetScale()"); + + VISU::TSetModified aModified(GetColoredPrs3d()); + + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificDeformedPL(), &VISU_DeformationPL::SetScale, theScale)); +} + +//--------------------------------------------------------------- +void VISU::Deformation_i::InitDeformedPipeLine(VISU_DeformationPL* theDeformedPipeLine){ + + if(MYDEBUG) MESSAGE("Deformation_i::InitDeformedPipeLine()"); + myDeformationPL = theDeformedPipeLine; +} + +//--------------------------------------------------------------- +CORBA::Double +VISU::Deformation_i +::GetScale() +{ + if(MYDEBUG) MESSAGE("Deformation_i::GetScale()"); + return GetSpecificDeformedPL()->GetScale(); +} + +//--------------------------------------------------------------- +VISU::Entity VISU::Deformation_i::GetVectorialFieldEntity(){ + return myVectorialEntity; +} + +//--------------------------------------------------------------- +char* VISU::Deformation_i::GetVectorialFieldName(){ + return CORBA::string_dup(myVectorialFieldName.c_str()); +} + +//--------------------------------------------------------------- +void VISU::Deformation_i:: +DeformationToStream(std::ostringstream& theStr) +{ + Storable::DataToStream(theStr,"myScaleFactor", GetScale()); + Storable::DataToStream(theStr,"myVectorialField", GetVectorialFieldName()); + Storable::DataToStream(theStr,"myVectorialEntiry", GetVectorialFieldEntity()); + +} + +//--------------------------------------------------------------- +void +VISU::Deformation_i::RestoreDeformation(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap) +{ + SetScale(VISU::Storable::FindValue(theMap,"myScaleFactor").toDouble()); + VISU::Entity anEntity = VISU::Entity(VISU::Storable::FindValue(theMap, "myVectorialEntiry").toInt()); + + SetVectorialField(anEntity, + VISU::Storable::FindValue(theMap, "myVectorialField")); +} + +//--------------------------------------------------------------- +void +VISU::Deformation_i::SameAsDeformation(const Deformation_i *aDeformedPrs){ + if(const Deformation_i* aPrs = dynamic_cast(aDeformedPrs)) { + Deformation_i* anOrigin = const_cast(aPrs); + + CORBA::String_var aVectorialFieldName = anOrigin->GetVectorialFieldName(); + VISU::Entity anEntity = anOrigin->GetVectorialFieldEntity(); + this->SetVectorialField(anEntity, + aVectorialFieldName); + this->SetScale(anOrigin->GetScale()); + } +} + +void VISU::Deformation_i::SetVectorialField(Entity theEntity, const char* theFieldName){ + if(MYDEBUG) MESSAGE("CutPlanes_i::SetVectorialField()"); + + bool anIsModified = false; + if(!anIsModified) + anIsModified |= GetVectorialFieldEntity() != theEntity; + + if(!anIsModified) + anIsModified |= GetVectorialFieldName() != theFieldName; + + if(!anIsModified) + return; + + ColoredPrs3d_i *aColoredPrs = GetColoredPrs3d(); + int aTimeStampNumber = aColoredPrs->GetTimeStampNumber(); + + VISU::TEntity aEntity = VISU::TEntity(theEntity); + + VISU::Result_i::PInput anInput = aColoredPrs->GetCResult()->GetInput(aColoredPrs->GetCMeshName(), + theEntity, + theFieldName, + aTimeStampNumber); + + PField aVectorialField = anInput->GetField(aColoredPrs->GetCMeshName(), aEntity, theFieldName); + + VISU::PUnstructuredGridIDMapper anIDMapper = + anInput->GetTimeStampOnMesh(aColoredPrs->GetCMeshName(), + aEntity, + theFieldName, + aTimeStampNumber); + if(GetSpecificDeformedPL() && anIDMapper) { + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificDeformedPL(), &VISU_DeformationPL::SetVectorialField, anIDMapper)); + + VISU::TSetModified aModified(GetColoredPrs3d()); + + myVectorialEntity = theEntity; + myVectorialFieldName = theFieldName; + myVectorialField = anIDMapper; + } +}; diff --git a/src/VISU_I/VISU_Deformation_i.hh b/src/VISU_I/VISU_Deformation_i.hh new file mode 100755 index 00000000..821b2735 --- /dev/null +++ b/src/VISU_I/VISU_Deformation_i.hh @@ -0,0 +1,103 @@ +// Copyright (C) 2008 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_Deformation_i.hxx +// Author : +// Module : VISU + +#ifndef VISU_Deformation_i_HeaderFile +#define VISU_Deformation_i_HeaderFile + +#include "VISU_I.hxx" +#include "VISU_ColoredPrs3d_i.hh" +#include "VISU_DeformationPL.hxx" + + + +namespace VISU{ + + class VISU_I_EXPORT Deformation_i : public virtual POA_VISU::Deformation + { + Deformation_i(const Deformation_i&); + public: + typedef VISU::Deformation TInterface; + + Deformation_i(VISU::ColoredPrs3d_i* theColoredPrs3d); + virtual ~Deformation_i(); + + virtual + void + SetScale(CORBA::Double theScale); + + virtual + CORBA::Double + GetScale(); + + virtual + void + DeformationToStream(std::ostringstream& theStr); + + virtual + void + RestoreDeformation(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap); + + virtual + void + SameAsDeformation(const Deformation_i *aDeformedPrs); + + virtual + VISU::Entity + GetVectorialFieldEntity(); + + virtual + char* + GetVectorialFieldName(); + + virtual void SetVectorialField(Entity theEntity, const char* theFieldName); + + protected: + virtual + void + InitDeformedPipeLine(VISU_DeformationPL* theDeformedPipeLine); + + VISU_DeformationPL* + GetSpecificDeformedPL() const + { + return myDeformationPL; + } + + ColoredPrs3d_i* GetColoredPrs3d(){ + return myColoredPrs3d; + } + + + private: + VISU_DeformationPL *myDeformationPL; + + PField myVectorialField; + VISU::Entity myVectorialEntity; + std::string myVectorialFieldName; + ColoredPrs3d_i *myColoredPrs3d; + + }; +} + +#endif diff --git a/src/VISU_I/VISU_DumpPython.cc b/src/VISU_I/VISU_DumpPython.cc index 84b03f05..95e42818 100644 --- a/src/VISU_I/VISU_DumpPython.cc +++ b/src/VISU_I/VISU_DumpPython.cc @@ -652,6 +652,27 @@ namespace VISU theStr<GetPlanePosition(anId)<<")"<IsDeformed())<<")"<IsDeformed()){ + theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<GetVectorialFieldEntity(); + switch(anEntity){ + case NODE: + aStringEntity = "VISU.NODE"; + break; + case EDGE: + aStringEntity = "VISU.EDGE"; + break; + case FACE: + aStringEntity = "VISU.FACE"; + break; + case CELL: + aStringEntity = "VISU.CELL"; + break; + } + theStr<< thePrefix << theName << ".SetVectorialField("<GetVectorialFieldName() <<"')"< + (GetSpecificDeformedPL(), &VISU_OptionalDeformationPL::UseDeformation, theFlag)); +} + +//--------------------------------------------------------------- +CORBA::Boolean VISU::OptionalDeformation_i::IsDeformed(){ + + if(MYDEBUG) MESSAGE("OptionalDeformation_i::IsDeformed()"); + return GetSpecificDeformedPL()->IsDeformed(); +} + + +void VISU::OptionalDeformation_i::InitDeformedPipeLine(VISU_DeformationPL* theDeformedPipeLine){ + + if(MYDEBUG) MESSAGE("OptionalDeformation_i::InitDeformedPipeLine()"); + myOptionalDeformationPL = dynamic_cast(theDeformedPipeLine); + + TSuperClass::InitDeformedPipeLine(myOptionalDeformationPL); +} + +//--------------------------------------------------------------- +void VISU::OptionalDeformation_i:: +DeformationToStream(std::ostringstream& theStr) +{ + Storable::DataToStream(theStr,"IsDeformed", IsDeformed()); + if(IsDeformed()) + TSuperClass::DeformationToStream(theStr); +} + +//--------------------------------------------------------------- +void +VISU::OptionalDeformation_i::RestoreDeformation(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap) +{ + UseDeformation(Storable::FindValue(theMap,"IsDeformed").toInt()); + if(IsDeformed()) + TSuperClass::RestoreDeformation(theSObject,theMap); +} + + + +void +VISU::OptionalDeformation_i::SameAsDeformation(const Deformation_i *aDeformedPrs){ + + if(const OptionalDeformation_i* aPrs3d = dynamic_cast(aDeformedPrs)){ + OptionalDeformation_i* anOrigin = const_cast(aPrs3d); + UseDeformation(anOrigin->IsDeformed()); + + if(anOrigin->IsDeformed()){ + TSuperClass::SameAsDeformation(aDeformedPrs); + } + } +} diff --git a/src/VISU_I/VISU_OptionalDeformation_i.hh b/src/VISU_I/VISU_OptionalDeformation_i.hh new file mode 100755 index 00000000..ac6a08ff --- /dev/null +++ b/src/VISU_I/VISU_OptionalDeformation_i.hh @@ -0,0 +1,76 @@ +// Copyright (C) 2008 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_Deformation_i.hxx +// Author : +// Module : VISU + +#ifndef VISU_OptionalDeformation_i_HeaderFile +#define VISU_OptionalDeformation_i_HeaderFile + +#include "VISU_I.hxx" +#include "VISU_Deformation_i.hh" +#include "VISU_OptionalDeformationPL.hxx" + +namespace VISU { + class VISU_I_EXPORT OptionalDeformation_i : public virtual POA_VISU::OptionalDeformation, + public virtual Deformation_i + { + OptionalDeformation_i(const OptionalDeformation_i&); + public: + typedef VISU::OptionalDeformation TInterface; + typedef Deformation_i TSuperClass; + + OptionalDeformation_i(VISU::ColoredPrs3d_i* theModifiedEngine); + virtual ~OptionalDeformation_i(); + + virtual void UseDeformation(CORBA::Boolean theFlag); + virtual CORBA::Boolean IsDeformed(); + + + virtual + void + DeformationToStream(std::ostringstream& theStr); + + virtual + void + RestoreDeformation(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap); + + virtual + void + SameAsDeformation(const Deformation_i *aDeformedPrs); + + protected: + virtual + void InitDeformedPipeLine(VISU_DeformationPL* theDeformedPipeLine); + + VISU_OptionalDeformationPL* + GetSpecificDeformedPL() const + { + return myOptionalDeformationPL; + } + + private: + VISU_OptionalDeformationPL* myOptionalDeformationPL; + + }; +} +#endif diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index 67e6c711..07bac9ec 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -1002,7 +1002,7 @@ VISU::Result_i { anEntities->length(aMeshOnEntityMap.size()); - VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.end(); + VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.begin(); for(size_t anId = 0; anIter != aMeshOnEntityMap.end(); anIter++, anId++){ const VISU::TEntity& anEntity = anIter->first; anEntities[anId] = VISU::Entity(anEntity); @@ -1046,7 +1046,7 @@ VISU::Result_i { aResult->length(aFamilyMap.size()); - VISU::TFamilyMap::const_iterator anIter = aFamilyMap.end(); + VISU::TFamilyMap::const_iterator anIter = aFamilyMap.begin(); for(size_t anId = 0; anIter != aFamilyMap.end(); anIter++, anId++){ const std::string& aName = anIter->first; aResult[anId] = aName.c_str(); @@ -1079,7 +1079,7 @@ VISU::Result_i { aResult->length(aGroupMap.size()); - VISU::TGroupMap::const_iterator anIter = aGroupMap.end(); + VISU::TGroupMap::const_iterator anIter = aGroupMap.begin(); for(size_t anId = 0; anIter != aGroupMap.end(); anIter++, anId++){ const std::string& aName = anIter->first; aResult[anId] = aName.c_str(); @@ -1123,7 +1123,7 @@ VISU::Result_i { aResult->length(aFieldMap.size()); - VISU::TFieldMap::const_iterator anIter = aFieldMap.end(); + VISU::TFieldMap::const_iterator anIter = aFieldMap.begin(); for(size_t anId = 0; anIter != aFieldMap.end(); anIter++, anId++){ const std::string& aName = anIter->first; aResult[anId] = aName.c_str(); @@ -1180,7 +1180,7 @@ VISU::Result_i { aResult->length(aValField.size()); - VISU::TValField::const_iterator anIter = aValField.end(); + VISU::TValField::const_iterator anIter = aValField.begin(); for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){ const vtkIdType& aTimeStampNumber = anIter->first; aResult[anId] = aTimeStampNumber;