From: rnv Date: Wed, 19 Feb 2014 13:41:33 +0000 (+0400) Subject: Implementation of the new PARAVIS "Elliplse Builder" plugin. X-Git-Tag: V7_4_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=abc138abebd39c1a18de83b542fadd9dc2c755e4;p=modules%2Fparavis.git Implementation of the new PARAVIS "Elliplse Builder" plugin. --- diff --git a/src/Plugins/CMakeLists.txt b/src/Plugins/CMakeLists.txt index b7923492..1833b16d 100755 --- a/src/Plugins/CMakeLists.txt +++ b/src/Plugins/CMakeLists.txt @@ -35,6 +35,7 @@ SET(_subdirs NavigationMode ElevationSurface ScaleVector + EllipseBuilder ) FOREACH(_dir ${_subdirs}) diff --git a/src/Plugins/EllipseBuilder/CMakeLists.txt b/src/Plugins/EllipseBuilder/CMakeLists.txt new file mode 100644 index 00000000..bda4ec5a --- /dev/null +++ b/src/Plugins/EllipseBuilder/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (C) 2010-2014 CEA/DEN, EDF R&D +# +# 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +PROJECT(EllipseBuilder) + +cmake_minimum_required(VERSION 2.8) + +FIND_PACKAGE(ParaView REQUIRED) +INCLUDE(${PARAVIEW_USE_FILE}) + +ADD_PARAVIEW_PLUGIN(EllipseBuilderFilter "1.0" + SERVER_MANAGER_XML EllipseBuilderFilter.xml + SERVER_MANAGER_SOURCES vtkEllipseBuilderFilter.cxx + GUI_RESOURCES pqEllipseBuilder.qrc + GUI_RESOURCE_FILES EllipseBuilderGUI.xml + ) + +INSTALL( + TARGETS EllipseBuilderFilter + DESTINATION lib/paraview +) diff --git a/src/Plugins/EllipseBuilder/EllipseBuilderFilter.xml b/src/Plugins/EllipseBuilder/EllipseBuilderFilter.xml new file mode 100644 index 00000000..e1f31ae6 --- /dev/null +++ b/src/Plugins/EllipseBuilder/EllipseBuilderFilter.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This property specifies the name of the real field. + + + + + + + + + + + This property specifies the name of the image field. + + + + + + + + + + + + + + This property specifies the scale factor to scale every ellipse by. + + + + + + + This property sets the number of the points for every ellipse. + + + + + + + This property sets the start angle for every ellipse. + + + + + + + This property sets the end angle for every ellipse. + + + + + diff --git a/src/Plugins/EllipseBuilder/EllipseBuilderGUI.xml b/src/Plugins/EllipseBuilder/EllipseBuilderGUI.xml new file mode 100644 index 00000000..bb2f35b1 --- /dev/null +++ b/src/Plugins/EllipseBuilder/EllipseBuilderGUI.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/Plugins/EllipseBuilder/pqEllipseBuilder.qrc b/src/Plugins/EllipseBuilder/pqEllipseBuilder.qrc new file mode 100644 index 00000000..677e155b --- /dev/null +++ b/src/Plugins/EllipseBuilder/pqEllipseBuilder.qrc @@ -0,0 +1,5 @@ + + + resources/ellipse-icon.png + + \ No newline at end of file diff --git a/src/Plugins/EllipseBuilder/resources/ellipse-icon.png b/src/Plugins/EllipseBuilder/resources/ellipse-icon.png new file mode 100644 index 00000000..9b0c3a8d Binary files /dev/null and b/src/Plugins/EllipseBuilder/resources/ellipse-icon.png differ diff --git a/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.cxx b/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.cxx new file mode 100644 index 00000000..7b071e28 --- /dev/null +++ b/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.cxx @@ -0,0 +1,316 @@ +// Copyright (C) 2010-2014 CEA/DEN, EDF R&D +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "vtkEllipseBuilderFilter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; + +//------------------------------------------------------------------------------ +bool isStringInList(const list& aList, const string& theName) +{ + list::const_iterator anIter; + for (anIter = aList.begin(); anIter != aList.end(); anIter++) + { + // Compares the values of the string. + if ( (*anIter).compare(theName) == 0) + return true; + } + return false; +} + +//------------------------------------------------------------------------------ +void add2List(const list& theSource, list& theDestination) +{ + list::const_iterator anIter; + for (anIter = theSource.begin(); anIter != theSource.end(); anIter++) + { + // Add the item to the list if it does not exist + if (!isStringInList(theDestination, *anIter)) + theDestination.push_back(*anIter); + } +} + +//------------------------------------------------------------------------------ +double maximumElement(vector< complex >& theList) +{ + double aMaximum; + vector tmpList; + vector< complex >::iterator it; + for (it = theList.begin(); it != theList.end(); ++it) + { + tmpList.push_back(((*it)*conj(*it)).real()); + } + aMaximum = *max_element(tmpList.begin(), tmpList.end()); + return aMaximum; +} + +//------------------------------------------------------------------------------ +list GetListOfFields(vtkDataObject* theObject) +{ + list aList; + + if (theObject->IsA("vtkDataSet")) + { + vtkDataSet* aDataSet = vtkDataSet::SafeDownCast(theObject); + vtkPointData* aPntData = aDataSet->GetPointData(); + + // Add fields name on points + int aNbArrays = aPntData->GetNumberOfArrays(); + for (int i = 0; iGetArray(i) ) { + //Data array should contains at least 3 components (1 - DX, 2 - DY, 3 - DZ) + if( anArray->GetNumberOfComponents() >= 3 ) { + const char* aName = aPntData->GetArrayName(i); + aList.push_back(aName); + } + } + } + } + return aList; +} + +//------------------------------------------------------------------------------ +vtkStandardNewMacro(vtkEllipseBuilderFilter); + +//------------------------------------------------------------------------------ +vtkEllipseBuilderFilter::vtkEllipseBuilderFilter() : vtkMultiBlockDataSetAlgorithm() +{ + this->RealField = NULL; + this->ImagField = NULL; + this->FieldList = vtkStringArray::New(); +} + +//------------------------------------------------------------------------------ +vtkEllipseBuilderFilter::~vtkEllipseBuilderFilter() +{ + this->SetRealField(NULL); + this->SetRealField(NULL); + this->FieldList->Delete(); +} + +//------------------------------------------------------------------------------ +int vtkEllipseBuilderFilter::RequestData(vtkInformation* vtkNotUsed(request), + vtkInformationVector** theInputVector, + vtkInformationVector* theOutputVector) +{ + int aResolution = this->Resolution; + if(aResolution <=0 ) + return 0; + if( this->ScaleFactor == 0.0 ) + return 0; + + int anAxis = this->Axis; + + // Get the info objects + vtkMultiBlockDataSet* anInputMDSet = vtkMultiBlockDataSet::GetData(theInputVector[0], 0); + vtkMultiBlockDataSet* anOutputMDSet = vtkMultiBlockDataSet::GetData(theOutputVector, 0); + + double a, b, z_point; + vector< complex > circle; + + // Points Ellipses + double range, min, max, delta; + if(this->EndAngle > this->StartAngle) { + min = this->StartAngle; + max = this->EndAngle; + } else { + min = this->StartAngle; + max = this->EndAngle + 360.; + } + range = max-min; + delta = range/(double)aResolution; + for (double iter = min; iter < max; iter+=delta) + { + a = cos(vtkMath::RadiansFromDegrees(iter)); + b = sin(vtkMath::RadiansFromDegrees(iter)); + complex aVal(a, b); + circle.push_back(aVal); + } + + //Scale Factor + double aScaleFactor; + aScaleFactor = 1./this->ScaleFactor; + + vtkDataObjectTreeIterator* anIter = anInputMDSet->NewTreeIterator(); + anIter->VisitOnlyLeavesOff(); + bool created = false; + for (anIter->InitTraversal(); !anIter->IsDoneWithTraversal(); anIter->GoToNextItem()) + { + vtkDataObject* anInputNode = anInputMDSet->GetDataSet(anIter); + if (anInputNode->IsA("vtkDataSet")) + { + vtkUnstructuredGrid* aSourceDS = vtkUnstructuredGrid::SafeDownCast(anInputNode); + if(!aSourceDS) continue; + + vtkPointData* aPointData = aSourceDS->GetPointData(); + if(!aPointData) continue; + + int aNumberPoints = aSourceDS->GetNumberOfPoints(); + + vtkDataArray* aRealArray = vtkDataArray::SafeDownCast(aPointData->GetArray(this->RealField)); + vtkDataArray* anImagArray = vtkDataArray::SafeDownCast(aPointData->GetArray(this->ImagField)); + + if(!aRealArray || !anImagArray) continue; + + int aNumberOfRealComponents = aRealArray->GetNumberOfComponents(); + int aNumberOfImagComponents = anImagArray->GetNumberOfComponents(); + if (aNumberOfRealComponents >= 3 and aNumberOfImagComponents >= 3) + { + anOutputMDSet->CopyStructure(anInputMDSet); + vtkUnstructuredGrid* aCloneDS = aSourceDS->NewInstance(); + vtkPoints* aClonePoints = vtkPoints::New(); + aCloneDS->SetPoints(aClonePoints); + aClonePoints->Delete(); + anOutputMDSet->SetDataSet(anIter, aCloneDS); + aCloneDS->Delete(); + double rx, ry, ix, iy; + created = true; + for (int j = 0; j < aNumberPoints; j++) + { + z_point = aSourceDS->GetPoint(j)[2]; + + if (anAxis == 2) // Z : DX and DY + { + rx = aRealArray->GetTuple(j)[0]; + ry = aRealArray->GetTuple(j)[1]; + ix = anImagArray->GetTuple(j)[0]; + iy = anImagArray->GetTuple(j)[1]; + } + else if (anAxis == 1) // Y : DX and DZ + { + rx = aRealArray->GetTuple(j)[0]; + ry = aRealArray->GetTuple(j)[2]; + ix = anImagArray->GetTuple(j)[0]; + iy = anImagArray->GetTuple(j)[2]; + } + else // X : DY and DZ + { + rx = aRealArray->GetTuple(j)[1]; + ry = aRealArray->GetTuple(j)[2]; + ix = anImagArray->GetTuple(j)[1]; + iy = anImagArray->GetTuple(j)[2]; + } + + complex x(rx, ix); + complex y(ry, iy); + + x = x / aScaleFactor; + y = y / aScaleFactor; + + double x_point, y_point; + for (int r = 0; r < circle.size(); r++) + { + x_point = (x*circle[r]).real(); + y_point = (y*circle[r]).real(); + vtkIdType anId[1]; + if (anAxis == 2) + anId[0] = aClonePoints->InsertNextPoint(x_point, y_point, z_point); + else if (anAxis == 1) + anId[0] = aClonePoints->InsertNextPoint(x_point, z_point, y_point); + else + anId[0] = aClonePoints->InsertNextPoint(z_point, x_point, y_point); + aCloneDS->InsertNextCell(VTK_VERTEX, 1, anId); + } + } + } + else + { + continue; + } + } + } + anIter->Delete(); + if(!created) + return 0; + return 1; +} + +//------------------------------------------------------------------------------ +int vtkEllipseBuilderFilter::RequestInformation(vtkInformation* request, + vtkInformationVector **theInputVector, + vtkInformationVector *theOutputVector) +{ + // Retrieve an instance of vtkMultiBlockDataSet class from an information object. + vtkMultiBlockDataSet* anInputMDataSet = vtkMultiBlockDataSet::GetData(theInputVector[0], 0); + + list aList; + vtkDataObjectTreeIterator* anIter = anInputMDataSet->NewTreeIterator(); + anIter->VisitOnlyLeavesOff(); + for (anIter->InitTraversal(); !anIter->IsDoneWithTraversal(); anIter->GoToNextItem()) + { + vtkDataObject* anInputNode = anInputMDataSet->GetDataSet(anIter); + if (anInputNode->IsA("vtkDataSet")) + { + list aSubList = GetListOfFields(anInputNode); + add2List(aSubList, aList); + } + } + anIter->Delete(); + + this->FieldList->Reset(); + this->FieldList->SetNumberOfValues(aList.size()); + list::const_iterator anIterName; + int i = 0; + for (anIterName = aList.begin(); anIterName != aList.end(); anIterName++) + { + this->FieldList->SetValue(i, *anIterName); + i++; + } + + return this->Superclass::RequestInformation(request, theInputVector, theOutputVector); +} + + +//------------------------------------------------------------------------------ +vtkStringArray* vtkEllipseBuilderFilter::GetFieldList() +{ + return this->FieldList; +} + +//------------------------------------------------------------------------------ +void vtkEllipseBuilderFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + os << indent << "Real Field : " << this->RealField << endl; + os << indent << "Imag Field : " << this->ImagField << endl; + os << indent << "Start Angle : " << this->StartAngle << endl; + os << indent << "End Angle : " << this->EndAngle << endl; + os << indent << "Scale Factor : " << this->ScaleFactor << endl; + os << indent << "Scale Resolution : " << this->Resolution << endl; + os << indent << "Axis : " << this->Axis << endl; +} + diff --git a/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.h b/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.h new file mode 100644 index 00000000..6664f603 --- /dev/null +++ b/src/Plugins/EllipseBuilder/vtkEllipseBuilderFilter.h @@ -0,0 +1,100 @@ +// Copyright (C) 2010-2014 CEA/DEN, EDF R&D +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __ElliplseBuilderFilter_h +#define __ElliplseBuilderFilter_h + +#include +#include + +class vtkDataObjectTreeIterator; +class vtkStringArray; + +/** + * Description of class: TODO +*/ +class vtkEllipseBuilderFilter : public vtkMultiBlockDataSetAlgorithm +{ +public: + /// Returns pointer on a new instance of the class + static vtkEllipseBuilderFilter* New(); + + vtkTypeMacro(vtkEllipseBuilderFilter, vtkMultiBlockDataSetAlgorithm); + + /// Prints current state of the objects + virtual void PrintSelf(ostream& os, vtkIndent indent); + + /// Set and Get methods for scale factor + vtkSetMacro(ScaleFactor, double); + vtkGetMacro(ScaleFactor, double); + + virtual vtkStringArray* GetFieldList(); + + /// Set and Get methods for field of real part + vtkSetStringMacro(RealField); + vtkGetStringMacro(RealField); + + /// Set and Get methods for field of imag part + vtkSetStringMacro(ImagField); + vtkGetStringMacro(ImagField); + + /// Set and Get methods for start angle + vtkSetMacro(StartAngle, double); + vtkGetMacro(StartAngle, double); + + /// Set and Get methods for end angle + vtkSetMacro(EndAngle, double); + vtkGetMacro(EndAngle, double); + + /// Set and Get methods for resolution + vtkSetMacro(Resolution, int); + vtkGetMacro(Resolution, int); + + /// Set and Get methods for axis + vtkSetMacro(Axis, int); + vtkGetMacro(Axis, int); + +protected: + /// Constructor + vtkEllipseBuilderFilter(); + + /// Destructor + virtual ~vtkEllipseBuilderFilter(); + + /// A method which is called on filtering data + virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + + vtkStringArray* FieldList; + + double ScaleFactor; + double StartAngle; + double EndAngle; + int Resolution; + int Axis; + char* RealField; + char* ImagField; + +private: + /// Methods for copy of the filter: Not implemented + vtkEllipseBuilderFilter(const vtkEllipseBuilderFilter&); // Not implemented + void operator=(const vtkEllipseBuilderFilter&); // Not implemented +}; + +#endif