--- /dev/null
+// 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 <vtkAppendPolyData.h>
+#include <vtkCutter.h>
+#include <vtkPlane.h>
+
+#include <vtkCellDataToPointData.h>
+#include <vtkGeometryFilter.h>
+#include <vtkContourFilter.h>
+#include <vtkWarpScalar.h>
+#include <vtkOutlineFilter.h>
+
+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<VISU_Plot3DPL*>(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;
+}
--- /dev/null
+// 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<vtkCellDataToPointData> myCellDataToPointData;
+ TVTKSmartPtr<vtkAppendPolyData> myAppendPolyData;
+ TVTKSmartPtr<vtkGeometryFilter> myGeometryFilter;
+ TVTKSmartPtr<vtkContourFilter> myContourFilter;
+ TVTKSmartPtr<vtkWarpScalar> myWarpScalar;
+};
+
+#endif