Skip to content

Commit

Permalink
add 3mf support for 3d processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McFadden committed Oct 11, 2024
1 parent 2e908e2 commit 0b869f4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions application/models/Filecontainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function makeLocal() {
return FILE_LOCAL;
}


}

/* End of file filecontainer.php */
Expand Down
37 changes: 34 additions & 3 deletions application/models/filehandlers/Objhandler.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ObjHandler extends FileHandlerBase {
protected $supportedTypes = array("obj", "stl");
protected $supportedTypes = array("obj", "stl", "3mf");
protected $noDerivatives = false;


Expand Down Expand Up @@ -123,11 +123,13 @@ public function createDerivative($args) {
return JOB_FAILED;
}

$sourceFile = $this->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;

Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions docker/commands/3mf2stl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker run --quiet --memory=8g --rm -i -v /scratch:/scratch ghcr.io/umn-elevator/3mf2stl:latest "$@"

0 comments on commit 0b869f4

Please sign in to comment.