From: admin Date: Tue, 14 Oct 2003 08:11:45 +0000 (+0000) Subject: This commit was generated by cvs2git to create branch 'BRANCH_MergeV1_2c'. X-Git-Tag: MergeV1_2c-1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=462ac1e6f6f4437d8a4a4408d21ce5de07d3cc21;p=modules%2Fvisu.git This commit was generated by cvs2git to create branch 'BRANCH_MergeV1_2c'. Sprout from master 2003-09-26 14:26:40 UTC nri 'NRI : INSTALL file defined into SALOME2_PRODUCTION_CYCLE document.' Cherrypick from IMPORT 2003-10-14 08:11:44 UTC nri 'sources v1.2c': resources/Visu_cutlines.png resources/config src/CONVERTOR/Makefile.in src/CONVERTOR/VISUConvertor.cxx src/CONVERTOR/VISU_Convertor.cxx src/CONVERTOR/VISU_Convertor.hxx src/CONVERTOR/VISU_ConvertorUtils.cxx src/CONVERTOR/VISU_ConvertorUtils.hxx src/CONVERTOR/VISU_Convertor_impl.cxx src/CONVERTOR/VISU_Convertor_impl.hxx src/CONVERTOR/VISU_DatConvertor.cxx src/CONVERTOR/VISU_DatConvertor.hxx src/CONVERTOR/VISU_MedConvertor.cxx src/CONVERTOR/VISU_MedConvertor.hxx src/OBJECT/VISU_LookupTable.cxx src/OBJECT/VISU_LookupTable.hxx src/OBJECT/VISU_MeshAct.cxx src/OBJECT/VISU_MeshAct.h src/OBJECT/VISU_ScalarBarActor.cxx src/OBJECT/VISU_ScalarBarActor.hxx src/OBJECT/VISU_ScalarMapAct.cxx src/OBJECT/VISU_ScalarMapAct.h src/OBJECT/VISU_VectorsAct.cxx src/OBJECT/VISU_VectorsAct.h src/PIPELINE/Makefile.in src/PIPELINE/VISUPipeLine.cxx src/PIPELINE/VISU_CutLinesPL.cxx src/PIPELINE/VISU_CutLinesPL.hxx src/PIPELINE/VISU_CutPlanesPL.cxx src/PIPELINE/VISU_CutPlanesPL.hxx src/PIPELINE/VISU_DeformedShapePL.cxx src/PIPELINE/VISU_DeformedShapePL.hxx src/PIPELINE/VISU_Extractor.cxx src/PIPELINE/VISU_Extractor.hxx src/PIPELINE/VISU_FieldTransform.cxx src/PIPELINE/VISU_FieldTransform.hxx src/PIPELINE/VISU_IsoSurfacesPL.cxx src/PIPELINE/VISU_IsoSurfacesPL.hxx src/PIPELINE/VISU_LookupTable.cxx src/PIPELINE/VISU_LookupTable.hxx src/PIPELINE/VISU_MeshPL.cxx src/PIPELINE/VISU_MeshPL.hxx src/PIPELINE/VISU_PipeLine.cxx src/PIPELINE/VISU_PipeLine.hxx src/PIPELINE/VISU_PipeLineUtils.cxx src/PIPELINE/VISU_PipeLineUtils.hxx src/PIPELINE/VISU_ScalarBarActor.cxx src/PIPELINE/VISU_ScalarBarActor.hxx src/PIPELINE/VISU_ScalarMapPL.cxx src/PIPELINE/VISU_ScalarMapPL.hxx src/PIPELINE/VISU_StreamLinesPL.cxx src/PIPELINE/VISU_StreamLinesPL.hxx src/PIPELINE/VISU_UsedPointsFilter.cxx src/PIPELINE/VISU_UsedPointsFilter.hxx src/PIPELINE/VISU_VectorsPL.cxx src/PIPELINE/VISU_VectorsPL.hxx src/VISUGUI/VisuGUI_FileDlg.cxx src/VISUGUI/VisuGUI_FileDlg.h src/VISU_I/VISUConfig.cc src/VISU_I/VISU_CutLines_i.cc src/VISU_I/VISU_CutLines_i.hh src/VISU_I/VISU_CutPlanes_i.cc src/VISU_I/VISU_CutPlanes_i.hh src/VISU_I/VISU_DeformedShape_i.cc src/VISU_I/VISU_DeformedShape_i.hh src/VISU_I/VISU_IsoSurfaces_i.cc src/VISU_I/VISU_IsoSurfaces_i.hh src/VISU_I/VISU_Mesh_i.cc src/VISU_I/VISU_Mesh_i.hh src/VISU_I/VISU_Prs3d_i.cc src/VISU_I/VISU_Prs3d_i.hh src/VISU_I/VISU_ScalarMap_i.cc src/VISU_I/VISU_ScalarMap_i.hh src/VISU_I/VISU_StreamLines_i.cc src/VISU_I/VISU_StreamLines_i.hh src/VISU_I/VISU_Vectors_i.cc src/VISU_I/VISU_Vectors_i.hh src/VISU_SWIG/VISU_Gen_s.cc src/VISU_SWIG/VISU_Gen_s.hh src/VISU_SWIG/batchmode_visu_table.py src/VISU_SWIG/visu_gui.py src/VISU_SWIG/visu_swig_test.py Cherrypick from IMPORT 2003-07-10 13:40:28 UTC nri 'sources v1.2': src/VISUGUI/VisuGUI_CutLinesDlg.cxx src/VISUGUI/VisuGUI_CutLinesDlg.h src/VISU_SWIG/visu_prs_example.py --- diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in new file mode 100644 index 00000000..69020189 --- /dev/null +++ b/src/CONVERTOR/Makefile.in @@ -0,0 +1,50 @@ +# 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 +# +# +# +# File : Makefile.in +# Module : VISU + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +EXPORT_HEADERS = VISU_Convertor.hxx VISU_Convertor_impl.hxx + +# Libraries targets + +LIB = libVisuConvertor.la +LIB_SRC = VISU_Convertor.cxx VISU_Convertor_impl.cxx VISU_ConvertorUtils.cxx \ + VISU_MedConvertor.cxx VISU_DatConvertor.cxx + +# Executables targets +BIN = VISUConvertor +BIN_SRC = + +CPPFLAGS+= -ftemplate-depth-32 $(VTK_INCLUDES) $(MED2_INCLUDES) $(QT_INCLUDES) +LDFLAGS+= $(VTK_LIBS) $(MED2_LIBS) $(HDF5_LIBS) $(QT_LIBS) + +@CONCLUDE@ diff --git a/src/CONVERTOR/VISUConvertor.cxx b/src/CONVERTOR/VISUConvertor.cxx new file mode 100644 index 00000000..c8b2e55a --- /dev/null +++ b/src/CONVERTOR/VISUConvertor.cxx @@ -0,0 +1,136 @@ +// 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 +// +// +// File: VISUConvertor.cxx +// Author: Alexey PETROV +// Module : VISU + +#include "VISU_Convertor.hxx" + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#ifdef DEBUG +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +void parseFile(const char* theFileName) throw(std::runtime_error&){ + try{ + cout<<"'"< aCon(CreateConvertor(theFileName)); + const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap(); + //return; + VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const VISU::TMesh& aMesh = aMeshMapIter->second; + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + //Import fields + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap; + VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + const string& aFieldName = aFieldMapIter->first; + const VISU::TField& aField = aFieldMapIter->second; + const VISU::TField::TValField& aValField = aField.myValField; + VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + } + } + } + //Importing groups + const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap; + VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + aCon->GetMeshOnGroup(aMeshName,aGroupName); + } + //Import families + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + //aCon->GetMeshOnEntity(aMeshName,anEntity); + const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName); + } + } + //Import mesh on entity + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + aCon->GetMeshOnEntity(aMeshName,anEntity); + } + } + cout<<"OK"< 1){ + QFileInfo fi(argv[1]); + for(int i = 0; i < 1; i++){ + if(fi.exists()){ + if(fi.isDir()){ + QDir aDir(fi.absFilePath()); + QStringList aStringList = aDir.entryList("*.med",QDir::Files); + int jEnd = aStringList.count(); + for(int j = 0; j < jEnd; j++){ + parseFile(aDir.filePath(aStringList[j]).latin1()); + } + }else{ + parseFile(argv[1]); + } + } + } + return 0; + } + }catch(std::runtime_error& exc){ + cout<<"Follow exception was accured :\n"< + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +extern "C" { + VISU_Convertor* CreateConvertor(const string& theFileName) throw(std::runtime_error&){ + if(QFileInfo(theFileName.c_str()).extension(false) == "med") + return CreateMedConvertor(theFileName); + else + return CreateDatConvertor(theFileName); + } +} + +void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){ +// vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); +// //aWriter->DebugOn(); +// //aWriter->SetFileType(VTK_BINARY); +// aWriter->SetFileName(theFileName.c_str()); +// aWriter->SetInput(theDataSet); +// //aWriter->Print(cout); +// aWriter->Write(); +// aWriter->Delete(); +} + +namespace VISU{ + TVtkCellInfoMap aVtkCellInfoMap; + static int INIT = ( + aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1), + aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2), + aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3), + aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4), + aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4), + aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8), + aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6), + aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5), + 1); + + pair TMeshOnEntity::GetCellsDims(const string& theFamilyName) const + throw(std::runtime_error&) + { + bool isFamilyPresent = (theFamilyName != ""); + int aNbCells = 0, aCellsSize = 0; + if(!isFamilyPresent){ + TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin(); + for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){ + const TConnForCellType& aConnForCellType = aCellsConnIter->second; + if(!aConnForCellType.empty()){ + aNbCells += aConnForCellType.size(); + aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1); + } + } + }else{ + TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName); + if(aFamilyMapIter == myFamilyMap.end()) + throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!"); + const TFamily& aFamily = aFamilyMapIter->second; + const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh; + TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin(); + for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){ + const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + if(!aSubMeshOnCellType.empty()){ + int tmp = aSubMeshOnCellType.size(); + aNbCells += tmp; + int aVtkType = aSubMeshIter->first; + int aVtkSize = aVtkCellInfoMap[aVtkType].mySize; + aCellsSize += tmp*(aVtkSize+1); + } + } + } + return make_pair(aNbCells,aCellsSize); + } + + const TField* TMesh::GetField(const string& theFieldName) const { + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap; + TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) + if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second); + } + return NULL; + } + + const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName) + throw(std::runtime_error&) + { + if(theFamilyName == "") return NULL; + const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName); + if(aFamilyMapIter == aFamilyMap.end()) + throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!"); + const VISU::TFamily& aFamily = aFamilyMapIter->second; + return &aFamily; + } + + TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName) + throw(std::runtime_error&) + { + if(theFamilyName == "") return NULL; + VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap; + VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName); + if(aFamilyMapIter == aFamilyMap.end()) + throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!"); + VISU::TFamily& aFamily = aFamilyMapIter->second; + return &aFamily; + } + + void TField::ShallowCopy(const TField& aField){ + myEntity = aField.myEntity; + myMeshName = aField.myMeshName; + myNbComp = aField.myNbComp; + VISU::TField::TValField::const_iterator iter = aField.myValField.begin(); + for(; iter != aField.myValField.end(); iter++) + myValField[iter->first]; + } +} + + +const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){ + if(!myIsDone) { myIsDone = true; Build();} + return myMeshMap; +} + + +string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){ + static QString aName; + const string aUnits = aTime.second, tmp(aUnits.size(),' '); + if(aUnits == "" || aUnits == tmp) + aName.sprintf("%g, -",aTime.first); + else + aName.sprintf("%g, %s",aTime.first,aTime.second.c_str()); + aName = aName.simplifyWhiteSpace(); + return aName.latin1(); +} + +string VISU_Convertor::GenerateName(const string& theName, unsigned int theTimeId) { + static QString aName; + aName = QString(theName.c_str()).simplifyWhiteSpace(); + int iEnd = strlen(aName); + static int VtkHighLevelLength = 12; //25 + if(iEnd > VtkHighLevelLength) iEnd = VtkHighLevelLength; + char aNewName[iEnd+1]; + aNewName[iEnd] = '\0'; + strncpy(aNewName,aName,iEnd); + replace(aNewName,aNewName+iEnd,' ','_'); + if(true || theTimeId == 0) + aName = aNewName; + else + aName.sprintf("%s_%d",aNewName,theTimeId); + return aName.latin1(); +} diff --git a/src/CONVERTOR/VISU_Convertor.hxx b/src/CONVERTOR/VISU_Convertor.hxx new file mode 100644 index 00000000..490ae99f --- /dev/null +++ b/src/CONVERTOR/VISU_Convertor.hxx @@ -0,0 +1,267 @@ +// 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 +// +// +// File : VISU_Convertor.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_Convertor_HeaderFile +#define VISU_Convertor_HeaderFile + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef MESSAGE +#define MESSAGE(msg) std::cout< +#include +#include + +namespace VISU{ + class TVtkCellInfo{ + public: + TVtkCellInfo() {} + TVtkCellInfo(const char* theName, vtkIdType theSize) : + myName(theName), mySize(theSize) {} + const char* myName; + vtkIdType mySize; + }; + typedef std::map TVtkCellInfoMap; + extern TVtkCellInfoMap aVtkCellInfoMap; + + enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY}; + template class vtk_ptr { + private: + _Tp* _M_ptr; + public: + typedef _Tp element_type; + explicit vtk_ptr(_Tp* __p = 0) : _M_ptr(__p) {} + vtk_ptr(const vtk_ptr& __a) : _M_ptr(0) {} + vtk_ptr(vtk_ptr& __a) : _M_ptr(__a.release()) {} + vtk_ptr& operator=(const vtk_ptr& __a) { return *this;} + vtk_ptr& operator=(vtk_ptr& __a) { + if (&__a != this) { + if(_M_ptr) _M_ptr->Delete(); + _M_ptr = __a.release(); + } + return *this; + } + ~vtk_ptr() { + if(_M_ptr) _M_ptr->Delete(); + _M_ptr = 0; + } + _Tp& operator*() const { return *_M_ptr;} + _Tp* operator->() const { return _M_ptr;} + _Tp* get() const { return _M_ptr;} + _Tp* release() { + _Tp* __tmp = _M_ptr; + _M_ptr = 0; + return __tmp; + } + void reset(_Tp* __p = 0) { + if(_M_ptr) _M_ptr->Delete(); + _M_ptr = __p; + } + }; + typedef vtk_ptr TVTKSource; + typedef vtk_ptr TVTKPoints; + + typedef std::set TBindGroups; + + struct TFamily{ + TVTKSource myStorage; + vtkIdType myId; + std::string myName; + TEntity myEntity; + TBindGroups myGroups; + vtkIdType myNbCells, myCellsSize; + typedef std::set TSubMeshOnCellType; + typedef std::map TSubMesh; + TSubMesh mySubMesh; + TFamily() : myNbCells(0), myCellsSize(0) {} + }; + typedef std::map TFamilyMap; + + struct TField{ + vtkIdType myId; + std::string myName; + TEntity myEntity; + std::string myMeshName; + vtkIdType myNbComp, myNbValField, myDataSize; + typedef std::vector TValForCellsWithType; + typedef std::map TValForCells; + typedef std::pair TTime; + typedef std::vector TCompNames; + typedef std::vector TUnitNames; + struct TValForTime{ + TVTKSource myStorage; + vtkIdType myId; + std::string myMeshName; + TEntity myEntity; + std::string myFieldName; + vtkIdType myNbComp; + TTime myTime; + TValForCells myValForCells; + TValForTime() : myNbComp(0) {} + }; + typedef std::map TValField; + TValField myValField; + TCompNames myCompNames; + TUnitNames myUnitNames; + TField() : myNbComp(0), myNbValField(0), myDataSize(0) {} + void ShallowCopy(const TField& aField); + }; + typedef std::map TFieldMap; + + struct TMeshOnEntity{ + TVTKSource myStorage; + std::string myMeshName; + TEntity myEntity; + vtkIdType myNbCells, myCellsSize; + typedef std::vector TConnect; + typedef std::vector TConnForCellType; + typedef std::map TCellsConn; + TCellsConn myCellsConn; + TFamilyMap myFamilyMap; + TFieldMap myFieldMap; + TMeshOnEntity() : myNbCells(0), myCellsSize(0) {} + std::pair GetCellsDims(const std::string& theFamilyName = "") const + throw(std::runtime_error&); + }; + typedef std::map TMeshOnEntityMap; + const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName) + throw(std::runtime_error&); + TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName) + throw(std::runtime_error&); + + typedef std::pair TFamilyAndEntity; + typedef std::set TFamilyAndEntitySet; + struct TGroup{ + TVTKSource myStorage; + std::string myName; + std::string myMeshName; + vtkIdType myNbCells, myCellsSize; + TGroup() : myNbCells(0), myCellsSize(0) {} + TFamilyAndEntitySet myFamilyAndEntitySet; + }; + typedef std::map TGroupMap; + + struct TMesh{ + TVTKPoints myPoints; + vtkIdType myDim, myNbPoints; + std::string myName; + typedef float TCoord; + typedef std::vector TPointsCoord; + TPointsCoord myPointsCoord; + TMeshOnEntityMap myMeshOnEntityMap; + TGroupMap myGroupMap; + TMesh() : myDim(0), myNbPoints(0) {} + const TField* GetField(const std::string& theFieldName) const; + }; + typedef std::map TMeshMap; + void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName); +}; + +class VISU_Convertor{ +protected: + std::string myName; + VISU::TMeshMap myMeshMap; + int myIsDone; +public: + virtual ~VISU_Convertor(){}; + virtual const std::string& GetName() { return myName;} + virtual int IsDone() const { return myIsDone;} + typedef vtkUnstructuredGrid TOutput; + + virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0; + virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&); + + + virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") + throw(std::runtime_error&) = 0; + virtual vtkIdType GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") + throw (std::runtime_error&) = 0; + + + virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, + const std::string& theGroupName) + throw(std::runtime_error&) = 0; + virtual vtkIdType GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) + throw(std::runtime_error&) = 0; + + + virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&) = 0; + virtual vtkIdType GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&) = 0; + virtual vtkIdType GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) + throw(std::runtime_error&) = 0; + virtual const VISU::TField& GetField(const std::string& theMeshName, + VISU::TEntity theEntity, + const std::string& theFieldName) + throw(std::runtime_error&) = 0; + virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&) = 0; + + static std::string GenerateName(const VISU::TField::TTime& aTime); + static std::string GenerateName(const std::string& theName, unsigned int theTimeId); + static void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName); +}; + +extern "C"{ + VISU_Convertor* CreateMedConvertor(const std::string& theFileName) throw(std::runtime_error&); + VISU_Convertor* CreateDatConvertor(const std::string& theFileName) throw(std::runtime_error&); + VISU_Convertor* CreateConvertor(const std::string& theFileName) throw(std::runtime_error&); +}; + +#endif diff --git a/src/CONVERTOR/VISU_ConvertorUtils.cxx b/src/CONVERTOR/VISU_ConvertorUtils.cxx new file mode 100644 index 00000000..22cb5b2f --- /dev/null +++ b/src/CONVERTOR/VISU_ConvertorUtils.cxx @@ -0,0 +1,82 @@ +// 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 +// +// +// File : VISU_Convertor_impl.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Convertor_impl.hxx" + +#include + +using namespace std; + +#define MED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \ + {MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES} +Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE] = { + MED2VTK(MED_POINT1,VTK_VERTEX,1), + MED2VTK(MED_SEG2,VTK_LINE,2), + MED2VTK(MED_SEG3,VTK_LINE,2), + MED2VTK(MED_TRIA3,VTK_TRIANGLE,3), + MED2VTK(MED_TRIA6,VTK_TRIANGLE,3), + MED2VTK(MED_QUAD4,VTK_QUAD,4), + MED2VTK(MED_QUAD8,VTK_QUAD,4), + MED2VTK(MED_TETRA4,VTK_TETRA,4), + MED2VTK(MED_TETRA10,VTK_TETRA,4), + MED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8), + MED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8), + MED2VTK(MED_PENTA6,VTK_WEDGE,6), + MED2VTK(MED_PENTA15,VTK_WEDGE,6), + MED2VTK(MED_PYRA5,VTK_PYRAMID,5), + MED2VTK(MED_PYRA13,VTK_PYRAMID,5) +}; +#undef MED2VTK + +extern "C" { + int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim){ + int anElemDim = theMedType / 100, nsup = 0; + if(theMedEntity == VISU::CELL_ENTITY && anElemDim < theMeshDim) nsup = 1; + return nsup + theMedType % 100; + } + + int getNbMedNodes(int geom){ + return geom % 100; + } + + int getIdMedType(int medType){ + for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++) + if(med2vtk[i].medType == medType) return i; + return -1; + } + + int med2vtkCellType(int medType){ + for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++) + if(med2vtk[i].medType == medType) return med2vtk[i].vtkType; + return -1; + } + + int vtk2medCellType(int vtkType){ + for(int i = 0; i < MED_NBR_GEOMETRIE_MAILLE; i++) + if(med2vtk[i].vtkType == vtkType) return med2vtk[i].medType; + return -1; + } +} diff --git a/src/CONVERTOR/VISU_ConvertorUtils.hxx b/src/CONVERTOR/VISU_ConvertorUtils.hxx new file mode 100644 index 00000000..bc6dcad7 --- /dev/null +++ b/src/CONVERTOR/VISU_ConvertorUtils.hxx @@ -0,0 +1,67 @@ +// 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 +// +// +// File : VISU_Convertor_impl.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ConvertorUtils_HeaderFile +#define VISU_ConvertorUtils_HeaderFile + +extern "C"{ +#include +} + +#include +#include + +#include + +#include +#include + +template std::string dtos(const std::string& fmt, T val){ + static QString aString; + aString.sprintf(fmt.c_str(),val); + return aString.latin1(); +} + +extern "C"{ + int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim); + int getNbMedNodes(int theMedType); + int med2vtkCellType(int theMedType); + int vtk2medCellType(int theVtkType); + int getIdMedType(int medType); +} + +struct Med2vtk { + med_geometrie_element medType; + const char *medName; + int medNbNodes; + int vtkType; + const char *vtkName; + int vtkNbNodes; +}; + +extern Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE]; + +#endif diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx new file mode 100644 index 00000000..8f6ed718 --- /dev/null +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -0,0 +1,606 @@ +// 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 +// +// +// File : VISU_Convertor_impl.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Convertor_impl.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + + +VISU_Convertor_impl::VISU_Convertor_impl() { + myIsDone = false; +} + +VISU_Convertor_impl::~VISU_Convertor_impl() {} + +VISU_Convertor::TOutput* +VISU_Convertor_impl::GetMeshOnEntity(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFamilyName) + throw (std::runtime_error&) +{ + if(MYDEBUG) + MESSAGE("GetMeshOnEntity - theMeshName = '"<myStorage); + else + pSource = &(aMeshOnEntity.myStorage); + VISU::TVTKSource& aSource = *pSource; + //Main part of code + if(aSource.get() == NULL){ + aSource.reset(TOutput::New()); + LoadMeshOnEntity(aMeshOnEntity,theFamilyName); + GetPoints(aSource,aMesh); + GetCellsOnEntity(aSource,aMeshOnEntity,theFamilyName); + if(MYDEBUGWITHFILES){ + string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1(); + string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk"; + VISU::WriteToFile(aSource.get(),aFileName); + } + } + return aSource.get(); +} + +VISU_Convertor::TOutput* +VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName, + const string& theGroupName) + throw(std::runtime_error&) +{ + if(MYDEBUG) MESSAGE("GetMeshOnGroup - theMeshName = '"<ShallowCopy(aVTKMeshOnEntity.myStorage.get()); + GetField(aSource,aMesh,aVTKMeshOnEntity,aField,aValForTime); + if(MYDEBUGWITHFILES){ + string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1(); + string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk"; + VISU::WriteToFile(aSource.get(),aFileName); + } + } + return aSource.get(); +} + +inline void PrintCells(int& theStartId, + vtkCellArray* theConnectivity, + const VISU::TMeshOnEntity::TConnect& theVector) +{ + vtkIdList *anIdList = vtkIdList::New(); + int kEnd = theVector.size(); + anIdList->SetNumberOfIds(kEnd); + for(int k = 0; k < kEnd; k++){ + anIdList->SetId(k,theVector[k]); + //anIdList->InsertNextId(theVector[k]); + } + theConnectivity->InsertNextCell(anIdList); + anIdList->Delete(); +} + +void VISU_Convertor_impl::GetCellsOnEntity(VISU::TVTKSource& theStorage, + const VISU::TMeshOnEntity& theMeshOnEntity, + const string& theFamilyName) + const throw (std::runtime_error&) +{ + //Check on existing family + const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName); + bool isFamilyPresent = (pFamily != NULL); + const VISU::TFamily& aFamily = *pFamily; + //Main part of code + pair aCellsDim = theMeshOnEntity.GetCellsDims(theFamilyName); + int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second; + vtkCellArray* aConnectivity = vtkCellArray::New(); + //vtkIdType *anIdArray = aConnectivity->WritePointer(0,aCellsSize); + aConnectivity->Allocate(aCellsSize,0); + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents(1); + aCellTypesArray->SetNumberOfTuples(aNbCells); + if(MYDEBUG) MESSAGE("GetCellsOnEntity - isFamilyPresent = "<second; + int aVtkType = aCellsConnIter->first; + if(MYDEBUG) MESSAGE("GetCellsOnEntity - aVtkType = "<> There is no elements on the family !!!"); + VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + if(MYDEBUG) MESSAGE("GetCellsOnEntity - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); + //aCellTypesArray->InsertNextValue((unsigned char)aVtkType); + } + } + } + vtkIdType *pts = 0, npts = 0; + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents(1); + aCellLocationsArray->SetNumberOfTuples(aNbCells); + aConnectivity->InitTraversal(); + for(int i=0; aConnectivity->GetNextCell(npts,pts); i++){ + aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); + //aCellLocationsArray->InsertNextValue(aConnectivity->GetTraversalLocation(npts)); + } + theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); +} + + +void VISU_Convertor_impl::GetCellsOnGroup(VISU::TVTKSource& theStorage, + const VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + const throw (std::runtime_error&) +{ + //Calculate dimentions of the group + int aNbCells = 0, aCellsSize = 0; + VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); + for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ + const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; + const string& aFamilyName = aFamilyAndEntity.first; + const VISU::TEntity& anEntity = aFamilyAndEntity.second; + const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; + pair aCellsDim = aMeshOnEntity.GetCellsDims(aFamilyName); + aNbCells += aCellsDim.first; + aCellsSize += aCellsDim.second; + } + vtkCellArray* aConnectivity = vtkCellArray::New(); + //vtkIdType *anIdArray = aConnectivity->WritePointer(0,aCellsSize); + aConnectivity->Allocate(aCellsSize,0); + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents(1); + aCellTypesArray->SetNumberOfTuples(aNbCells); + aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); + for(int i = 0, j = 0; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ + const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; + const string& aFamilyName = aFamilyAndEntity.first; + const VISU::TEntity& anEntity = aFamilyAndEntity.second; + const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; + const VISU::TFamily& aFamily = *(VISU::GetFamily(aMeshOnEntity,aFamilyName)); + const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn; + VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); + for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ + const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second; + int aVtkType = aCellsConnIter->first; + if(MYDEBUG) MESSAGE("GetCellsOnGroup - aVtkType = "<> There is no elements on the family !!!"); + VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + if(MYDEBUG) MESSAGE("GetCellsOnGroup - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); + //aCellTypesArray->InsertNextValue((unsigned char)aVtkType); + } + } + } + vtkIdType *pts = 0, npts = 0; + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents(1); + aCellLocationsArray->SetNumberOfTuples(aNbCells); + aConnectivity->InitTraversal(); + for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++){ + aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); + //aCellLocationsArray->InsertNextValue(aConnectivity->GetTraversalLocation(npts)); + } + theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); +} + + +void VISU_Convertor_impl::GetPoints(VISU::TVTKSource& theStorage, const VISU::TMesh& theMesh) + const throw (std::runtime_error&) +{ + vtkPoints* aPoints = theMesh.myPoints.get(); + if(!aPoints){ + aPoints = vtkPoints::New(); + const VISU::TMesh::TPointsCoord& anArray = theMesh.myPointsCoord; + vtkIdType iEnd = theMesh.myPointsCoord.size(); + vtkIdType aNbPoints = iEnd / theMesh.myDim; + aPoints->SetNumberOfPoints(aNbPoints); + if(MYDEBUG) + MESSAGE("GetPoints - aNbPoints = "<SetName(aFieldName.c_str()); + if(MYDEBUG) MESSAGE("GetField - aNumberOfTuples = "<second; + int iEnd = anArray.size()/theField.myNbComp; + int aVtkType = aValForCellsIter->first; + if(MYDEBUG) MESSAGE("GetField - iEnd = "<> There is no mesh with the name!!!"); + theMesh = &myMeshMap[theMeshName]; +} + + +void VISU_Convertor_impl::FindMeshOnEntity(const string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, VISU::TMeshOnEntity*& theMeshOnEntity, + const string& theFamilyName, VISU::TFamily*& theFamily) + throw (std::runtime_error&) +{ + FindMesh(theMeshName,theMesh); + VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.find(theEntity) == aMeshOnEntityMap.end()) + throw std::runtime_error("FindMeshOnEntity >> There is no mesh on the entity!!!"); + theMeshOnEntity = &aMeshOnEntityMap[theEntity]; + theFamily = VISU::GetFamily(*theMeshOnEntity,theFamilyName); +} + + +vtkIdType VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) + throw (std::runtime_error&) +{ + VISU::TMesh* pMesh = NULL; + VISU::TFamily* pFamily = NULL; + VISU::TMeshOnEntity* pMeshOnEntity = NULL; + FindMeshOnEntity(theMeshName,pMesh,theEntity,pMeshOnEntity,theFamilyName,pFamily); + vtkIdType aResult = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord); + vtkIdType aNbCells, aCellsSize; + if(!pFamily){ + aNbCells = pMeshOnEntity->myNbCells; + aCellsSize = pMeshOnEntity->myCellsSize; + }else{ + aNbCells = pFamily->myNbCells; + aCellsSize = pFamily->myCellsSize; + } + //that is Connectivity + (Types + Locations + Links) + aResult += aCellsSize*sizeof(vtkIdType) + + aNbCells*(sizeof(char) + sizeof(int) + (sizeof(short) + sizeof(vtkIdType))); + if(MYDEBUG) cout<<"VISU_Convertor_impl::GetMeshOnEntitySize = "<myGroupMap; + VISU::TGroupMap::iterator aGroupMapIter = aGroupMap.find(theGroupName); + if(aGroupMapIter == aGroupMap.end()) + throw std::runtime_error("FindMeshOnGroup >> There is no the group in the mesh!!!"); + theGroup = &aGroupMapIter->second; +} + + +vtkIdType VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) + throw (std::runtime_error&) +{ + VISU::TMesh* pMesh = NULL; + VISU::TGroup* pGroup = NULL; + FindMeshOnGroup(theMeshName,pMesh,theGroupName,pGroup); + vtkIdType aResult = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord); + aResult += pGroup->myCellsSize*sizeof(vtkIdType); + if(MYDEBUG) cout<<"VISU_Convertor_impl::GetMeshOnGroupSize = "<myMeshOnEntityMap; + if(theEntity == VISU::NODE_ENTITY){ + if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) == aMeshOnEntityMap.end()) + throw std::runtime_error("FindField >> There is no mesh on CELL_ENTITY!!!"); + pMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY]; + } + theVTKMeshOnEntity = pMeshOnEntity; + VISU::TFieldMap& aFieldMap = theMeshOnEntity->myFieldMap; + if(aFieldMap.find(theFieldName) == aFieldMap.end()) + throw std::runtime_error("FindField >> There is no field on the mesh!!!"); + theField = &aFieldMap[theFieldName]; +} + + +vtkIdType VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) + throw(std::runtime_error&) +{ + VISU::TMesh* pMesh = NULL; + VISU::TField* pField = NULL; + VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL; + FindField(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity, + theFieldName,pField); + + vtkIdType aResult = GetMeshOnEntitySize(theMeshName,theEntity); + aResult += pField->myDataSize*sizeof(float)*pField->myNbValField; + if(MYDEBUG) cout<<"VISU_Convertor_impl::GetFieldOnMeshSize = "<myValField; + if(aValField.find(theStampsNum) == aValField.end()) + throw std::runtime_error("FindTimeStamp >> There is no field with the timestamp!!!"); + theValForTime = &aValField[theStampsNum]; +} + + +vtkIdType VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw (std::runtime_error&) +{ + VISU::TMesh* pMesh = NULL; + VISU::TField* pField = NULL; + VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL; + VISU::TField::TValForTime* pValForTime = NULL; + FindTimeStamp(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity, + theFieldName,pField,theStampsNum,pValForTime); + + vtkIdType aResult = GetMeshOnEntitySize(theMeshName,theEntity); + aResult += pField->myDataSize*sizeof(float); + if(MYDEBUG) cout<<"VISU_Convertor_impl::GetTimeStampSize = "< +} + +#include +#include + +class VISU_Convertor_impl: public VISU_Convertor{ +private: + void GetPoints(VISU::TVTKSource& theStorage, + const VISU::TMesh& theMesh) + const throw (std::runtime_error&); + void GetCellsOnEntity(VISU::TVTKSource& theStorage, + const VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName) + const throw (std::runtime_error&); + void GetCellsOnGroup(VISU::TVTKSource& theStorage, + const VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + const throw (std::runtime_error&); + void GetField(VISU::TVTKSource& theStorage, + const VISU::TMesh& theMesh, + const VISU::TMeshOnEntity& theMeshOnEntity, + const VISU::TField& theField, + const VISU::TField::TValForTime& theValForTime) + const throw (std::runtime_error&); + + +protected: + void FindMesh(const std::string& theMeshName, VISU::TMesh*& theMesh) + throw(std::runtime_error&); + void FindMeshOnEntity(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, VISU::TMeshOnEntity*& theMeshOnEntity, + const std::string& theFamilyName, VISU::TFamily*& theFamily) + throw (std::runtime_error&); + + void FindMeshOnGroup(const std::string& theMeshName, VISU::TMesh*& theMesh, + const std::string& theGroupName, VISU::TGroup*& theGroup) + throw (std::runtime_error&); + + void FindField(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, + VISU::TMeshOnEntity*& theMeshOnEntity, + VISU::TMeshOnEntity*& theVTKMeshOnEntity, + const std::string& theFieldName, VISU::TField*& theField) + throw (std::runtime_error&); + void FindTimeStamp(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, + VISU::TMeshOnEntity*& theMeshOnEntity, + VISU::TMeshOnEntity*& theVTKMeshOnEntity, + const std::string& theFieldName, VISU::TField*& theField, + int theStampsNum, VISU::TField::TValForTime*& theValForTime) + throw (std::runtime_error&); + + +public: + virtual vtkIdType GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") + throw (std::runtime_error&); + virtual vtkIdType GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) + throw(std::runtime_error&); + virtual vtkIdType GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&); + virtual vtkIdType GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) + throw(std::runtime_error&); + virtual const VISU::TField& GetField(const std::string& theMeshName, + VISU::TEntity theEntity, + const std::string& theFieldName) + throw(std::runtime_error&); + virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&); + +public: + VISU_Convertor_impl(); + virtual ~VISU_Convertor_impl(); + virtual VISU_Convertor* Build() throw (std::runtime_error&) { return this;}; + virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") + throw(std::runtime_error&); + virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, + const std::string& theGroupName) + throw(std::runtime_error&); + virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) + throw(std::runtime_error&); + + protected: + virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName = "") + throw (std::runtime_error&) = 0; + virtual int LoadMeshOnGroup(VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + throw (std::runtime_error&) = 0; + virtual int LoadFieldOnMesh(VISU::TMesh& theMesh, + VISU::TMeshOnEntity& theMeshOnEntity, + VISU::TField& theField, + VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) = 0; +}; + +template std::string dtos(const std::string& fmt, T val){ + static QString aString; + aString.sprintf(fmt.c_str(),val); + return aString.latin1(); +} + +extern "C"{ + int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim); + int getNbMedNodes(int theMedType); + int med2vtkCellType(int theMedType); + int vtk2medCellType(int theVtkType); + int getIdMedType(int medType); +} + +struct Med2vtk { + med_geometrie_element medType; + const char *medName; + int medNbNodes; + int vtkType; + const char *vtkName; + int vtkNbNodes; +}; +extern Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE]; +#endif diff --git a/src/CONVERTOR/VISU_DatConvertor.cxx b/src/CONVERTOR/VISU_DatConvertor.cxx new file mode 100644 index 00000000..91151aff --- /dev/null +++ b/src/CONVERTOR/VISU_DatConvertor.cxx @@ -0,0 +1,253 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VISU_DatConvertor.cxx +// Author : Alexey PETROV +// Module : VISU + +using namespace std; +#include "VISU_DatConvertor.hxx" +using namespace std; + +#ifdef DEBUG +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif +static int PRECISION = 7; + +extern "C" +VISU_Convertor* CreateDatConvertor(const string& theFileName) throw(std::runtime_error&){ + VISU_DatConvertor* aConvertor = new VISU_DatConvertor(theFileName); + aConvertor->Build(); + return aConvertor; +} +VISU_DatConvertor::VISU_DatConvertor(const string& theFileName) throw(std::runtime_error&){ + myFileInfo.setFile(QString(theFileName.c_str())); + myName = (const char*)(myFileInfo.baseName()); +} + +VISU_Convertor* VISU_DatConvertor::Build() throw (std::runtime_error&){ + /* + ifstream stmIn(myFileInfo.absFilePath()); + if(!stmIn.good()) + throw std::runtime_error(string("VISU_DatConvertor::CreateResult() >> can't open file - ") + + (const char*)myFileInfo.absFilePath()); + int aNbPoints, aNbCells, aNbFields; + ImportHead(&stmIn,&aNbPoints,&aNbCells,&aNbFields); + ImportPoints(&stmIn,aNbPoints); + vector aCellsType(aNbCells); + ImportCells(&stmIn,&aCellsType); + for(int i = 0; i < aNbFields; i++) + ImportField(&stmIn,aNbPoints,&aCellsType); + myIsDone = true; + */ + return this; +} + +int VISU_DatConvertor::ImportField(ifstream* pStmIn, int theNbPoints, vector* pCellsType) + throw (std::runtime_error&) +{ + /* + ifstream &stmIn = *pStmIn; + vector& aCellsType = *pCellsType; + int aNbCells = aCellsType.size(); + string aName; stmIn>>aName; stmIn>>aName; + VISU::TMesh& aMesh = myMeshMap[myName]; + VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY]; + VISU::TField& aField = aMeshOnEntity.myFieldMap[aName]; + aField.myMeshName = myName; + stmIn>>(aField.myNbComp); + aField.myNbComp %= 100; + int iEnd; stmIn>>iEnd; + if(iEnd == theNbPoints) + aField.myEntity = VISU::NODE_ENTITY; + else if(iEnd == aNbCells) + aField.myEntity = VISU::CELL_ENTITY; + else + throw std::runtime_error("ImportChamp >> elements doesn't connected to points or cells"); + if(MYDEBUG) + MESSAGE("FieldInfo - myMeshName = "<>tmp; + anArray.push_back(tmp); + } + } + */ + return 0; +} + +int VISU_DatConvertor::ImportHead(ifstream* pStmIn, int* theNbPoints, + int* theNbCells, int* theNbFields) + throw (std::runtime_error&) +{ + /* + ifstream &stmIn = *pStmIn; + const int BUFSIZE = 256; + char buf[BUFSIZE]; + stmIn.getline(buf,BUFSIZE); + istrstream strIn(buf); + VISU::TMesh& aMesh = myMeshMap[myName]; + *theNbFields = 0; + strIn>>(*theNbPoints); strIn>>(*theNbCells); strIn>>(*theNbFields); + if(MYDEBUG) + MESSAGE("ImportHead - theNbPoints = "<<(*theNbPoints)<< + "; theNbCells = "<<(*theNbCells)<< + "; theNbFields = "<<(*theNbFields)); + */ + return 0; +} + +int VISU_DatConvertor::ImportPoints(ifstream* pStmIn, int theNbPoints) + throw (std::runtime_error&) +{ + /* + ifstream &stmIn = *pStmIn; + VISU::TMesh& aMesh = myMeshMap[myName]; + aMesh.myName = myName; + aMesh.myDim = 3; + int iEnd = aMesh.myDim*theNbPoints; + if(MYDEBUG) MESSAGE("ImportPoints - iEnd = "< &aPointsCoord = aMesh.myPointsCoord; + aPointsCoord.resize(iEnd); + for(int i = 0, tmp; i < iEnd;){ + stmIn>>tmp; + stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++]; stmIn>>aPointsCoord[i++]; + } + */ + return 0; +} + +int VISU_DatConvertor::ImportCells(ifstream* pStmIn, vector* pCellsType) + throw (std::runtime_error&) +{ + /* + ifstream &stmIn = *pStmIn; + vector& aCellsType = *pCellsType; + int aNbCells = aCellsType.size(); + if(MYDEBUG) MESSAGE("ImportCells - theNbCells - Beginning"); + VISU::TMesh& aMesh = myMeshMap[myName]; + VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY]; + aMeshOnEntity.myEntity = VISU::CELL_ENTITY; + aMeshOnEntity.myMeshName = myName; + for(int i = 0, aMedType, aVtkType; i < aNbCells; i++){ + stmIn>>aMedType; stmIn>>aMedType; + aCellsType[i] = aVtkType = med2vtkCellType(aMedType); + VISU::TMeshOnEntity::TConnForCellType& anArray = aMeshOnEntity.myCellsConn[aVtkType]; + anArray.push_back(VISU::TMeshOnEntity::TConnect()); + VISU::TMeshOnEntity::TConnect& aVector = anArray.back(); + int jEnd = getNbMedNodes(aMedType); + aVector.resize(jEnd); + for(int j = 0, tmp; j < jEnd; j++){ + stmIn>>tmp; + aVector[j] = tmp - 1; + } + } + if(MYDEBUG) MESSAGE("ImportCells - theNbCells - End"); + */ + return 0; +} + +/* +int VISU_Convertor_impl::ToDatFile(const string& theFileName) throw(std::runtime_error&){ + if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - "<second; + if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aMeshName = "<first); + VISU::TFieldMap aFieldMap = GetFieldMapForMesh(aMeshIter->first); + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(VISU::CELL_ENTITY); + if(aMeshOnEntityMapIter != aMeshOnEntityMap.end()){ + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim; + int aNbCells = aMeshOnEntity.GetCellsDims().first; + stmOut<first)<<"\t"; + const vector& aVector = anArray[j]; + int kEnd = aVector.size(); + for(int k = 0; k < kEnd; k++) + stmOut<second; + const VISU::TField::TValField &aValField = aField.myValField; + VISU::TField::TValField::const_reverse_iterator iter = aField.myValField.rbegin(); + for(int i = 0; iter != aValField.rend(); iter++, i++) { + if(MYDEBUG) MESSAGE("VISU_Convertor_impl::ToDatFile - aTime = "<second; + VISU::TField::TValForTime::const_iterator jter = aValForTime.begin(); + stmOut<<(++i)<first).c_str(),i); + stmOut< + +class VISU_DatConvertor: public VISU_Convertor_impl{ + VISU_DatConvertor(); + VISU_DatConvertor(const VISU_DatConvertor&); +public: + VISU_DatConvertor(const string& theFileName) throw (std::runtime_error&); + virtual VISU_Convertor* Build() throw (std::runtime_error&); +protected: + QFileInfo myFileInfo; + int ImportHead(ifstream* pStmIn, int* theNbPoints, int* theNbCells, int* theNbFields) + throw (std::runtime_error&); + int ImportPoints(ifstream*, int theNbPoints) + throw (std::runtime_error&); + int ImportCells(ifstream*, vector* aCellsType) + throw (std::runtime_error&); + int ImportField(ifstream*, int theNbPoints, vector* aCellsType) + throw (std::runtime_error&); + protected: + virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, + const string& theFamilyName = "") + throw (std::runtime_error&) {return 1;} + virtual int LoadMeshOnGroup(VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + throw (std::runtime_error&) {return 1;} + virtual int LoadFieldOnMesh(VISU::TMesh& theMesh, + VISU::TMeshOnEntity& theMeshOnEntity, + VISU::TField& theField, + VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) {return 1;} +}; + +#endif diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx new file mode 100644 index 00000000..9587f53f --- /dev/null +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -0,0 +1,711 @@ +// 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 +// +// +// File : VISU_MedConvertor.cxx +// Author : Alexey PETROV +// Module : VISU + + +#include "VISU_MedConvertor.hxx" +#include +#include +#define USER_INTERLACE MED_FULL_INTERLACE + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +static med_err ret = 0; + +typedef map TVisu2MedEntity; + +static TVisu2MedEntity aVisu2MedEntity; + +static int INIT = ( + aVisu2MedEntity[VISU::NODE_ENTITY] = MED_NOEUD, + aVisu2MedEntity[VISU::EDGE_ENTITY] = MED_ARETE, + aVisu2MedEntity[VISU::FACE_ENTITY] = MED_FACE, + aVisu2MedEntity[VISU::CELL_ENTITY] = MED_MAILLE, + 1); + +static med_geometrie_element NODEGEOM[1] = {MED_POINT1}; + +static med_geometrie_element EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = { + MED_SEG2, MED_SEG3 + }; + +static med_geometrie_element FACEGEOM[MED_NBR_GEOMETRIE_FACE] = { + MED_TRIA3, MED_QUAD4, MED_TRIA6, MED_QUAD8 + }; + +static med_geometrie_element CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = { + MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3, + MED_QUAD4, MED_TRIA6, MED_QUAD8, MED_TETRA4, + MED_PYRA5, MED_PENTA6, MED_HEXA8, MED_TETRA10, + MED_PYRA13, MED_PENTA15, MED_HEXA20 + }; + +void GetEntity2Geom(const VISU::TEntity& theEntity, med_geometrie_element*& theVector, int* theEnd) + throw (std::runtime_error&) +{ + switch(theEntity){ + case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break; + case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break; + case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break; + case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break; + default: + throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect"); + } +} + +extern "C" +VISU_Convertor* CreateMedConvertor(const string& theFileName) throw(std::runtime_error&){ + return new VISU_MedConvertor(theFileName); +} + +class MedFile{ + char* myFileName; + med_idt myFid; + MedFile(); + MedFile(const MedFile&); +public: + MedFile(const char* theFileName) throw(std::runtime_error&) : + myFileName(strdup(theFileName)) + { + myFid = MEDouvrir(myFileName,MED_LECT); + if(myFid < 0){ + free(myFileName); + throw std::runtime_error(string("MedFile::MedFile >> MEDouvrir(...) - ") + theFileName); + } + } + ~MedFile(){ + free(myFileName); + if(myFid >= 0) + MEDfermer(myFid); + } + const med_idt& GetFid() const { return myFid;}; +}; + +VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) throw (std::runtime_error&) { + myFileInfo.setFile(QString(theFileName.c_str())); + myName = myFileInfo.baseName().latin1(); +} + +VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { + MedFile aMedFile(myFileInfo.absFilePath()); + med_idt fid = aMedFile.GetFid(); + med_int iMeshEnd = MEDnMaa(fid); //Get number of meshes + if(MYDEBUG) MESSAGE("ImportInfo - MEDnMaa = "<> MEDnoeudsLire(...)"); + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + if(num_fam_elem[iNumElem] != 0){ + aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity; + aFamilyNbCellsCounterMap[num_fam_elem[iNumElem]] += 1; + aFamilyCellsSizeCounterMap[num_fam_elem[iNumElem]] += 2; + } + } + } + //Get number of connectivities + med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aMedType,MED_NOD); + if (iNumElemEnd > 0) { + VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity]; + aMeshOnEntity.myEntity = anEntity; + aMeshOnEntity.myMeshName = aMeshName; + med_booleen iname_elem, inum_elem; + valarray num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); + valarray name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1); + med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim); + aMeshOnEntity.myNbCells += iNumElemEnd; + aMeshOnEntity.myCellsSize += iNumElemEnd*(med2vtk[medId].vtkNbNodes + 1); + if(MYDEBUG) + MESSAGE("ImportInfo -\t anEntity = "<> MEDelementsLire(...)"); + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + if(num_fam_elem[iNumElem] != 0){ + aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity; + aFamilyNbCellsCounterMap[num_fam_elem[iNumElem]] += 1; + aFamilyCellsSizeCounterMap[num_fam_elem[iNumElem]] += med2vtk[medId].vtkNbNodes + 1; + } + } + } + } + med_int aNbFamily = MEDnFam(fid,aMeshName,0,MED_FAMILLE); + if(MYDEBUG) MESSAGE("ImportInfo - aNbFamily = "< anAttId(aNbAttrib), anAttVal(aNbAttrib); + valarray anAttDesc('\0',aNbAttrib*MED_TAILLE_DESC+1); + med_int aNbGroup = MEDnFam(fid,aMeshName,aFamInd,MED_GROUPE); + if(0 && MYDEBUG) + MESSAGE("ImportInfo - aFamInd = "<> MEDfamInfo"); + if(0 && MYDEBUG) + MESSAGE("ImportInfo - aFamilyNum = "<second; + const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap; + if(aFamilyMap.empty()) continue; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const VISU::TFamily& aFamily = aFamilyMapIter->second; + const VISU::TBindGroups& aBindGroups = aFamily.myGroups; + if(aBindGroups.empty()) continue; + VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin(); + for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){ + const string& aGroupName = *aBindGroupsIter; + VISU::TGroup& aGroup = aGroupMap[aGroupName]; + aGroup.myName = aGroupName; + aGroup.myMeshName = aMesh.myName; + VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity); + aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity); + aGroup.myNbCells += aFamily.myNbCells; + aGroup.myCellsSize += aFamily.myCellsSize; + } + } + } + //Displaing information for the TMesh.TGroupMap + VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + if(MYDEBUG) MESSAGE("ImportInfo - aGroupMap.size() = "<second; + const string& aGroupName = aGroupMapIter->first; + if(MYDEBUG) MESSAGE("ImportInfo - aGroupName = '"<> MEDnChamp(fid,0)"); + if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<> MEDnChamp(fid,i)"); + valarray aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1); + valarray aUnitNames('\0',ncomp*MED_TAILLE_PNOM + 1); + char name_field[MED_TAILLE_NOM + 1] = ""; + med_type_champ type_field; + if(MEDchampInfo(fid,iField,name_field,&type_field,&aCompNames[0],&aUnitNames[0],ncomp) < 0) + throw std::runtime_error(string("ImportInfo >> MEDchampInfo(...)")); + //if(type_field != MED_REEL64) continue; //There is some problem in reading INTXX values + TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin(); + for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) { + VISU::TEntity anEntity = aVisu2MedEntityIter->first; + int iGeomElemEnd; + med_geometrie_element* aGeomElemVector; + GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd); + med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity]; + for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) { + med_geometrie_element& aGeom = aGeomElemVector[iGeomElem]; + med_int iTimeStampEnd = MEDnPasdetemps(fid,name_field,aMedEntity,aGeom); + if(iTimeStampEnd < 0) throw std::runtime_error("ImportInfo >> MEDnPasdetemps(...)"); + if(iTimeStampEnd > 0) { + for(med_int iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++) { + char aMeshName[MED_TAILLE_NOM+1] = ""; + med_int ngauss = 0, numdt = 0, numo = 0; + char dt_unit[MED_TAILLE_PNOM+1] = ""; + med_float dt = 0; + ret = MEDpasdetempsInfo(fid,name_field,aMedEntity,aGeom,iTimeStamp, + aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo); + if(ret < 0) throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...) < 0"); + if(myMeshMap.find(aMeshName) == myMeshMap.end()) + throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...)"); + VISU::TMesh &aMesh = myMeshMap[aMeshName]; + VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity]; + VISU::TFieldMap::iterator aFieldMapIter = aMeshOnEntity.myFieldMap.find(name_field); + //if(MYDEBUG && aFieldMapIter == aMeshOnEntity.myFieldMap.end()){ + VISU::TField& aField = aMeshOnEntity.myFieldMap[name_field]; + if(iTimeStamp == 1){ + aField.myId = iField; + aField.myName = name_field; + aField.myEntity = anEntity; + aField.myMeshName = aMeshName; + aField.myNbComp = ncomp; + aField.myNbValField = iTimeStampEnd; + aField.myDataSize = aMeshOnEntity.myNbCells * ncomp; + aField.myCompNames.resize(ncomp); + aField.myUnitNames.resize(ncomp); + if(MYDEBUG) + MESSAGE("ImportInfo - aField.myName = '"<first; + const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second; + VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity]; + if(anEntity == VISU::NODE_ENTITY){ + isPointsUpdated += LoadPoints(fid,theMesh,aFamilyName); + isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity); + }else{ + isPointsUpdated += LoadPoints(fid,theMesh); + isCellsOnEntityUpdated += LoadCellsOnEntity(fid,aMeshOnEntity,aFamilyName); + } + } + + return (isPointsUpdated || isCellsOnEntityUpdated); +} + +int VISU_MedConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh, + VISU::TMeshOnEntity& theMeshOnEntity, + VISU::TField& theField, + VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) +{ + //Open the med file (it will be closed by call of destructor) + MedFile aMedFile(myFileInfo.absFilePath()); + med_idt fid = aMedFile.GetFid(); + //Main part of code + int isPointsUpdated = LoadPoints(fid,theMesh); + int isCellsOnEntityUpdated = LoadCellsOnEntity(fid,theMeshOnEntity); + int isFieldUpdated = LoadField(fid,theMeshOnEntity,theField,theValForTime); + + return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated); +} + +int VISU_MedConvertor::LoadPoints(const med_idt& fid, VISU::TMesh& theMesh, const string& theFamilyName) + throw (std::runtime_error&) +{ + try{ + //Check on existing family + VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY]; + aMeshOnEntity.myEntity = VISU::NODE_ENTITY; + aMeshOnEntity.myMeshName = theMesh.myName; + VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName); + bool isFamilyPresent = (pFamily != NULL); + VISU::TFamily& aFamily = *pFamily; + //Check on loading already done + bool isPointsLoaded = !theMesh.myPointsCoord.empty(); + if(isPointsLoaded) + if(!isFamilyPresent) return 0; + else if(!aFamily.mySubMesh.empty()) return 0; + if(MYDEBUG) + MESSAGE("LoadPoints - isPointsLoaded = "<> MEDnEntMaa(...)"); + if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "< num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); + valarray name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1); + valarray name_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1); + valarray unit_coord('\0',theMesh.myDim*MED_TAILLE_PNOM+1); + valarray coord(theMesh.myDim*iNumElemEnd); + ret = MEDnoeudsLire(fid,aMeshName,theMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep, + &name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem, + &num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd); + if(ret < 0) throw std::runtime_error("LoadPoints >> MEDnoeudsLire(...)"); + if(!isPointsLoaded){ + VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord; + aPointsCoord.resize(iNumElemEnd*theMesh.myDim); + if(MYDEBUG) MESSAGE("LoadPoints - Filling coordinates of the mesh - inum_elem = "< 0){ + if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh"); + VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX]; + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + if(num_fam_elem[iNumElem] == aFamily.myId) + aSubMeshOnCellType.insert(iNumElem); + } + return 1; + }catch(std::runtime_error& exc){ + theMesh.myPointsCoord.clear(); + throw std::runtime_error(exc.what()); + }catch(...){ + theMesh.myPointsCoord.clear(); + throw std::runtime_error("Unknown exception !!!"); + } + return 0; +} + +int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity& theMeshOnEntity, + const string& theFamilyName) + throw (std::runtime_error&) +{ + try{ + //Check on existing family + VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName); + bool isFamilyPresent = (pFamily != NULL); + VISU::TFamily& aFamily = *pFamily; + //Check on loading already done + bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty(); + if(isCellsLoaded) + if(!isFamilyPresent) return 0; + else if(!aFamily.mySubMesh.empty()) return 0; + if(MYDEBUG) { + MESSAGE("LoadCellsOnEntity - theFamilyName = '"< 0) { + med_booleen iname_elem, inum_elem; + valarray num_elem(iNumElemEnd), num_fam_elem(iNumElemEnd); + valarray name_elem('\0',iNumElemEnd*MED_TAILLE_PNOM+1); + med_int aNbConnForElem = getNbMedConnect(aMedType,anEntity,aMesh.myDim); + if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<> MEDelementsLire(...)"); + if(!isCellsLoaded){ + VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType]; + aConnForCellType.resize(iNumElemEnd); + valarray aConnect(nbMedNodes); + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) { + VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem]; + anArray.resize(nbVtkNodes); + for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) { + aConnect[k] = conn[kj+k] - 1; + } + switch(aMedType){ + case MED_TETRA4 : + case MED_TETRA10 : + anArray[0] = aConnect[0]; + anArray[1] = aConnect[1]; + anArray[2] = aConnect[3]; + anArray[3] = aConnect[2]; + break; + case MED_PYRA5 : + case MED_PYRA13 : + anArray[0] = aConnect[0]; + anArray[1] = aConnect[3]; + anArray[2] = aConnect[2]; + anArray[3] = aConnect[1]; + anArray[4] = aConnect[4]; + break; + default: + for (int k = 0; k < nbVtkNodes; k++) + anArray[k] = aConnect[k]; + } + for (int k = 0; k < nbVtkNodes; k++) + if(anArray[k] < 0 || aNbPoints <= anArray[k]){ + static QString aString; + aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d](%d) < 0",aNbPoints,iNumElem,k,anArray[k]); + throw std::runtime_error(aString.latin1()); + } + } + } + //Filling aFamily SubMesh + if(isFamilyPresent){ + VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType]; + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + if(num_fam_elem[iNumElem] == aFamily.myId) + aSubMeshOnCellType.insert(iNumElem); + } + } + } + return 1; + }catch(std::runtime_error& exc){ + theMeshOnEntity.myCellsConn.clear(); + throw std::runtime_error(exc.what()); + }catch(...){ + theMeshOnEntity.myCellsConn.clear(); + throw std::runtime_error("Unknown exception !!!"); + } + return 0; +} + +int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity, + const VISU::TField& theField, VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) +{ + //Check on loading already done + if(!theValForTime.myValForCells.empty()) return 0; + //Main part of code + med_int ncomp = MEDnChamp(fid,theField.myId); + if(ncomp < 0) throw std::runtime_error("LoadField >> MEDnChamp(fid,i)"); + valarray comp('\0',ncomp*MED_TAILLE_PNOM + 1); + valarray unit('\0',ncomp*MED_TAILLE_PNOM + 1); + char aFieldName[MED_TAILLE_NOM + 1] = ""; + med_type_champ type_field; + if(MEDchampInfo(fid,theField.myId,aFieldName,&type_field,&comp[0],&unit[0],ncomp) < 0) + throw std::runtime_error(string("LoadField >> MEDchampInfo(...)")); + int iGeomElemEnd; + med_geometrie_element* aGeomElemVector; + const VISU::TEntity& anEntity = theField.myEntity; + GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd); + med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity]; + if(MYDEBUG) { + MESSAGE("LoadField - aFieldName = '"<> MEDpasdetempsInfo(...)"); + med_int nval = MEDnVal(fid,aFieldName,aMedEntity,aGeom,numdt,numo); + if (nval <= 0) throw std::runtime_error("LoadField >> MEDnVal(...) - nval <= 0"); + else{ + //Checking for accordance between the mesh and the field on number of geomterical elements + int aVtkType = med2vtkCellType(aGeom); + const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn; + VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType); + if(aCellsConnIter == aCellsConn.end()) throw std::runtime_error("LoadField - There is no the geom. elem. on the mesh !!!"); + const VISU::TMeshOnEntity::TConnForCellType aConnForCellType = aCellsConnIter->second; + if(aConnForCellType.size() != nval) throw std::runtime_error("LoadField - Size of values and size of mesh not equal !!!"); + if(MYDEBUG) MESSAGE("LoadField - aGeom = "< valr(jEnd); + ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL, + pflname,aMedEntity,aGeom,numdt,numo); + for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j]; + break; + } + //case MED_INT64 : //valarray valr(jEnd); + case MED_INT32 : //valarray valr(jEnd); + case MED_INT : { + valarray valr(jEnd); + ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL, + pflname,aMedEntity,aGeom,numdt,numo); + for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j]; + break; + } + default : + throw std::runtime_error("LoadField >> Value of med_type_champ for the field is wrong !!!"); + } + if(ret < 0) throw std::runtime_error("ChampLire >> MEDchampLire(...)"); + } + } + } + return 1; +} diff --git a/src/CONVERTOR/VISU_MedConvertor.hxx b/src/CONVERTOR/VISU_MedConvertor.hxx new file mode 100644 index 00000000..742b0852 --- /dev/null +++ b/src/CONVERTOR/VISU_MedConvertor.hxx @@ -0,0 +1,50 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VISU_MedConvertor.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_MedConvertor_HeaderFile +#define VISU_MedConvertor_HeaderFile + +#include "VISU_Convertor_impl.hxx" + +extern "C"{ +#include +} + +class VISU_MedConvertor: public VISU_Convertor_impl{ + VISU_MedConvertor(); + VISU_MedConvertor(const VISU_MedConvertor&); +public: + VISU_MedConvertor(const std::string& theFileName) throw (std::runtime_error&); + virtual VISU_Convertor* Build() throw (std::runtime_error&); +protected: + QFileInfo myFileInfo; + + virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName = "") + throw (std::runtime_error&); + virtual int LoadMeshOnGroup(VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + throw (std::runtime_error&); + virtual int LoadFieldOnMesh(VISU::TMesh& theMesh, + VISU::TMeshOnEntity& theMeshOnEntity, + VISU::TField& theField, + VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&); + + int LoadPoints(const med_idt& fid, VISU::TMesh& theMesh, + const std::string& theFamilyName = "") + throw (std::runtime_error&); + int LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity& theMeshOnEntity, + const std::string& theFamilyName = "") + throw (std::runtime_error&); + int LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity, + const VISU::TField& theField, VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&); +}; + +#endif diff --git a/src/OBJECT/VISU_MeshAct.cxx b/src/OBJECT/VISU_MeshAct.cxx new file mode 100644 index 00000000..eb9203b9 --- /dev/null +++ b/src/OBJECT/VISU_MeshAct.cxx @@ -0,0 +1,199 @@ +// 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 +// +// +// +// File : VISU_MeshAct.cxx +// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VISU_MeshAct.h" +#include "SALOME_PassThroughFilter.h" + +#include +#include +#include + +vtkStandardNewMacro(VISU_MeshAct); + +VISU_MeshAct::VISU_MeshAct(){ + mySurfaceActor = VISU_Actor::New(); + mySurfaceActor->SetParent(this); + mySurfaceActor->GetProperty()->FrontfaceCullingOff(); + mySurfaceActor->GetProperty()->BackfaceCullingOff(); + mySurfaceActor->SetRepresentation(2); //SURFACE + + myEdgeActor = VISU_Actor::New(); + myEdgeActor->SetParent(this); + myEdgeActor->PickableOff(); + myEdgeActor->GetProperty()->FrontfaceCullingOff(); + myEdgeActor->GetProperty()->BackfaceCullingOff(); + myEdgeActor->SetRepresentation(1); //WIREFRAME + + myNodeActor = VISU_Actor::New(); + myNodeActor->SetParent(this); + myNodeActor->PickableOff(); + myNodeActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE); + myNodeActor->GetProperty()->FrontfaceCullingOff(); + myNodeActor->GetProperty()->BackfaceCullingOff(); + myNodeActor->SetRepresentation(0); //POINT + + SetRepresentation(2); //SURFACE +} + +VISU_MeshAct::~VISU_MeshAct(){ + mySurfaceActor->Delete(); + myEdgeActor->Delete(); + myNodeActor->Delete(); +} + +void VISU_MeshAct::setIO(const Handle(SALOME_InteractiveObject)& theIO){ + mySurfaceActor->setIO(theIO); + myEdgeActor->setIO(theIO); + myNodeActor->setIO(theIO); +} + +void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){ + if(thePrs3d){ + VISU_Actor::SetPrs3d(thePrs3d); + mySurfaceActor->SetPrs3d(thePrs3d); + myEdgeActor->SetPrs3d(thePrs3d); + myNodeActor->SetPrs3d(thePrs3d); + } +} + +void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){ + theRenderer->AddActor(mySurfaceActor); + theRenderer->AddActor(myEdgeActor); + theRenderer->AddActor(myNodeActor); +} + +void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){ + theRenderer->RemoveActor(mySurfaceActor); + theRenderer->RemoveActor(myEdgeActor); + theRenderer->RemoveActor(myNodeActor); +} + +void VISU_MeshAct::SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&){ + VISU_Actor::SetPipeLine(thePipeLine); + mySurfaceActor->SetPipeLine(thePipeLine); + myEdgeActor->SetPipeLine(thePipeLine); + myNodeActor->SetPipeLine(thePipeLine); +} + +void VISU_MeshAct::SetTransform(SALOME_Transform* theTransform){ + mySurfaceActor->SetTransform(theTransform); + myEdgeActor->SetTransform(theTransform); + myNodeActor->SetTransform(theTransform); +} + +void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){ + VISU_Actor::SetShrinkable(theIsShrinkable); + mySurfaceActor->SetShrinkable(theIsShrinkable); + myEdgeActor->SetShrinkable(theIsShrinkable); + myNodeActor->SetShrinkable(theIsShrinkable); +} + +vtkProperty* VISU_MeshAct::GetProperty(){ + mySurfaceActor->GetProperty(); +} + +void VISU_MeshAct::SetProperty(vtkProperty* theProperty){ + mySurfaceActor->SetProperty(theProperty); +} + +vtkProperty* VISU_MeshAct::GetEdgeProperty(){ + myEdgeActor->GetProperty(); +} + +void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){ + myEdgeActor->SetProperty(theProperty); +} + +vtkProperty* VISU_MeshAct::GetNodeProperty(){ + myNodeActor->GetProperty(); +} + +void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){ + myNodeActor->SetProperty(theProperty); +} + +void VISU_MeshAct::SetLineWidth(float theLineWidth){ + GetEdgeProperty()->SetLineWidth(theLineWidth); +} + +float VISU_MeshAct::GetLineWidth(){ + return GetEdgeProperty()->GetLineWidth(); +} + +void VISU_MeshAct::SetShrink(float theFactor){ + VISU_Actor::SetShrink(theFactor); + mySurfaceActor->SetShrink(theFactor); + myEdgeActor->SetShrink(theFactor); + SetRepresentation(GetRepresentation()); +} + +void VISU_MeshAct::UnShrink(){ + VISU_Actor::UnShrink(); + mySurfaceActor->UnShrink(); + myEdgeActor->UnShrink(); + SetRepresentation(GetRepresentation()); +} + +void VISU_MeshAct::SetRepresentation(int theMode){ + SALOME_Actor::SetRepresentation(theMode); + mySurfaceActor->VisibilityOff(); + myEdgeActor->VisibilityOff(); + myNodeActor->VisibilityOff(); + switch(theMode){ + case 0: //POINTS + myNodeActor->VisibilityOn(); + break; + case 1: //WIREFRAME + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(1); + break; + case 2: //SURFACE + mySurfaceActor->VisibilityOn(); + break; + case 3: //INSIDEFRAME + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(3); + break; + case 4: //SURFACEFRAME + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(1); + mySurfaceActor->VisibilityOn(); + break; + } +} + +void VISU_MeshAct::SetVisibility(int theMode){ + VISU_Actor::SetVisibility(theMode); + if(GetVisibility()) + SetRepresentation(GetRepresentation()); + else{ + myNodeActor->VisibilityOff(); + myEdgeActor->VisibilityOff(); + mySurfaceActor->VisibilityOff(); + } +} diff --git a/src/OBJECT/VISU_MeshAct.h b/src/OBJECT/VISU_MeshAct.h new file mode 100644 index 00000000..ae5e6f51 --- /dev/null +++ b/src/OBJECT/VISU_MeshAct.h @@ -0,0 +1,76 @@ +// 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 +// +// +// +// File : VISU_MeshAct.h +// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISU_MeshAct_HeaderFile +#define VISU_MeshAct_HeaderFile + +#include "VISU_Actor.h" +class vtkDataSetMapper; + +class VTKOCC_EXPORT VISU_MeshAct : public VISU_Actor { + public: + vtkTypeMacro(VISU_MeshAct,VISU_Actor); + static VISU_MeshAct* New(); + ~VISU_MeshAct(); + + virtual void setIO(const Handle(SALOME_InteractiveObject)& theIO); + virtual void SetPrs3d(VISU::Prs3d_i* thePrs3d); + + virtual void AddToRender(vtkRenderer* theRenderer); + virtual void RemoveFromRender(vtkRenderer* theRenderer); + + virtual void SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&); + virtual void SetTransform(SALOME_Transform* theTransform); + + virtual vtkProperty* GetProperty(); + virtual void SetProperty(vtkProperty* theProperty); + + virtual vtkProperty* GetEdgeProperty(); + virtual void SetEdgeProperty(vtkProperty* theProperty); + + virtual vtkProperty* GetNodeProperty(); + virtual void SetNodeProperty(vtkProperty* theProperty); + + virtual void SetLineWidth(float theLineWidth); + virtual float GetLineWidth(); + + virtual void SetRepresentation(int theMode); + + virtual void SetVisibility(int theMode); + + virtual void SetShrinkable(bool theIsShrinkable); + + virtual void SetShrink(float theFactor = 0.8); + virtual void UnShrink(); + + protected: + VISU_MeshAct(); + VISU_Actor *mySurfaceActor, *myEdgeActor, *myNodeActor; +}; + +#endif diff --git a/src/OBJECT/VISU_ScalarMapAct.cxx b/src/OBJECT/VISU_ScalarMapAct.cxx new file mode 100644 index 00000000..30a7c4a7 --- /dev/null +++ b/src/OBJECT/VISU_ScalarMapAct.cxx @@ -0,0 +1,69 @@ +// 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 +// +// +// +// File : VISU_MeshAct.hxx +// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VISU_ScalarMapAct.h" +#include "VISU_LookupTable.hxx" +#include "VISU_ScalarBarActor.hxx" + +vtkStandardNewMacro(VISU_ScalarMapAct); + +VISU_ScalarMapAct::VISU_ScalarMapAct(){ + myScalarBar = VISU_ScalarBarActor::New(); + GetProperty()->FrontfaceCullingOff(); + GetProperty()->BackfaceCullingOff(); +} + +VISU_ScalarMapAct::~VISU_ScalarMapAct(){ + myScalarBar->Delete(); +} + +void VISU_ScalarMapAct::AddToRender(vtkRenderer* theRenderer){ + SALOME_Actor::AddToRender(theRenderer); + if(myScalarBar) + theRenderer->AddActor2D(myScalarBar); +} + +void VISU_ScalarMapAct::RemoveFromRender(vtkRenderer* theRenderer){ + SALOME_Actor::RemoveFromRender(theRenderer); + if(myScalarBar) + theRenderer->RemoveActor(myScalarBar); +} + +void VISU_ScalarMapAct::SetVisibility(int theMode){ + SALOME_Actor::SetVisibility(theMode); + if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility && theMode); +} + +int VISU_ScalarMapAct::GetVisibility(){ + return SALOME_Actor::GetVisibility(); +} + +void VISU_ScalarMapAct::SetBarVisibility(bool theMode){ + myBarVisibility = theMode; + if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility); +} diff --git a/src/OBJECT/VISU_ScalarMapAct.h b/src/OBJECT/VISU_ScalarMapAct.h new file mode 100644 index 00000000..bae6e529 --- /dev/null +++ b/src/OBJECT/VISU_ScalarMapAct.h @@ -0,0 +1,59 @@ +// 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 +// +// +// +// File : VISU_ScalarMapAct.h +// Author : Laurent CORNABE with help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISU_ScalarMapAct_HeaderFile +#define VISU_ScalarMapAct_HeaderFile + +#include "VISU_Actor.h" + +class VISU_ScalarBarActor; + +class VTKOCC_EXPORT VISU_ScalarMapAct : public VISU_Actor { + public: + vtkTypeMacro(VISU_ScalarMapAct,VISU_Actor); + static VISU_ScalarMapAct* New(); + ~VISU_ScalarMapAct(); + + virtual void AddToRender(vtkRenderer* theRenderer); + virtual void RemoveFromRender(vtkRenderer* theRenderer); + + virtual void SetVisibility(int theMode); + virtual int GetVisibility(); + + virtual VISU_ScalarBarActor* GetScalarBar(){ return myScalarBar;} + + virtual void SetBarVisibility(bool theMode); + virtual bool GetBarVisibility(){ return myBarVisibility;} + + protected: + VISU_ScalarMapAct(); + bool myBarVisibility; + VISU_ScalarBarActor* myScalarBar; +}; + +#endif diff --git a/src/OBJECT/VISU_VectorsAct.cxx b/src/OBJECT/VISU_VectorsAct.cxx new file mode 100644 index 00000000..2e823ab1 --- /dev/null +++ b/src/OBJECT/VISU_VectorsAct.cxx @@ -0,0 +1,79 @@ +// 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 +// +// +// +// File : VISU_VectorsAct.cxx +// Author : Laurent CORNABE with help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VISU_VectorsAct.h" +#include "VISU_VectorsPL.hxx" +#include "SALOME_PassThroughFilter.h" + +// VTK Includes +#include + +using namespace std; + +//======================================================================= + +vtkStandardNewMacro(VISU_VectorsAct); + + +VISU_VectorsAct::VISU_VectorsAct(){} + + +VISU_VectorsAct::~VISU_VectorsAct(){} + + +void VISU_VectorsAct::SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&){ + if(myPipeLine = dynamic_cast(thePipeLine)){ + VISU_Actor::SetPipeLine(myPipeLine); + myPipeLine->Delete(); + } +} + + +void VISU_VectorsAct::SetTransform(SALOME_Transform* theTransform){ + myPipeLine->SetTransform(theTransform); + Modified(); +} + + +void VISU_VectorsAct::SetMapper(vtkMapper* theMapper){ + if(theMapper){ + myPassFilter[0]->SetInput(theMapper->GetInput()); + myPassFilter[0]->Update(); + myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput()); + myPassFilter[1]->Update(); + myPassFilter[2]->SetInput(myPassFilter[1]->GetPolyDataOutput()); + myPassFilter[2]->Update(); + myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput()); + myPassFilter[3]->Update(); + if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)) + aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput()); + else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)) + aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput()); + } + vtkLODActor::SetMapper(theMapper); +} diff --git a/src/OBJECT/VISU_VectorsAct.h b/src/OBJECT/VISU_VectorsAct.h new file mode 100644 index 00000000..45e3c14f --- /dev/null +++ b/src/OBJECT/VISU_VectorsAct.h @@ -0,0 +1,55 @@ +// 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 +// +// +// +// File : VISU_VectorsAct.h +// Author : Laurent CORNABE with help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISU_VectorsAct_HeaderFile +#define VISU_VectorsAct_HeaderFile + +#include "VISU_ScalarMapAct.h" + +class SALOME_Transform; +class VISU_VectorsPL; + +class VTKOCC_EXPORT VISU_VectorsAct : public VISU_ScalarMapAct { + public: + vtkTypeMacro(VISU_VectorsAct,VISU_ScalarMapAct); + static VISU_VectorsAct* New(); + ~VISU_VectorsAct(); + + virtual void SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&); + + virtual void SetTransform(SALOME_Transform* theTransform); + + virtual void SetMapper(vtkMapper* theMapper); + + protected: + VISU_VectorsAct(); + + VISU_VectorsPL* myPipeLine; +}; + +#endif diff --git a/src/PIPELINE/Makefile.in b/src/PIPELINE/Makefile.in new file mode 100644 index 00000000..ae6728c9 --- /dev/null +++ b/src/PIPELINE/Makefile.in @@ -0,0 +1,64 @@ +# 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 +# +# +# +# File : Makefile.in +# Module : VISU + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +EXPORT_HEADERS = VISU_PipeLine.hxx VISU_PipeLineUtils.hxx \ + VISU_MeshPL.hxx VISU_ScalarMapPL.hxx \ + VISU_CutPlanesPL.hxx VISU_CutLinesPL.hxx \ + VISU_IsoSurfacesPL.hxx VISU_DeformedShapePL.hxx \ + VISU_VectorsPL.hxx VISU_StreamLinesPL.hxx \ + VISU_LookupTable.hxx VISU_ScalarBarActor.hxx \ + VISU_Extractor.hxx VISU_FieldTransform.hxx \ + VISU_UsedPointsFilter.hxx + +# Libraries targets + +LIB = libVisuPipeLine.la +LIB_SRC = VISU_PipeLine.cxx VISU_PipeLineUtils.cxx \ + VISU_MeshPL.cxx VISU_ScalarMapPL.cxx \ + VISU_CutPlanesPL.cxx VISU_CutLinesPL.cxx \ + VISU_IsoSurfacesPL.cxx VISU_DeformedShapePL.cxx \ + VISU_VectorsPL.cxx VISU_StreamLinesPL.cxx \ + VISU_LookupTable.cxx VISU_ScalarBarActor.cxx \ + VISU_Extractor.cxx VISU_FieldTransform.cxx \ + VISU_UsedPointsFilter.cxx + +# Executables targets + +BIN = VISUPipeLine +BIN_SRC = + +CPPFLAGS+= $(VTK_INCLUDES) +LDFLAGS+= $(VTK_LIBS) -lSalomeVTKFilter -lVisuConvertor + +@CONCLUDE@ diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx new file mode 100644 index 00000000..1b5181a6 --- /dev/null +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -0,0 +1,139 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#include "VISU_Convertor.hxx" +#include "VISU_MeshPL.hxx" +#include "VISU_ScalarMapPL.hxx" +#include "VISU_IsoSurfacesPL.hxx" +#include "VISU_CutPlanesPL.hxx" +#include "VISU_CutLinesPL.hxx" +#include "VISU_DeformedShapePL.hxx" +#include "VISU_VectorsPL.hxx" +#include "VISU_StreamLinesPL.hxx" + +typedef VISU_StreamLinesPL TPresent; + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +static int isOnlyMesh = false; + +int main(int argc, char** argv){ + try{ + if(argc > 1){ + vtkRenderWindow *renWin = vtkRenderWindow::New(); + vtkRenderer *ren = vtkRenderer::New(); + renWin->AddRenderer(ren); + ren->GetActiveCamera()->ParallelProjectionOn(); + vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); + iren->SetRenderWindow(renWin); + VISU_Convertor* aConvertor = CreateConvertor(argv[1]); + const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap(); + VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + if(aMeshMapIter == aMeshMap.end()) return 0; + const string& aMeshName = aMeshMapIter->first; + const VISU::TMesh& aMesh = aMeshMapIter->second; + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + if(isOnlyMesh){ + const VISU::TEntity& anEntity = VISU::CELL_ENTITY; + aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity); + vtkUnstructuredGrid* aDataSet = aConvertor->GetMeshOnEntity(aMeshName,anEntity); + + VISU_MeshPL* aPresent = VISU_MeshPL::New(); + aPresent->SetInput(aDataSet); + aPresent->Build(); + + vtkActor* aActor = vtkActor::New(); + aActor->SetMapper(aPresent->GetMapper()); + aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME); + //ren->ResetCameraClippingRange(); + + ren->AddActor(aActor); + + renWin->Render(); + iren->Start(); + return 0; + } + //Import fields + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap; + VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + const VISU::TField& aField = aFieldMapIter->second; + if(aField.myNbComp == 1) continue; + const string& aFieldName = aFieldMapIter->first; + const VISU::TField::TValField& aValField = aField.myValField; + VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin(); + if(aValFieldIter == aValField.end()) return 0; + int aTimeStamp = aValFieldIter->first; + vtkUnstructuredGrid* aDataSet = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + + TPresent* aPresent = TPresent::New(); + aPresent->SetInput(aDataSet); + aPresent->Build(); + aPresent->Init(); + //aPresent->SetPartDefault(0); + //aPresent->SetScalarMin(0.01); + //aPresent->SetScaling(VTK_SCALE_LOG10); + aPresent->Update(); + + vtkActor* anActor = vtkActor::New(); + anActor->SetMapper(aPresent->GetMapper()); + + VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); + aScalarBar->SetLookupTable(aPresent->GetBarTable()); + + aPresent->Build(); + + ren->AddActor(anActor); + ren->AddActor2D(aScalarBar); + ren->ResetCameraClippingRange(); + + renWin->Render(); + iren->Start(); + return 0; + } + } + } + }catch(std::runtime_error& exc){ + cout<<"Follow exception was accured :\n"< + +using namespace std; + +vtkStandardNewMacro(VISU_CutLinesPL); + +VISU_CutLinesPL::VISU_CutLinesPL(){} + +void VISU_CutLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_CutPlanesPL::ShallowCopy(thePipeLine); + if(VISU_CutLinesPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetPlaneOrientation(aPipeLine->GetPlaneOrientation(1),1); + SetDisplacement(aPipeLine->GetDisplacement(1),1); + SetDefault(); + if (!aPipeLine->IsDefault()) SetPosition(aPipeLine->GetPosition()); + SetRotateX(aPipeLine->GetRotateX(1),1); + SetRotateY(aPipeLine->GetRotateY(1),1); + } +} + +void VISU_CutLinesPL::Init(){ + VISU_CutPlanesPL::Init(); + + myBasePlane[0] = XY; + myBasePlane[1] = YZ; + myDisplacement[0] = myDisplacement[1] = 0.5; + myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0; + myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0; + + myCondition = 1; + myPosition = 0; +} + + +void VISU_CutLinesPL::SetPosition(float thePosition){ + myPosition = thePosition; + myCondition = 0; + Modified(); +} +float VISU_CutLinesPL::GetPosition(){ + float aPosition = myPosition; + if(myCondition){ + float aDir[3], aBounds[6], aBoundPrj[3]; + myInput->GetBounds(aBounds); + GetDir(aDir,myAng[0],myBasePlane[0]); + GetBoundProject(aBoundPrj,aBounds,aDir); + aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[0]; + } + return aPosition; +} + +void VISU_CutLinesPL::SetDefault(){ + myCondition = 1; + Modified(); +} +int VISU_CutLinesPL::IsDefault(){ + return myCondition; +} + + +void VISU_CutLinesPL::Update(){ + ClearAppendPolyData(myAppendPolyData); + SetPartPosition(1); + vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New(); + //Build base plane + float aDir[2][3], aBaseBounds[6]; + myInput->GetBounds(aBaseBounds); + GetDir(aDir[0],myAng[0],myBasePlane[0]); + vtkUnstructuredGrid* anUnstructuredGrid = + myFieldTransform->GetUnstructuredGridOutput(); + CutWithPlanes(anAppendPolyData,anUnstructuredGrid,1,aDir[0],aBaseBounds, + myPosition,myCondition,myDisplacement[0]); + //Build lines + float aBounds[6]; + vtkDataSet *aDataSet = anAppendPolyData->GetOutput(); + aDataSet->Update(); + if(aDataSet->GetNumberOfCells() == 0) + aDataSet = anUnstructuredGrid; + aDataSet->GetBounds(aBounds); + GetDir(aDir[1],myAng[1],myBasePlane[1]); + VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,aDataSet,GetNbParts(),aDir[1],aBounds, + myPartPosition,myPartCondition,myDisplacement[1]); + anAppendPolyData->Register(myAppendPolyData); + anAppendPolyData->Delete(); + //Calculate values for building of table + vtkMath::Cross(aDir[0],aDir[1],myDirLn); + GetBoundProject(myBoundPrjLn, aBaseBounds, myDirLn); + VISU::Mul(myDirLn,myBoundPrjLn[0],myBasePnt); + CorrectPnt(myBasePnt,aBaseBounds); + + VISU_ScalarMapPL::Update(); +} + + +void VISU_CutLinesPL::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, + int theNbPlanes, float theDir[3], float theBounds[6], + float thePartPosition, int thePartCondition, + float theDisplacement) +{ + vector aPartPosition(1,thePartPosition); + vector aPartCondition(1,thePartCondition); + VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,theDataSet,theNbPlanes,theDir,theBounds, + aPartPosition,aPartCondition,theDisplacement); +} diff --git a/src/PIPELINE/VISU_CutLinesPL.hxx b/src/PIPELINE/VISU_CutLinesPL.hxx new file mode 100644 index 00000000..cc316781 --- /dev/null +++ b/src/PIPELINE/VISU_CutLinesPL.hxx @@ -0,0 +1,69 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_CutLinesPL_HeaderFile +#define VISU_CutLinesPL_HeaderFile + +#include "VISU_CutPlanesPL.hxx" + +class vtkAppendPolyData; + +class VISU_CutLinesPL : public VISU_CutPlanesPL{ +protected: + VISU_CutLinesPL(); + VISU_CutLinesPL(const VISU_CutLinesPL&); +public: + vtkTypeMacro(VISU_CutLinesPL,VISU_CutPlanesPL); + static VISU_CutLinesPL* New(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual void SetPosition(float thePosition); + virtual float GetPosition(); + + virtual void SetDefault(); + virtual int IsDefault(); + +public: + virtual void Init(); + virtual void Update(); + + static void CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, + int theNbPlanes, float theDir[3], float theBounds[6], + float thePlanePosition, int thePlaneCondition, + float theDisplacement); + + const float* GetDirLn(){ return myDirLn;} + const float* GetBoundPrjLn(){ return myBoundPrjLn;} + const float* GetBasePnt(){ return myBasePnt;} + +protected: + float myDirLn[3], myBoundPrjLn[3], myBasePnt[3]; + float myPosition; + int myCondition; +}; + + +#endif diff --git a/src/PIPELINE/VISU_CutPlanesPL.cxx b/src/PIPELINE/VISU_CutPlanesPL.cxx new file mode 100644 index 00000000..a6cb0665 --- /dev/null +++ b/src/PIPELINE/VISU_CutPlanesPL.cxx @@ -0,0 +1,311 @@ +// 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 +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_CutPlanesPL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "SALOME_GeometryFilter.h" + +#include +#include +#include + +using namespace std; + +static float EPS = 1.0E-3; + +vtkStandardNewMacro(VISU_CutPlanesPL); + +VISU_CutPlanesPL::VISU_CutPlanesPL(){ + myAppendPolyData = vtkAppendPolyData::New(); +} + +VISU_CutPlanesPL::~VISU_CutPlanesPL(){ + myAppendPolyData->Delete(); +} + +void VISU_CutPlanesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_ScalarMapPL::ShallowCopy(thePipeLine); + if(VISU_CutPlanesPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetPlaneOrientation(aPipeLine->GetPlaneOrientation()); + SetDisplacement(aPipeLine->GetDisplacement()); + SetNbParts(aPipeLine->GetNbParts()); + for (int i = 0, iend = GetNbParts(); i < iend; i++) + if(!aPipeLine->IsPartDefault(i)) SetPartPosition(i, aPipeLine->GetPartPosition(i)); + SetRotateX(aPipeLine->GetRotateX()); + SetRotateY(aPipeLine->GetRotateY()); + } +} + +void VISU_CutPlanesPL::Init(){ + VISU_ScalarMapPL::Init(); + + SetNbParts(10); + myBasePlane[0] = YZ; + myDisplacement[0] = 0.5; + myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0; +} + +VISU_ScalarMapPL::THook* VISU_CutPlanesPL::DoHook(){ + return myAppendPolyData->GetOutput(); +} + +void VISU_CutPlanesPL::Update(){ + ClearAppendPolyData(myAppendPolyData); + SetPartPosition(); + float aDir[3]; + GetDir(aDir,myAng[0],myBasePlane[0]); + float aBounds[6]; + myInput->GetBounds(aBounds); + vtkDataSet* aDataSet = myFieldTransform->GetUnstructuredGridOutput(); + CutWithPlanes(myAppendPolyData,aDataSet,myNbParts,aDir,aBounds, + myPartPosition,myPartCondition,myDisplacement[0]); + + VISU_ScalarMapPL::Update(); +} + +void VISU_CutPlanesPL::SetPartPosition(int theNum){ + for(int i = 0; i < myNbParts; i++) + myPartPosition[i] = GetPartPosition(i,theNum); +} + +void VISU_CutPlanesPL::ClearAppendPolyData(vtkAppendPolyData *theAppendPolyData){ + int iEnd = theAppendPolyData->GetNumberOfInputs(); + for(int i = iEnd-1; i >= 0; i--) + theAppendPolyData->RemoveInput(theAppendPolyData->GetInput(i)); +} + +float* VISU_CutPlanesPL::GetRx(float theRx[3][3], float thaAng){ + theRx[0][0] = 1.0; theRx[0][1] = 0.0; theRx[0][2] = 0.0; + theRx[1][0] = 0.0; theRx[1][1] = cos(thaAng); theRx[1][2] = -sin(thaAng); + theRx[2][0] = 0.0; theRx[2][1] = sin(thaAng); theRx[2][2] = cos(thaAng); + return theRx[0]; +} + + +float* VISU_CutPlanesPL::GetRy(float theRy[3][3], float thaAng){ + theRy[0][0] = cos(thaAng); theRy[0][1] = 0.0; theRy[0][2] = sin(thaAng); + theRy[1][0] = 0.0; theRy[1][1] = 1.0; theRy[1][2] = 0.0; + theRy[2][0] = -sin(thaAng); theRy[2][1] = 0.0; theRy[2][2] = cos(thaAng); + return theRy[0]; +} + + +float* VISU_CutPlanesPL::GetRz(float theRz[3][3], float thaAng){ + theRz[0][0] = cos(thaAng); theRz[0][1] = -sin(thaAng); theRz[0][2] = 0.0; + theRz[1][0] = sin(thaAng); theRz[1][1] = cos(thaAng); theRz[1][2] = 0.0; + theRz[2][0] = 0.0; theRz[2][1] = 0.0; theRz[2][2] = 1.0; + return theRz[0]; +} + + +void VISU_CutPlanesPL::CorrectPnt(float thePnt[3], const float BoundPrj[6]){ + for(int i = 0, j = 0; i < 3; ++i, j=2*i){ + if(thePnt[i] < BoundPrj[j]) thePnt[i] = BoundPrj[j]; + if(thePnt[i] > BoundPrj[j+1]) thePnt[i] = BoundPrj[j+1]; + } +} + +void VISU_CutPlanesPL::GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]){ + float BoundPoints[8][3] = { {BoundBox[0],BoundBox[2],BoundBox[4]}, + {BoundBox[1],BoundBox[2],BoundBox[4]}, + {BoundBox[0],BoundBox[3],BoundBox[4]}, + {BoundBox[1],BoundBox[3],BoundBox[4]}, + {BoundBox[0],BoundBox[2],BoundBox[5]}, + {BoundBox[1],BoundBox[2],BoundBox[5]}, + {BoundBox[0],BoundBox[3],BoundBox[5]}, + {BoundBox[1],BoundBox[3],BoundBox[5]}}; + BoundPrj[0] = vtkMath::Dot(Dir,BoundPoints[0]), BoundPrj[1] = BoundPrj[0]; + for(int i = 1; i < 8; i++){ + float tmp = vtkMath::Dot(Dir,BoundPoints[i]); + if(BoundPrj[1] < tmp) BoundPrj[1] = tmp; + if(BoundPrj[0] > tmp) BoundPrj[0] = tmp; + } + BoundPrj[2] = BoundPrj[1] - BoundPrj[0]; + BoundPrj[1] = BoundPrj[0] + (1.0 - EPS)*BoundPrj[2]; + BoundPrj[0] = BoundPrj[0] + EPS*BoundPrj[2]; + BoundPrj[2] = BoundPrj[1] - BoundPrj[0]; +} + +void VISU_CutPlanesPL::SetRotateX(float theAng, int theNum){ + switch(myBasePlane[theNum]){ + case XY: myAng[theNum][0] = theAng; break; + case YZ: myAng[theNum][1] = theAng; break; + case ZX: myAng[theNum][2] = theAng; break; + } +} + +float VISU_CutPlanesPL::GetRotateX(int theNum){ + switch(myBasePlane[theNum]){ + case XY: return myAng[theNum][0]; + case YZ: return myAng[theNum][1]; + case ZX: return myAng[theNum][2]; + } +} + +void VISU_CutPlanesPL::SetRotateY(float theAng, int theNum){ + switch(myBasePlane[theNum]){ + case XY: myAng[theNum][1] = theAng; break; + case YZ: myAng[theNum][2] = theAng; break; + case ZX: myAng[theNum][0] = theAng; break; + } +} + +float VISU_CutPlanesPL::GetRotateY(int theNum){ + switch(myBasePlane[theNum]){ + case XY: return myAng[theNum][1]; + case YZ: return myAng[theNum][2]; + case ZX: return myAng[theNum][0]; + } +} + + +void VISU_CutPlanesPL::SetNbParts(int theNb) { + myNbParts = theNb; + myPartPosition.resize(myNbParts); + myPartCondition.resize(myNbParts,1); + Modified(); +} + + +void VISU_CutPlanesPL::SetPartPosition(int thePartNumber, float thePartPosition){ + if(thePartNumber >= myNbParts) return; + myPartPosition[thePartNumber] = thePartPosition; + myPartCondition[thePartNumber] = 0; + Modified(); +} +float VISU_CutPlanesPL::GetPartPosition(int thePartNumber, int theNum){ + if(thePartNumber >= myNbParts) return 0; + float aPosition = myPartPosition[thePartNumber]; + if(myPartCondition[thePartNumber]){ + float aDir[3], aBounds[6], aBoundPrj[3]; + myInput->GetBounds(aBounds); + GetDir(aDir,myAng[theNum],myBasePlane[theNum]); + GetBoundProject(aBoundPrj,aBounds,aDir); + if (myNbParts > 1){ + float aDBoundPrj = aBoundPrj[2]/(myNbParts - 1); + float aDisplacement = aDBoundPrj * myDisplacement[theNum]; + float aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement; + aPosition = aStartPosition + thePartNumber*aDBoundPrj; + }else + aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[theNum]; + } + return aPosition; +} + + +void VISU_CutPlanesPL::SetPartDefault(int thePartNumber){ + if(thePartNumber >= myNbParts) return; + myPartPosition[thePartNumber] = GetPartPosition(thePartNumber); + myPartCondition[thePartNumber] = 1; + Modified(); +} +int VISU_CutPlanesPL::IsPartDefault(int thePartNumber){ + if(thePartNumber >= myNbParts) return 1; + return myPartCondition[thePartNumber]; +} + + +void VISU_CutPlanesPL::GetDir(float theDir[3], float theAng[3], const PlaneOrientation& theBasePlane){ + int iPlane = 0; + float aRx[3][3], aRy[3][3], aRz[3][3], aRotation[3][3]; + switch(theBasePlane){ + case XY: + if(fabs(theAng[0]) > EPS) GetRx(aRx,theAng[0]); else vtkMath::Identity3x3(aRx); + if(fabs(theAng[1]) > EPS) GetRy(aRy,theAng[1]); else vtkMath::Identity3x3(aRy); + vtkMath::Multiply3x3(aRx,aRy,aRotation); + iPlane = 2; + break; + case YZ: + if(fabs(theAng[1]) > EPS) GetRy(aRy,theAng[1]); else vtkMath::Identity3x3(aRy); + if(fabs(theAng[2]) > EPS) GetRz(aRz,theAng[2]); else vtkMath::Identity3x3(aRz); + vtkMath::Multiply3x3(aRy,aRz,aRotation); + iPlane = 0; + break; + case ZX: + if(fabs(theAng[2]) > EPS) GetRz(aRz,theAng[2]); else vtkMath::Identity3x3(aRz); + if(fabs(theAng[0]) > EPS) GetRx(aRx,theAng[0]); else vtkMath::Identity3x3(aRx); + vtkMath::Multiply3x3(aRz,aRx,aRotation); + iPlane = 1; + break; + } + for(int i = 0; i < 3; i++) + theDir[i] = aRotation[i][iPlane]; +} + + +void VISU_CutPlanesPL::CutWithPlane(vtkAppendPolyData* theAppendPolyData, + vtkDataSet* theDataSet, + float theDir[3], float theOrig[3]) +{ + vtkCutter *aCutPlane = vtkCutter::New(); + aCutPlane->SetInput(theDataSet); + vtkPlane *aPlane = vtkPlane::New(); + aPlane->SetOrigin(theOrig); + + aPlane->SetNormal(theDir); + aCutPlane->SetCutFunction(aPlane); + aPlane->Delete(); + theAppendPolyData->AddInput(aCutPlane->GetOutput()); + aCutPlane->Register(theAppendPolyData); + aCutPlane->Delete(); +} + + +void VISU_CutPlanesPL::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, + int theNbPlanes, float theDir[3], float theBounds[6], + const vector& thePlanePosition, + const vector& thePlaneCondition, + float theDisplacement) +{ + float aBoundPrj[3], aOrig[3], aPosition; + GetBoundProject(aBoundPrj, theBounds, theDir); + if(theNbPlanes > 1){ + float aDBoundPrj = aBoundPrj[2]/(theNbPlanes - 1); + float aDisplacement = aDBoundPrj*theDisplacement; + float aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement; + for (int i = 0; i < theNbPlanes; i++){ + aPosition = aStartPosition + i*aDBoundPrj; + float aDelta = (aBoundPrj[0] - aPosition) / aBoundPrj[2]; + if(thePlaneCondition[i]){ + aPosition = aStartPosition + i*aDBoundPrj; + }else + aPosition = thePlanePosition[i]; + VISU::Mul(theDir,aPosition,aOrig); + CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig); + } + }else{ + if(thePlaneCondition[0]) + aPosition = aBoundPrj[0] + aBoundPrj[2]*theDisplacement; + else + aPosition = thePlanePosition[0]; + VISU::Mul(theDir,aPosition,aOrig); + CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig); + } + vtkPolyData *aPolyData = theAppendPolyData->GetOutput(); + aPolyData->Update(); + theAppendPolyData->Update(); +} diff --git a/src/PIPELINE/VISU_CutPlanesPL.hxx b/src/PIPELINE/VISU_CutPlanesPL.hxx new file mode 100644 index 00000000..73b42cdf --- /dev/null +++ b/src/PIPELINE/VISU_CutPlanesPL.hxx @@ -0,0 +1,105 @@ +// 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 +// +// +// File: VISU_CutPlanesPL.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_CutPlanesPL_HeaderFile +#define VISU_CutPlanesPL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" + +#include + +class vtkAppendPolyData; + +class VISU_CutPlanesPL : public VISU_ScalarMapPL{ +protected: + VISU_CutPlanesPL(); + VISU_CutPlanesPL(const VISU_CutPlanesPL&); +public: + vtkTypeMacro(VISU_CutPlanesPL,VISU_ScalarMapPL); + static VISU_CutPlanesPL* New(); + virtual ~VISU_CutPlanesPL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + enum PlaneOrientation {XY, YZ, ZX}; + virtual const PlaneOrientation& GetPlaneOrientation(int theNum = 0) { return myBasePlane[theNum];} + virtual void SetPlaneOrientation(const PlaneOrientation& theOrient, int theNum = 0) { + myBasePlane[theNum] = theOrient; + } + + virtual float GetDisplacement(int theNum = 0) { return myDisplacement[theNum];} + virtual void SetDisplacement(float theDisp, int theNum = 0) { myDisplacement[theNum] = theDisp;} + + virtual void SetPartPosition(int thePartNumber, float thePartPosition); + virtual float GetPartPosition(int thePartNumber, int theNum = 0); + + virtual void SetPartDefault(int thePartNumber); + virtual int IsPartDefault(int thePartNumber); + + virtual void SetRotateX(float theAngle, int theNum = 0); + virtual float GetRotateX(int theNum = 0); + virtual void SetRotateY(float theAngle, int theNum = 0); + virtual float GetRotateY(int theNum = 0); + + virtual void SetNbParts(int theNb); + virtual int GetNbParts(){ return myNbParts;} + +public: + virtual void Init(); + virtual void Update(); + virtual vtkAppendPolyData* GetAppendPolyData() { return myAppendPolyData; } + +public: + static float* GetRx(float theRx[3][3], float thaAng); + static float* GetRy(float theRy[3][3], float thaAng); + static float* GetRz(float theRz[3][3], float thaAng); + + static void CorrectPnt(float thePnt[3], const float BoundPrj[6]); + static void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]); + + static void GetDir(float theDir[3], float theAng[3], const PlaneOrientation& theBasePlane); + + static void ClearAppendPolyData(vtkAppendPolyData *theAppendPolyData); + + static void CutWithPlane(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, + float theDir[3], float theOrig[3]); + static void CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, + int theNbPlanes, float theDir[3], float theBounds[6], + const std::vector& thePlanePosition, + const std::vector& thePlaneCondition, + float theDisplacement); +protected: + virtual THook* DoHook(); + void SetPartPosition(int theNum = 0); + + int myNbParts; + PlaneOrientation myBasePlane[2]; + float myAng[2][3], myDisplacement[2]; + vtkAppendPolyData *myAppendPolyData; + std::vector myPartPosition; + std::vector myPartCondition; +}; + +#endif diff --git a/src/PIPELINE/VISU_DeformedShapePL.cxx b/src/PIPELINE/VISU_DeformedShapePL.cxx new file mode 100644 index 00000000..e125c4f9 --- /dev/null +++ b/src/PIPELINE/VISU_DeformedShapePL.cxx @@ -0,0 +1,108 @@ +// 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 +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_DeformedShapePL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "SALOME_Transform.h" + +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +vtkStandardNewMacro(VISU_DeformedShapePL); + +VISU_DeformedShapePL::VISU_DeformedShapePL(){ + myWarpVector = vtkWarpVector::New(); +} + +VISU_DeformedShapePL::~VISU_DeformedShapePL(){ + myWarpVector->Delete(); +} + +void VISU_DeformedShapePL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_ScalarMapPL::ShallowCopy(thePipeLine); + if(VISU_DeformedShapePL *aPipeLine = dynamic_cast(thePipeLine)){ + SetScale(aPipeLine->GetScale()); + } +} + +float VISU_DeformedShapePL::GetScaleFactor(vtkDataSet* theDataSet){ + if(!theDataSet) return 0.0; + theDataSet->Update(); + int aNbCells = theDataSet->GetNumberOfCells(); + int aNbPoints = theDataSet->GetNumberOfPoints(); + int aNbElem = aNbCells? aNbCells: aNbPoints; + float* aBounds = theDataSet->GetBounds(); + float aVolume = 1, aVol, idim = 0; + for(int i = 0; i < 6; i += 2){ + aVol = fabs(aBounds[i+1] - aBounds[i]); + if(aVol > 0) { + idim++; + aVolume *= aVol; + } + } + aVolume /= aNbElem; + return pow(aVolume,float(1.0/idim)); +} + + +void VISU_DeformedShapePL::SetScale(float theScale) { + if(myScaleFactor == theScale) return; + myScaleFactor = theScale; + myWarpVector->SetScaleFactor(myScaleFactor); + Modified(); +} +float VISU_DeformedShapePL::GetScale() { + return myWarpVector->GetScaleFactor(); +} + +void VISU_DeformedShapePL::Init(){ + VISU_ScalarMapPL::Init(); + float aScalarRange[2]; + GetSourceRange(aScalarRange); + SetScale(GetScaleFactor(myInput)/aScalarRange[1]); +} + +VISU_ScalarMapPL::THook* VISU_DeformedShapePL::DoHook(){ + VISU::CellDataToPoint(myWarpVector,myInput,myFieldTransform); + return myWarpVector->GetOutput(); +} + +void VISU_DeformedShapePL::Update(){ + VISU_ScalarMapPL::Update(); +} + +void VISU_DeformedShapePL::SetMapScale(float theMapScale){ + VISU_ScalarMapPL::SetMapScale(theMapScale); + + myWarpVector->SetScaleFactor(myScaleFactor*theMapScale); + Modified(); +} diff --git a/src/PIPELINE/VISU_DeformedShapePL.hxx b/src/PIPELINE/VISU_DeformedShapePL.hxx new file mode 100644 index 00000000..f555faef --- /dev/null +++ b/src/PIPELINE/VISU_DeformedShapePL.hxx @@ -0,0 +1,63 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_DeformedShapePL_HeaderFile +#define VISU_DeformedShapePL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" + +class SALOME_Transform; +class vtkWarpVector; + +class VISU_DeformedShapePL : public VISU_ScalarMapPL{ +protected: + VISU_DeformedShapePL(); + VISU_DeformedShapePL(const VISU_DeformedShapePL&); +public: + vtkTypeMacro(VISU_DeformedShapePL,VISU_ScalarMapPL); + static VISU_DeformedShapePL* New(); + virtual ~VISU_DeformedShapePL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual void SetScale(float theScale); + virtual float GetScale(); + +public: + virtual void Init(); + virtual void Update(); + virtual void SetMapScale(float theMapScale = 1.0); + + static float GetScaleFactor(vtkDataSet* theDataSet); + +protected: + virtual THook* DoHook(); + + vtkWarpVector *myWarpVector; + float myScaleFactor; +}; + + +#endif diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx new file mode 100644 index 00000000..0b3f7859 --- /dev/null +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -0,0 +1,107 @@ +// 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 +// +// +// File : VISU_Extractor.cxx +// Module : VISU + +#include "VISU_Extractor.hxx" + +#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() {} + +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); + } + theOutputData->SetScalars(newScalars); + //theOutputData->SetActiveScalars(newScalars->GetName()); + newScalars->Delete(); +} + + +void VISU_Extractor::Execute(){ + vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); + output->CopyStructure(input); + output->GetPointData()->CopyAllOff(); + output->GetCellData()->CopyAllOff(); + if(input->GetPointData()->GetNumberOfArrays()){ + output->GetPointData()->CopyVectorsOn(); + int nbComp = input->GetNumberOfPoints(); + vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); + if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) + execute(nbComp,myScalarMode,inData,outData); + else + output->GetPointData()->CopyScalarsOn(); + outData->PassData(inData); + }else{ + output->GetCellData()->CopyVectorsOn(); + int nbComp = input->GetNumberOfCells(); + vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData(); + if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) + execute(nbComp,myScalarMode,inData,outData); + else + output->GetCellData()->CopyScalarsOn(); + outData->PassData(inData); + } +} diff --git a/src/PIPELINE/VISU_Extractor.hxx b/src/PIPELINE/VISU_Extractor.hxx new file mode 100644 index 00000000..6889b7a9 --- /dev/null +++ b/src/PIPELINE/VISU_Extractor.hxx @@ -0,0 +1,50 @@ +// 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 +// +// +// File : VISU_Extractor.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_Extractor_HeaderFile +#define VISU_Extractor_HeaderFile + +#include + +class VTK_EXPORT VISU_Extractor : public vtkPointSetToPointSetFilter{ +public: + vtkTypeMacro(VISU_Extractor,vtkPointSetToPointSetFilter); + static VISU_Extractor *New(); + ~VISU_Extractor(); + + virtual int GetScalarMode(){ return myScalarMode;} + virtual void SetScalarMode(int theScalarMode = 0); + +protected: + VISU_Extractor(); + VISU_Extractor(const VISU_Extractor&); + + virtual void Execute(); + + int myScalarMode; +}; + +#endif diff --git a/src/PIPELINE/VISU_FieldTransform.cxx b/src/PIPELINE/VISU_FieldTransform.cxx new file mode 100644 index 00000000..ea239eb2 --- /dev/null +++ b/src/PIPELINE/VISU_FieldTransform.cxx @@ -0,0 +1,159 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VISU_FieldTransform.cxx +// Module : VISU + +#include "VISU_FieldTransform.hxx" +#include "SALOME_Transform.h" + +#include +#include +#include +#include +#include +#include + +using namespace std; + +#ifdef DEBUG +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +vtkStandardNewMacro(VISU_FieldTransform); + +double VISU_FieldTransform::Ident(double theArg){ + return theArg; +} +double VISU_FieldTransform::Log10(double theArg){ + if(theArg <= 0.0) return -VTK_LARGE_FLOAT; + return log10(theArg); +} + + +VISU_FieldTransform::VISU_FieldTransform(){ + myFunction = &Ident; + myTransform = NULL; +} + +VISU_FieldTransform::~VISU_FieldTransform() {} + + +void VISU_FieldTransform::Update(){ + if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime()) + Modified(); + vtkSource::Update(); +} + +unsigned long VISU_FieldTransform::GetMTime(){ + if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime()) + return myTransform->GetMTime(); + return vtkSource::GetMTime(); +} + +void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) { + myFunction = theFunction; + if(myFunction == NULL) myFunction = &Ident; + Modified(); +} + +void VISU_FieldTransform::SetSpaceTransform(SALOME_Transform* theTransform){ + if(myTransform != theTransform){ + if (myTransform != NULL) myTransform->UnRegister(this); + myTransform = theTransform; + if (myTransform != NULL) myTransform->Register(this); + this->Modified(); + } +} + + +void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) { + myScalarRange[0] = theScalarRange[0]; + myScalarRange[1] = theScalarRange[1]; + Modified(); +} +void VISU_FieldTransform::SetScalarMin(float theValue){ + float aScalarRange[2] = {theValue, GetScalarRange()[1]}; + SetScalarRange(aScalarRange); +} +void VISU_FieldTransform::SetScalarMax(float theValue){ + float aScalarRange[2] = {GetScalarRange()[0], theValue}; + SetScalarRange(aScalarRange); +} + +template void +ExecVectors(VISU_FieldTransform::TTransformFun theFunction, + SALOME_Transform* theTransform, + float theScalarRange[2], int theNbComponent, + TypeData* theInputData, TypeData* theOutputData) +{ + vtkDataArray *inVectors = theInputData->GetVectors(); + if ( !inVectors || theNbComponent < 1 ) return; + vtkFloatArray *newVectors = vtkFloatArray::New(); + newVectors->SetNumberOfComponents(3); + newVectors->SetNumberOfTuples(theNbComponent); + float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; + float *V, v[3], vMag, aDelta = aScalarRange[1] - aScalarRange[0]; + float aScale[3] = {1.0, 1.0, 1.0}; + if(theTransform){ + aScale[0] = theTransform->GetScale()[0]; + aScale[1] = theTransform->GetScale()[1]; + aScale[2] = theTransform->GetScale()[2]; + } + for (int ptId = 0; ptId < theNbComponent; ptId++) { + V = inVectors->GetTuple3(ptId); + vMag = vtkMath::Norm(V); + vMag = ((*theFunction)(vMag) - aScalarRange[0]) / aDelta * theScalarRange[1] / vMag; + if(vMag <= 0.0) vMag = 0.0; + v[0] = V[0]*vMag*aScale[0]; + v[1] = V[1]*vMag*aScale[1]; + v[2] = V[2]*vMag*aScale[2]; + newVectors->SetTuple3(ptId, v[0], v[1], v[2]); + } + theOutputData->SetVectors(newVectors); + newVectors->Delete(); +} + +template void +ExecScalars(VISU_FieldTransform::TTransformFun theFunction, float theScalarRange[2], + int theNbComponent, TypeData* theInputData, TypeData* theOutputData) +{ + vtkDataArray *inScalars = theInputData->GetScalars(); + if ( !inScalars || theNbComponent < 1 ) + return; + vtkFloatArray *newScalars = vtkFloatArray::New(); + newScalars->SetNumberOfComponents(1); + newScalars->SetNumberOfTuples(theNbComponent); + float aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; + for (int ptId = 0; ptId < theNbComponent; ptId++) { + float s = (*theFunction)(inScalars->GetTuple1(ptId )); + if(s < aScalarRange[0]) s = aScalarRange[0]; + newScalars->SetTuple1(ptId, s); + } + theOutputData->SetScalars(newScalars); + newScalars->Delete(); +} + +void VISU_FieldTransform::Execute(){ + vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); + output->CopyStructure(input); + if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){ + output->GetPointData()->CopyAllOff(); + output->GetCellData()->CopyAllOff(); + + ExecScalars(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); + ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); + + ExecScalars(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); + ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); + }else{ + output->GetPointData()->CopyAllOn(); + output->GetCellData()->CopyAllOn(); + + output->GetPointData()->PassData(input->GetPointData()); + output->GetCellData()->PassData(input->GetCellData()); + } +} diff --git a/src/PIPELINE/VISU_FieldTransform.hxx b/src/PIPELINE/VISU_FieldTransform.hxx new file mode 100644 index 00000000..f1ce02de --- /dev/null +++ b/src/PIPELINE/VISU_FieldTransform.hxx @@ -0,0 +1,68 @@ +// 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 +// +// +// File : VISU_Extractor.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_FieldTransform_HeaderFile +#define VISU_FieldTransform_HeaderFile + +#include + +class SALOME_Transform; + +class VTK_EXPORT VISU_FieldTransform : public vtkDataSetToDataSetFilter{ +public: + vtkTypeMacro(VISU_FieldTransform,vtkDataSetToDataSetFilter); + static VISU_FieldTransform *New(); + + virtual void Update(); + virtual unsigned long GetMTime(); + + static double Ident(double theArg); + static double Log10(double theArg); + typedef double (*TTransformFun)(double); + void SetScalarTransform(TTransformFun theFunction); + TTransformFun GetScalarTransform() { return myFunction;} + + void SetSpaceTransform(SALOME_Transform* theTransform); + SALOME_Transform* GetSpaceTransform() { return myTransform;} + + float* GetScalarRange(){ return myScalarRange; } + void SetScalarRange(float theScalarRange[2]); + void SetScalarMin(float theValue); + void SetScalarMax(float theValue); + +protected: + VISU_FieldTransform(); + virtual ~VISU_FieldTransform(); + VISU_FieldTransform(const VISU_FieldTransform&) {}; + void operator=(const VISU_FieldTransform&) {}; + void Execute(); + + SALOME_Transform *myTransform; + TTransformFun myFunction; + float myScalarRange[2]; +}; + +#endif diff --git a/src/PIPELINE/VISU_IsoSurfacesPL.cxx b/src/PIPELINE/VISU_IsoSurfacesPL.cxx new file mode 100644 index 00000000..ecd27659 --- /dev/null +++ b/src/PIPELINE/VISU_IsoSurfacesPL.cxx @@ -0,0 +1,118 @@ +// 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 +// +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_IsoSurfacesPL.hxx" +#include "VISU_PipeLineUtils.hxx" + +#include + +VISU_IsoSurfacesPL* VISU_IsoSurfacesPL::New(){ + vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_IsoSurfacesPL"); + if(ret) return (VISU_IsoSurfacesPL*)ret; + return new VISU_IsoSurfacesPL; +} + +VISU_IsoSurfacesPL::VISU_IsoSurfacesPL(){ + myContourFilter = vtkContourFilter::New(); +} + +VISU_IsoSurfacesPL::~VISU_IsoSurfacesPL(){ + myContourFilter->Delete(); +} + +void VISU_IsoSurfacesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_ScalarMapPL::ShallowCopy(thePipeLine); + if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetNbParts(aPipeLine->GetNbParts()); + float aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()}; + SetRange(aRange); + } +} + +int VISU_IsoSurfacesPL::GetNbParts() { + return myContourFilter->GetNumberOfContours(); +} +void VISU_IsoSurfacesPL::SetNbParts(int theNb) { + myContourFilter->SetNumberOfContours(theNb); + Modified(); +} + + +void VISU_IsoSurfacesPL::SetScaling(int theScaling) { + VISU_ScalarMapPL::SetScaling(theScaling); + SetRange(myRange); +} +void VISU_IsoSurfacesPL::SetRange(float theRange[2]){ + if(theRange[0] <= theRange[1]){ + myRange[0] = theRange[0]; myRange[1] = theRange[1]; + float aRange[2] = {myRange[0], myRange[1]}; + if(GetScaling() == VTK_SCALE_LOG10) + VISU_LookupTable::ComputeLogRange(theRange,aRange); + myContourFilter->GenerateValues(GetNbParts(),aRange); + Modified(); + } +} +float VISU_IsoSurfacesPL::GetMin() { + return myRange[0]; +} +float VISU_IsoSurfacesPL::GetMax() { + return myRange[1]; +} + + +void VISU_IsoSurfacesPL::Init(){ + VISU_ScalarMapPL::Init(); + + SetNbParts(10); + float aScalarRange[2]; + GetSourceRange(aScalarRange); + SetRange(aScalarRange); +} + +VISU_ScalarMapPL::THook* VISU_IsoSurfacesPL::DoHook(){ + return myContourFilter->GetOutput(); +} + + +void VISU_IsoSurfacesPL::Update(){ + VISU::CellDataToPoint(myContourFilter,myInput,myFieldTransform); + SetMapScale(); + + VISU_ScalarMapPL::Update(); +} + +void VISU_IsoSurfacesPL::SetMapScale(float theMapScale){ + VISU_ScalarMapPL::SetMapScale(theMapScale); + + float aRange[2] = {GetMax() - theMapScale*(GetMax()-GetMin()), GetMax()}; + float aNewRange[2] = {aRange[0], aRange[1]}; + if(GetScaling() == VTK_SCALE_LOG10) + VISU_LookupTable::ComputeLogRange(aRange,aNewRange); + myContourFilter->GenerateValues(GetNbParts(),aNewRange); + Modified(); +} diff --git a/src/PIPELINE/VISU_IsoSurfacesPL.hxx b/src/PIPELINE/VISU_IsoSurfacesPL.hxx new file mode 100644 index 00000000..6eeb4564 --- /dev/null +++ b/src/PIPELINE/VISU_IsoSurfacesPL.hxx @@ -0,0 +1,65 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_IsoSurfacesPL_HeaderFile +#define VISU_IsoSurfacesPL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" + +class vtkContourFilter; + +class VISU_IsoSurfacesPL : public VISU_ScalarMapPL{ +protected: + VISU_IsoSurfacesPL(); + VISU_IsoSurfacesPL(const VISU_IsoSurfacesPL&); +public: + vtkTypeMacro(VISU_IsoSurfacesPL,VISU_ScalarMapPL); + static VISU_IsoSurfacesPL* New(); + virtual ~VISU_IsoSurfacesPL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual int GetNbParts(); + virtual void SetNbParts(int theNb = 10); + + virtual void SetScaling(int theScaling = VTK_SCALE_LINEAR); + virtual void SetRange(float theRange[2]); + virtual float GetMin(); + virtual float GetMax(); + +public: + virtual void Init(); + virtual void Update(); + virtual THook* DoHook(); + virtual void SetMapScale(float theMapScale = 1.0); + +protected: + int myNbParts; + float myRange[2]; + vtkContourFilter *myContourFilter; +}; + + +#endif diff --git a/src/PIPELINE/VISU_LookupTable.cxx b/src/PIPELINE/VISU_LookupTable.cxx new file mode 100644 index 00000000..06f21c5a --- /dev/null +++ b/src/PIPELINE/VISU_LookupTable.cxx @@ -0,0 +1,579 @@ +// 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 +// +// +// File : VISU_LookupTable.cxx +// Author : Vitaliy Smetannikov +// Module : VISU + +#include "VISU_LookupTable.hxx" + +#include +#include +#include + +using namespace std; + +VISU_LookupTable *VISU_LookupTable::New() { + vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_LookupTable"); + if(ret) + return (VISU_LookupTable*)ret; + return new VISU_LookupTable; +} + +VISU_LookupTable::VISU_LookupTable(int sze, int ext) + : vtkLookupTable(sze, ext), myScale(1.0) {} + +int VISU_LookupTable::ComputeLogRange(float inRange[2], float outRange[2]){ + if(inRange[0] >= inRange[1]) + return -1; + if(0.0 <= inRange[0] && 0.0 < inRange[1]){ + if(inRange[0] != 0.0) + outRange[0] = log10((double)inRange[0]); + else + outRange[0] = log10((double)inRange[1]*1.0E-6); + outRange[1] = log10((double)inRange[1]); + return 0; + }else if(inRange[0] < 0.0 && inRange[1] <= 0.0){ + outRange[0] = log10((double)-inRange[0]); + outRange[1] = log10((double)-inRange[1]); + return 1; + }else + return -1; +} + +unsigned char* VISU_LookupTable::MapValue(float v) { + if(GetScale() == VTK_SCALE_LOG10) { + float aLowBound = log10(this->TableRange[0]); + v = pow(10.0f,aLowBound + (v - aLowBound)*myScale); + return vtkLookupTable::MapValue(v); + }else{ + v = this->TableRange[0] + (v - this->TableRange[0])*myScale; + return vtkLookupTable::MapValue(v); + } +} + +// Apply log to value, with appropriate constraints. +inline float VISU_ApplyLogScale(float v, float range[2], + float logRange[2]) +{ + // is the range set for negative numbers? + if (range[0] < 0) + { + if (v < 0) + { + v = log10(-static_cast(v)); + } + else if (range[0] > range[1]) + { + v = logRange[0]; + } + else + { + v = logRange[1]; + } + } + else + { + if (v > 0) + { + v = log10(static_cast(v)); + } + else if (range[0] < range[1]) + { + v = logRange[0]; + } + else + { + v = logRange[1]; + } + } + return v; +} + +// Apply shift/scale to the scalar value v and do table lookup. +inline unsigned char *VISU_LinearLookup(float v, + unsigned char *table, + float maxIndex, + float shift, float scale) +{ + float findx = (v + shift)*scale; + if (findx < 0) + { + findx = 0; + } + if (findx > maxIndex) + { + findx = maxIndex; + } + return &table[4*static_cast(findx)]; + /* round + return &table[4*(int)(findx + 0.5f)]; + */ +} + +// accelerate the mapping by copying the data in 32-bit chunks instead +// of 8-bit chunks +template +void VISU_LookupTableMapData(vtkLookupTable *self, T *input, + unsigned char *output, int length, + int inIncr, int outFormat, float theMapScale) +{ + int i = length; + float *range = self->GetTableRange(); + float maxIndex = self->GetNumberOfColors() - 1; + float shift, scale; + unsigned char *table = self->GetPointer(0); + unsigned char *cptr; + float alpha; + + if ( (alpha=self->GetAlpha()) >= 1.0 ) //no blending required + { + if (self->GetScale() == VTK_SCALE_LOG10) + { + float val; + float logRange[2]; + VISU_LookupTable::ComputeLogRange(range, logRange); + shift = -logRange[0]; + if (logRange[1] <= logRange[0]) + { + scale = VTK_LARGE_FLOAT; + } + else + { + scale = (maxIndex + 1)/(logRange[1] - logRange[0]); + } + /* correct scale + scale = maxIndex/(logRange[1] - logRange[0]); + */ + if (outFormat == VTK_RGBA) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_RGB) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_LUMINANCE_ALPHA) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + *output++ = cptr[3]; + input += inIncr; + } + } + else // outFormat == VTK_LUMINANCE + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + input += inIncr; + } + } + }//if log scale + + else //not log scale + { + shift = -range[0]; + if (range[1] <= range[0]) + { + scale = VTK_LARGE_FLOAT; + } + else + { + scale = (maxIndex + 1)/(range[1] - range[0]); + } + /* correct scale + scale = maxIndex/(range[1] - range[0]); + */ + + if (outFormat == VTK_RGBA) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_RGB) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_LUMINANCE_ALPHA) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + *output++ = cptr[3]; + input += inIncr; + } + } + else // outFormat == VTK_LUMINANCE + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + input += inIncr; + } + } + }//if not log lookup + }//if blending not needed + + else //blend with the specified alpha + { + if (self->GetScale() == VTK_SCALE_LOG10) + { + float val; + float logRange[2]; + VISU_LookupTable::ComputeLogRange(range, logRange); + shift = -logRange[0]; + if (logRange[1] <= logRange[0]) + { + scale = VTK_LARGE_FLOAT; + } + else + { + scale = (maxIndex + 1)/(logRange[1] - logRange[0]); + } + /* correct scale + scale = maxIndex/(logRange[1] - logRange[0]); + */ + if (outFormat == VTK_RGBA) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = static_cast((*cptr)*alpha); cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_RGB) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_LUMINANCE_ALPHA) + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + *output++ = static_cast(alpha*cptr[3]); + input += inIncr; + } + } + else // outFormat == VTK_LUMINANCE + { + while (--i >= 0) + { + val = VISU_ApplyLogScale(*input, range, logRange); + cptr = VISU_LinearLookup(val, table, maxIndex, shift, scale*theMapScale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + input += inIncr; + } + } + }//log scale with blending + + else //no log scale with blending + { + shift = -range[0]; + if (range[1] <= range[0]) + { + scale = VTK_LARGE_FLOAT; + } + else + { + scale = (maxIndex + 1)/(range[1] - range[0]); + } + /* correct scale + scale = maxIndex/(range[1] - range[0]); + */ + + if (outFormat == VTK_RGBA) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = static_cast((*cptr)*alpha); cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_RGB) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + *output++ = *cptr++; + *output++ = *cptr++; + *output++ = *cptr++; + input += inIncr; + } + } + else if (outFormat == VTK_LUMINANCE_ALPHA) + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + *output++ = static_cast(cptr[3]*alpha); + input += inIncr; + } + } + else // outFormat == VTK_LUMINANCE + { + while (--i >= 0) + { + cptr = VISU_LinearLookup(*input, table, maxIndex, shift, scale); + *output++ = static_cast(cptr[0]*0.30 + cptr[1]*0.59 + + cptr[2]*0.11 + 0.5); + input += inIncr; + } + } + }//no log scale + }//alpha blending +} + +// Although this is a relatively expensive calculation, +// it is only done on the first render. Colors are cached +// for subsequent renders. +template +void VISU_LookupTableMapMag(vtkLookupTable *self, T *input, + unsigned char *output, int length, + int inIncr, int outFormat, float theMapScale) +{ + double tmp, sum; + double *mag; + int i, j; + + mag = new double[length]; + for (i = 0; i < length; ++i) + { + sum = 0; + for (j = 0; j < inIncr; ++j) + { + tmp = (double)(*input); + sum += (tmp * tmp); + ++input; + } + mag[i] = sqrt(sum); + } + + VISU_LookupTableMapData(self, mag, output, length, 1, outFormat, theMapScale); + + delete [] mag; +} + + +void VISU_LookupTable::MapScalarsThroughTable2(void *input, + unsigned char *output, + int inputDataType, + int numberOfValues, + int inputIncrement, + int outputFormat) +{ + if (this->UseMagnitude && inputIncrement > 1) + { + switch (inputDataType) + { + case VTK_BIT: + vtkErrorMacro("Cannot comput magnitude of bit array."); + break; + case VTK_CHAR: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_UNSIGNED_CHAR: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_SHORT: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_UNSIGNED_SHORT: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_INT: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_UNSIGNED_INT: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_LONG: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_UNSIGNED_LONG: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_FLOAT: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + case VTK_DOUBLE: + VISU_LookupTableMapMag(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + return; + default: + vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); + return; + } + } + + switch (inputDataType) + { + case VTK_BIT: + { + vtkIdType i, id; + vtkBitArray *bitArray = vtkBitArray::New(); + bitArray->SetVoidArray(input,numberOfValues,1); + vtkUnsignedCharArray *newInput = vtkUnsignedCharArray::New(); + newInput->SetNumberOfValues(numberOfValues); + for (id=i=0; iSetValue(i, bitArray->GetValue(id)); + } + VISU_LookupTableMapData(this, + static_cast(newInput->GetPointer(0)), + output,numberOfValues, + inputIncrement,outputFormat,myScale); + newInput->Delete(); + bitArray->Delete(); + } + break; + + case VTK_CHAR: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_UNSIGNED_CHAR: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_SHORT: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_UNSIGNED_SHORT: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_INT: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_UNSIGNED_INT: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_LONG: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_UNSIGNED_LONG: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_FLOAT: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + case VTK_DOUBLE: + VISU_LookupTableMapData(this,static_cast(input),output, + numberOfValues,inputIncrement,outputFormat,myScale); + break; + + default: + vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType"); + return; + } +} + diff --git a/src/PIPELINE/VISU_LookupTable.hxx b/src/PIPELINE/VISU_LookupTable.hxx new file mode 100644 index 00000000..769ba892 --- /dev/null +++ b/src/PIPELINE/VISU_LookupTable.hxx @@ -0,0 +1,35 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VISU_LookupTable.h +// Author : Vitaliy Smetannikov +// Module : VISU + +#ifndef VISU_LookupTable_H +#define VISU_LookupTable_H + +#include + +class VISU_LookupTable: public vtkLookupTable { + public: + vtkTypeMacro(VISU_LookupTable,vtkLookupTable); + static VISU_LookupTable *New(); + + virtual void MapScalarsThroughTable2(void *input, unsigned char *output, + int inputDataType, int numberOfValues, + int inputIncrement, int outputIncrement); + + float GetMapScale() { return myScale; } + void SetMapScale(float theScale = 1.0) { myScale = theScale; Modified(); } + + static int ComputeLogRange(float inRange[2], float outRange[2]); + unsigned char *MapValue(float v); + + protected: + VISU_LookupTable(int sze=256, int ext=256); + ~VISU_LookupTable() {}; + + float myScale; +}; +#endif // VISU_LookupTable_H diff --git a/src/PIPELINE/VISU_MeshPL.cxx b/src/PIPELINE/VISU_MeshPL.cxx new file mode 100644 index 00000000..4e3e92d2 --- /dev/null +++ b/src/PIPELINE/VISU_MeshPL.cxx @@ -0,0 +1,46 @@ +// 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 +// +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_MeshPL.hxx" +#include "SALOME_GeometryFilter.h" + +#include +#include +#include +#include + +vtkStandardNewMacro(VISU_MeshPL); + +VISU_MeshPL::VISU_MeshPL(){} + +void VISU_MeshPL::Build() { + myMapper->SetInput(myInput); +} + +void VISU_MeshPL::Init(){ +} diff --git a/src/PIPELINE/VISU_MeshPL.hxx b/src/PIPELINE/VISU_MeshPL.hxx new file mode 100644 index 00000000..27be219c --- /dev/null +++ b/src/PIPELINE/VISU_MeshPL.hxx @@ -0,0 +1,45 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_MeshPL_HeaderFile +#define VISU_MeshPL_HeaderFile + +#include "VISU_PipeLine.hxx" + +class VISU_MeshPL : public VISU_PipeLine{ +protected: + VISU_MeshPL(); + VISU_MeshPL(const VISU_MeshPL&); +public: + vtkTypeMacro(VISU_MeshPL,VISU_PipeLine); + static VISU_MeshPL* New(); + +public: + virtual void Build(); + virtual void Init(); +}; + +#endif diff --git a/src/PIPELINE/VISU_PipeLine.cxx b/src/PIPELINE/VISU_PipeLine.cxx new file mode 100644 index 00000000..d4354e35 --- /dev/null +++ b/src/PIPELINE/VISU_PipeLine.cxx @@ -0,0 +1,110 @@ +// 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 +// +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_PipeLine.hxx" + +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +VISU_PipeLine::VISU_PipeLine(){ + myMapper = TMapper::New(); + myInput = NULL; +} + +VISU_PipeLine::~VISU_PipeLine(){ + myMapper->Delete(); + SetInput(NULL); +} + +void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){ + SetInput(thePipeLine->GetInput()); + myMapper->ShallowCopy(thePipeLine->GetMapper()); + Build(); +} + +void VISU_PipeLine::SetInput(TInput* theInput){ + if (myInput != theInput){ + if (myInput != NULL) myInput->UnRegister(this); + myInput = theInput; + if (myInput != NULL) { + myInput->Register(this); + myInput->Update(); + } + Modified(); + } +} + +VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper() { + if(myInput){ + if(!myMapper->GetInput()){ + myInput->Update(); + Build(); + } + myMapper->Update(); + } + return myMapper; +} + +void VISU_PipeLine::Update(){ + myMapper->Update(); +} + + +size_t VISU_PipeLine::CheckAvailableMemory(const size_t& theSize){ + try{ + char *aCheck = new char[theSize]; + if(aCheck) delete [] aCheck; + if(MYDEBUG && aCheck == NULL) + cout<<"VISU_PipeLine::CheckAvailableMemory("< theMinSize) + theSize /= 2; + else + return 0; + return theSize; +} diff --git a/src/PIPELINE/VISU_PipeLine.hxx b/src/PIPELINE/VISU_PipeLine.hxx new file mode 100644 index 00000000..21a8b24d --- /dev/null +++ b/src/PIPELINE/VISU_PipeLine.hxx @@ -0,0 +1,68 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_PipeLine_HeaderFile +#define VISU_PipeLine_HeaderFile + +#include +#include +#include +#include + +class vtkDataSetMapper; +class vtkUnstructuredGrid; + +class VISU_PipeLine : public vtkObject{ +protected: + VISU_PipeLine(); + VISU_PipeLine(const VISU_PipeLine&); +public: + vtkTypeMacro(VISU_PipeLine,vtkObject); + virtual ~VISU_PipeLine(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + +public: + typedef vtkUnstructuredGrid TInput; + virtual void SetInput(TInput* theInput); + virtual TInput* GetInput() { return myInput;} + + typedef vtkDataSetMapper TMapper; + virtual TMapper* GetMapper(); + + virtual void Init() = 0; + virtual void Update(); + + static size_t CheckAvailableMemory(const size_t& theSize); + static size_t GetAvailableMemory(size_t theSize = 16*1024*1024, + size_t theMinSize = 1024*1024); +protected: + virtual void Build() = 0; + + TInput *myInput; + TMapper *myMapper; +}; + +#endif diff --git a/src/PIPELINE/VISU_PipeLineUtils.cxx b/src/PIPELINE/VISU_PipeLineUtils.cxx new file mode 100644 index 00000000..f60c2cca --- /dev/null +++ b/src/PIPELINE/VISU_PipeLineUtils.cxx @@ -0,0 +1,36 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#include "VISU_PipeLineUtils.hxx" + +void VISU::Mul(const float A[3], float b, float C[3]){ // A*b; + for(int i = 0; i < 3; i++) C[i] = A[i]*b; +} + +void VISU::Sub(const float A[3], const float B[3], float C[3]){ //A-B + for(int i = 0; i < 3; i++) C[i] = A[i] - B[i]; +} + diff --git a/src/PIPELINE/VISU_PipeLineUtils.hxx b/src/PIPELINE/VISU_PipeLineUtils.hxx new file mode 100644 index 00000000..a6242399 --- /dev/null +++ b/src/PIPELINE/VISU_PipeLineUtils.hxx @@ -0,0 +1,81 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_PipeLineUtils_HeaderFile +#define VISU_PipeLineUtils_HeaderFile + +#include "VISU_FieldTransform.hxx" +#include "VISU_LookupTable.hxx" +#include "VISU_Extractor.hxx" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace VISU{ + void Mul(const float A[3], float b, float C[3]); // C = A * b + void Sub(const float A[3], const float B[3], float C[3]); // C = A - B + + template void CellDataToPoint(TItem* theTItem, vtkDataSet* theDataSet, + VISU_FieldTransform *theFieldTransform) + { + if(theDataSet->GetCellData()->GetNumberOfArrays()){ + vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New(); + aFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput()); + aFilter->PassCellDataOn(); + theTItem->SetInput(aFilter->GetUnstructuredGridOutput()); + aFilter->Register(theTItem); + aFilter->Delete(); + }else + theTItem->SetInput(theFieldTransform->GetUnstructuredGridOutput()); + } + + template void ToCellCenters(TItem* theTItem, vtkDataSet* theDataSet, + VISU_FieldTransform *theFieldTransform) + { + if(theDataSet->GetCellData()->GetNumberOfArrays()){ + vtkCellCenters *aCenters = vtkCellCenters::New(); // for vectors on cells + aCenters->SetInput(theFieldTransform->GetUnstructuredGridOutput()); + aCenters->VertexCellsOn(); + theTItem->SetInput(aCenters->GetOutput()); + aCenters->Register(theTItem); + aCenters->Delete(); + }else + theTItem->SetInput(theFieldTransform->GetUnstructuredGridOutput()); + } +} + +#endif + diff --git a/src/PIPELINE/VISU_ScalarBarActor.cxx b/src/PIPELINE/VISU_ScalarBarActor.cxx new file mode 100644 index 00000000..afa44bd7 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarActor.cxx @@ -0,0 +1,607 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#include "VISU_ScalarBarActor.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +vtkCxxRevisionMacro(VISU_ScalarBarActor, "$Revision$"); + +vtkCxxSetObjectMacro(VISU_ScalarBarActor,LookupTable,VISU_LookupTable); +vtkCxxSetObjectMacro(VISU_ScalarBarActor,LabelTextProperty,vtkTextProperty); +vtkCxxSetObjectMacro(VISU_ScalarBarActor,TitleTextProperty,vtkTextProperty); + +//------------------------------------------------------------------------------ +VISU_ScalarBarActor* VISU_ScalarBarActor::New(){ + vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_ScalarBarActor"); + if(ret) + return (VISU_ScalarBarActor*)ret; + return new VISU_ScalarBarActor; +} + +VISU_ScalarBarActor::VISU_ScalarBarActor() +{ + this->LookupTable = NULL; + this->Position2Coordinate->SetValue(0.17, 0.8); + + this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport(); + this->PositionCoordinate->SetValue(0.82,0.1); + + this->MaximumNumberOfColors = 64; + this->NumberOfLabels = 5; + this->NumberOfLabelsBuilt = 0; + this->Orientation = VTK_ORIENT_VERTICAL; + this->Title = NULL; + + this->LabelTextProperty = vtkTextProperty::New(); + this->LabelTextProperty->SetFontSize(12); + this->LabelTextProperty->SetBold(1); + this->LabelTextProperty->SetItalic(1); + this->LabelTextProperty->SetShadow(1); + this->LabelTextProperty->SetFontFamilyToArial(); + + this->TitleTextProperty = vtkTextProperty::New(); + this->TitleTextProperty->ShallowCopy(this->LabelTextProperty); + + this->LabelFormat = new char[8]; + sprintf(this->LabelFormat,"%s","%-#6.3g"); + + this->TitleMapper = vtkTextMapper::New(); + this->TitleActor = vtkActor2D::New(); + this->TitleActor->SetMapper(this->TitleMapper); + this->TitleActor->GetPositionCoordinate()-> + SetReferenceCoordinate(this->PositionCoordinate); + + this->TextMappers = NULL; + this->TextActors = NULL; + + this->ScalarBar = vtkPolyData::New(); + this->ScalarBarMapper = vtkPolyDataMapper2D::New(); + this->ScalarBarMapper->SetInput(this->ScalarBar); + this->ScalarBarActor = vtkActor2D::New(); + this->ScalarBarActor->SetMapper(this->ScalarBarMapper); + this->ScalarBarActor->GetPositionCoordinate()-> + SetReferenceCoordinate(this->PositionCoordinate); + this->LastOrigin[0] = 0; + this->LastOrigin[1] = 0; + this->LastSize[0] = 0; + this->LastSize[1] = 0; +} + +void VISU_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win) +{ + this->TitleActor->ReleaseGraphicsResources(win); + if (this->TextMappers != NULL ) + { + for (int i=0; i < this->NumberOfLabelsBuilt; i++) + { + this->TextActors[i]->ReleaseGraphicsResources(win); + } + } + this->ScalarBarActor->ReleaseGraphicsResources(win); +} + +VISU_ScalarBarActor::~VISU_ScalarBarActor() +{ + if (this->LabelFormat) + { + delete [] this->LabelFormat; + this->LabelFormat = NULL; + } + + this->TitleMapper->Delete(); + this->TitleActor->Delete(); + + if (this->TextMappers != NULL ) + { + for (int i=0; i < this->NumberOfLabelsBuilt; i++) + { + this->TextMappers[i]->Delete(); + this->TextActors[i]->Delete(); + } + delete [] this->TextMappers; + delete [] this->TextActors; + } + + this->ScalarBar->Delete(); + this->ScalarBarMapper->Delete(); + this->ScalarBarActor->Delete(); + + if (this->Title) + { + delete [] this->Title; + this->Title = NULL; + } + + this->SetLookupTable(NULL); + this->SetLabelTextProperty(NULL); + this->SetTitleTextProperty(NULL); +} + +int VISU_ScalarBarActor::RenderOverlay(vtkViewport *viewport) +{ + int renderedSomething = 0; + int i; + + // Everything is built, just have to render + if (this->Title != NULL) + { + renderedSomething += this->TitleActor->RenderOverlay(viewport); + } + this->ScalarBarActor->RenderOverlay(viewport); + if( this->TextActors == NULL) + { + vtkWarningMacro(<<"Need a mapper to render a scalar bar"); + return renderedSomething; + } + + for (i=0; iNumberOfLabels; i++) + { + renderedSomething += this->TextActors[i]->RenderOverlay(viewport); + } + + renderedSomething = (renderedSomething > 0)?(1):(0); + + return renderedSomething; +} + +int VISU_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport) +{ + int renderedSomething = 0; + int i; + int size[2]; + + if (!this->LookupTable) + { + vtkWarningMacro(<<"Need a mapper to render a scalar bar"); + return 0; + } + + if (!this->TitleTextProperty) + { + vtkErrorMacro(<<"Need title text property to render a scalar bar"); + return 0; + } + + if (!this->LabelTextProperty) + { + vtkErrorMacro(<<"Need label text property to render a scalar bar"); + return 0; + } + + // Check to see whether we have to rebuild everything + int positionsHaveChanged = 0; + if (viewport->GetMTime() > this->BuildTime || + (viewport->GetVTKWindow() && + viewport->GetVTKWindow()->GetMTime() > this->BuildTime)) + { + // if the viewport has changed we may - or may not need + // to rebuild, it depends on if the projected coords chage + int *barOrigin; + barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport); + size[0] = + this->Position2Coordinate->GetComputedViewportValue(viewport)[0] - + barOrigin[0]; + size[1] = + this->Position2Coordinate->GetComputedViewportValue(viewport)[1] - + barOrigin[1]; + if (this->LastSize[0] != size[0] || + this->LastSize[1] != size[1] || + this->LastOrigin[0] != barOrigin[0] || + this->LastOrigin[1] != barOrigin[1]) + { + positionsHaveChanged = 1; + } + } + + // Check to see whether we have to rebuild everything + if (positionsHaveChanged || + this->GetMTime() > this->BuildTime || + this->LookupTable->GetMTime() > this->BuildTime || + this->LabelTextProperty->GetMTime() > this->BuildTime || + this->TitleTextProperty->GetMTime() > this->BuildTime) + { + + // Delete previously constructed objects + // + if (this->TextMappers != NULL ) + { + for (i=0; i < this->NumberOfLabelsBuilt; i++) + { + this->TextMappers[i]->Delete(); + this->TextActors[i]->Delete(); + } + delete [] this->TextMappers; + delete [] this->TextActors; + } + + // Build scalar bar object; determine its type + // + VISU_LookupTable *lut = this->LookupTable; //SALOME specific + int isLogTable = lut->GetScale() == VTK_SCALE_LOG10; + + // we hard code how many steps to display + int numColors = this->MaximumNumberOfColors; + float *range = lut->GetRange(); + + int numPts = 2*(numColors + 1); + vtkPoints *pts = vtkPoints::New(); + pts->SetNumberOfPoints(numPts); + vtkCellArray *polys = vtkCellArray::New(); + polys->Allocate(polys->EstimateSize(numColors,4)); + vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New(); + colors->SetNumberOfComponents(3); + colors->SetNumberOfTuples(numColors); + + this->ScalarBarActor->SetProperty(this->GetProperty()); + this->ScalarBar->Initialize(); + this->ScalarBar->SetPoints(pts); + this->ScalarBar->SetPolys(polys); + this->ScalarBar->GetCellData()->SetScalars(colors); + pts->Delete(); polys->Delete(); colors->Delete(); + + // get the viewport size in display coordinates + int *barOrigin, barWidth, barHeight; + barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport); + size[0] = + this->Position2Coordinate->GetComputedViewportValue(viewport)[0] - + barOrigin[0]; + size[1] = + this->Position2Coordinate->GetComputedViewportValue(viewport)[1] - + barOrigin[1]; + this->LastOrigin[0] = barOrigin[0]; + this->LastOrigin[1] = barOrigin[1]; + this->LastSize[0] = size[0]; + this->LastSize[1] = size[1]; + + // Update all the composing objects + this->TitleActor->SetProperty(this->GetProperty()); + this->TitleMapper->SetInput(this->Title); + if (this->TitleTextProperty->GetMTime() > this->BuildTime) + { + // Shallow copy here so that the size of the title prop is not affected + // by the automatic adjustment of its text mapper's size (i.e. its + // mapper's text property is identical except for the font size + // which will be modified later). This allows text actors to + // share the same text property, and in that case specifically allows + // the title and label text prop to be the same. + this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty); + this->TitleMapper->GetTextProperty()->SetJustificationToCentered(); + } + + // find the best size for the title font + int titleSize[2]; + this->SizeTitle(titleSize, size, viewport); + + // find the best size for the ticks + int labelSize[2]; + this->AllocateAndSizeLabels(labelSize, size, viewport,range); + this->NumberOfLabelsBuilt = this->NumberOfLabels; + + // generate points + float x[3]; x[2] = 0.0; + float delta, val; + if ( this->Orientation == VTK_ORIENT_VERTICAL ) + { + barWidth = size[0] - 4 - labelSize[0]; + barHeight = (int)(0.86*size[1]); + delta=(float)barHeight/numColors; + for (i=0; iSetPoint(2*i,x); + x[0] = barWidth; + pts->SetPoint(2*i+1,x); + } + } + else + { + barWidth = size[0]; + barHeight = (int)(0.4*size[1]); + delta=(float)barWidth/numColors; + for (i=0; iSetPoint(2*i,x); + x[1] = 0; + pts->SetPoint(2*i+1,x); + } + } + + //polygons & cell colors + unsigned char *rgba, *rgb; + vtkIdType ptIds[4]; + for (i=0; iInsertNextCell(4,ptIds); + + if ( isLogTable ){ //SALOME specific + float rgbval = log10(range[0]) + + i*(log10(range[1])-log10(range[0]))/(numColors -1); + rgba = lut->MapValue(rgbval); + }else{ + rgba = lut->MapValue(range[0] + (range[1] - range[0])* + ((float)i /(numColors-1.0))); + } + + rgb = colors->GetPointer(3*i); //write into array directly + rgb[0] = rgba[0]; + rgb[1] = rgba[1]; + rgb[2] = rgba[2]; + } + + // Now position everything properly + // + if (this->Orientation == VTK_ORIENT_VERTICAL) + { + int sizeTextData[2]; + + // center the title + this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]); + + for (i=0; i < this->NumberOfLabels; i++) + { + val = (float)i/(this->NumberOfLabels-1) *barHeight; + this->TextMappers[i]->GetSize(viewport,sizeTextData); + this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft(); + this->TextActors[i]->SetPosition(barWidth+3, + val - sizeTextData[1]/2); + } + } + else + { + this->TitleActor->SetPosition(size[0]/2, + barHeight + labelSize[1] + 0.1*size[1]); + for (i=0; i < this->NumberOfLabels; i++) + { + this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered(); + val = (float)i/(this->NumberOfLabels-1) * barWidth; + this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]); + } + } + + this->BuildTime.Modified(); + } + + // Everything is built, just have to render + if (this->Title != NULL) + { + renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport); + } + this->ScalarBarActor->RenderOpaqueGeometry(viewport); + for (i=0; iNumberOfLabels; i++) + { + renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport); + } + + renderedSomething = (renderedSomething > 0)?(1):(0); + + return renderedSomething; +} + +void VISU_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + + if ( this->LookupTable ) + { + os << indent << "Lookup Table:\n"; + this->LookupTable->PrintSelf(os,indent.GetNextIndent()); + } + else + { + os << indent << "Lookup Table: (none)\n"; + } + + if (this->TitleTextProperty) + { + os << indent << "Title Text Property:\n"; + this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent()); + } + else + { + os << indent << "Title Text Property: (none)\n"; + } + + if (this->LabelTextProperty) + { + os << indent << "Label Text Property:\n"; + this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent()); + } + else + { + os << indent << "Label Text Property: (none)\n"; + } + + os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n"; + os << indent << "Maximum Number Of Colors: " + << this->MaximumNumberOfColors << "\n"; + os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n"; + os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n"; + + os << indent << "Orientation: "; + if ( this->Orientation == VTK_ORIENT_HORIZONTAL ) + { + os << "Horizontal\n"; + } + else + { + os << "Vertical\n"; + } + + os << indent << "Label Format: " << this->LabelFormat << "\n"; +} + +void VISU_ScalarBarActor::ShallowCopy(vtkProp *prop) +{ + VISU_ScalarBarActor *a = VISU_ScalarBarActor::SafeDownCast(prop); + if ( a != NULL ) + { + this->SetPosition2(a->GetPosition2()); + this->SetLookupTable(a->GetLookupTable()); + this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors()); + this->SetOrientation(a->GetOrientation()); + this->SetLabelTextProperty(a->GetLabelTextProperty()); + this->SetTitleTextProperty(a->GetTitleTextProperty()); + this->SetLabelFormat(a->GetLabelFormat()); + this->SetTitle(a->GetTitle()); + this->GetPositionCoordinate()->SetCoordinateSystem( + a->GetPositionCoordinate()->GetCoordinateSystem()); + this->GetPositionCoordinate()->SetValue( + a->GetPositionCoordinate()->GetValue()); + this->GetPosition2Coordinate()->SetCoordinateSystem( + a->GetPosition2Coordinate()->GetCoordinateSystem()); + this->GetPosition2Coordinate()->SetValue( + a->GetPosition2Coordinate()->GetValue()); + } + + // Now do superclass + this->vtkActor2D::ShallowCopy(prop); +} + +void VISU_ScalarBarActor::AllocateAndSizeLabels(int *labelSize, int *size, + vtkViewport *viewport, + float *range) +{ + labelSize[0] = labelSize[1] = 0; + + this->TextMappers = new vtkTextMapper * [this->NumberOfLabels]; + this->TextActors = new vtkActor2D * [this->NumberOfLabels]; + + char string[512]; + + float val; + int i; + + // TODO: this should be optimized, maybe by keeping a list of + // allocated mappers, in order to avoid creation/destruction of + // their underlying text properties (i.e. each time a mapper is + // created, text properties are created and shallow-assigned a font size + // which value might be "far" from the target font size). + + VISU_LookupTable *lut = this->LookupTable; //SALOME specific + int isLogTable = lut->GetScale() == VTK_SCALE_LOG10; + + for (i=0; i < this->NumberOfLabels; i++) + { + this->TextMappers[i] = vtkTextMapper::New(); + + if(isLogTable && 0 < i && i < this->NumberOfLabels - 1){ // SALOME specific + float lval = log10(range[0]) + (float)i/(this->NumberOfLabels-1) * + (log10(range[1])-log10(range[0])); + val = pow(10,lval); + }else{ + val = range[0] + (float)i/(this->NumberOfLabels-1) * (range[1]-range[0]); + } + sprintf(string, this->LabelFormat, val); + this->TextMappers[i]->SetInput(string); + + // Shallow copy here so that the size of the label prop is not affected + // by the automatic adjustment of its text mapper's size (i.e. its + // mapper's text property is identical except for the font size + // which will be modified later). This allows text actors to + // share the same text property, and in that case specifically allows + // the title and label text prop to be the same. + this->TextMappers[i]->GetTextProperty()->ShallowCopy( + this->LabelTextProperty); + + this->TextActors[i] = vtkActor2D::New(); + this->TextActors[i]->SetMapper(this->TextMappers[i]); + this->TextActors[i]->SetProperty(this->GetProperty()); + this->TextActors[i]->GetPositionCoordinate()-> + SetReferenceCoordinate(this->PositionCoordinate); + } + + if (this->NumberOfLabels) + { + int targetWidth, targetHeight; + + if ( this->Orientation == VTK_ORIENT_VERTICAL ) + { + targetWidth = (int)(0.6*size[0]); + targetHeight = (int)(0.86*size[1]/this->NumberOfLabels); + } + else + { + targetWidth = (int)(size[0]*0.8/this->NumberOfLabels); + targetHeight = (int)(0.25*size[1]); + } + + vtkTextMapper::SetMultipleConstrainedFontSize(viewport, + targetWidth, + targetHeight, + this->TextMappers, + this->NumberOfLabels, + labelSize); + } +} + +void VISU_ScalarBarActor::SizeTitle(int *titleSize, int *size, + vtkViewport *viewport) +{ + titleSize[0] = titleSize[1] = 0; + + if (this->Title == NULL || !strlen(this->Title)) + { + return; + } + + int targetWidth, targetHeight; + + targetWidth = size[0]; + if ( this->Orientation == VTK_ORIENT_VERTICAL ) + { + targetHeight = (int)(0.1*size[1]); + } + else + { + targetHeight = (int)(0.25*size[1]); + } + + this->TitleMapper->SetConstrainedFontSize( + viewport, targetWidth, targetHeight); + + this->TitleMapper->GetSize(viewport, titleSize); +} diff --git a/src/PIPELINE/VISU_ScalarBarActor.hxx b/src/PIPELINE/VISU_ScalarBarActor.hxx new file mode 100644 index 00000000..be2f62ce --- /dev/null +++ b/src/PIPELINE/VISU_ScalarBarActor.hxx @@ -0,0 +1,164 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_ScalarBarActor_HeaderFile +#define VISU_ScalarBarActor_HeaderFile + +#include "VISU_LookupTable.hxx" + +#include + +class vtkPolyData; +class vtkPolyDataMapper2D; +class vtkScalarsToColors; +class vtkTextMapper; +class vtkTextProperty; + +#ifndef VTK_ORIENT_HORIZONTAL +#define VTK_ORIENT_HORIZONTAL 0 +#endif + +#ifndef VTK_ORIENT_VERTICAL +#define VTK_ORIENT_VERTICAL 1 +#endif + +class VISU_ScalarBarActor : public vtkActor2D +{ +public: + vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label + // format, no title, and vertical orientation. The initial scalar bar + // size is (0.05 x 0.8) of the viewport size. + static VISU_ScalarBarActor *New(); + + // Description: + // Draw the scalar bar and annotation text to the screen. + int RenderOpaqueGeometry(vtkViewport* viewport); + int RenderTranslucentGeometry(vtkViewport*) { return 0; }; + int RenderOverlay(vtkViewport* viewport); + + // Description: + // Release any graphics resources that are being consumed by this actor. + // The parameter window could be used to determine which graphic + // resources to release. + virtual void ReleaseGraphicsResources(vtkWindow *); + + // Description: + // Set/Get the vtkLookupTable to use. The lookup table specifies the number + // of colors to use in the table (if not overridden), as well as the scalar + // range. + virtual void SetLookupTable(VISU_LookupTable*); + vtkGetObjectMacro(LookupTable,VISU_LookupTable); + + // Description: + // Set/Get the maximum number of scalar bar segments to show. This may + // differ from the number of colors in the lookup table, in which case + // the colors are samples from the lookup table. + vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER); + vtkGetMacro(MaximumNumberOfColors, int); + + // Description: + // Set/Get the number of annotation labels to show. + vtkSetClampMacro(NumberOfLabels, int, 0, 64); + vtkGetMacro(NumberOfLabels, int); + + // Description: + // Control the orientation of the scalar bar. + vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL); + vtkGetMacro(Orientation, int); + void SetOrientationToHorizontal() + {this->SetOrientation(VTK_ORIENT_HORIZONTAL);}; + void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);}; + + // Description: + // Set/Get the title text property. + virtual void SetTitleTextProperty(vtkTextProperty *p); + vtkGetObjectMacro(TitleTextProperty,vtkTextProperty); + + // Description: + // Set/Get the labels text property. + virtual void SetLabelTextProperty(vtkTextProperty *p); + vtkGetObjectMacro(LabelTextProperty,vtkTextProperty); + + // Description: + // Set/Get the format with which to print the labels on the scalar + // bar. + vtkSetStringMacro(LabelFormat); + vtkGetStringMacro(LabelFormat); + + // Description: + // Set/Get the title of the scalar bar actor, + vtkSetStringMacro(Title); + vtkGetStringMacro(Title); + + // Description: + // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method. + void ShallowCopy(vtkProp *prop); + +protected: + VISU_ScalarBarActor(); + ~VISU_ScalarBarActor(); + + VISU_LookupTable *LookupTable; + vtkTextProperty *TitleTextProperty; + vtkTextProperty *LabelTextProperty; + + int MaximumNumberOfColors; + int NumberOfLabels; + int NumberOfLabelsBuilt; + int Orientation; + char *Title; + char *LabelFormat; + + vtkTextMapper **TextMappers; + virtual void AllocateAndSizeLabels(int *labelSize, int *size, + vtkViewport *viewport, float *range); + +private: + vtkTextMapper *TitleMapper; + vtkActor2D *TitleActor; + + vtkActor2D **TextActors; + + vtkPolyData *ScalarBar; + vtkPolyDataMapper2D *ScalarBarMapper; + vtkActor2D *ScalarBarActor; + + vtkTimeStamp BuildTime; + int LastSize[2]; + int LastOrigin[2]; + + void SizeTitle(int *titleSize, int *size, vtkViewport *viewport); + +private: + VISU_ScalarBarActor(const VISU_ScalarBarActor&); // Not implemented. + void operator=(const VISU_ScalarBarActor&); // Not implemented. +}; + +#endif diff --git a/src/PIPELINE/VISU_ScalarMapPL.cxx b/src/PIPELINE/VISU_ScalarMapPL.cxx new file mode 100644 index 00000000..5025d98e --- /dev/null +++ b/src/PIPELINE/VISU_ScalarMapPL.cxx @@ -0,0 +1,183 @@ +// 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 +// +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_PipeLineUtils.hxx" + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +vtkStandardNewMacro(VISU_ScalarMapPL); + + +VISU_ScalarMapPL::VISU_ScalarMapPL(){ + myFieldTransform = VISU_FieldTransform::New(); + + myMapperTable = VISU_LookupTable::New(); + myMapperTable->SetScale(VTK_SCALE_LINEAR); + myMapperTable->SetHueRange(0.667,0.0); + + myBarTable = VISU_LookupTable::New(); + myBarTable->SetScale(VTK_SCALE_LINEAR); + myBarTable->SetHueRange(0.667,0.0); + + myExtractor = VISU_Extractor::New(); +} + + +VISU_ScalarMapPL::~VISU_ScalarMapPL(){ + myFieldTransform->Delete(); + myMapperTable->Delete();; + myBarTable->Delete(); + myExtractor->Delete(); +} + + +void VISU_ScalarMapPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_PipeLine::ShallowCopy(thePipeLine); + if(VISU_ScalarMapPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetScalarRange(aPipeLine->GetScalarRange()); + SetScalarMode(aPipeLine->GetScalarMode()); + SetNbColors(aPipeLine->GetNbColors()); + SetScaling(aPipeLine->GetScaling()); + //Update(); + } +} + + +int VISU_ScalarMapPL::GetScalarMode(){ + return myExtractor->GetScalarMode(); +} +void VISU_ScalarMapPL::SetScalarMode(int theScalarMode){ + myExtractor->SetScalarMode(theScalarMode); + Modified(); +} + + +int VISU_ScalarMapPL::GetScaling() { + return myBarTable->GetScale(); +} +void VISU_ScalarMapPL::SetScaling(int theScaling) { + myBarTable->SetScale(theScaling); + if(theScaling == VTK_SCALE_LOG10) + myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10)); + else + myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident)); + Modified(); +} + + +float* VISU_ScalarMapPL::GetScalarRange() { + return myFieldTransform->GetScalarRange(); +} +void VISU_ScalarMapPL::SetScalarRange(float theRange[2]){ + myFieldTransform->SetScalarRange(theRange); + myBarTable->SetRange(theRange); + Modified(); +} +void VISU_ScalarMapPL::SetScalarMin(float theValue){ + float aScalarRange[2] = {theValue, GetScalarRange()[1]}; + SetScalarRange(aScalarRange); +} +void VISU_ScalarMapPL::SetScalarMax(float theValue){ + float aScalarRange[2] = {GetScalarRange()[0], theValue}; + SetScalarRange(aScalarRange); +} + + +void VISU_ScalarMapPL::SetNbColors(int theNbColors) { + myMapperTable->SetNumberOfColors(theNbColors); + myBarTable->SetNumberOfColors(theNbColors); + Modified(); +} +int VISU_ScalarMapPL::GetNbColors() { + return myMapperTable->GetNumberOfColors(); +} + + +VISU_ScalarMapPL::THook* VISU_ScalarMapPL::DoHook(){ + myMapper->SetColorModeToMapScalars(); + myMapper->ScalarVisibilityOn(); + return myFieldTransform->GetUnstructuredGridOutput(); +} + + +void VISU_ScalarMapPL::Init(){ + //SetSourceRange(); +} + + +void VISU_ScalarMapPL::Build() { + myExtractor->SetInput(myInput); + myFieldTransform->SetInput(myExtractor->GetOutput()); + myMapper->SetInput(DoHook()); +} + + +void VISU_ScalarMapPL::Update() { + float *aRange = myFieldTransform->GetScalarRange(); + float aScalarRange[2] = {aRange[0], aRange[1]}; + if(myBarTable->GetScale() == VTK_SCALE_LOG10) + VISU_LookupTable::ComputeLogRange(aRange,aScalarRange); + myMapperTable->SetRange(aScalarRange); + myMapperTable->SetMapScale(1.0); + + myMapperTable->Build(); + myBarTable->Build(); + + myMapper->SetLookupTable(myMapperTable); + myMapper->SetScalarRange(aScalarRange); + + myFieldTransform->Update(); + + VISU_PipeLine::Update(); +} + + +void VISU_ScalarMapPL::SetMapScale(float theMapScale){ + myMapperTable->SetMapScale(theMapScale); + myMapperTable->Build(); +} +float VISU_ScalarMapPL::GetMapScale(){ + return myMapperTable->GetMapScale(); +} + + +void VISU_ScalarMapPL::GetSourceRange(float theRange[2]){ + myExtractor->Update(); + myExtractor->GetOutput()->GetScalarRange(theRange); +} + +void VISU_ScalarMapPL::SetSourceRange(){ + float aRange[2]; + GetSourceRange(aRange); + SetScalarRange(aRange); +} diff --git a/src/PIPELINE/VISU_ScalarMapPL.hxx b/src/PIPELINE/VISU_ScalarMapPL.hxx new file mode 100644 index 00000000..b5358285 --- /dev/null +++ b/src/PIPELINE/VISU_ScalarMapPL.hxx @@ -0,0 +1,86 @@ +// 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 +// +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_ScalrMapPL_HeaderFile +#define VISU_ScalrMapPL_HeaderFile + +#include "VISU_PipeLine.hxx" +#include "VISU_ScalarBarActor.hxx" + +class vtkDataSet; + +class VISU_Extractor; +class VISU_FieldTransform; + +class VISU_ScalarMapPL : public VISU_PipeLine{ +protected: + VISU_ScalarMapPL(); + VISU_ScalarMapPL(const VISU_ScalarMapPL&); +public: + vtkTypeMacro(VISU_ScalarMapPL,VISU_PipeLine); + static VISU_ScalarMapPL* New(); + virtual ~VISU_ScalarMapPL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual int GetScalarMode(); + virtual void SetScalarMode(int theScalarMode = 0); + + virtual int GetScaling(); + virtual void SetScaling(int theScaling = VTK_SCALE_LINEAR); + + virtual float* GetScalarRange(); + virtual void SetScalarRange(float theRange[2]); + virtual void SetScalarMin(float theValue); + virtual void SetScalarMax(float theValue); + + virtual void SetNbColors(int theNbColors = 16); + virtual int GetNbColors(); + +public: + virtual void Init(); + virtual void Build(); + virtual void Update(); + + virtual VISU_LookupTable *GetMapperTable(){ return myMapperTable;} + virtual VISU_LookupTable *GetBarTable(){ return myBarTable;} + + virtual void SetMapScale(float theMapScale = 1.0); + virtual float GetMapScale(); + + virtual void GetSourceRange(float theRange[2]); + virtual void SetSourceRange(); + +protected: + typedef vtkDataSet THook; + virtual THook* DoHook(); + + VISU_LookupTable *myMapperTable, *myBarTable; + VISU_FieldTransform *myFieldTransform; + VISU_Extractor* myExtractor; +}; + +#endif diff --git a/src/PIPELINE/VISU_StreamLinesPL.cxx b/src/PIPELINE/VISU_StreamLinesPL.cxx new file mode 100644 index 00000000..fabf6993 --- /dev/null +++ b/src/PIPELINE/VISU_StreamLinesPL.cxx @@ -0,0 +1,260 @@ +// 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 +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_StreamLinesPL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "VISU_UsedPointsFilter.hxx" +#include "SALOME_GeometryFilter.h" + +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +static float EPS = 1.0e-20; +int VISU_StreamLinesPL::myMaxIncrementMemorySize = 64; + +void SetStreamerSource(vtkStreamer *theStreamer, vtkPointSet* theDataSet, float thePercents){ + theDataSet->Update(); + VISU_UsedPointsFilter* anUsedPointsFilter = VISU_UsedPointsFilter::New(); + anUsedPointsFilter->SetInput(theDataSet); + anUsedPointsFilter->SetPercentsOfUsedPoints(thePercents); + theStreamer->SetSource(anUsedPointsFilter->GetOutput()); + anUsedPointsFilter->Register(theStreamer); + anUsedPointsFilter->Delete(); +} + + +vtkStandardNewMacro(VISU_StreamLinesPL); + +VISU_StreamLinesPL::VISU_StreamLinesPL(){ + myStream = vtkStreamLine::New(); + myGeomFilter = SALOME_GeometryFilter::New(); + mySource = NULL; +} + +VISU_StreamLinesPL::~VISU_StreamLinesPL(){ + myStream->Delete(); + myGeomFilter->Delete(); + SetSource(NULL); +} + +void VISU_StreamLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_DeformedShapePL::ShallowCopy(thePipeLine); + if(VISU_StreamLinesPL *aPipeLine = dynamic_cast(thePipeLine)){ + + //Order of setting of the values are important + SetUsedPoints(aPipeLine->GetUsedPoints()); + SetSource(aPipeLine->GetSource()); + + SetDirection(aPipeLine->GetDirection()); + + //Order of setting of the values are important + SetIntegrationStep(aPipeLine->GetIntegrationStep()); + SetPropagationTime(aPipeLine->GetPropagationTime()); + SetStepLength(aPipeLine->GetStepLength()); + } +} + +void VISU_StreamLinesPL::SetSource(vtkPointSet* theSource){ + if (mySource != NULL) mySource->UnRegister(this); + mySource = theSource; + if (mySource != NULL) mySource->Register(this); + if(myInput && myInput->GetCellData()->GetNumberOfArrays()){ + vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New(); + aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); + aFilter->PassCellDataOn(); + myStream->SetInput(aFilter->GetOutput()); + aFilter->Register(myStream); + aFilter->Delete(); + vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells + centers->SetInput(myFieldTransform->GetUnstructuredGridOutput()); + centers->VertexCellsOn(); + mySource = mySource? mySource: centers->GetOutput(); + SetStreamerSource(myStream,mySource,myPercents); + centers->Register(myStream); + centers->Delete(); + }else{ + myStream->SetInput(myFieldTransform->GetUnstructuredGridOutput()); + mySource = mySource? mySource: myFieldTransform->GetUnstructuredGridOutput(); + SetStreamerSource(myStream,mySource,myPercents); + } + myStream->Modified(); + Modified(); +} + + +float VISU_StreamLinesPL::GetMaxIntegrationStep(vtkPointSet* theDataSet) { + if(!theDataSet) return 0.0; + theDataSet->Update(); + float* aBounds = theDataSet->GetBounds(); + float aMaxSizeY = aBounds[3] - aBounds[2]; + float aMaxSizeZ = aBounds[5] - aBounds[4]; + float aMinMax = aBounds[1] - aBounds[0]; + if (aMinMax < EPS || (aMaxSizeY < aMinMax && aMaxSizeY > EPS)) aMinMax = aMaxSizeY; + if (aMinMax < EPS || (aMaxSizeZ < aMinMax && aMaxSizeZ > EPS)) aMinMax = aMaxSizeZ; + return aMinMax / 2.0; +} + +float VISU_StreamLinesPL::GetMinIntegrationStep(vtkPointSet* theDataSet) { + if(!theDataSet) return 0.0; + float aVolume = 1.0, tmp; + int degree = 0; + theDataSet->Update(); + float* aBounds = theDataSet->GetBounds(); + for(int i = 0, j = 0; i < 3; ++i, j = 2*i){ + float tmp = aBounds[j+1] - aBounds[j]; + if (tmp > EPS ) { + aVolume *= tmp; + degree += 1; + } + } + if (degree < 1) return 0.0; // absolutely empty object + unsigned long aSize = 1024*theDataSet->GetActualMemorySize(); + // we have to use no more, than myMaxIncrementMemorySize*aSize amount of memory + unsigned long aRealSize = GetAvailableMemory(myMaxIncrementMemorySize*aSize); + if(MYDEBUG) cout<<"GetMinIntegrationStep - GetActualMemorysize() = "<Update(); + float* aScalarRange = theDataSet->GetScalarRange(); + return theDataSet->GetLength()/fabs(aScalarRange[1] + aScalarRange[0])*2.0; +} + + +int VISU_StreamLinesPL::GetDirection(){ + return myStream->GetIntegrationDirection(); +} +void VISU_StreamLinesPL::SetDirection(int theDirection){ + myStream->SetIntegrationDirection(theDirection); + Modified(); +} + + +float VISU_StreamLinesPL::GetPropagationTime() { + return myStream->GetMaximumPropagationTime(); +} +void VISU_StreamLinesPL::SetPropagationTime(float theTime) { + if(myStream->GetMaximumPropagationTime() == theTime) return; + myStream->SetMaximumPropagationTime(theTime); + Modified(); +} + + +float VISU_StreamLinesPL::GetIntegrationStep(){ + return myStream->GetIntegrationStepLength(); +} +float VISU_StreamLinesPL::SetIntegrationStep(float theStep){ + if(myStream->GetIntegrationStepLength() == theStep) return theStep; + myExtractor->Update(); + vtkPointSet* aDataSet = GetSource(); + aDataSet->Update(); + float anIntegrationStep = theStep; + float aMinIntegrationStep = GetMinIntegrationStep(aDataSet); + float aMaxIntegrationStep = GetMaxIntegrationStep(aDataSet); + if(aMinIntegrationStep < anIntegrationStep && anIntegrationStep < aMaxIntegrationStep){ + myStream->SetIntegrationStepLength(theStep); + Modified(); + }else{ + anIntegrationStep = aMaxIntegrationStep / 10.0; + float aMinMax = aDataSet->GetLength()/myInput->GetNumberOfPoints(); + if(aMinMax > anIntegrationStep) + anIntegrationStep = (anIntegrationStep*9.0+aMinMax)/10.0; + if(aMinIntegrationStep > anIntegrationStep) + anIntegrationStep = aMinIntegrationStep; + } + return anIntegrationStep; +} + + +float VISU_StreamLinesPL::GetStepLength() { + return myStream->GetStepLength(); +} +float VISU_StreamLinesPL::GetMinStepLength(float theIntegrationStep){ + return theIntegrationStep*2.0; +} +float VISU_StreamLinesPL::GetMaxStepLength(float thePropagationTime){ + return thePropagationTime/100.0; +} +float VISU_StreamLinesPL::CorrectStepLength(float theStep, float theIntegrationStep, float thePropagationTime){ + float aMinStep = GetMinStepLength(theIntegrationStep); + if(theStep < aMinStep) theStep = aMinStep; + float aMaxStep = GetMaxStepLength(thePropagationTime); + if(theStep > aMaxStep) theStep = aMaxStep; + return theStep; +} +float VISU_StreamLinesPL::SetStepLength(float theStep){ + if(myStream->GetStepLength() == theStep) return theStep; + float aStepLength = CorrectStepLength(theStep,GetIntegrationStep(),GetPropagationTime()); + if(aStepLength == theStep){ + myStream->SetStepLength(theStep); + Modified(); + } + return aStepLength; +} + + +void VISU_StreamLinesPL::Init(){ + VISU_ScalarMapPL::Init(); + + SetDirection(VTK_INTEGRATE_BOTH_DIRECTIONS); + vtkPointSet* aDataSet = myExtractor->GetOutput(); + //Order of setting of the values are important + myPercents = 0.3; + SetSource(NULL); + + SetIntegrationStep(SetIntegrationStep(GetMaxIntegrationStep(aDataSet)/10.0)); + SetPropagationTime(GetBasePropagationTime(aDataSet)); + SetStepLength(SetStepLength(GetPropagationTime()/20.)); +} + +VISU_ScalarMapPL::THook* VISU_StreamLinesPL::DoHook(){ + SetSource(NULL); + myInput->Update(); + float *aBounds = myInput->GetBounds(); + myGeomFilter->SetExtent(aBounds); + myGeomFilter->ExtentClippingOn(); + myGeomFilter->SetInput(myStream->GetOutput()); + return myGeomFilter->GetOutput(); +} + +void VISU_StreamLinesPL::Update(){ + VISU_ScalarMapPL::Update(); +} + +void VISU_StreamLinesPL::SetMapScale(float theMapScale){ + VISU_ScalarMapPL::SetMapScale(theMapScale); +} diff --git a/src/PIPELINE/VISU_StreamLinesPL.hxx b/src/PIPELINE/VISU_StreamLinesPL.hxx new file mode 100644 index 00000000..ab56a041 --- /dev/null +++ b/src/PIPELINE/VISU_StreamLinesPL.hxx @@ -0,0 +1,93 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_StreamLinesPL_HeaderFile +#define VISU_StreamLinesPL_HeaderFile + +#include "VISU_DeformedShapePL.hxx" +#include + +class vtkPointSet; +class SALOME_GeometryFilter; + +class VISU_StreamLinesPL : public VISU_DeformedShapePL{ +protected: + VISU_StreamLinesPL(); + VISU_StreamLinesPL(const VISU_StreamLinesPL&); +public: + vtkTypeMacro(VISU_StreamLinesPL,VISU_DeformedShapePL); + static VISU_StreamLinesPL* New(); + virtual ~VISU_StreamLinesPL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual int GetDirection(); + virtual void SetDirection(int theDirection); + + virtual float GetStepLength(); + virtual float SetStepLength(float theStep); + + virtual float GetPropagationTime(); + virtual void SetPropagationTime(float theTime); + + virtual float GetIntegrationStep(); + virtual float SetIntegrationStep(float theStep); + + virtual void SetSource(vtkPointSet* theSource); + virtual vtkPointSet* GetSource() {return mySource;} + + virtual void SetUsedPoints(float thePercents) { myPercents = thePercents;} + virtual float GetUsedPoints() { return myPercents;} + + virtual float GetMaxIntegrationStep(){ return GetMaxIntegrationStep(GetSource());} + virtual float GetMinIntegrationStep(){ return GetMinIntegrationStep(GetSource());} + virtual float GetBasePropagationTime(){ return GetBasePropagationTime(GetSource());}; + +public: + virtual THook* DoHook(); + virtual void Init(); + virtual void Update(); + virtual void SetMapScale(float theMapScale = 1.0); + +public: + static int myMaxIncrementMemorySize; + + static float GetMinStepLength(float theIntegrationStep); + static float GetMaxStepLength(float thePropagationTime); + static float CorrectStepLength(float theStep, float theIntegrationStep, float thePropagationTime); + + static float GetMaxIntegrationStep(vtkPointSet* theDataSet); + static float GetMinIntegrationStep(vtkPointSet* theDataSet); + static float GetBasePropagationTime(vtkPointSet* theDataSet); + +protected: + vtkStreamLine* myStream; + vtkPointSet* mySource; + SALOME_GeometryFilter *myGeomFilter; + float myPercents; +}; + + +#endif diff --git a/src/PIPELINE/VISU_UsedPointsFilter.cxx b/src/PIPELINE/VISU_UsedPointsFilter.cxx new file mode 100644 index 00000000..9e2e2612 --- /dev/null +++ b/src/PIPELINE/VISU_UsedPointsFilter.cxx @@ -0,0 +1,78 @@ +// 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 +// +// +// File: VISU_StreamLinesPL.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_UsedPointsFilter.hxx" + +#include +#include +#include +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +vtkStandardNewMacro(VISU_UsedPointsFilter); + +VISU_UsedPointsFilter::VISU_UsedPointsFilter(){ + PercentsOfUsedPoints = 0.1; +} + +VISU_UsedPointsFilter::~VISU_UsedPointsFilter(){} + +void VISU_UsedPointsFilter::Execute(){ + vtkPointSet *anInput = this->GetInput(), *anOutput = this->GetOutput(); + anOutput->GetPointData()->CopyAllOff(); + anOutput->GetCellData()->CopyAllOff(); + vtkPoints* aPoints = vtkPoints::New(); + vtkIdType aCellSize = anInput->GetMaxCellSize(); + vtkIdList *anIdList = vtkIdList::New(); + vtkIdType iEnd = anInput->GetNumberOfPoints(); + for(vtkIdType i = 0; i < iEnd; i++){ + anInput->GetPointCells(i,anIdList); + if(anIdList->GetNumberOfIds() > 0) + aPoints->InsertNextPoint(anInput->GetPoint(i)); + } + static float EPS = 1E-5; + if(PercentsOfUsedPoints < EPS){ + anOutput->SetPoints(aPoints); + }else{ + vtkPoints* aNewPoints = vtkPoints::New(); + iEnd = aPoints->GetNumberOfPoints(); + vtkIdType anOffset = vtkIdType(1.0/PercentsOfUsedPoints); + if(anOffset < 1) anOffset = 1; + for(vtkIdType i = 0; i < iEnd; i += anOffset) + aNewPoints->InsertNextPoint(aPoints->GetPoint(i)); + anOutput->SetPoints(aNewPoints); + aNewPoints->Delete(); + } + aPoints->Delete(); +} diff --git a/src/PIPELINE/VISU_UsedPointsFilter.hxx b/src/PIPELINE/VISU_UsedPointsFilter.hxx new file mode 100644 index 00000000..273ab3d2 --- /dev/null +++ b/src/PIPELINE/VISU_UsedPointsFilter.hxx @@ -0,0 +1,49 @@ +// 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 +// +// +// File: VISU_UsedPointsFilter.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_UsedPointsFilter_HeaderFile +#define VISU_UsedPointsFilter_HeaderFile + +#include + +class VISU_UsedPointsFilter : public vtkPointSetToPointSetFilter{ +protected: + VISU_UsedPointsFilter(); + VISU_UsedPointsFilter(const VISU_UsedPointsFilter&); + + virtual void Execute(); + float PercentsOfUsedPoints; + +public: + vtkTypeMacro(VISU_UsedPointsFilter,vtkPointSetToPointSetFilter); + static VISU_UsedPointsFilter* New(); + virtual ~VISU_UsedPointsFilter(); + + vtkSetMacro(PercentsOfUsedPoints,float); + vtkGetMacro(PercentsOfUsedPoints,float); +}; + +#endif diff --git a/src/PIPELINE/VISU_VectorsPL.cxx b/src/PIPELINE/VISU_VectorsPL.cxx new file mode 100644 index 00000000..786f7ec0 --- /dev/null +++ b/src/PIPELINE/VISU_VectorsPL.cxx @@ -0,0 +1,151 @@ +// 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 +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_VectorsPL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "SALOME_TransformFilter.h" +#include "SALOME_Transform.h" + +#include +#include +#include +#include + +vtkStandardNewMacro(VISU_VectorsPL); + +VISU_VectorsPL::VISU_VectorsPL(){ + myGlyph = vtkGlyph3D::New(); + myTransformFilter = SALOME_TransformFilter::New(); +} + +VISU_VectorsPL::~VISU_VectorsPL(){ + myGlyph->Delete(); + myTransformFilter->Delete(); +} + +void VISU_VectorsPL::ShallowCopy(VISU_PipeLine *thePipeLine){ + VISU_DeformedShapePL::ShallowCopy(thePipeLine); + if(VISU_VectorsPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetGlyphType(aPipeLine->GetGlyphType()); + SetGlyphPos(aPipeLine->GetGlyphPos()); + } +} + + +void VISU_VectorsPL::SetTransform(SALOME_Transform* theTransform){ + myFieldTransform->SetSpaceTransform(theTransform); + myTransformFilter->SetTransform(theTransform); + myTransformFilter->Modified(); +} +SALOME_Transform* VISU_VectorsPL::GetTransform(){ + return myFieldTransform->GetSpaceTransform(); +} + + +void VISU_VectorsPL::SetScale(float theScale) { + if(myScaleFactor == theScale) return; + myScaleFactor = theScale; + myGlyph->SetScaleFactor(myScaleFactor); + Modified(); +} +float VISU_VectorsPL::GetScale() { + return myGlyph->GetScaleFactor(); +} + + +void VISU_VectorsPL::Init(){ + VISU_DeformedShapePL::Init(); + + myTypeGlyph = ARROW; + myPosGlyph = TAIL; +} + + +VISU_ScalarMapPL::THook* VISU_VectorsPL::DoHook(){ + VISU::ToCellCenters(myTransformFilter,myInput,myFieldTransform); + myGlyph->SetInput(myTransformFilter->GetOutput()); + myGlyph->SetVectorModeToUseVector(); + myGlyph->SetScaleModeToScaleByVector(); + myGlyph->SetColorModeToColorByScalar(); + return myGlyph->GetOutput(); +} + + +void VISU_VectorsPL::Update(){ + switch (myTypeGlyph) { + case ARROW: { + vtkGlyphSource2D *aGlyphSource = vtkGlyphSource2D::New(); + aGlyphSource->SetGlyphTypeToArrow(); + aGlyphSource->SetFilled(0); + if(myPosGlyph == TAIL) + aGlyphSource->SetCenter(0.5, 0.0, 0.0); + else if(myPosGlyph == HEAD) + aGlyphSource->SetCenter(-0.5, 0.0, 0.0); + myGlyph->SetSource(aGlyphSource->GetOutput()); + aGlyphSource->Register(myGlyph); + aGlyphSource->Delete(); + } + break; + case CONE2: + case CONE6: { + vtkConeSource *aGlyphSource = vtkConeSource::New(); //by default + if (myTypeGlyph == CONE2) + aGlyphSource->SetResolution(3); + else + aGlyphSource->SetResolution(7); + aGlyphSource->SetHeight(1.0); + aGlyphSource->SetRadius(.1); + + if(myPosGlyph == TAIL) + aGlyphSource->SetCenter(0.5, 0.0, 0.0); + else if(myPosGlyph == HEAD) + aGlyphSource->SetCenter(-0.5, 0.0, 0.0); + + myGlyph->SetSource(aGlyphSource->GetOutput()); + aGlyphSource->Register(myGlyph); + aGlyphSource->Delete(); + } + break; + case NONE: + default: { + vtkLineSource *aGlyphSource = vtkLineSource::New(); + myGlyph->SetSource(aGlyphSource->GetOutput()); + aGlyphSource->Register(myGlyph); + aGlyphSource->Delete(); + } + } + + VISU_DeformedShapePL::Update(); +} + + +void VISU_VectorsPL::SetMapScale(float theMapScale){ + VISU_ScalarMapPL::SetMapScale(theMapScale); + + myGlyph->SetScaleFactor(myScaleFactor*theMapScale); + myGlyph->Modified(); +} diff --git a/src/PIPELINE/VISU_VectorsPL.hxx b/src/PIPELINE/VISU_VectorsPL.hxx new file mode 100644 index 00000000..81a1f33b --- /dev/null +++ b/src/PIPELINE/VISU_VectorsPL.hxx @@ -0,0 +1,75 @@ +// 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 +// +// +// File: VISU_PipeLine.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_VectorsPL_HeaderFile +#define VISU_VectorsPL_HeaderFile + +#include "VISU_DeformedShapePL.hxx" + +class SALOME_TransformFilter; +class SALOME_Transform; +class vtkGlyph3D; + +class VISU_VectorsPL : public VISU_DeformedShapePL{ +protected: + VISU_VectorsPL(); + VISU_VectorsPL(const VISU_VectorsPL&); +public: + vtkTypeMacro(VISU_VectorsPL,VISU_DeformedShapePL); + static VISU_VectorsPL* New(); + virtual ~VISU_VectorsPL(); + virtual void ShallowCopy(VISU_PipeLine *thePipeLine); + + virtual void SetScale(float theScale); + virtual float GetScale(); + + enum GlyphType{ ARROW, CONE2, CONE6, NONE}; + virtual void SetGlyphType(GlyphType theType) { myTypeGlyph = theType;} + virtual GlyphType GetGlyphType() { return myTypeGlyph;} + + enum GlyphPos{ CENTER, TAIL,HEAD}; + virtual void SetGlyphPos(GlyphPos thePos) { myPosGlyph = thePos;} + virtual GlyphPos GetGlyphPos() { return myPosGlyph;} + +public: + virtual THook* DoHook(); + virtual void Init(); + virtual void Update(); + + virtual void SetTransform(SALOME_Transform* theTransform); + virtual SALOME_Transform* GetTransform(); + + virtual void SetMapScale(float theMapScale = 1.0); + +protected: + GlyphType myTypeGlyph; + GlyphPos myPosGlyph; + vtkGlyph3D *myGlyph; + SALOME_TransformFilter *myTransformFilter; +}; + + +#endif diff --git a/src/VISUGUI/VisuGUI_FileDlg.cxx b/src/VISUGUI/VisuGUI_FileDlg.cxx new file mode 100644 index 00000000..87672a24 --- /dev/null +++ b/src/VISUGUI/VisuGUI_FileDlg.cxx @@ -0,0 +1,106 @@ +// SALOME SALOMEGUI : GUI of VISU module +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : QAD_FileDlg.cxx +// Author : +// Module : SALOME +// $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx + + +#include +#include +#include +#include +#include "QAD_Config.h" +#include "VisuGUI_FileDlg.h" + +using namespace std; + +bool VisuGUI_FileDlg::IsBuild = false; + +/*! +Constructor +*/ +VisuGUI_FileDlg::VisuGUI_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal ) : + QAD_FileDlg( parent, open, showQuickDir, modal ) +{ + myCBuildAll = new QCheckBox( tr("Full loading for current file"), this ); + QLabel* label = new QLabel("", this); + label->setMaximumWidth(0); + QPushButton* pb = new QPushButton(this); + pb->setMaximumWidth(0); + addWidgets( label, myCBuildAll, pb ); + QString aIsBuild = QAD_CONFIG->getSetting("Visu:BuildResult"); + if (aIsBuild.isEmpty()? 0 : aIsBuild.toInt()) myCBuildAll->setChecked(true); +} + +/*! + Destructor +*/ +VisuGUI_FileDlg::~VisuGUI_FileDlg() +{ +} + +/*! + Processes selection : tries to set given path or filename as selection +*/ +bool VisuGUI_FileDlg::processPath( const QString& path ) +{ + if ( !path.isNull() ) { + QFileInfo fi( path ); + if ( fi.exists() ) { + if ( fi.isFile() ) + setSelection( path ); + else if ( fi.isDir() ) + setDir( path ); + return true; + } + else { + if ( QFileInfo( fi.dirPath() ).exists() ) { + setDir( fi.dirPath() ); + return true; + } + } + } + return false; +} + +/*! + Returns the file name for Open/Save [ static ] +*/ +QString VisuGUI_FileDlg::getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + bool open, + bool showQuickDir, + QAD_FileValidator* validator ) +{ + VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true ); + if ( !caption.isEmpty() ) + fd->setCaption( caption ); + if ( !initial.isEmpty() ) { + fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug + } + fd->setFilters( filters ); + if ( validator ) + fd->setValidator( validator ); + fd->exec(); + QString filename = fd->selectedFile(); + + VisuGUI_FileDlg::IsBuild = fd->IsChecked(); + + delete fd; + qApp->processEvents(); + + return filename; +} + +bool VisuGUI_FileDlg::IsChecked() +{ + return myCBuildAll->isChecked(); +} + diff --git a/src/VISUGUI/VisuGUI_FileDlg.h b/src/VISUGUI/VisuGUI_FileDlg.h new file mode 100644 index 00000000..d3e2e59e --- /dev/null +++ b/src/VISUGUI/VisuGUI_FileDlg.h @@ -0,0 +1,43 @@ +// SALOME SALOMEGUI : GUI of VISU module +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : QAD_FileDlg.h +// Author : +// Module : SALOME +// $Header: /dn05/salome/CVS/SALOME_ROOT/VISU/src/VISUGUI/VisuGUI_FileDlg.h + +#ifndef VISU_FILEDIALOG_H +#define VISU_FILEDIALOG_H + +#include "QAD_FileDlg.h" +#include + +class VisuGUI_FileDlg : public QAD_FileDlg +{ + Q_OBJECT + +public: + VisuGUI_FileDlg( QWidget* parent, bool open, bool showQuickDir = true, bool modal = true ); + ~VisuGUI_FileDlg(); + +public: + static bool IsBuild; + static QString getFileName( QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + bool open, + bool showQuickDir = true, + QAD_FileValidator* validator = 0); + +private: + QCheckBox* myCBuildAll; + bool IsChecked(); + bool processPath( const QString& path ); + +}; + +#endif diff --git a/src/VISU_I/VISUConfig.cc b/src/VISU_I/VISUConfig.cc new file mode 100644 index 00000000..e23f6210 --- /dev/null +++ b/src/VISU_I/VISUConfig.cc @@ -0,0 +1,299 @@ +// 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 +// +// +// File : VISUConfig.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISUConfig.hh" + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +namespace VISU{ + //=========================================================================== + QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex; + CORBA::ORB_var Base_i::myOrb; + PortableServer::POA_var Base_i::myPOA; + SALOME_NamingService* Base_i::myNamingService; + SALOME_LifeCycleCORBA* Base_i::myEnginesLifeCycle; + VISU_Gen_i* Base_i::myVisuGenImpl; + Base_i::~Base_i() {} + char* Base_i::GetID(){ + CORBA::Object_ptr anObject = _this(); + CORBA::String_var aString = myOrb->object_to_string(anObject); + return aString._retn(); + //return CORBA::string_dup(myOrb->object_to_string(_this())); + } + + //=========================================================================== + static int mySCnt = 0; + static int myQCnt = 0; + static int myIsBatchMode = 0; + + Mutex::Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay) : + myQApp(theQApp), isQAppLocked(theQApp->locked()), myDelay(theDelay), + myMutex(theMutex), isSessionLocked(theMutex->locked()) + { + if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt)); + if(!myIsBatchMode && isQAppLocked) myIsBatchMode++; + if(!isSessionLocked && !mySCnt) { myMutex->lock();}; mySCnt++; + if(!isQAppLocked && !myQCnt) { + myQApp->lock(); + myQApp->syncX(); + }; + myQCnt++; + } + Mutex::~Mutex(){ + myQCnt--; + if(!isQAppLocked && !myQCnt) { + myQApp->flushX(); + //if(myDelay > 0) + myQApp->processEvents(myDelay+3); + myQApp->unlock(); + } + mySCnt--; if(!isSessionLocked && !mySCnt) { myMutex->unlock();} + if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt)); + } + + + //=========================================================================== + static Storable::TCallbackMap VisuStoreMap; + string Storable::ToString(){ + ostringstream strOut; + Storable::DataToStream( strOut, "myComment", GetComment() ); + ToStream(strOut); + strOut< aRet(strOut.str()); + return strOut.str(); + } + + void Storable::Registry(const char* theComment, TStorableEngine theEngine) + throw(std::logic_error&) + { + if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){ + if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!"); + throw std::logic_error("Storable::Registry >> dupliacte registring !!!"); + } + } + + void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){ + if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<GetID()); + //aMap.insert(TRestoringMap::value_type("ResultID", strdup(aResultID))); + bool isExist; + QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist); + if ( isExist ) { + TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1()); + if(MYDEBUG) MESSAGE("Storable::Create - "<second)(theSObject,thePrefix,aMap); + } + }catch(std::logic_error& exc){ + INFOS("Follow exception was accured :\n"<> there is no value for "<> there is no value for ") + theArg); + static QString BAD_VALUE("NULL"); + return BAD_VALUE; + } + if(isFind != NULL) *isFind = true; + return i->second; + } + + + //=========================================================================== + PortableServer::Servant GetServant(CORBA::Object_ptr theObject){ + if(CORBA::is_nil(theObject)) return NULL; + try{ + PortableServer::POA_ptr aPOA = Base_i::GetPOA(); + return aPOA->reference_to_servant(theObject); + } catch (...) { + INFOS("GetServant - Unknown exception was accured!"); + return NULL; + } + } + + + //=========================================================================== + CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){ + SALOMEDS::GenericAttribute_var anAttr; + CORBA::Object_var anObj; + try{ + if(theSObject->FindAttribute(anAttr, "AttributeIOR")){ + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var aValue = anIOR->Value(); + CORBA::ORB_ptr anORB = Base_i::GetORB(); + if(strcmp(aValue,"") != 0) + anObj = anORB->string_to_object(aValue); + } + }catch(...){ + INFOS("SObjectToObject - Unknown exception was accured!"); + } + return anObj; + } + + + //=========================================================================== + string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry, + const char* theComment, int IsAllLevels) + { + SALOMEDS::ChildIterator_var anIter = + theStudyDocument->NewChildIterator(theStudyDocument->FindObjectID(theStartEntry)); + anIter->InitEx(IsAllLevels); + SALOMEDS::SObject_var aFieldSO; + for(;anIter->More();anIter->Next()) { + SALOMEDS::GenericAttribute_var anAttr; + if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) { + SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); + CORBA::String_var aString = aCmnt->Value(); + string aValue(aString); + if (aValue == theComment) { + aFieldSO = anIter->Value(); + aString = aFieldSO->GetID(); + aValue = aString; + return aValue; + } + } + } + return ""; + } + //=========================================================================== + string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument, + const char* theFatherEntry, const char* theRefFatherEntry, + const char* theIOR, const char* theName, + const char* thePersistentRef, const char* theComment, + CORBA::Boolean theCreateNew) + { + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); + SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry); + SALOMEDS::SObject_var newObj; + if (theCreateNew) newObj = aStudyBuilder->NewObject(aFather); + else newObj = aFather; + SALOMEDS::GenericAttribute_var anAttr; + if(strcmp(theIOR,"") != 0){ + anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + anIOR->SetValue(theIOR); + } + if(strcmp(theName,"") != 0){ + anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue(theName); + } + if(strcmp(thePersistentRef,"") != 0){ + anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef"); + SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr); + aPRef->SetValue(thePersistentRef); + } + if(strcmp(theComment,"") != 0){ + anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment"); + SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); + aCmnt->SetValue(theComment); + INFOS("CreateAttributes - Comment = "<FindObjectID(theRefFatherEntry); + SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather); + aStudyBuilder->Addreference(anObj,newObj); + } + CORBA::String_var anEntry = newObj->GetID(); + string aRet(anEntry); + if(0 && MYDEBUG) MESSAGE("CreateAttributes - anEntry = "< + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +int VISU::CutLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); +} + +int VISU::CutLines_i::myNbPresent = 0; +QString VISU::CutLines_i::GenerateName() { return VISU::GenerateName("CutLines",myNbPresent++);} + +const string VISU::CutLines_i::myComment = "CUTLINES"; +const char* VISU::CutLines_i::GetComment() const { return myComment.c_str();} + +VISU::CutLines_i::CutLines_i(Result_i* theResult, bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy) +{ + myCutLinesPL = NULL; +} + +void VISU::CutLines_i::Destroy(){ + ScalarMap_i::Destroy(); +} + +void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin){ + CutLines_i* aCutLines = const_cast(theOrigin); + VISU::ScalarMap_i::SameAs(theOrigin); + + //SetNbLines(aCutLines->GetNbLines()); + //SetDisplacement(aCutLines->GetDisplacement()); + //SetDisplacement2(aCutLines->GetDisplacement2()); + //SetOrientationType(aCutLines->GetOrientationType()); + //SetOrientationType2(aCutLines->GetOrientationType2()); + //SetRotateX(aCutLines->GetRotateX()); + //SetRotateY(aCutLines->GetRotateY()); + //SetRotateX2(aCutLines->GetRotateX2()); + //SetRotateY2(aCutLines->GetRotateY2()); +} + +VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + +VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + ScalarMap_i::Restore(theMap); + SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt()); + SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble()); + SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble()); + SetOrientationType(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt())); + SetOrientationType(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt())); + SetRotateX(VISU::Storable::FindValue(theMap,"aRot[0][0]").toDouble()); + SetRotateY(VISU::Storable::FindValue(theMap,"aRot[0][1]").toDouble()); + SetRotateX2(VISU::Storable::FindValue(theMap,"aRot[1][0]").toDouble()); + SetRotateY2(VISU::Storable::FindValue(theMap,"aRot[1][1]").toDouble()); + + return Build(true); +} + +void VISU::CutLines_i::ToStream(std::ostringstream& theStr){ + ScalarMap_i::ToStream(theStr); + Storable::DataToStream( theStr, "myNbLines", int(GetNbLines()) ); + Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() ); + Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() ); + Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) ); + Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) ); + Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() ); + Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() ); + Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() ); + Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() ); +} + +VISU::Storable* VISU::CutLines_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::CutLines_i* pResent = new VISU::CutLines_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::CutLines_i::~CutLines_i(){ + if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()"); +} + + +void VISU::CutLines_i::SetOrientationType(VISU::CutPlanes::Orientation theOrient){ + myCutLinesPL->SetPlaneOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient)); +} +void VISU::CutLines_i::SetOrientationType2(VISU::CutPlanes::Orientation theOrient){ + myCutLinesPL->SetPlaneOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),1); +} + +VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType() { + return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation()); +} +VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType2() { + return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1)); +} + + +void VISU::CutLines_i::SetDisplacement(CORBA::Double theDisp) { + myCutLinesPL->SetDisplacement(theDisp); +} +void VISU::CutLines_i::SetDisplacement2(CORBA::Double theDisp) { + myCutLinesPL->SetDisplacement(theDisp,1); +} + +CORBA::Double VISU::CutLines_i::GetDisplacement() { + return myCutLinesPL->GetDisplacement(); +} +CORBA::Double VISU::CutLines_i::GetDisplacement2() { + return myCutLinesPL->GetDisplacement(1); +} + + +void VISU::CutLines_i::SetBasePlanePosition(CORBA::Double thePlanePosition){ + myCutLinesPL->SetPosition(thePlanePosition); +} + +CORBA::Double VISU::CutLines_i::GetBasePlanePosition(){ + return myCutLinesPL->GetPosition(); +} + +void VISU::CutLines_i::SetLinePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){ + myCutLinesPL->SetPartPosition(thePlaneNumber,thePlanePosition); +} + +CORBA::Double VISU::CutLines_i::GetLinePosition(CORBA::Long thePlaneNumber){ + return myCutLinesPL->GetPartPosition(thePlaneNumber,1); +} + + +void VISU::CutLines_i::SetDefault(){ + myCutLinesPL->SetDefault(); +} + +CORBA::Boolean VISU::CutLines_i::IsDefault(){ + return myCutLinesPL->IsDefault(); +} + +void VISU::CutLines_i::SetDefaultPosition(CORBA::Long thePlaneNumber){ + myCutLinesPL->SetPartDefault(thePlaneNumber); +} + +CORBA::Boolean VISU::CutLines_i::IsDefaultPosition(CORBA::Long thePlaneNumber){ + return myCutLinesPL->IsPartDefault(thePlaneNumber); +} + + +void VISU::CutLines_i::SetNbLines(CORBA::Long theNb) { + myCutLinesPL->SetNbParts(theNb); +} +CORBA::Long VISU::CutLines_i::GetNbLines() { + return myCutLinesPL->GetNbParts(); +} + + +void VISU::CutLines_i::SetRotateX(CORBA::Double theAngle){ + myCutLinesPL->SetRotateX(theAngle); +} +CORBA::Double VISU::CutLines_i::GetRotateX(){ + return myCutLinesPL->GetRotateX(); +} + +void VISU::CutLines_i::SetRotateY(CORBA::Double theAngle){ + myCutLinesPL->SetRotateY(theAngle); +} +CORBA::Double VISU::CutLines_i::GetRotateY(){ + return myCutLinesPL->GetRotateY(); +} + +void VISU::CutLines_i::SetRotateX2(CORBA::Double theAngle){ + myCutLinesPL->SetRotateX(theAngle,1); +} +CORBA::Double VISU::CutLines_i::GetRotateX2(){ + return myCutLinesPL->GetRotateX(1); +} + +void VISU::CutLines_i::SetRotateY2(CORBA::Double theAngle){ + myCutLinesPL->SetRotateY(theAngle,1); +} +CORBA::Double VISU::CutLines_i::GetRotateY2(){ + return myCutLinesPL->GetRotateY(1); +} + +void VISU::CutLines_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_CutLinesPL::New(); + myCutLinesPL = dynamic_cast(myPipeLine); + + ScalarMap_i::DoHook(); +} + +void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){ + + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal"); + Update(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder(); + anAttr = aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributeTableOfReal"); + SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr); + + typedef set TLineCont; + typedef map TXMap; + typedef map TXYMap; + typedef vector TCurveVect; + + const VISU::TField::TValField& aValField = myField->myValField; + const VISU::TField::TValForTime& aValForTime = aValField.find((int)myIteration)->second; + const VISU::TField::TTime& aTime = aValForTime.myTime; + QString aTitle; + //aTitle.sprintf("%s %s",myTitle.c_str(),aTime.second.c_str()); + aTitle.sprintf("%s",myTitle.c_str()); + aTitle = aTitle.simplifyWhiteSpace(); + aTableOfReal->SetTitle(aTitle.latin1()); + + int iLineEnd = myCutLinesPL->GetAppendPolyData()->GetNumberOfInputs(); + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<GetDirLn(); + const float *aBasePnt = myCutLinesPL->GetBasePnt(); + const float *aBoundPrjLn = myCutLinesPL->GetBoundPrjLn(); + for(int iLine = 0; iLine < iLineEnd; iLine++){ + vtkDataSet *aDataSet = myCutLinesPL->GetAppendPolyData()->GetInput(iLine); + aDataSet->Update(); + int aNbPoints = aDataSet->GetNumberOfPoints(); + vtkPointData *aPointData = aDataSet->GetPointData(); + vtkDataArray *aScalars = aPointData->GetScalars(); + vtkCellDataToPointData *aFilter = NULL; + if(!aScalars) { + aFilter = vtkCellDataToPointData::New(); + aFilter->SetInput(aDataSet); + aFilter->PassCellDataOn(); + aDataSet = aFilter->GetOutput(); + aDataSet->Update(); + } + aPointData = aDataSet->GetPointData(); + aScalars = aPointData->GetScalars(); + if(!aScalars) continue; + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "< 2){ + TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()}; + aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second; + aXMap[aXYMapIter[0]->first].insert(iLine); + for(; aXYMapIter[1] != aXYMap.end(); aXYMapIter[0]++, aXYMapIter[1]++){ + float aY[3] = {aXYMapIter[0]->second, aXYMapIter[1]->second, 0.0}; + aY[2] = (aY[0] + aY[1])/2.0; + float aX[3] = {aXYMapIter[0]->first, aXYMapIter[1]->first, 0.0}; + aX[2] = (aX[0] + aX[1])/2.0; + aNewXYMap[aX[2]] = aY[2]; + aXMap[aX[2]].insert(iLine); + } + aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second; + aXMap[aXYMapIter[0]->first].insert(iLine); + aXYMap = aNewXYMap; + }else{ + TXYMap::const_iterator aXYMapIter = aXYMap.begin(); + for(; aXYMapIter != aXYMap.end(); aXYMapIter++){ + aXMap[aXYMapIter->first].insert(iLine); + } + } + } + QString aString; + aTableOfReal->SetNbColumns(aXMap.size()); + TXMap::const_iterator aXMapIter = aXMap.begin(); + for(long i = 0; aXMapIter != aXMap.end(); aXMapIter++, i++){ + float aDist = aXMapIter->first; + aTableOfReal->PutValue(aDist,1,i+1); + aString.sprintf("%d",i); + aTableOfReal->SetColumnTitle(i+1,aString.latin1()); + const TLineCont& aLineCont = aXMapIter->second; + long jEnd = aLineCont.size(); + if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<myUnitNames[0].c_str(); + int aScalarMode = myCutLinesPL->GetScalarMode(); + if(aScalarMode != 0) + aUnitName = myField->myUnitNames[aScalarMode-1].c_str(); + aUnitName = aUnitName.simplifyWhiteSpace(); + for(long i = 0; aLineContIter != aLineCont.end(); aLineContIter++, i++){ + long iLine = *aLineContIter; + aString.sprintf("Y%d",iLine); + aTableOfReal->SetRowTitle(i+2,aString.latin1()); + aTableOfReal->SetRowUnit(i+2,aUnitName.latin1()); + } +} diff --git a/src/VISU_I/VISU_CutLines_i.hh b/src/VISU_I/VISU_CutLines_i.hh new file mode 100644 index 00000000..3ebd8331 --- /dev/null +++ b/src/VISU_I/VISU_CutLines_i.hh @@ -0,0 +1,115 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_CutLines_i_HeaderFile +#define VISU_CutLines_i_HeaderFile + +#include "VISU_ScalarMap_i.hh" + +class VISU_CutLinesPL; + +namespace VISU{ + class CutLines_i : public virtual POA_VISU::CutLines, + public virtual ScalarMap_i + { + static int myNbPresent; + CutLines_i(); + CutLines_i(const CutLines_i&); + public: + CutLines_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const CutLines_i* theOrigin); + virtual ~CutLines_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TCUTLINES;}; + + virtual void SetOrientationType(VISU::CutPlanes::Orientation theOrient); + virtual VISU::CutPlanes::Orientation GetOrientationType(); + + virtual void SetOrientationType2(VISU::CutPlanes::Orientation theOrient); + virtual VISU::CutPlanes::Orientation GetOrientationType2(); + + virtual void SetDisplacement(CORBA::Double theDisp); + virtual CORBA::Double GetDisplacement(); + + virtual void SetDisplacement2(CORBA::Double theDisp); + virtual CORBA::Double GetDisplacement2(); + + virtual void SetBasePlanePosition(CORBA::Double thePlanePosition); + virtual CORBA::Double GetBasePlanePosition(); + + virtual void SetLinePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition); + virtual CORBA::Double GetLinePosition(CORBA::Long thePlaneNumber); + + virtual void SetDefault(); + virtual CORBA::Boolean IsDefault(); + + virtual void SetDefaultPosition(CORBA::Long thePlaneNumber); + virtual CORBA::Boolean IsDefaultPosition(CORBA::Long thePlaneNumber); + + virtual void SetNbLines(CORBA::Long theNb); + virtual CORBA::Long GetNbLines(); + + virtual void SetRotateX(CORBA::Double theAngle); + virtual CORBA::Double GetRotateX(); + virtual void SetRotateY(CORBA::Double theAngle); + virtual CORBA::Double GetRotateY(); + + virtual void SetRotateX2(CORBA::Double theAngle); + virtual CORBA::Double GetRotateX2(); + virtual void SetRotateY2(CORBA::Double theAngle); + virtual CORBA::Double GetRotateY2(); + + typedef VISU::CutLines TInterface; + VISU_CutLinesPL* GetCutLinesPL(){ return myCutLinesPL;} + + protected: + virtual void DoHook(); + + VISU_CutLinesPL *myCutLinesPL; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + void BuildTableOfReal(SALOMEDS::SObject_ptr theSObject); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + }; +} +#endif diff --git a/src/VISU_I/VISU_CutPlanes_i.cc b/src/VISU_I/VISU_CutPlanes_i.cc new file mode 100644 index 00000000..a4ede3a5 --- /dev/null +++ b/src/VISU_I/VISU_CutPlanes_i.cc @@ -0,0 +1,196 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_CutPlanesPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_CutPlanes_i.hh" +#include "VISU_Actor.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +int VISU::CutPlanes_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); +} + + +int VISU::CutPlanes_i::myNbPresent = 0; +QString VISU::CutPlanes_i::GenerateName() { return VISU::GenerateName("CutPlanes",myNbPresent++);} + + +const string VISU::CutPlanes_i::myComment = "CUTPLANES"; +const char* VISU::CutPlanes_i::GetComment() const { return myComment.c_str();} + + +VISU::CutPlanes_i::CutPlanes_i(Result_i* theResult, bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy) +{ + myCutPlanesPL = NULL; +} + + +void VISU::CutPlanes_i::Destroy(){ + ScalarMap_i::Destroy(); +} + + +void VISU::CutPlanes_i::SameAs(const CutPlanes_i* theOrigin){ + CutPlanes_i* aCutPlanes = const_cast(theOrigin); + VISU::ScalarMap_i::SameAs(theOrigin); + + //SetNbPlanes(aCutPlanes->GetNbPlanes()); + //SetDisplacement(aCutPlanes->GetDisplacement()); + //SetOrientationType(aCutPlanes->GetOrientationType()); + //SetRotateX(aCutPlanes->GetRotateX()); + //SetRotateY(aCutPlanes->GetRotateY()); +} + + +VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + + +VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + ScalarMap_i::Restore(theMap); + + SetNbPlanes(VISU::Storable::FindValue(theMap,"myNbPlanes").toInt()); + SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement").toDouble()); + SetOrientationType(VISU::CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane").toInt())); + SetRotateX(VISU::Storable::FindValue(theMap,"aRot[0]").toDouble()); + SetRotateY(VISU::Storable::FindValue(theMap,"aRot[1]").toDouble()); + + return Build(true); +} + + +void VISU::CutPlanes_i::ToStream(std::ostringstream& theStr){ + ScalarMap_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myNbPlanes", int(GetNbPlanes()) ); + Storable::DataToStream( theStr, "myDisplacement", GetDisplacement() ); + Storable::DataToStream( theStr, "myBasePlane", int(GetOrientationType()) ); + Storable::DataToStream( theStr, "aRot[0]", GetRotateX() ); + Storable::DataToStream( theStr, "aRot[1]", GetRotateY() ); +} + + +VISU::Storable* VISU::CutPlanes_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::CutPlanes_i* pResent = new VISU::CutPlanes_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::CutPlanes_i::~CutPlanes_i(){ + if(MYDEBUG) MESSAGE("CutPlanes_i::~CutPlanes_i()"); +} + + +void VISU::CutPlanes_i::SetOrientationType(VISU::CutPlanes::Orientation theOrient){ + myCutPlanesPL->SetPlaneOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient)); +} +VISU::CutPlanes::Orientation VISU::CutPlanes_i::GetOrientationType() { + return VISU::CutPlanes::Orientation(myCutPlanesPL->GetPlaneOrientation()); +} + + +void VISU::CutPlanes_i::SetDisplacement(CORBA::Double theDisp) { + myCutPlanesPL->SetDisplacement(theDisp); +} +CORBA::Double VISU::CutPlanes_i::GetDisplacement() { + return myCutPlanesPL->GetDisplacement(); +} + + +void VISU::CutPlanes_i::SetPlanePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){ + myCutPlanesPL->SetPartPosition(thePlaneNumber,thePlanePosition); +} +CORBA::Double VISU::CutPlanes_i::GetPlanePosition(CORBA::Long thePlaneNumber){ + return myCutPlanesPL->GetPartPosition(thePlaneNumber); +} + + +void VISU::CutPlanes_i::SetDefault(CORBA::Long thePlaneNumber){ + myCutPlanesPL->SetPartDefault(thePlaneNumber); +} +CORBA::Boolean VISU::CutPlanes_i::IsDefault(CORBA::Long thePlaneNumber){ + return myCutPlanesPL->IsPartDefault(thePlaneNumber); +} + + +void VISU::CutPlanes_i::SetNbPlanes(CORBA::Long theNb) { + myCutPlanesPL->SetNbParts(theNb); +} +CORBA::Long VISU::CutPlanes_i::GetNbPlanes() { + return myCutPlanesPL->GetNbParts(); +} + + +void VISU::CutPlanes_i::SetRotateX(CORBA::Double theAngle){ + myCutPlanesPL->SetRotateX(theAngle); +} +CORBA::Double VISU::CutPlanes_i::GetRotateX(){ + return myCutPlanesPL->GetRotateX(); +} + + +void VISU::CutPlanes_i::SetRotateY(CORBA::Double theAngle){ + myCutPlanesPL->SetRotateY(theAngle); +} +CORBA::Double VISU::CutPlanes_i::GetRotateY(){ + return myCutPlanesPL->GetRotateY(); +} + + +void VISU::CutPlanes_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_CutPlanesPL::New(); + myCutPlanesPL = dynamic_cast(myPipeLine); + + ScalarMap_i::DoHook(); +} diff --git a/src/VISU_I/VISU_CutPlanes_i.hh b/src/VISU_I/VISU_CutPlanes_i.hh new file mode 100644 index 00000000..a64190bc --- /dev/null +++ b/src/VISU_I/VISU_CutPlanes_i.hh @@ -0,0 +1,101 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_CutPlanes_i_HeaderFile +#define VISU_CutPlanes_i_HeaderFile + +#include "VISU_ScalarMap_i.hh" + +class VISU_CutPlanesPL; + +namespace VISU{ + class CutPlanes_i : public virtual POA_VISU::CutPlanes, + public virtual ScalarMap_i + { + static int myNbPresent; + CutPlanes_i(); + CutPlanes_i(const CutPlanes_i&); + public: + CutPlanes_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const CutPlanes_i* theOrigin); + virtual ~CutPlanes_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TCUTPLANES;}; + + virtual void SetOrientationType(VISU::CutPlanes::Orientation theOrient); + virtual VISU::CutPlanes::Orientation GetOrientationType(); + + virtual void SetDisplacement(CORBA::Double theDisp); + virtual CORBA::Double GetDisplacement(); + + virtual void SetPlanePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition); + virtual CORBA::Double GetPlanePosition(CORBA::Long thePlaneNumber); + + virtual void SetDefault(CORBA::Long thePlaneNumber); + virtual CORBA::Boolean IsDefault(CORBA::Long thePlaneNumber); + + virtual void SetNbPlanes(CORBA::Long theNb); + virtual CORBA::Long GetNbPlanes(); + + virtual void SetRotateX(CORBA::Double theAngle); + virtual CORBA::Double GetRotateX(); + + virtual void SetRotateY(CORBA::Double theAngle); + virtual CORBA::Double GetRotateY(); + + typedef VISU::CutPlanes TInterface; + VISU_CutPlanesPL* GetCutPlanesPL(){ return myCutPlanesPL;} + + protected: + virtual void DoHook(); + + VISU_CutPlanesPL *myCutPlanesPL; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + }; +} + + +#endif + + diff --git a/src/VISU_I/VISU_DeformedShape_i.cc b/src/VISU_I/VISU_DeformedShape_i.cc new file mode 100644 index 00000000..19baed97 --- /dev/null +++ b/src/VISU_I/VISU_DeformedShape_i.cc @@ -0,0 +1,184 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_DeformedShapePL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_ScalarMapAct.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + try{ + if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration)) return 0; + const VISU::TField& aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName); + return aField.myNbComp > 1; + }catch(std::runtime_error& exc){ + INFOS("Follow exception was accured :\n"<GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy) +{ + if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i"); + myDeformedShapePL = NULL; +} + +void VISU::DeformedShape_i::Destroy(){ + ScalarMap_i::Destroy(); +} + +void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin) +{ + DeformedShape_i* aDefShape = const_cast(theOrigin); + VISU::ScalarMap_i::SameAs(theOrigin); + + //SetScale(aDefShape->GetScale()); + SetColor(aDefShape->GetColor()); + ShowColored(aDefShape->IsColored()); +} + + +VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + myIsColored = false; + myColor.R = myColor.G = myColor.B = 0.5; + return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + +VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + ScalarMap_i::Restore(theMap); + + SetScale(VISU::Storable::FindValue(theMap,"myFactor").toDouble()); + + myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt(); + myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); + myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); + myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); + + return Build(true); +} + +void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){ + ScalarMap_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myFactor", GetScale() ); + + Storable::DataToStream( theStr, "myIsColored", myIsColored ); + Storable::DataToStream( theStr, "myColor.R", myColor.R ); + Storable::DataToStream( theStr, "myColor.G", myColor.G ); + Storable::DataToStream( theStr, "myColor.B", myColor.B ); +} + +VISU::Storable* VISU::DeformedShape_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::DeformedShape_i* pResent = new VISU::DeformedShape_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::DeformedShape_i::~DeformedShape_i(){ + if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()"); +} + + +void VISU::DeformedShape_i::SetScale(CORBA::Double theScale) { + myDeformedShapePL->SetScale(theScale); +} +CORBA::Double VISU::DeformedShape_i::GetScale(){ + return myDeformedShapePL->GetScale(); +} + + +void VISU::DeformedShape_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_DeformedShapePL::New(); + myDeformedShapePL = dynamic_cast(myPipeLine); + myPipeLine->GetMapper()->SetScalarVisibility(IsColored()); + + ScalarMap_i::DoHook(); +} + + +void VISU::DeformedShape_i::SetMapScale(double theMapScale){ + myDeformedShapePL->SetMapScale(theMapScale); +} + + +VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) + throw (std::runtime_error&) +{ + VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO); + anActor->SetRepresentation(1); + anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + return anActor; +} + + +void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor){ + if(VISU_ScalarMapAct* anActor = dynamic_cast(theActor)){ + if(IsColored()){ + anActor->SetBarVisibility(true); + myPipeLine->GetMapper()->SetScalarVisibility(1); + }else{ + anActor->SetBarVisibility(false); + myPipeLine->GetMapper()->SetScalarVisibility(0); + anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + } + VISU::ScalarMap_i::UpdateActor(theActor); + } +} diff --git a/src/VISU_I/VISU_DeformedShape_i.hh b/src/VISU_I/VISU_DeformedShape_i.hh new file mode 100644 index 00000000..1454fcbb --- /dev/null +++ b/src/VISU_I/VISU_DeformedShape_i.hh @@ -0,0 +1,95 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_DeformedShape_i_HeaderFile +#define VISU_DeformedShape_i_HeaderFile + +#include "VISU_ScalarMap_i.hh" + +class VISU_DeformedShapePL; + +namespace VISU{ + class DeformedShape_i : public virtual POA_VISU::DeformedShape, + public virtual ScalarMap_i + { + static int myNbPresent; + DeformedShape_i(); + DeformedShape_i(const DeformedShape_i&); + public: + DeformedShape_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const DeformedShape_i* theOrigin); + virtual ~DeformedShape_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TDEFORMEDSHAPE;}; + + virtual void SetScale(CORBA::Double theScale); + virtual CORBA::Double GetScale(); + + virtual CORBA::Boolean IsColored() { return myIsColored; } + virtual void ShowColored(CORBA::Boolean theColored) { myIsColored = theColored; } + + virtual SALOMEDS::Color GetColor() { return myColor;} + virtual void SetColor(const SALOMEDS::Color& theColor) { myColor = theColor;} + + typedef VISU::DeformedShape TInterface; + VISU_DeformedShapePL* GetDeformedShapePL(){ return myDeformedShapePL;} + + protected: + virtual void DoHook(); + + VISU_DeformedShapePL *myDeformedShapePL; + SALOMEDS::Color myColor; + bool myIsColored; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + virtual void SetMapScale(double theMapScale = 1.0); + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) + throw (std::runtime_error&); + virtual void UpdateActor(VISU_Actor* theActor); + }; +} +#endif + + diff --git a/src/VISU_I/VISU_IsoSurfaces_i.cc b/src/VISU_I/VISU_IsoSurfaces_i.cc new file mode 100644 index 00000000..d7e6bf15 --- /dev/null +++ b/src/VISU_I/VISU_IsoSurfaces_i.cc @@ -0,0 +1,151 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_IsoSurfacesPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_IsoSurfaces_i.hh" +#include "VISU_Actor.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +int VISU::IsoSurfaces_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); +} + +int VISU::IsoSurfaces_i::myNbPresent = 0; +QString VISU::IsoSurfaces_i::GenerateName() { return VISU::GenerateName("IsoSurfaces",myNbPresent++);} + +const string VISU::IsoSurfaces_i::myComment = "ISOSURFACES"; +const char* VISU::IsoSurfaces_i::GetComment() const { return myComment.c_str();} + +VISU::IsoSurfaces_i::IsoSurfaces_i(Result_i* theResult, bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy) +{ + myIsoSurfacesPL = NULL; +} + +void VISU::IsoSurfaces_i::Destroy(){ + ScalarMap_i::Destroy(); +} + +void VISU::IsoSurfaces_i::SameAs(const IsoSurfaces_i* theOrigin) { + IsoSurfaces_i* aIsoSurfaces = const_cast(theOrigin); + VISU::ScalarMap_i::SameAs(theOrigin); + + //SetNbSurfaces(aIsoSurfaces->GetNbSurfaces()); + //SetSubRange(aIsoSurfaces->GetSubMin(),aIsoSurfaces->GetSubMax()); +} + +VISU::Storable* VISU::IsoSurfaces_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + +VISU::Storable* VISU::IsoSurfaces_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + ScalarMap_i::Restore(theMap); + + SetNbSurfaces(VISU::Storable::FindValue(theMap,"myNbSurface").toInt()); + float aMin = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble(); + float aMax = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble(); + SetSubRange(aMin,aMax); + + return Build(true); +} + +void VISU::IsoSurfaces_i::ToStream(std::ostringstream& theStr){ + ScalarMap_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myNbSurface", int(GetNbSurfaces()) ); + Storable::DataToStream( theStr, "myRange[0]", GetSubMin() ); + Storable::DataToStream( theStr, "myRange[1]", GetSubMax() ); +} + +VISU::Storable* VISU::IsoSurfaces_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::IsoSurfaces_i* pResent = new VISU::IsoSurfaces_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::IsoSurfaces_i::~IsoSurfaces_i(){ + if(MYDEBUG) MESSAGE("IsoSurfaces_i::~IsoSurfaces_i()"); +} + + +void VISU::IsoSurfaces_i::SetNbSurfaces(CORBA::Long theNb){ + myIsoSurfacesPL->SetNbParts(theNb); +} +CORBA::Long VISU::IsoSurfaces_i::GetNbSurfaces(){ + return myIsoSurfacesPL->GetNbParts(); +} + + +void VISU::IsoSurfaces_i::SetSubRange(CORBA::Double theMin, CORBA::Double theMax){ + float aRange[2] = {theMin, theMax}; + myIsoSurfacesPL->SetRange(aRange); +} +CORBA::Double VISU::IsoSurfaces_i::GetSubMin(){ + return myIsoSurfacesPL->GetMin(); +} +CORBA::Double VISU::IsoSurfaces_i::GetSubMax(){ + return myIsoSurfacesPL->GetMax(); +} + + +void VISU::IsoSurfaces_i::DoHook(){ + if(MYDEBUG) MESSAGE("IsoSurfaces_i::DoHook()- "<(myPipeLine); + + ScalarMap_i::DoHook(); +} + + +void VISU::IsoSurfaces_i::SetMapScale(double theMapScale){ + myIsoSurfacesPL->SetMapScale(theMapScale); +} diff --git a/src/VISU_I/VISU_IsoSurfaces_i.hh b/src/VISU_I/VISU_IsoSurfaces_i.hh new file mode 100644 index 00000000..a5a6d208 --- /dev/null +++ b/src/VISU_I/VISU_IsoSurfaces_i.hh @@ -0,0 +1,85 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_IsoSurfaces_i_HeaderFile +#define VISU_IsoSurfaces_i_HeaderFile + +#include "VISU_ScalarMap_i.hh" + +class VISU_IsoSurfacesPL; + +namespace VISU{ + class IsoSurfaces_i : public virtual POA_VISU::IsoSurfaces, + public virtual ScalarMap_i + { + static int myNbPresent; + IsoSurfaces_i(); + IsoSurfaces_i(const IsoSurfaces_i&); + public: + IsoSurfaces_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const IsoSurfaces_i* theOrigin); + virtual ~IsoSurfaces_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TISOSURFACE;}; + + virtual void SetNbSurfaces(CORBA::Long theNb); + virtual CORBA::Long GetNbSurfaces(); + + virtual void SetSubRange(CORBA::Double theMin, CORBA::Double theMax); + virtual CORBA::Double GetSubMin(); + virtual CORBA::Double GetSubMax(); + + typedef VISU::IsoSurfaces TInterface; + VISU_IsoSurfacesPL* GetIsoSurfacesPL(){ return myIsoSurfacesPL;} + + protected: + virtual void DoHook(); + VISU_IsoSurfacesPL* myIsoSurfacesPL; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + virtual void SetMapScale(double theMapScale = 1.0); + }; +} + +#endif diff --git a/src/VISU_I/VISU_Mesh_i.cc b/src/VISU_I/VISU_Mesh_i.cc new file mode 100644 index 00000000..0a5ad229 --- /dev/null +++ b/src/VISU_I/VISU_Mesh_i.cc @@ -0,0 +1,270 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_MeshPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_Mesh_i.hh" +#include "VISU_MeshAct.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +static int INCMEMORY = 4; + +int VISU::Mesh_i::myNbPresent = 0; + +QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);} + +const string VISU::Mesh_i::myComment = "MESH"; + +const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();} + +VISU::Mesh_i::Mesh_i(Result_i* theResult) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult) +{ + myPipeLine = myMeshPL = VISU_MeshPL::New();; +} + +void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin){ + return; // "SameAs" command for mesh is not valid in current architecture +} + +void VISU::Mesh_i::Destroy(){ + SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(GetEntry()); + if(!aSObj->_is_nil()){ + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder(); + aStudyBuilder->RemoveAttribute(aSObj,"AttributeIOR"); + } + Prs3d_i::Destroy(); +} + +int VISU::Mesh_i::IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName){ + try{ + vtkIdType aSize = INCMEMORY* + theResult->GetInput()->GetMeshOnEntitySize(theMeshName,(VISU::TEntity)theEntity,theFamilyName); + if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<GetInput()->GetMeshOnGroupSize(theMeshName,theGroupName); + if(MYDEBUG) MESSAGE("Mesh_i::IsPossible - CheckAvailableMemory = "<Restore(theMap); + } + return NULL; +} + + +VISU::Mesh_i::~Mesh_i(){ + if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()"); +} + + +VISU::Storable* VISU::Mesh_i::Build(int theRestoring){ + try{ + if(myResult->GetInput() == NULL) + throw std::runtime_error("Mesh_i::Build - myResult->GetInput() == NULL !!!"); + if(!theRestoring){ + myPresentType = VISU::SHADED; + myName = GenerateName().latin1(); + myCellColor.R = 0.0; myCellColor.G = myCellColor.B = 1.0; + myNodeColor.R = myNodeColor.G = 1.0; myNodeColor.B = 1.0; + myLinkColor.R = myLinkColor.G = myLinkColor.B = 83/255.; + } + if(int(myEntity) >= 0) + if(mySubMeshName == "") + myType = VISU::TENTITY; + else + myType = VISU::TFAMILY; + else + myType = VISU::TGROUP; + if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<GetInput()->GetMeshOnEntity(myMeshName,myEntity); + aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d", + VISU::TENTITY,myMeshName.c_str(),myEntity); + break; + case VISU::TFAMILY : + anOutput = myResult->GetInput()->GetMeshOnEntity(myMeshName,myEntity,mySubMeshName); + aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", + VISU::TFAMILY,myMeshName.c_str(),myEntity,mySubMeshName.c_str()); + break; + case VISU::TGROUP : + anOutput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName); + aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", + VISU::TGROUP,myMeshName.c_str(),mySubMeshName.c_str()); + break; + } + if(anOutput == NULL) throw std::runtime_error("Mesh_i::Build - anOutput == NULL !!!"); + myMeshPL->SetInput(anOutput); + myMeshPL->Build(); + if(!theRestoring) { //Setting IOR on the label + myMeshPL->Init(); + string aResultEntry = myResult->GetEntry(); + string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1()); + if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!"); + SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(anEntry.c_str()); + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObj,"AttributeIOR"); + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var aString = GetID(); + anIOR->SetValue(aString); + } + return this; + }catch(std::runtime_error& exc){ + INFOS("Follow exception was accured :\n"<Delete(); + throw exc; + } + return anActor; +} + +void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor){ + if(VISU_MeshAct* anActor = dynamic_cast(theActor)){ + if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor"); + VISU::Prs3d_i::UpdateActor(anActor); + anActor->SetRepresentation(myPresentType); + anActor->GetProperty()->SetColor(myCellColor.R, myCellColor.G, myCellColor.B); + anActor->GetEdgeProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B); + anActor->GetNodeProperty()->SetColor(myNodeColor.R, myNodeColor.G, myNodeColor.B); + } +} diff --git a/src/VISU_I/VISU_Mesh_i.hh b/src/VISU_I/VISU_Mesh_i.hh new file mode 100644 index 00000000..51668a83 --- /dev/null +++ b/src/VISU_I/VISU_Mesh_i.hh @@ -0,0 +1,104 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_Mesh_i_HeaderFile +#define VISU_Mesh_i_HeaderFile + +#include "VISU_Prs3d_i.hh" + +class VISU_MeshPL; + +namespace VISU{ + class Mesh_i : public virtual POA_VISU::Mesh, + public virtual Prs3d_i + { + static int myNbPresent; + Mesh_i(); + Mesh_i(const Mesh_i&); + public: + Mesh_i(Result_i* theResult); + virtual void SameAs(const Mesh_i* theOrigin); + virtual ~Mesh_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TMESH;}; + + virtual void SetCellColor(const SALOMEDS::Color& theColor) { myCellColor = theColor;} + virtual SALOMEDS::Color GetCellColor() { return myCellColor;} + + virtual void SetNodeColor(const SALOMEDS::Color& theColor) { myNodeColor = theColor;} + virtual SALOMEDS::Color GetNodeColor() { return myNodeColor;} + + virtual void SetLinkColor(const SALOMEDS::Color& theColor) { myLinkColor = theColor;} + virtual SALOMEDS::Color GetLinkColor() { return myLinkColor;} + + virtual void SetPresentationType(VISU::PresentationType theType) { myPresentType = theType;} + virtual PresentationType GetPresentationType() { return myPresentType;} + + typedef VISU::Mesh TInterface; + VISU_MeshPL* GetMeshPL(){ return myMeshPL;} + + protected: + Storable* Build(int theRestoring); + + VISU_MeshPL* myMeshPL; + + string myMeshName; + TEntity myEntity; + string mySubMeshName; + VISU::VISUType myType; + + VISU::PresentationType myPresentType; + struct SALOMEDS::Color myCellColor, myNodeColor, myLinkColor; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, Entity theEntity, const char* theFamilyName = ""); + virtual Storable* Create(const char* theMeshName, Entity theEntity, const char* theFamilyName = ""); + + static int IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName); + virtual Storable* Create(const char* theMeshName, const char* theGroupName); + + virtual void ToStream(std::ostringstream& theStr); + + virtual const char* GetComment() const; + static const string myComment; + virtual QString GenerateName(); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) + throw (std::runtime_error&); + virtual void UpdateActor(VISU_Actor* theActor); + }; +} + +#endif + + diff --git a/src/VISU_I/VISU_Prs3d_i.cc b/src/VISU_I/VISU_Prs3d_i.cc new file mode 100644 index 00000000..350c651d --- /dev/null +++ b/src/VISU_I/VISU_Prs3d_i.cc @@ -0,0 +1,123 @@ +// 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 +// +// +// File : VISU_Prs3d_i.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_PipeLine.hxx" +#include "VISU_Result_i.hh" +#include "VISU_Prs3d_i.hh" +#include "VISU_Actor.h" +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +VISU::Prs3d_i::Prs3d_i(Result_i* theResult) : + PrsObject_i(theResult->GetStudyDocument()), + myResult(theResult) +{ + myAddToStudy = true; + myPipeLine = NULL; +} + +void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin) +{ + Prs3d_i* aOrigin = const_cast(theOrigin); + myPipeLine->ShallowCopy(aOrigin->GetPL()); +} + +VISU::Prs3d_i::~Prs3d_i() { + if(MYDEBUG) MESSAGE("Prs3d_i::~Prs3d_i()"); + myPipeLine->Delete(); +} + +void VISU::Prs3d_i::Destroy() { + CORBA::Object_var anObj = _this(); + PortableServer::POA_ptr aPOA = Base_i::GetPOA(); + PortableServer::ObjectId_var anId = aPOA->reference_to_id(anObj); + aPOA->deactivate_object(anId.in()); + this->_remove_ref(); +} + + +void VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO) + throw (std::runtime_error&) +{ + try{ + Update(); + if(myAddToStudy){ + Handle(SALOME_InteractiveObject) anIO = theIO; + if (anIO.IsNull()) + anIO = new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",strdup(GetName())); + theActor->setIO(anIO); + } + theActor->SetPipeLine(GetPipeLine()); + theActor->SetPrs3d(this); + }catch(std::runtime_error& ex){ + throw ex; + }catch(...){ + throw std::runtime_error("Prs3d_i::CreateActor >> unexpected exception was caught!!!"); + } +} + +void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor){ + theActor->GetMapper()->ShallowCopy(myPipeLine->GetMapper()); + theActor->Modified(); +} + +VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + myName = VISU::Storable::FindValue(theMap,"myName").latin1(); + return this; +} + +void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){ + Storable::DataToStream( theStr, "myName", myName.c_str() ); +} + +void VISU::Prs3d_i::Update(){ + myPipeLine->Update(); +} + +VISU_PipeLine* VISU::Prs3d_i::GetPipeLine(){ + return GetPL(); +} + +VISU_PipeLine* VISU::Prs3d_i::GetPL(){ + return myPipeLine; +} + +VISU::Result_i* VISU::Prs3d_i::GetResult(SALOMEDS::SObject_ptr theSObject){ + VISU::Result_var aResult = FindResult(theSObject); + if(!aResult->_is_nil()) + return dynamic_cast(VISU::GetServant(aResult.in())); + return NULL; +} diff --git a/src/VISU_I/VISU_Prs3d_i.hh b/src/VISU_I/VISU_Prs3d_i.hh new file mode 100644 index 00000000..3ebbb965 --- /dev/null +++ b/src/VISU_I/VISU_Prs3d_i.hh @@ -0,0 +1,78 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_Prs3d_i_HeaderFile +#define VISU_Prs3d_i_HeaderFile + +#include "VISU_PrsObject_i.hh" +#include "Handle_SALOME_InteractiveObject.hxx" +#include "VISU_Convertor.hxx" + +class VISU_PipeLine; +class VISU_Actor; + +namespace VISU{ + class Result_i; + class Prs3d_i : public virtual POA_VISU::Prs3d, + public virtual PrsObject_i + { + Prs3d_i(); + Prs3d_i(const Prs3d_i&); + public: + Prs3d_i(Result_i* theResult); + virtual void SameAs(const Prs3d_i* theOrigin); + virtual ~Prs3d_i(); + virtual void Destroy(); + + protected: + Result_i *myResult; + VISU_PipeLine *myPipeLine; + + bool myAddToStudy; + void CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO = NULL) throw (std::runtime_error&); + + public: + virtual void Update(); + virtual VISU_PipeLine* GetPipeLine(); + VISU_PipeLine* GetPL(); + + virtual const char* GetComment() const = 0; + virtual QString GenerateName() = 0; + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + virtual void ToStream(std::ostringstream& theStr); + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) throw (std::runtime_error&) = 0; + virtual void UpdateActor(VISU_Actor* theActor); + + Result_i* GetResult() const { return myResult;} + + static Result_i* GetResult(SALOMEDS::SObject_ptr theSObject); + }; +} + +#endif diff --git a/src/VISU_I/VISU_ScalarMap_i.cc b/src/VISU_I/VISU_ScalarMap_i.cc new file mode 100644 index 00000000..270e77d4 --- /dev/null +++ b/src/VISU_I/VISU_ScalarMap_i.cc @@ -0,0 +1,429 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_ScalarMap_i.hh" +#include "VISU_ScalarMapAct.h" +#include "QAD_Config.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +static int INCMEMORY = 4; + +int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + try{ + vtkIdType aSize = INCMEMORY* + theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration); + if(MYDEBUG) MESSAGE("ScalarMap_i::IsPossible - CheckAvailableMemory = "<GetStudyDocument()), + Prs3d_i(theResult) +{ + myAddToStudy = theAddToStudy; + myScalarMapPL = NULL; +} + +void VISU::ScalarMap_i::Destroy(){ + if(myAddToStudy){ + SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(GetEntry()); + if(!aSObj->_is_nil()){ + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder(); + aStudyBuilder->RemoveObject(aSObj); + } + } + Prs3d_i::Destroy(); +} + + +void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin) +{ + ScalarMap_i* aScalarMap = const_cast(theOrigin); + DoHook(); + VISU::Prs3d_i::SameAs(aScalarMap); + myField = aScalarMap->GetField(); + myMeshName = myField->myMeshName; + myEntity = myField->myEntity; + myIteration = aScalarMap->GetIteration(); + myFieldName = aScalarMap->GetFieldName(); + + SetScalarMode(aScalarMap->GetScalarMode()); + + SetRange(aScalarMap->GetMin(), aScalarMap->GetMax()); + myIsFixedRange = aScalarMap->IsRangeFixed(); + + SetScaling(aScalarMap->GetScaling()); + + SetOrientation(aScalarMap->GetOrientation()); + SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY()); + SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight()); + SetNbColors(aScalarMap->GetNbColors()); + SetLabels(aScalarMap->GetLabels()); + SetTitle(aScalarMap->GetTitle()); + + Build(-1); + Update(); +} + + +/** + * Creates Scalar Map and initialises it from resources + */ +VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + DoHook(); + + // Orientation + QString aOrient = QAD_CONFIG->getSetting("Visu:SBOrientation"); + if ( !aOrient.isEmpty() ) + myOrientation = (VISU::ScalarMap::Orientation) aOrient.toInt(); + else + myOrientation = VISU::ScalarMap::VERTICAL; + + // Scalar Bar origin + QString aXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin"); + if ( !aXorigin.isEmpty() ) + myPosition[0] = aXorigin.toFloat(); + else { + if(myOrientation == VISU::ScalarMap::VERTICAL) { + myPosition[0] = 0.03; + } else { + myPosition[0] = 0.2; + } + } + + QString aYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin"); + if ( !aYorigin.isEmpty() ) + myPosition[1] = aYorigin.toFloat(); + else { + if(myOrientation == VISU::ScalarMap::VERTICAL) { + myPosition[1] = 0.1; + } else { + myPosition[1] = 0.012; + } + } + + // Scalar Bar size + QString aWidth = QAD_CONFIG->getSetting("Visu:SBWidth"); + if ( !aWidth.isEmpty() ) + myWidth = aWidth.toFloat(); + else { + myWidth =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.17:0.6; + } + QString aHeight = QAD_CONFIG->getSetting("Visu:SBHeight"); + if ( !aHeight.isEmpty() ) + myHeight = aHeight.toFloat(); + else { + myHeight =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12; + } + + // Nb of Colors + QString aColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors"); + int aNumberOfColors = (aColors.isEmpty())? 64 : aColors.toInt(); + if (aNumberOfColors > 64) + aNumberOfColors = 64; + SetNbColors(aNumberOfColors); + + // Nb of Labels + QString aLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels"); + myNumberOfLabels = (aLabels.isEmpty())? 5 : aLabels.toInt(); + if (myNumberOfLabels > 65) + myNumberOfLabels = 65; + + // Scalar Range + QString aFixRange = QAD_CONFIG->getSetting("Visu:SBImposeRange"); + myIsFixedRange = (aFixRange.compare("true") == 0); + + if(myIsFixedRange){ + float aScalarRange[2]; + QString aRangeMin = QAD_CONFIG->getSetting("Visu:SBMinimumValue"); + float aMin = (aRangeMin.isEmpty())? 0 : aRangeMin.toFloat(); + QString aRangeMax = QAD_CONFIG->getSetting("Visu:SBMaximumValue"); + float aMax = (aRangeMax.isEmpty())? 0 : aRangeMax.toFloat(); + SetRange(aMin,aMax); + } + + QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling"); + if(aScaling.compare("LOGARITHMIC") == 0) + SetScaling(VISU::LOGARITHMIC); + else + SetScaling(VISU::LINEAR); + + myMeshName = theMeshName; + myEntity = (VISU::TEntity)theEntity; + myFieldName =theFieldName; + myIteration = theIteration; + + return Build(false); +} + + +VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + DoHook(); + + Prs3d_i::Restore(theMap); + + myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study. + + myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); + myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt(); + myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1(); + myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt(); + + SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt()); + SetScaling(VISU::Scaling(VISU::Storable::FindValue(theMap,"myScaling").toInt())); + float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble(); + float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble(); + SetRange(aMin,aMax); + myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt(); + + myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1(); + myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt(); + SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt()); + myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt(); + myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); + myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); + myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); + myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); + + return Build(true); +} + + +void VISU::ScalarMap_i::ToStream(std::ostringstream& theStr){ + Prs3d_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); + Storable::DataToStream( theStr, "myEntity", myEntity ); + Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() ); + Storable::DataToStream( theStr, "myIteration", myIteration ); + + Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) ); + Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() ); + Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() ); + Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange ); + Storable::DataToStream( theStr, "myScaling", GetScaling() ); + + Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); + Storable::DataToStream( theStr, "myOrientation", myOrientation ); + Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) ); + Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels ); + Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] ); + Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); + Storable::DataToStream( theStr, "myWidth", myWidth ); + Storable::DataToStream( theStr, "myHeight", myHeight ); +} + + +CORBA::Long VISU::ScalarMap_i::GetScalarMode(){ + return myScalarMapPL->GetScalarMode(); +} +void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode) { + myScalarMapPL->SetScalarMode(theScalarMode); +} + + +VISU::Scaling VISU::ScalarMap_i::GetScaling(){ + return VISU::Scaling(myScalarMapPL->GetScaling()); +} +void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){ + myScalarMapPL->SetScaling(theScaling); +} + + +void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax){ + if(theMin > theMax) return; + float aScalarRange[2] = {theMin, theMax}; + myScalarMapPL->SetScalarRange(aScalarRange); + myIsFixedRange = true; +} + +CORBA::Double VISU::ScalarMap_i::GetMin(){ + return myScalarMapPL->GetScalarRange()[0]; +} + +CORBA::Double VISU::ScalarMap_i::GetMax(){ + return myScalarMapPL->GetScalarRange()[1]; +} + + +void VISU::ScalarMap_i::SetNbColors(CORBA::Long theNbColors){ + myScalarMapPL->SetNbColors(theNbColors); +} + +CORBA::Long VISU::ScalarMap_i::GetNbColors(){ + return myScalarMapPL->GetNbColors(); +} + + +VISU::Storable* VISU::ScalarMap_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + if(VISU::Result_i* pResult = GetResult(theSObject)){ + VISU::ScalarMap_i* pResent = new VISU::ScalarMap_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::ScalarMap_i::~ScalarMap_i(){ + if(MYDEBUG) MESSAGE("ScalarMap_i::~ScalarMap_i()"); +} + + +VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){ + if(MYDEBUG) + MESSAGE("ScalarMap_i::Build - "<GetInput() == NULL !!!"); + myField = &(myResult->GetInput()->GetField(myMeshName,myEntity,myFieldName)); + if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!"); + VISU_Convertor::TOutput *anOutput = + myResult->GetInput()->GetTimeStampOnMesh(myMeshName,myEntity,myFieldName,myIteration); + if(anOutput == NULL) throw std::runtime_error("There is no TimeStamp with the parameters !!!"); + myScalarMapPL->SetInput(anOutput); + myScalarMapPL->Build(); + QString aComment; + myName = "NoName"; + if(theRestoring <= 0){ + if(theRestoring == 0) myScalarMapPL->Init(); + if(!myIsFixedRange) myScalarMapPL->SetSourceRange(); + const VISU::TField::TValField& aValField = myField->myValField; + const VISU::TField::TValForTime& aValForTime = aValField.find(myIteration)->second; + aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime.myTime).c_str()); + myTitle = aComment.simplifyWhiteSpace().latin1(); + } + if(myAddToStudy){ + myName = GenerateName().latin1(); + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + string aResultEntry = myResult->GetEntry(); + string aRefFatherEntry = myResult->GetRefFatherEntry(); + string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1()); + if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!"); + aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + CORBA::String_var anIOR = GetID(); + CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true); + } + return this; + }catch(std::runtime_error& exc){ + INFOS("Follow exception was accured :\n"<GetMapper()->SetScalarVisibility(1); + } + myScalarMapPL = dynamic_cast(myPipeLine); +} + +void VISU::ScalarMap_i::Update(){ + VISU::Prs3d_i::Update(); +} + +void VISU::ScalarMap_i::SetMapScale(double theMapScale){ + myScalarMapPL->SetMapScale(theMapScale); +} + +VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) + throw (std::runtime_error&) +{ + VISU_ScalarMapAct* anActor = VISU_ScalarMapAct::New(); + try{ + VISU::Prs3d_i::CreateActor(anActor,theIO); + anActor->SetBarVisibility(true); + anActor->SetRepresentation(2); + anActor->myFieldName = myFieldName; + UpdateActor(anActor); + }catch(std::runtime_error& exc){ + anActor->Delete(); + throw exc; + } + return anActor; +} + +void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor){ + if(VISU_ScalarMapAct* anActor = dynamic_cast(theActor)){ + VISU::Prs3d_i::UpdateActor(theActor); + VISU_ScalarBarActor *aScalarBar = anActor->GetScalarBar(); + aScalarBar->SetLookupTable(myScalarMapPL->GetBarTable()); + aScalarBar->SetTitle(myTitle.c_str()); + aScalarBar->SetOrientation(myOrientation); + aScalarBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(); + aScalarBar->GetPositionCoordinate()->SetValue(myPosition[0],myPosition[1]); + aScalarBar->SetWidth(myWidth); + aScalarBar->SetHeight(myHeight); + aScalarBar->SetNumberOfLabels(myNumberOfLabels); + aScalarBar->Modified(); + } +} + + +void VISU::ScalarMap_i::SetSourceRange(){ + myScalarMapPL->SetSourceRange(); + myIsFixedRange = false; +} diff --git a/src/VISU_I/VISU_ScalarMap_i.hh b/src/VISU_I/VISU_ScalarMap_i.hh new file mode 100644 index 00000000..f6dbca2a --- /dev/null +++ b/src/VISU_I/VISU_ScalarMap_i.hh @@ -0,0 +1,141 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ScalarMap_i_HeaderFile +#define VISU_ScalarMap_i_HeaderFile + +#include "VISU_Prs3d_i.hh" + +class VISU_ScalarMapPL; + +namespace VISU{ + class ScalarMap_i : public virtual POA_VISU::ScalarMap, + public virtual Prs3d_i + { + static int myNbPresent; + ScalarMap_i(); + ScalarMap_i(const ScalarMap_i&); + + public: + ScalarMap_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const ScalarMap_i* theOrigin); + virtual ~ScalarMap_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TSCALARMAP;}; + + virtual CORBA::Long GetScalarMode(); + virtual void SetScalarMode(CORBA::Long theScalarMode); + + virtual VISU::Scaling GetScaling(); + virtual void SetScaling(VISU::Scaling theScaling); + + virtual void SetRange(CORBA::Double theMin, CORBA::Double theMax); + virtual CORBA::Double GetMin(); + virtual CORBA::Double GetMax(); + + virtual void SetNbColors(CORBA::Long theNbColors); + virtual CORBA::Long GetNbColors(); + + virtual void SetOrientation(VISU::ScalarMap::Orientation theOrientation){ + myOrientation = theOrientation; + } + virtual VISU::ScalarMap::Orientation GetOrientation() { return myOrientation;} + + virtual void SetPosition(CORBA::Double X, CORBA::Double Y) { myPosition[0] = X; myPosition[1] = Y;} + virtual CORBA::Double GetPosX() { return myPosition[0];} + virtual CORBA::Double GetPosY() { return myPosition[1];} + + virtual void SetSize(CORBA::Double theWidth, CORBA::Double theHeight) { + myWidth = theWidth; myHeight = theHeight; + } + virtual CORBA::Double GetWidth() { return myWidth;} + virtual CORBA::Double GetHeight() { return myHeight;} + + virtual void SetLabels(CORBA::Long theNbLabels) { myNumberOfLabels = theNbLabels;} + virtual CORBA::Long GetLabels() { return myNumberOfLabels;} + + virtual void SetTitle(const char* theName) { myTitle = theName;} + virtual char* GetTitle() { return CORBA::string_dup(myTitle.c_str());} + + typedef VISU::ScalarMap TInterface; + VISU_ScalarMapPL* GetScalarMapPL(){ return myScalarMapPL;} + + protected: + Storable* Build(int theRestoring); + virtual void DoHook(); + + VISU_ScalarMapPL* myScalarMapPL; + const TField* myField; + + string myMeshName; + TEntity myEntity; + string myFieldName; + int myIteration; + + bool myIsFixedRange; + + std::string myTitle; + int myNumberOfLabels; + float myPosition[2], myWidth, myHeight; + VISU::ScalarMap::Orientation myOrientation; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + virtual void Update(); + virtual void SetMapScale(double theMapScale = 1.0); + + const VISU::TField* GetField() const { return myField;} + const string& GetFieldName() const { return myFieldName;} + + virtual bool IsRangeFixed() { return myIsFixedRange; } + virtual void SetSourceRange(); + + virtual int GetIteration() { return myIteration; } + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) + throw (std::runtime_error&); + virtual void UpdateActor(VISU_Actor* theActor); + }; +} + +#endif diff --git a/src/VISU_I/VISU_StreamLines_i.cc b/src/VISU_I/VISU_StreamLines_i.cc new file mode 100644 index 00000000..7eb2f338 --- /dev/null +++ b/src/VISU_I/VISU_StreamLines_i.cc @@ -0,0 +1,252 @@ +// 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 +// +// +// File : VISU_PrsObject_i.cxx +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_StreamLinesPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_StreamLines_i.hh" +#include "VISU_Actor.h" + +#include + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +static int INCMEMORY = 2; + +int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + try{ + vtkIdType aSize = + (VISU_StreamLinesPL::myMaxIncrementMemorySize+INCMEMORY)* + theResult->GetInput()->GetTimeStampSize(theMeshName,(VISU::TEntity)theEntity,theFieldName,theIteration); + if(MYDEBUG) MESSAGE("StreamLines_i::IsPossible - CheckAvailableMemory = "<GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy), + DeformedShape_i(theResult, theAddToStudy) +{ + myStreamLinesPL = NULL; +} + +void VISU::StreamLines_i::Destroy(){ + DeformedShape_i::Destroy(); +} + + +void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) { + StreamLines_i* aStreamLines = const_cast(theOrigin); + VISU::DeformedShape_i::SameAs(theOrigin); + + //Order of setting of the values are important + //SetIntegrationStep(aStreamLines->GetIntegrationStep()); + //SetPropagationTime(aStreamLines->GetPropagationTime()); + //SetStepLength(aStreamLines->GetStepLength()); + + //SetUsedPoints(aStreamLines->GetUsedPoints()); + //SetDirection(aStreamLines->GetDirection()); + + SetSource(aStreamLines->GetSource()); +} + + +VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + + +VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + DeformedShape_i::Restore(theMap); + + //Order of setting of the values are important + SetIntegrationStep(VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble()); + SetPropagationTime(VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble()); + SetStepLength(VISU::Storable::FindValue(theMap,"myStepLength").toDouble()); + + SetDirection(VISU::StreamLines::Direction(VISU::Storable::FindValue(theMap,"myDirection").toInt())); + SetUsedPoints(VISU::Storable::FindValue(theMap,"myPercents").toDouble()); + mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1(); + + return Build(true); +} + + +void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){ + DeformedShape_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myIntegrationStep", GetIntegrationStep()); + Storable::DataToStream( theStr, "myPropagationTime", GetPropagationTime()); + Storable::DataToStream( theStr, "myStepLength", GetStepLength()); + + Storable::DataToStream( theStr, "myDirection", int(GetDirection())); + Storable::DataToStream( theStr, "myPercents", GetUsedPoints()); + + Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str()); +} + + +VISU::Storable* VISU::StreamLines_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::StreamLines_i* pResent = new VISU::StreamLines_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::StreamLines_i::~StreamLines_i(){ + if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()"); +} + + +void VISU::StreamLines_i::SetDirection(VISU::StreamLines::Direction theDirection) { + myStreamLinesPL->SetDirection(theDirection); +} +VISU::StreamLines::Direction VISU::StreamLines_i::GetDirection() { + return VISU::StreamLines::Direction(myStreamLinesPL->GetDirection()); +} + + +void VISU::StreamLines_i::SetStepLength(CORBA::Double theStep) { + myStreamLinesPL->SetStepLength(theStep); +} +CORBA::Double VISU::StreamLines_i::GetStepLength() { + return myStreamLinesPL->GetStepLength(); +} + + +void VISU::StreamLines_i::SetPropagationTime(CORBA::Double theTime) { + myStreamLinesPL->SetPropagationTime(theTime); +} +CORBA::Double VISU::StreamLines_i::GetPropagationTime() { + return myStreamLinesPL->GetPropagationTime(); +} + + +void VISU::StreamLines_i::SetIntegrationStep(CORBA::Double theStep) { + myStreamLinesPL->SetIntegrationStep(theStep); +} +CORBA::Double VISU::StreamLines_i::GetIntegrationStep() { + return myStreamLinesPL->GetIntegrationStep(); +} + + +void VISU::StreamLines_i::SetUsedPoints(CORBA::Double thePercents) { + myStreamLinesPL->SetUsedPoints(thePercents); +} +CORBA::Double VISU::StreamLines_i::GetUsedPoints() { + return myStreamLinesPL->GetUsedPoints(); +} + + +void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){ + if(!thePrs3d->_is_nil()) + if(VISU::Prs3d_i* aPrs3di = dynamic_cast(VISU::GetServant(thePrs3d))){ + CORBA::String_var aString = thePrs3d->GetID(); + SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(aString); + if(!CORBA::is_nil(aSObject)){ + vtkAppendFilter* anAppendFilter = vtkAppendFilter::New(); + anAppendFilter->AddInput(aPrs3di->GetPipeLine()->GetMapper()->GetInput()); + myStreamLinesPL->SetSource(anAppendFilter->GetOutput()); + anAppendFilter->Register(myStreamLinesPL); + anAppendFilter->Delete(); + aString = aSObject->GetID(); + mySourceEntry = aString.in(); + return; + } + } + myStreamLinesPL->SetSource(NULL); + mySourceEntry = ""; +} +VISU::Prs3d_ptr VISU::StreamLines_i::GetSource(){ + VISU::Prs3d_var aPrs3d; + if(MYDEBUG) MESSAGE("StreamLines_i::GetSource() mySourceEntry = '"<FindObjectID(mySourceEntry.c_str()); + CORBA::Object_var anObj = SObjectToObject(aSObject); + if(!CORBA::is_nil(anObj)) aPrs3d = VISU::Prs3d::_narrow(anObj); + } + return aPrs3d._retn(); +} + + +float VISU::StreamLines_i::GetMaxIntegrationStep(){ + return myStreamLinesPL->GetMaxIntegrationStep(); +} + + +float VISU::StreamLines_i::GetMinIntegrationStep(){ + return myStreamLinesPL->GetMinIntegrationStep(); +} + + +float VISU::StreamLines_i::GetBasePropagationTime(){ + return myStreamLinesPL->GetBasePropagationTime(); +} + + +void VISU::StreamLines_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_StreamLinesPL::New(); + myStreamLinesPL = dynamic_cast(myPipeLine); + + DeformedShape_i::DoHook(); +} diff --git a/src/VISU_I/VISU_StreamLines_i.hh b/src/VISU_I/VISU_StreamLines_i.hh new file mode 100644 index 00000000..5ead8e9b --- /dev/null +++ b/src/VISU_I/VISU_StreamLines_i.hh @@ -0,0 +1,101 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_StreamLines_i_HeaderFile +#define VISU_StreamLines_i_HeaderFile + +#include "VISU_DeformedShape_i.hh" + +class VISU_StreamLinesPL; + +namespace VISU{ + class StreamLines_i : public virtual POA_VISU::StreamLines, + public virtual DeformedShape_i + { + static int myNbPresent; + StreamLines_i(); + StreamLines_i(const StreamLines_i&); + public: + StreamLines_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const StreamLines_i* theOriginal); + virtual ~StreamLines_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TSTREAMLINES;} + + virtual void SetDirection(VISU::StreamLines::Direction theDirection); + virtual VISU::StreamLines::Direction GetDirection(); + + virtual void SetStepLength(CORBA::Double theStep); + virtual CORBA::Double GetStepLength(); + + virtual void SetPropagationTime(CORBA::Double theTime); + virtual CORBA::Double GetPropagationTime(); + + virtual void SetIntegrationStep(CORBA::Double theStep); + virtual CORBA::Double GetIntegrationStep(); + + virtual void SetUsedPoints(CORBA::Double thePercents); + virtual CORBA::Double GetUsedPoints(); + + virtual void SetSource(VISU::Prs3d_ptr thePrs3d); + virtual VISU::Prs3d_ptr GetSource(); + + typedef VISU::StreamLines TInterface; + VISU_StreamLinesPL* GetStreamLinesPL(){ return myStreamLinesPL;} + + protected: + virtual void DoHook(); + + VISU_StreamLinesPL* myStreamLinesPL; + string mySourceEntry; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual float GetMinIntegrationStep(); + virtual float GetMaxIntegrationStep(); + virtual float GetBasePropagationTime(); + + virtual QString GetSourceEntry() { return QString(mySourceEntry.c_str()); } + }; +} +#endif diff --git a/src/VISU_I/VISU_Vectors_i.cc b/src/VISU_I/VISU_Vectors_i.cc new file mode 100644 index 00000000..81a5664e --- /dev/null +++ b/src/VISU_I/VISU_Vectors_i.cc @@ -0,0 +1,198 @@ +// 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 +// +// +// File : VISU_Vectors_i.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_VectorsPL.hxx" +#include "VISU_Result_i.hh" +#include "VISU_Vectors_i.hh" +#include "VISU_VectorsAct.h" + +using namespace VISU; +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); +} + + +int VISU::Vectors_i::myNbPresent = 0; +QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);} + + +const string VISU::Vectors_i::myComment = "VECTORS"; +const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();} + + +VISU::Vectors_i::Vectors_i(Result_i* theResult, bool theAddToStudy) : + PrsObject_i(theResult->GetStudyDocument()), + Prs3d_i(theResult), + ScalarMap_i(theResult, theAddToStudy), + DeformedShape_i(theResult, theAddToStudy) +{ + myVectorsPL = NULL; +} + + +void VISU::Vectors_i::Destroy(){ + DeformedShape_i::Destroy(); +} + + +void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) { + Vectors_i* aVectors = const_cast(theOrigin); + VISU::DeformedShape_i::SameAs(theOrigin); + + SetLineWidth(aVectors->GetLineWidth()); + //SetGlyphType(aVectors->GetGlyphType()); + //SetGlyphPos(aVectors->GetGlyphPos()); +} + + +VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration) +{ + myLineWidth = 1.0; + return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration); +} + + +VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + DeformedShape_i::Restore(theMap); + + SetGlyphType(VISU::Vectors::GlyphType(VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt())); + SetGlyphPos(VISU::Vectors::GlyphPos(VISU::Storable::FindValue(theMap,"myPosGlyph").toInt())); + SetLineWidth(VISU::Storable::FindValue(theMap,"myLineWidth").toDouble()); + + return Build(true); +} + +void VISU::Vectors_i::ToStream(std::ostringstream& theStr){ + DeformedShape_i::ToStream(theStr); + + Storable::DataToStream( theStr, "myTypeGlyph", int(GetGlyphType())); + Storable::DataToStream( theStr, "myPosGlyph", int(GetGlyphPos())); + Storable::DataToStream( theStr, "myLineWidth", GetLineWidth()); +} + +VISU::Storable* VISU::Vectors_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&) +{ + VISU::Result_i* pResult = GetResult(theSObject); + if(pResult != NULL){ + VISU::Vectors_i* pResent = new VISU::Vectors_i(pResult); + return pResent->Restore(theMap); + } + return NULL; +} + + +VISU::Vectors_i::~Vectors_i(){ + if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()"); +} + + +void VISU::Vectors_i::SetLineWidth(CORBA::Double theWidth) { + myLineWidth = theWidth; +} +CORBA::Double VISU::Vectors_i::GetLineWidth() { + return myLineWidth; +} + + +void VISU::Vectors_i::SetGlyphType(VISU::Vectors::GlyphType theType) { + myVectorsPL->SetGlyphType(VISU_VectorsPL::GlyphType(theType)); +} +VISU::Vectors::GlyphType VISU::Vectors_i::GetGlyphType() { + return VISU::Vectors::GlyphType(myVectorsPL->GetGlyphType()); +} + + +void VISU::Vectors_i::SetGlyphPos(VISU::Vectors::GlyphPos thePos) { + myVectorsPL->SetGlyphPos(VISU_VectorsPL::GlyphPos(thePos)); +} +VISU::Vectors::GlyphPos VISU::Vectors_i::GetGlyphPos() { + return VISU::Vectors::GlyphPos(myVectorsPL->GetGlyphPos()); +} + + +void VISU::Vectors_i::DoHook(){ + if(!myPipeLine) myPipeLine = VISU_VectorsPL::New(); + myVectorsPL = dynamic_cast(myPipeLine); + + DeformedShape_i::DoHook(); +} + + +VISU_PipeLine* VISU::Vectors_i::GetPipeLine(){ + VISU_PipeLine* aPipeLine = VISU_VectorsPL::New(); + aPipeLine->ShallowCopy(myPipeLine); + aPipeLine->Update(); + return aPipeLine; +} + + +VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) + throw (std::runtime_error&) +{ + VISU_VectorsAct* anActor = VISU_VectorsAct::New(); + try{ + VISU::Prs3d_i::CreateActor(anActor,theIO); + anActor->SetBarVisibility(true); + anActor->myFieldName = myFieldName; + anActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); + anActor->GetProperty()->SetLineWidth(GetLineWidth()); + UpdateActor(anActor); + }catch(std::runtime_error& exc){ + anActor->Delete(); + throw exc; + } + return anActor; +} + + +void VISU::Vectors_i::UpdateActor(VISU_Actor* theActor){ + if(VISU_VectorsAct* anActor = dynamic_cast(theActor)){ + VISU::DeformedShape_i::UpdateActor(anActor); + anActor->GetProperty()->SetLineWidth(GetLineWidth()); + if(VISU_VectorsPL* aVectorsPL = dynamic_cast(anActor->GetPipeLine())){ + aVectorsPL->ShallowCopy(myPipeLine); + aVectorsPL->Update(); + aVectorsPL->SetMapScale(myVectorsPL->GetMapScale()); + } + } +} diff --git a/src/VISU_I/VISU_Vectors_i.hh b/src/VISU_I/VISU_Vectors_i.hh new file mode 100644 index 00000000..1a2322d2 --- /dev/null +++ b/src/VISU_I/VISU_Vectors_i.hh @@ -0,0 +1,92 @@ +// 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 +// +// +// File : VISU_PrsObject_i.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_Vectors_i_HeaderFile +#define VISU_Vectors_i_HeaderFile + +#include "VISU_DeformedShape_i.hh" + +class VISU_VectorsPL; + +namespace VISU{ + class Vectors_i : public virtual POA_VISU::Vectors, + public virtual DeformedShape_i + { + static int myNbPresent; + Vectors_i(); + Vectors_i(const Vectors_i&); + public: + Vectors_i(Result_i* theResult, bool theAddToStudy = true); + virtual void SameAs(const Vectors_i* theOrigin); + virtual ~Vectors_i(); + virtual void Destroy(); + + virtual VISU::VISUType GetType() { return VISU::TVECTORS;}; + + virtual void SetLineWidth(CORBA::Double theWidth); + virtual CORBA::Double GetLineWidth(); + + virtual void SetGlyphType(VISU::Vectors::GlyphType theType); + virtual VISU::Vectors::GlyphType GetGlyphType(); + + virtual void SetGlyphPos(VISU::Vectors::GlyphPos thePos); + virtual VISU::Vectors::GlyphPos GetGlyphPos(); + + typedef VISU::Vectors TInterface; + VISU_VectorsPL* GetVectorsPL(){ return myVectorsPL;} + + protected: + virtual void DoHook(); + virtual VISU_PipeLine* GetPipeLine(); + + VISU_VectorsPL *myVectorsPL; + float myLineWidth; + + public: + static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + virtual Storable* Create(const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, int theIteration); + + virtual void ToStream(std::ostringstream& theStr); + + virtual Storable* Restore(const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + static Storable* Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, const Storable::TRestoringMap& theMap) + throw(std::logic_error&); + + + static const string myComment; + virtual const char* GetComment() const; + virtual QString GenerateName(); + + virtual VISU_Actor* CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) + throw (std::runtime_error&); + virtual void UpdateActor(VISU_Actor* theActor); + }; +} +#endif diff --git a/src/VISU_SWIG/VISU_Gen_s.cc b/src/VISU_SWIG/VISU_Gen_s.cc new file mode 100644 index 00000000..1a499def --- /dev/null +++ b/src/VISU_SWIG/VISU_Gen_s.cc @@ -0,0 +1,103 @@ +// 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 +// +// +// File : VISU_Gen_s.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Gen_s.hh" + +#include "VISU_Convertor.hxx" +#include "VISU_ScalarMapPL.hxx" + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +Convertor::Convertor(const char* theFileName) : myConvertor(CreateConvertor(theFileName)){} + + +ScalarMap::ScalarMap(Convertor* theConvertor, const char* theMeshName, int theEntity, + const char* theFieldName, int theIteration) + : myScalarMap(NULL) +{ + if(VISU_Convertor* aConvertor = theConvertor->GetImpl()){ + vtkUnstructuredGrid* aDataSet = + aConvertor->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration); + if(aDataSet){ + myScalarMap = VISU_ScalarMapPL::New(); + myScalarMap->SetInput(aDataSet); + myScalarMap->Build(); + myScalarMap->Init(); + myScalarMap->SetSourceRange(); + } + } +} + + +View3D::View3D(){ + myRen = vtkRenderer::New(); + myRenWin = vtkRenderWindow::New(); + myRenWin->AddRenderer(myRen); + myRenWin->SetSize(300, 300); + myRen->Delete(); + myRen->GetActiveCamera()->ParallelProjectionOn(); + myIRen = vtkRenderWindowInteractor::New(); + myIRen->SetRenderWindow(myRenWin); + myRenWin->Delete(); +} + +void View3D::SetPosition(int theX, int theY) { + myRenWin->SetPosition(theX, theY); +} + +View3D::~View3D(){ + myIRen->Delete(); +} + +void View3D::Display(ScalarMap* theScalarMap){ + if(VISU_ScalarMapPL* aScalarMap = theScalarMap->GetImpl()){ + aScalarMap->Update(); + + myRen->RemoveAllProps(); + vtkActor* anActor = vtkActor::New(); + anActor->SetMapper(aScalarMap->GetMapper()); + + VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); + aScalarBar->SetLookupTable(aScalarMap->GetBarTable()); + + aScalarMap->Build(); + + myRen->AddActor(anActor); + myRen->AddActor2D(aScalarBar); + myRen->ResetCameraClippingRange(); + + myRenWin->Render(); + } +} diff --git a/src/VISU_SWIG/VISU_Gen_s.hh b/src/VISU_SWIG/VISU_Gen_s.hh new file mode 100644 index 00000000..ecb0c3d0 --- /dev/null +++ b/src/VISU_SWIG/VISU_Gen_s.hh @@ -0,0 +1,67 @@ +// 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 +// +// +// File : VISU_Gen_s.hh +// Author : Alexey PETROV +// Module : VISU + +#ifndef __VISU_VISU_Gen_s_H__ +#define __VISU_VISU_Gen_s_H__ + +class VISU_Convertor; +class Convertor{ + VISU_Convertor* myConvertor; +public: + Convertor() : myConvertor(0) {}; + Convertor(const char* theFileName); + + VISU_Convertor* GetImpl(){ return myConvertor;} +}; + +class VISU_ScalarMapPL; +class ScalarMap{ + VISU_ScalarMapPL* myScalarMap; +public: + ScalarMap() : myScalarMap(0) {}; + ScalarMap(Convertor* theConvertor, const char* theMeshName, int theEntity, + const char* theFieldName, int theIteration); + + VISU_ScalarMapPL* GetImpl(){ return myScalarMap;} +}; + +class vtkRenderer; +class vtkRenderWindow; +class vtkRenderWindowInteractor; +class View3D{ + vtkRenderer *myRen; + vtkRenderWindow *myRenWin; + vtkRenderWindowInteractor *myIRen; +public: + View3D(); + ~View3D(); + + void SetPosition(int theX, int theY); + void Display(ScalarMap* theScalarMap); +}; + + +#endif diff --git a/src/VISU_SWIG/visu_swig_test.py b/src/VISU_SWIG/visu_swig_test.py new file mode 100644 index 00000000..45a26744 --- /dev/null +++ b/src/VISU_SWIG/visu_swig_test.py @@ -0,0 +1,6 @@ +from libVISU_Swig import * +medFile = os.getenv('SALOME_ROOT_DIR') + '/data/fra.med' +myCon=Convertor(medFile) +myPrs=ScalarMap(myCon,"LE VOLUME",0,"VITESSE",1) +myView=View3D() +myView.Display(myPrs)