From: apo Date: Wed, 20 Apr 2005 05:46:35 +0000 (+0000) Subject: POST-PROCESSOR 2005, T1.5, 2D fields displaed in 3D - new pipeline (Plot#D) is introduced X-Git-Tag: V2_2_0_VISU_improvement_2005-05-27~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b0188528317b481c1174154e06c1a5321b88287;p=modules%2Fvisu.git POST-PROCESSOR 2005, T1.5, 2D fields displaed in 3D - new pipeline (Plot#D) is introduced --- diff --git a/src/PIPELINE/Makefile.in b/src/PIPELINE/Makefile.in index f4ba1694..db0e8fca 100644 --- a/src/PIPELINE/Makefile.in +++ b/src/PIPELINE/Makefile.in @@ -51,7 +51,7 @@ LIB_SRC = VISU_PipeLine.cxx VISU_PipeLineUtils.cxx \ VISU_VectorsPL.cxx VISU_StreamLinesPL.cxx \ VISU_LookupTable.cxx VISU_ScalarBarActor.cxx \ VISU_Extractor.cxx VISU_FieldTransform.cxx \ - VISU_UsedPointsFilter.cxx \ + VISU_UsedPointsFilter.cxx VISU_Plot3DPL.cxx \ SALOME_ExtractGeometry.cxx # Executables targets diff --git a/src/PIPELINE/VISUPipeLine.cxx b/src/PIPELINE/VISUPipeLine.cxx index 9c26e3ff..25a236c5 100644 --- a/src/PIPELINE/VISUPipeLine.cxx +++ b/src/PIPELINE/VISUPipeLine.cxx @@ -33,8 +33,9 @@ #include "VISU_DeformedShapePL.hxx" #include "VISU_VectorsPL.hxx" #include "VISU_StreamLinesPL.hxx" +#include "VISU_Plot3DPL.hxx" -typedef VISU_ScalarMapPL TPresent; +typedef VISU_Plot3DPL TPresent; #include #include @@ -112,8 +113,9 @@ int main(int argc, char** argv){ aPresent->Build(); aPresent->Init(); aPresent->SetSourceRange(); - //aPresent->SetPartDefault(0); - //aPresent->SetScalarMin(0.01); + //aPresent->SetNumberOfContours(50); + //aPresent->SetNbParts(1); + //aPresent->SetOrientation(VISU_CutPlanesPL::XY,0.0,0.0); //aPresent->SetScaling(VTK_SCALE_LOG10); aPresent->Update(); @@ -127,9 +129,10 @@ int main(int argc, char** argv){ ren->AddActor(anActor); ren->AddActor2D(aScalarBar); - ren->ResetCameraClippingRange(); renWin->Render(); + ren->ResetCamera(); + iren->Start(); return 0; } diff --git a/src/PIPELINE/VISU_CutPlanesPL.cxx b/src/PIPELINE/VISU_CutPlanesPL.cxx index 0904935b..e5799558 100644 --- a/src/PIPELINE/VISU_CutPlanesPL.cxx +++ b/src/PIPELINE/VISU_CutPlanesPL.cxx @@ -236,7 +236,10 @@ int VISU_CutPlanesPL::IsPartDefault(int thePartNumber){ } -void VISU_CutPlanesPL::GetDir(float theDir[3], float theAng[3], const PlaneOrientation& theBasePlane){ +void VISU_CutPlanesPL::GetDir(float theDir[3], + const float theAng[3], + const PlaneOrientation& theBasePlane) +{ int iPlane = 0; float aRx[3][3], aRy[3][3], aRz[3][3], aRotation[3][3]; switch(theBasePlane){ diff --git a/src/PIPELINE/VISU_CutPlanesPL.hxx b/src/PIPELINE/VISU_CutPlanesPL.hxx index 094c9463..170df02e 100644 --- a/src/PIPELINE/VISU_CutPlanesPL.hxx +++ b/src/PIPELINE/VISU_CutPlanesPL.hxx @@ -76,7 +76,9 @@ public: static void CorrectPnt(float thePnt[3], const float BoundPrj[6]); static void GetBoundProject(float BoundPrj[3], const float BoundBox[6], const float Dir[3]); - static void GetDir(float theDir[3], float theAng[3], const PlaneOrientation& theBasePlane); + static void GetDir(float theDir[3], + const float theAng[3], + const PlaneOrientation& theBasePlane); static void ClearAppendPolyData(vtkAppendPolyData *theAppendPolyData); diff --git a/src/PIPELINE/VISU_PipeLine.hxx b/src/PIPELINE/VISU_PipeLine.hxx index 0f1670ce..75b8cf5d 100644 --- a/src/PIPELINE/VISU_PipeLine.hxx +++ b/src/PIPELINE/VISU_PipeLine.hxx @@ -47,8 +47,13 @@ public: r->Delete(); return *this; } - TVTKSmartPtr& operator=(T* r){ vtkSmartPointer::operator=(r); return *this;} - T* Get() const { return GetPointer();} + TVTKSmartPtr& operator=(T* r){ + vtkSmartPointer::operator=(r); + return *this; + } + operator T* () const { + return GetPointer(); + } }; class vtkDataSetMapper; diff --git a/src/PIPELINE/VISU_Plot3DPL.cxx b/src/PIPELINE/VISU_Plot3DPL.cxx new file mode 100644 index 00000000..0f4e02c9 --- /dev/null +++ b/src/PIPELINE/VISU_Plot3DPL.cxx @@ -0,0 +1,286 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_PipeLine.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_Plot3DPL.hxx" +#include "VISU_CutPlanesPL.hxx" +#include "VISU_PipeLineUtils.hxx" +#include "SALOME_GeometryFilter.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +vtkStandardNewMacro(VISU_Plot3DPL); + +VISU_Plot3DPL::VISU_Plot3DPL(): + myCellDataToPointData(vtkCellDataToPointData::New(),true), + myAppendPolyData(vtkAppendPolyData::New(),true), + myGeometryFilter(vtkGeometryFilter::New(),true), + myContourFilter(vtkContourFilter::New(),true), + myWarpScalar(vtkWarpScalar::New(),true), + myOrientation(VISU_CutPlanesPL::YZ), + myIsRelative(true), + myPosition(0.5) +{ + myAngle[0] = myAngle[1] = myAngle[2]; + SetNumberOfContours(32); +} + +VISU_Plot3DPL::~VISU_Plot3DPL() +{ +} + +void +VISU_Plot3DPL:: +ShallowCopy(VISU_PipeLine *thePipeLine) +{ + VISU_ScalarMapPL::ShallowCopy(thePipeLine); + //if(VISU_Plot3DPL *aPipeLine = dynamic_cast(thePipeLine)){ + //} +} + +VISU_CutPlanesPL::PlaneOrientation +VISU_Plot3DPL:: +GetOrientation(vtkDataSet* theDataSet) +{ + theDataSet->Update(); + + float aBounds[6]; + theDataSet->GetBounds(aBounds); + float aDelta[3] = {aBounds[1] - aBounds[0], aBounds[3] - aBounds[2], aBounds[5] - aBounds[4]}; + + if(aDelta[0] >= aDelta[1] && aDelta[0] >= aDelta[2]) + if(aDelta[1] >= aDelta[2]) + return VISU_CutPlanesPL::XY; + else + return VISU_CutPlanesPL::ZX; + + if(aDelta[1] >= aDelta[0] && aDelta[1] >= aDelta[2]) + if(aDelta[0] >= aDelta[2]) + return VISU_CutPlanesPL::XY; + else + return VISU_CutPlanesPL::YZ; + + if(aDelta[2] >= aDelta[0] && aDelta[2] >= aDelta[1]) + if(aDelta[0] >= aDelta[1]) + return VISU_CutPlanesPL::ZX; + else + return VISU_CutPlanesPL::YZ; + + return VISU_CutPlanesPL::XY; +} + +float +VISU_Plot3DPL:: +GetScaleFactor(vtkDataSet* theDataSet) +{ + theDataSet->Update(); + float aLength = theDataSet->GetLength(); + + float aScalarRange[2]; + GetSourceRange(aScalarRange); + + static float EPS = 0.3; + float aRange = aScalarRange[1] - aScalarRange[0]; + if(aRange > 0.0) + return aLength / aRange * EPS; + + return 0.0; +} + +void +VISU_Plot3DPL:: +Init() +{ + VISU_ScalarMapPL::Init(); + + myOrientation = GetOrientation(GetInput2()); + SetScaleFactor(GetScaleFactor(GetInput2())); +} + +VISU_ScalarMapPL::THook* +VISU_Plot3DPL:: +DoHook() +{ + return myAppendPolyData->GetOutput(); +} + +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 anOrigin[3]; + VISU::Mul(aDir,GetPlanePosition(),anOrigin); + + vtkUnstructuredGrid* anUnstructuredGrid = + myFieldTransform->GetUnstructuredGridOutput(); + vtkCutter *aCutPlane = vtkCutter::New(); + aCutPlane->SetInput(anUnstructuredGrid); + + vtkPlane *aPlane = vtkPlane::New(); + aPlane->SetOrigin(anOrigin); + aPlane->SetNormal(aDir); + + aCutPlane->SetCutFunction(aPlane); + aPlane->Delete(); + + vtkPolyData* aPolyData = aCutPlane->GetOutput(); + aPolyData->Update(); + if(aPolyData->GetNumberOfCells() == 0){ + myGeometryFilter->SetInput(anUnstructuredGrid); + aPolyData = myGeometryFilter->GetOutput(); + } + myWarpScalar->SetInput(aPolyData); + 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); + + VISU_ScalarMapPL::Update(); +} + +void +VISU_Plot3DPL:: +SetNumberOfContours(int theNumber) +{ + myContourFilter->SetNumberOfContours(theNumber); +} + +int +VISU_Plot3DPL:: +GetNumberOfContours() const +{ + return myContourFilter->GetNumberOfContours(); +} + +void +VISU_Plot3DPL:: +SetScaleFactor(float theScaleFactor) +{ + myWarpScalar->SetScaleFactor(theScaleFactor); +} + +float +VISU_Plot3DPL:: +GetScaleFactor() const +{ + return myWarpScalar->GetScaleFactor(); +} + +void +VISU_Plot3DPL:: +SetPlanePosition(float thePosition, + bool theIsRelative) +{ + myIsRelative = theIsRelative; + myPosition = thePosition; +} + +bool +VISU_Plot3DPL:: +IsPositionRelative() const +{ + return myIsRelative; +} + +VISU_CutPlanesPL::PlaneOrientation +VISU_Plot3DPL:: +GetPlaneOrientation() const +{ + return myOrientation; +} + +void +VISU_Plot3DPL:: +SetOrientation(VISU_CutPlanesPL::PlaneOrientation theOrientation, + float theXAngle, + float theYAngle) +{ + switch(theOrientation){ + case VISU_CutPlanesPL::XY: myAngle[0] = theXAngle; break; + case VISU_CutPlanesPL::YZ: myAngle[1] = theXAngle; break; + case VISU_CutPlanesPL::ZX: myAngle[2] = theXAngle; break; + } + switch(theOrientation){ + case VISU_CutPlanesPL::XY: myAngle[1] = theYAngle; break; + case VISU_CutPlanesPL::YZ: myAngle[2] = theYAngle; break; + case VISU_CutPlanesPL::ZX: myAngle[0] = theYAngle; break; + } + myOrientation = theOrientation; +} + +float +VISU_Plot3DPL:: +GetPlanePosition() const +{ + if(!myIsRelative) + return myPosition; + + float aBounds[6]; + GetInput2()->GetBounds(aBounds); + + float aDir[3]; + VISU_CutPlanesPL::GetDir(aDir,myAngle,myOrientation); + + float aBoundPrj[3]; + VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aDir); + + return aBoundPrj[0] + aBoundPrj[2]*myPosition; +} diff --git a/src/PIPELINE/VISU_Plot3DPL.hxx b/src/PIPELINE/VISU_Plot3DPL.hxx new file mode 100644 index 00000000..7924c25c --- /dev/null +++ b/src/PIPELINE/VISU_Plot3DPL.hxx @@ -0,0 +1,108 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_CutPlanesPL.hxx +// Author: Alexey PETROV +// Module : VISU + +#ifndef VISU_Plot3DPL_HeaderFile +#define VISU_Plot3DPL_HeaderFile + +#include "VISU_ScalarMapPL.hxx" +#include "VISU_CutPlanesPL.hxx" + +class vtkWarpScalar; +class vtkContourFilter; +class vtkGeometryFilter; +class vtkCellDataToPointData; + +class VISU_Plot3DPL : public VISU_ScalarMapPL{ +protected: + VISU_Plot3DPL(); + VISU_Plot3DPL(const VISU_Plot3DPL&); + +public: + vtkTypeMacro(VISU_Plot3DPL,VISU_ScalarMapPL); + static VISU_Plot3DPL* New(); + virtual ~VISU_Plot3DPL(); + + virtual + void + ShallowCopy(VISU_PipeLine *thePipeLine); + + VISU_CutPlanesPL::PlaneOrientation + GetPlaneOrientation() const; + + void + SetOrientation(VISU_CutPlanesPL::PlaneOrientation theOrientation, + float theXAngle = 0.0, + float theYAngle = 0.0); + + float + GetPlanePosition() const; + + bool + IsPositionRelative() const; + + void + SetPlanePosition(float thePosition, + bool theIsRelative); + + void + SetScaleFactor(float theScaleFactor); + + float + GetScaleFactor() const; + + void + SetNumberOfContours(int theNumber); + + int + GetNumberOfContours() const; + +public: + virtual void Init(); + virtual void Update(); + + static + VISU_CutPlanesPL::PlaneOrientation + GetOrientation(vtkDataSet* theDataSet); + + float + GetScaleFactor(vtkDataSet* theDataSet); + +protected: + virtual THook* DoHook(); + + float myAngle[3]; + bool myIsRelative; + float myPosition; + VISU_CutPlanesPL::PlaneOrientation myOrientation; + + TVTKSmartPtr myCellDataToPointData; + TVTKSmartPtr myAppendPolyData; + TVTKSmartPtr myGeometryFilter; + TVTKSmartPtr myContourFilter; + TVTKSmartPtr myWarpScalar; +}; + +#endif