Mercurial > hg > orthanc-stone
diff Framework/Layers/FrameRenderer.cpp @ 97:d18dcc963930 wasm
separation of the renderers vs. viewport slice
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 May 2017 14:09:11 +0200 |
parents | 7b14c12a3be5 |
children | 53025eecbc95 |
line wrap: on
line diff
--- a/Framework/Layers/FrameRenderer.cpp Tue May 30 10:30:57 2017 +0200 +++ b/Framework/Layers/FrameRenderer.cpp Tue May 30 14:09:11 2017 +0200 @@ -28,54 +28,6 @@ namespace OrthancStone { - static bool ComputePixelTransform(cairo_matrix_t& target, - const SliceGeometry& viewportSlice, - const SliceGeometry& frameSlice, - double pixelSpacingX, - double pixelSpacingY) - { - bool isOpposite; - if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, - viewportSlice.GetNormal(), - frameSlice.GetNormal())) - { - return false; - } - else - { - double x0, y0, x1, y1, x2, y2; - viewportSlice.ProjectPoint(x0, y0, frameSlice.GetOrigin() - - 0.5 * pixelSpacingX * frameSlice.GetAxisX() - - 0.5 * pixelSpacingY * frameSlice.GetAxisY()); - viewportSlice.ProjectPoint(x1, y1, frameSlice.GetOrigin() - + 0.5 * pixelSpacingX * frameSlice.GetAxisX() - - 0.5 * pixelSpacingY * frameSlice.GetAxisY()); - viewportSlice.ProjectPoint(x2, y2, frameSlice.GetOrigin() - - 0.5 * pixelSpacingX * frameSlice.GetAxisX() - + 0.5 * pixelSpacingY * frameSlice.GetAxisY()); - - /** - * Now we solve the system of linear equations Ax + b = x', given: - * A [0 ; 0] + b = [x0 ; y0] - * A [1 ; 0] + b = [x1 ; y1] - * A [0 ; 1] + b = [x2 ; y2] - * <=> - * b = [x0 ; y0] - * A [1 ; 0] = [x1 ; y1] - b = [x1 - x0 ; y1 - y0] - * A [0 ; 1] = [x2 ; y2] - b = [x2 - x0 ; y2 - y0] - * <=> - * b = [x0 ; y0] - * [a11 ; a21] = [x1 - x0 ; y1 - y0] - * [a12 ; a22] = [x2 - x0 ; y2 - y0] - **/ - - cairo_matrix_init(&target, x1 - x0, y1 - y0, x2 - x0, y2 - y0, x0, y0); - - return true; - } - } - - FrameRenderer::FrameRenderer(const SliceGeometry& frameSlice, double pixelSpacingX, double pixelSpacingY, @@ -88,56 +40,8 @@ } - bool FrameRenderer::ComputeFrameExtent(double& x1, - double& y1, - double& x2, - double& y2, - const SliceGeometry& viewportSlice, - const SliceGeometry& frameSlice, - unsigned int frameWidth, - unsigned int frameHeight, - double pixelSpacingX, - double pixelSpacingY) - { - bool isOpposite; - if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, viewportSlice.GetNormal(), frameSlice.GetNormal())) - { - return false; - } - else - { - cairo_matrix_t transform; - if (!ComputePixelTransform(transform, viewportSlice, frameSlice, pixelSpacingX, pixelSpacingY)) - { - return true; - } - - x1 = 0; - y1 = 0; - cairo_matrix_transform_point(&transform, &x1, &y1); - - x2 = frameWidth; - y2 = frameHeight; - cairo_matrix_transform_point(&transform, &x2, &y2); - - if (x1 > x2) - { - std::swap(x1, x2); - } - - if (y1 > y2) - { - std::swap(y1, y2); - } - - return true; - } - } - - bool FrameRenderer::RenderLayer(CairoContext& context, - const ViewportGeometry& view, - const SliceGeometry& viewportSlice) + const ViewportGeometry& view) { if (!style_.visible_) { @@ -146,12 +50,6 @@ if (display_.get() == NULL) { - if (!ComputePixelTransform(transform_, viewportSlice, frameSlice_, - pixelSpacingX_, pixelSpacingY_)) - { - return true; - } - display_.reset(GenerateDisplay(style_)); } @@ -161,7 +59,12 @@ cairo_save(cr); - cairo_transform(cr, &transform_); + cairo_matrix_t transform; + cairo_matrix_init_identity(&transform); + cairo_matrix_scale(&transform, pixelSpacingX_, pixelSpacingY_); + cairo_matrix_translate(&transform, -0.5, -0.5); + cairo_transform(cr, &transform); + //cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_surface(cr, display_->GetObject(), 0, 0); @@ -215,30 +118,6 @@ ILayerRenderer* FrameRenderer::CreateRenderer(Orthanc::ImageAccessor* frame, - const SliceGeometry& frameSlice, - const OrthancPlugins::IDicomDataset& dicom, - double pixelSpacingX, - double pixelSpacingY, - bool isFullQuality) - { - std::auto_ptr<Orthanc::ImageAccessor> protect(frame); - - if (frame->GetFormat() == Orthanc::PixelFormat_RGB24) - { - return new ColorFrameRenderer(protect.release(), frameSlice, - pixelSpacingX, pixelSpacingY, isFullQuality); - } - else - { - DicomFrameConverter converter; - converter.ReadParameters(dicom); - return new GrayscaleFrameRenderer(protect.release(), converter, frameSlice, - pixelSpacingX, pixelSpacingY, isFullQuality); - } - } - - - ILayerRenderer* FrameRenderer::CreateRenderer(Orthanc::ImageAccessor* frame, const Slice& frameSlice, bool isFullQuality) { @@ -246,13 +125,18 @@ if (frame->GetFormat() == Orthanc::PixelFormat_RGB24) { - return new ColorFrameRenderer(protect.release(), frameSlice.GetGeometry(), - frameSlice.GetPixelSpacingX(), frameSlice.GetPixelSpacingY(), isFullQuality); + return new ColorFrameRenderer(protect.release(), + frameSlice.GetGeometry(), + frameSlice.GetPixelSpacingX(), + frameSlice.GetPixelSpacingY(), isFullQuality); } else { - return new GrayscaleFrameRenderer(protect.release(), frameSlice.GetConverter(), frameSlice.GetGeometry(), - frameSlice.GetPixelSpacingX(), frameSlice.GetPixelSpacingY(), isFullQuality); + return new GrayscaleFrameRenderer(protect.release(), + frameSlice.GetConverter(), + frameSlice.GetGeometry(), + frameSlice.GetPixelSpacingX(), + frameSlice.GetPixelSpacingY(), isFullQuality); } } }