2 // File: VISU_PrsObject_i.cxx
3 // Created: Fri Jan 17 09:27:59 2003
4 // Author: Alexey PETROV
5 // <apo@ivanox.nnov.matra-dtv.fr>
8 #include "VISU_PrsObject_i.hh"
9 #include "VISU_Extractor.hxx"
10 #include "VISU_FieldTransform.hxx"
11 #include "VISU_LookupTable.hxx"
12 #include "VISU_ScalarBarActor.hxx"
13 #include "VISU_Actor.h"
16 //#include "QAD_Study.h"
17 #include "QAD_Config.h"
19 #include <vtkUnstructuredGridReader.h>
20 #include <vtkUnstructuredGridWriter.h>
22 #include <vtkDataSet.h>
23 #include <vtkDataSetMapper.h>
24 #include <vtkProperty.h>
26 #include <vtkWarpVector.h>
27 #include <vtkContourFilter.h>
28 #include <vtkAppendPolyData.h>
29 #include <vtkCutter.h>
31 #include <vtkCellDataToPointData.h>
33 #include <vtkGlyph3D.h>
34 #include <vtkHedgeHog.h>
35 #include <vtkPolyDataSource.h>
36 #include <vtkGlyphSource2D.h>
37 #include <vtkTransformPolyDataFilter.h>
38 #include <vtkCellCenters.h>
39 #include <vtkConeSource.h>
40 #include <vtkStreamLine.h>
41 #include <vtkTriangleFilter.h>
42 #include <vtkGeometryFilter.h>
43 #include <vtkFeatureEdges.h>
48 #include <OSD_Timer.hxx>
52 static int MYDEBUG = 1;
53 static int MYDEBUGWITHFILES = 0;
55 static int MYDEBUG = 0;
56 static int MYDEBUGWITHFILES = 0;
58 static float EPS = 1.0E-3;
59 const float PI2 = 2.0*PI;
61 //==============================================================================
62 void SetIOR(SALOMEDS::SObject_var& theSObject, const char* theIOR){
63 SALOMEDS::GenericAttribute_var anAttr;
64 theSObject->FindAttribute(anAttr, "AttributeIOR");
65 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
66 CORBA::String_var aValue(theIOR);
67 anIOR->SetValue(aValue);
70 float CalcScaleFactor(float theBound[6], int theNbElem){
71 float aVolume = 1, vol, idim = 0;
72 for(int i = 0; i < 6; i += 2){
73 vol = fabs(theBound[i+1] - theBound[i]);
80 float aFactor = pow(aVolume,(float)1./idim);
84 VISU::Result_i* GetResult(SALOMEDS::SObject_ptr theSObject){
85 VISU::Result_var aResult = FindResult(theSObject);
86 if(!aResult->_is_nil())
87 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(aResult.in()));
92 //==============================================================================
93 QString VISU::PrsObject_i::GetEntry() {
94 CORBA::String_var anIOR = GetID();
95 SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(anIOR);
96 CORBA::String_var anEntry = aSObject->GetID();
101 //----------------------------------------------------------------
103 //----------------------------------------------------------------
104 VISU::Prs3d_i::Prs3d_i(Result_i* theResult) :
105 PrsObject_i(theResult->GetStudyDocument()),
108 myMapper = MapperType::New();
109 myColor.R = myColorRGB[0] = 0.5;
110 myColor.G = myColorRGB[1] = 0.5;
111 myColor.B = myColorRGB[2] = 0.5;
115 void VISU::Prs3d_i::SameAs(const Prs3d_i* theOrigin)
117 SetColor(theOrigin->GetColor());
118 myMapper = MapperType::New();
119 myMapper->ShallowCopy(theOrigin->GetMapper());
122 VISU::Prs3d_i::~Prs3d_i() {
128 * Create Actor referred on existing IO
130 VISU_Actor* VISU::Prs3d_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO){
133 static float eps = VTK_LARGE_FLOAT * 0.1 ;
134 myMapper->GetBounds(bounds);
135 for (int i =0; i <6; ++i) {
136 if (fabs (bounds[i] - myBounds[i]) > eps ) {
137 MESSAGE(" Boundaries of actor do not coincide with boundaries of initial shape : \
138 error finish of VISU::Prs3d_i::CreateActor");
141 VISU_Actor* aActor = VISU_Actor::New();
142 if(myMapper->GetInput()->GetNumberOfCells() < 10)
143 aActor->IsShrinkable = false; //Bug SAL2011 Crash on shrink view
145 aActor->IsShrinkable = true;
146 aActor->SetMapper(myMapper);
149 //Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(GetEntry(),"VISU",GetName());
150 //There is a bug in gcc compiler - const Standard_CString is mapping as char * const not as const char *
151 //(where Standard_CString is defined as typedef char* Standard_CString)
152 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",
153 (const Standard_CString)GetName());
156 aActor->setIO(theIO);
158 aActor->DataSource = myMapper->GetInput();
159 aActor->Presentation = this;
160 vtkProperty* aProperty = aActor->GetProperty();
161 aProperty->SetColor(myColorRGB);
165 VISU::Storable* VISU::Prs3d_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
166 throw(std::logic_error&)
168 if(MYDEBUG) MESSAGE(GetComment());
169 myName = VISU::Storable::FindValue(theMap,"myName");
170 myColorRGB[0] = myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
171 myColorRGB[1] = myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
172 myColorRGB[2] = myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
176 void VISU::Prs3d_i::ToStream(ostrstream& theStr){
177 Storable::DataToStream( theStr, "myName", myName.c_str() );
178 Storable::DataToStream( theStr, "myColor.R", myColor.R );
179 Storable::DataToStream( theStr, "myColor.G", myColor.G );
180 Storable::DataToStream( theStr, "myColor.B", myColor.B );
183 void VISU::Prs3d_i::Update()
189 //----------------------------------------------------------------
191 //----------------------------------------------------------------
192 int VISU::Mesh_i::myNbPresent = 0;
194 QString VISU::Mesh_i::GenerateName() { return VISU::GenerateName("Mesh",myNbPresent++);}
196 const string VISU::Mesh_i::myComment = "MESH";
198 const char* VISU::Mesh_i::GetComment() const { return myComment.c_str();}
201 VISU::Mesh_i::Mesh_i(Result_i* theResult) :
202 PrsObject_i(theResult->GetStudyDocument()),
206 SALOMEDS::Color aColor = {0,1,1};
207 SetCellColor(aColor);
208 SetNodeColor(aColor);
209 SALOMEDS::Color aLinkColor = {83/255.,83/255.,83/255.};
210 SetLinkColor(aLinkColor);
213 void VISU::Mesh_i::SameAs(const Mesh_i* theOrigin)
215 VISU::Prs3d_i::SameAs(theOrigin);
216 Mesh_i* aMesh = (Mesh_i*) theOrigin;
217 SetCellColor(aMesh->GetCellColor());
218 SetNodeColor(aMesh->GetNodeColor());
219 SetLinkColor(aMesh->GetLinkColor());
220 SetPresentationType(aMesh->GetPresentationType());
221 //myName = string("Copy of ") + theOrigin->GetName();
225 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity){
226 myMeshName = theMeshName;
227 myEntity = theEntity;
232 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, int theEntity, const char* theFamilyName){
233 myMeshName = theMeshName;
234 myEntity = theEntity;
235 mySubMeshName = theFamilyName;
238 VISU::Storable* VISU::Mesh_i::Create(const char* theMeshName, const char* theGroupName){
239 myMeshName = theMeshName;
241 mySubMeshName = theGroupName;
245 VISU::Storable* VISU::Mesh_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
246 throw(std::logic_error&)
248 Prs3d_i::Restore(theMap,false);
250 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1();
251 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();
252 mySubMeshName = VISU::Storable::FindValue(theMap,"mySubMeshName").latin1();
254 myCellColor.R = VISU::Storable::FindValue(theMap,"myCellColor.R").toDouble();
255 myCellColor.G = VISU::Storable::FindValue(theMap,"myCellColor.G").toDouble();
256 myCellColor.B = VISU::Storable::FindValue(theMap,"myCellColor.B").toDouble();
258 myNodeColor.R = VISU::Storable::FindValue(theMap,"myNodeColor.R").toDouble();
259 myNodeColor.G = VISU::Storable::FindValue(theMap,"myNodeColor.G").toDouble();
260 myNodeColor.B = VISU::Storable::FindValue(theMap,"myNodeColor.B").toDouble();
262 myLinkColor.R = VISU::Storable::FindValue(theMap,"myLinkColor.R").toDouble();
263 myLinkColor.G = VISU::Storable::FindValue(theMap,"myLinkColor.G").toDouble();
264 myLinkColor.B = VISU::Storable::FindValue(theMap,"myLinkColor.B").toDouble();
271 void VISU::Mesh_i::ToStream(ostrstream& theStr){
272 Prs3d_i::ToStream(theStr);
274 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
275 Storable::DataToStream( theStr, "myEntity", myEntity );
276 Storable::DataToStream( theStr, "mySubMeshName", mySubMeshName.c_str() );
278 Storable::DataToStream( theStr, "myCellColor.R", myCellColor.R );
279 Storable::DataToStream( theStr, "myCellColor.G", myCellColor.G );
280 Storable::DataToStream( theStr, "myCellColor.B", myCellColor.B );
282 Storable::DataToStream( theStr, "myNodeColor.R", myNodeColor.R );
283 Storable::DataToStream( theStr, "myNodeColor.G", myNodeColor.G );
284 Storable::DataToStream( theStr, "myNodeColor.B", myNodeColor.B );
286 Storable::DataToStream( theStr, "myLinkColor.R", myLinkColor.R );
287 Storable::DataToStream( theStr, "myLinkColor.G", myLinkColor.G );
288 Storable::DataToStream( theStr, "myLinkColor.B", myLinkColor.B );
291 VISU::Storable* VISU::MeshRestore(SALOMEDS::SObject_ptr theSObject,
292 const string& thePrefix, const Storable::TRestoringMap& theMap)
293 throw(std::logic_error&)
295 VISU::Result_i* pResult = GetResult(theSObject);
297 VISU::Mesh_i* pResent = new VISU::Mesh_i(pResult);
298 return pResent->Restore(theMap);
304 VISU::Mesh_i::~Mesh_i(){
305 if(MYDEBUG) MESSAGE("Mesh_i::~Mesh_i()");
309 VISU::Storable* VISU::Mesh_i::Build(int theRestoring){
315 if(!theRestoring) myName = GenerateName();
317 if(mySubMeshName == "")
318 myType = VISU::TENTITY;
320 myType = VISU::TFAMILY;
322 myType = VISU::TGROUP;
323 if(MYDEBUG) MESSAGE("Mesh_i::Build - myType = "<<myType);
324 //Building Input and comment for searching according label
328 myInput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity);
329 aComment.sprintf("myComment=ENTITY;myType=%d;myResultName=%s;myMeshName=%s;myId=%d",
330 VISU::TENTITY,myResult->GetName(),myMeshName.c_str(),myEntity);
333 myInput = myResult->GetInput()->GetMeshOnEntity(myMeshName,(VISU::TEntity)myEntity,mySubMeshName);
334 aComment.sprintf("myComment=FAMILY;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s",
335 VISU::TFAMILY,myResult->GetName(),myMeshName.c_str(),myEntity,mySubMeshName.c_str());
338 myInput = myResult->GetInput()->GetMeshOnGroup(myMeshName,mySubMeshName);
339 aComment.sprintf("myComment=GROUP;myType=%d;myResultName=%s;myMeshName=%s;myName=%s",
340 VISU::TGROUP,myResult->GetName(),myMeshName.c_str(),mySubMeshName.c_str());
343 if(myInput == NULL) throw std::runtime_error("Mesh_i::Build - myInput == NULL !!!");
345 vtkUnstructuredGrid *aDataSet = myInput->GetOutput();
346 //Avoid selection points that don't belong any of cells
347 vtkGeometryFilter *aGeomFilter = vtkGeometryFilter::New();
348 aGeomFilter->SetInput(aDataSet);
349 vtkTriangleFilter *aTriangleFilter = vtkTriangleFilter::New();
350 aTriangleFilter->SetInput(aGeomFilter->GetOutput());
351 myMapper->SetInput(aTriangleFilter->GetOutput());
352 // myMapper->SetInput(aDataSet);
353 myMapper->ScalarVisibilityOff();
354 //Setting IOR on the label
356 string aResultEntry = myResult->GetEntry();
357 string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
358 if(anEntry == "") throw std::runtime_error("Mesh_i::Build - anEntry was not found !!!");
359 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(anEntry.c_str());
360 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
361 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSObj,"AttributeIOR");
362 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
363 CORBA::String_var aString = GetID();
364 anIOR->SetValue(aString);
370 aDataSet->GetBounds(myBounds);
372 }catch(std::runtime_error& exc){
373 MESSAGE("Follow exception was accured :\n"<<exc.what());
375 MESSAGE("Unknown exception was accured!");
381 VISU_Actor* VISU::Mesh_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
382 VISU_Actor* aActor = VISU::Prs3d_i::CreateActor(theIO);
383 if ( !aActor ) return NULL;
384 aActor->VisuActorType = VisuActorType_Mesh;
386 vtkProperty* aProperty = aActor->GetProperty();
387 //aProperty->SetRepresentation(TypeRepresentation);
388 aProperty->BackfaceCullingOff();
389 aProperty->EdgeVisibilityOn();
391 vtkGeometryFilter *gf = vtkGeometryFilter::New();
392 gf->SetInput(aActor->DataSource);
393 vtkFeatureEdges *edges = vtkFeatureEdges::New();
394 edges->SetInput(gf->GetOutput());
395 edges->BoundaryEdgesOn();
396 edges->ManifoldEdgesOn();
398 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
399 edgeMapper->SetInput(edges->GetOutput());
400 edgeMapper->ScalarVisibilityOff();
402 aActor->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
403 aActor->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
405 aActor->EdgeDevice->SetMapper(edgeMapper);
406 edgeMapper->Update();
408 aActor->EdgeDevice->GetProperty()->SetColor(myLinkColor.R, myLinkColor.G, myLinkColor.B);
410 aActor->EdgeDevice->VisibilityOn();
417 //==============================================================================
418 int VISU::ScalarMap_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
419 const char* theFieldName, double theIteration){
420 const VISU::TField* aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
421 if(aField == NULL) return 0;
422 const VISU::TField::TValField& aValField = aField->myValField;
423 if(aValField.find((int)theIteration) == aValField.end()) return 0;
427 int VISU::ScalarMap_i::myNbPresent = 0;
428 QString VISU::ScalarMap_i::GenerateName() { return VISU::GenerateName("ScalarMap",myNbPresent++);}
430 const string VISU::ScalarMap_i::myComment = "SCALARMAP";
431 const char* VISU::ScalarMap_i::GetComment() const { return myComment.c_str();}
433 VISU::ScalarMap_i::ScalarMap_i(Result_i* theResult, bool theAddToStudy) :
434 PrsObject_i(theResult->GetStudyDocument()),
437 myAddToStudy = theAddToStudy;
438 myInput = VISU_Extractor::New();
439 myFieldTransform = VISU_FieldTransform::New();
442 void VISU::ScalarMap_i::SameAs(const ScalarMap_i* theOrigin)
444 ScalarMap_i* aScalarMap = (ScalarMap_i*) theOrigin;
445 VISU::Prs3d_i::SameAs(aScalarMap);
446 myField = aScalarMap->GetField();
447 myMeshName = myField->myMeshName;
448 myEntity = myField->myEntity;
449 myIteration = aScalarMap->GetIteration();
450 myFieldName = aScalarMap->GetFieldName();
452 SetScalarMode(aScalarMap->GetScalarMode());
454 SetScaling(aScalarMap->GetScaling());
455 SetOrientation(aScalarMap->GetOrientation());
456 SetPosition(aScalarMap->GetPosX(), aScalarMap->GetPosY());
457 SetSize(aScalarMap->GetWidth(), aScalarMap->GetHeight());
458 SetNbColors(aScalarMap->GetNbColors());
459 SetLabels(aScalarMap->GetLabels());
460 SetTitle(aScalarMap->GetTitle());
461 //if (aScalarMap->isRangeFixed())
462 SetRange(aScalarMap->GetMin(), aScalarMap->GetMax());
465 //myScalarMode = aScalarMap->GetScalarMode();
466 //myName = string("Copy of ") + theOrigin->GetName();
471 * Creates Scalar Map and initialises it from resources
473 VISU::Storable* VISU::ScalarMap_i::Create(const char* theMeshName, VISU::Entity theEntity,
474 const char* theFieldName, CORBA::Double theIteration){
475 myIsFixedRange = false;
478 QString aOrient = QAD_CONFIG->getSetting("Visu:SBOrientation");
479 if ( !aOrient.isEmpty() )
480 myOrientation = (VISU::ScalarMap::Orientation) aOrient.toInt();
482 myOrientation = VISU::ScalarMap::VERTICAL;
485 QString aXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
486 if ( !aXorigin.isEmpty() )
487 myPosition[0] = aXorigin.toFloat();
489 if(myOrientation == VISU::ScalarMap::VERTICAL) {
490 myPosition[0] = 0.03;
496 QString aYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
497 if ( !aYorigin.isEmpty() )
498 myPosition[1] = aYorigin.toFloat();
500 if(myOrientation == VISU::ScalarMap::VERTICAL) {
503 myPosition[1] = 0.012;
508 QString aWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
509 if ( !aWidth.isEmpty() )
510 myWidth = aWidth.toFloat();
512 myWidth =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.17:0.6;
514 QString aHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
515 if ( !aHeight.isEmpty() )
516 myHeight = aHeight.toFloat();
518 myHeight =(myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12;
522 QString aColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
523 myNumberOfColors = (aColors.isEmpty())? 64 : aColors.toInt();
524 if (myNumberOfColors > 64)
525 myNumberOfColors = 64;
528 QString aLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
529 myNumberOfLabels = (aLabels.isEmpty())? 5 : aLabels.toInt();
530 if (myNumberOfLabels > 65)
531 myNumberOfLabels = 65;
534 QString aFixRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
535 myIsFixedRange = (aFixRange.compare("true") == 0);
537 QString aRangeMin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
538 myScalarRange[0] = (aRangeMin.isEmpty())? 0 : aRangeMin.toFloat();
540 QString aRangeMax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
541 myScalarRange[1] = (aRangeMax.isEmpty())? 0 : aRangeMax.toFloat();
543 QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
544 if(aScaling.compare("LOGARITHMIC") == 0)
545 myScaling = VISU::LOGARITHMIC;
547 myScaling = VISU::LINEAR;
549 // myName = GenerateName();
550 myMeshName = theMeshName;
551 myEntity = theEntity;
552 myFieldName =theFieldName;
554 myIteration = theIteration;
560 VISU::Storable* VISU::ScalarMap_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
561 throw(std::logic_error&)
563 Prs3d_i::Restore(theMap,false);
565 myMeshName = VISU::Storable::FindValue(theMap,"myMeshName");
566 myEntity = VISU::Storable::FindValue(theMap,"myEntity").toInt();
567 myFieldName = VISU::Storable::FindValue(theMap,"myFieldName");
568 myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt();
570 myScalarMode = VISU::Storable::FindValue(theMap,"myScalarMode").toInt();
571 myScalarRange[0] = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble();
572 myScalarRange[1] = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble();
573 myIsFixedRange = VISU::Storable::FindValue(theMap,"myIsFixedRange").toInt();
574 myScaling = (VISU::Scaling)VISU::Storable::FindValue(theMap,"myScaling").toInt();
576 myTitle = VISU::Storable::FindValue(theMap,"myTitle");
577 myOrientation = (VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt();
578 myNumberOfColors = VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt();
579 myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt();
580 myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
581 myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
582 myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble();
583 myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble();
590 void VISU::ScalarMap_i::ToStream(ostrstream& theStr){
591 Prs3d_i::ToStream(theStr);
593 Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() );
594 Storable::DataToStream( theStr, "myEntity", myEntity );
595 Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() );
596 Storable::DataToStream( theStr, "myIteration", myIteration );
598 Storable::DataToStream( theStr, "myScalarMode", myScalarMode );
599 Storable::DataToStream( theStr, "myScalarRange[0]", myScalarRange[0] );
600 Storable::DataToStream( theStr, "myScalarRange[1]", myScalarRange[1] );
601 Storable::DataToStream( theStr, "myIsFixedRange", myIsFixedRange );
602 Storable::DataToStream( theStr, "myScaling", myScaling );
604 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
605 Storable::DataToStream( theStr, "myOrientation", myOrientation );
606 Storable::DataToStream( theStr, "myNumberOfColors", myNumberOfColors );
607 Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels );
608 Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] );
609 Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] );
610 Storable::DataToStream( theStr, "myWidth", myWidth );
611 Storable::DataToStream( theStr, "myHeight", myHeight );
614 void VISU::ScalarMap_i::SetScaling(VISU::Scaling theScaling){
615 VISU_FieldTransform::TTransformFun aFun;
616 if(MYDEBUG) MESSAGE("ScalarMap_i::SetScaling - theScaling = "<<theScaling);
618 case VISU::LOGARITHMIC :
619 aFun = &Logarithmic10;
624 myScaling = theScaling;
625 myFieldTransform->SetTransformFunction(aFun);
627 WriteToFile(myFieldTransform->GetUnstructuredGridOutput(),(string("/tmp/")+getenv("USER")+"-PrsScaling").c_str());
630 VISU::Scaling VISU::ScalarMap_i::GetScaling(){
635 void VISU::ScalarMap_i::SetRange(CORBA::Double theMin, CORBA::Double theMax) {
636 myScalarRange[0] = theMin;
637 myScalarRange[1] = theMax;
638 myIsFixedRange = true;
640 MESSAGE("ScalarMap_i::SetRange - myScalarRange[0] = "<<myScalarRange[0]<<
641 "; myScalarRange[1] = "<<myScalarRange[1]);
645 void VISU::ScalarMap_i::CalculateRange() {
646 myIsFixedRange = false;
647 myInput->GetUnstructuredGridOutput()->GetScalarRange(myScalarRange);
649 MESSAGE("ScalarMap_i::CalculateRange - myScalarRange[0] = "<<myScalarRange[0]<<
650 "; myScalarRange[1] = "<<myScalarRange[1]);
653 void VISU::ScalarMap_i::SetScalarMode(CORBA::Long theScalarMode){
654 myScalarMode = theScalarMode;
655 vtkUnstructuredGridReader* aReader =
656 myResult->GetInput()->GetFieldOnMesh(myMeshName,(VISU::TEntity)myEntity,myFieldName,myIteration);
657 if(aReader != NULL) {
658 string aFieldName = VISU_Convertor::GenerateName(myFieldName,(int)myIteration);
659 myInput->Extract(aReader,aFieldName,myScalarMode,myField->myNbComp,myField->myEntity);
663 VISU::Storable* VISU::ScalarMapRestore(SALOMEDS::SObject_ptr theSObject,
664 const string& thePrefix, const Storable::TRestoringMap& theMap)
665 throw(std::logic_error&)
667 VISU::Result_i* pResult = GetResult(theSObject);
669 VISU::ScalarMap_i* pResent = new VISU::ScalarMap_i(pResult);
670 return pResent->Restore(theMap);
676 VISU::ScalarMap_i::~ScalarMap_i(){
677 if(MYDEBUG) MESSAGE("ScalarMap_i::~ScalarMap_i()");
679 myFieldTransform->Delete();
683 VISU::Storable* VISU::ScalarMap_i::Build(int theRestoring){
685 MESSAGE("ScalarMap_i::Build - "<<myFieldName<<"; theRestoring = "<<theRestoring);
691 myField = myResult->GetInput()->GetField(myMeshName,(VISU::TEntity)myEntity,myFieldName);
692 if(myField == NULL) throw std::runtime_error("There is no Field with the parameters !!!");
693 SetScalarMode(myScalarMode);
694 if(myInput->GetInput() == NULL) throw std::runtime_error("Can't build build vtk representation !!!");
695 vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput();
696 myFieldTransform->SetInput(aDataSet);
697 SetScaling(myScaling);
698 aDataSet->GetBounds(myBounds);
700 if (!myIsFixedRange) aDataSet->GetScalarRange(myScalarRange);
702 CORBA::String_var anIOR = GetID();
703 const VISU::TField::TValField& aValField = myField->myValField;
704 const VISU::TField::TValForTime& aValForTime = aValField.find((int)myIteration)->second;
705 const VISU::TField::TTime& aTime = aValForTime.myTime;
707 aComment.sprintf("%s, %g",myFieldName.c_str(),aTime.first);
708 myTitle = aComment.simplifyWhiteSpace();
710 myName = GenerateName();
711 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
712 VISU::TTIMESTAMP,myResult->GetName(),myMeshName.c_str(),myEntity,myFieldName.c_str(),(int)myIteration,myField->myNbComp);
713 string aResultEntry = myResult->GetEntry();
714 string aRefFatherEntry = myResult->GetRefFatherEntry();
715 string anEntry = FindEntryWithComment(myStudy,aResultEntry.c_str(),aComment.latin1());
716 if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!");
717 aComment.sprintf("myComment=%s;myResultName=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d;myComponentId=%d",
718 GetComment(),myResult->GetName(),myMeshName.c_str(),myEntity,myFieldName.c_str(),(int)myIteration,myField->myNbComp,myScalarMode);
719 CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),
720 anIOR,myName.c_str(),"",aComment.latin1(),true);
724 MESSAGE("ScalarMap_i::Build - myFieldName = "<<myFieldName<<"; myName = "<<myName<<
725 "; myScalarRange[0] = "<<myScalarRange[0]<<"; myScalarRange[1] = "<<myScalarRange[1]<<
726 "; myNumberOfColors = "<<myNumberOfColors);
728 myMapper->SetInput(DoHook(theRestoring));
729 myMapper->ScalarVisibilityOn();
735 }catch(std::runtime_error& exc){
736 MESSAGE("Follow exception was accured :\n"<<exc.what());
738 MESSAGE("Unknown exception was accured!");
744 VISU::ScalarMap_i::DataType* VISU::ScalarMap_i::DoHook(int theRestoring){
745 myMapper->ScalarVisibilityOn();
746 return myFieldTransform->GetUnstructuredGridOutput();
751 VISU_Actor* VISU::ScalarMap_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
753 VISU_LookupTable* aActorLookupTbl = VISU_LookupTable::New();
754 if(GetScaling() == VISU::LOGARITHMIC)
755 aActorLookupTbl->SetLog(true);
756 aActorLookupTbl->SetHueRange(0.667,0.0);
757 aActorLookupTbl->SetNumberOfColors(myNumberOfColors);
758 aActorLookupTbl->SetRange(myScalarRange);
759 aActorLookupTbl->SetMapScale(1.);
760 aActorLookupTbl->Build();
761 myMapper->SetLookupTable(aActorLookupTbl);
762 // if(GetScaling() == VISU::ScalarMap::LOGARITHMIC){
763 // float* aLogScalarRange = aActorLookupTbl->GetLogRange();
764 // myMapper->SetScalarRange(aLogScalarRange);
766 myMapper->SetScalarRange(myScalarRange);
767 aActorLookupTbl->Delete();
769 VISU_Actor* aActor = VISU::Prs3d_i::CreateActor(theIO);
770 if ( !aActor ) return NULL;
772 VISU_ScalarBarActor* aBar = VISU_ScalarBarActor::New();
773 VISU_LookupTable* aBarLookupTbl = VISU_LookupTable::New();
774 if(GetScaling() == VISU::LOGARITHMIC)
775 aBarLookupTbl->SetLog(true);
776 aBarLookupTbl->SetHueRange(0.667,0.0);
777 aBarLookupTbl->SetNumberOfColors(myNumberOfColors);
778 aBarLookupTbl->SetRange(myScalarRange);
779 aBarLookupTbl->Build();
780 aBar->SetLookupTable(aBarLookupTbl);
781 aBarLookupTbl->Delete();
783 aBar->SetTitle(myTitle.c_str());
784 aBar->SetOrientation(myOrientation);
785 aBar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
786 aBar->GetPositionCoordinate()->SetValue(myPosition[0],
788 aBar->SetWidth(myWidth);
789 aBar->SetHeight(myHeight);
790 aBar->SetNumberOfLabels(myNumberOfLabels);
791 aActor->setScalarBar(aBar);
793 aActor->VisuActorType = VisuActorType_ScalarMap;
794 strncpy(aActor->FieldName, myFieldName.c_str(), 40);
795 aActor->FieldName[39] = '\0';
797 vtkProperty* aProperty = aActor->GetProperty();
798 // aProperty->SetSpecularColor( 1, 1, 1);
799 // aProperty->SetSpecular( 0.3 );
800 // aProperty->SetSpecularPower( 20 );
801 // aProperty->SetAmbient( 0.2);
802 // aProperty->SetDiffuse( 0.8 );
803 aProperty->EdgeVisibilityOn();
808 //==============================================================================
809 int VISU::DeformedShape_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
810 const char* theFieldName, double theIteration){
811 if(!VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration)) return 0;
812 const VISU::TField* aField = theResult->GetInput()->GetField(theMeshName,(VISU::TEntity)theEntity,theFieldName);
813 return aField->myNbComp > 1;
816 int VISU::DeformedShape_i::myNbPresent = 0;
817 QString VISU::DeformedShape_i::GenerateName() { return VISU::GenerateName("Def.Shape",myNbPresent++);}
819 const string VISU::DeformedShape_i::myComment = "DEFORMEDSHAPE";
820 const char* VISU::DeformedShape_i::GetComment() const { return myComment.c_str();}
822 VISU::DeformedShape_i::DeformedShape_i(Result_i* theResult, bool theAddToStudy) :
823 PrsObject_i(theResult->GetStudyDocument()),
825 ScalarMap_i(theResult, theAddToStudy)
827 if(MYDEBUG) MESSAGE("DeformedShape_i::DeformedShape_i");
828 myWarpVector = vtkWarpVector::New();
832 void VISU::DeformedShape_i::SameAs(const DeformedShape_i* theOrigin)
834 DeformedShape_i* aDefShape = (DeformedShape_i*) theOrigin;
835 setColored(aDefShape->isColored());
836 VISU::ScalarMap_i::SameAs(theOrigin);
837 SetScale(aDefShape->GetScale());
841 VISU::Storable* VISU::DeformedShape_i::Create(const char* theMeshName, VISU::Entity theEntity,
842 const char* theFieldName, double theIteration){
844 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
847 VISU::Storable* VISU::DeformedShape_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
848 throw(std::logic_error&)
850 ScalarMap_i::Restore(theMap,false);
852 myFactor = VISU::Storable::FindValue(theMap,"myFactor").toDouble();
853 myIsColored = VISU::Storable::FindValue(theMap,"myIsColored").toInt();
860 void VISU::DeformedShape_i::ToStream(ostrstream& theStr){
861 ScalarMap_i::ToStream(theStr);
863 Storable::DataToStream( theStr, "myFactor", myFactor );
864 Storable::DataToStream( theStr, "myIsColored", myIsColored );
867 VISU::Storable* VISU::DeformedShapeRestore(SALOMEDS::SObject_ptr theSObject,
868 const string& thePrefix, const Storable::TRestoringMap& theMap)
869 throw(std::logic_error&)
871 VISU::Result_i* pResult = GetResult(theSObject);
873 VISU::DeformedShape_i* pResent = new VISU::DeformedShape_i(pResult);
874 return pResent->Restore(theMap);
880 VISU::DeformedShape_i::~DeformedShape_i(){
881 if(MYDEBUG) MESSAGE("DeformedShape_i::~DeformedShape_i()");
882 myWarpVector->Delete();
886 VISU::ScalarMap_i::DataType* VISU::DeformedShape_i::DoHook(int theRestoring){
888 myFactor = ScaleFactor();
890 MESSAGE("DeformedShape_i::DoHook() - myFactor = "<<myFactor);
891 if(myField->myNbComp > 1){
892 if(myField->myEntity == VISU::CELL_ENTITY){
893 vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
894 aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
895 aFilter->PassCellDataOn();
896 myWarpVector->SetInput(aFilter->GetUnstructuredGridOutput());
899 myWarpVector->SetInput(myFieldTransform->GetUnstructuredGridOutput());
901 if(GetScaling() == VISU::LOGARITHMIC)
902 myWarpVector->SetScaleFactor(log10(myFactor));
904 myWarpVector->SetScaleFactor(myFactor);
906 myMapper->ScalarVisibilityOn();
908 return myWarpVector->GetOutput();
912 float VISU::DeformedShape_i::ScaleFactor() {
913 vtkUnstructuredGrid *aDataSet = myInput->GetUnstructuredGridOutput();
914 int nbCells = aDataSet->GetNumberOfCells(), nbPoints = aDataSet->GetNumberOfPoints();
915 return ::CalcScaleFactor(myBounds, nbCells? nbCells: nbPoints);
918 void VISU::DeformedShape_i::Update(){
919 myWarpVector->SetScaleFactor(myFactor);
923 VISU_Actor* VISU::DeformedShape_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
924 VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
925 if ( ! aActor ) return NULL;
927 myMapper->ScalarVisibilityOn();
929 myMapper->ScalarVisibilityOff();
930 aActor->setScalarBar(NULL);
932 aActor->VisuActorType = VisuActorType_DeformedShape;
933 aActor->GetProperty()->SetRepresentation(1);
938 //==============================================================================
939 int VISU::CutPlanes_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
940 const char* theFieldName, double theIteration){
941 return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
944 int VISU::CutPlanes_i::myNbPresent = 0;
945 QString VISU::CutPlanes_i::GenerateName() { return VISU::GenerateName("CutPlanes",myNbPresent++);}
947 const string VISU::CutPlanes_i::myComment = "CUTPLANES";
948 const char* VISU::CutPlanes_i::GetComment() const { return myComment.c_str();}
950 VISU::CutPlanes_i::CutPlanes_i(Result_i* theResult, bool theAddToStudy) :
951 PrsObject_i(theResult->GetStudyDocument()),
953 ScalarMap_i(theResult, theAddToStudy)
955 if(MYDEBUG) MESSAGE("CutPlanes_i::CutPlanes_i");
956 myAppendPolyData = vtkAppendPolyData::New();
959 void VISU::CutPlanes_i::SameAs(const CutPlanes_i* theOrigin)
961 CutPlanes_i* aCutPlanes = (CutPlanes_i*) theOrigin;
962 SetNbPlanes(aCutPlanes->GetNbPlanes());
963 SetOrientationType(aCutPlanes->GetOrientationType());
964 SetRotateX(aCutPlanes->GetRotateX());
965 SetRotateY(aCutPlanes->GetRotateY());
967 VISU::ScalarMap_i::SameAs(theOrigin);
970 VISU::Storable* VISU::CutPlanes_i::Create(const char* theMeshName, VISU::Entity theEntity,
971 const char* theFieldName, double theIteration){
972 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
975 VISU::Storable* VISU::CutPlanes_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
976 throw(std::logic_error&)
978 ScalarMap_i::Restore(theMap,false);
980 myNbPlanes = VISU::Storable::FindValue(theMap,"myNbPlanes").toInt();
981 myBasePlane = (VISU::CutPlanes::Orientation)VISU::Storable::FindValue(theMap,"myBasePlane").toInt();
982 SetOrientationType(myBasePlane);
984 aRot[0] = VISU::Storable::FindValue(theMap,"aRot[0]").toDouble();
986 aRot[1] = VISU::Storable::FindValue(theMap,"aRot[1]").toDouble();
994 void VISU::CutPlanes_i::ToStream(ostrstream& theStr){
995 ScalarMap_i::ToStream(theStr);
997 Storable::DataToStream( theStr, "myNbPlanes", myNbPlanes );
998 Storable::DataToStream( theStr, "myBasePlane", myBasePlane );
999 Storable::DataToStream( theStr, "aRot[0]", GetRotateX() );
1000 Storable::DataToStream( theStr, "aRot[1]", GetRotateY() );
1003 VISU::Storable* VISU::CutPlanesRestore(SALOMEDS::SObject_ptr theSObject,
1004 const string& thePrefix, const Storable::TRestoringMap& theMap)
1005 throw(std::logic_error&)
1007 VISU::Result_i* pResult = GetResult(theSObject);
1008 if(pResult != NULL){
1009 VISU::CutPlanes_i* pResent = new VISU::CutPlanes_i(pResult);
1010 return pResent->Restore(theMap);
1016 VISU::CutPlanes_i::~CutPlanes_i(){
1017 if(MYDEBUG) MESSAGE("CutPlanes_i::~CutPlanes_i()");
1018 myAppendPolyData->Delete();
1021 VISU_Actor* VISU::CutPlanes_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1022 VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
1023 if (! aActor ) return NULL;
1024 aActor->VisuActorType = VisuActorType_CutPlanes;
1030 float* GetIdent(float theR[3][3]){
1031 for(int i = 0; i < 3; i++)
1032 for(int j = 0; j < 3; j++)
1033 theR[i][j] = (i==j? 1.0: 0.0);
1038 float* GetRx(float theRx[3][3], float thaAng){
1039 theRx[0][0] = 1.0; theRx[0][1] = 0.0; theRx[0][2] = 0.0;
1040 theRx[1][0] = 0.0; theRx[1][1] = cos(thaAng); theRx[1][2] = -sin(thaAng);
1041 theRx[2][0] = 0.0; theRx[2][1] = sin(thaAng); theRx[2][2] = cos(thaAng);
1046 float* GetRy(float theRy[3][3], float thaAng){
1047 theRy[0][0] = cos(thaAng); theRy[0][1] = 0.0; theRy[0][2] = sin(thaAng);
1048 theRy[1][0] = 0.0; theRy[1][1] = 1.0; theRy[1][2] = 0.0;
1049 theRy[2][0] = -sin(thaAng); theRy[2][1] = 0.0; theRy[2][2] = cos(thaAng);
1054 float* GetRz(float theRz[3][3], float thaAng){
1055 theRz[0][0] = cos(thaAng); theRz[0][1] = -sin(thaAng); theRz[0][2] = 0.0;
1056 theRz[1][0] = sin(thaAng); theRz[1][1] = cos(thaAng); theRz[1][2] = 0.0;
1057 theRz[2][0] = 0.0; theRz[2][1] = 0.0; theRz[2][2] = 1.0;
1062 void MulMatrix(float C[3][3], const float A[3][3], const float B[3][3]){ // C = A*B;
1063 for(int i = 0; i < 3; i++)
1064 for(int j = 0; j < 3; j++){
1066 for(int k = 0; k < 3; k++)
1067 C[i][j] += A[i][k]*B[k][j];
1072 float DotMul(const float A[3], const float B[3]){ // A*B;
1074 for(int i = 0; i < 3; i++) C += A[i]*B[i];
1079 void Mul(float C[3], const float A[3], float B){ // A*B;
1080 for(int i = 0; i < 3; i++) C[i] = A[i]*B;
1084 void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]){
1085 float BoundPoints[8][3] = { {BoundBox[0],BoundBox[2],BoundBox[4]},
1086 {BoundBox[1],BoundBox[2],BoundBox[4]},
1087 {BoundBox[0],BoundBox[3],BoundBox[4]},
1088 {BoundBox[1],BoundBox[3],BoundBox[4]},
1089 {BoundBox[0],BoundBox[2],BoundBox[5]},
1090 {BoundBox[1],BoundBox[2],BoundBox[5]},
1091 {BoundBox[0],BoundBox[3],BoundBox[5]},
1092 {BoundBox[1],BoundBox[3],BoundBox[5]}};
1093 BoundPrj[0] = DotMul(Dir,BoundPoints[0]), BoundPrj[1] = BoundPrj[0];
1095 for(int i = 1; i < 8; i++){
1096 tmp = DotMul(Dir,BoundPoints[i]);
1097 if(BoundPrj[1] < tmp) BoundPrj[1] = tmp;
1098 if(BoundPrj[0] > tmp) BoundPrj[0] = tmp;
1100 BoundPrj[2] = BoundPrj[1] - BoundPrj[0];
1101 BoundPrj[1] = BoundPrj[0] + (1.0 - EPS)*BoundPrj[2];
1102 BoundPrj[0] = BoundPrj[0] + EPS*BoundPrj[2];
1103 BoundPrj[2] = BoundPrj[1] - BoundPrj[0];
1106 void VISU::CutPlanes_i::SetRotateX(CORBA::Double theAng){
1107 if(myBasePlane == VISU::CutPlanes::XY)
1109 else if(myBasePlane == VISU::CutPlanes::YZ)
1111 else if(myBasePlane == VISU::CutPlanes::ZX)
1115 CORBA::Double VISU::CutPlanes_i::GetRotateX(){
1116 if(myBasePlane == VISU::CutPlanes::XY)
1118 else if(myBasePlane == VISU::CutPlanes::YZ)
1120 else if(myBasePlane == VISU::CutPlanes::ZX)
1124 void VISU::CutPlanes_i::SetRotateY(CORBA::Double theAng){
1125 if(myBasePlane == VISU::CutPlanes::XY)
1127 else if(myBasePlane == VISU::CutPlanes::YZ)
1129 else if(myBasePlane == VISU::CutPlanes::ZX)
1133 CORBA::Double VISU::CutPlanes_i::GetRotateY(){
1134 if(myBasePlane == VISU::CutPlanes::XY)
1136 else if(myBasePlane == VISU::CutPlanes::YZ)
1138 else if(myBasePlane == VISU::CutPlanes::ZX)
1142 VISU::ScalarMap_i::DataType* VISU::CutPlanes_i::DoHook(int theRestoring){
1144 myAng[0] = myAng[1] = myAng[2] = 0.0;
1146 myBasePlane = VISU::CutPlanes::XY;
1149 MESSAGE("CutPlanes_i::DoHook() - myNbPlanes = "<<myNbPlanes<<"; myBasePlane = "<<myBasePlane<<
1150 "; myAng[0] = "<<myAng[0]<<"; myAng[1] = "<<myAng[1]<<"; myAng[2] = "<<myAng[2]);
1152 myMapper->ScalarVisibilityOn();
1153 return myAppendPolyData->GetOutput();
1157 void VISU::CutPlanes_i::SetPlane(int theId){
1158 vtkCutter *aCutPlane = vtkCutter::New();
1159 aCutPlane->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1160 vtkPlane *aPlane = vtkPlane::New();
1162 Mul(aOrig,myDir,myBoundPrj[0] + theId*myDBPrj);
1163 if(MYDEBUG) MESSAGE("aOrig["<<theId<<"]: "<<aOrig[0]<<"; "<<aOrig[1]<<"; "<<aOrig[2]);
1164 aPlane->SetOrigin(aOrig);
1165 if(theId == 0) aPlane->SetNormal(myInvDir);
1166 else aPlane->SetNormal(myDir);
1167 aCutPlane->SetCutFunction(aPlane);
1169 myAppendPolyData->AddInput(aCutPlane->GetOutput());
1170 aCutPlane->Delete();
1174 void VISU::CutPlanes_i::Update(){
1175 int iEnd = myAppendPolyData->GetNumberOfInputs();
1176 if(MYDEBUG) MESSAGE("CutPlanes_i::Update - iEnd = "<<iEnd);
1177 for(int i = iEnd-1; i >= 0; i--)
1178 myAppendPolyData->RemoveInput(myAppendPolyData->GetInput(i));
1180 float aRx[3][3], aRy[3][3], aRz[3][3];
1182 if(myBasePlane == VISU::CutPlanes::XY){ // X-Y
1183 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
1184 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
1185 ::MulMatrix(myRotation,aRx,aRy);
1187 }else if(myBasePlane == VISU::CutPlanes::YZ){ // Y-Z
1188 if(fabs(myAng[1]) > EPS) ::GetRy(aRy,myAng[1]); else ::GetIdent(aRy);
1189 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
1190 ::MulMatrix(myRotation,aRy,aRz);
1192 }else if(myBasePlane == VISU::CutPlanes::ZX){ // Z-X
1193 if(fabs(myAng[2]) > EPS) ::GetRz(aRz,myAng[2]); else ::GetIdent(aRz);
1194 if(fabs(myAng[0]) > EPS) ::GetRx(aRx,myAng[0]); else ::GetIdent(aRx);
1195 ::MulMatrix(myRotation,aRz,aRx);
1198 for(int i = 0; i < 3; i++) myDir[i] = myRotation[i][iPlane];
1199 ::Mul(myInvDir,myDir,-1.0);
1200 ::GetBoundProject(myBoundPrj, myBounds, myDir);
1201 if(MYDEBUG) MESSAGE("myDir "<<myDir[0]<<"; "<<myDir[1]<<"; "<<myDir[2]);
1202 int aNbPlanes = GetNbPlanes();
1204 if (aNbPlanes > 1 ) {
1205 myDBPrj = myBoundPrj[2]/(aNbPlanes - 1);
1206 for (int i = 0; i < aNbPlanes; i++){
1211 myDBPrj = 0.5*myBoundPrj[2];
1217 //==============================================================================
1218 int VISU::IsoSurfaces_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
1219 const char* theFieldName, double theIteration){
1220 return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1223 int VISU::IsoSurfaces_i::myNbPresent = 0;
1224 QString VISU::IsoSurfaces_i::GenerateName() { return VISU::GenerateName("IsoSurfaces",myNbPresent++);}
1226 const string VISU::IsoSurfaces_i::myComment = "ISOSURFACES";
1227 const char* VISU::IsoSurfaces_i::GetComment() const { return myComment.c_str();}
1229 VISU::IsoSurfaces_i::IsoSurfaces_i(Result_i* theResult, bool theAddToStudy) :
1230 PrsObject_i(theResult->GetStudyDocument()),
1232 ScalarMap_i(theResult, theAddToStudy)
1234 if(MYDEBUG) MESSAGE("IsoSurfaces_i::IsoSurfaces_i");
1235 myContourFilter = vtkContourFilter::New();
1238 void VISU::IsoSurfaces_i::SameAs(const IsoSurfaces_i* theOrigin) {
1239 IsoSurfaces_i* aIsoSurfaces = (IsoSurfaces_i*) theOrigin;
1240 SetNbSurfaces(aIsoSurfaces->GetNbSurfaces());
1241 SetRange(aIsoSurfaces->GetRangeMin(), aIsoSurfaces->GetRangeMax());
1242 VISU::ScalarMap_i::SameAs(theOrigin);
1245 VISU::Storable* VISU::IsoSurfaces_i::Create(const char* theMeshName, VISU::Entity theEntity,
1246 const char* theFieldName, double theIteration){
1250 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1253 VISU::Storable* VISU::IsoSurfaces_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1254 throw(std::logic_error&)
1256 ScalarMap_i::Restore(theMap,false);
1258 myNbSurface = VISU::Storable::FindValue(theMap,"myNbSurface").toInt();
1259 myRange[0] = VISU::Storable::FindValue(theMap,"myRange[0]").toDouble();
1260 myRange[1] = VISU::Storable::FindValue(theMap,"myRange[1]").toDouble();
1267 void VISU::IsoSurfaces_i::ToStream(ostrstream& theStr){
1268 ScalarMap_i::ToStream(theStr);
1270 Storable::DataToStream( theStr, "myNbSurface", myNbSurface );
1271 Storable::DataToStream( theStr, "myRange[0]", myRange[0] );
1272 Storable::DataToStream( theStr, "myRange[1]", myRange[1] );
1275 VISU::Storable* VISU::IsoSurfacesRestore(SALOMEDS::SObject_ptr theSObject,
1276 const string& thePrefix, const Storable::TRestoringMap& theMap)
1277 throw(std::logic_error&)
1279 VISU::Result_i* pResult = GetResult(theSObject);
1280 if(pResult != NULL){
1281 VISU::IsoSurfaces_i* pResent = new VISU::IsoSurfaces_i(pResult);
1282 return pResent->Restore(theMap);
1288 VISU::IsoSurfaces_i::~IsoSurfaces_i(){
1289 if(MYDEBUG) MESSAGE("IsoSurfaces_i::~IsoSurfaces_i()");
1290 myContourFilter->Delete();
1294 VISU::ScalarMap_i::DataType* VISU::IsoSurfaces_i::DoHook(int theRestoring){
1296 MESSAGE("IsoSurfaces_i::DoHook() - myNbSurface = "<<myNbSurface);
1297 if(myField->myEntity == VISU::CELL_ENTITY){
1298 vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
1299 aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1300 aFilter->PassCellDataOn();
1301 myContourFilter->SetInput(aFilter->GetOutput());
1304 myContourFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1306 if ((myRange[0]==0) && (myRange[1]==0)) {
1307 myRange[0] = myScalarRange[0];
1308 myRange[1] = myScalarRange[1];
1310 if(GetScaling() == VISU::LOGARITHMIC){
1312 VISU_LookupTable::ComputeLogRange(myRange,aLogRange);
1314 MESSAGE("IsoSurfaces_i::DoHook() - aLogRange = {"<<aLogRange[0]<<", "<<aLogRange[1]<<"}");
1315 myContourFilter->GenerateValues(myNbSurface, aLogRange);
1317 myContourFilter->GenerateValues(myNbSurface, myRange);
1318 myMapper->ScalarVisibilityOn();
1319 return myContourFilter->GetOutput();
1323 void VISU::IsoSurfaces_i::Update(){
1324 if ((myRange[0]==0) && (myRange[1]==0)) {
1325 myRange[0] = myScalarRange[0];
1326 myRange[1] = myScalarRange[1];
1328 if(GetScaling() == VISU::LOGARITHMIC){
1330 VISU_LookupTable::ComputeLogRange(myRange,aLogRange);
1332 MESSAGE("IsoSurfaces_i::Update() - aLogRange = {"<<aLogRange[0]<<", "<<aLogRange[1]<<"}");
1333 myContourFilter->GenerateValues(myNbSurface, aLogRange);
1335 myContourFilter->GenerateValues(myNbSurface, myRange);
1340 VISU_Actor* VISU::IsoSurfaces_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1341 VISU_Actor* aActor = VISU::ScalarMap_i::CreateActor(theIO);
1342 if ( ! aActor ) return NULL;
1343 aActor->VisuActorType = VisuActorType_IsoSurfaces;
1347 //==============================================================================
1348 int VISU::StreamLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
1349 const char* theFieldName, double theIteration){
1350 return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1353 int VISU::StreamLines_i::myNbPresent = 0;
1354 QString VISU::StreamLines_i::GenerateName() { return VISU::GenerateName("StreamLines",myNbPresent++);}
1356 const string VISU::StreamLines_i::myComment = "STREAMLINES";
1357 const char* VISU::StreamLines_i::GetComment() const { return myComment.c_str();}
1359 VISU::StreamLines_i::StreamLines_i(Result_i* theResult, bool theAddToStudy) :
1360 PrsObject_i(theResult->GetStudyDocument()),
1362 ScalarMap_i(theResult, theAddToStudy),
1363 DeformedShape_i(theResult, theAddToStudy)
1365 if(MYDEBUG) MESSAGE("StreamLines_i::StreamLines_i");
1366 myStream = vtkStreamLine::New();
1369 VISU::Storable* VISU::StreamLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
1370 const char* theFieldName, double theIteration){
1371 myDirection = VISU::StreamLines::FORWARD;
1373 myIntegrationStep = 0.1;
1374 myPropagationTime = 100;
1375 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1378 void VISU::StreamLines_i::SameAs(const StreamLines_i* theOrigin) {
1379 StreamLines_i* aIsoLines = (StreamLines_i*) theOrigin;
1380 SetDirection(aIsoLines->GetDirection());
1381 SetStepLength(aIsoLines->GetStepLength());
1382 SetIntegrationStep(aIsoLines->GetIntegrationStep());
1383 SetPropagationTime(aIsoLines->GetPropagationTime());
1384 VISU::DeformedShape_i::SameAs(theOrigin);
1387 VISU::Storable* VISU::StreamLines_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1388 throw(std::logic_error&)
1390 DeformedShape_i::Restore(theMap,false);
1392 myStepLength = VISU::Storable::FindValue(theMap,"myStepLength").toDouble();
1393 myIntegrationStep = VISU::Storable::FindValue(theMap,"myIntegrationStep").toDouble();
1394 myPropagationTime = VISU::Storable::FindValue(theMap,"myPropagationTime").toDouble();
1395 myDirection = (VISU::StreamLines::Direction) VISU::Storable::FindValue(theMap,"myDirection").toInt();
1402 void VISU::StreamLines_i::ToStream(ostrstream& theStr){
1403 DeformedShape_i::ToStream(theStr);
1405 Storable::DataToStream( theStr, "myStepLength", myStepLength );
1406 Storable::DataToStream( theStr, "myIntegrationStep", myIntegrationStep );
1407 Storable::DataToStream( theStr, "myPropagationTime", myPropagationTime );
1408 Storable::DataToStream( theStr, "myDirection", (int)myDirection );
1412 VISU::Storable* VISU::StreamLinesRestore(SALOMEDS::SObject_ptr theSObject,
1413 const string& thePrefix, const Storable::TRestoringMap& theMap)
1414 throw(std::logic_error&)
1416 VISU::Result_i* pResult = GetResult(theSObject);
1417 if(pResult != NULL){
1418 VISU::StreamLines_i* pResent = new VISU::StreamLines_i(pResult);
1419 return pResent->Restore(theMap);
1425 VISU::StreamLines_i::~StreamLines_i(){
1426 if(MYDEBUG) MESSAGE("StreamLines_i::~StreamLines_i()");
1431 VISU::ScalarMap_i::DataType* VISU::StreamLines_i::DoHook(int theRestoring){
1432 return myStream->GetOutput();
1436 void VISU::StreamLines_i::Update(){
1437 if(myField->myNbComp > 1){
1438 if(myField->myEntity == VISU::CELL_ENTITY){
1439 //myStream->DebugOn();
1440 vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
1441 aFilter->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1442 aFilter->PassCellDataOn();
1443 myStream->SetInput(aFilter->GetOutput());
1446 vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1447 centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1448 centers->VertexCellsOn();
1449 myStream->SetSource(centers->GetOutput());
1452 myStream->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1453 myStream->SetSource(myFieldTransform->GetUnstructuredGridOutput());
1455 myStream->SetStepLength(myStepLength);
1456 myStream->SetIntegrationStepLength(myIntegrationStep);
1457 myStream->SetMaximumPropagationTime(myPropagationTime);
1458 switch (myDirection) {
1459 case VISU::StreamLines::FORWARD:
1460 myStream->SetIntegrationDirectionToForward();
1462 case VISU::StreamLines::BACKWARD:
1463 myStream->SetIntegrationDirectionToBackward();
1465 case VISU::StreamLines::BOTH:
1466 myStream->SetIntegrationDirectionToIntegrateBothDirections();
1474 VISU_Actor* VISU::StreamLines_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1475 VISU_Actor* aActor = VISU::DeformedShape_i::CreateActor(theIO);
1476 if ( ! aActor ) return NULL;
1477 aActor->VisuActorType = VisuActorType_StreamLines;
1481 //==============================================================================
1482 int VISU::Vectors_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
1483 const char* theFieldName, double theIteration){
1484 return DeformedShape_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration);
1487 int VISU::Vectors_i::myNbPresent = 0;
1488 QString VISU::Vectors_i::GenerateName() { return VISU::GenerateName("Vectors",myNbPresent++);}
1490 const string VISU::Vectors_i::myComment = "VECTORS";
1491 const char* VISU::Vectors_i::GetComment() const { return myComment.c_str();}
1493 VISU::Vectors_i::Vectors_i(Result_i* theResult, bool theAddToStudy) :
1494 PrsObject_i(theResult->GetStudyDocument()),
1496 ScalarMap_i(theResult, theAddToStudy),
1497 DeformedShape_i(theResult, theAddToStudy)
1499 if(MYDEBUG) MESSAGE("Vectors_i::Vectors_i");
1500 myGlyph = vtkGlyph3D::New();
1501 myHog = vtkHedgeHog::New();
1504 void VISU::Vectors_i::SameAs(const VISU::Vectors_i* theOrigin) {
1505 Vectors_i* aVectors = (Vectors_i*) theOrigin;
1506 SetLineWidth(aVectors->GetLineWidth());
1507 SetGlyphType(aVectors->GetGlyphType());
1508 SetGlyphPos(aVectors->GetGlyphPos());
1509 VISU::DeformedShape_i::SameAs(theOrigin);
1512 VISU::Storable* VISU::Vectors_i::Create(const char* theMeshName, VISU::Entity theEntity,
1513 const char* theFieldName, double theIteration){
1515 myTypeGlyph = VISU::Vectors::ARROW;
1516 myPosGlyph = VISU::Vectors::CENTER;
1517 return DeformedShape_i::Create(theMeshName,theEntity,theFieldName,theIteration);
1520 VISU::Storable* VISU::Vectors_i::Restore(const Storable::TRestoringMap& theMap, int theBuilding)
1521 throw(std::logic_error&)
1523 DeformedShape_i::Restore(theMap,false);
1525 myTypeGlyph = (VISU::Vectors::GlyphType)VISU::Storable::FindValue(theMap,"myTypeGlyph").toInt();
1526 myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toDouble();
1527 myPosGlyph = (VISU::Vectors::GlyphPos)VISU::Storable::FindValue(theMap,"myPosGlyph").toInt();
1534 void VISU::Vectors_i::ToStream(ostrstream& theStr){
1535 DeformedShape_i::ToStream(theStr);
1537 Storable::DataToStream( theStr, "myTypeGlyph", myTypeGlyph );
1538 Storable::DataToStream( theStr, "myLineWidth", myLineWidth );
1539 Storable::DataToStream( theStr, "myPosGlyph", myPosGlyph );
1542 VISU::Storable* VISU::VectorsRestore(SALOMEDS::SObject_ptr theSObject,
1543 const string& thePrefix, const Storable::TRestoringMap& theMap)
1544 throw(std::logic_error&)
1546 VISU::Result_i* pResult = GetResult(theSObject);
1547 if(pResult != NULL){
1548 VISU::Vectors_i* pResent = new VISU::Vectors_i(pResult);
1549 return pResent->Restore(theMap);
1555 VISU::ScalarMap_i::DataType* VISU::Vectors_i::DoHook(int theRestoring){
1557 myFactor = ScaleFactor();
1560 MESSAGE("Vectors_i::DoHook() - myFactor = "<<myFactor<<"; myTypeGlyph = "<<myTypeGlyph<<
1561 "; myLineWidth = "<<myLineWidth<<"; myPosGlyph = "<<myPosGlyph);
1562 if (myTypeGlyph == VISU::Vectors::NONE) return myHog->GetOutput();
1563 return myGlyph->GetOutput();
1566 VISU::Vectors_i::~Vectors_i(){
1567 if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
1572 VISU_Actor* VISU::Vectors_i::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) {
1573 VISU_Actor* aActor = VISU::DeformedShape_i::CreateActor(theIO);
1574 if ( ! aActor ) return NULL;
1575 aActor->VisuActorType = VisuActorType_Vectors;
1576 aActor->IsShrinkable = false;
1577 vtkProperty* aProperty = aActor->GetProperty();
1578 aProperty->SetRepresentation(2);
1579 aProperty->SetLineWidth(myLineWidth);
1583 void VISU::Vectors_i::Update() {
1584 switch (myTypeGlyph) {
1585 case VISU::Vectors::ARROW:
1587 vtkGlyphSource2D *aGlyphSource = vtkGlyphSource2D::New();
1588 aGlyphSource->SetGlyphTypeToArrow();
1589 aGlyphSource->SetFilled(0);
1590 if(myPosGlyph == VISU::Vectors::TAIL)
1591 aGlyphSource->SetCenter(0.5, 0.0, 0.0);
1592 else if(myPosGlyph == VISU::Vectors::HEAD)
1593 aGlyphSource->SetCenter(-0.5, 0.0, 0.0);
1594 myGlyph->SetSource(aGlyphSource->GetOutput());
1595 aGlyphSource->Delete();
1599 case VISU::Vectors::CONE2:
1600 case VISU::Vectors::CONE6:
1602 vtkConeSource *aGlyphSource = vtkConeSource::New(); //by default
1603 if (myTypeGlyph == VISU::Vectors::CONE6)
1604 aGlyphSource->SetResolution(7);
1606 aGlyphSource->SetResolution(3);
1607 aGlyphSource->SetHeight(.7);
1608 aGlyphSource->SetRadius(.1);
1609 vtkTransform *aTransform = vtkTransform::New();
1610 if(myPosGlyph == VISU::Vectors::TAIL)
1611 aTransform->Translate(0.5*aGlyphSource->GetHeight(),0.0,0.0);
1612 else if(myPosGlyph == VISU::Vectors::HEAD)
1613 aTransform->Translate(-0.5*aGlyphSource->GetHeight(),0.0,0.0);
1615 vtkTransformPolyDataFilter *aFilter = vtkTransformPolyDataFilter::New();
1616 aFilter->SetInput(aGlyphSource->GetOutput());
1617 aGlyphSource->Delete();
1618 aFilter->SetTransform(aTransform);
1619 aTransform->Delete();
1620 myGlyph->SetSource(aGlyphSource->GetOutput());
1624 case VISU::Vectors::NONE:
1626 if(myField->myEntity == VISU::CELL_ENTITY){
1627 vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1628 centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1629 centers->VertexCellsOn();
1630 myHog->SetInput(centers->GetOutput());
1633 myHog->SetInput(myFieldTransform->GetInput());
1635 myHog->SetScaleFactor(myFactor);
1637 myMapper->SetInput(myHog->GetOutput());
1642 if(myField->myNbComp > 1){
1643 if(myField->myEntity == VISU::CELL_ENTITY){
1644 vtkCellCenters *centers = vtkCellCenters::New(); // for vectors on cells
1645 centers->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1646 centers->VertexCellsOn();
1647 myGlyph->SetInput(centers->GetOutput());
1650 myGlyph->SetInput(myFieldTransform->GetUnstructuredGridOutput());
1651 myGlyph->SetVectorModeToUseVector();
1652 myGlyph->SetScaleFactor(2*myFactor);
1655 myMapper->SetInput(myGlyph->GetOutput());
1658 //==============================================================================