SmartFixedPointVolumeRayCastMapper and camera modify logic for style.

This commit is contained in:
Krad
2022-11-16 11:32:53 +08:00
parent 6d70e5d309
commit c4c762c42e
4 changed files with 163 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
#include <vtkCallbackCommand.h> #include <vtkCallbackCommand.h>
#include <vtkRenderWindow.h> #include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkVolume.h> #include <vtkVolume.h>
#include <vtkPropCollection.h> #include <vtkPropCollection.h>
#include <vtkAssemblyPath.h> #include <vtkAssemblyPath.h>
@@ -160,6 +161,13 @@ void VolumeInteractorStyle::OnMouseMove() {
MeasurePlace(); MeasurePlace();
// this->InvokeEvent(vtkCommand::InteractionEvent, nullptr); // this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break; break;
case VTKIS_ROTATE:
case VTKIS_PAN:
case VTKIS_SPIN:
case VTKIS_DOLLY:
this->CurrentRenderer->GetActiveCamera()->Modified();
break;
// no state pick // no state pick
default:{ default:{
if (measureStore.size()){ if (measureStore.size()){
@@ -255,6 +263,7 @@ void VolumeInteractorStyle::WindowLevel() {
opacity->RemoveAllPoints(); opacity->RemoveAllPoints();
opacity->AddPoint(newMin,0.0); opacity->AddPoint(newMin,0.0);
opacity->AddPoint(newMax,1.0); opacity->AddPoint(newMax,1.0);
VolumeProperty->Modified();
this->Interactor->Render(); this->Interactor->Render();
} }
} }

View File

@@ -0,0 +1,119 @@
//
// Created by Krad on 2022/11/11.
//
#include "SmartFixedPointVolumeRayCastMapper.h"
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkCamera.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>
#include <vtkTimerLog.h>
#include <vtkRenderWindow.h>
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;
};

View File

@@ -0,0 +1,30 @@
//
// Created by Krad on 2022/11/11.
//
#ifndef OMEGAV_SMARTFIXEDPOINTVOLUMERAYCASTMAPPER_H
#define OMEGAV_SMARTFIXEDPOINTVOLUMERAYCASTMAPPER_H
#include <vtkFixedPointVolumeRayCastMapper.h>
#include <string>
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

View File

@@ -25,6 +25,7 @@
#include "Interaction/VolumeInteractorStyle.h" #include "Interaction/VolumeInteractorStyle.h"
#include "Rendering/Widget/ClickableOrientationMarkerWidget.h" #include "Rendering/Widget/ClickableOrientationMarkerWidget.h"
#include "Rendering/Core/SmartFixedPointVolumeRayCastMapper.h"
#include "IO/DICOM/ExtendMedicalImageProperties.h" #include "IO/DICOM/ExtendMedicalImageProperties.h"
#include "Rendering/Measure/ArrowAnnotationActor.h" #include "Rendering/Measure/ArrowAnnotationActor.h"
@@ -77,7 +78,7 @@ VolumeRenderingViewer::VolumeRenderingViewer()
, Renderer(nullptr) , Renderer(nullptr)
, VolumeActor(vtkVolume::New()) , VolumeActor(vtkVolume::New())
, annotation(vtkCornerAnnotation::New()) , annotation(vtkCornerAnnotation::New())
, VolumeMapper(vtkFixedPointVolumeRayCastMapper::New()) , VolumeMapper(SmartFixedPointVolumeRayCastMapper::New())
, InteractorStyle(nullptr) , InteractorStyle(nullptr)
, Interactor(nullptr) , Interactor(nullptr)
, firstRender(true) , firstRender(true)
@@ -269,6 +270,9 @@ void VolumeRenderingViewer::SetRenderWindow(vtkRenderWindow *arg) {
if (this->RenderWindow) { if (this->RenderWindow) {
this->RenderWindow->Register(this); this->RenderWindow->Register(this);
this->RenderWindow->PointSmoothingOn();
this->RenderWindow->LineSmoothingOn();
this->RenderWindow->PolygonSmoothingOn();
} }
//add legend to render //add legend to render
this->InstallPipeline(); this->InstallPipeline();