Commit e1f83f7c authored by Haocheng LIU's avatar Haocheng LIU

Expose vtkm's WarpVector filter to vtk

It uses the same API as vtkWarpVector filter.
parent fbcec203
......@@ -49,6 +49,7 @@ set(headers
vtkmThreshold.h
vtkmTriangleMeshPointNormals.h
vtkmWarpScalar.h
vtkmWarpVector.h
)
#implementation of the algorithms for cpu accelerators
......@@ -73,6 +74,7 @@ set(cpu_accelerator_srcs
vtkmThreshold.cxx
vtkmTriangleMeshPointNormals.cxx
vtkmWarpScalar.cxx
vtkmWarpVector.cxx
vtkmlib/Portals.cxx
vtkmlib/ImplicitFunctionConverter.cxx
)
......@@ -99,6 +101,7 @@ set(cuda_accelerator_srcs
vtkmThreshold.cu
vtkmTriangleMeshPointNormals.cu
vtkmWarpScalar.cu
vtkmWarpVector.cu
vtkmlib/Portals.cu
vtkmlib/ImplicitFunctionConverter.cu
)
......
......@@ -18,6 +18,7 @@ vtk_add_test_cxx(vtkAcceleratorsVtkmCxxTests tests
TestVTKMThreshold2.cxx
TestVTKMTriangleMeshPointNormals.cxx
TestVTKMWarpScalar.cxx
TestVTKMWarpVector.cxx
)
vtk_test_cxx_executable(vtkAcceleratorsVtkmCxxTests tests
RENDERING_FACTORY
......
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmWarpVector.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkDataSetMapper.h"
#include "vtkDataArray.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRegressionTestImage.h"
#include "vtkRTAnalyticSource.h"
#include "vtkSphereSource.h"
int TestVTKMWarpVector(int argc, char* argv[])
{
vtkNew<vtkRenderer> xyplaneRen, dataNormalRen;
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 300);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
// Define viewport ranges
// (xmin, ymin, xmax, ymax)
double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
double centerViewport[4] = {0.5, 0.0, 1.0, 1.0};
/// First window - xy plane
vtkSmartPointer<vtkRTAnalyticSource> xySource =
vtkSmartPointer<vtkRTAnalyticSource>::New();
xySource->SetWholeExtent(-100, 100, -100, 100, 1, 1);
xySource->SetCenter(0, 0, 0);
xySource->SetMaximum(255);
xySource->SetStandardDeviation(.5);
xySource->SetXFreq(60);
xySource->SetYFreq(30);
xySource->SetZFreq(40);
xySource->SetXMag(10);
xySource->SetYMag(18);
xySource->SetZMag(10);
xySource->SetSubsampleRate(1);
xySource->Update();
vtkNew<vtkFloatArray> xyVector;
xyVector->SetNumberOfComponents(3);
xyVector->SetName("scalarVector");
xyVector->SetNumberOfTuples(xySource->GetOutput()->GetNumberOfPoints());
for(vtkIdType i = 0; i < xySource->GetOutput()->GetNumberOfPoints(); i++)
{
xyVector->SetTuple3(i, 0.0, 0.0, 1.0);
}
xySource->GetOutput()->GetPointData()->AddArray(xyVector);
vtkNew<vtkmWarpVector> xyWarpVector;
xyWarpVector->SetScaleFactor(2);
xyWarpVector->SetInputConnection(xySource->GetOutputPort());
// Create a scalarVector array
xyWarpVector->SetInputArrayToProcess(0,0,0, vtkDataObject::FIELD_ASSOCIATION_POINTS,
"scalarVector");
xyWarpVector->Update();
vtkNew<vtkDataSetMapper> xyplaneMapper;
xyplaneMapper->SetInputConnection(xyWarpVector->GetOutputPort());
vtkNew<vtkActor> xyplaneActor;
xyplaneActor->SetMapper(xyplaneMapper);
renWin->AddRenderer(xyplaneRen);
xyplaneRen->SetViewport(leftViewport);
xyplaneRen->SetBackground(0.5, 0.4, 0.3);
xyplaneRen->AddActor(xyplaneActor);
/// Second window - data normal
vtkSmartPointer<vtkSphereSource> dataNormalSource =
vtkSmartPointer<vtkSphereSource>::New();
dataNormalSource->SetRadius(100);
dataNormalSource->SetThetaResolution(20);
dataNormalSource->SetPhiResolution(20);
dataNormalSource->Update();
auto dataNormalSourceOutput = dataNormalSource->GetOutput();
vtkNew<vtkmWarpVector> dataNormalWarpVector;
dataNormalWarpVector->SetScaleFactor(5);
dataNormalWarpVector->SetInputData(dataNormalSource->GetOutput());
dataNormalWarpVector->SetInputArrayToProcess(0,0,0,
vtkDataObject::POINT, dataNormalSourceOutput->GetPointData()->GetNormals()->GetName());
vtkNew<vtkDataSetMapper> dataNormalMapper;
dataNormalMapper->SetInputConnection(dataNormalWarpVector->GetOutputPort());
vtkNew<vtkActor> dataNormalActor;
dataNormalActor->SetMapper(dataNormalMapper);
renWin->AddRenderer(dataNormalRen);
dataNormalRen->SetViewport(centerViewport);
dataNormalRen->SetBackground(0.0, 0.7, 0.2);
dataNormalRen->AddActor(dataNormalActor);
xyplaneRen->ResetCamera();
dataNormalRen->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
3e366533603d32a147baca023a6b98a6ceb92f9b4a01fe28e3cb1f1a537c6bf9dd524680b5c433563da259a36fe787791a29b56b0ebbc2b21b72d495b4f01f76
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmWarpVector.cxx"
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmWarpVector.h"
#include "vtkmConfig.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkImageData.h"
#include "vtkImageDataToPointSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkRectilinearGrid.h"
#include "vtkRectilinearGridToPointSet.h"
#include "vtkUnstructuredGrid.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/DataSetConverters.h"
#include "vtkmlib/Storage.h"
#include "vtkmFilterPolicy.h"
#include "vtkm/cont/DataSetFieldAdd.h"
#include <vtkm/filter/WarpVector.h>
vtkStandardNewMacro(vtkmWarpVector)
//------------------------------------------------------------------------------
vtkmWarpVector::vtkmWarpVector() : vtkWarpVector()
{
}
//------------------------------------------------------------------------------
vtkmWarpVector::~vtkmWarpVector()
{
}
//------------------------------------------------------------------------------
int vtkmWarpVector::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
vtkSmartPointer<vtkPointSet> input = vtkPointSet::GetData(inputVector[0]);
vtkSmartPointer<vtkPointSet> output = vtkPointSet::GetData(outputVector);
if (!input)
{
// Try converting image data.
vtkImageData *inImage = vtkImageData::GetData(inputVector[0]);
if (inImage)
{
vtkNew<vtkImageDataToPointSet> image2points;
image2points->SetInputData(inImage);
image2points->Update();
input = image2points->GetOutput();
}
}
if (!input)
{
// Try converting rectilinear grid.
vtkRectilinearGrid *inRect = vtkRectilinearGrid::GetData(inputVector[0]);
if (inRect)
{
vtkNew<vtkRectilinearGridToPointSet> rect2points;
rect2points->SetInputData(inRect);
rect2points->Update();
input = rect2points->GetOutput();
}
}
if (!input)
{
vtkErrorMacro(<< "Invalid or missing input");
return 0;
}
vtkIdType numPts = input->GetPoints()->GetNumberOfPoints();
vtkDataArray* vectors = this->GetInputArrayToProcess(0, inputVector);
int vectorsAssociation = this->GetInputArrayAssociation(0, inputVector);
if (!vectors || !numPts)
{
vtkDebugMacro(<< "no input data");
return 1;
}
output->CopyStructure(input);
try
{
vtkm::cont::DataSet in = tovtkm::Convert(input, tovtkm::FieldsFlag::PointsAndCells);
vtkm::cont::Field vectorField = tovtkm::Convert(vectors,
vectorsAssociation);
in.AddField(vectorField);
vtkmInputFilterPolicy policy;
vtkm::filter::WarpVector warpVector(this->ScaleFactor);
warpVector.SetUseCoordinateSystemAsPrimaryField("true");
warpVector.SetVectorField(vectorField.GetName(), vectorField.GetAssociation());
auto result = warpVector.Execute(in, policy);
vtkDataArray* warpVectorResult = fromvtkm::Convert(
result.GetField("warpvector",vtkm::cont::Field::Association::POINTS));
vtkNew<vtkPoints> newPts;
newPts->SetNumberOfPoints(warpVectorResult->GetNumberOfTuples());
newPts->SetData(warpVectorResult);
output->SetPoints(newPts);
warpVectorResult->FastDelete();
}
catch (const vtkm::cont::Error& e)
{
vtkErrorMacro(<< "VTK-m error: " << e.GetMessage());
return 0;
}
// Update ourselves and release memory
output->GetPointData()->CopyNormalsOff(); // distorted geometry
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->CopyNormalsOff(); // distorted geometry
output->GetCellData()->PassData(input->GetCellData());
return 1;
}
//------------------------------------------------------------------------------
void vtkmWarpVector::PrintSelf(std::ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
/**
* @class vtkmWarpVector
* @brief deform geometry with vector data
*
* vtkWarpVector is a filter that modifies point coordinates by moving
* points along vector times the scale factor. Useful for showing flow
* profiles or mechanical deformation.
*
* The filter passes both its point data and cell data to its output.
*/
#ifndef vtkmWarpVector_h
#define vtkmWarpVector_h
#include "vtkWarpVector.h"
#include "vtkAcceleratorsVTKmModule.h" // required for correct export
class VTKACCELERATORSVTKM_EXPORT vtkmWarpVector : public vtkWarpVector
{
public:
vtkTypeMacro(vtkmWarpVector, vtkWarpVector)
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkmWarpVector* New();
protected:
vtkmWarpVector();
~vtkmWarpVector();
int RequestData(vtkInformation* , vtkInformationVector**,
vtkInformationVector*) override;
private:
vtkmWarpVector(const vtkmWarpVector&) = delete;
void operator=(const vtkmWarpVector&) = delete;
};
#endif // vtkmWarpVector_h
// VTK-HeaderTest-Exclude: vtkmWarpVector.h
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