- 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 = "<<myNbPlanes<<"; myBasePlane = "<<myBasePlane<<
- "; myAng[0] = "<<myAng[0]<<"; myAng[1] = "<<myAng[1]<<"; myAng[2] = "<<myAng[2]);
- Update();
- return myAppendPolyData->GetOutput();
-}
-
-void VISU::CutPlanes_i::Update(){
- int iEnd = myAppendPolyData->GetNumberOfInputs();
- if(MYDEBUG) MESSAGE("CutPlanes_i::Update - iEnd = "<<iEnd);
- for(int i = iEnd-1; i >= 0; i--)
- myAppendPolyData->RemoveInput(myAppendPolyData->GetInput(i));
- float aDir[3];
- ::GetDir(aDir,myAng,myBasePlane);
- vtkDataSet* aDataSet = myFieldTransform->GetUnstructuredGridOutput();
- ::CutWithPlanes(myAppendPolyData,aDataSet,GetNbPlanes(),aDir,myBounds,myDisplacement);
- myMapper->ScalarVisibilityOn();
- VISU::ScalarMap_i::Update();
-}
-
-//==============================================================================
-int VISU::CutLines_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::CutLines_i::myNbPresent = 0;
-QString VISU::CutLines_i::GenerateName() { return VISU::GenerateName("CutLines",myNbPresent++);}
-
-const string VISU::CutLines_i::myComment = "CUTLINES";
-const char* VISU::CutLines_i::GetComment() const { return myComment.c_str();}
-
-VISU::CutLines_i::CutLines_i(Result_i* theResult, bool theAddToStudy) :
- PrsObject_i(theResult->GetStudyDocument()),
- Prs3d_i(theResult),
- ScalarMap_i(theResult, theAddToStudy)
-{
- 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<CutLines_i*>(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() = "<<aPolyData->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<long> TLineCont;
- typedef map<float,TLineCont> TXMap;
- typedef map<float,float> TXYMap;
- typedef vector<TXYMap> 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 = "<<iLineEnd);
- TCurveVect aCurveVect(iLineEnd);
- TLineCont aLineCont;
- TXMap aXMap;
- for(int iLine = 0; iLine < iLineEnd; iLine++){
- vtkDataSet *aDataSet = myAppendPolyData->GetInput(iLine);
- aDataSet->Update();
- int aNbPoints = aDataSet->GetNumberOfPoints();
- if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "<<iLine<<"; aNbPoints = "<<aNbPoints);
- vtkPointData *aPointData = aDataSet->GetPointData();
- vtkDataArray *aScalars = aPointData->GetScalars();
- vtkCellDataToPointData *aFilter = NULL;
- if(!aScalars) {
- aFilter = vtkCellDataToPointData::New();
- aFilter->SetInput(aDataSet);
- aFilter->PassCellDataOn();
- aDataSet = aFilter->GetOutput();
- aDataSet->Update();
- }
- aPointData = aDataSet->GetPointData();
- aScalars = aPointData->GetScalars();
- if(!aScalars) continue;
- aLineCont.insert(iLine);
- TXYMap& aXYMap = aCurveVect[iLine];
- float aPnt[3], aVect[3], aDist;
- for(int i = 0; i < aNbPoints; i++){
- aDataSet->GetPoint(i,aPnt);
- Sub(aVect,myBasePnt,aPnt);
- aDist = DotMul(aVect,myDirLn) / myBoundPrjLn[2];
- // the workaround
- if(aDist < 0.0) aDist = 0.0;
- if(aDist > 1.0) aDist = 1.0;
- aXYMap[aDist] = aScalars->GetTuple1(i);
- //aXMap[aDist].insert(iLine);
- }
- if(aFilter) aFilter->Delete();
- }
- iLineEnd = aLineCont.size();
- if(iLineEnd == 0){
- MESSAGE("CutPlanes_i::BuildTableOfReal aLineCont.size() == 0 !!!");
- return;
- }
- //Resorting of theXYMap
- for(int iLine = 0; iLine < iLineEnd; iLine++){
- TXYMap& aXYMap = aCurveVect[iLine], aNewXYMap;
- if(aXYMap.size() > 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 = "<<aDist<<"; jEnd = "<<jEnd);
- TLineCont::const_iterator aLineContIter = aLineCont.begin();
- for(; aLineContIter != aLineCont.end(); aLineContIter++){
- long iLine = *aLineContIter;
- const TXYMap& aXYMap = aCurveVect[iLine];
- TXYMap::const_iterator aXYMapIter = aXYMap.find(aDist);
- if(aXYMapIter == aXYMap.end()) continue;
- float aVal = aXYMapIter->second;
- aTableOfReal->PutValue(aVal,iLine+2,i+1);
- }
- }
-
- aTableOfReal->SetRowTitle(1,"X");
- TLineCont::const_iterator aLineContIter = aLineCont.begin();
- QString aUnitName = myField->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<IsoSurfaces_i*>(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 = "<<myNbSurface);
- if(theRestoring == 0) {
- myRange[0] = myScalarRange[0];
- myRange[1] = myScalarRange[1];
- }
- Update();
- return myContourFilter->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<StreamLines_i*>(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<VISU::Prs3d_i*>(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 = '"<<mySourceEntry<<"'");
- if(mySourceEntry != ""){
- SALOMEDS::SObject_var aSObject = myStudy->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<VISU::Prs3d_i*>(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 = "<<theDataSet->GetNumberOfPoints()<<";\t"<<aNbPoints);
- aMaskPoints->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<Vectors_i*>(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 = "<<myFactor<<"; myTypeGlyph = "<<myTypeGlyph<<
- "; myLineWidth = "<<myLineWidth<<"; myPosGlyph = "<<myPosGlyph);
- Update();
- if (myTypeGlyph == VISU::Vectors::NONE) return myHog->GetOutput();
- return myGlyph->GetOutput();
-}
-
-VISU::Vectors_i::~Vectors_i(){
- if(MYDEBUG) MESSAGE("Vectors_i::~Vectors_i()");
- myGlyph->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);