Corner annotation render logic.

This commit is contained in:
Krad
2022-11-25 10:48:58 +08:00
parent bac9e425eb
commit 1ca3c95cae
4 changed files with 76 additions and 13 deletions

View File

@@ -168,8 +168,8 @@ void VolumeInteractorStyle::OnMouseMove() {
// this->InvokeEvent(vtkCommand::InteractionEvent, nullptr); // this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
break; break;
case VTKIS_ROTATE: case VTKIS_ROTATE:
case VTKIS_PAN:
case VTKIS_SPIN: case VTKIS_SPIN:
case VTKIS_PAN:
case VTKIS_DOLLY: case VTKIS_DOLLY:
this->CurrentRenderer->GetActiveCamera()->Modified(); this->CurrentRenderer->GetActiveCamera()->Modified();
break; break;
@@ -200,7 +200,6 @@ void VolumeInteractorStyle::OnMouseMove() {
} }
} }
vtkInteractorStyleTrackballCamera::OnMouseMove(); vtkInteractorStyleTrackballCamera::OnMouseMove();
} }
void VolumeInteractorStyle::WindowLevel() { void VolumeInteractorStyle::WindowLevel() {
@@ -209,12 +208,7 @@ void VolumeInteractorStyle::WindowLevel() {
this->WindowLevelCurrentPosition[0] = rwi->GetEventPosition()[0]; this->WindowLevelCurrentPosition[0] = rwi->GetEventPosition()[0];
this->WindowLevelCurrentPosition[1] = rwi->GetEventPosition()[1]; this->WindowLevelCurrentPosition[1] = rwi->GetEventPosition()[1];
if (this->HandleObservers && if(VolumeProperty){
this->HasObserver(vtkCommand::WindowLevelEvent))
{
this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
}
else if(VolumeProperty){
auto opacity = VolumeProperty->GetScalarOpacity(); auto opacity = VolumeProperty->GetScalarOpacity();
if (opacity) { if (opacity) {
double range[2] = {0.0, 0.0}; double range[2] = {0.0, 0.0};
@@ -270,6 +264,7 @@ void VolumeInteractorStyle::WindowLevel() {
opacity->AddPoint(newMin,0.0); opacity->AddPoint(newMin,0.0);
opacity->AddPoint(newMax,1.0); opacity->AddPoint(newMax,1.0);
VolumeProperty->Modified(); VolumeProperty->Modified();
this->InvokeEvent(vtkCommand::WindowLevelEvent, this);
this->Interactor->Render(); this->Interactor->Render();
} }
} }
@@ -376,3 +371,60 @@ void VolumeInteractorStyle::EndMeasure() {
this->InvokeEvent(EndMeasureEvent, this->measure); this->InvokeEvent(EndMeasureEvent, this->measure);
} }
void VolumeInteractorStyle::Rotate() {
if (this->CurrentRenderer == nullptr) {
return;
}
vtkRenderWindowInteractor *rwi = this->Interactor;
int dx = rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0];
int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
const int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
double delta_elevation = -20.0 / size[1];
double delta_azimuth = -20.0 / size[0];
double rxf = dx * delta_azimuth * this->MotionFactor;
double ryf = dy * delta_elevation * this->MotionFactor;
vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
camera->Azimuth(rxf);
camera->Elevation(ryf);
camera->OrthogonalizeViewUp();
if (this->AutoAdjustCameraClippingRange) {
this->CurrentRenderer->ResetCameraClippingRange();
}
if (rwi->GetLightFollowCamera()) {
this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
}
this->InvokeEvent(vtkCommand::RotateEvent);
rwi->Render();
}
void VolumeInteractorStyle::Spin() {
if (this->CurrentRenderer == nullptr)
{
return;
}
vtkRenderWindowInteractor* rwi = this->Interactor;
double* center = this->CurrentRenderer->GetCenter();
double newAngle = vtkMath::DegreesFromRadians(
atan2(rwi->GetEventPosition()[1] - center[1], rwi->GetEventPosition()[0] - center[0]));
double oldAngle = vtkMath::DegreesFromRadians(
atan2(rwi->GetLastEventPosition()[1] - center[1], rwi->GetLastEventPosition()[0] - center[0]));
vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
camera->Roll(newAngle - oldAngle);
camera->OrthogonalizeViewUp();
this->InvokeEvent(vtkCommand::RotateEvent);
rwi->Render();
}

View File

@@ -66,6 +66,10 @@ protected:
void EndMeasure(); void EndMeasure();
void MeasurePlace(); void MeasurePlace();
void Rotate() override;
void Spin() override;
private: private:
VolumeInteractorStyle(const VolumeInteractorStyle &) = delete; VolumeInteractorStyle(const VolumeInteractorStyle &) = delete;

View File

@@ -193,6 +193,8 @@ void VolumeRenderingViewer::InstallPipeline() {
&VolumeRenderingViewer::DecreaseMaximumImageSampleDistance); &VolumeRenderingViewer::DecreaseMaximumImageSampleDistance);
this->InteractorStyle->AddObserver(vtkCommand::EndWindowLevelEvent,this, this->InteractorStyle->AddObserver(vtkCommand::EndWindowLevelEvent,this,
&VolumeRenderingViewer::ResetMaximumImageSampleDistance); &VolumeRenderingViewer::ResetMaximumImageSampleDistance);
InteractorStyle->AddObserver(vtkCommand::RotateEvent,this, &VolumeRenderingViewer::renderOrientationAnnotation);
InteractorStyle->AddObserver(vtkCommand::WindowLevelEvent,this, &VolumeRenderingViewer::renderWindowAnnotation);
} }
this->Interactor->SetInteractorStyle(this->InteractorStyle); this->Interactor->SetInteractorStyle(this->InteractorStyle);
@@ -202,7 +204,7 @@ void VolumeRenderingViewer::InstallPipeline() {
if (this->Renderer && this->VolumeActor) { if (this->Renderer && this->VolumeActor) {
this->Renderer->AddVolume(this->VolumeActor); this->Renderer->AddVolume(this->VolumeActor);
this->Renderer->AddViewProp(annotation); this->Renderer->AddViewProp(annotation);
// Renderer->AddObserver(vtkCommand::EndEvent,this, &VolumeRenderingViewer::renderAnnotation);
this->Renderer->SetBackground(0.0, 0.0, 0.0); this->Renderer->SetBackground(0.0, 0.0, 0.0);
} }
} }
@@ -330,17 +332,20 @@ vtkImageData *VolumeRenderingViewer::GetInput() {
} }
void VolumeRenderingViewer::renderAnnotation() { void VolumeRenderingViewer::renderAnnotation() {
renderWindowAnnotation();
renderOrientationAnnotation();
}
// set FPS void VolumeRenderingViewer::renderWindowAnnotation() {
double timeInSeconds = Renderer->GetLastRenderTimeInSeconds();
double fps = 1.0 / timeInSeconds;
char buff[200]={0}; char buff[200]={0};
double *range = VolumeActor->GetProperty()->GetScalarOpacity()->GetRange(); double *range = VolumeActor->GetProperty()->GetScalarOpacity()->GetRange();
double wl = (range[0]+range[1])/2.0; double wl = (range[0]+range[1])/2.0;
double ww = (range[1] - range[0]); double ww = (range[1] - range[0]);
sprintf(buff,"FPS:%3.0f\r\nWW:%.0f WL:%.0f", fps,ww,wl); sprintf(buff,"WW:%.0f WL:%.0f", ww,wl);
annotation->SetText(0,buff ); annotation->SetText(0,buff );
}
void VolumeRenderingViewer::renderOrientationAnnotation() {
auto camera = Renderer->GetActiveCamera(); auto camera = Renderer->GetActiveCamera();
double dop[4] = {.0, .0, .0, 1.}; double dop[4] = {.0, .0, .0, 1.};
camera->GetDirectionOfProjection(dop); camera->GetDirectionOfProjection(dop);

View File

@@ -105,6 +105,8 @@ protected:
virtual void UnInstallPipeline(); virtual void UnInstallPipeline();
void renderAnnotation(); void renderAnnotation();
void renderWindowAnnotation();
void renderOrientationAnnotation();
private: private:
VolumeRenderingViewer(const VolumeRenderingViewer &) = delete; VolumeRenderingViewer(const VolumeRenderingViewer &) = delete;
void operator=(const VolumeRenderingViewer &) = delete; void operator=(const VolumeRenderingViewer &) = delete;