27using namespace Kernel;
29using namespace Geometry;
32 auto wsValidator = std::make_shared<InstrumentValidator>();
36 "The name of the workspace containing the environment to save ");
39 const std::vector<std::string> extensions{
".stl",
".3mf"};
41 "The path name of the file to save");
48 const MeshObject &sampleShape,
const std::vector<const Geometry::MeshObject *> &environmentPieces) {
50 if (environmentPieces.size() > 0) {
60 offset = std::accumulate(environmentPieces.begin(), environmentPieces.end(), offset,
62 return addMeshToVector(*mesh, currentOffset);
73 size_t numTriangles = 0;
74 size_t numVertices = 0;
77 const auto &sampleShape =
toMeshObject(inputWS->sample().getShape());
78 if (!sampleShape.hasValidShape()) {
79 throw std::invalid_argument(
"Sample Shape is not complete");
81 numVertices += sampleShape.numberOfVertices();
82 numTriangles += (sampleShape.numberOfTriangles() * 3);
85 std::vector<const MeshObject *> environmentPieces;
87 if (inputWS->sample().hasEnvironment()) {
89 auto environment = inputWS->sample().getEnvironment();
91 auto numElements = environment.nelements();
92 environmentPieces.reserve(numElements);
95 bool environmentValid =
true;
96 environmentPieces.emplace_back(&
toMeshObject(environment.getContainer().getShape()));
97 environmentValid = environmentValid && environmentPieces[0]->hasValidShape();
98 numVertices += environmentPieces[0]->numberOfVertices();
99 numTriangles += (environmentPieces[0]->numberOfTriangles() * 3);
102 for (
size_t i = 1; i < numElements; ++i) {
106 environmentValid = environmentValid && temp->
hasValidShape();
107 environmentPieces.emplace_back(temp);
109 if (!environmentValid) {
110 throw std::invalid_argument(
"Environment Shape is not complete");
119 std::string fileExt = std::filesystem::path(filename).extension().string().substr(1);
120 std::transform(fileExt.begin(), fileExt.end(), fileExt.begin(), toupper);
122 if (fileExt ==
"STL") {
136 throw std::runtime_error(
"3MF format not supported on this platform");
148 auto vertices = mesh.
getV3Ds();
165 auto vertices = mesh.
getV3Ds();
170 std::transform(std::begin(triangles), std::end(triangles), std::begin(triangles),
171 [&offset](
const uint32_t &val) {
return val + uint32_t(offset); });
176 return offset += vertices.size();
189 }
catch (
const std::bad_cast &) {
192 throw std::invalid_argument(
"Attempted to Save out non mesh based Sample or Environment");
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Save
to specify a file to write to, the file may or may not exist
A property class for workspaces.
Class to load and save .3mf files .3mf format is a 3D manufacturing format for storing mesh descripti...
void writeMeshObjects(std::vector< const Geometry::MeshObject * > meshObjects, MeshObject_const_sptr &sample, DataHandling::ScaleUnits scale)
void saveFile(std::string filename)
std::vector< Kernel::V3D > m_vertices
std::vector< uint32_t > m_triangle
void init() override
Virtual method - must be overridden by concrete algorithm.
void addMeshToVector(const Mantid::Geometry::MeshObject &mesh)
Function to add the triangles and vertices of a mesh object into a vector to allow combining with mul...
void mergeSampleEnvironmentIntoSingleMesh(const Mantid::Geometry::MeshObject &sample, const std::vector< const Geometry::MeshObject * > &environmentPieces)
void exec() override
Virtual method - must be overridden by concrete algorithm.
Class to contain functionality for writing out STL files for SaveShapeAndEnvironment.
void writeStl()
Function to write out the full mesh to an stl binary file.
IObject : Interface for geometry objects.
size_t numberOfTriangles() const
Output functions for rendering, may also be used internally.
bool hasValidShape() const override
Return whether this object has a valid shape.
const std::vector< Kernel::V3D > & getV3Ds() const
get vertices in V3D form
size_t numberOfVertices() const
Read access to mesh object for rendering.
const std::vector< uint32_t > & getTriangles() const
get faces
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
const Mantid::Geometry::MeshObject & toMeshObject(const Mantid::Geometry::IObject &object)
Function to convert an IObject to a mesh, and throw if this can't be done.
std::shared_ptr< const Geometry::MeshObject > MeshObject_const_sptr
Typdef for a shared pointer to a const object.
ScaleUnits getScaleTypeFromStr(const std::string &scaleProperty)
@ Input
An input workspace.