Refactor infinitiViewer.

This commit is contained in:
Krad
2022-07-01 15:38:58 +08:00
parent 62700bea0a
commit cad3c89fb8
4 changed files with 1460 additions and 1595 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -14,273 +14,324 @@
#include "Common/QGlobals.h"
class vtkAlgorithm;
class vtkAlgorithmOutput;
class vtkImageStack;
class vtkImageSlice;
class vtkLookupTable;
class vtkScalarsToColors;
class vtkImageSliceMapper;
class vtkImageData;
class vtkInformation;
class ActorDraggableInteractorStyle;
class vtkRenderWindow;
class vtkRenderer;
class vtkRenderWindowInteractor;
class ExtendMedicalImageProperties;
class MeasureStore;
#define IN_TEST_MODE
#ifdef IN_TEST_MODE
class vtkScalarBarActor;
#endif
class vtkCornerAnnotation;
class Measure;
class infinitiViewer : public vtkObject
{
class infinitiViewer : public vtkObject {
public:
static infinitiViewer* New();
vtkTypeMacro(infinitiViewer, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent) override;
static infinitiViewer *New();
//vtkGetMacro(m_cornerAnnotation, vtkCornerAnnotation);
vtkCornerAnnotation* GetvtkCornerAnnotation()
{
return cornerAnnotation;
}
void updateCornerInfo(int index);
void updateCornerInfoAll();
void initCornerInfo(ExtendMedicalImageProperties *pSeriesTags);
void updateOrienInfo();
void setUpImageViewer();
vtkTypeMacro(infinitiViewer, vtkObject);
//For Export
void initTopLeftCornerInfo(const std::string &lbl_ser_num, const std::string &SeriesNumber);
/**
* Get the name of rendering window.
*/
virtual const char* GetWindowName();
void PrintSelf(ostream &os, vtkIndent indent) override;
/**
* Render the resulting image.
*/
virtual void Render();
//vtkGetMacro(m_cornerAnnotation, vtkCornerAnnotation);
vtkCornerAnnotation *GetvtkCornerAnnotation() {
return cornerAnnotation;
}
//@{
/**
* Set/Get the input image to the viewer.
*/
virtual void SetInputData(vtkImageData* in);
virtual vtkImageData* GetInput();
virtual void SetInputConnection(vtkAlgorithmOutput* input);
void UpdateCornerInfo(int index);
//@}
void UpdateCornerInfoAll();
/**
* Set/get the slice orientation
*/
void InitCornerInfo(ExtendMedicalImageProperties *pSeries);
enum
{
SLICE_ORIENTATION_YZ = 0,
SLICE_ORIENTATION_XZ = 1,
SLICE_ORIENTATION_XY = 2
};
void UpdateOrientationInfo();
vtkGetMacro(SliceOrientation, int);
virtual void SetSliceOrientation(int orientation);
void SetupImageViewer();
virtual void SetSliceOrientationToXY()
{
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_XY);
}
//For Export
void InitTopLeftCornerInfo(const std::string &lbl_ser_num, const std::string &ser_num);
virtual void SetSliceOrientationToYZ()
{
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_YZ);
}
/**
* Get the name of rendering window.
*/
virtual const char *GetWindowName();
/**
* Render the resulting image.
*/
virtual void Render();
//@{
/**
* Set/Get the input image to the viewer.
*/
virtual void SetInputData(vtkImageData *in);
virtual vtkImageData *GetInput();
virtual void SetInputConnection(vtkAlgorithmOutput *input);
//@}
/**
* Set/get the slice orientation
*/
enum {
SLICE_ORIENTATION_YZ = 0,
SLICE_ORIENTATION_XZ = 1,
SLICE_ORIENTATION_XY = 2
};
vtkGetMacro(SliceOrientation, int);
virtual void SetSliceOrientation(int orientation);
virtual void SetSliceOrientationToXY() {
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_XY);
}
virtual void SetSliceOrientationToYZ() {
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_YZ);
}
virtual void SetSliceOrientationToXZ() {
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_XZ);
}
virtual void SetSliceOrientationToXZ()
{
this->SetSliceOrientation(infinitiViewer::SLICE_ORIENTATION_XZ);
}
int GetWorldSliceOrientation();
//@{
/**
* Set/Get the current slice to display (depending on the orientation
* this can be in X, Y or Z).
*/
virtual int GetSlice();
virtual void SetSlice(int s);
//@}
//@{
/**
* Set/Get the current slice to display (depending on the orientation
* this can be in X, Y or Z).
*/
virtual int GetSlice();
//@{
/**
* Return the minimum and maximum slice values (depending on the orientation
* this can be in X, Y or Z).
*/
virtual int GetSliceMin();
virtual int GetSliceMax();
virtual void GetSliceRange(int range[2]) { this->GetSliceRange(range[0], range[1]); }
virtual void GetSliceRange(int& min, int& max);
virtual int* GetSliceRange();
//@}
virtual void SetSlice(int s);
//@}
void ChangeSlice(vtkObject*,unsigned long eventid,void* calldata);
vtkSmartPointer<vtkPoints> GetSliceBoundPoints();
//@{
/**
* Return the minimum and maximum slice values (depending on the orientation
* this can be in X, Y or Z).
*/
virtual int GetSliceMin();
//@{
/**
* Set window and level for mapping pixels to colors.
*/
virtual double GetColorWindow();
virtual double GetColorLevel();
virtual void SetColorWindow(double s);
virtual void SetColorLevel(double s);
void SetNegativeMode(bool negative);
void SetLookupTable(vtkLookupTable *lut);
//@}
virtual int GetSliceMax();
//@{
/**
* These are here when using a Tk window.
*/
virtual void SetDisplayId(void* a);
virtual void SetWindowId(void* a);
virtual void SetParentId(void* a);
//@}
virtual void GetSliceRange(int range[2]) { this->GetSliceRange(range[0], range[1]); }
void SetZoomScale(double scale);
void SetPanOffset(const double* point);
void ResetZoomScaleToFitWindowSize();
//@{
/**
* Get the position (x and y) of the rendering window in
* screen coordinates (in pixels).
*/
virtual int* GetPosition() VTK_SIZEHINT(2);
virtual void GetSliceRange(int &min, int &max);
/**
* Set the position (x and y) of the rendering window in
* screen coordinates (in pixels). This resizes the operating
* system's view/window and redraws it.
*/
virtual void SetPosition(int x, int y);
virtual void SetPosition(int a[2]) { this->SetPosition(a[0], a[1]); }
//@}
virtual int *GetSliceRange();
//@}
//@{
/**
* Get the size (width and height) of the rendering window in
* screen coordinates (in pixels).
*/
virtual int* GetSize() VTK_SIZEHINT(2);
void ChangeSlice(vtkObject *, unsigned long eventid, void *calldata);
/**
* Set the size (width and height) of the rendering window in
* screen coordinates (in pixels). This resizes the operating
* system's view/window and redraws it.
*
* If the size has changed, this method will fire
* vtkCommand::WindowResizeEvent.
*/
virtual void SetSize(int width, int height);
virtual void SetSize(int a[2]) { this->SetSize(a[0], a[1]); }
//@}
vtkSmartPointer<vtkPoints> GetSliceBoundPoints();
//@{
/**
* Get the internal render window, renderer, image actor, and
* image map instances.
*/
vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
vtkGetObjectMacro(Renderer, vtkRenderer);
vtkGetObjectMacro(ImageActor, vtkImageSlice);
vtkGetObjectMacro(ImageMapper, vtkImageSliceMapper);
vtkGetObjectMacro(InteractorStyle, ActorDraggableInteractorStyle);
//@}
//@{
/**
* Set window and level for mapping pixels to colors.
*/
virtual double GetColorWindow();
//@{
/**
* Set your own renderwindow and renderer
*/
virtual void SetRenderWindow(vtkRenderWindow* arg);
virtual void SetRenderer(vtkRenderer* arg);
//@}
virtual double GetColorLevel();
/**
* Attach an interactor for the internal render window.
*/
virtual void SetupInteractor(vtkRenderWindowInteractor*);
virtual void SetColorWindow(double s);
//@{
/**
* Create a window in memory instead of on the screen. This may not
* be supported for every type of window and on some windows you may
* need to invoke this prior to the first render.
*/
virtual void SetOffScreenRendering(vtkTypeBool);
virtual vtkTypeBool GetOffScreenRendering();
vtkBooleanMacro(OffScreenRendering, vtkTypeBool);
//@}
virtual void SetColorLevel(double s);
void SetNegativeMode(bool negative);
void SetLookupTable(vtkLookupTable *lut);
//@}
//@{
/**
* These are here when using a Tk window.
*/
virtual void SetDisplayId(void *a);
virtual void SetWindowId(void *a);
virtual void SetParentId(void *a);
//@}
void SetZoomScale(double scale);
void SetPanOffset(const double *point);
void ResetZoomScaleToFitWindowSize();
//@{
/**
* Get the position (x and y) of the rendering window in
* screen coordinates (in pixels).
*/
virtual int *GetPosition() VTK_SIZEHINT(2);
/**
* Set the position (x and y) of the rendering window in
* screen coordinates (in pixels). This resizes the operating
* system's view/window and redraws it.
*/
virtual void SetPosition(int x, int y);
virtual void SetPosition(int a[2]) { this->SetPosition(a[0], a[1]); }
//@}
//@{
/**
* Get the size (width and height) of the rendering window in
* screen coordinates (in pixels).
*/
virtual int *GetSize() VTK_SIZEHINT(2);
/**
* Set the size (width and height) of the rendering window in
* screen coordinates (in pixels). This resizes the operating
* system's view/window and redraws it.
*
* If the size has changed, this method will fire
* vtkCommand::WindowResizeEvent.
*/
virtual void SetSize(int width, int height);
virtual void SetSize(int a[2]) { this->SetSize(a[0], a[1]); }
//@}
//@{
/**
* Get the internal render window, renderer, image actor, and
* image map instances.
*/
vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
vtkGetObjectMacro(Renderer, vtkRenderer);
vtkGetObjectMacro(ImageActor, vtkImageSlice);
vtkGetObjectMacro(ImageMapper, vtkImageSliceMapper);
vtkGetObjectMacro(InteractorStyle, ActorDraggableInteractorStyle);
//@}
//@{
/**
* Set your own renderwindow and renderer
*/
virtual void SetRenderWindow(vtkRenderWindow *arg);
virtual void SetRenderer(vtkRenderer *arg);
//@}
/**
* Attach an interactor for the internal render window.
*/
virtual void SetupInteractor(vtkRenderWindowInteractor *);
//@{
/**
* Create a window in memory instead of on the screen. This may not
* be supported for every type of window and on some windows you may
* need to invoke this prior to the first render.
*/
virtual void SetOffScreenRendering(vtkTypeBool);
virtual vtkTypeBool GetOffScreenRendering();
vtkBooleanMacro(OffScreenRendering, vtkTypeBool);
//@}
vtkGetMacro(Fusion, vtkTypeBool);
vtkSetMacro(Fusion, vtkTypeBool);
//@{
/**
* Fusion On and Off,if fusion is on ,the renderer will try to show Fusion Data,
* which need to be set with SetFusionInputData function. Without SetFusionInputData,
* there will no Fusion Data show.
*/
vtkBooleanMacro(Fusion, vtkTypeBool);
//@}
vtkGetMacro(Fusion, vtkTypeBool);
//@{
/**
* Fusion Opacity, default is 0.5
*/
vtkGetMacro(FusionOpacity, double);
//@}
void SetFusionOpacity(double);
void IncreFusionOpacity(double);
void SetScalarBarTitle(double);
//@{
/**
* Set a imageData to fusion with current rendered image.
*/
void SetFusionInputData(vtkImageData*);
//@}
//@{
/**
* Set color level for fusion lookupTable, only will take effect after SetFusionInputData.
*/
void SetFusionColorLeveL(double level);
//@}
vtkSetMacro(Fusion, vtkTypeBool);
//@{
/**
* Fusion On and Off,if fusion is on ,the renderer will try to show Fusion Data,
* which need to be set with SetFusionInputData function. Without SetFusionInputData,
* there will no Fusion Data show.
*/
vtkBooleanMacro(Fusion, vtkTypeBool);
//@}
//@{
/**
* Set color window for fusion lookupTable, only will take effect after SetFusionInputData.
*/
void SetFusionColorWindow(double window);
//@}
//@{
/**
* Fusion Opacity, default is 0.5
*/
vtkGetMacro(FusionOpacity, double);
//@{
/**
* Set a ColorTable for fusion, only will take effect after SetFusionInputData.
*/
void SetFusionColorTable(vtkScalarsToColors*);
//@}
void SetFusionOpacity(double);
void IncreFusionOpacity(double);
void SetScalarBarTitle(double);
//@{
/**
* Set a imageData to fusion with current rendered image.
*/
void SetFusionInputData(vtkImageData *);
//@}
//@{
/**
* Set color level for fusion lookupTable, only will take effect after SetFusionInputData.
*/
void SetFusionColorLeveL(double level);
//@}
//@{
/**
* Set color window for fusion lookupTable, only will take effect after SetFusionInputData.
*/
void SetFusionColorWindow(double window);
//@}
//@{
/**
* Set a ColorTable for fusion, only will take effect after SetFusionInputData.
*/
void SetFusionColorTable(vtkScalarsToColors *);
//@}
//@{
/**
* Set a Preset ColorTable for fusion, only will take effect after SetFusionInputData.
*/
void SetFusionColorPreset(const char *preset);
//@}
//@}
//@}
//@{
/**
@@ -288,109 +339,123 @@ public:
*/
void SwitchToNextPreset();
//@}
//
//@{
/**
* Remove fusion from viewer
*/
void RemoveFusionData();
//@}
//
//@{
/**
* Remove fusion from viewer
*/
void RemoveFusionData();
//@}
//@{
/**
* Remove fusion actor from viewer
*/
void RemoveFusionActor();
//@{
/**
* Remove fusion actor from viewer
*/
void RemoveFusionActor();
void DeleteSelectedMeasure();
void DeleteCurrentSliceMeasure();
void DeleteCurrentSeriesMeasure();
void ActiveMeasure(Measure* m);
void UnActiveMeasure();
void ActiveMeasure(Measure *m);
void UnActiveMeasure();
void ActiveRuler();
void UnActiveRuler();
//for convert vtkEvent to Qt signal
vtkSignalRaiser* GetSignalRaiser(){
//for convert vtkEvent to Qt signal
vtkSignalRaiser *GetSignalRaiser() {
return &raiser;
}
void SyncSlicePoint(double* point);
void GetSlicePoint(double* point);
void SyncSlicePoint(double *point);
void GetSlicePoint(double *point);
protected:
infinitiViewer();
~infinitiViewer() override;
infinitiViewer();
~infinitiViewer() override;
vtkAlgorithm *GetInputAlgorithm();
vtkInformation *GetInputInformation();
virtual void InstallPipeline();
virtual void UnInstallPipeline();
void PrepareFusionColorTable(vtkScalarsToColors* table, bool reset = false);
virtual void UnInstallPipeline();
vtkRenderWindow* RenderWindow;
vtkRenderer* Renderer;
vtkImageStack* ImageStack;
vtkImageSlice* ImageActor;
vtkImageSlice* FusionActor;
vtkImageSliceMapper* ImageMapper;
vtkImageSliceMapper* FusionMapper;
vtkRenderWindowInteractor* Interactor;
ActorDraggableInteractorStyle* InteractorStyle = nullptr;
vtkTextActor* OpacityActor;
vtkCornerAnnotation* cornerAnnotation;
void PrepareFusionColorTable(vtkScalarsToColors *table, bool reset = false);
#ifdef IN_TEST_MODE
vtkScalarBarActor* bar;
#endif
virtual void UpdateOrientation();
int SliceOrientation;
int FirstRender;
int Slice;
int loadedMeasureSlice;
vtkTypeBool Fusion = false;
vtkTypeBool firstFusion = true;
double FusionOpacity = 0.5;
virtual void UpdateOrientation();
vtkAlgorithm* GetInputAlgorithm();
vtkInformation* GetInputInformation();
void LoadMeasures(){
void LoadMeasures() {
LoadMeasures(false);
}
void LoadMeasures(bool forceReload);
void AddMeasures(vtkObject*,unsigned long eventid,void* calldata );
void RemoveMeasures(vtkObject*,unsigned long eventid,void* calldata );
}
void LoadMeasures(bool forceReload);
void AddMeasures(vtkObject *, unsigned long eventid, void *calldata);
void RemoveMeasures(vtkObject *, unsigned long eventid, void *calldata);
private:
infinitiViewer(const infinitiViewer&) = delete;
void operator=(const infinitiViewer&) = delete;
std::vector<std::vector<double>> fusion_tf_vector;
infinitiViewer(const infinitiViewer &) = delete;
void operator=(const infinitiViewer &) = delete;
std::vector<std::vector<double>> fusion_tf_vector;
//for convert vtkEvent to Qt signal
vtkSignalRaiser raiser;
QList<Measure*>* list = nullptr;
MeasureStore* measureStore;
QList<Measure *> *list = nullptr;
MeasureStore *measureStore;
void raiseEvent(vtkObject* sender,unsigned long eventId,void* callData = nullptr){
raiser.raiseEvent(sender,eventId,callData);
void raiseEvent(vtkObject *sender, unsigned long eventId, void *callData = nullptr) {
raiser.raiseEvent(sender, eventId, callData);
}
void ClearCurrentSliceMeasure() const;
void ReloadCurrentSliceMeasure();
void updateTopLeftCornerInfo();
void UpdateTopLeftCornerInfo();
void RenderRuler();
vtkRenderWindow *RenderWindow;
vtkRenderer *Renderer;
vtkImageStack *ImageStack;
vtkImageSlice *ImageActor;
vtkImageSlice *FusionActor;
vtkImageSliceMapper *ImageMapper;
vtkImageSliceMapper *FusionMapper;
vtkRenderWindowInteractor *Interactor;
ActorDraggableInteractorStyle *InteractorStyle = nullptr;
vtkTextActor *OpacityActor;
vtkCornerAnnotation *cornerAnnotation;
vtkScalarBarActor *bar;
vtkNew<RulerLegendActor> ruler;
bool rulerActive = false;
void RenderRuler();
int currentPresetIndex=1;
int viewUpIndex = 0;
int viewRightIndex = 1;
DicomCornerInfo m_cornerInfo;
char SOP_UID[20]={0};
double imageDataOrigin[3] = {.0, .0, .0};
vtkNew<vtkMatrix4x4> matrix;
DicomCornerInfo m_cornerInfo;
int SliceOrientation;
int FirstRender;
int Slice;
int loadedMeasureSlice;
int currentPresetIndex = 1;
vtkTypeBool Fusion = false;
vtkTypeBool firstFusion = true;
double FusionOpacity = 0.5;
bool rulerActive = false;
char SOP_UID[20] = {0};
double imageDataOrigin[3] = {.0, .0, .0};
};
#endif

View File

@@ -128,7 +128,7 @@ void DicomImageView::Slot_WindowLevelEventForFusion(double level, double width)
void DicomImageView::Slot_Transformation()
{
mImageViewer->updateOrienInfo();
mImageViewer->UpdateOrientationInfo();
mImageViewer->Render();
}
@@ -331,9 +331,9 @@ void DicomImageView::LoadSeries(SeriesImageSet *series)
{
mSeries = series;
mImageViewer->SetInputData(mSeries->GetData());
mImageViewer->initCornerInfo(series->GetProperty());
mImageViewer->setUpImageViewer();
mImageViewer->updateOrienInfo();
mImageViewer->InitCornerInfo(series->GetProperty());
mImageViewer->SetupImageViewer();
mImageViewer->UpdateOrientationInfo();
//以下是一些转接函数
//使用connect 替代 AddObserver,避免出现多种事件机制架构
connect(mImageViewer->GetSignalRaiser(),&vtkSignalRaiser::raiseEvent, this, &DicomImageView::syncEventFunc);
@@ -350,7 +350,7 @@ void DicomImageView::LoadSeries(SeriesImageSet *series)
//Callbacks------------------------------------------------------------------------------------
void DicomImageView::updateWindowLevelCb(vtkObject* caller, unsigned long eid, void *calldata)
{
mImageViewer->updateCornerInfo(BOTTOM_RIGHT);
mImageViewer->UpdateCornerInfo(BOTTOM_RIGHT);
emit Signal_WindowLevelEventForFusion(mImageViewer->GetColorLevel(), mImageViewer->GetColorWindow());
}
@@ -538,7 +538,7 @@ void DicomImageView::SetWindowLevel(double level, double width)
mImageViewer->SetColorWindow(width);
//You have to call updateConerInfo manually
//only mouse event can rely on callback
mImageViewer->updateCornerInfo(BOTTOM_RIGHT);
mImageViewer->UpdateCornerInfo(BOTTOM_RIGHT);
emit Signal_WindowLevelEventForFusion(level, width);
}
@@ -652,7 +652,7 @@ void DicomImageView::updateCornerInfoAll()
{
if (HasSeries())
{
mImageViewer->updateCornerInfoAll();
mImageViewer->UpdateCornerInfoAll();
}
}
@@ -660,7 +660,7 @@ void DicomImageView::updateCornerInfoPrivacy()
{
if (HasSeries())
{
mImageViewer->updateCornerInfo(TOP_RIGHT);
mImageViewer->UpdateCornerInfo(TOP_RIGHT);
}
}
@@ -802,8 +802,5 @@ void DicomImageView::viewerClicked() {
}
void DicomImageView::SyncScrollBar() {
// setScrollChangedType(scrollScope::TriggerType::SYNC_ONLY);
mScrollBar->SetValueSilently(mImageViewer->GetSlice());
mImageViewer->updateCornerInfo(TOP_LEFT);
// setScrollChangedType(scrollScope::TriggerType::USER_TRIGGER);
}

View File

@@ -594,7 +594,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->Rotate(90, ROTATE_90_CCW);
//curV->getImageViewer()->updateOrienInfo();
}
});
@@ -603,7 +602,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->Rotate(-90, ROTATE_90_CW);
//curV->getImageViewer()->updateOrienInfo();
}
});
m->addAction(tr("Rotate 180"), this, [&] {
@@ -611,7 +609,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->Rotate(180, ROTATE_180);
//curV->getImageViewer()->updateOrienInfo();
}
});
@@ -621,7 +618,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->HFlip();
//curV->getImageViewer()->updateOrienInfo(H_FLIP);
}
});
m->addAction(tr("Flip vertical"), this, [&] {
@@ -629,7 +625,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->VFlip();
//curV->getImageViewer()->updateOrienInfo(V_FLIP);
}
});
@@ -639,7 +634,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->ClearTransformations();
//curV->getImageViewer()->updateOrienInfo(CLEAR);
}
});
flipBtn->setPopupMode(QToolButton::MenuButtonPopup);
@@ -650,7 +644,6 @@ void QDicomViewer::SetupFlipTool(QToolButton* flipBtn)
if (curV != nullptr && curV->HasSeries())
{
curV->Rotate(90, ROTATE_90_CCW);
//curV->getImageViewer()->updateOrienInfo(ROTATE_90_CCW);
}
});
}