Load data memory fix.(corner anno caused)

This commit is contained in:
Krad
2022-03-01 17:32:35 +08:00
parent 00ccdb8368
commit f36e8d2330
7 changed files with 331 additions and 310 deletions

View File

@@ -19,6 +19,7 @@ class SeriesImageSet;
class DICOMDirectoryHelper; class DICOMDirectoryHelper;
class ExtendMedicalImageProperties; class ExtendMedicalImageProperties;
class vtkDICOMImageReader2; class vtkDICOMImageReader2;
typedef std::map<std::string, SeriesImageSet*> ImageSetStore;
class DicomLoader { class DicomLoader {
public: public:
@@ -53,8 +54,8 @@ public:
} }
//if not duplicate
SeriesImageSet* InitFromRead(const UniqueIDInfo &uniqueID);// , DicomTagInfo_t* tag_info); SeriesImageSet* getSeriesImageSet(const UniqueIDInfo &uniqueID);
SeriesInfo_t* getSerieInfo(const UniqueIDInfo &uniqueID); SeriesInfo_t* getSerieInfo(const UniqueIDInfo &uniqueID);
SeriesImageSet* getFirstInstance(const UniqueIDInfo &uniqueID); SeriesImageSet* getFirstInstance(const UniqueIDInfo &uniqueID);
@@ -84,7 +85,7 @@ private:
ExtendMedicalImageProperties * currentImageProperty = nullptr; ExtendMedicalImageProperties * currentImageProperty = nullptr;
std::vector<ExtendMedicalImageProperties*> imageProperties; std::vector<ExtendMedicalImageProperties*> imageProperties;
vtkDICOMImageReader2 * reader = nullptr; vtkDICOMImageReader2 * reader = nullptr;
ImageSetStore store;
AddDicomType m_addType; AddDicomType m_addType;
PatientsMapType m_patients; PatientsMapType m_patients;
vtkObject* placeHolder; vtkObject* placeHolder;

View File

@@ -46,6 +46,11 @@ public slots:
void Slot_ViewClicked(DicomImageView *view); void Slot_ViewClicked(DicomImageView *view);
void Slot_ViewDoubleClicked(DicomImageView *view); void Slot_ViewDoubleClicked(DicomImageView *view);
void Slot_DragDropEvent(DicomImageView *view, thumbnailImage* tb); void Slot_DragDropEvent(DicomImageView *view, thumbnailImage* tb);
/**
* 缩略图点击槽函数会导致当前选中的view重新load数据
* @param tb 缩略图对象
* @return
*/
void Slot_ThumbnailClickEvent(thumbnailImage* tb); void Slot_ThumbnailClickEvent(thumbnailImage* tb);
void Slot_SyncEvent(DicomImageView *view, int interactionMode, void* calldata); void Slot_SyncEvent(DicomImageView *view, int interactionMode, void* calldata);

View File

