From 0b869f464982cf3631db734237696972d184ff4e Mon Sep 17 00:00:00 2001 From: Colin McFadden Date: Fri, 11 Oct 2024 17:05:54 -0500 Subject: [PATCH] add 3mf support for 3d processing --- application/config/config.php | 1 + application/models/Filecontainer.php | 1 + .../models/filehandlers/Objhandler.php | 37 +++++++++++++++++-- docker/commands/3mf2stl | 2 + 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100755 docker/commands/3mf2stl diff --git a/application/config/config.php b/application/config/config.php index 143b7a5bf..d95c46fa7 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -452,6 +452,7 @@ $config['convert'] = '/usr/local/bin/convert'; $config['cziutils'] = '/usr/local/bin/cziutils'; $config['tarrific'] = '/usr/local/bin/tarrific'; +$config['3mf2stl'] = '/usr/local/bin/3mf2stl'; // LDAP username and password. // Application should bind anonymously if not set, or set to blanks. diff --git a/application/models/Filecontainer.php b/application/models/Filecontainer.php index e26164de4..fa4e7cf68 100644 --- a/application/models/Filecontainer.php +++ b/application/models/Filecontainer.php @@ -42,6 +42,7 @@ public function makeLocal() { return FILE_LOCAL; } + } /* End of file filecontainer.php */ diff --git a/application/models/filehandlers/Objhandler.php b/application/models/filehandlers/Objhandler.php index 5e0e624fa..46163d8aa 100755 --- a/application/models/filehandlers/Objhandler.php +++ b/application/models/filehandlers/Objhandler.php @@ -1,7 +1,7 @@ swapLocal3MFForSTL($this->sourceFile); + $foundMTL = false; - $localPath = $this->sourceFile->getPathToLocalFile(); + $localPath = $sourceFile->getPathToLocalFile(); $pathparts = pathinfo($localPath); - $originalExtension = pathinfo($this->sourceFile->originalFilename, PATHINFO_EXTENSION); + $originalExtension = pathinfo($sourceFile->originalFilename, PATHINFO_EXTENSION); $objFile = $localPath . "." .$originalExtension; @@ -465,6 +467,35 @@ public function createNxsFileInternal($sourceFileContainer, $args) { } + + function swapLocal3MFForSTL($sourceFile= null) { + if(!$sourceFile) { + $sourceFile = $this->sourceFile; + } + // this is ugly, but we might get passed in an intermediate. We need to look at the original to see if + // it was a whole slide + if($sourceFile->getType() != "3mf") { + return; + } + + $source = $sourceFile->getPathToLocalFile(); + // use the original filename as well to keep extensions sane + $dest = $this->sourceFile->getPathToLocalFile() . ".stl"; + if(file_exists($dest)) { + return new FileContainer($dest); + } + $convertString = $this->config->item('3mf2stl') . " -i " . $source . " -o " . $dest; + $process = new Cocur\BackgroundProcess\BackgroundProcess($convertString); + $process->run(); + while($process->isRunning()) { + sleep(5); + $this->pheanstalk->touch($this->job); + echo "."; + } + return new FileContainer($dest); + + } + } /* End of file */ diff --git a/docker/commands/3mf2stl b/docker/commands/3mf2stl new file mode 100755 index 000000000..477714a55 --- /dev/null +++ b/docker/commands/3mf2stl @@ -0,0 +1,2 @@ +#!/bin/bash +docker run --quiet --memory=8g --rm -i -v /scratch:/scratch ghcr.io/umn-elevator/3mf2stl:latest "$@"