Commit 6d5a3c0f authored by T.J. Corona's avatar T.J. Corona

Remove bathymetry operator.

It is no longer necessary to apply bathymetry to a model's
tessellation. Since the means of applying bathymetry to a mesh is
handled by ElevateMesh, this MR deprecates ApplyBathymetry and its
associated classes & tests.
parent f3628f7e
......@@ -18,7 +18,6 @@ if(SMTK_ENABLE_OPENCV)
endif()
set(srcs
vtkCMBApplyBathymetryFilter.cxx
vtkCleanPolylines.cxx
vtkDEMToMesh.cxx
vtkExtractImageBlock.cxx
......@@ -30,7 +29,6 @@ set(srcs
)
set(headers
vtkCMBApplyBathymetryFilter.h
vtkCleanPolylines.h
vtkDEMToMesh.h
vtkExtractImageBlock.h
......
//=========================================================================
// 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.
//=========================================================================
// .NAME vtkCMBApplyBathymetryFilter
// .SECTION Description
#ifndef __smtkdiscrete_vtkCMBApplyBathymetryFilter_h
#define __smtkdiscrete_vtkCMBApplyBathymetryFilter_h
#include "smtk/extension/vtk/filter/Exports.h" // For export macro
#include "vtkDataSetAlgorithm.h"
class vtkPoints;
class VTKSMTKFILTEREXT_EXPORT vtkCMBApplyBathymetryFilter : public vtkDataSetAlgorithm
{
public:
static vtkCMBApplyBathymetryFilter* New();
vtkTypeMacro(vtkCMBApplyBathymetryFilter, vtkDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
//Description:
//Set/Get the radius of the cone to use for elevation smoothing
vtkSetMacro(ElevationRadius, double);
vtkGetMacro(ElevationRadius, double);
//Description:
//Set/Get the highest z value which the input will be set to if
// UseHighestZValue is set to true. Default is 0.0
vtkSetMacro(HighestZValue, double);
vtkGetMacro(HighestZValue, double);
// Description:
// If "on", the input points' highest z values will be set to HighestZValue
// Default is OFF
vtkBooleanMacro(UseHighestZValue, bool);
vtkSetMacro(UseHighestZValue, bool);
vtkGetMacro(UseHighestZValue, bool);
//Description:
//Set/Get the lowest z value which the input will be set to if
// UseLowestZValue is set to true. Default is 0.0
vtkSetMacro(LowestZValue, double);
vtkGetMacro(LowestZValue, double);
// Description:
// If "on", the input points' lowest z values will be set to LowestZValue
// Default is OFF;
vtkBooleanMacro(UseLowestZValue, bool);
vtkSetMacro(UseLowestZValue, bool);
vtkGetMacro(UseLowestZValue, bool);
//Description:
//Set/Get the z value which the input will be set to if
// FlattenZValues is set to true. Default is 0.0
vtkSetMacro(FlatZValue, double);
vtkGetMacro(FlatZValue, double);
// Description:
// If "on", the input points' z values will be set to FlatZValue
vtkBooleanMacro(FlattenZValues, bool);
vtkSetMacro(FlattenZValues, bool);
vtkGetMacro(FlattenZValues, bool);
// Description:
// If "on", the output is simply a shallowcopy of input
vtkBooleanMacro(NoOP, bool);
vtkSetMacro(NoOP, bool);
vtkGetMacro(NoOP, bool);
// Description:
// Value for when bathymetry field has no supporting data
vtkSetMacro(InvalidValue, double);
vtkGetMacro(InvalidValue, double);
// Description:
// Invert scalar values
vtkBooleanMacro(InvertScalars, bool);
vtkSetMacro(InvertScalars, bool);
vtkGetMacro(InvertScalars, bool);
//Description:
//Remove all connections on port 0, dataset that will be altered
//with bathymetry
void RemoveInputConnections();
//Description:
//Remove all connection on port 1, point sources
void RemoveSourceConnections();
protected:
vtkCMBApplyBathymetryFilter();
~vtkCMBApplyBathymetryFilter() override;
int FillInputPortInformation(int port, vtkInformation* info) override;
int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
//methods for flattening mesh
bool FlattenMesh(vtkPoints*);
//methods for apply bathymetry
bool ApplyBathymetry(vtkPoints* points);
double ElevationRadius;
double HighestZValue;
bool UseHighestZValue;
double LowestZValue;
bool UseLowestZValue;
double FlatZValue;
bool FlattenZValues;
bool NoOP;
double InvalidValue;
bool InvertScalars;
class vtkCmbInternalTerrainInfo;
vtkCmbInternalTerrainInfo* TerrainInfo;
private:
vtkCMBApplyBathymetryFilter(const vtkCMBApplyBathymetryFilter&); // Not implemented.
void operator=(const vtkCMBApplyBathymetryFilter&); // Not implemented.
};
#endif
This diff is collapsed.
//=========================================================================
// 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.
//=========================================================================
#ifndef __smtk_model_BathymetryHelper_h
#define __smtk_model_BathymetryHelper_h
#include "smtk/PublicPointerDefs.h"
#include "smtk/SharedFromThis.h" // for smtkTypeMacroBase
#include "smtk/extension/vtk/operators/Exports.h" // for VTKSMTKOPERATORSEXT_EXPORT
#include "smtk/mesh/ForEachTypes.h"
#include "vtkSmartPointer.h"
#include <iostream>
#include <map>
#include <vector>
class vtkDataSet;
class vtkPolyData;
class vtkPoints;
namespace smtk
{
namespace model
{
static const std::string BO_elevation("bathymetry original elevations");
class Session;
/**\brief Helper class for loading and caching bathymetry files for session.
*
* This class will read the following files and cache their output:
* "LIDAR (*.pts *.bin *.bin.pts);;LAS (*.las);;DEM (*.hdr *.FLT *.ftw);;VTK files (*.vtk)"
*/
class VTKSMTKOPERATORSEXT_EXPORT BathymetryHelper
{
public:
smtkTypeMacroBase(BathymetryHelper);
virtual ~BathymetryHelper();
virtual bool loadBathymetryFile(const std::string& filename);
vtkDataSet* bathymetryData(const std::string& filename);
void loadedBathymetryFiles(std::vector<std::string>& result) const;
bool storeMeshPointsZ(smtk::mesh::CollectionPtr collection);
bool resetMeshPointsZ(smtk::mesh::CollectionPtr collection);
void clear();
bool computeBathymetryPoints(vtkDataSet* input, vtkPoints* output);
vtkIdType GenerateRepresentationFromModel(
vtkPoints* pts, const smtk::model::EntityRef& entityref);
void CopyCoordinatesToTessellation(
vtkPoints* pts, const smtk::model::EntityRef& entityref, const vtkIdType startingIndex);
void GetZValuesFromMasterModelPts(vtkPoints* pts, std::vector<double>& zValues);
bool SetZValuesIntoMasterModelPts(vtkPoints* pts, const std::vector<double>* zValues);
protected:
friend class Session;
friend class BathymetryOperator;
BathymetryHelper();
std::map<std::string, vtkSmartPointer<vtkDataSet> > m_filesToSources;
private:
BathymetryHelper(const BathymetryHelper& other); // Not implemented.
void operator=(const BathymetryHelper& other); // Not implemented.
const std::vector<double> m_dummy;
};
class ZValueHelper : public smtk::mesh::PointForEach
{
std::vector<double>& m_originalZs;
bool m_modifyZ;
public:
ZValueHelper(std::vector<double>& originalZs, bool modifyZ)
: m_originalZs(originalZs)
, m_modifyZ(modifyZ)
{
}
void forPoints(const smtk::mesh::HandleRange& pointIds, std::vector<double>& xyz,
bool& coordinatesModified) override
{
if (!m_modifyZ)
{
m_originalZs.resize(pointIds.size());
}
if (m_modifyZ && xyz.size() != (m_originalZs.size() * 3))
{
std::cerr << "originalZs size does not match with PointSet points!\n";
return;
}
coordinatesModified = m_modifyZ;
for (std::size_t offset = 0; offset < xyz.size(); offset += 3)
{
// modify
if (m_modifyZ)
{
//reset Z to original
xyz[offset + 2] = m_originalZs[offset / 3];
}
// copy
else
{
m_originalZs[offset / 3] = xyz[offset + 2];
}
}
}
};
} // namespace model
} // namespace smtk
#endif // __smtk_model_BathymetryHelper_h
This diff is collapsed.
//=========================================================================
// 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.
//=========================================================================
#ifndef __smtk_model_BathymetryOperator_h
#define __smtk_model_BathymetryOperator_h
#include "smtk/extension/vtk/operators/Exports.h" // For export macro
#include "smtk/model/Operator.h"
#include "vtkNew.h"
class vtkPolyData;
namespace smtk
{
namespace model
{
class BathymetryHelper;
class VTKSMTKOPERATORSEXT_EXPORT BathymetryOperator : public smtk::model::Operator
{
public:
smtkTypeMacro(BathymetryOperator);
smtkCreateMacro(BathymetryOperator);
smtkSharedFromThisMacro(Operator);
smtkDeclareModelOperator();
bool ableToOperate() override;
virtual ~BathymetryOperator();
protected:
BathymetryOperator();
smtk::model::OperatorResult operateInternal() override;
BathymetryHelper* bathyHelper;
};
} // namespace model
} // namespace smtk
#endif // __smtk_model_BathymetryOperator_h
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the CMB Model "apply bathymetry" Operator -->
<SMTK_AttributeSystem Version="2">
<Definitions>
<!-- Operator -->
<AttDef Type="apply bathymetry" Label="Mesh - Apply Bathymetry" BaseType="operator">
<BriefDescription>
Add or Remove elevation from a model or mesh.
</BriefDescription>
<DetailedDescription>
&lt;p&gt;Add or Remove elevation from a model or mesh.
&lt;p&gt;This operator modifies the z-coordinate of a model, a
mesh or both a model and a mesh according to an auxiliary
geometry. It computes new z-coordinates at each mesh node
as a radial average of the scalar values in the external data
set. The elevation data can be applied or removed.
</DetailedDescription>
<ItemDefinitions>
<String Name="operation" Label="Operation" Version="0" AdvanceLevel="0" NumberOfRequiredValues="1">
<ChildrenDefinitions>
<ModelEntity Name="auxiliary geometry" Label = "auxiliary geometry" NumberOfRequiredValues="1">
<MembershipMask>aux_geom</MembershipMask>
<BriefDescription>
Add auxiliary geometry first then apply bathymetry.
</BriefDescription>
</ModelEntity>
<ModelEntity Name="model" Label = "model" NumberOfRequiredValues="1">
<MembershipMask>model</MembershipMask>
</ModelEntity>
<MeshEntity Name="mesh" NumberOfRequiredValues="0" Extensible = "1">
<MembershipMask>mesh</MembershipMask>
</MeshEntity>
<Double Name="averaging elevation radius" Label="Radius for Averaging Elevation:" Version="0" NumberOfRequiredValues="1">
<BriefDescription>The radius used to identify a point locus
for computing elevation.</BriefDescription>
<DetailedDescription>
The radius used to identify a point locus for computing
elevation.
For each node in the input mesh or model tessellation,
a corresponding point locus whose positions projected
onto the x-y plane are within a radius of the node is
used to compute a new elevation value.
</DetailedDescription>
</Double>
<Double Name="set highest elevation" Label="Highest Elevation" Version="0" NumberOfRequiredValues="1" Optional="true">
</Double>
<Double Name="set lowest elevation" Label="Lowest Elevation" Version="0" NumberOfRequiredValues="1" Optional="true">
</Double>
<Void Name="invert scalars" Label="Invert Scalar Values" Version="0"
Optional="true" IsEnabledByDefault="false" AdvanceLevel="1">
<BriefDescription>This toggle adds a prefactor of -1 to the
values in the auxiliary geometry's bathymetry values.</BriefDescription>
</Void>
</ChildrenDefinitions>
<DiscreteInfo DefaultIndex="0">
<Structure>
<Value Enum="Apply Bathymetry (Auto)">Apply Bathymetry (Auto)</Value>
<Items>
<Item>auxiliary geometry</Item>
<Item>averaging elevation radius</Item>
<Item>set highest elevation</Item>
<Item>set lowest elevation</Item>
<Item>invert scalars</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Apply Bathymetry (Model&Mesh)">Apply Bathymetry (Model&Mesh)</Value>
<Items>
<Item>auxiliary geometry</Item>
<Item>averaging elevation radius</Item>
<Item>set highest elevation</Item>
<Item>set lowest elevation</Item>
<Item>invert scalars</Item>
<Item>mesh</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Apply Bathymetry (Model Only)">Apply Bathymetry (Model Only)</Value>
<Items>
<Item>auxiliary geometry</Item>
<Item>averaging elevation radius</Item>
<Item>set highest elevation</Item>
<Item>set lowest elevation</Item>
<Item>invert scalars</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Apply Bathymetry (Mesh only)">Apply Bathymetry (Mesh Only)</Value>
<Items>
<Item>auxiliary geometry</Item>
<Item>averaging elevation radius</Item>
<Item>set highest elevation</Item>
<Item>set lowest elevation</Item>
<Item>invert scalars</Item>
<Item>mesh</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Remove Bathymetry">Remove Bathymetry</Value>
<Items>
<Item>model</Item>
</Items>
</Structure>
</DiscreteInfo>
</String>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<AttDef Type="result(apply bathymetry)" BaseType="result">
<ItemDefinitions>
<ModelEntity Name="tess_changed" NumberOfRequiredValues="1"/>
<!-- The modified entities are stored in the base result's "modified" item. -->
<MeshEntity Name="mesh_modified" NumberOfRequiredValues="0" Extensible="true" AdvanceLevel="11"/>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeSystem>
set(srcs
vtkSMTKOperator.cxx
BathymetryHelper.cxx
BathymetryOperator.cxx
ElevateMesh.cxx
ExportEdgesToVTK.cxx
)
set(headers
vtkSMTKOperator.h
BathymetryHelper.h
BathymetryOperator.h
ElevateMesh.h
ExportEdgesToVTK.h
)
smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/BathymetryOperator.sbt" smtkVTKOperatorXML)
smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/ElevateMesh.sbt" smtkVTKOperatorXML)
smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/ExportEdgesToVTK.sbt" smtkVTKOperatorXML)
set_source_files_properties(
BathymetryHelper.cxx
BathymetryOperator.cxx
ElevateMesh.cxx
ExportEdgesToVTK.cxx
PROPERTIES
......
......@@ -4,7 +4,7 @@
<Definitions>
<!-- Operator -->
<AttDef Type="elevate mesh"
Label="Mesh - Elevate" BaseType="operator">
Label="Mesh - Apply Elevation" BaseType="operator">
<BriefDescription>
Modify the z-coordinates a mesh's nodes according to an
external data set.
......
......@@ -11,5 +11,4 @@
#include "smtk/AutoInit.h"
#include "smtk/Options.h"
smtkComponentInitMacro(smtk_apply_bathymetry_operator);
smtkComponentInitMacro(smtk_export_edges_to_vtk_operator);
//=========================================================================
// 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.
//=========================================================================
#include "smtk/bridge/discrete/Session.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/DoubleItem.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/model/EntityPhrase.h"
#include "smtk/model/EntityRef.h"
#include "smtk/model/Face.h"
#include "smtk/model/Group.h"
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/model/Operator.h"
#include "smtk/model/SimpleModelSubphrases.h"
#include "smtk/model/Tessellation.h"
#include "smtk/mesh/testing/cxx/helpers.h"
#include "smtk/extension/vtk/source/vtkModelMultiBlockSource.h"
#include "vtkActor.h"
#include "vtkCommand.h"
#include "vtkCompositePolyDataMapper.h"
#include "vtkDataSetAttributes.h"
#include "vtkInteractorStyleSwitch.h"
#include "vtkNew.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkStringArray.h"
#include "vtkXMLMultiBlockDataWriter.h"
#include "vtkRegressionTestImage.h"
using namespace smtk::model;
int main(int argc, char* argv[])
{
if (argc < 2)
return 1;
smtk::model::ManagerPtr manager = smtk::model::Manager::create();
std::cout << "Available sessions\n";
StringList sessions = manager->sessionTypeNames();
for (StringList::iterator it = sessions.begin(); it != sessions.end(); ++it)
std::cout << " " << *it << "\n";
std::cout << "\n";
smtk::bridge::discrete::Session::Ptr session = smtk::bridge::discrete::Session::create();
manager->registerSession(session);
std::cout << "Available cmb operators in discrete session\n";
StringList opnames = session->operatorNames();
for (StringList::iterator it = opnames.begin(); it != opnames.end(); ++it)
std::cout << " " << *it << "\n";
std::cout << "\n";
// read the data
smtk::model::OperatorPtr readOp = session->op("read");
if (!readOp)
{
std::cerr << "No read operator\n";
return 1;
}
readOp->specification()->findFile("filename")->setValue(std::string(argv[1]));
std::cout << "Importing " << argv[1] << "\n";
smtk::model::OperatorResult opresult = readOp->operate();
if (opresult->findInt("outcome")->value() != smtk::operation::Operator::OPERATION_SUCCEEDED)
{
std::cerr << "Read operator failed\n";
return 1;
}
// assign model value
smtk::model::Model modelChesaBay = opresult->findModelEntity("created")->value();
manager->assignDefaultNames(); // should force transcription of every entity, but doesn't yet.
if (!modelChesaBay.isValid())
{
std::cerr << "Reading bay contour file failed!\n";
return 1;
}
// add auxiliary geometry
smtk::model::OperatorPtr aux_geOp = session->op("add auxiliary geometry");
std::cout << "The url for auxiliary geometry is: " << argv[2] << std::endl;
aux_geOp->specification()->findFile("url")->setValue(std::string(argv[2]));
aux_geOp->associateEntity(modelChesaBay);
smtk::model::OperatorResult aux_geOpresult = aux_geOp->operate();
if (aux_geOpresult->findInt("outcome")->value() != smtk::operation::Operator::OPERATION_SUCCEEDED)
{
std::cerr << "Add auxiliary geometry failed!\n";
return 1;
}
smtk::model::AuxiliaryGeometry auxGoChesaBay =
aux_geOpresult->findModelEntity("created")->value();
std::cout << "After aux_geo op, the url inside is: " << auxGoChesaBay.url() << std::endl;
if (!auxGoChesaBay.isValid())
{
std::cerr << "Auxiliary geometry is not valid!\n";
return 1;
}
// create the bathymetry operator
std::cout << "Creating apply bathymetry operator\n";
smtk::model::OperatorPtr bathyOperator = session->op("apply bathymetry");
if (!bathyOperator)
{
std::cerr << "No apply bathymetry!\n";
return 1;
}
// Check the optypeItem value
std::cout << "optypeItem initial value is: "
<< bathyOperator->specification()->findString("operation")->value() << std::endl;
// set input values for bathymetry filter
bathyOperator->specification()->findModelEntity("auxiliary geometry")->setValue(auxGoChesaBay);
bathyOperator->specification()->findDouble("averaging elevation radius")->setValue(0.05);
smtk::model::OperatorResult bathyResult = bathyOperator->operate();
if (bathyResult->findInt("outcome")->value() != smtk::operation::Operator::OPERATION_SUCCEEDED)
{
std::cerr << "Apply bathymetry operator failed\n";
return 1;
}
// Remove the bathymetry operator test
//bathyOperator->specification()->findString("operation")->setValue("Remove Bathymetry");
//std::cout<<"optypeItem value in Bathymetry Operator is: "<< bathyOperator->specification()->findString("operation")->value() << std::endl;
//smtk::model::OperatorResult RmBathyResult = bathyOperator->operate();
//if (RmBathyResult->findInt("outcome")->value() != smtk::operation::Operator::OPERATION_SUCCEEDED)
//{
// std::cerr<< "Remove Bathymetry operator failed\n";
// return 1;
//}
vtkNew<vtkActor> act;
vtkNew<vtkModelMultiBlockSource> src;
vtkNew<vtkCompositePolyDataMapper> map;
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> win;
src->SetModelManager(manager);
win->SetMultiSamples(0);
src->AllowNormalGenerationOn();
map->SetInputConnection(src->GetOutputPort());
act->SetMapper(map.GetPointer());
act->SetScale(100, 100, 1);
win->AddRenderer(ren.GetPointer());
ren->AddActor(act.GetPointer());
ren->SetBackground(0.5, 0.5, 1);
vtkRenderWindowInteractor* iac = win->MakeRenderWindowInteractor();
vtkInteractorStyleSwitch::SafeDownCast(iac->GetInteractorStyle())
->SetCurrentStyleToTrackballCamera();
win->SetInteractor(iac);
win->Render();
ren->ResetCamera();
int reVal = vtkRegressionTestImage(win.GetPointer());
if (reVal == vtkRegressionTester::DO_INTERACTOR)
{
iac->Start();
}
return !reVal;
}
// This macro ensures the vtk io library is loaded into the executable
smtkComponentInitMacro(smtk_apply_bathymetry_operator)
//=========================================================================
// 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.