@@ -154,8 +154,15 @@ bool DicomLoader::IsDuplicate(UniqueIDInfo_t* unique)
SeriesImageSet* DicomLoader::InitFromRead(const UniqueIDInfo &uniqueID)//, DicomTagInfo_t* tag_info) SeriesImageSet* DicomLoader::getSeriesImageSet(const UniqueIDInfo &uniqueID)//, DicomTagInfo_t* tag_info)
{ {
//only user key to the series level
auto key = uniqueID.patient_name+uniqueID.study_uid+uniqueID.series_uid;
if (store.count(key)>0)
{
//use cache instead load
return store[key];
}
if (reader) reader->Delete(); if (reader) reader->Delete();
reader = vtkDICOMImageReader2::New(); reader = vtkDICOMImageReader2::New();
reader->SetFileNames(*(currentImageProperty->GetFileNames())); reader->SetFileNames(*(currentImageProperty->GetFileNames()));
@@ -163,6 +170,7 @@ SeriesImageSet* DicomLoader::InitFromRead(const UniqueIDInfo &uniqueID)//, Dicom
SeriesImageSet* result = new SeriesImageSet(uniqueID,currentImageProperty,reader->GetOutput()); SeriesImageSet* result = new SeriesImageSet(uniqueID,currentImageProperty,reader->GetOutput());
reader->Delete(); reader->Delete();
reader = nullptr; reader = nullptr;
store[key] = result;
return result; return result;
} }
@@ -398,7 +406,7 @@ DicomTagInfo_t* DicomLoader::createDicomTagsInfo()
SeriesImageSet* DicomLoader::createSeries(UniqueIDInfo_t* uniqueID) SeriesImageSet* DicomLoader::createSeries(UniqueIDInfo_t* uniqueID)
{ {
SeriesImageSet* series =instance->InitFromRead(*uniqueID); SeriesImageSet* series = instance->getSeriesImageSet(*uniqueID);
series->setUpSeriesInstance(); series->setUpSeriesInstance();
return series; return series;

View File

@@ -355,6 +355,7 @@ infinitiViewer::~infinitiViewer()
{ {
if (this->ImageMapper) if (this->ImageMapper)
{ {
this->ImageMapper->SetInputData(nullptr);
this->ImageMapper->Delete(); this->ImageMapper->Delete();
this->ImageMapper = nullptr; this->ImageMapper = nullptr;
} }
@@ -363,6 +364,7 @@ infinitiViewer::~infinitiViewer()
this->ImageActor->Delete(); this->ImageActor->Delete();
this->ImageActor = nullptr; this->ImageActor = nullptr;
} }
if (this->FusionMapper) if (this->FusionMapper)
{ {
this->FusionMapper->Delete(); this->FusionMapper->Delete();
@@ -394,9 +396,14 @@ infinitiViewer::~infinitiViewer()
if (this->InteractorStyle) if (this->InteractorStyle)
{ {
this->InteractorStyle->SetCornerAnnotation(nullptr);
this->InteractorStyle->Delete(); this->InteractorStyle->Delete();
this->InteractorStyle = nullptr; this->InteractorStyle = nullptr;
} }
if (this->cornerAnnotation) {
this->cornerAnnotation->Delete();
this->cornerAnnotation = nullptr;
}
measureStore->RemoveAllInSeries(SOP_UID); measureStore->RemoveAllInSeries(SOP_UID);
// measureStore->Clear(); // measureStore->Clear();
//delete measureStore; //delete measureStore;
@@ -1202,14 +1209,14 @@ void infinitiViewer::initTopLeftCornerInfo(const std::string& lbl_ser_num, const
void infinitiViewer::initCornerInfo(ExtendMedicalImageProperties* pSeries) void infinitiViewer::initCornerInfo(ExtendMedicalImageProperties* pSeries)
{ {
if(pSeries->GetNumberOfWindowLevelPresets()>0) if (pSeries->GetNumberOfWindowLevelPresets() > 0)
{ {
double * wwwl = pSeries->GetNthWindowLevelPreset(0); double* wwwl = pSeries->GetNthWindowLevelPreset(0);
m_cornerInfo.win_level = (int)wwwl[1]; m_cornerInfo.win_level = (int)wwwl[1];
m_cornerInfo.win_width = (int)wwwl[0]; m_cornerInfo.win_width = (int)wwwl[0];
} }
char buffer [sizeof(long)*8+1]; char buffer[sizeof(long) * 8 + 1];
const char* s = ltoa(pSeries->GetFileNames()->size(), buffer, 10); const char* s = ltoa(pSeries->GetFileNames()->size(), buffer, 10);
m_cornerInfo.ConstAnno[TOP_LEFT].append(buffer); m_cornerInfo.ConstAnno[TOP_LEFT].append(buffer);
m_cornerInfo.ConstAnno[TOP_LEFT].append(" "); m_cornerInfo.ConstAnno[TOP_LEFT].append(" ");

View File

@@ -29,7 +29,7 @@
#include "QGlobals.h" #include "QGlobals.h"
vtkStandardNewMacro(ActorDraggableInteractorStyle); vtkStandardNewMacro(ActorDraggableInteractorStyle);
ActorDraggableInteractorStyle::ActorDraggableInteractorStyle() { ActorDraggableInteractorStyle::ActorDraggableInteractorStyle() {
this->AddObserver(vtkCommand::InteractionEvent,this,&ActorDraggableInteractorStyle::DispatchEvent); this->AddObserver(vtkCommand::InteractionEvent, this, &ActorDraggableInteractorStyle::DispatchEvent);
#ifdef _DEBUG #ifdef _DEBUG
this->AddObserver(DraggableStyleEvents::EndDollyEvent, this, &ActorDraggableInteractorStyle::TestOutPut); this->AddObserver(DraggableStyleEvents::EndDollyEvent, this, &ActorDraggableInteractorStyle::TestOutPut);
this->AddObserver(vtkCommand::EventIds::EndPanEvent, this, &ActorDraggableInteractorStyle::TestOutPut); this->AddObserver(vtkCommand::EventIds::EndPanEvent, this, &ActorDraggableInteractorStyle::TestOutPut);
@@ -40,7 +40,13 @@ ActorDraggableInteractorStyle::ActorDraggableInteractorStyle() {
} }
ActorDraggableInteractorStyle::~ActorDraggableInteractorStyle() { ActorDraggableInteractorStyle::~ActorDraggableInteractorStyle() {
if (scalarProp) {
scalarProp->Delete();
scalarProp = nullptr;
}
if (CornerAnnotation) {
CornerAnnotation->UnRegister(this);
}
} }
template<typename T> template<typename T>
@@ -75,9 +81,9 @@ void ActorDraggableInteractorStyle::OnLeftButtonUp() {
this->EndMeasure(); this->EndMeasure();
auto temp = measure; auto temp = measure;
measure = measure->GetNextMeasure(); measure = measure->GetNextMeasure();
if (!temp->Valid()){ if (!temp->Valid()) {
temp->ForceDelete(); temp->ForceDelete();
temp= nullptr; temp = nullptr;
} }
} }
break; break;
@@ -90,11 +96,11 @@ void ActorDraggableInteractorStyle::OnLeftButtonUp() {
void ActorDraggableInteractorStyle::ColorMapping() void ActorDraggableInteractorStyle::ColorMapping()
{ {
vtkRenderWindowInteractor *rwi = this->Interactor; vtkRenderWindowInteractor* rwi = this->Interactor;
this->ScalarCurrentPosition[1] = rwi->GetEventPosition()[1]; this->ScalarCurrentPosition[1] = rwi->GetEventPosition()[1];
//pos[0] = (this->ScalarCurrentPosition[0] - this->ScalarStartPosition[0]); //pos[0] = (this->ScalarCurrentPosition[0] - this->ScalarStartPosition[0]);
double total = 0.01*((this->ScalarCurrentPosition[1] - this->ScalarStartPosition[1])/scalarSensitivity); double total = 0.01 * ((this->ScalarCurrentPosition[1] - this->ScalarStartPosition[1]) / scalarSensitivity);
double left = total - ConsumedOpacity; double left = total - ConsumedOpacity;
//printf("ColorMapping:%d,%d,%.2f \r\n", ScalarCurrentPosition[1], ScalarStartPosition[1],left); //printf("ColorMapping:%d,%d,%.2f \r\n", ScalarCurrentPosition[1], ScalarStartPosition[1],left);
if (abs(left) >= 0.01) { if (abs(left) >= 0.01) {
@@ -121,7 +127,7 @@ void ActorDraggableInteractorStyle::EndColorMapping()
void ActorDraggableInteractorStyle::Drag() { void ActorDraggableInteractorStyle::Drag() {
int* pos = this->Interactor->GetEventPosition(); int* pos = this->Interactor->GetEventPosition();
this->FindPokedRenderer(pos[0],pos[1]); this->FindPokedRenderer(pos[0], pos[1]);
DraggableActor::SafeDownCast(dragProp)->Transform(pos[0] - DragStartOrigin[0], pos[1] - DragStartOrigin[1]); DraggableActor::SafeDownCast(dragProp)->Transform(pos[0] - DragStartOrigin[0], pos[1] - DragStartOrigin[1]);
this->Interactor->Render(); this->Interactor->Render();
} }
@@ -205,10 +211,10 @@ void ActorDraggableInteractorStyle::NoneStatePick() {
scalarProp = nullptr; scalarProp = nullptr;
} }
dragProp = nullptr; dragProp = nullptr;
this->CornerAnnotation->SetText(BOTTOM_LEFT, ""); if (this->CornerAnnotation)this->CornerAnnotation->SetText(BOTTOM_LEFT, "");
} }
} }
this->CornerAnnotation->SetText(BOTTOM_LEFT, ""); if (this->CornerAnnotation)this->CornerAnnotation->SetText(BOTTOM_LEFT, "");
this->Interactor->Render(); this->Interactor->Render();
} }
@@ -244,7 +250,7 @@ void ActorDraggableInteractorStyle::OnMouseMove() {
void ActorDraggableInteractorStyle::WindowLevel() void ActorDraggableInteractorStyle::WindowLevel()
{ {
vtkRenderWindowInteractor *rwi = this->Interactor; vtkRenderWindowInteractor* rwi = this->Interactor;
this->WindowLevelCurrentPosition[0] = rwi->GetEventPosition()[0]; this->WindowLevelCurrentPosition[0] = rwi->GetEventPosition()[0];
this->WindowLevelCurrentPosition[1] = rwi->GetEventPosition()[1]; this->WindowLevelCurrentPosition[1] = rwi->GetEventPosition()[1];
@@ -256,7 +262,7 @@ void ActorDraggableInteractorStyle::WindowLevel()
} }
if (this->CurrentImageProperty) if (this->CurrentImageProperty)
{ {
int *size = this->CurrentRenderer->GetSize(); int* size = this->CurrentRenderer->GetSize();
double window = this->WindowLevelInitial[0]; double window = this->WindowLevelInitial[0];
double level = this->WindowLevelInitial[1]; double level = this->WindowLevelInitial[1];
@@ -346,7 +352,7 @@ void ActorDraggableInteractorStyle::OnLeftButtonDown() {
selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::UnSelectedEvent); selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::UnSelectedEvent);
selectedProp = nullptr; selectedProp = nullptr;
} }
if (dragProp){ if (dragProp) {
selectedProp = dragProp; selectedProp = dragProp;
selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::SelectedEvent); selectedProp->InvokeEvent(DraggableActor::DraggableActorEvents::SelectedEvent);
if (this->Interactor->GetRepeatCount()) if (this->Interactor->GetRepeatCount())
@@ -358,7 +364,7 @@ void ActorDraggableInteractorStyle::OnLeftButtonDown() {
this->StartDrag(); this->StartDrag();
return; return;
} }
if (Interactor->GetRepeatCount()){ if (Interactor->GetRepeatCount()) {
if (measure) if (measure)
{ {
measure->SetPlacing(measure->onMeasureDoubleClick(this->Interactor)); measure->SetPlacing(measure->onMeasureDoubleClick(this->Interactor));
@@ -366,9 +372,9 @@ void ActorDraggableInteractorStyle::OnLeftButtonDown() {
this->EndMeasure(); this->EndMeasure();
auto temp = measure; auto temp = measure;
measure = measure->GetNextMeasure(); measure = measure->GetNextMeasure();
if (!temp->Valid()){ if (!temp->Valid()) {
temp->ForceDelete(); temp->ForceDelete();
temp= nullptr; temp = nullptr;
} }
} }
return; return;
@@ -379,7 +385,7 @@ void ActorDraggableInteractorStyle::OnLeftButtonDown() {
if (measure) if (measure)
{ {
measure->SetPlacing(measure->onMeasureLeftButtonDown(this->Interactor)); measure->SetPlacing(measure->onMeasureLeftButtonDown(this->Interactor));
if(this->State!=VTKIS_MEASURE) this->StartMeasure(); if (this->State != VTKIS_MEASURE) this->StartMeasure();
return; return;
} }
@@ -414,7 +420,7 @@ void ActorDraggableInteractorStyle::OnLeftButtonDown() {
} }
void ActorDraggableInteractorStyle::ActiveMeasure(Measure *m) { void ActorDraggableInteractorStyle::ActiveMeasure(Measure* m) {
if (this->measure && nullptr == m) { if (this->measure && nullptr == m) {
this->measure->onTerminate(this->Interactor); this->measure->onTerminate(this->Interactor);
} }
@@ -440,8 +446,8 @@ void ActorDraggableInteractorStyle::DispatchEvent() {
this->SetCurrentImageNumber(this->CurrentImageNumber); this->SetCurrentImageNumber(this->CurrentImageNumber);
} }
if (!this->CurrentImageSlice) return; if (!this->CurrentImageSlice) return;
vtkImageSliceMapper *mapper = vtkImageSliceMapper::SafeDownCast(this->CurrentImageSlice->GetMapper()); vtkImageSliceMapper* mapper = vtkImageSliceMapper::SafeDownCast(this->CurrentImageSlice->GetMapper());
int slice[1] = {mapper ? mapper->GetSliceNumber() : -1}; int slice[1] = { mapper ? mapper->GetSliceNumber() : -1 };
//鼠标滑动不一定能造成翻页!!!所以需要进行一次判定 //鼠标滑动不一定能造成翻页!!!所以需要进行一次判定
if (slice[0] != lastslice) { if (slice[0] != lastslice) {
this->InvokeEvent(DraggableStyleEvents::SlicedEvent, slice); this->InvokeEvent(DraggableStyleEvents::SlicedEvent, slice);
@@ -546,8 +552,8 @@ void ActorDraggableInteractorStyle::EndDolly() {
} }
//激发缩放完成事件 //激发缩放完成事件
if (this->HandleObservers) { if (this->HandleObservers) {
vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
double result[2] = {0.0, 0.0}; double result[2] = { 0.0, 0.0 };
//image 必然是ParallelProjection //image 必然是ParallelProjection
result[0] = this->DollyStartScale; result[0] = this->DollyStartScale;
result[1] = camera->GetParallelScale(); result[1] = camera->GetParallelScale();
@@ -564,9 +570,9 @@ void ActorDraggableInteractorStyle::StartPan() {
void ActorDraggableInteractorStyle::EndPan() { void ActorDraggableInteractorStyle::EndPan() {
if (this->State != VTKIS_PAN) return; if (this->State != VTKIS_PAN) return;
if (this->HandleObservers) { if (this->HandleObservers) {
vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
double *nf = camera->GetFocalPoint(); double* nf = camera->GetFocalPoint();
double calldata[6] = {PanStartOrigin[0], PanStartOrigin[1], PanStartOrigin[2], nf[0], nf[1], nf[2]}; double calldata[6] = { PanStartOrigin[0], PanStartOrigin[1], PanStartOrigin[2], nf[0], nf[1], nf[2] };
this->InvokeEvent(vtkCommand::EventIds::EndPanEvent, calldata); this->InvokeEvent(vtkCommand::EventIds::EndPanEvent, calldata);
} }
this->StopState(); this->StopState();
@@ -577,7 +583,7 @@ void ActorDraggableInteractorStyle::EndWindowLevel() {
return; return;
} }
if (this->HandleObservers) { if (this->HandleObservers) {
double calldata[2] = {this->CurrentImageProperty->GetColorWindow(),this->CurrentImageProperty->GetColorLevel()}; double calldata[2] = { this->CurrentImageProperty->GetColorWindow(),this->CurrentImageProperty->GetColorLevel() };
this->InvokeEvent(vtkCommand::EndWindowLevelEvent, calldata); this->InvokeEvent(vtkCommand::EndWindowLevelEvent, calldata);
} }
this->StopState(); this->StopState();
@@ -586,11 +592,11 @@ void ActorDraggableInteractorStyle::OnChar() {
vtkInteractorStyleImage::OnChar(); vtkInteractorStyleImage::OnChar();
vtkRenderWindowInteractor* rwi = this->Interactor; vtkRenderWindowInteractor* rwi = this->Interactor;
std::string keySym = rwi->GetKeySym(); std::string keySym = rwi->GetKeySym();
if (keySym=="Delete") if (keySym == "Delete")
{ {
if (selectedProp) if (selectedProp)
{ {
this->InvokeEvent(DraggableStyleEvents::DeleteMeasureEvent,selectedProp); this->InvokeEvent(DraggableStyleEvents::DeleteMeasureEvent, selectedProp);
} }
} }
} }

View File

@@ -684,6 +684,9 @@ void DicomImageView::Render()
void DicomImageView::CopyFromSeries(SeriesImageSet *series) void DicomImageView::CopyFromSeries(SeriesImageSet *series)
{ {
if (_Series){
delete _Series;
}
_Series = series; _Series = series;
_ImageViewer->SetInputData(_Series->GetData()); _ImageViewer->SetInputData(_Series->GetData());
@@ -804,16 +807,14 @@ void DicomImageView::ResetView()
removeViewWithFusion(); removeViewWithFusion();
removeViewWithMeasure(); removeViewWithMeasure();
orphanizeSeriesInstance(); orphanizeSeriesInstance();
//_glWidt->update(); //_glWidt->update();
//_scrollBar = nullptr; //_scrollBar = nullptr;
_ImageViewer->Delete(); _ImageViewer->Delete();
_ImageViewer = nullptr; _ImageViewer = nullptr;
int count = _Series->GetData()->GetReferenceCount();
qDebug()<<count;
_Series = nullptr; _Series = nullptr;
_ScrollTriggerType = scrollScope::TriggerType::USER_TRIGGER; _ScrollTriggerType = scrollScope::TriggerType::USER_TRIGGER;

View File

@@ -407,13 +407,6 @@ void ViewContainerWidget::Slot_ThumbnailClickEvent(thumbnailImage* tb)
return; return;
} }
SeriesInfo_t* serie_info = tb->getSeriesInfo(); SeriesInfo_t* serie_info = tb->getSeriesInfo();
SeriesImageSet* old = nullptr;
bool copy = true;
if (view->HasSeries())
{
old = view->getSeriesInstance();
}
replaceViewWithSerie(serie_info->unique_info, view); replaceViewWithSerie(serie_info->unique_info, view);
setCurrentView(view); setCurrentView(view);
} }