# HG changeset patch # User Sebastien Jodogne # Date 1712244483 -7200 # Node ID 3570c23764d415062432bdb365e9ec3c39b87883 # Parent 62abf3c523f95712e3181bfe3763abd4a1455194 set stl origin diff -r 62abf3c523f9 -r 3570c23764d4 Sources/Plugin.cpp --- a/Sources/Plugin.cpp Thu Apr 04 16:29:01 2024 +0200 +++ b/Sources/Plugin.cpp Thu Apr 04 17:28:03 2024 +0200 @@ -1301,12 +1301,12 @@ double x1, x2, x3, y1, y2, y3; if (items.size() == 6 && - MyParseDouble(y1, items[0]) && - MyParseDouble(y2, items[1]) && - MyParseDouble(y3, items[2]) && - MyParseDouble(x1, items[3]) && - MyParseDouble(x2, items[4]) && - MyParseDouble(x3, items[5])) + MyParseDouble(x1, items[0]) && + MyParseDouble(x2, items[1]) && + MyParseDouble(x3, items[2]) && + MyParseDouble(y1, items[3]) && + MyParseDouble(y2, items[4]) && + MyParseDouble(y3, items[5])) { axisX = Vector3D(x1, x2, x3); axisY = Vector3D(y1, y2, y3); @@ -1369,6 +1369,12 @@ assert(sizeof(unsigned char) == 1); memset(volume->GetScalarPointer(), 0, resolution * resolution * depth); + const double pixelSpacingX = extent.GetWidth() / static_cast(resolution); + const double pixelSpacingY = extent.GetHeight() / static_cast(resolution); + const double pixelSpacingZ = geometry.GetSlicesSpacing(); + + bool first = true; + for (size_t i = 0; i < structureSet.GetPolygonsCount(); i++) { const StructurePolygon& polygon = structureSet.GetPolygon(i); @@ -1389,6 +1395,14 @@ double y = (Vector3D::DotProduct(point, axisY) - extent.GetMinY()) / extent.GetHeight() * static_cast(resolution); points.push_back(Orthanc::ImageProcessing::ImagePoint(static_cast(std::floor(x)), static_cast(std::floor(y)))); + + if (first) + { + first = false; + volume->SetOrigin(point.GetX() - x * pixelSpacingX, + point.GetY() - y * pixelSpacingY, + point.GetZ() - z * pixelSpacingZ); + } } Orthanc::ImageAccessor slice; @@ -1401,12 +1415,7 @@ } } - volume->SetSpacing(extent.GetWidth() / static_cast(resolution), - extent.GetHeight() / static_cast(resolution), - geometry.GetSlicesSpacing()); - - // TODO - // volume->SetOrigin() + volume->SetSpacing(pixelSpacingX, pixelSpacingY, pixelSpacingZ); return EncodeVolume(stl, volume.Get(), resolution, smooth); }