Commit a3f04ed8 authored by T.J. Corona's avatar T.J. Corona

Update mesh I/O operations.

parent 0ae19c3b
......@@ -41,11 +41,13 @@ set(meshSrcs
operators/DeleteMesh.cxx
operators/ElevateMesh.cxx
operators/ExportMesh.cxx
operators/Export.cxx
operators/GenerateHotStartData.cxx
operators/Import.cxx
operators/InterpolateOntoMesh.cxx
operators/Read.cxx
operators/UndoElevateMesh.cxx
operators/WriteMesh.cxx
operators/Write.cxx
resource/Registrar.cxx
......@@ -96,11 +98,13 @@ set(meshHeaders
operators/DeleteMesh.h
operators/ElevateMesh.h
operators/ExportMesh.h
operators/Export.h
operators/GenerateHotStartData.h
operators/Import.h
operators/InterpolateOntoMesh.h
operators/Read.h
operators/UndoElevateMesh.h
operators/WriteMesh.h
operators/Write.h
resource/PropertyData.h
resource/Registrar.h
......@@ -115,11 +119,13 @@ set(meshHeaders
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/DeleteMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/ElevateMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/ExportMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Export.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/GenerateHotStartData.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Import.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/InterpolateOntoMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Read.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/UndoElevateMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/WriteMesh.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Write.sbt" defOpXML)
#install the headers
smtk_public_headers(smtkCore ${meshHeaders})
......
......@@ -8,17 +8,21 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/mesh/operators/ExportMesh.h"
#include "smtk/mesh/operators/Export.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/FileItemDefinition.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/io/ExportMesh.h"
#include "smtk/io/mesh/MeshIO.h"
#include "smtk/mesh/ExportMesh_xml.h"
#include "smtk/mesh/Export_xml.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/core/MeshSet.h"
......@@ -53,7 +57,7 @@ namespace smtk
namespace mesh
{
bool ExportMesh::ableToOperate()
bool Export::ableToOperate()
{
if (!this->Superclass::ableToOperate())
{
......@@ -62,7 +66,7 @@ bool ExportMesh::ableToOperate()
return true;
}
ExportMesh::Result ExportMesh::operateInternal()
Export::Result Export::operateInternal()
{
std::string outputfile = this->parameters()->findFile("filename")->value();
......@@ -114,9 +118,60 @@ ExportMesh::Result ExportMesh::operateInternal()
return this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
}
const char* ExportMesh::xmlDescription() const
Export::Specification Export::createSpecification()
{
return ExportMesh_xml;
Specification spec = this->smtk::operation::XMLOperation::createSpecification();
auto exportDef = spec->findDefinition("export");
std::vector<smtk::attribute::FileItemDefinition::Ptr> fileItemDefinitions;
auto fileItemDefinitionFilter = [](
smtk::attribute::FileItemDefinition::Ptr ptr) { return ptr->name() == "filename"; };
exportDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter);
assert(fileItemDefinitions.size() == 1);
std::stringstream fileFilters;
for (auto& ioType : smtk::io::ExportMesh::SupportedIOTypes())
{
bool firstFormat = true;
for (auto& format : ioType->FileFormats())
{
if (format.CanExport())
{
if (firstFormat)
{
firstFormat = false;
}
else
{
fileFilters << ";;";
}
fileFilters << format.Name << "(";
bool first = true;
for (auto& ext : format.Extensions)
{
if (first)
{
first = false;
}
else
{
fileFilters << " ";
}
fileFilters << "*" << ext;
}
fileFilters << ")";
}
}
}
fileItemDefinitions[0]->setFileFilters(fileFilters.str());
return spec;
}
const char* Export::xmlDescription() const
{
return Export_xml;
}
}
}
......@@ -7,8 +7,8 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef __smtk_mesh_WriteMesh_h
#define __smtk_mesh_WriteMesh_h
#ifndef __smtk_mesh_Export_h
#define __smtk_mesh_Export_h
#include "smtk/operation/XMLOperation.h"
......@@ -19,11 +19,11 @@ namespace mesh
/**\brief A class for writing meshes to file.
*/
class SMTKCORE_EXPORT WriteMesh : public smtk::operation::XMLOperation
class SMTKCORE_EXPORT Export : public smtk::operation::XMLOperation
{
public:
smtkTypeMacro(smtk::mesh::WriteMesh);
smtkCreateMacro(WriteMesh);
smtkTypeMacro(smtk::mesh::Export);
smtkCreateMacro(Export);
smtkSharedFromThisMacro(smtk::operation::Operation);
smtkSuperclassMacro(smtk::operation::XMLOperation);
......@@ -31,10 +31,11 @@ public:
protected:
Result operateInternal() override;
Specification createSpecification() override;
virtual const char* xmlDescription() const override;
};
} // mesh namespace
} // smtk namespace
#endif // __smtk_mesh_WriteMesh_h
#endif // __smtk_mesh_Export_h
......@@ -3,7 +3,7 @@
<Definitions>
<!-- Operation -->
<include href="smtk/operation/Operation.xml"/>
<AttDef Type="export mesh" Label="Mesh - Export" BaseType="operation">
<AttDef Type="export" Label="Mesh - Export" BaseType="operation">
<BriefDescription>
Export a mesh to disk.
</BriefDescription>
......@@ -20,13 +20,13 @@
</AssociationsDef>
<ItemDefinitions>
<File Name="filename" NumberOfRequiredValues="1" ShouldExist="false"
FileFilters="AdH 2D Mesh file (*.2dm);;AdH 3D Mesh file (*.3dm)">
FileFilters="[defined programatically]">
</File>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(export mesh)" BaseType="result">
<AttDef Type="result(export)" BaseType="result">
</AttDef>
</Definitions>
</SMTK_AttributeResource>
//=========================================================================
// 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/mesh/operators/Import.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/FileItemDefinition.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/io/ImportMesh.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/Import_xml.h"
namespace
{
class AddMeshToResult : public smtk::mesh::MeshForEach
{
public:
AddMeshToResult(smtk::mesh::Import::Result& result)
: smtk::mesh::MeshForEach()
, m_result(result)
{
}
void forMesh(smtk::mesh::MeshSet& mesh) override
{
m_result->findComponent("created")->appendValue(smtk::mesh::Component::create(mesh));
}
private:
smtk::mesh::Import::Result& m_result;
};
}
namespace smtk
{
namespace mesh
{
Import::Result Import::operateInternal()
{
// Get the import file name
smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename");
std::string filePath = filePathItem->value();
// Get the subset value
smtk::attribute::StringItem::Ptr labelItem = this->parameters()->findString("label");
std::string label = labelItem->value();
auto collection = smtk::mesh::Collection::create();
bool success = smtk::io::importMesh(filePath, collection, label);
if (success == false)
{
return this->createResult(smtk::operation::Operation::Outcome::FAILED);
}
auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
AddMeshToResult addMeshToResult(result);
smtk::mesh::for_each(collection->meshes(), addMeshToResult);
result->findResource("resource")->appendValue(collection);
return result;
}
Import::Specification Import::createSpecification()
{
Specification spec = this->smtk::operation::XMLOperation::createSpecification();
auto importDef = spec->findDefinition("import");
std::vector<smtk::attribute::FileItemDefinition::Ptr> fileItemDefinitions;
auto fileItemDefinitionFilter = [](
smtk::attribute::FileItemDefinition::Ptr ptr) { return ptr->name() == "filename"; };
importDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter);
assert(fileItemDefinitions.size() == 1);
std::stringstream fileFilters;
for (auto& ioType : smtk::io::ImportMesh::SupportedIOTypes())
{
bool firstFormat = true;
for (auto& format : ioType->FileFormats())
{
if (format.CanImport())
{
if (firstFormat)
{
firstFormat = false;
}
else
{
fileFilters << ";;";
}
fileFilters << format.Name << "(";
bool first = true;
for (auto& ext : format.Extensions)
{
if (first)
{
first = false;
}
else
{
fileFilters << " ";
}
fileFilters << "*" << ext;
}
fileFilters << ")";
}
}
}
fileItemDefinitions[0]->setFileFilters(fileFilters.str());
return spec;
}
const char* Import::xmlDescription() const
{
return Import_xml;
}
}
}
//=========================================================================
// 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_mesh_Import_h
#define __smtk_mesh_Import_h
#include "smtk/session/mesh/Exports.h"
#include "smtk/operation/XMLOperation.h"
namespace smtk
{
namespace mesh
{
/**\brief Import an smtk mesh file.
*
* Here and throughout SMTK, we use the terms read/write to describe
* serialization of native SMTK files, while the terms import/export describe
* transcription from/to a different format.
*/
class SMTKCORE_EXPORT Import : public smtk::operation::XMLOperation
{
public:
smtkTypeMacro(smtk::mesh::Import);
smtkCreateMacro(Import);
smtkSharedFromThisMacro(smtk::operation::Operation);
protected:
Result operateInternal() override;
Specification createSpecification() override;
virtual const char* xmlDescription() const override;
};
}
}
#endif
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the CMB mesh "read" Operation -->
<SMTK_AttributeResource Version="3">
<Definitions>
<include href="smtk/operation/Operation.xml"/>
<AttDef Type="import" Label="Mesh - Import Resource" BaseType="operation">
<ItemDefinitions>
<File Name="filename" Label="File Name" NumberOfRequiredValues="1"
ShouldExist="true"
FileFilters="[defined programatically]">
</File>
<String Name="label" Label="Domain Property" NumberOfRequiredValues="1" AdvanceLevel="1">
<DefaultValue></DefaultValue>
</String>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(import)" BaseType="result">
<ItemDefinitions>
<Resource Name="resource">
<Accepts>
<Resource Name="smtk::mesh::Collection"/>
</Accepts>
</Resource>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeResource>
//=========================================================================
// 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/mesh/operators/Read.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/FileItemDefinition.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/io/ReadMesh.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/Read_xml.h"
#include "smtk/common/CompilerInformation.h"
SMTK_THIRDPARTY_PRE_INCLUDE
#include "nlohmann/json.hpp"
SMTK_THIRDPARTY_POST_INCLUDE
#include <fstream>
namespace
{
class AddMeshToResult : public smtk::mesh::MeshForEach
{
public:
AddMeshToResult(smtk::mesh::Read::Result& result)
: smtk::mesh::MeshForEach()
, m_result(result)
{
}
void forMesh(smtk::mesh::MeshSet& mesh) override
{
m_result->findComponent("created")->appendValue(smtk::mesh::Component::create(mesh));
}
private:
smtk::mesh::Read::Result& m_result;
};
}
namespace smtk
{
namespace mesh
{
Read::Result Read::operateInternal()
{
// Get the read file name
smtk::attribute::FileItem::Ptr filePathItem = this->parameters()->findFile("filename");
std::string filePath = filePathItem->value();
// Get the subset value
smtk::attribute::IntItem::Ptr subsetItem = this->parameters()->findInt("subset");
smtk::io::mesh::Subset subset = static_cast<smtk::io::mesh::Subset>(subsetItem->value());
auto collection = smtk::mesh::Collection::create();
bool success = smtk::io::readMesh(filePath, collection, subset);
if (success == false)
{
return this->createResult(smtk::operation::Operation::Outcome::FAILED);
}
auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
AddMeshToResult addMeshToResult(result);
smtk::mesh::for_each(collection->meshes(), addMeshToResult);
result->findResource("resource")->appendValue(collection);
return result;
}
Read::Specification Read::createSpecification()
{
Specification spec = this->smtk::operation::XMLOperation::createSpecification();
auto importDef = spec->findDefinition("read");
std::vector<smtk::attribute::FileItemDefinition::Ptr> fileItemDefinitions;
auto fileItemDefinitionFilter = [](
smtk::attribute::FileItemDefinition::Ptr ptr) { return ptr->name() == "filename"; };
importDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter);
assert(fileItemDefinitions.size() == 1);
std::stringstream fileFilters;
for (auto& ioType : smtk::io::ReadMesh::SupportedIOTypes())
{
bool firstFormat = true;
for (auto& format : ioType->FileFormats())
{
if (format.CanImport())
{
if (firstFormat)
{
firstFormat = false;
}
else
{
fileFilters << ";;";
}
fileFilters << format.Name << "(";
bool first = true;
for (auto& ext : format.Extensions)
{
if (first)
{
first = false;
}
else
{
fileFilters << " ";
}
fileFilters << "*" << ext;
}
fileFilters << ")";
}
}
}
fileItemDefinitions[0]->setFileFilters(fileFilters.str());
return spec;
}
const char* Read::xmlDescription() const
{
return Read_xml;
}
}
}
//=========================================================================
// 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_mesh_Read_h
#define __smtk_mesh_Read_h
#include "smtk/session/mesh/Exports.h"
#include "smtk/operation/XMLOperation.h"
namespace smtk
{
namespace mesh
{
/**\brief Read an smtk mesh file.
*
* Here and throughout SMTK, we use the terms read/write to describe
* serialization of native SMTK files, while the terms import/export describe
* transcription from/to a different format.
*/
class SMTKCORE_EXPORT Read : public smtk::operation::XMLOperation
{
public:
smtkTypeMacro(smtk::mesh::Read);
smtkCreateMacro(Read);
smtkSharedFromThisMacro(smtk::operation::Operation);
protected:
Result operateInternal() override;
Specification createSpecification() override;
virtual const char* xmlDescription() const override;
};
}
}
#endif
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the CMB mesh "read" Operation -->
<SMTK_AttributeResource Version="3">
<Definitions>
<include href="smtk/operation/Operation.xml"/>
<AttDef Type="read" Label="Mesh - Read Resource" BaseType="operation">
<ItemDefinitions>
<File Name="filename" Label="File Name" NumberOfRequiredValues="1"
ShouldExist="true"
FileFilters="SMTK Files (*.smtk)">
</File>
<Int Name="subset" Label="Mesh Subset"
NumberOfRequiredValues="1" AdvanceLevel="1">
<BriefDescription>Subset of the mesh to load</BriefDescription>
<DiscreteInfo DefaultIndex="0">
<Value Enum="Entire Collection">0</Value>
<Value Enum="Only Domain">1</Value>
<Value Enum="Only Dirichlet">2</Value>
<Value Enum="Only Neumann">3</Value>
</DiscreteInfo>
</Int>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(read)" BaseType="result">
<ItemDefinitions>
<Resource Name="resource">
<Accepts>
<Resource Name="smtk::mesh::Collection"/>
</Accepts>
</Resource>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeResource>
......@@ -8,16 +8,21 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/mesh/operators/WriteMesh.h"
#include "smtk/mesh/operators/Write.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/FileItemDefinition.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ResourceItem.h"
#include "smtk/io/WriteMesh.h"
#include "smtk/io/mesh/MeshIO.h"
#include "smtk/mesh/WriteMesh_xml.h"
#include "smtk/mesh/Write_xml.h"
#include "smtk/mesh/core/Collection.h"
#include "smtk/mesh/core/Component.h"
#include "smtk/mesh/core/MeshSet.h"
......@@ -52,7 +57,7 @@ namespace smtk
namespace mesh
{
bool WriteMesh::ableToOperate()
bool Write::ableToOperate()
{
if (!this->Superclass::ableToOperate())
{
......@@ -61,7 +66,7 @@ bool WriteMesh::ableToOperate()
return true;
}
WriteMesh::Result WriteMesh::operateInternal()
Write::Result Write::operateInternal()
{
std::string outputfile = this->parameters()->findFile("filename")->value();
......@@ -117,9 +122,60 @@ WriteMesh::Result WriteMesh::operateInternal()
return result;
}
const char* WriteMesh::xmlDescription() const
Write::Specification Write::createSpecification()
{
return WriteMesh_xml;
Specification spec = this->smtk::operation::XMLOperation::createSpecification();
auto writeDef = spec->findDefinition("write");
std::vector<smtk::attribute::FileItemDefinition::Ptr> fileItemDefinitions;
auto fileItemDefinitionFilter = [](
smtk::attribute::FileItemDefinition::Ptr ptr) { return ptr->name() == "filename"; };
writeDef->filterItemDefinitions(fileItemDefinitions, fileItemDefinitionFilter);
assert(fileItemDefinitions.size() == 1);
std::stringstream fileFilters;
for (auto& ioType : smtk::io::WriteMesh::SupportedIOTypes())
{
bool firstFormat = true;