From c00257e9d9b2d8cf5ccd861905b2663457dad6ba Mon Sep 17 00:00:00 2001 From: Jacob Becker Date: Tue, 14 Jun 2016 17:25:09 -0400 Subject: [PATCH 1/2] move bathymetry to a filters directory so it is exposed --- smtk/bridge/discrete/CMakeLists.txt | 3 +- .../discrete/operators/BathymetryOperator.cxx | 2 +- smtk/extension/vtk/filter/CMakeLists.txt | 31 +++++++++++++++++++ smtk/extension/vtk/filter/module.cmake | 11 +++++++ .../filter}/vtkCMBApplyBathymetryFilter.cxx | 3 +- .../vtk/filter}/vtkCMBApplyBathymetryFilter.h | 4 +-- 6 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 smtk/extension/vtk/filter/CMakeLists.txt create mode 100644 smtk/extension/vtk/filter/module.cmake rename smtk/{bridge/discrete/operation => extension/vtk/filter}/vtkCMBApplyBathymetryFilter.cxx (99%) rename smtk/{bridge/discrete/operation => extension/vtk/filter}/vtkCMBApplyBathymetryFilter.h (95%) diff --git a/smtk/bridge/discrete/CMakeLists.txt b/smtk/bridge/discrete/CMakeLists.txt index 802d5ed32f..25d094d3a5 100644 --- a/smtk/bridge/discrete/CMakeLists.txt +++ b/smtk/bridge/discrete/CMakeLists.txt @@ -47,7 +47,6 @@ SET(DiscreteModelFiles ) SET(DiscreteOperationFiles - operation/vtkCMBApplyBathymetryFilter.cxx operation/vtkCMBModelPointsOperator.cxx operation/vtkEdgeSplitOperator.cxx operation/vtkEdgeSplitOperatorBase.cxx @@ -75,7 +74,6 @@ SET(DiscreteOperationFiles ) SET(DiscreteModelHeaders - operation/vtkCMBApplyBathymetryFilter.h operation/vtkCMBModelPointsOperator.h operation/vtkCMBMapToCMBModel.h operation/vtkCMBModelBuilder.h @@ -225,6 +223,7 @@ target_link_libraries(smtkDiscreteSession vtkPVVTKExtensionsDefault vtkSMTKReaderExt vtkSMTKDiscreteModel + vtkSMTKFilterExt ) if (SMTK_ENABLE_REMUS_SUPPORT) diff --git a/smtk/bridge/discrete/operators/BathymetryOperator.cxx b/smtk/bridge/discrete/operators/BathymetryOperator.cxx index 8e00340174..714fe35803 100644 --- a/smtk/bridge/discrete/operators/BathymetryOperator.cxx +++ b/smtk/bridge/discrete/operators/BathymetryOperator.cxx @@ -12,7 +12,7 @@ #include "smtk/bridge/discrete/Session.h" #include "smtk/bridge/discrete/BathymetryHelper.h" -#include "smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.h" +#include "smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h" #include "smtk/attribute/Attribute.h" #include "smtk/attribute/Definition.h" diff --git a/smtk/extension/vtk/filter/CMakeLists.txt b/smtk/extension/vtk/filter/CMakeLists.txt new file mode 100644 index 0000000000..8de4f11dbb --- /dev/null +++ b/smtk/extension/vtk/filter/CMakeLists.txt @@ -0,0 +1,31 @@ + +set(srcs + vtkCMBApplyBathymetryFilter.cxx + ) + +set(headers + vtkCMBApplyBathymetryFilter.h +) + +set(${vtk-module}_NO_HeaderTest 1) +set(VTK_INSTALL_NO_HEADERS 1) +vtk_module_library(${vtk-module} ${srcs}) +target_include_directories(${vtk-module} + PUBLIC + $ + $ + $) + +# ... and make header compilation tests link properly: +smtk_install_library(${vtk-module}) + +# ... and install the export header +#has to be after the vtk_module_library +smtk_export_header(${vtk-module} Exports.h) + +if (SMTK_ENABLE_PARAVIEW_SUPPORT) + vtk_add_cs_wrapping(${vtk-module}) + smtk_install_library(${vtk-module}CS) +endif () + +smtk_public_headers(${headers}) diff --git a/smtk/extension/vtk/filter/module.cmake b/smtk/extension/vtk/filter/module.cmake new file mode 100644 index 0000000000..8c088e7432 --- /dev/null +++ b/smtk/extension/vtk/filter/module.cmake @@ -0,0 +1,11 @@ +set (__dependencies) + +vtk_module(vtkSMTKFilterExt + DEPENDS + vtkCommonCore + PRIVATE_DEPENDS + vtkFiltersGeneral + ${__dependencies} + TEST_DEPENDS + EXCLUDE_FROM_WRAP_HIERARCHY +) diff --git a/smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.cxx b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx similarity index 99% rename from smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.cxx rename to smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx index 9abe1cd715..dbdeb294f1 100644 --- a/smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.cxx +++ b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx @@ -7,8 +7,7 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //========================================================================= - -#include "smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.h" +#include "smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h" #include "vtkCellArray.h" #include "vtkCellData.h" diff --git a/smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.h b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h similarity index 95% rename from smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.h rename to smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h index ba35a89ebf..d57c1bfc36 100644 --- a/smtk/bridge/discrete/operation/vtkCMBApplyBathymetryFilter.h +++ b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h @@ -14,12 +14,12 @@ #ifndef __smtkdiscrete_vtkCMBApplyBathymetryFilter_h #define __smtkdiscrete_vtkCMBApplyBathymetryFilter_h -#include "smtk/bridge/discrete/Exports.h" // For export macro +#include "smtk/extension/vtk/filter/Exports.h" // For export macro #include "vtkDataSetAlgorithm.h" class vtkPoints; -class SMTKDISCRETESESSION_EXPORT vtkCMBApplyBathymetryFilter : public vtkDataSetAlgorithm +class VTKSMTKFILTEREXT_EXPORT vtkCMBApplyBathymetryFilter : public vtkDataSetAlgorithm { public: static vtkCMBApplyBathymetryFilter *New(); -- GitLab From 04ee39f7009a48aa2382c0ceb53636a8eff3f42f Mon Sep 17 00:00:00 2001 From: Jacob Becker Date: Tue, 14 Jun 2016 18:13:20 -0400 Subject: [PATCH 2/2] performance improvements and add a no data value --- .../filter/vtkCMBApplyBathymetryFilter.cxx | 60 +++++++++++-------- .../vtk/filter/vtkCMBApplyBathymetryFilter.h | 6 ++ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx index dbdeb294f1..1a4f687b6b 100644 --- a/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx +++ b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.cxx @@ -44,7 +44,7 @@ namespace{ } template void copyArrayZValues(T *t, vtkIdType size, - std::map& idToElevation, + std::vector& idToElevation, bool useHighLimit, double eleHigh, bool useLowLimit, double eleLow) { double dtmp; @@ -61,7 +61,7 @@ namespace{ class vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo { public: - vtkCmbInternalTerrainInfo(vtkInformation* input, const double &radius, + vtkCmbInternalTerrainInfo(vtkInformation* input, const double &radius, double &invalid, bool useHighLimit, double eleHigh, bool useLowLimit, double eleLow); ~vtkCmbInternalTerrainInfo() { @@ -75,17 +75,19 @@ public: Radius = r; } - std::map IdToElevation; + std::vector IdToElevation; protected: double Radius; + double InvalidValue; vtkSmartPointer Locator; }; //----------------------------------------------------------------------------- vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInfo( - vtkInformation* inInfo, const double &radius, - bool useHighLimit, double eleHigh, bool useLowLimit, double eleLow): Radius(radius) - { + vtkInformation* inInfo, const double &radius, double &invalid, + bool useHighLimit, double eleHigh, bool useLowLimit, double eleLow) +: Radius(radius), InvalidValue(invalid) +{ //1. Create a set of points while removing all the z values from the points //and storing them in the map. //2. Create locater of the resulting 2D point set @@ -117,10 +119,10 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf //second iteration is building the point set and elevation mapping vtkPoints *inputPoints = NULL; vtkPoints *points = vtkPoints::New(); - vtkIdType size, i, j; + vtkIdType size, i; double p[3]; double dtmp; - // Uniform Grids may not have the max number of points + // Uniform Grids may not have the max number of points if (gridInput) { vtkDataArray *dataArray = gridInput->GetPointData()->GetScalars("Elevation"); @@ -128,7 +130,9 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf { return; } - points->Allocate(numPoints); + points->SetNumberOfPoints(numPoints); + this->IdToElevation.resize(numPoints); + vtkIdType at = 0; for (i = 0; numPoints; i++) { if (!gridInput->IsPointVisible(i)) @@ -142,9 +146,12 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf //flatten z p[2] = 0.0; - j = points->InsertNextPoint(p); - this->IdToElevation[j]=dtmp; + points->SetPoint(at, p); + this->IdToElevation[at]=dtmp; + ++at; } + points->Resize(at); + this->IdToElevation.resize(at); } else { @@ -153,6 +160,8 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf { inputPoints = pd->GetPoints(); size = inputPoints->GetNumberOfPoints(); + points->SetNumberOfPoints(size); + this->IdToElevation.resize(size); for (i=0; i < size; ++i) { //get the point @@ -163,12 +172,14 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf //store the z value & flatten this->IdToElevation[i]=dtmp; p[2] = 0.0; - points->InsertPoint(i,p); + points->SetPoint(i,p); } } else if(imageInput) { size = imageInput->GetNumberOfPoints(); + points->SetNumberOfPoints(size); + this->IdToElevation.resize(size); vtkDataArray *dataArray = imageInput->GetPointData()->GetScalars("Elevation"); if(!dataArray || dataArray->GetNumberOfTuples() != size) { @@ -196,7 +207,7 @@ vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::vtkCmbInternalTerrainInf //flatten z p[2] = 0.0; - points->InsertPoint(i,p); + points->SetPoint(i,p); } } } @@ -229,16 +240,13 @@ T vtkCMBApplyBathymetryFilter::vtkCmbInternalTerrainInfo::getElevation( for ( vtkIdType i=0; i < size; ++i) { //average the elevation - it = this->IdToElevation.find(ids->GetId(i)); - if ( it != this->IdToElevation.end() ) - { - sum += it->second; - } + assert(ids->GetId(i)IdToElevation.size()); + sum += this->IdToElevation[ids->GetId(i)]; } ids->Delete(); //handle the zero size use case - T elev = static_cast((size == 0) ? dpoint[2] : sum/size); + T elev = static_cast((size == 0) ? InvalidValue : sum/size); return elev; } @@ -254,6 +262,7 @@ vtkCMBApplyBathymetryFilter::vtkCMBApplyBathymetryFilter() this->UseHighestZValue = false; this->UseLowestZValue = false; this->HighestZValue=this->LowestZValue=0.0; + this->InvalidValue = 0.0; } //----------------------------------------------------------------------------- @@ -267,7 +276,7 @@ vtkCMBApplyBathymetryFilter::~vtkCMBApplyBathymetryFilter() //---------------------------------------------------------------------------- int vtkCMBApplyBathymetryFilter::FillInputPortInformation(int port, - vtkInformation *info) + vtkInformation *info) { info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet"); info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1); @@ -292,8 +301,8 @@ void vtkCMBApplyBathymetryFilter::RemoveSourceConnections() //---------------------------------------------------------------------------- int vtkCMBApplyBathymetryFilter::RequestData(vtkInformation* /*request*/, - vtkInformationVector** inputVector, - vtkInformationVector* outputVector) + vtkInformationVector** inputVector, + vtkInformationVector* outputVector) { // get the info and input data vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); @@ -326,9 +335,9 @@ int vtkCMBApplyBathymetryFilter::RequestData(vtkInformation* /*request*/, //Construct the TerrainInfo first this->TerrainInfo = new vtkCmbInternalTerrainInfo( inputVector[1]->GetInformationObject(0), - this->ElevationRadius, this->UseHighestZValue, + this->ElevationRadius, this->InvalidValue, this->UseHighestZValue, this->HighestZValue, this->UseLowestZValue, this->LowestZValue); - if(this->TerrainInfo->IdToElevation.size()>0) + if(!this->TerrainInfo->IdToElevation.empty()) { validMesh = this->ApplyBathymetry(finalMesh->GetPoints()); } @@ -415,4 +424,5 @@ void vtkCMBApplyBathymetryFilter::PrintSelf(ostream& os, vtkIndent indent) os << indent << "ElevationRadius: " << this->ElevationRadius << std::endl; os << indent << "FlatZValue: " << this->FlatZValue << std::endl; os << indent << "FlattenZValues: " << this->FlattenZValues << std::endl; -} + os << indent << "InvalidValue: " << this->InvalidValue << std::endl; +} \ No newline at end of file diff --git a/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h index d57c1bfc36..4fc7209df9 100644 --- a/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h +++ b/smtk/extension/vtk/filter/vtkCMBApplyBathymetryFilter.h @@ -75,6 +75,11 @@ public: vtkSetMacro(NoOP, bool); vtkGetMacro(NoOP, bool); + // Description: + // Value for when bathymetry field has no supporting data + vtkSetMacro(InvalidValue, double); + vtkGetMacro(InvalidValue, double); + //Description: //Remove all connections on port 0, dataset that will be altered //with bathymetry @@ -108,6 +113,7 @@ protected: double FlatZValue; bool FlattenZValues; bool NoOP; + double InvalidValue; class vtkCmbInternalTerrainInfo; vtkCmbInternalTerrainInfo *TerrainInfo; -- GitLab