From: Anthony Geay Date: Thu, 11 Oct 2018 09:26:01 +0000 (+0200) Subject: Jira413 : Static Plane Cutter update for StaticMesh plugin X-Git-Tag: V9_2_0a2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=078d041552d270bc480e11ce8c0fb245359c71ff;p=modules%2Fparavis.git Jira413 : Static Plane Cutter update for StaticMesh plugin --- diff --git a/src/Plugins/StaticMesh/vtkStaticDataSetSurfaceFilter.h b/src/Plugins/StaticMesh/vtkStaticDataSetSurfaceFilter.h index 4158f246..ec885829 100644 --- a/src/Plugins/StaticMesh/vtkStaticDataSetSurfaceFilter.h +++ b/src/Plugins/StaticMesh/vtkStaticDataSetSurfaceFilter.h @@ -30,8 +30,8 @@ #ifndef vtkStaticDataSetSurfaceFilter_h #define vtkStaticDataSetSurfaceFilter_h -#include "vtkDataSetSurfaceFilter.h" -#include "vtkNew.h" +#include +#include class vtkPolyData; @@ -41,13 +41,13 @@ public: static vtkStaticDataSetSurfaceFilter* New(); typedef vtkDataSetSurfaceFilter Superclass; // vtkTypeMacro can't be used with a factory built object - void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; + void PrintSelf(ostream& os, vtkIndent indent) override; - int UnstructuredGridExecute(vtkDataSet* input, vtkPolyData* output) VTK_OVERRIDE; + int UnstructuredGridExecute(vtkDataSet* input, vtkPolyData* output) override; protected: vtkStaticDataSetSurfaceFilter(); - ~vtkStaticDataSetSurfaceFilter() VTK_OVERRIDE; + ~vtkStaticDataSetSurfaceFilter() override; vtkNew Cache; vtkMTimeType InputMeshTime; @@ -55,8 +55,8 @@ protected: private: // Hide these from the user and the compiler. - vtkStaticDataSetSurfaceFilter(const vtkStaticDataSetSurfaceFilter&) VTK_DELETE_FUNCTION; - void operator=(const vtkStaticDataSetSurfaceFilter&) VTK_DELETE_FUNCTION; + vtkStaticDataSetSurfaceFilter(const vtkStaticDataSetSurfaceFilter&) = delete; + void operator=(const vtkStaticDataSetSurfaceFilter&) = delete; }; #endif diff --git a/src/Plugins/StaticMesh/vtkStaticEnSight6BinaryReader.h b/src/Plugins/StaticMesh/vtkStaticEnSight6BinaryReader.h index 58680aa8..eadf1726 100644 --- a/src/Plugins/StaticMesh/vtkStaticEnSight6BinaryReader.h +++ b/src/Plugins/StaticMesh/vtkStaticEnSight6BinaryReader.h @@ -38,8 +38,8 @@ #ifndef vtkStaticEnSight6BinaryReader_h #define vtkStaticEnSight6BinaryReader_h -#include "vtkEnSight6BinaryReader.h" -#include "vtkNew.h" +#include +#include class vtkMultiBlockDataSet; diff --git a/src/Plugins/StaticMesh/vtkStaticEnSight6Reader.h b/src/Plugins/StaticMesh/vtkStaticEnSight6Reader.h index d4a2d6a8..30fe1484 100644 --- a/src/Plugins/StaticMesh/vtkStaticEnSight6Reader.h +++ b/src/Plugins/StaticMesh/vtkStaticEnSight6Reader.h @@ -38,8 +38,8 @@ #ifndef vtkStaticEnSight6Reader_h #define vtkStaticEnSight6Reader_h -#include "vtkEnSight6Reader.h" -#include "vtkNew.h" +#include +#include class vtkMultiBlockDataSet; diff --git a/src/Plugins/StaticMesh/vtkStaticEnSightGoldBinaryReader.h b/src/Plugins/StaticMesh/vtkStaticEnSightGoldBinaryReader.h index 7a815743..e246509a 100644 --- a/src/Plugins/StaticMesh/vtkStaticEnSightGoldBinaryReader.h +++ b/src/Plugins/StaticMesh/vtkStaticEnSightGoldBinaryReader.h @@ -38,8 +38,8 @@ #ifndef vtkStaticEnSightGoldBinaryReader_h #define vtkStaticEnSightGoldBinaryReader_h -#include "vtkEnSightGoldBinaryReader.h" -#include "vtkNew.h" +#include +#include class vtkMultiBlockDataSet; diff --git a/src/Plugins/StaticMesh/vtkStaticEnSightGoldReader.h b/src/Plugins/StaticMesh/vtkStaticEnSightGoldReader.h index 1760e19f..2be1a028 100644 --- a/src/Plugins/StaticMesh/vtkStaticEnSightGoldReader.h +++ b/src/Plugins/StaticMesh/vtkStaticEnSightGoldReader.h @@ -38,8 +38,8 @@ #ifndef vtkStaticEnSightGoldReader_h #define vtkStaticEnSightGoldReader_h -#include "vtkEnSightGoldReader.h" -#include "vtkNew.h" +#include +#include class vtkMultiBlockDataSet; diff --git a/src/Plugins/StaticMesh/vtkStaticMeshObjectFactory.h b/src/Plugins/StaticMesh/vtkStaticMeshObjectFactory.h index 8af46d5f..316b9fab 100644 --- a/src/Plugins/StaticMesh/vtkStaticMeshObjectFactory.h +++ b/src/Plugins/StaticMesh/vtkStaticMeshObjectFactory.h @@ -23,14 +23,14 @@ #ifndef vtkStaticMeshObjectFactory_h #define vtkStaticMeshObjectFactory_h -#include "vtkObjectFactory.h" // Must be included before singletons +#include // Must be included before singletons class vtkStaticMeshObjectFactory : public vtkObjectFactory { public: vtkTypeMacro(vtkStaticMeshObjectFactory, vtkObjectFactory); static vtkStaticMeshObjectFactory* New(); - void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; + void PrintSelf(ostream& os, vtkIndent indent) override; /** * All sub-classes of vtkObjectFactory must return the version of @@ -39,20 +39,20 @@ public: * As the version needs to be compiled into the file as a string constant. * This is critical to determine possible incompatible dynamic factory loads. */ - const char* GetVTKSourceVersion() VTK_OVERRIDE; + const char* GetVTKSourceVersion() override; /** * Return a descriptive string describing the factory. */ - const char* GetDescription() VTK_OVERRIDE; + const char* GetDescription() override; protected: vtkStaticMeshObjectFactory(); - ~vtkStaticMeshObjectFactory() VTK_OVERRIDE; + ~vtkStaticMeshObjectFactory() override; private: - vtkStaticMeshObjectFactory(const vtkStaticMeshObjectFactory&) VTK_DELETE_FUNCTION; - void operator=(const vtkStaticMeshObjectFactory&) VTK_DELETE_FUNCTION; + vtkStaticMeshObjectFactory(const vtkStaticMeshObjectFactory&) = delete; + void operator=(const vtkStaticMeshObjectFactory&) = delete; }; #endif diff --git a/src/Plugins/StaticMesh/vtkStaticPUnstructuredGridGhostCellsGenerator.h b/src/Plugins/StaticMesh/vtkStaticPUnstructuredGridGhostCellsGenerator.h index f40653aa..ecfadfec 100644 --- a/src/Plugins/StaticMesh/vtkStaticPUnstructuredGridGhostCellsGenerator.h +++ b/src/Plugins/StaticMesh/vtkStaticPUnstructuredGridGhostCellsGenerator.h @@ -46,13 +46,13 @@ public: static vtkStaticPUnstructuredGridGhostCellsGenerator* New(); typedef vtkPUnstructuredGridGhostCellsGenerator Superclass; // vtkTypeMacro can't be used with a factory built object - void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; + void PrintSelf(ostream& os, vtkIndent indent) override; - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) VTK_OVERRIDE; + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; protected: vtkStaticPUnstructuredGridGhostCellsGenerator(); - ~vtkStaticPUnstructuredGridGhostCellsGenerator() VTK_OVERRIDE; + ~vtkStaticPUnstructuredGridGhostCellsGenerator() override; /** * Check input for "ProcessId" and "Ids" point and cell array, @@ -95,8 +95,8 @@ protected: private: // Hide these from the user and the compiler. vtkStaticPUnstructuredGridGhostCellsGenerator( - const vtkStaticPUnstructuredGridGhostCellsGenerator&) VTK_DELETE_FUNCTION; - void operator=(const vtkStaticPUnstructuredGridGhostCellsGenerator&) VTK_DELETE_FUNCTION; + const vtkStaticPUnstructuredGridGhostCellsGenerator&) = delete; + void operator=(const vtkStaticPUnstructuredGridGhostCellsGenerator&) = delete; }; #endif diff --git a/src/Plugins/StaticMesh/vtkStaticPlaneCutter.cxx b/src/Plugins/StaticMesh/vtkStaticPlaneCutter.cxx index 68fe3e3d..393bddcf 100644 --- a/src/Plugins/StaticMesh/vtkStaticPlaneCutter.cxx +++ b/src/Plugins/StaticMesh/vtkStaticPlaneCutter.cxx @@ -26,9 +26,12 @@ #include #include #include +#include vtkStandardNewMacro(vtkStaticPlaneCutter); +static const char* IdsArrayName = "__vtkSPC_Ids"; + //---------------------------------------------------------------------------- vtkStaticPlaneCutter::vtkStaticPlaneCutter() { @@ -39,6 +42,7 @@ vtkStaticPlaneCutter::vtkStaticPlaneCutter() //---------------------------------------------------------------------------- vtkStaticPlaneCutter::~vtkStaticPlaneCutter() { + this->ClearWeightsVector(); } //----------------------------------------------------------------------------- @@ -58,7 +62,7 @@ int vtkStaticPlaneCutter::RequestData( return 0; } - // Recover the fisrt and only block so this works with single block mb + // Recover the first and only block so this works with single block mb if (inputMB && inputMB->GetNumberOfBlocks() == 1) { input = vtkUnstructuredGrid::SafeDownCast(inputMB->GetBlock(0)); @@ -108,15 +112,14 @@ int vtkStaticPlaneCutter::RequestData( vtkErrorMacro("Output is not of expected type"); return 0; } - this->RemovePointData(output); this->Cache->ShallowCopy(output); this->InputMeshTime = input->GetMeshMTime(); this->FilterMTime = this->GetMTime(); - // Compute the cell ids to be passed from the input to the cache - this->ComputeCellIds(); - + // Compute the ids to be passed from the input to the cache + this->ComputeIds(input); + this->RemoveIdsArray(this->Cache); return ret; } } @@ -124,17 +127,17 @@ int vtkStaticPlaneCutter::RequestData( //----------------------------------------------------------------------------- void vtkStaticPlaneCutter::AddIdsArray(vtkDataSet* input, vtkDataSet* output) { - vtkDataSet* tmpInput; - tmpInput = input; + vtkDataSet* tmpInput = input; vtkNew generateIdScalars; // Check for Ids array - vtkAbstractArray* cellIdsTmp = input->GetCellData()->GetAbstractArray("Ids"); + vtkIdTypeArray *cellIdsTmp = vtkIdTypeArray::SafeDownCast(input->GetCellData()->GetAbstractArray(IdsArrayName)); if (!cellIdsTmp) { // Create Ids array generateIdScalars->SetInputData(tmpInput); - generateIdScalars->SetIdsArrayName("Ids"); + generateIdScalars->SetIdsArrayName(IdsArrayName); + generateIdScalars->FieldDataOn(); generateIdScalars->Update(); tmpInput = generateIdScalars->GetOutput(); } @@ -142,40 +145,48 @@ void vtkStaticPlaneCutter::AddIdsArray(vtkDataSet* input, vtkDataSet* output) } //----------------------------------------------------------------------------- -void vtkStaticPlaneCutter::RemovePointData(vtkMultiPieceDataSet* dataset) +void vtkStaticPlaneCutter::RemoveIdsArray(vtkMultiPieceDataSet* output) { - // Iterate over each piece of the multipiece output - vtkCompositeDataIterator* iter = dataset->NewIterator(); + vtkSmartPointer iter; + iter.TakeReference(output->NewIterator()); iter->SkipEmptyNodesOn(); for (iter->GoToFirstItem(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) { vtkPolyData* slice = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject()); if (slice) { - // Remove all point data array on each slice - vtkPointData* pd = slice->GetPointData(); - for (int i = pd->GetNumberOfArrays() - 1; i >= 0; i--) - { - pd->RemoveArray(i); - } + slice->GetCellData()->RemoveArray(IdsArrayName); } } - iter->Delete(); } //----------------------------------------------------------------------------- -void vtkStaticPlaneCutter::ComputeCellIds() +void vtkStaticPlaneCutter::ClearWeightsVector() +{ + for(auto& weightsVector : this->WeightsVectorCompo) + { + delete[] weightsVector[0].second; + } + this->WeightsVectorCompo.clear(); +} + +//----------------------------------------------------------------------------- +void vtkStaticPlaneCutter::ComputeIds(vtkUnstructuredGrid* input) { this->CellToCopyFrom.clear(); this->CellToCopyTo.clear(); + this->ClearWeightsVector(); // Iterate over each piece of the multipiece output - vtkCompositeDataIterator* iter = this->Cache->NewIterator(); + vtkNew tmpCell; + vtkSmartPointer iter; + iter.TakeReference(this->Cache->NewIterator()); iter->SkipEmptyNodesOn(); for (iter->GoToFirstItem(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) { vtkPolyData* slice = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject()); - if (slice) + vtkIdType sliceNbPoints = slice ? slice->GetNumberOfPoints() : 0; + if (sliceNbPoints > 0) { // For each piece, recover the Ids of the cells sliced and the corresponding // cellId in the slice @@ -184,7 +195,8 @@ void vtkStaticPlaneCutter::ComputeCellIds() this->CellToCopyFrom.push_back(cellIdsFrom); this->CellToCopyTo.push_back(cellIdsTo); - vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(slice->GetCellData()->GetArray("Ids")); + vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(slice->GetCellData()->GetArray(IdsArrayName)); + assert(ids); cellIdsFrom->SetNumberOfIds(ids->GetNumberOfValues()); cellIdsTo->SetNumberOfIds(ids->GetNumberOfValues()); for (vtkIdType i = 0; i < ids->GetNumberOfValues(); i++) @@ -192,9 +204,34 @@ void vtkStaticPlaneCutter::ComputeCellIds() cellIdsFrom->SetId(i, ids->GetValue(i)); cellIdsTo->SetId(i, i); } + if (input->GetPointData()->GetNumberOfArrays() > 0) + { + slice->BuildLinks(); + vtkIdType maxCellSize = input->GetMaxCellSize(); + std::vector, double*>> weightsVector; + weightsVector.resize(sliceNbPoints); + double *allWeights = new double[maxCellSize * sliceNbPoints]; + for (vtkIdType i = 0; i < sliceNbPoints; i++) + { + vtkNew ptIds; + double *weights = &allWeights[maxCellSize * i]; + unsigned short ncells; + vtkIdType *cells; + slice->GetPointCells(i, ncells, cells); + vtkIdType cellId = cellIdsFrom->GetId(cells[0]); + assert(cellId < input->GetNumberOfCells()); + input->GetCell(cellId, tmpCell); + input->GetCellPoints(cellId, ptIds); + double dist, pcoords[3], x[3], p[3]; + int subId = 0; + slice->GetPoint(i, p); + tmpCell->EvaluatePosition(p, x, subId, pcoords, dist, weights); + weightsVector[i] = { ptIds, weights }; + } + this->WeightsVectorCompo.push_back(weightsVector); + } } } - iter->Delete(); } //----------------------------------------------------------------------------- @@ -208,17 +245,18 @@ void vtkStaticPlaneCutter::UpdateCacheData(vtkDataSet* input) mpFieldData->RemoveArray(i); } - // Recover cell data - // We may want to improve this and support PointData at some point + // Recover cell/point data vtkCellData* inCD = input->GetCellData(); + vtkPointData* inPD = input->GetPointData(); - vtkCompositeDataIterator* iter = this->Cache->NewIterator(); + vtkSmartPointer iter; + iter.TakeReference(this->Cache->NewIterator()); iter->SkipEmptyNodesOn(); - int i = 0; + int blockId = 0; for (iter->GoToFirstItem(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) { vtkPolyData* slice = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject()); - if (slice) + if (slice && slice->GetNumberOfPoints() > 0) { vtkCellData* sliceCD = slice->GetCellData(); for (int iArr = 0; iArr < inCD->GetNumberOfArrays(); iArr++) @@ -228,16 +266,28 @@ void vtkStaticPlaneCutter::UpdateCacheData(vtkDataSet* input) if (arrayToCopyIn) { // Copy the tuples from the input cell ids to the slice cell ids - arrayToCopyIn->InsertTuples(this->CellToCopyTo[i].Get(), this->CellToCopyFrom[i].Get(), + arrayToCopyIn->InsertTuples(this->CellToCopyTo[blockId].Get(), this->CellToCopyFrom[blockId].Get(), inCD->GetAbstractArray(iArr)); } } + + if (input->GetPointData()->GetNumberOfArrays() > 0) + { + vtkPointData* slicePD = slice->GetPointData(); + vtkIdType sliceNbPoints = slice->GetNumberOfPoints(); + slicePD->InterpolateAllocate(inPD, sliceNbPoints); + auto& weightsVector = this->WeightsVectorCompo[blockId]; + for (vtkIdType ptIdx = 0; ptIdx < sliceNbPoints; ptIdx++) + { + slicePD->InterpolatePoint(inPD, ptIdx, weightsVector[ptIdx].first, weightsVector[ptIdx].second); + } + } + // Update field data slice->GetFieldData()->PassData(input->GetFieldData()); + blockId++; } - i++; } - iter->Delete(); } //---------------------------------------------------------------------------- diff --git a/src/Plugins/StaticMesh/vtkStaticPlaneCutter.h b/src/Plugins/StaticMesh/vtkStaticPlaneCutter.h index badea399..ab473e7c 100644 --- a/src/Plugins/StaticMesh/vtkStaticPlaneCutter.h +++ b/src/Plugins/StaticMesh/vtkStaticPlaneCutter.h @@ -45,44 +45,47 @@ class vtkStaticPlaneCutter : public vtkPlaneCutter public: static vtkStaticPlaneCutter* New(); typedef vtkPlaneCutter Superclass; // vtkTypeMacro can't be used with a factory built object - void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; + void PrintSelf(ostream &os, vtkIndent indent) override; - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) VTK_OVERRIDE; + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; protected: vtkStaticPlaneCutter(); - ~vtkStaticPlaneCutter() VTK_OVERRIDE; + ~vtkStaticPlaneCutter() override; /** - * Check input for "Ids" cell array, if absent, compute and add them. + * Check input for Ids cell array, if absent, compute and add them. */ static void AddIdsArray(vtkDataSet* input, vtkDataSet* output); /** - * Update cache point, cell and field data using input + * Remove an Ids cell array in all polydata pieces of output */ - void UpdateCacheData(vtkDataSet* input); + static void RemoveIdsArray(vtkMultiPieceDataSet* output); /** - * Compute the cells ids to be used when updating the cache later + * Update cache point, cell and field data using input */ - void ComputeCellIds(); + void UpdateCacheData(vtkDataSet* input); /** - * Remove all point data array of a multipiece input with polydata leafs + * Compute the ids and weights to be used when updating the cache later */ - static void RemovePointData(vtkMultiPieceDataSet* dataset); + void ComputeIds(vtkUnstructuredGrid* input); + + void ClearWeightsVector(); vtkNew Cache; std::vector > CellToCopyFrom; std::vector > CellToCopyTo; + std::vector, double*>>> WeightsVectorCompo; vtkMTimeType InputMeshTime; vtkMTimeType FilterMTime; private: // Hide these from the user and the compiler. - vtkStaticPlaneCutter(const vtkStaticPlaneCutter&) VTK_DELETE_FUNCTION; - void operator=(const vtkStaticPlaneCutter&) VTK_DELETE_FUNCTION; + vtkStaticPlaneCutter(const vtkStaticPlaneCutter&) = delete; + void operator=(const vtkStaticPlaneCutter&) = delete; }; #endif diff --git a/src/Plugins/StaticMesh/vtkTemporalUGWavelet.cxx b/src/Plugins/StaticMesh/vtkTemporalUGWavelet.cxx index 404ba4d0..f1f2a007 100644 --- a/src/Plugins/StaticMesh/vtkTemporalUGWavelet.cxx +++ b/src/Plugins/StaticMesh/vtkTemporalUGWavelet.cxx @@ -14,19 +14,19 @@ =========================================================================*/ #include "vtkTemporalUGWavelet.h" -#include "vtkCellData.h" -#include "vtkDataSetTriangleFilter.h" -#include "vtkFloatArray.h" -#include "vtkImageData.h" -#include "vtkInformation.h" -#include "vtkInformationVector.h" -#include "vtkMultiProcessController.h" -#include "vtkNew.h" -#include "vtkObjectFactory.h" -#include "vtkPointData.h" -#include "vtkRTAnalyticSource.h" -#include "vtkStreamingDemandDrivenPipeline.h" -#include "vtkUnstructuredGrid.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include vtkStandardNewMacro(vtkTemporalUGWavelet); diff --git a/src/Plugins/StaticMesh/vtkTemporalUGWavelet.h b/src/Plugins/StaticMesh/vtkTemporalUGWavelet.h index e1a11965..2758debd 100644 --- a/src/Plugins/StaticMesh/vtkTemporalUGWavelet.h +++ b/src/Plugins/StaticMesh/vtkTemporalUGWavelet.h @@ -25,7 +25,7 @@ #ifndef vtkTemporalUGWavelet_h #define vtkTemporalUGWavelet_h -#include "vtkRTAnalyticSource.h" +#include class vtkUnstructuredGrid; @@ -34,7 +34,7 @@ class vtkTemporalUGWavelet : public vtkRTAnalyticSource public: static vtkTemporalUGWavelet* New(); vtkTypeMacro(vtkTemporalUGWavelet, vtkRTAnalyticSource); - void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; + void PrintSelf(ostream& os, vtkIndent indent) override; //@{ /** @@ -48,20 +48,20 @@ protected: vtkTemporalUGWavelet(); ~vtkTemporalUGWavelet(); - int FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info) VTK_OVERRIDE; + int FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info) override; int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector, - vtkInformationVector* outputVector) VTK_OVERRIDE; + vtkInformationVector* outputVector) override; - int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) VTK_OVERRIDE; + int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override; int NumberOfTimeSteps; vtkUnstructuredGrid* Cache; vtkTimeStamp CacheMTime; private: - vtkTemporalUGWavelet(const vtkTemporalUGWavelet&) VTK_DELETE_FUNCTION; - void operator=(const vtkTemporalUGWavelet&) VTK_DELETE_FUNCTION; + vtkTemporalUGWavelet(const vtkTemporalUGWavelet&) = delete; + void operator=(const vtkTemporalUGWavelet&) = delete; }; #endif