From c4c762c42e7908d2f5858fc39bfb6c74ccdab160 Mon Sep 17 00:00:00 2001 From: Krad Date: Wed, 16 Nov 2022 11:32:53 +0800 Subject: [PATCH] SmartFixedPointVolumeRayCastMapper and camera modify logic for style. --- src/src/Interaction/VolumeInteractorStyle.cpp | 9 ++ .../SmartFixedPointVolumeRayCastMapper.cpp | 119 ++++++++++++++++++ .../Core/SmartFixedPointVolumeRayCastMapper.h | 30 +++++ .../Viewer/VolumeRenderingViewer.cpp | 6 +- 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.cpp create mode 100644 src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.h diff --git a/src/src/Interaction/VolumeInteractorStyle.cpp b/src/src/Interaction/VolumeInteractorStyle.cpp index cb2b7dc..8a745e1 100644 --- a/src/src/Interaction/VolumeInteractorStyle.cpp +++ b/src/src/Interaction/VolumeInteractorStyle.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -160,6 +161,13 @@ void VolumeInteractorStyle::OnMouseMove() { MeasurePlace(); // this->InvokeEvent(vtkCommand::InteractionEvent, nullptr); break; + case VTKIS_ROTATE: + case VTKIS_PAN: + case VTKIS_SPIN: + case VTKIS_DOLLY: + this->CurrentRenderer->GetActiveCamera()->Modified(); + break; + // no state pick default:{ if (measureStore.size()){ @@ -255,6 +263,7 @@ void VolumeInteractorStyle::WindowLevel() { opacity->RemoveAllPoints(); opacity->AddPoint(newMin,0.0); opacity->AddPoint(newMax,1.0); + VolumeProperty->Modified(); this->Interactor->Render(); } } diff --git a/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.cpp b/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.cpp new file mode 100644 index 0000000..fbc1c0b --- /dev/null +++ b/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.cpp @@ -0,0 +1,119 @@ +// +// Created by Krad on 2022/11/11. +// + +#include "SmartFixedPointVolumeRayCastMapper.h" +#include +#include +#include +#include +#include +#include +#include + +vtkStandardNewMacro(SmartFixedPointVolumeRayCastMapper) + +SmartFixedPointVolumeRayCastMapper::SmartFixedPointVolumeRayCastMapper() +:vtkFixedPointVolumeRayCastMapper() { + +} + +SmartFixedPointVolumeRayCastMapper::~SmartFixedPointVolumeRayCastMapper() { + +} + +void SmartFixedPointVolumeRayCastMapper::Render(vtkRenderer *ren, vtkVolume *vol) { + if(this->GetBlendMode()!=vtkVolumeMapper::COMPOSITE_BLEND && + this->GetBlendMode()!=vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND && + this->GetBlendMode()!=vtkVolumeMapper::MINIMUM_INTENSITY_BLEND && + this->GetBlendMode()!=vtkVolumeMapper::ADDITIVE_BLEND) + { + vtkErrorMacro(<< "Selected blend mode not supported. " + << "Only Composite, MIP, MinIP and additive modes " + << "are supported by the fixed point implementation."); + return; + } + + this->Timer->StartTimer(); + char buff[1024]={0}; + sprintf(buff,"W%lld-C%lld-V%lld-P%lld",ren->GetRenderWindow()->GetMTime(), + ren->GetActiveCamera()->GetMTime(), vol->GetMTime(), vol->GetProperty()->GetMTime()); + std::string stamp(buff); + if (stamp == ModifiedStamp){ + this->DisplayRenderedImage( ren, vol ); + + this->Timer->StopTimer(); + this->TimeToDraw = this->Timer->GetElapsedTime(); + // If we've increased the sample distance, account for that in the stored time. Since we + // don't get linear performance improvement, use a factor of .66 + this->StoreRenderTime( ren, vol, + this->TimeToDraw * + this->ImageSampleDistance * + this->ImageSampleDistance * + ( 1.0 + 0.66* + (this->SampleDistance - this->OldSampleDistance) / + this->OldSampleDistance ) ); + + this->SampleDistance = this->OldSampleDistance; + return; + } + else{ + ModifiedStamp = stamp; + } + + // Since we are passing in a value of 0 for the multiRender flag + // (this is a single render pass - not part of a multipass AMR render) + // then we know the origin, spacing, and extent values will not + // be used so just initialize everything to 0. No need to check + // the return value of the PerImageInitialization method - since this + // is not a multirender it will always return 1. + double dummyOrigin[3] = {0.0, 0.0, 0.0}; + double dummySpacing[3] = {0.0, 0.0, 0.0}; + int dummyExtent[6] = {0, 0, 0, 0, 0, 0}; + this->PerImageInitialization( ren, vol, 0, + dummyOrigin, + dummySpacing, + dummyExtent ); + + this->PerVolumeInitialization( ren, vol ); + + vtkRenderWindow *renWin=ren->GetRenderWindow(); + + if ( renWin && renWin->CheckAbortStatus() ) + { + this->AbortRender(); + return; + } + + this->PerSubVolumeInitialization( ren, vol, 0 ); + if ( renWin && renWin->CheckAbortStatus() ) + { + this->AbortRender(); + return; + } + + this->RenderSubVolume(); + + if ( renWin && renWin->CheckAbortStatus() ) + { + this->AbortRender(); + return; + } + + this->DisplayRenderedImage( ren, vol ); + + this->Timer->StopTimer(); + this->TimeToDraw = this->Timer->GetElapsedTime(); + // If we've increased the sample distance, account for that in the stored time. Since we + // don't get linear performance improvement, use a factor of .66 + this->StoreRenderTime( ren, vol, + this->TimeToDraw * + this->ImageSampleDistance * + this->ImageSampleDistance * + ( 1.0 + 0.66* + (this->SampleDistance - this->OldSampleDistance) / + this->OldSampleDistance ) ); + + this->SampleDistance = this->OldSampleDistance; +}; + diff --git a/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.h b/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.h new file mode 100644 index 0000000..292c4b8 --- /dev/null +++ b/src/src/Rendering/Core/SmartFixedPointVolumeRayCastMapper.h @@ -0,0 +1,30 @@ +// +// Created by Krad on 2022/11/11. +// + +#ifndef OMEGAV_SMARTFIXEDPOINTVOLUMERAYCASTMAPPER_H +#define OMEGAV_SMARTFIXEDPOINTVOLUMERAYCASTMAPPER_H + +#include + +#include + +class SmartFixedPointVolumeRayCastMapper : public vtkFixedPointVolumeRayCastMapper { +public: + static SmartFixedPointVolumeRayCastMapper *New(); + vtkTypeMacro(SmartFixedPointVolumeRayCastMapper,vtkFixedPointVolumeRayCastMapper); + + void Render(vtkRenderer *renderer, vtkVolume *volume) override; + +protected: + SmartFixedPointVolumeRayCastMapper(); + ~SmartFixedPointVolumeRayCastMapper() override; +private: + SmartFixedPointVolumeRayCastMapper(const SmartFixedPointVolumeRayCastMapper&) = delete; + void operator=(const SmartFixedPointVolumeRayCastMapper&) = delete; + + std::string ModifiedStamp; +}; + + +#endif //OMEGAV_SMARTFIXEDPOINTVOLUMERAYCASTMAPPER_H diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp index 499444f..47ac95c 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp @@ -25,6 +25,7 @@ #include "Interaction/VolumeInteractorStyle.h" #include "Rendering/Widget/ClickableOrientationMarkerWidget.h" +#include "Rendering/Core/SmartFixedPointVolumeRayCastMapper.h" #include "IO/DICOM/ExtendMedicalImageProperties.h" #include "Rendering/Measure/ArrowAnnotationActor.h" @@ -77,7 +78,7 @@ VolumeRenderingViewer::VolumeRenderingViewer() , Renderer(nullptr) , VolumeActor(vtkVolume::New()) , annotation(vtkCornerAnnotation::New()) -, VolumeMapper(vtkFixedPointVolumeRayCastMapper::New()) +, VolumeMapper(SmartFixedPointVolumeRayCastMapper::New()) , InteractorStyle(nullptr) , Interactor(nullptr) , firstRender(true) @@ -269,6 +270,9 @@ void VolumeRenderingViewer::SetRenderWindow(vtkRenderWindow *arg) { if (this->RenderWindow) { this->RenderWindow->Register(this); + this->RenderWindow->PointSmoothingOn(); + this->RenderWindow->LineSmoothingOn(); + this->RenderWindow->PolygonSmoothingOn(); } //add legend to render this->InstallPipeline();