X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvSlicerManager.cxx;h=89fd42b49fae4177e89ec0c2ee4590e38c9a6f54;hb=857c9e74552dccd4c71364c15cca4ade140511fc;hp=6f5c55abff3cbb809394638bbaf937c901f021c3;hpb=d38b545ea6b6428350b3a40c79df800cd62bef02;p=clitk.git diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 6f5c55a..89fd42b 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -40,6 +40,7 @@ #include #include +#include //---------------------------------------------------------------------------- vvSlicerManager::vvSlicerManager(int numberOfSlicers) { @@ -62,10 +63,12 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers) mFusionLevel = 1000; mFusionShowLegend = true; + mFusionSequenceInvolvementCode = -1; + mFusionSequenceIndexLinkedManager = -1; mFusionSequenceFrameIndex = -1; - mFusionSequenceSpatialSyncFlag = false; mFusionSequenceNbFrames = 0; - mFusionSequenceIndexLinkedManager = -1; + mFusionSequenceSpatialSyncFlag = false; + mFusionSequenceTemporalSyncFlag = false; mLandmarks = NULL; mLinkedId.resize(0); @@ -74,8 +77,8 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers) mSlicers.push_back(vtkSmartPointer::New()); mSelectedSlicer = -1; - mPreviousSlice.resize(numberOfSlicers); - mPreviousTSlice.resize(numberOfSlicers); + mPreviousSlice.resize(numberOfSlicers, 0); + mPreviousTSlice.resize(numberOfSlicers, 0); mSlicingPreset = WORLD_SLICING; @@ -276,20 +279,18 @@ bool vvSlicerManager::SetOverlay(std::vector filenames,int dim, std //---------------------------------------------------------------------------- -bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component) +bool vvSlicerManager::SetFusion(std::vector filenames,int dim, std::string component, vvImageReader::LoadedImageType type) { - mFusionName = filename; + mFusionName = filenames[0]; mFusionComponent = component; if (dim > mImage->GetNumberOfDimensions()) { - mLastError = " Overlay dimension cannot be greater then reference image!"; + mLastError = " Fusion dimension cannot be greater than reference image!"; return false; } if (mFusionReader.IsNull()) mFusionReader = vvImageReader::New(); - std::vector filenames; - filenames.push_back(filename); mFusionReader->SetInputFilenames(filenames); - mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType); + mFusionReader->Update(type); if (mFusionReader->GetLastError().size() == 0) { for ( unsigned int i = 0; i < mSlicers.size(); i++) { mSlicers[i]->SetFusion(mFusionReader->GetOutput()); @@ -307,8 +308,11 @@ bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string compon //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- -bool vvSlicerManager::SetFusionSequence(std::vector filenames,int dim, std::string component, vvImageReader::LoadedImageType type) +//this function is called by vvMainWindow::AddFusionSequence for the primary sequence (CT), while the given files constitute the secondary sequence. +bool vvSlicerManager::SetFusionSequence(std::vector filenames, int dim, std::string component, vvImageReader::LoadedImageType type) { + mFusionSequenceInvolvementCode = 0; + mFusionName = filenames[0]; mFusionComponent = component; @@ -326,7 +330,7 @@ bool vvSlicerManager::SetFusionSequence(std::vector filenames,int d if (mFusionSequenceReader->GetLastError().size() == 0) { for ( unsigned int i = 0; i < mSlicers.size(); i++) { - mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), true); + mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), mFusionSequenceInvolvementCode); } } else { mLastError = mFusionSequenceReader->GetLastError(); @@ -345,7 +349,7 @@ bool vvSlicerManager::SetFusionSequence(std::vector filenames,int d } //adjust the time slider in the overlay panel - mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size()-1; //actually, this is the maximum index... + mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size(); mFusionSequenceFrameIndex = std::max( 0, std::min(mFusionSequenceFrameIndex, mFusionSequenceNbFrames)); return true; @@ -411,8 +415,9 @@ vvSlicer* vvSlicerManager::GetSlicer(int i) //---------------------------------------------------------------------------- void vvSlicerManager::UpdateSlicer(int num, bool state) { - if (mSlicers[num]->GetImage()) + if (mSlicers[num]->GetImage()) { mSlicers[num]->SetDisplayMode(state); + } } //---------------------------------------------------------------------------- @@ -506,7 +511,7 @@ int vvSlicerManager::GetTSlice() //---------------------------------------------------------------------------- void vvSlicerManager::SetTSlice(int slice, bool updateLinkedImages) { - if (!updateLinkedImages) { + if (!updateLinkedImages) { //for fusionSequence, TMax / MaxCurrentTSlice are irrelevant. for ( unsigned int i = 0; i < mSlicers.size(); i++) { mSlicers[i]->SetTSlice(slice, updateLinkedImages); UpdateTSlice(i); @@ -514,7 +519,6 @@ void vvSlicerManager::SetTSlice(int slice, bool updateLinkedImages) return; } - if (slice < 0) slice = 0; else if (slice > mSlicers[0]->GetTMax()) @@ -550,7 +554,7 @@ void vvSlicerManager::SetNextTSlice(int originating_slicer) if (t > mSlicers[0]->GetTMax()) t = 0; //std::cout << "vvSlicerManager::SetNextTSlice" << std::endl; - emit UpdateTSlice(originating_slicer,t); + emit UpdateTSlice(originating_slicer,t, mFusionSequenceInvolvementCode); } //---------------------------------------------------------------------------- @@ -563,7 +567,7 @@ void vvSlicerManager::SetPreviousTSlice(int originating_slicer) if (t < 0) t = mSlicers[0]->GetTMax(); //std::cout << "vvSlicerManager::SetPreviousTSlice" << std::endl; - emit UpdateTSlice(originating_slicer,t); + emit UpdateTSlice(originating_slicer,t, mFusionSequenceInvolvementCode); } //---------------------------------------------------------------------------- @@ -777,7 +781,7 @@ void vvSlicerManager::UpdateLinked(int slicer) z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 && z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) { for (std::list::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) { - if (mFusionSequenceIndexLinkedManager>0) { + if (this->IsInvolvedInFusionSequence()) { //this SlicerManager is involved in fusionSequence => do not synchronize the times emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], -1); } @@ -935,8 +939,8 @@ void vvSlicerManager::Reload() mSlicers[i]->SetImage(mImage); } - //check if this image is involved in a fusion sequence, then the main transform matrix should be updated. - if (mFusionSequenceReader.IsNotNull()) { + //if this image is the primary sequence of a fusion sequence, then the main transform matrix should be updated. + if (this->IsMainSequenceOfFusionSequence()) { SetFusionSequenceMainTransformMatrix( mImage->GetTransform()[0]->GetMatrix() ); } } @@ -956,12 +960,17 @@ void vvSlicerManager::ReloadFusion() //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- +//the secondary sequence is being reloaded. void vvSlicerManager::ReloadFusionSequence() { + // this is to keep the slice thickness, which needs to be artificially increased for visualization + double sp_x, sp_y, sp_z; + this->GetImage()->GetVTKImages()[0]->GetSpacing(sp_x, sp_y, sp_z); + mFusionSequenceReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),vvImageReader::MERGEDWITHTIME); for ( unsigned int i = 0; i < mSlicers.size(); i++) { - mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), true); + mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), 1); mSlicers[i]->Render(); } @@ -972,12 +981,18 @@ void vvSlicerManager::ReloadFusionSequence() } //Update the list of initial transforms - //Warning, the main transform will not be updated on reload......... mFusionSequenceListInitialTransformMatrices.clear(); for (unsigned i=0 ; iAddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() ); } + // also update the slice thickness + for (unsigned i=0 ; iGetImage()->GetTransform().size() ; i++) { + sp_x = this->GetImage()->GetVTKImages()[i]->GetSpacing()[0]; + sp_y = this->GetImage()->GetVTKImages()[i]->GetSpacing()[1]; + this->GetImage()->GetVTKImages()[i]->SetSpacing( sp_x, sp_y, sp_z); + } + } //---------------------------------------------------------------------------- @@ -1049,7 +1064,6 @@ void vvSlicerManager::RemoveActors() //---------------------------------------------------------------------------- void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer) { -//TODO: this is probably here that I shall prevent the overlayPanel to disappear when the mouse goes over the linked sequence! // int view = mSlicers[slicer]->GetSliceOrientation(); // int slice = mSlicers[slicer]->GetSlice(); double x = mSlicers[slicer]->GetCursorPosition()[0]; @@ -1113,7 +1127,9 @@ void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer) double Zover = (z - fusion->GetOrigin()[2]) / fusion->GetSpacing()[2]; valueFus = this->GetScalarComponentAsDouble(fusion, Xover, Yover, Zover); } - else if (mFusionSequenceIndexLinkedManager>=0) { + else if (this->IsInvolvedInFusionSequence()) { + //if the cursor moves over the 'independent' version of the secondary sequence + //do not update the panel, just keep it as it is. displayFus = 1; valueFus = std::numeric_limits::quiet_NaN(); } @@ -1171,9 +1187,9 @@ void vvSlicerManager::UpdateSlice(int slicer) void vvSlicerManager::UpdateTSlice(int slicer) { int slice = mSlicers[slicer]->GetSlice(); + int tslice = mSlicers[slicer]->GetMaxCurrentTSlice(); - - if (mFusionSequenceIndexLinkedManager>=0) tslice = mSlicers[slicer]->GetTSlice(); + //if (this->IsInvolvedInFusionSequence()) tslice = mSlicers[slicer]->GetTSlice(); //actually, this is handled by the Slicer if (mPreviousSlice[slicer] == slice) { if (mPreviousTSlice[slicer] == tslice) { @@ -1184,9 +1200,7 @@ void vvSlicerManager::UpdateTSlice(int slicer) mPreviousSlice[slicer] = slice; mPreviousTSlice[slicer] = tslice; - if (mFusionSequenceIndexLinkedManager>=0) return; - - emit UpdateTSlice(slicer, tslice); + emit UpdateTSlice(slicer, tslice, mFusionSequenceInvolvementCode); } //---------------------------------------------------------------------------- @@ -1239,41 +1253,46 @@ void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset) //---------------------------------------------------------------------------- void vvSlicerManager::SetPreset(int preset) { + //vtkLookupTable* LUT = static_cast(mSlicers[0]->GetWindowLevel()->GetLookupTable()); double window = mSlicers[0]->GetColorWindow(); double level = mSlicers[0]->GetColorLevel(); std::string component_type=mImage->GetScalarTypeAsITKString(); switch (preset) { - case 0: + case WL_AUTO: double range[2]; mImage->GetScalarRange(range); window = range[1] - range[0]; level = (range[1] + range[0])* 0.5; break; - case 1: + case WL_HOUNSFIELD: window = 2000; level = 0; break; - case 2: + case WL_SOFTTISSUE: window = 400; level = 20; break; - case 3: // lungs (same as FOCAL) + case WL_LUNGS: // lungs (same as FOCAL) window = 1700; level = -300; break; - case 4: + case WL_BONES: window = 1000; level = 500; break; - case 5: + case WL_HEAD: + window = 200; + level = 70; + break; + case WL_BINARY: window = 1; level = 0.5; break; - case 6: + case WL_USER: break; - case 7: + case WL_VENTILATION: window=1.; level=0.; break; @@ -1323,7 +1342,7 @@ void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlK this->mSlicers[slicer]->GetConcatenatedTransform()); this->SetColorWindow(max-min); this->SetColorLevel(0.5*(min+max)); - this->SetPreset(6); + this->SetPreset(WL_USER); } this->Render(); this->UpdateWindowLevel(); @@ -1392,18 +1411,22 @@ void vvSlicerManager::SetColorMap(int colormap) LUT->Build(); } vtkWindowLevelLookupTable* fusLUT = NULL; + + //FUSION / FUSION SEQUENCE if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) { - fusLUT = vtkWindowLevelLookupTable::New(); + fusLUT = vtkWindowLevelLookupTable::New(); double fusRange [2]; fusRange[0] = mFusionLevel - mFusionWindow/2; fusRange[1] = mFusionLevel + mFusionWindow/2; - //check whether it is actually a fusionSequence or a fusion, before invoking mFusionReader... - double* frange; - if (mFusionReader.IsNull()) frange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange(); - else frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange(); + //check whether it is actually a fusionSequence or a fusion, before invoking mFusionReader... + double* frange; + if (this->IsInvolvedInFusionSequence()) + frange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange(); + else + frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange(); - fusLUT->SetTableRange(frange); + fusLUT->SetTableRange(frange); fusLUT->SetValueRange(1,1); fusLUT->SetSaturationRange(1,1); fusLUT->SetAlphaRange(1, 1); @@ -1425,10 +1448,10 @@ void vvSlicerManager::SetColorMap(int colormap) fusLUT->SetValueRange(0,1); fusLUT->SetSaturationRange(0,0); } - + fusLUT->ForceBuild(); double v[4]; - + // set color table transparency //double alpha_range=(double)mFusionThresOpacity/10; double range_end = fusRange[0] + (double)mFusionThresOpacity*(fusRange[1] - fusRange[0])/100; @@ -1444,7 +1467,7 @@ void vvSlicerManager::SetColorMap(int colormap) } } for ( unsigned int i = 0; i < mSlicers.size(); i++) { - + if (mSlicers[i]->GetOverlay()) { vtkLookupTable* supLUT = vtkLookupTable::New(); supLUT->SetTableRange(range[0],range[1]); @@ -1467,7 +1490,7 @@ void vvSlicerManager::SetColorMap(int colormap) } else { mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT); } - + if (mSlicers[i]->GetFusion()) { mSlicers[i]->ShowFusionLegend(mFusionShowLegend); mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);