X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FVISU_I%2FVISU_PrsObject_i.cc;h=1893a1b689445f0a388ba08742a81be9dbbd484e;hb=1ffdb3278d27b8bc7761d45bf3822281f76e2dc4;hp=4595e48e2e27b2423e87c58094850c77ecf29195;hpb=cafa7b43bd370e22789fd5fb37af62caf1705fe5;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_PrsObject_i.cc b/src/VISU_I/VISU_PrsObject_i.cc index 4595e48e..1893a1b6 100644 --- a/src/VISU_I/VISU_PrsObject_i.cc +++ b/src/VISU_I/VISU_PrsObject_i.cc @@ -1,2219 +1,128 @@ -// Copyright (C) 2003 CEA/DEN, EDF R&D +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// VISU OBJECT : interactive object for VISU entities implementation // File : VISU_PrsObject_i.cxx // Author : Alexey PETROV // Module : VISU - -using namespace std; +// #include "VISU_PrsObject_i.hh" -#include "VISU_Extractor.hxx" -#include "VISU_FieldTransform.hxx" -#include "VISU_LookupTable.hxx" -#include "VISU_ScalarBarActor.hxx" -#include "VISU_Actor.h" -using namespace VISU; - -#include "QAD_Config.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef DEBUG +#ifdef _DEBUG_ static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #else static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #endif -static float EPS = 1.0E-3; -const float PI2 = 2.0*PI; - -void WriteToFile(vtkPolyData* theDataSet, const string& theFileName){ - vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); - aWriter->SetFileName(theFileName.c_str()); - aWriter->SetInput(theDataSet); - aWriter->Write(); - aWriter->Delete(); -} - -//============================================================================== -void SetIOR(SALOMEDS::SObject_var& theSObject, const char* theIOR){ - SALOMEDS::GenericAttribute_var anAttr; - theSObject->FindAttribute(anAttr, "AttributeIOR"); - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aValue(theIOR); - anIOR->SetValue(aValue); -} - -float CalcScaleFactor(float theBound[6], int theNbElem){ - float aVolume = 1, vol, idim = 0; - for(int i = 0; i < 6; i += 2){ - vol = fabs(theBound[i+1] - theBound[i]); - if(vol > 0) { - idim++; - aVolume *= vol; - } - } - aVolume /= theNbElem; - float aFactor = pow(aVolume,(float)1./idim); - return aFactor; -} - -VISU::Result_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; -} - - -//---------------------------------------------------------------- -// PrsObject -//---------------------------------------------------------------- -void VISU::PrsObject_i::SetName( const char* theName ) -{ - myName = theName; - SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() ); - if ( !mySO->_is_nil() ) { - SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute( mySO, "AttributeName" ); - SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr ); - aNameAttr->SetValue( theName ); - } -} -QString VISU::PrsObject_i::GetEntry() { - CORBA::String_var anIOR = GetID(); - SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(anIOR); - CORBA::String_var anEntry = aSObject->GetID(); - return anEntry.in(); -} - - -//---------------------------------------------------------------- -// Prs3d Object -//---------------------------------------------------------------- -VISU::Prs3d_i::Prs3d_i(Result_i* theResult) : - PrsObject_i(theResult->GetStudyDocument()), - myResult(theResult) -{ - myMapper = MapperType::New(); - myGeomFilter = vtkGeometryFilter::New(); - myGeomFilter->PointClippingOff(); - myGeomFilter->CellClippingOff(); - myGeomFilter->ExtentClippingOff(); - myGeomFilter->MergingOff(); - myColor.R = 0.5; - myColor.G = 0.5; - myColor.B = 0.5; - myAddToStudy = true; -} - -void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin) -{ - Prs3d_i* aOrigin = const_cast(theOrigin); - SetColor(aOrigin->GetColor()); - myMapper->ShallowCopy(aOrigin->GetMapper()); -} - -void VISU::Prs3d_i::SetColor(const SALOMEDS::Color& theColor){ - myColor = theColor; -} - -VISU::Prs3d_i::~Prs3d_i() { - CORBA::release(myStudy); - myMapper->Delete(); - myGeomFilter->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(); -} - - -/** - * Create Actor referred on existing IO - */ -bool VISU::Prs3d_i::CreateActor(VISU_Actor* theActor, const Handle(SALOME_InteractiveObject)& theIO){ - //MESSAGE("Prs3d_i::CreateActor"); - Update(); - myMapper->Update(); - static float eps = VTK_LARGE_FLOAT * 0.1 ; - float aLength = myMapper->GetInput()->GetLength(); - if(aLength > eps){ - MESSAGE("Prs3d_i::CreateActor >> Diagonal of the actor is too large : "<SetShrinkable(myMapper->GetInput()->GetNumberOfCells() > 10); - myMapper->SetResolveCoincidentTopologyToShiftZBuffer(); - myMapper->SetResolveCoincidentTopologyZShift(0.02); - theActor->SetMapper(myMapper); - if (myAddToStudy) { - if (theIO.IsNull()){ - //Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(GetEntry(),"VISU",GetName()); - //There is a bug in gcc compiler - const Standard_CString is mapping as char * const not as const char * - //(where Standard_CString is defined as typedef char* Standard_CString) - Handle(SALOME_InteractiveObject) anIO = - new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",(const Standard_CString)GetName()); - theActor->setIO(anIO); - }else - theActor->setIO(theIO); - } - theActor->setPrs3d(this); - return true; -} - -void VISU::Prs3d_i::UpdateActor(VISU_Actor* theActor) { - if(MYDEBUG) MESSAGE("Prs3d_i::UpdateActor"); - myMapper->Update(); - theActor->Modified(); -} - -VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - if(MYDEBUG) MESSAGE(GetComment()); - myName = (const char*)(VISU::Storable::FindValue(theMap,"myName")); - 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 this; -} - -void VISU::Prs3d_i::ToStream(std::ostringstream& theStr){ - Storable::DataToStream( theStr, "myName", myName.c_str() ); - Storable::DataToStream( theStr, "myColor.R", myColor.R ); - Storable::DataToStream( theStr, "myColor.G", myColor.G ); - Storable::DataToStream( theStr, "myColor.B", myColor.B ); -} - -void VISU::Prs3d_i::Update(){ - myMapper->Modified(); -} - - -//---------------------------------------------------------------- -// Mesh Object -//---------------------------------------------------------------- -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) -{ - myInput = NULL; - SALOMEDS::Color aColor = {0,1,1}; - SetCellColor(aColor); - SetNodeColor(aColor); - SALOMEDS::Color aLinkColor = {83/255.,83/255.,83/255.}; - SetLinkColor(aLinkColor); -} - -void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin) -{ - return; // Same as command for mesh is not valid in current architecture -// VISU::Prs3d_i::SameAs(theOrigin); -// Mesh_i* aMesh = (Mesh_i*) theOrigin; -// SetCellColor(aMesh->GetCellColor()); -// SetNodeColor(aMesh->GetNodeColor()); -// SetLinkColor(aMesh->GetLinkColor()); -// SetPresentationType(aMesh->GetPresentationType()); -// Build(false); -} - -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(); -} - -VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity){ - myMeshName = theMeshName; - myEntity = theEntity; - mySubMeshName = ""; - return Build(false); -} - -VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity, const char* theFamilyName){ - myMeshName = theMeshName; - myEntity = theEntity; - mySubMeshName = theFamilyName; - return Build(false); -} -VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){ - myMeshName = theMeshName; - myEntity = -1; - mySubMeshName = theGroupName; - return Build(false); -} - -VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - Prs3d_i::Restore(theMap,false); - - myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); - myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt(); - mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1(); - - myColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble(); - myColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble(); - myColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble(); - - myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble(); - myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble(); - myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble(); - - myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble(); - myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble(); - myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble(); - - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::Mesh_i::ToStream(std::ostringstream& theStr){ - Prs3d_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); - Storable::DataToStream( theStr, "myEntity", myEntity ); - Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() ); - - Storable::DataToStream( theStr, "myCellColor.R", myColor.R ); - Storable::DataToStream( theStr, "myCellColor.G", myColor.G ); - Storable::DataToStream( theStr, "myCellColor.B", myColor.B ); - - Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R ); - Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G ); - Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B ); - - Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R ); - Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G ); - Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B ); -} - -VISU::Storable* VISU::MeshRestore(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::Mesh_i* pResent = new VISU::Mesh_i(pResult); - return pResent->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) myName = (const char*)(GenerateName()); - if(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,(VISU::TEntity)myEntity); - aComment.sprintf("myComment=ENTITY;myType=%d;myResultName=%s;myMeshName=%s;myId=%d", - VISU::TENTITY,myResult->GetName(),myMeshName.c_str(),myEntity); - break; - case VISU::TFAMILY : - myInput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName); - aComment.sprintf("myComment=FAMILY;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s", - VISU::TFAMILY,myResult->GetName(),myMeshName.c_str(),myEntity,mySubMeshName.c_str()); - break; - case VISU::TGROUP : - myInput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName); - aComment.sprintf("myComment=GROUP;myType=%d;myResultName=%s;myMeshName=%s;myName=%s", - VISU::TGROUP,myResult->GetName(),myMeshName.c_str(),mySubMeshName.c_str()); - break; - } - if(myInput == NULL) throw std::runtime_error("Mesh_i::Build - myInput == NULL !!!"); - //Binding pipeline - vtkUnstructuredGrid *aDataSet = myInput->GetOutput(); - //Avoid selection points that don't belong any of cells - myGeomFilter->SetInput(aDataSet); - myMapper->SetInput(myGeomFilter->GetOutput()); - myMapper->ScalarVisibilityOff(); - //Setting IOR on the label - if(!theRestoring) { - 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); - } - aDataSet->GetBounds(myBounds); - if(MYDEBUGWITHFILES){ - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER"); - aFileName += "-Mesh.vtk"; - ::WriteToFile(myGeomFilter->GetOutput(),aFileName.c_str()); - } - return this; - }catch(std::runtime_error& exc){ - MESSAGE("Follow exception was accured :\n"<Delete(); - return NULL; - } -} - -void VISU::Mesh_i::UpdateActor(VISU_Actor* theActor) { - if(VISUMesh_Actor* anActor = dynamic_cast(theActor)){ - if(MYDEBUG) MESSAGE("Mesh_i::UpdateActor"); - VISU::Prs3d_i::UpdateActor(theActor); - vtkProperty* aSurfaceProperty = anActor->GetProperty(); - aSurfaceProperty->SetColor(myColor.R, myColor.G, myColor.B); - vtkProperty* anEdgeProperty = anActor->GetEdgeProperty(); - anEdgeProperty->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B); - } -} - - - -//============================================================================== -int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - try{ - const VISU::TField& aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName); - const VISU::TField::TValField& aValField = aField.myValField; - bool aRes = aValField.find((int)theIteration) != aValField.end(); - if(MYDEBUG) MESSAGE("ScalarMap_i::IsPossible = "<GetStudyDocument()), - Prs3d_i(theResult) -{ - myAddToStudy = theAddToStudy; - myInput = VISU_Extractor::New(); - myFieldTransform = VISU_FieldTransform::New(); - myMapperTable = VISU_LookupTable::New(); - myBarTable = VISU_LookupTable::New(); - myIsColored = true; - myMapScale = 1.0; -} - -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) +//--------------------------------------------------------------- +VISU::RemovableObject_i +::RemovableObject_i() { - ScalarMap_i* aScalarMap = const_cast(theOrigin); - 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()); - 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, CORBA::Double theIteration){ - myIsFixedRange = false; - // 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"); - myNumberOfColors = (aColors.isEmpty())? 64 : aColors.toInt(); - if (myNumberOfColors > 64) - myNumberOfColors = 64; - - // 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); - - QString aRangeMin = QAD_CONFIG->getSetting("Visu:SBMinimumValue"); - myScalarRange[0] = (aRangeMin.isEmpty())? 0 : aRangeMin.toFloat(); - - QString aRangeMax = QAD_CONFIG->getSetting("Visu:SBMaximumValue"); - myScalarRange[1] = (aRangeMax.isEmpty())? 0 : aRangeMax.toFloat(); - - QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling"); - if(aScaling.compare("LOGARITHMIC") == 0) - myScaling = VISU::LOGARITHMIC; - else - myScaling = VISU::LINEAR; - -// myName = GenerateName(); - myMeshName = theMeshName; - myEntity = theEntity; - myFieldName =theFieldName; - myScalarMode = 0; - myIteration = theIteration; - return Build(false); + if(MYDEBUG) MESSAGE("RemovableObject_i::RemovableObject_i - this = "<GetUnstructuredGridOutput(),aFileName.c_str()); - } -} - -VISU::Scaling VISU::ScalarMap_i::GetScaling(){ - return myScaling; -} - - -void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax) { - if(theMin > theMax) return; - myScalarRange[0] = theMin; - myScalarRange[1] = theMax; - myFieldTransform->SetScalarRange(myScalarRange); - myIsFixedRange = true; - if(MYDEBUG) MESSAGE("ScalarMap_i::SetRange = "<Update(); - myInput->GetUnstructuredGridOutput()->GetScalarRange(theRange); + if(MYDEBUG) MESSAGE("RemovableObject_i::~RemovableObject_i - this = "<GetInput()->GetFieldOnMesh(myMeshName,(VISU::TEntity)myEntity,myFieldName,(int)myIteration); - if(aReader != NULL) { - if( MYDEBUG) MESSAGE("ScalarMap_i::SetScalarMode = "<Extract(aReader,aFieldName,myScalarMode,myField->myNbComp,myField->myEntity); - if(MYDEBUGWITHFILES){ - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER"); - aFileName += "-ScalarMode.vtk"; - WriteToFile(myInput->GetUnstructuredGridOutput(),aFileName.c_str()); - } - } -} -VISU::Storable* VISU::ScalarMapRestore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, const Storable::TRestoringMap& theMap) - throw(std::logic_error&) +//--------------------------------------------------------------- +void +VISU::RemovableObject_i +::SetName(const std::string& theName, + bool theIsUpdateStudyAttr) { - VISU::Result_i* pResult = GetResult(theSObject); - if(pResult != NULL){ - 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()"); - myInput->Delete(); - myFieldTransform->Delete(); - myMapperTable->Delete(); - myBarTable->Delete(); -} - - -VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){ - if(MYDEBUG) - MESSAGE("ScalarMap_i::Build - "<GetInput() == NULL !!!"); - myField = &(myResult->GetInput()->GetField(myMeshName,(VISU::TEntity)myEntity,myFieldName)); - if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!"); - SetScalarMode(myScalarMode); - if(myInput->GetInput() == NULL) throw std::runtime_error("Can't build build vtk representation !!!"); - vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput(); - SetScaling(myScaling); - aDataSet->GetBounds(myBounds); - CORBA::String_var anIOR = GetID(); - 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 aComment; - myName = "NoName"; - if(theRestoring == 0){ - if (!myIsFixedRange) aDataSet->GetScalarRange(myScalarRange); - aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime.myTime).c_str()); - //aComment.sprintf("%s, %g",myFieldName.c_str(),aTime.first); - myTitle = (const char*)(aComment.simplifyWhiteSpace()); - } - if (myAddToStudy) { - myName = (const char*)(GenerateName()); - 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(),(int)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;myComponentId=%d", - GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),(int)myIteration,myField->myNbComp,myScalarMode); - CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(), - anIOR,myName.c_str(),"",aComment.latin1(),true); + myName = theName; + if(theIsUpdateStudyAttr){ + SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID(GetEntry().c_str()); + if(!aSObject->_is_nil()){ + SALOMEDS::StudyBuilder_var aBuilder = GetStudyDocument()->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute( aSObject, "AttributeName" ); + SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr ); + aNameAttr->SetValue( theName.c_str() ); } - if(MYDEBUG) - MESSAGE("ScalarMap_i::Build - myFieldName = "<ScalarVisibilityOn(); - Update(); - return myFieldTransform->GetUnstructuredGridOutput(); -} - -void VISU::ScalarMap_i::Update() { - if (!myIsFixedRange) CalculateRange(); - - int aScaling = GetScaling() == VISU::LOGARITHMIC? VTK_SCALE_LOG10: VTK_SCALE_LINEAR; - float aScalarRange[2] = {myScalarRange[0], myScalarRange[1]}; - myMapperTable->SetScale(VTK_SCALE_LINEAR); - if(aScaling == VTK_SCALE_LOG10) - VISU_LookupTable::ComputeLogRange(myScalarRange,aScalarRange); - myMapperTable->SetRange(aScalarRange); - myMapper->SetScalarRange(aScalarRange); - myMapperTable->SetHueRange(0.667,0.0); - myMapperTable->SetNumberOfColors(myNumberOfColors); - myMapperTable->SetMapScale(myMapScale); - myMapperTable->Build(); - myMapper->SetLookupTable(myMapperTable); - myMapper->MapScalars(1.0f); - - myBarTable->SetHueRange(0.667,0.0); - myBarTable->SetNumberOfColors(myNumberOfColors); - myBarTable->SetRange(myScalarRange); - myBarTable->SetScale(aScaling); - myBarTable->Build(); - - VISU::Prs3d_i::Update(); -} - -void VISU::ScalarMap_i::SetMapScale(double theMapScale){ - if(MYDEBUG) MESSAGE("ScalarMap_i::SetMapScale() - theMapScale = "<SetBarVisibility(&myIsColored); - anActor->myFieldName = myFieldName; - anActor->GetProperty()->EdgeVisibilityOn(); - UpdateActor(anActor); - return anActor; - }else{ - anActor->Delete(); - return NULL; - } -} - -void VISU::ScalarMap_i::UpdateActor(VISU_Actor* theActor) { - if(VISUScalarMap_Actor* anActor = dynamic_cast(theActor)){ - VISU::Prs3d_i::UpdateActor(theActor); - theActor->SetVisibility(theActor->GetVisibility()); - VISU_ScalarBarActor * aScalarBar = anActor->GetScalarBar(); - aScalarBar->SetLookupTable(myBarTable); - 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(); - } -} - - -//============================================================================== -int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - 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; -} - -int VISU::DeformedShape_i::myNbPresent = 0; -QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);} - -const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE"; -const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();} - -VISU::DeformedShape_i::DeformedShape_i(Result_i* theResult, bool theAddToStudy) : - PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult), - ScalarMap_i(theResult, theAddToStudy) -{ - if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i"); - myWarpVector = vtkWarpVector::New(); -} - -void VISU::DeformedShape_i::Destroy(){ - ScalarMap_i::Destroy(); -} - -void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin) -{ - DeformedShape_i* aDefShape = const_cast(theOrigin); - setColored(aDefShape->isColored()); - SetScale(aDefShape->GetScale()); - VISU::ScalarMap_i::SameAs(theOrigin); -} - - -VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - myIsColored = false; - return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); -} - -VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - ScalarMap_i::Restore(theMap,false); - - myFactor = VISU::Storable::FindValue(theMap,"myFactor").toDouble(); - myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt(); - - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::DeformedShape_i::ToStream(std::ostringstream& theStr){ - ScalarMap_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myFactor", myFactor ); - Storable::DataToStream( theStr, "myIsColored", myIsColored ); -} - -VISU::Storable* VISU::DeformedShapeRestore(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()"); - myWarpVector->Delete(); -} - - -VISU::ScalarMap_i::DataType* VISU::DeformedShape_i::DoHook(int theRestoring){ - if(theRestoring == 0) - myFactor = ScaleFactor()/GetMax(); - if(MYDEBUG) MESSAGE("DeformedShape_i::DoHook() - myFactor = "<GetOutput(); -} - - -float VISU::DeformedShape_i::ScaleFactor() { - vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput(); - aDataSet->Update(); - int nbCells = aDataSet->GetNumberOfCells(), nbPoints = aDataSet->GetNumberOfPoints(); - return ::CalcScaleFactor(myBounds, nbCells? nbCells: nbPoints); -} - -void VISU::DeformedShape_i::Update(){ - if(myField->myNbComp > 1){ - if(myField->myEntity == VISU::CELL_ENTITY){ - vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New(); - aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - aFilter->PassCellDataOn(); - myWarpVector->SetInput(aFilter->GetUnstructuredGridOutput()); - aFilter->Delete(); - }else - myWarpVector->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - myWarpVector->SetScaleFactor(myFactor*myMapScale); - myMapper->SetScalarVisibility(myIsColored); } - ScalarMap_i::Update(); -} - -void VISU::DeformedShape_i::SetColor(const SALOMEDS::Color& theColor){ - VISU::Prs3d_i::SetColor(theColor); - myIsColored = false; } -void VISU::DeformedShape_i::SetMapScale(double theMapScale){ - myMapScale = theMapScale; - Update(); -} -VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { - VISU_Actor* anActor = VISU::ScalarMap_i::CreateActor(theIO); - anActor->SetRepresentation(1); - return anActor; +//--------------------------------------------------------------- +std::string +VISU::RemovableObject_i +::GetName() const +{ + return myName; } -void VISU::DeformedShape_i::UpdateActor(VISU_Actor* theActor) { - VISU::ScalarMap_i::UpdateActor(theActor); - if(!myIsColored) - theActor->GetProperty()->SetColor(myColor.R,myColor.G,myColor.B); -} -//============================================================================== -int VISU::CutPlanes_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); +//--------------------------------------------------------------- +SALOMEDS::Study_var +VISU::RemovableObject_i +::GetStudyDocument() const +{ + return myStudyDocument; } -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) -{ - if(MYDEBUG) MESSAGE("CutPlanes_i::CutPlanes_i"); - myAppendPolyData = vtkAppendPolyData::New(); -} - -void VISU::CutPlanes_i::Destroy(){ - ScalarMap_i::Destroy(); +//--------------------------------------------------------------- +SalomeApp_Study* +VISU::RemovableObject_i +::GetGUIStudy() const +{ + return myGUIStudy; } -void VISU::CutPlanes_i::SameAs(const CutPlanes_i* theOrigin) -{ - CutPlanes_i* aCutPlanes = const_cast(theOrigin); - SetNbPlanes(aCutPlanes->GetNbPlanes()); - SetDisplacement(aCutPlanes->GetDisplacement()); - SetOrientationType(aCutPlanes->GetOrientationType()); - SetRotateX(aCutPlanes->GetRotateX()); - SetRotateY(aCutPlanes->GetRotateY()); - VISU::ScalarMap_i::SameAs(theOrigin); -} -VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); +//--------------------------------------------------------------- +void +VISU::RemovableObject_i +::SetStudyDocument(SALOMEDS::Study_ptr theStudy) +{ + myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); + myGUIStudy = VISU::GetGUIStudy(theStudy); } -VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - ScalarMap_i::Restore(theMap,false); - - myNbPlanes = VISU::Storable::FindValue(theMap,"myNbPlanes").toInt(); - myDisplacement = VISU::Storable::FindValue(theMap,"myDisplacement").toDouble(); - myBasePlane = (VISU::CutPlanes::Orientation)VISU::Storable::FindValue(theMap,"myBasePlane").toInt(); - SetOrientationType(myBasePlane); - float aRot[2]; - aRot[0] = VISU::Storable::FindValue(theMap,"aRot[0]").toDouble(); - SetRotateX(aRot[0]); - aRot[1] = VISU::Storable::FindValue(theMap,"aRot[1]").toDouble(); - SetRotateY(aRot[1]); - if(theBuilding) - return Build(true); - return NULL; +//--------------------------------------------------------------- +std::string +VISU::RemovableObject_i +::GetEntry() +{ + CORBA::String_var anIOR = GetID(); + SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectIOR(anIOR.in()); + CORBA::String_var anEntry(""); + if(!CORBA::is_nil(aSObject.in())) + anEntry = aSObject->GetID(); + return anEntry.in(); } -void VISU::CutPlanes_i::ToStream(std::ostringstream& theStr){ - ScalarMap_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myNbPlanes", myNbPlanes ); - Storable::DataToStream( theStr, "myDisplacement", myDisplacement ); - Storable::DataToStream( theStr, "myBasePlane", myBasePlane ); - Storable::DataToStream( theStr, "aRot[0]", GetRotateX() ); - Storable::DataToStream( theStr, "aRot[1]", GetRotateY() ); -} -VISU::Storable* VISU::CutPlanesRestore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, const Storable::TRestoringMap& theMap) - throw(std::logic_error&) +//--------------------------------------------------------------- +VISU::PrsObject_i +::PrsObject_i(SALOMEDS::Study_ptr theStudy) { - 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()"); - myAppendPolyData->Delete(); -} - - -float* GetIdent(float theR[3][3]){ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - theR[i][j] = (i==j? 1.0: 0.0); - return theR[0]; -} - - -float* 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* 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* 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 MulMatrix(float C[3][3], const float A[3][3], const float B[3][3]){ // C = A*B; - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++){ - C[i][j] = 0.0; - for(int k = 0; k < 3; k++) - C[i][j] += A[i][k]*B[k][j]; - } -} - - -void Sub(float C[3], const float A[3], float B[3]){ // AxB; - for(int i = 0; i < 3; i++) C[i] = B[i] - A[i]; -} - -float DotMul(const float A[3], const float B[3]){ // A*B; - float C = 0.0; - for(int i = 0; i < 3; i++) C += A[i]*B[i]; - return C; -} - -void Mul(float C[3], const float A[3], float B[3]){ // AxB; - C[0] = A[1]*B[2] - A[2]*B[1]; - C[1] = A[2]*B[0] - A[0]*B[2]; - C[2] = A[0]*B[1] - A[1]*B[0]; -} - -void Mul(float C[3], const float A[3], float B){ // A*B; - for(int i = 0; i < 3; i++) C[i] = A[i]*B; -} - -void CorrectPnt(float thePnt[3], const float BoundPrj[3]){ - 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 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] = DotMul(Dir,BoundPoints[0]), BoundPrj[1] = BoundPrj[0]; - float tmp; - for(int i = 1; i < 8; i++){ - tmp = DotMul(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::CutPlanes_i::SetRotateX(CORBA::Double theAng){ - if(myBasePlane == VISU::CutPlanes::XY) - myAng[0] = theAng; - else if(myBasePlane == VISU::CutPlanes::YZ) - myAng[1] = theAng; - else if(myBasePlane == VISU::CutPlanes::ZX) - myAng[2] = theAng; -} - -CORBA::Double VISU::CutPlanes_i::GetRotateX(){ - if(myBasePlane == VISU::CutPlanes::XY) - return myAng[0]; - else if(myBasePlane == VISU::CutPlanes::YZ) - return myAng[1]; - else if(myBasePlane == VISU::CutPlanes::ZX) - return myAng[2]; -} - -void VISU::CutPlanes_i::SetRotateY(CORBA::Double theAng){ - if(myBasePlane == VISU::CutPlanes::XY) - myAng[1] = theAng; - else if(myBasePlane == VISU::CutPlanes::YZ) - myAng[2] = theAng; - else if(myBasePlane == VISU::CutPlanes::ZX) - myAng[0] = theAng; -} - -CORBA::Double VISU::CutPlanes_i::GetRotateY(){ - if(myBasePlane == VISU::CutPlanes::XY) - return myAng[1]; - else if(myBasePlane == VISU::CutPlanes::YZ) - return myAng[2]; - else if(myBasePlane == VISU::CutPlanes::ZX) - return myAng[0]; -} - -void GetDir(float theDir[3], float theAng[3], - const VISU::CutPlanes::Orientation& theBasePlane) -{ - int iPlane = 0; - float aRx[3][3], aRy[3][3], aRz[3][3], aRotation[3][3]; - if(theBasePlane == VISU::CutPlanes::XY){ // X-Y - if(fabs(theAng[0]) > EPS) ::GetRx(aRx,theAng[0]); else ::GetIdent(aRx); - if(fabs(theAng[1]) > EPS) ::GetRy(aRy,theAng[1]); else ::GetIdent(aRy); - ::MulMatrix(aRotation,aRx,aRy); - iPlane = 2; - }else if(theBasePlane == VISU::CutPlanes::YZ){ // Y-Z - if(fabs(theAng[1]) > EPS) ::GetRy(aRy,theAng[1]); else ::GetIdent(aRy); - if(fabs(theAng[2]) > EPS) ::GetRz(aRz,theAng[2]); else ::GetIdent(aRz); - ::MulMatrix(aRotation,aRy,aRz); - iPlane = 0; - }else if(theBasePlane == VISU::CutPlanes::ZX){ // Z-X - if(fabs(theAng[2]) > EPS) ::GetRz(aRz,theAng[2]); else ::GetIdent(aRz); - if(fabs(theAng[0]) > EPS) ::GetRx(aRx,theAng[0]); else ::GetIdent(aRx); - ::MulMatrix(aRotation,aRz,aRx); - iPlane = 1; - } - for(int i = 0; i < 3; i++) theDir[i] = aRotation[i][iPlane]; -} - -void 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->Delete(); -} - -void CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet, - int theNbPlanes, float theDir[3], float theBounds[6], float theDisplacement) -{ - float aInvDir[3], aBoundPrj[3], aOrig[3], aPosition; - ::Mul(aInvDir,theDir,-1.0); - ::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(aDelta > 0) - aPosition = aBoundPrj[0]; - //if(fabs(aDelta) < EPS) aPosition = aBoundPrj[0]; else continue; - aDelta = (aBoundPrj[2] - aPosition) / aBoundPrj[2]; - if(aDelta < 0) - aPosition = aBoundPrj[2]; - //if(fabs(aDelta) < EPS) aPosition = aBoundPrj[2]; else continue; - Mul(aOrig,theDir,aPosition); - if(i != 0) - CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig); - else - CutWithPlane(theAppendPolyData,theDataSet,aInvDir,aOrig); - } - }else{ - aPosition = aBoundPrj[0] + aBoundPrj[2]*theDisplacement; - Mul(aOrig,theDir,aPosition); - CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig); - } -} - -VISU::ScalarMap_i::DataType* VISU::CutPlanes_i::DoHook(int theRestoring){ - if(theRestoring == 0){ - myNbPlanes = 10; - myDisplacement = 0.5; - myBasePlane = VISU::CutPlanes::XY; - myAng[0] = myAng[1] = myAng[2] = 0.0; - } - if(MYDEBUG) - MESSAGE("CutPlanes_i::DoHook() - myNbPlanes = "<GetStudyDocument()), - Prs3d_i(theResult), - ScalarMap_i(theResult, theAddToStudy) -{ - if(MYDEBUG) MESSAGE("CutLines_i::CutLines_i"); - myAppendPolyData = vtkAppendPolyData::New(); -} - -void VISU::CutLines_i::Destroy(){ - ScalarMap_i::Destroy(); -} - -void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin) -{ - CutLines_i* aCutLines = const_cast(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::ScalarMap_i::SameAs(theOrigin); -} - -VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); -} - -VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - ScalarMap_i::Restore(theMap,false); - myNbLines = VISU::Storable::FindValue(theMap,"myNbLines").toInt(); - myDisplacement[0] = VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble(); - myDisplacement[1] = VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble(); - myBasePlane[0] = (VISU::CutPlanes::Orientation)VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt(); - myBasePlane[1] = (VISU::CutPlanes::Orientation)VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt(); - SetOrientationType(myBasePlane[0]); - SetOrientationType2(myBasePlane[1]); - float aRot[2]; - aRot[0] = VISU::Storable::FindValue(theMap,"aRot[0][0]").toDouble(); - SetRotateX(aRot[0]); - aRot[1] = VISU::Storable::FindValue(theMap,"aRot[0][1]").toDouble(); - SetRotateY(aRot[1]); - aRot[0] = VISU::Storable::FindValue(theMap,"aRot[1][0]").toDouble(); - SetRotateX2(aRot[0]); - aRot[1] = VISU::Storable::FindValue(theMap,"aRot[1][1]").toDouble(); - SetRotateY2(aRot[1]); - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::CutLines_i::ToStream(std::ostringstream& theStr){ - ScalarMap_i::ToStream(theStr); - Storable::DataToStream( theStr, "myNbLines", myNbLines ); - Storable::DataToStream( theStr, "myDisplacement[0]", myDisplacement[0] ); - Storable::DataToStream( theStr, "myDisplacement[1]", myDisplacement[1] ); - Storable::DataToStream( theStr, "myBasePlane[0]", myBasePlane[0] ); - Storable::DataToStream( theStr, "myBasePlane[1]", myBasePlane[1] ); - 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::CutLinesRestore(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()"); - myAppendPolyData->Delete(); -} - -void VISU::CutLines_i::SetRotateX(CORBA::Double theAng){ - if(myBasePlane[0] == VISU::CutPlanes::XY) - myAng[0][0] = theAng; - else if(myBasePlane[0] == VISU::CutPlanes::YZ) - myAng[0][1] = theAng; - else if(myBasePlane[0] == VISU::CutPlanes::ZX) - myAng[0][2] = theAng; -} - -CORBA::Double VISU::CutLines_i::GetRotateX(){ - if(myBasePlane[0] == VISU::CutPlanes::XY) - return myAng[0][0]; - else if(myBasePlane[0] == VISU::CutPlanes::YZ) - return myAng[0][1]; - else if(myBasePlane[0] == VISU::CutPlanes::ZX) - return myAng[0][2]; -} - -void VISU::CutLines_i::SetRotateY(CORBA::Double theAng){ - if(myBasePlane[0] == VISU::CutPlanes::XY) - myAng[0][1] = theAng; - else if(myBasePlane[0] == VISU::CutPlanes::YZ) - myAng[0][2] = theAng; - else if(myBasePlane[0] == VISU::CutPlanes::ZX) - myAng[0][0] = theAng; -} - -CORBA::Double VISU::CutLines_i::GetRotateY(){ - if(myBasePlane[0] == VISU::CutPlanes::XY) - return myAng[0][1]; - else if(myBasePlane[0] == VISU::CutPlanes::YZ) - return myAng[0][2]; - else if(myBasePlane[0] == VISU::CutPlanes::ZX) - return myAng[0][0]; -} - -void VISU::CutLines_i::SetRotateX2(CORBA::Double theAng){ - if(myBasePlane[1] == VISU::CutPlanes::XY) - myAng[1][0] = theAng; - else if(myBasePlane[1] == VISU::CutPlanes::YZ) - myAng[1][1] = theAng; - else if(myBasePlane[1] == VISU::CutPlanes::ZX) - myAng[1][2] = theAng; -} - -CORBA::Double VISU::CutLines_i::GetRotateX2(){ - if(myBasePlane[1] == VISU::CutPlanes::XY) - return myAng[1][0]; - else if(myBasePlane[1] == VISU::CutPlanes::YZ) - return myAng[1][1]; - else if(myBasePlane[1] == VISU::CutPlanes::ZX) - return myAng[1][2]; -} - -void VISU::CutLines_i::SetRotateY2(CORBA::Double theAng){ - if(myBasePlane[1] == VISU::CutPlanes::XY) - myAng[1][1] = theAng; - else if(myBasePlane[1] == VISU::CutPlanes::YZ) - myAng[1][2] = theAng; - else if(myBasePlane[1] == VISU::CutPlanes::ZX) - myAng[1][0] = theAng; -} - -CORBA::Double VISU::CutLines_i::GetRotateY2(){ - if(myBasePlane[1] == VISU::CutPlanes::XY) - return myAng[1][1]; - else if(myBasePlane[1] == VISU::CutPlanes::YZ) - return myAng[1][2]; - else if(myBasePlane[1] == VISU::CutPlanes::ZX) - return myAng[1][0]; -} - -VISU::ScalarMap_i::DataType* VISU::CutLines_i::DoHook(int theRestoring){ - if(theRestoring == 0){ - myNbLines = 10; - 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; - myBasePlane[0] = VISU::CutPlanes::ZX; - myBasePlane[1] = VISU::CutPlanes::XY; - } - Update(); - return myAppendPolyData->GetOutput(); -} - -void ClearAppendPolyData(vtkAppendPolyData *theAppendPolyData){ - int iEnd = theAppendPolyData->GetNumberOfInputs(); - for(int i = iEnd-1; i >= 0; i--) - theAppendPolyData->RemoveInput(theAppendPolyData->GetInput(i)); -} - -void VISU::CutLines_i::Update(){ - ::ClearAppendPolyData(myAppendPolyData); - vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New(); - //Build base plane - float aDir[2][3]; - ::GetDir(aDir[0],myAng[0],myBasePlane[0]); - ::CutWithPlanes(anAppendPolyData,myFieldTransform->GetUnstructuredGridOutput(),1,aDir[0],myBounds,myDisplacement[0]); - anAppendPolyData->Update(); - vtkPolyData *aPolyData = anAppendPolyData->GetOutput(); - if(MYDEBUG) MESSAGE("CutPlanes_i::Update - aPolyData->GetNumberOfCells() = "<GetNumberOfCells()); - if(aPolyData->GetNumberOfCells() == 0){ - ::ClearAppendPolyData(anAppendPolyData); - vtkGeometryFilter *aGeomFilter = vtkGeometryFilter::New(); - aGeomFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - anAppendPolyData->AddInput(aGeomFilter->GetOutput()); - aGeomFilter->Delete(); - anAppendPolyData->Update(); - } - //Build lines - float aBounds[6]; - aPolyData = anAppendPolyData->GetOutput(); - aPolyData->GetBounds(aBounds); - ::GetDir(aDir[1],myAng[1],myBasePlane[1]); - ::CutWithPlanes(myAppendPolyData,aPolyData,GetNbLines(),aDir[1],aBounds,myDisplacement[1]); - anAppendPolyData->Delete(); - //Calculate values for building of table - ::Mul(myDirLn,aDir[0],aDir[1]); - ::GetBoundProject(myBoundPrjLn, myBounds, myDirLn); - Mul(myBasePnt,myDirLn,myBoundPrjLn[0]); - CorrectPnt(myBasePnt,myBounds); - myMapper->ScalarVisibilityOn(); - VISU::ScalarMap_i::Update(); -} - -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()); - - myAppendPolyData->Update(); - int iLineEnd = myAppendPolyData->GetNumberOfInputs(); - if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<GetInput(iLine); - aDataSet->Update(); - int aNbPoints = aDataSet->GetNumberOfPoints(); - if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "< 2){ - TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()}; - aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second; - 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; - aXYMap = aNewXYMap; - } - } - 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(0&& MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<myUnitNames[0].c_str(); - if(myScalarMode != 0) - aUnitName = myField->myUnitNames[myScalarMode-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()); - } -} - -//============================================================================== -int VISU::IsoSurfaces_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double 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) -{ - if(MYDEBUG) MESSAGE("IsoSurfaces_i::IsoSurfaces_i"); - myContourFilter = vtkContourFilter::New(); -} - -void VISU::IsoSurfaces_i::Destroy(){ - ScalarMap_i::Destroy(); -} - -void VISU::IsoSurfaces_i::SameAs(const IsoSurfaces_i* theOrigin) { - IsoSurfaces_i* aIsoSurfaces = const_cast(theOrigin); - SetNbSurfaces(aIsoSurfaces->GetNbSurfaces()); - SetRange(aIsoSurfaces->GetRangeMin(), aIsoSurfaces->GetRangeMax()); - VISU::ScalarMap_i::SameAs(theOrigin); -} - -VISU::Storable* VISU::IsoSurfaces_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - myNbSurface = 10; - myRange[0] = 0; - myRange[1] = 0; - return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration); -} - -VISU::Storable* VISU::IsoSurfaces_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - ScalarMap_i::Restore(theMap,false); - - myNbSurface = VISU::Storable::FindValue(theMap,"myNbSurface").toInt(); - myRange[0] = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble(); - myRange[1] = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble(); - - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::IsoSurfaces_i::ToStream(std::ostringstream& theStr){ - ScalarMap_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myNbSurface", myNbSurface ); - Storable::DataToStream( theStr, "myRange[0]", myRange[0] ); - Storable::DataToStream( theStr, "myRange[1]", myRange[1] ); -} - -VISU::Storable* VISU::IsoSurfacesRestore(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()"); - myContourFilter->Delete(); -} - -void VISU::IsoSurfaces_i::SetRange(float theMin, float theMax){ - if(theMin <= theMax){ - myRange[0] = theMin; myRange[1] = theMax; - } -} - -VISU::ScalarMap_i::DataType* VISU::IsoSurfaces_i::DoHook(int theRestoring){ - if(MYDEBUG) MESSAGE("IsoSurfaces_i::DoHook() - myNbSurface = "<GetOutput(); -} - - -void VISU::IsoSurfaces_i::Update(){ - if(myField->myEntity == VISU::CELL_ENTITY){ - vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New(); - aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - aFilter->PassCellDataOn(); - myContourFilter->SetInput(aFilter->GetOutput()); - aFilter->Delete(); - } else - myContourFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - int aNbSurface = (int)(myMapScale*myNbSurface); - if(aNbSurface < 1) aNbSurface = 1; - if(GetScaling() == VISU::LOGARITHMIC){ - float aLogRange[2]; - VISU_LookupTable::ComputeLogRange(myRange,aLogRange); - myContourFilter->GenerateValues(aNbSurface,aLogRange); - }else - myContourFilter->GenerateValues(aNbSurface,myRange); - myMapper->ScalarVisibilityOn(); - VISU::ScalarMap_i::Update(); -} - -void VISU::IsoSurfaces_i::SetMapScale(double theMapScale){ - myMapScale = theMapScale; - Update(); -} - -//============================================================================== -int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration); -} - -int VISU::StreamLines_i::myNbPresent = 0; -QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);} - -const string VISU::StreamLines_i::myComment = "STREAMLINES"; -const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();} - -VISU::StreamLines_i::StreamLines_i(Result_i* theResult, bool theAddToStudy) : - PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult), - ScalarMap_i(theResult, theAddToStudy), - DeformedShape_i(theResult, theAddToStudy) -{ - if(MYDEBUG) MESSAGE("StreamLines_i::StreamLines_i"); - myStream = vtkStreamLine::New(); -} - -void VISU::StreamLines_i::Destroy(){ - DeformedShape_i::Destroy(); -} - -VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration) -{ - return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration); -} - -void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) { - myPrs3di = NULL; - StreamLines_i* aIsoLines = const_cast(theOrigin); - SetDirection(aIsoLines->GetDirection()); - SetStepLength(aIsoLines->GetStepLength()); - SetIntegrationStep(aIsoLines->GetIntegrationStep()); - SetPropagationTime(aIsoLines->GetPropagationTime()); - VISU::DeformedShape_i::SameAs(theOrigin); - SetUsedPoints(aIsoLines->GetUsedPoints()); -} - -VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - DeformedShape_i::Restore(theMap,false); - - myStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble(); - myIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble(); - myPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble(); - myDirection = (VISU::StreamLines::Direction) VISU::Storable::FindValue(theMap,"myDirection").toInt(); - mySourceEntry = VISU::Storable::FindValue(theMap,"mySourceEntry").latin1(); - myPercents = VISU::Storable::FindValue(theMap,"myPercents").toDouble(); - myPrs3di = NULL; - - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::StreamLines_i::ToStream(std::ostringstream& theStr){ - DeformedShape_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myStepLength", myStepLength ); - Storable::DataToStream( theStr, "myIntegrationStep", myIntegrationStep ); - Storable::DataToStream( theStr, "myPropagationTime", myPropagationTime ); - Storable::DataToStream( theStr, "myDirection", (int)myDirection ); - Storable::DataToStream( theStr, "mySourceEntry", mySourceEntry.c_str()); - Storable::DataToStream( theStr, "myPercents", myPercents ); - -} - -VISU::Storable* VISU::StreamLinesRestore(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()"); - myStream->Delete(); -} - -void VISU::StreamLines_i::SetSource(VISU::Prs3d_ptr thePrs3d){ - if(thePrs3d->_is_nil()) { - myPrs3di = NULL; - mySourceEntry = ""; - } else { - myPrs3di = dynamic_cast(GetServant(thePrs3d)); - CORBA::String_var aString = thePrs3d->GetID(); - SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(aString); - aString = aSObject->GetID(); - mySourceEntry = aString.in(); - } -} - -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); - if(!aPrs3d->_is_nil()) - myPrs3di = dynamic_cast(GetServant(aPrs3d.in())); - } - } - return aPrs3d._retn(); -} - -// in this method we calculate minimal width of the dataset -// at least three integration steps could be in this width -float VISU::StreamLines_i::GetMaxIntegrationStep() { - float aMaxSizeY = fabs(myBounds[2] - myBounds[3]); - float aMaxSizeZ = fabs(myBounds[4] - myBounds[5]); - float aMinMax = fabs(myBounds[0] - myBounds[1]); - if (aMinMax < 1.0e-20 || (aMaxSizeY < aMinMax && aMaxSizeY > 1.0e-20)) aMinMax = aMaxSizeY; - if (aMinMax < 1.0e-20 || (aMaxSizeZ < aMinMax && aMaxSizeZ > 1.0e-20)) aMinMax = aMaxSizeZ; - return aMinMax / 2.0; -} - -float VISU::StreamLines_i::GetMinIntegrationStep() { - float aVolume = 1; - float degree = 0; - if (fabs(myBounds[0] - myBounds[1]) > 1.0e-20 ) { - aVolume *= fabs(myBounds[0] - myBounds[1]); - degree+=1.0; - } - if (fabs(myBounds[2] - myBounds[3]) > 1.0e-20 ) { - aVolume *= fabs(myBounds[2] - myBounds[3]); - degree+=1.0; - } - if (fabs(myBounds[4] - myBounds[5]) > 1.0e-20 ) { - aVolume *= fabs(myBounds[4] - myBounds[5]); - degree+=1.0; - } - if (degree < 0.5) return 0.0; // absolutely empty object - float anAverageVolume = aVolume / 1.0e+8; // we have to use no more, than 1GB memory (approx) - return pow((double)(anAverageVolume), (double)(1.0 / degree)); -} - -float VISU::StreamLines_i::GetBasePropagationTime() { - return myFieldTransform->GetUnstructuredGridOutput()->GetLength() / (GetMax() + GetMin()) * 2.0; -} - -VISU::ScalarMap_i::DataType* VISU::StreamLines_i::DoHook(int theRestoring){ - if(theRestoring == 0){ - myDirection = VISU::StreamLines::BOTH; - vtkDataSet *aDataSet = myFieldTransform->GetUnstructuredGridOutput(); - aDataSet->Update(); - - myIntegrationStep = GetMaxIntegrationStep() / 10.0; - float aMinMax = aDataSet->GetLength() / - (sqrt((float)(aDataSet->GetNumberOfPoints() + aDataSet->GetNumberOfCells()))+1.0); - if (aMinMax > myIntegrationStep) myIntegrationStep = (myIntegrationStep * 9.0 + aMinMax) / 10.0; - if (myIntegrationStep < GetMinIntegrationStep()) myIntegrationStep = GetMinIntegrationStep(); - - myPropagationTime = GetBasePropagationTime(); - myStepLength = myPropagationTime / 20.; - if (myStepLength > myIntegrationStep * 2) myStepLength = myIntegrationStep * 2; - if (myStepLength < myPropagationTime / 100.) myStepLength = myPropagationTime / 100.; - - myPrs3di = NULL; - myPercents = 0.3; - } - Update(); - return myStream->GetOutput(); -} - - -void SetStreamerSource(vtkStreamer *theStreamer, vtkDataSet* theDataSet, - VISU::Prs3d_i* thePrs3di, float thePercents) -{ - if(thePrs3di) - theDataSet = thePrs3di->GetMapper()->GetInput(); - theDataSet->Modified(); - theDataSet->Update(); - vtkMaskPoints *aMaskPoints = vtkMaskPoints::New(); - aMaskPoints->SetInput(theDataSet); - //aMaskPoints->RandomModeOn(); - int aNbPoints = (int)(theDataSet->GetNumberOfPoints()*thePercents); - if(MYDEBUG) MESSAGE("SetStreamerSource aNbPoints = "<GetNumberOfPoints()<<";\t"<SetMaximumNumberOfPoints(aNbPoints); - theStreamer->SetSource(aMaskPoints->GetOutput()); - aMaskPoints->Delete(); -} - -void VISU::StreamLines_i::Update(){ - //apo - myStream->DebugOn(); - VISU::Prs3d_var aPrs3d = GetSource(); - if(myField->myNbComp > 1){ - myStream->SetStepLength(myStepLength); - myStream->SetIntegrationStepLength(myIntegrationStep); - myStream->SetMaximumPropagationTime(myPropagationTime); - if(myField->myEntity == VISU::CELL_ENTITY){ - vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New(); - aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - aFilter->PassCellDataOn(); - myStream->SetInput(aFilter->GetOutput()); - aFilter->Delete(); - vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells - centers->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - centers->VertexCellsOn(); - //myStream->SetSource(centers->GetOutput()); - SetStreamerSource(myStream,centers->GetOutput(),myPrs3di,myPercents); - centers->Delete(); - }else{ - myStream->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - //myStream->SetSource(myFieldTransform->GetUnstructuredGridOutput()); - SetStreamerSource(myStream,myFieldTransform->GetUnstructuredGridOutput(),myPrs3di,myPercents); - } - switch (myDirection) { - case VISU::StreamLines::FORWARD: - myStream->SetIntegrationDirectionToForward(); - break; - case VISU::StreamLines::BACKWARD: - myStream->SetIntegrationDirectionToBackward(); - break; - case VISU::StreamLines::BOTH: - myStream->SetIntegrationDirectionToIntegrateBothDirections(); - } - } - myStream->Modified(); - VISU::DeformedShape_i::Update(); -} - -//============================================================================== -int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double 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) -{ - if(MYDEBUG) MESSAGE("Vectors_i::Vectors_i"); - myGlyph = vtkGlyph3D::New(); - myHog = vtkHedgeHog::New(); -} - -void VISU::Vectors_i::Destroy(){ - DeformedShape_i::Destroy(); -} - -void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) { - Vectors_i* aVectors = const_cast(theOrigin); - SetLineWidth(aVectors->GetLineWidth()); - SetGlyphType(aVectors->GetGlyphType()); - SetGlyphPos(aVectors->GetGlyphPos()); - VISU::DeformedShape_i::SameAs(theOrigin); -} - -VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, double theIteration){ - myLineWidth = 1.0; - myTypeGlyph = VISU::Vectors::ARROW; - myPosGlyph = VISU::Vectors::CENTER; - return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration); -} - -VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding) - throw(std::logic_error&) -{ - DeformedShape_i::Restore(theMap,false); - - myTypeGlyph = (VISU::Vectors::GlyphType)VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt(); - myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toDouble(); - myPosGlyph = (VISU::Vectors::GlyphPos)VISU::Storable::FindValue(theMap,"myPosGlyph").toInt(); - - if(theBuilding) - return Build(true); - return NULL; -} - -void VISU::Vectors_i::ToStream(std::ostringstream& theStr){ - DeformedShape_i::ToStream(theStr); - - Storable::DataToStream( theStr, "myTypeGlyph", myTypeGlyph ); - Storable::DataToStream( theStr, "myLineWidth", myLineWidth ); - Storable::DataToStream( theStr, "myPosGlyph", myPosGlyph ); -} - -VISU::Storable* VISU::VectorsRestore(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::ScalarMap_i::DataType* VISU::Vectors_i::DoHook(int theRestoring){ - if(theRestoring == 0){ - myTypeGlyph = VISU::Vectors::ARROW; - myLineWidth = 1; - myPosGlyph = VISU::Vectors::TAIL; - myFactor = ScaleFactor()/GetMax(); - } - if(MYDEBUG) - MESSAGE("Vectors_i::DoHook() - myFactor = "<Delete(); - myHog->Delete(); -} - -void VISU::Vectors_i::Update() { - switch (myTypeGlyph) { - case VISU::Vectors::ARROW: - { - vtkGlyphSource2D *aGlyphSource = vtkGlyphSource2D::New(); - aGlyphSource->SetGlyphTypeToArrow(); - aGlyphSource->SetFilled(0); - if(myPosGlyph == VISU::Vectors::TAIL) - aGlyphSource->SetCenter(0.5, 0.0, 0.0); - else if(myPosGlyph == VISU::Vectors::HEAD) - aGlyphSource->SetCenter(-0.5, 0.0, 0.0); - myGlyph->SetSource(aGlyphSource->GetOutput()); - aGlyphSource->Delete(); - } - break; - - case VISU::Vectors::CONE2: - case VISU::Vectors::CONE6: - { - vtkConeSource *aGlyphSource = vtkConeSource::New(); //by default - if (myTypeGlyph == VISU::Vectors::CONE6) - aGlyphSource->SetResolution(7); - else - aGlyphSource->SetResolution(3); - aGlyphSource->SetHeight(1.0); - aGlyphSource->SetRadius(.1); - vtkTransform *aTransform = vtkTransform::New(); - - if(myPosGlyph == VISU::Vectors::TAIL) - aGlyphSource->SetCenter(0.5, 0.0, 0.0); - else if(myPosGlyph == VISU::Vectors::HEAD) - aGlyphSource->SetCenter(-0.5, 0.0, 0.0); - - vtkTransformPolyDataFilter *aFilter = vtkTransformPolyDataFilter::New(); - aFilter->SetInput(aGlyphSource->GetOutput()); - aGlyphSource->Delete(); - aFilter->SetTransform(aTransform); - aTransform->Delete(); - myGlyph->SetSource(aGlyphSource->GetOutput()); - aFilter->Delete(); - } - break; - case VISU::Vectors::NONE: - { - if(myField->myEntity == VISU::CELL_ENTITY){ - vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells - centers->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - centers->VertexCellsOn(); - myHog->SetInput(centers->GetOutput()); - centers->Delete(); - }else - myHog->SetInput(myFieldTransform->GetInput()); - - myHog->SetScaleFactor(myFactor); - myHog->Update(); - myMapper->SetInput(myHog->GetOutput()); - myMapper->Update(); - return; - } - } - if(myField->myNbComp > 1){ - if(myField->myEntity == VISU::CELL_ENTITY){ - vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells - centers->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - centers->VertexCellsOn(); - myGlyph->SetInput(centers->GetOutput()); - centers->Delete(); - }else - myGlyph->SetInput(myFieldTransform->GetUnstructuredGridOutput()); - myGlyph->SetVectorModeToUseVector(); - myGlyph->SetScaleModeToScaleByVector(); - //myGlyph->SetColorModeToColorByVector(); - myGlyph->SetColorModeToColorByScalar(); - myGlyph->SetScaleFactor(2*myFactor); - } - myGlyph->Modified(); - VISU::DeformedShape_i::Update(); -} - -VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { - VISU_Actor* anActor = VISU::DeformedShape_i::CreateActor(theIO); - return anActor; -} - -void VISU::Vectors_i::UpdateActor(VISU_Actor* theActor) { - VISU::DeformedShape_i::UpdateActor(theActor); - theActor->GetProperty()->SetLineWidth(myLineWidth); - theActor->GetProperty()->SetRepresentation(2); - theActor->SetShrinkable(false); + SetStudyDocument(theStudy); } -//==============================================================================