# HG changeset patch # User Sebastien Jodogne # Date 1540892833 -3600 # Node ID 8262e4e9826de26b534f0596cd6593babb24f672 # Parent 100df90bf0eaa1f9b938dbad45c9a71da2298850 export to png diff -r 100df90bf0ea -r 8262e4e9826d Applications/Samples/SingleFrameEditorApplication.h --- a/Applications/Samples/SingleFrameEditorApplication.h Tue Oct 30 08:11:06 2018 +0100 +++ b/Applications/Samples/SingleFrameEditorApplication.h Tue Oct 30 10:47:13 2018 +0100 @@ -35,6 +35,8 @@ #include #include +#include + #include @@ -2240,10 +2242,13 @@ stack_.Render(*floatBuffer_, GetView(), interpolation); - // Very similar to GrayscaleFrameRenderer => TODO MERGE? + // Conversion from Float32 to BGRA32 (cairo). Very similar to + // GrayscaleFrameRenderer => TODO MERGE? Orthanc::ImageAccessor target; cairoBuffer_->GetAccessor(target); + + float scaling = 255.0f / (x1 - x0); for (unsigned int y = 0; y < height; y++) { @@ -2264,7 +2269,7 @@ else { // https://en.wikipedia.org/wiki/Linear_interpolation - v = static_cast(255.0f * (*p - x0) / (x1 - x0)); // (*) + v = static_cast(scaling * (*p - x0)); // (*) } if (invert_) @@ -2598,11 +2603,11 @@ break; case 'e': - Export(); + Export(GetStack(widget), 0.1, 0.1, GetWidget(widget).GetInterpolation()); break; case 'i': - dynamic_cast(widget).SwitchInvert(); + GetWidget(widget).SwitchInvert(); break; case 'm': @@ -2611,18 +2616,16 @@ case 'n': { - BitmapStackWidget& w = dynamic_cast(widget); - - switch (w.GetInterpolation()) + switch (GetWidget(widget).GetInterpolation()) { case ImageInterpolation_Nearest: LOG(INFO) << "Switching to bilinear interpolation"; - w.SetInterpolation(ImageInterpolation_Bilinear); + GetWidget(widget).SetInterpolation(ImageInterpolation_Bilinear); break; case ImageInterpolation_Bilinear: LOG(INFO) << "Switching to nearest neighbor interpolation"; - w.SetInterpolation(ImageInterpolation_Nearest); + GetWidget(widget).SetInterpolation(ImageInterpolation_Nearest); break; default: @@ -2672,15 +2675,51 @@ } - void Export() + void Export(const BitmapStack& stack, + double pixelSpacingX, + double pixelSpacingY, + ImageInterpolation interpolation) { + if (pixelSpacingX <= 0 || + pixelSpacingY <= 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + if (orthanc_ == NULL) { return; } - // TODO LOG(WARNING) << "Exporting DICOM"; + + Extent2D extent = stack.GetSceneExtent(); + + int w = std::ceil(extent.GetWidth() / pixelSpacingX); + int h = std::ceil(extent.GetHeight() / pixelSpacingY); + + if (w < 0 || h < 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + Orthanc::Image layers(Orthanc::PixelFormat_Float32, + static_cast(w), + static_cast(h), false); + + ViewportGeometry view; + view.SetDisplaySize(layers.GetWidth(), layers.GetHeight()); + view.SetSceneExtent(extent); + view.FitContent(); + + stack.Render(layers, view, interpolation); + + Orthanc::Image rendered(Orthanc::PixelFormat_Grayscale16, + layers.GetWidth(), layers.GetHeight(), false); + Orthanc::ImageProcessing::Convert(rendered, layers); + + Orthanc::PngWriter png; + png.WriteToFile("/tmp/a.png", rendered); } };