Commit 5a11d5dc authored by Haocheng LIU's avatar Haocheng LIU

Expose vtkm point elevation filter

parent cb5d53ac
......@@ -32,6 +32,7 @@ set(lib_srcs
#needed to properly setup language wrappers
set(headers
vtkmAverageToCells.h
vtkmAverageToPoints.h
vtkmCleanGrid.h
vtkmClip.h
......@@ -40,14 +41,15 @@ set(headers
vtkmExtractVOI.h
vtkmThreshold.h
vtkmLevelOfDetail.h
vtkmAverageToCells.h
vtkmGradient.h
vtkmPointElevation.h
vtkmPolyDataNormals.h
vtkmTriangleMeshPointNormals.h
)
#implementation of the algorithms for cpu accelerators
set(cpu_accelerator_srcs
vtkmAverageToCells.cxx
vtkmAverageToPoints.cxx
vtkmCleanGrid.cxx
vtkmClip.cxx
......@@ -56,11 +58,11 @@ set(cpu_accelerator_srcs
vtkmExtractVOI.cxx
vtkmThreshold.cxx
vtkmLevelOfDetail.cxx
vtkmAverageToCells.cxx
vtkmCellSetExplicit.cxx
vtkmCellSetSingleType.cxx
vtkmConnectivityExec.cxx
vtkmGradient.cxx
vtkmPointElevation.cxx
vtkmPolyDataNormals.cxx
vtkmTriangleMeshPointNormals.cxx
vtkmlib/Portals.cxx
......@@ -82,6 +84,7 @@ set(cuda_accelerator_srcs
vtkmCellSetSingleType.cu
vtkmConnectivityExec.cu
vtkmGradient.cu
vtkmPointElevation.cu
vtkmPolyDataNormals.cu
vtkmTriangleMeshPointNormals.cu
vtkmlib/Portals.cu
......
......@@ -9,6 +9,7 @@ vtk_add_test_cxx(vtkAcceleratorsVtkmCxxTests tests
TestVTKMLevelOfDetail.cxx
TestVTKMMarchingCubes.cxx
TestVTKMMarchingCubes2.cxx
TestVTKMPointElevation.cxx
TestVTKMPolyDataNormals.cxx
TestVTKMThreshold.cxx
TestVTKMThreshold2.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 "vtkActor.h"
#include "vtkCamera.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkPlaneSource.h"
#include "vtkmPointElevation.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPoints.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTriangleFilter.h"
namespace
{
int RunVTKPipeline(vtkPlaneSource* plane, int argc, char* argv[])
{
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
renWin->AddRenderer(ren);
iren->SetRenderWindow(renWin);
vtkNew<vtkTriangleFilter> tf;
tf->SetInputConnection(plane->GetOutputPort());
tf->Update();
vtkNew<vtkPolyData> pd;
pd->CopyStructure(tf->GetOutput());
vtkIdType numPts = pd->GetNumberOfPoints();
vtkPoints* oldPts = tf->GetOutput()->GetPoints();
vtkNew<vtkPoints> newPts;
newPts->SetNumberOfPoints(numPts);
for (vtkIdType i = 0; i < numPts; i++)
{
auto pt = oldPts->GetPoint(i);
auto r = sqrt(pow(pt[0],2) + pow(pt[1], 2));
auto z = 1.5 * cos (2* r);
newPts->SetPoint(i, pt[0], pt[1], z);
}
pd->SetPoints(newPts);
vtkNew<vtkmPointElevation> pe;
pe->SetInputData(pd);
pe->SetLowPoint(0, 0, -1.5);
pe->SetHighPoint(0, 0, 1.5);
pe->SetScalarRange(-1.5, 1.5);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(pe->GetOutputPort());
mapper->ScalarVisibilityOn();
mapper->SelectColorArray("elevation");
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
// Add the actor to the renderer, set the background and size
ren->AddActor(actor);
ren->SetBackground(0, 0, 0);
vtkNew<vtkCamera> camera;
camera->SetPosition(1, 50, 50);
ren->SetActiveCamera(camera);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if(retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
retVal = vtkRegressionTester::PASSED;
}
return (!retVal);
}
} // Anonymous namespace
int TestVTKMPointElevation(int argc, char* argv[])
{
// Create a plane source
vtkNew<vtkPlaneSource> plane;
int res = 200;
plane->SetXResolution(res);
plane->SetYResolution(res);
plane->SetOrigin(-10, -10, 0);
plane->SetPoint1(10, -10, 0);
plane->SetPoint2(-10, 10, 0);
// Run the pipeline
return RunVTKPipeline(plane, argc, argv);
}
029e47f874e502e228edfe40f48443920cbcbdb158f40ad3ff0cba2acf6deb409c58238fb62bbec0671d1d0f98f64216df07ad817a7618beb2dcfb3ebab80152
//=============================================================================
//
// 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 "vtkmPointElevation.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 "vtkmPointElevation.h"
#include "vtkmConfig.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/DataSetConverters.h"
#include "vtkmlib/Storage.h"
#include "vtkmlib/UnstructuredGridConverter.h"
#include "vtkmFilterPolicy.h"
#include <vtkm/filter/PointElevation.h>
vtkStandardNewMacro(vtkmPointElevation)
//------------------------------------------------------------------------------
vtkmPointElevation::vtkmPointElevation()
{
}
//------------------------------------------------------------------------------
vtkmPointElevation::~vtkmPointElevation()
{
}
//------------------------------------------------------------------------------
int vtkmPointElevation::RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// Get the input and output data objects.
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkDataSet* input =
vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet* output = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->ShallowCopy(input);
// Check the size of the input.
vtkIdType numPts = input->GetNumberOfPoints();
if(numPts < 1)
{
vtkDebugMacro("No input!");
return 1;
}
try
{
// Convert the input dataset to a vtkm::cont::DataSet
auto in = tovtkm::Convert(input, tovtkm::FieldsFlag::Points);
vtkmInputFilterPolicy policy;
// Setup input
vtkm::filter::PointElevation filter;
filter.SetLowPoint(this->LowPoint[0],this->LowPoint[1],
this->LowPoint[2]);
filter.SetHighPoint(this->HighPoint[0],this->HighPoint[1],
this->HighPoint[2]);
filter.SetRange(this->ScalarRange[0], this->ScalarRange[1]);
filter.SetOutputFieldName("elevation");
filter.SetUseCoordinateSystemAsField(true);
auto result = filter.Execute(in, policy);
// Convert the result back
vtkDataArray* resultingArray =
fromvtkm::Convert(result.GetField("elevation"));
if (resultingArray == nullptr)
{
vtkErrorMacro(<< "Unable to convert result array from VTK-m to VTK");
return 0;
}
output->GetPointData()->AddArray(resultingArray);
output->GetPointData()->SetActiveScalars("elevation");
resultingArray->FastDelete();
}
catch (const vtkm::cont::Error& e)
{
vtkErrorMacro(<< "VTK-m error: " << e.GetMessage()
<< "Falling back to serial implementation");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
return 1;
}
//------------------------------------------------------------------------------
void vtkmPointElevation::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 vtkmPointElevation
* @brief generate a scalar field along a specified direction
*
* vtkmPointElevation is a filter that generates a scalar field along a specified
* direction. The scalar field values lie within a user specified range, and are
* generated by computing a projection of each dataset point onto a line. The line
* can be oriented arbitrarily. A typical example is to generate scalars based
* on elevation or height above a plane.
*
*/
#ifndef vtkmPointElevation_h
#define vtkmPointElevation_h
#include "vtkElevationFilter.h"
#include "vtkAcceleratorsVTKmModule.h" // required for correct export
class VTKACCELERATORSVTKM_EXPORT vtkmPointElevation : public vtkElevationFilter
{
public:
vtkTypeMacro(vtkmPointElevation, vtkElevationFilter)
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkmPointElevation* New();
protected:
vtkmPointElevation();
~vtkmPointElevation();
virtual int RequestData(vtkInformation* , vtkInformationVector**,
vtkInformationVector*) override;
private:
vtkmPointElevation(const vtkmPointElevation&) = delete;
void operator=(const vtkmPointElevation&) = delete;
};
#endif // vtkmPointElevation_h
// VTK-HeaderTest-Exclude: vtkmPointElevation.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