Commit a94c1c8e authored by Mathieu Westphal's avatar Mathieu Westphal
Browse files

Fixing parallel periodic filter

parent e180b45d
set(Module_SRCS
vtkAngularPeriodicFilter.cxx
vtkAnnotationLink.cxx
vtkAppendPoints.cxx
vtkApproximatingSubdivisionFilter.cxx
......@@ -47,7 +46,6 @@ set(Module_SRCS
vtkOBBDicer.cxx
vtkOBBTree.cxx
vtkPassThrough.cxx
vtkPeriodicFilter.cxx
vtkPolyDataStreamer.cxx
vtkPolyDataToReebGraphFilter.cxx
vtkProbePolyhedron.cxx
......
......@@ -15,7 +15,6 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
BoxClipTetrahedra.cxx
BoxClipTriangulateAndInterpolate.cxx
BoxClipTriangulate.cxx,NO_VALID
TestAngularPeriodicFilter.cxx
TestAppendPoints.cxx,NO_VALID
TestBooleanOperationPolyDataFilter2.cxx
TestBooleanOperationPolyDataFilter.cxx
......
set(Module_SRCS
vtkAngularPeriodicFilter.cxx
vtkCollectGraph.cxx
vtkCollectPolyData.cxx
vtkCollectTable.cxx
......@@ -10,6 +11,7 @@ set(Module_SRCS
vtkExtractUserDefinedPiece.cxx
vtkPCellDataToPointData.cxx
vtkPExtractArraysOverTime.cxx
vtkPeriodicFilter.cxx
vtkPKdTree.cxx
vtkPLinearExtrusionFilter.cxx
vtkPMaskPoints.cxx
......
include(vtkMPI)
vtk_add_test_cxx(${vtk-module}CxxTests testsStd
TestAngularPeriodicFilter.cxx
)
vtk_add_test_mpi(${vtk-module}CxxTests-MPI tests
TESTING_DATA
DistributedData.cxx
......@@ -18,3 +22,4 @@ set(all_tests
${no_data_tests}
)
vtk_test_mpi_executable(${vtk-module}CxxTests-MPI all_tests)
vtk_test_cxx_executable(${vtk-module}CxxTests testsStd)
......@@ -12,10 +12,12 @@ vtk_module(vtkFiltersParallel
vtkTestingCore
vtkTestingRendering
vtkInteractionStyle
vtkIOXML
vtkRendering${VTK_RENDERING_BACKEND}
vtkRenderingParallel
vtkFiltersParallelMPI
vtkFiltersParallelImaging
vtkFiltersFlowPaths
vtkIOLegacy
KIT
vtkParallel
......
......@@ -20,6 +20,7 @@
#include "vtkDoubleArray.h"
#include "vtkFieldData.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkNew.h"
......@@ -32,6 +33,8 @@
#include "vtkTransformFilter.h"
#include "vtkUnstructuredGrid.h"
#include <sstream>
vtkStandardNewMacro(vtkAngularPeriodicFilter);
//----------------------------------------------------------------------------
......@@ -101,14 +104,17 @@ void vtkAngularPeriodicFilter::SetRotationAxisToZ()
}
//----------------------------------------------------------------------------
void vtkAngularPeriodicFilter::CreatePeriodicDataSet(
vtkCompositeDataIterator* loc,
vtkCompositeDataSet* output,
vtkCompositeDataSet* input)
void vtkAngularPeriodicFilter::CreatePeriodicDataSet(
vtkCompositeDataIterator* loc,
vtkCompositeDataSet* output,
vtkCompositeDataSet* input)
{
vtkDataObject* inputNode = input->GetDataSet(loc);
vtkNew<vtkMultiPieceDataSet> multiPiece;
// Number of periods
int periodsNb = 0;
// Rotation angle in degree
double angle = this->GetRotationAngle();
switch (this->GetRotationMode())
......@@ -117,15 +123,22 @@ void vtkAngularPeriodicFilter::SetRotationAxisToZ()
break;
case VTK_ROTATION_MODE_ARRAY_VALUE:
{
vtkDataArray* angleArray =
inputNode->GetFieldData()->GetArray(this->GetRotationArrayName());
if (!angleArray)
if (inputNode != NULL)
{
vtkErrorMacro(<< "Bad rotation mode.");
return;
vtkDataArray* angleArray =
inputNode->GetFieldData()->GetArray(this->GetRotationArrayName());
if (!angleArray)
{
vtkErrorMacro(<< "Bad rotation mode.");
return;
}
double angleRad = angleArray->GetTuple1(0);
angle = vtkMath::DegreesFromRadians(angleRad);
}
else
{
angle = 360;
}
double angleRad = angleArray->GetTuple1(0);
angle = vtkMath::DegreesFromRadians(angleRad);
break;
}
default:
......@@ -135,8 +148,6 @@ void vtkAngularPeriodicFilter::SetRotationAxisToZ()
}
}
// Number of iterations
vtkIdType periodsNb;
switch (this->GetIterationMode())
{
case VTK_ITERATION_MODE_DIRECT_NB:
......@@ -158,11 +169,7 @@ void vtkAngularPeriodicFilter::SetRotationAxisToZ()
}
}
multiPiece->SetNumberOfPieces(periodsNb);
if (periodsNb > 0 && inputNode != NULL)
{
// Shallow copy the first piece, it is not transformed
......@@ -178,8 +185,24 @@ void vtkAngularPeriodicFilter::SetRotationAxisToZ()
this->GeneratePieceName(input, loc, multiPiece.Get(), iPiece);
}
}
this->PeriodNumbers.push_back(periodsNb);
output->SetDataSet(loc, multiPiece.Get());
}
//----------------------------------------------------------------------------
void vtkAngularPeriodicFilter::SetPeriodNumber(vtkCompositeDataIterator* loc,
vtkCompositeDataSet* output,
int nbPeriod)
{
vtkMultiPieceDataSet* mp = vtkMultiPieceDataSet::SafeDownCast(output->GetDataSet(loc));
if (mp)
{
mp->SetNumberOfPieces(nbPeriod);
}
else
{
vtkErrorMacro(<< "Setting period on a non existent vtkMultiPieceDataSet");
}
}
//----------------------------------------------------------------------------
void vtkAngularPeriodicFilter::AppendPeriodicPiece(double angle,
......@@ -337,3 +360,40 @@ void vtkAngularPeriodicFilter::ComputePeriodicMesh(vtkPointSet* dataset,
// Shallow copy field data
transformedDataset->GetFieldData()->ShallowCopy(dataset->GetFieldData());
}
//----------------------------------------------------------------------------
int vtkAngularPeriodicFilter::RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
if (this->GetRotationMode() == VTK_ROTATION_MODE_ARRAY_VALUE &&
this->GetIterationMode() == VTK_ITERATION_MODE_MAX)
{
this->ReducePeriodNumbers = true;
}
return this->Superclass::RequestData(request, inputVector, outputVector);
}
//----------------------------------------------------------------------------
void vtkAngularPeriodicFilter::GeneratePieceName(vtkCompositeDataSet* input,
vtkCompositeDataIterator* inputLoc, vtkMultiPieceDataSet* output, vtkIdType outputId)
{
vtkDataObjectTree* inputTree = vtkDataObjectTree::SafeDownCast(input);
if (!inputTree)
{
return;
}
std::ostringstream ss;
const char* parentName =
inputTree->GetMetaData(inputLoc)->Get(vtkCompositeDataSet::NAME());
if (parentName)
{
ss << parentName;
}
else
{
ss << "Piece";
}
ss << "_period" << outputId;
output->GetMetaData(outputId)->Set(vtkCompositeDataSet::NAME(), ss.str().c_str());
}
......@@ -35,7 +35,7 @@
#ifndef vtkAngularPeriodicFilter_h
#define vtkAngularPeriodicFilter_h
#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkFiltersParallelModule.h" // For export macro
#include "vtkPeriodicFilter.h"
class vtkDataSetAttributes;
......@@ -45,7 +45,7 @@ class vtkPointSet;
#define VTK_ROTATION_MODE_DIRECT_ANGLE 0 // Use user-provided angle
#define VTK_ROTATION_MODE_ARRAY_VALUE 1 // Use array from input data as angle
class VTKFILTERSGENERAL_EXPORT vtkAngularPeriodicFilter : public vtkPeriodicFilter
class VTKFILTERSPARALLEL_EXPORT vtkAngularPeriodicFilter : public vtkPeriodicFilter
{
public:
static vtkAngularPeriodicFilter* New();
......@@ -94,6 +94,10 @@ protected:
vtkAngularPeriodicFilter();
~vtkAngularPeriodicFilter();
virtual int RequestData(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *);
// Description:
// Create a transform copy of the provided data array
vtkDataArray* TransformDataArray(vtkDataArray* inputArray,
......@@ -107,6 +111,12 @@ protected:
vtkDataObject* inputNode,
vtkMultiPieceDataSet* multiPiece);
// Description:
// Manually set the number of period on a specific leaf
virtual void SetPeriodNumber(vtkCompositeDataIterator* loc,
vtkCompositeDataSet* output,
int nbPeriod);
// Description:
// Compute periodic pointset, rotating point, using provided angle
void ComputePeriodicMesh(vtkPointSet* dataset, vtkPointSet* rotatedDataset,
......@@ -124,6 +134,12 @@ protected:
vtkCompositeDataSet* output,
vtkCompositeDataSet* input);
// Description:
// Generate a name for a piece in the periodic dataset from the input dataset
virtual void GeneratePieceName(vtkCompositeDataSet* input,
vtkCompositeDataIterator* inputLoc,
vtkMultiPieceDataSet* output,
vtkIdType outputId);
private:
vtkAngularPeriodicFilter(const vtkAngularPeriodicFilter&); // Not implemented.
void operator=(const vtkAngularPeriodicFilter&); // Not implemented.
......
......@@ -16,17 +16,16 @@
#include "vtkPeriodicFilter.h"
#include "vtkDataObjectTreeIterator.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkMultiProcessController.h"
#include <sstream>
//----------------------------------------------------------------------------
vtkPeriodicFilter::vtkPeriodicFilter()
{
this->IterationMode = VTK_ITERATION_MODE_MAX;
this->NumberOfPeriods = 1;
this->ReducePeriodNumbers = false;
}
//----------------------------------------------------------------------------
......@@ -85,6 +84,8 @@ int vtkPeriodicFilter::RequestData(vtkInformation *vtkNotUsed(request),
return 1;
}
this->PeriodNumbers.clear();
output->CopyStructure(input);
// Copy selected blocks over to the output.
......@@ -114,30 +115,34 @@ int vtkPeriodicFilter::RequestData(vtkInformation *vtkNotUsed(request),
}
iter->GoToNextItem();
}
iter->Delete();
return 1;
}
//----------------------------------------------------------------------------
void vtkPeriodicFilter::GeneratePieceName(vtkCompositeDataSet* input,
vtkCompositeDataIterator* inputLoc, vtkMultiPieceDataSet* output, vtkIdType outputId)
{
vtkDataObjectTree* inputTree = vtkDataObjectTree::SafeDownCast(input);
if (!inputTree)
{
return;
}
std::ostringstream ss;
const char* parentName =
inputTree->GetMetaData(inputLoc)->Get(vtkCompositeDataSet::NAME());
if (parentName)
// Reduce period number in case of parrallelism, and update empty multipieces
if (this->ReducePeriodNumbers)
{
ss << parentName;
}
else
{
ss << "Piece";
int* reducedPeriodNumbers = new int[this->PeriodNumbers.size()];
vtkMultiProcessController *controller = vtkMultiProcessController::GetGlobalController();
if (controller)
{
controller->AllReduce(&this->PeriodNumbers.front(), reducedPeriodNumbers,
this->PeriodNumbers.size(), vtkCommunicator::MAX_OP);
int i = 0;
iter->InitTraversal();
while (!iter->IsDoneWithTraversal() && this->Indices.size() > 0)
{
if (reducedPeriodNumbers[i] > this->PeriodNumbers[i])
{
const unsigned int index = iter->GetCurrentFlatIndex();
if (this->Indices.find(index) != this->Indices.end())
{
this->SetPeriodNumber(iter, output, reducedPeriodNumbers[i]);
}
}
iter->GoToNextItem();
i++;
}
}
delete [] reducedPeriodNumbers;
}
ss << "_period" << outputId;
output->GetMetaData(outputId)->Set(vtkCompositeDataSet::NAME(), ss.str().c_str());
iter->Delete();
return 1;
}
......@@ -32,10 +32,11 @@
#ifndef vtkPeriodicFilter_h
#define vtkPeriodicFilter_h
#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkFiltersParallelModule.h" // For export macro
#include "vtkMultiBlockDataSetAlgorithm.h"
#include <set> // For block selection
#include <vector> // For pieces number
class vtkCompositeDataIterator;
class vtkCompositeDataSet;
......@@ -45,7 +46,7 @@ class vtkMultiPieceDataSet;
#define VTK_ITERATION_MODE_DIRECT_NB 0 // Generate a user-provided number of periods
#define VTK_ITERATION_MODE_MAX 1 // Generate a maximum of periods, i.e. a full period.
class VTKFILTERSGENERAL_EXPORT vtkPeriodicFilter : public vtkMultiBlockDataSetAlgorithm
class VTKFILTERSPARALLEL_EXPORT vtkPeriodicFilter : public vtkMultiBlockDataSetAlgorithm
{
public:
vtkTypeMacro(vtkPeriodicFilter, vtkMultiBlockDataSetAlgorithm);
......@@ -102,11 +103,13 @@ protected:
vtkCompositeDataSet* input) = 0;
// Description:
// Generate a name for a piece in the periodic dataset from the input dataset
virtual void GeneratePieceName(vtkCompositeDataSet* input,
vtkCompositeDataIterator* inputLoc,
vtkMultiPieceDataSet* output,
vtkIdType outputId);
// Manually set the number of period on a specific leaf
virtual void SetPeriodNumber(vtkCompositeDataIterator* loc,
vtkCompositeDataSet* output,
int nbPeriod) = 0;
std::vector<int> PeriodNumbers; // Periods numbers by leaf
bool ReducePeriodNumbers;
private:
vtkPeriodicFilter(const vtkPeriodicFilter&); // Not implemented.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment