From 8d940463ce40a2f39c93e30fc0c773beaaf3587f Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 3 May 2005 12:53:26 +0000 Subject: [PATCH] PostPro 2005, T1.5: 2D fields displayed in 3D. Add GetBasePlane(), GetMinMaxPosition() and methods about presentation type --- src/PIPELINE/VISU_Plot3DPL.cxx | 141 +++++++++++++++++++++++---------- src/PIPELINE/VISU_Plot3DPL.hxx | 14 +++- 2 files changed, 112 insertions(+), 43 deletions(-) diff --git a/src/PIPELINE/VISU_Plot3DPL.cxx b/src/PIPELINE/VISU_Plot3DPL.cxx index 2f78d530..920e6427 100644 --- a/src/PIPELINE/VISU_Plot3DPL.cxx +++ b/src/PIPELINE/VISU_Plot3DPL.cxx @@ -52,9 +52,10 @@ VISU_Plot3DPL::VISU_Plot3DPL(): myWarpScalar(vtkWarpScalar::New(),true), myOrientation(VISU_CutPlanesPL::YZ), myIsRelative(true), + myIsContour(false), myPosition(0.5) { - myAngle[0] = myAngle[1] = myAngle[2]; + myAngle[0] = myAngle[1] = myAngle[2] = 0.; SetNumberOfContours(32); } @@ -67,8 +68,15 @@ VISU_Plot3DPL:: ShallowCopy(VISU_PipeLine *thePipeLine) { VISU_ScalarMapPL::ShallowCopy(thePipeLine); - //if(VISU_Plot3DPL *aPipeLine = dynamic_cast(thePipeLine)){ - //} + if(VISU_Plot3DPL *aPipeLine = dynamic_cast(thePipeLine)){ + SetOrientation (aPipeLine->GetPlaneOrientation(), + aPipeLine->GetRotateX(), aPipeLine->GetRotateY()); + SetPlanePosition (aPipeLine->GetPlanePosition(), + aPipeLine->IsPositionRelative() ); + SetScaleFactor( aPipeLine->GetScaleFactor() ); + SetContourPrs( aPipeLine->GetIsContourPrs() ); + SetNumberOfContours( aPipeLine->GetNumberOfContours() ); + } } VISU_CutPlanesPL::PlaneOrientation @@ -107,13 +115,13 @@ VISU_Plot3DPL:: GetScaleFactor(vtkDataSet* theDataSet) { theDataSet->Update(); - float aLength = theDataSet->GetLength(); + float aLength = theDataSet->GetLength(); // diagonal length float aScalarRange[2]; GetSourceRange(aScalarRange); static float EPS = 0.3; - float aRange = aScalarRange[1] - aScalarRange[0]; + float aRange = aScalarRange[1]; if(aRange > 0.0) return aLength / aRange * EPS; @@ -141,19 +149,9 @@ void VISU_Plot3DPL:: Update() { - VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData); - - float aDir[3]; - VISU_CutPlanesPL::GetDir(aDir,myAngle,myOrientation); - - float aBounds[6]; - GetInput2()->GetBounds(aBounds); - - float aBoundPrj[3]; - VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aDir); - + float aPlaneNormal[3]; float anOrigin[3]; - VISU::Mul(aDir,GetPlanePosition(),anOrigin); + GetBasePlane( anOrigin, aPlaneNormal ); vtkUnstructuredGrid* anUnstructuredGrid = myFieldTransform->GetUnstructuredGridOutput(); @@ -162,36 +160,44 @@ Update() vtkPlane *aPlane = vtkPlane::New(); aPlane->SetOrigin(anOrigin); - aPlane->SetNormal(aDir); + aPlane->SetNormal(aPlaneNormal); aCutPlane->SetCutFunction(aPlane); aPlane->Delete(); + VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData); + vtkPolyData* aPolyData = aCutPlane->GetOutput(); aPolyData->Update(); + if(aPolyData->GetNumberOfCells() == 0){ myGeometryFilter->SetInput(anUnstructuredGrid); aPolyData = myGeometryFilter->GetOutput(); } - myWarpScalar->SetInput(aPolyData); + if ( !myIsContour ) // surface prs + { + myWarpScalar->SetInput(aPolyData); + } + else // contour prs + { + if(aPolyData->GetCellData()->GetNumberOfArrays()) { + myCellDataToPointData->SetInput(aPolyData); + myCellDataToPointData->PassCellDataOn(); + myContourFilter->SetInput(myCellDataToPointData->GetOutput()); + }else + myContourFilter->SetInput(aPolyData); + + float aScalarRange[2]; + GetSourceRange(aScalarRange); + + myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange); + myWarpScalar->SetInput(myContourFilter->GetOutput()); + } myAppendPolyData->AddInput(myWarpScalar->GetPolyDataOutput()); - - float aScalarRange[2]; - GetSourceRange(aScalarRange); - - if(aPolyData->GetCellData()->GetNumberOfArrays()){ - myCellDataToPointData->SetInput(aPolyData); - myCellDataToPointData->PassCellDataOn(); - myContourFilter->SetInput(myCellDataToPointData->GetOutput()); - }else - myContourFilter->SetInput(aPolyData); - - myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange); - myAppendPolyData->AddInput(myContourFilter->GetOutput()); aCutPlane->Delete(); - myWarpScalar->SetNormal(aDir); + myWarpScalar->SetNormal(aPlaneNormal); VISU_ScalarMapPL::Update(); } @@ -294,17 +300,68 @@ float VISU_Plot3DPL:: GetPlanePosition() const { - if(!myIsRelative) - return myPosition; + return myPosition; +} - float aBounds[6]; - GetInput2()->GetBounds(aBounds); +//======================================================================= +//function : GetBasePlane +//purpose : +//======================================================================= - float aDir[3]; - VISU_CutPlanesPL::GetDir(aDir,myAngle,myOrientation); +void VISU_Plot3DPL::GetBasePlane(float theOrigin[3], + float theNormal[3], + bool theCenterOrigine ) const +{ + VISU_CutPlanesPL::GetDir(theNormal,myAngle,myOrientation); + + float aPosition = myPosition; + float aBounds[6], aBoundPrj[3]; + if ( myIsRelative ) + { + GetInput()->GetBounds(aBounds); + VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,theNormal); + aPosition = aBoundPrj[0] + aBoundPrj[2]*myPosition; + } + VISU::Mul(theNormal,aPosition,theOrigin); + + if ( theCenterOrigine ) { + // move theOrigin to the center of aBounds projections to the plane + GetInput2()->GetBounds(aBounds); + float boundPoints[8][3] = { + {aBounds[0],aBounds[2],aBounds[4]}, + {aBounds[1],aBounds[2],aBounds[4]}, + {aBounds[0],aBounds[3],aBounds[4]}, + {aBounds[1],aBounds[3],aBounds[4]}, + {aBounds[0],aBounds[2],aBounds[5]}, + {aBounds[1],aBounds[2],aBounds[5]}, + {aBounds[0],aBounds[3],aBounds[5]}, + {aBounds[1],aBounds[3],aBounds[5]}}; + float newOrigin[3] = { 0,0,0 }; + for(int i = 0; i < 8; i++) { + float proj[3]; + vtkPlane::ProjectPoint( boundPoints[i], theOrigin, theNormal, proj ); + newOrigin[0] += proj[0]; + newOrigin[1] += proj[1]; + newOrigin[2] += proj[2]; + } + theOrigin[0] = newOrigin[0] / 8.; + theOrigin[1] = newOrigin[1] / 8.; + theOrigin[2] = newOrigin[2] / 8.; + } +} - float aBoundPrj[3]; - VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aDir); +//======================================================================= +//function : GetMinMaxPosition +//purpose : return absolute position range +//======================================================================= - return aBoundPrj[0] + aBoundPrj[2]*myPosition; +void VISU_Plot3DPL::GetMinMaxPosition( float& minPos, float& maxPos ) const +{ + float aBounds[6], aBoundPrj[3], aNormal[3]; + VISU_CutPlanesPL::GetDir(aNormal,myAngle,myOrientation); + GetInput()->GetBounds(aBounds); + VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aNormal); + minPos = aBoundPrj[0]; + maxPos = aBoundPrj[1]; } + diff --git a/src/PIPELINE/VISU_Plot3DPL.hxx b/src/PIPELINE/VISU_Plot3DPL.hxx index 1e406928..467e81eb 100644 --- a/src/PIPELINE/VISU_Plot3DPL.hxx +++ b/src/PIPELINE/VISU_Plot3DPL.hxx @@ -79,12 +79,24 @@ public: float GetScaleFactor() const; + void + SetContourPrs (bool theIsContourPrs ) { myIsContour = theIsContourPrs; } + + bool + GetIsContourPrs() { return myIsContour; } + void SetNumberOfContours(int theNumber); int GetNumberOfContours() const; + void GetBasePlane (float theOrigin[3], + float theNormal[3], + bool theCenterOrigine = false ) const; + + void GetMinMaxPosition( float& minPos, float& maxPos ) const; + public: virtual void Init(); virtual void Update(); @@ -100,7 +112,7 @@ protected: virtual THook* DoHook(); float myAngle[3]; - bool myIsRelative; + bool myIsRelative, myIsContour; float myPosition; VISU_CutPlanesPL::PlaneOrientation myOrientation; -- 2.39.2