#include <cassert>
//--------------------------------------------------------------------
-vvImage::vvImage():mTransform(vtkSmartPointer<vtkTransform>::New())
+vvImage::vvImage()
{
Init();
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
-vtkSmartPointer<vtkTransform> vvImage::GetTransform()
+const std::vector< vtkSmartPointer<vtkTransform> >& vvImage::GetTransform()
{
return this->mTransform;
}
bool IsTimeSequence() const;
bool IsScalarTypeInteger();
bool IsScalarTypeInteger(int t);
- vtkSmartPointer<vtkTransform> GetTransform();
+ const std::vector< vtkSmartPointer<vtkTransform> >& GetTransform();
void SetTimeSpacing(double s) { mTimeSpacing = s; }
void SetTimeOrigin(double o) { mTimeOrigin = o; }
bool HaveSameSizeAndSpacingThan(vvImage * other);
~vvImage();
std::vector< ConverterPointer > mItkToVtkConverters;
- std::vector<vtkImageData*> mVtkImages;
- vtkSmartPointer<vtkTransform> mTransform;
+ std::vector< vtkImageData* > mVtkImages;
+ std::vector< vtkSmartPointer<vtkTransform> > mTransform;
double mTimeOrigin;
double mTimeSpacing;
// GetDirection provides the forward transform, vtkImageReslice wants the inverse
matrix->Invert();
- mTransform->SetMatrix(matrix);
+ mTransform.push_back(vtkSmartPointer<vtkTransform>::New());
+ mTransform.back()->SetMatrix(matrix);
}
//--------------------------------------------------------------------
//------------------------------------------------------------------------------
//Read transformation in NKI format (Xdr, transposed, cm)
-void vvImageReader::ReadNkiImageTransform()
-{
- bool bRead=false;
- std::string filename = mInputFilenames[0]+".MACHINEORIENTATION";
- if(itksys::SystemTools::FileExists(filename.c_str())){
- typedef itk::ImageFileReader< itk::Image< double, 2 > > MatrixReaderType;
- MatrixReaderType::Pointer readerTransfo = MatrixReaderType::New();
- readerTransfo->SetFileName(filename);
- try {
- bRead = true;
- readerTransfo->Update();
- } catch( itk::ExceptionObject & err ) {
- bRead=false;
- std::cerr << "Cannot read " << filename << std::endl
- << "The error is: " << err << std::endl;
- }
-
- if (bRead) {
- //Transpose matrix (NKI format)
- for(int j=0; j<4; j++)
- for(int i=0; i<4; i++)
- mImage->GetTransform()->GetMatrix()->SetElement(j,i,readerTransfo->GetOutput()->GetBufferPointer()[4*i+j]);
-
- //From cm to mm
- for(int i=0; i<3; i++)
- mImage->GetTransform()->GetMatrix()->SetElement(i,3,10*mImage->GetTransform()->GetMatrix()->GetElement(i,3));
-
- mImage->GetTransform()->Inverse();
- }
- }
-}
+//void vvImageReader::ReadNkiImageTransform()
+//{
+// bool bRead=false;
+// std::string filename = mInputFilenames[0]+".MACHINEORIENTATION";
+// if(itksys::SystemTools::FileExists(filename.c_str())){
+// typedef itk::ImageFileReader< itk::Image< double, 2 > > MatrixReaderType;
+// MatrixReaderType::Pointer readerTransfo = MatrixReaderType::New();
+// readerTransfo->SetFileName(filename);
+// try {
+// bRead = true;
+// readerTransfo->Update();
+// } catch( itk::ExceptionObject & err ) {
+// bRead=false;
+// std::cerr << "Cannot read " << filename << std::endl
+// << "The error is: " << err << std::endl;
+// }
+
+// if (bRead) {
+// //Transpose matrix (NKI format)
+// for(int j=0; j<4; j++)
+// for(int i=0; i<4; i++)
+// mImage->GetTransform()->GetMatrix()->SetElement(j,i,readerTransfo->GetOutput()->GetBufferPointer()[4*i+j]);
+
+// //From cm to mm
+// for(int i=0; i<3; i++)
+// mImage->GetTransform()->GetMatrix()->SetElement(i,3,10*mImage->GetTransform()->GetMatrix()->GetElement(i,3));
+
+// mImage->GetTransform()->Inverse();
+// }
+// }
+//}
//------------------------------------------------------------------------------
vtkGenericWarningMacro("Matrix in " << filename.c_str() << " cannot be inverted (determinant = 0)");
}
- mImage->GetTransform()->PostMultiply();
- mImage->GetTransform()->Concatenate(matrix);
- mImage->GetTransform()->Update();
+ // TODO SR and BP: check on the list of transforms and not the first only
+ mImage->GetTransform()[0]->PostMultiply();
+ mImage->GetTransform()[0]->Concatenate(matrix);
+ mImage->GetTransform()[0]->Update();
}
}
//------------------------------------------------------------------------------
std::string mInputPixelType;
//====================================================================
- void ReadNkiImageTransform();
+// void ReadNkiImageTransform();
void ReadMatImageTransform();
private:
vvImageReader();
0.,0.,1.,0.,
0.,-1.,0.,0.,
0.,0.,0.,1.};
+ // TODO SR and BP: check on the list of transforms and not the first only
int i;
- for(i=0; i<16 && m[i]==mImage->GetTransform()->GetMatrix()->GetElement(i%4, i/4); i++);
+ for(i=0; i<16 && m[i]==mImage->GetTransform()[0]->GetMatrix()->GetElement(i%4, i/4); i++);
if(i==16) {
itkWarningMacro(<< "Analyze image file format detected with unknown orientation. "
<< "Forcing identity orientation, use other file format if not ok.");
- mImage->GetTransform()->Identity();
+ mImage->GetTransform()[0]->Identity();
}
}
}
0.,-1.,0.,0.,
0.,0.,0.,1.};
int i;
- for (i = 0; i < 16 && m[i] == mImage->GetTransform()->GetMatrix()->GetElement(i % 4, i / 4); i++)
+ for (i = 0; i < 16 && m[i] == mImage->GetTransform()[0]->GetMatrix()->GetElement(i % 4, i / 4); i++)
;
if (i == 16)
{
itkWarningMacro(<< "Analyze image file format detected with unknown orientation. "
<< "Forcing identity orientation, use other file format if not ok.");
- mImage->GetTransform()->Identity();
+ mImage->GetTransform()[0]->Identity();
}
}
}
itk::Matrix<double, 4, 4> trans;
for(int i=0; i<4; i++)
for(int j=0; j<4; j++)
- trans[i][j] = mImage->GetTransform()->GetMatrix()->GetElement(i,j);
+ // TODO SR and BP: check on the list of transforms and not the first only
+ trans[i][j] = mImage->GetTransform()[0]->GetMatrix()->GetElement(i,j);
trans = trans.GetInverse();
// Direction
this,SLOT(UpdateSlice(int,int)));
connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
this,SLOT(UpdateTSlice(int, int)));
+ connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
+ this,SLOT(ImageInfoChanged()));
connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
this,SLOT(UpdateSliceRange(int,int,int,int,int)));
connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
infoPanel->setOrigin(GetVectorDoubleAsString(origin));
infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
- transformation = imageSelected->GetTransform()->GetMatrix();
+ transformation = imageSelected->GetTransform()[mSlicerManagers[index]->GetTSlice()]->GetMatrix();
infoPanel->setTransformation(Get4x4MatrixDoubleAsString(transformation));
landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
{
if (DataTree->selectedItems().size()) {
int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
- mSlicerManagers[index]->SetSlicingPreset(slicingPresetComboBox->currentIndex());
+ mSlicerManagers[index]->SetSlicingPreset(vvSlicerManager::SlicingPresetType(slicingPresetComboBox->currentIndex()));
}
}
//------------------------------------------------------------------------------
bool bId = true;
for(int i=0; i<4; i++)
for(int j=0; j<4; j++) {
- double elt = mSlicerManagers[index]->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j);
+ // TODO SR and BP: check on the list of transforms and not the first only
+ double elt = mSlicerManagers[index]->GetImage()->GetTransform()[0]->GetMatrix()->GetElement(i,j);
if(i==j && elt!=1.)
bId = false;
if(i!=j && elt!=0.)
this,SLOT(UpdateSlice(int,int)));
connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
this,SLOT(UpdateTSlice(int, int)));
+ connect(mSlicerManagers.back(), SIGNAL(UpdateTSlice(int, int)),
+ this,SLOT(ImageInfoChanged()));
connect(mSlicerManagers.back(), SIGNAL(UpdateSliceRange(int,int,int,int,int)),
this,SLOT(UpdateSliceRange(int,int,int,int,int)));
connect(mSlicerManagers.back(), SIGNAL(UpdateLinkManager(std::string,int,double,double,double,int)),
}
mConcatenatedTransform->Identity();
- mConcatenatedTransform->Concatenate(mImage->GetTransform());
+ mConcatenatedTransform->Concatenate(mImage->GetTransform()[0]);
mConcatenatedTransform->Concatenate(mSlicingTransform);
mImageReslice->SetResliceTransform(mConcatenatedTransform);
mImageReslice->SetInput(0, mImage->GetFirstVTKImageData());
mOverlayReslice->AutoCropOutputOn();
mOverlayReslice->SetBackgroundColor(-1000,-1000,-1000,1);
}
- mOverlayReslice->SetResliceTransform(mOverlay->GetTransform());
+ mOverlayReslice->SetResliceTransform(mOverlay->GetTransform()[0]);
mOverlayReslice->SetInput(0, mOverlay->GetFirstVTKImageData());
if (!mOverlayMapper)
mFusionReslice->AutoCropOutputOn();
mFusionReslice->SetBackgroundColor(-1000,-1000,-1000,1);
}
- mFusionReslice->SetResliceTransform(mFusion->GetTransform());
+ mFusionReslice->SetResliceTransform(mFusion->GetTransform()[0]);
mFusionReslice->SetInput(0, mFusion->GetFirstVTKImageData());
if (!mFusionMapper)
else if ((unsigned int)t >= mImage->GetVTKImages().size())
t = mImage->GetVTKImages().size() -1;
+ // Update transform
+ mConcatenatedTransform->Identity();
+ mConcatenatedTransform->Concatenate(mImage->GetTransform()[t]);
+ mConcatenatedTransform->Concatenate(mSlicingTransform);
+
+ // Update image data
mCurrentTSlice = t;
mImageReslice->SetInput( mImage->GetVTKImages()[mCurrentTSlice] );
if (mVF && mVFActor->GetVisibility()) {
mPreviousSlice.resize(numberOfSlicers);
mPreviousTSlice.resize(numberOfSlicers);
- mSlicingPreset = 0;
+ mSlicingPreset = WORLD_SLICING;
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+int vvSlicerManager::GetTSlice()
+{
+ return mSlicers[0]->GetTSlice();
+}
+//----------------------------------------------------------------------------
+
//----------------------------------------------------------------------------
void vvSlicerManager::SetTSlice(int slice)
{
for ( unsigned int i = 0; i < mSlicers.size(); i++) {
if (slice != mSlicers[i]->GetTSlice()) {
mSlicers[i]->SetTSlice(slice);
- UpdateTSlice(i);
+ UpdateTSlice(i);
}
}
}
if (mSlicers[slicer]->GetTSlice() == tslice) return;
+ if(mSlicingPreset==VOXELS_SLICING) {
+ vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
+ mImage->GetTransform()[tslice]->GetInverse(imageTransformInverse);
+ this->GetSlicer(slicer)->GetSlicingTransform()->SetMatrix(imageTransformInverse);
+ imageTransformInverse->Delete();
+ }
+
mSlicers[slicer]->SetTSlice(tslice);
UpdateTSlice(slicer);
}
void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)
{
if(actorType == "image")
- this->GetImage()->GetTransform()->Identity();
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
+ this->GetImage()->GetTransform()[i]->Identity();
else if(actorType == "overlay")
- this->GetSlicer(0)->GetOverlay()->GetTransform()->Identity();
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
+ this->GetSlicer(0)->GetOverlay()->GetTransform()[i]->Identity();
else if(actorType == "fusion")
- this->GetSlicer(0)->GetFusion()->GetTransform()->Identity();
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
+ this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
else if(actorType == "vf")
- this->GetVF()->GetTransform()->Identity();
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
+ this->GetVF()->GetTransform()[i]->Identity();
else
return;
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
-void vvSlicerManager::SetSlicingPreset(int preset)
+void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset)
{
if(mSlicingPreset==preset)
return;
- vtkMatrix4x4 *mImageTransformInverse = vtkMatrix4x4::New();
- mImage->GetTransform()->GetInverse(mImageTransformInverse);
+ vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
+ mImage->GetTransform()[this->GetTSlice()]->GetInverse(imageTransformInverse);
for(int i=0; i< this->GetNumberOfSlicers(); i++){
switch(preset)
{
- case 0: // World
+ case WORLD_SLICING:
this->GetSlicer(i)->GetSlicingTransform()->Identity();
break;
- case 1: // Voxels
- this->GetSlicer(i)->GetSlicingTransform()->SetMatrix(mImageTransformInverse);
+ case VOXELS_SLICING:
+ this->GetSlicer(i)->GetSlicingTransform()->SetMatrix(imageTransformInverse);
break;
default:
- mImageTransformInverse->Delete();
+ imageTransformInverse->Delete();
return;
}
this->GetSlicer(i)->ForceUpdateDisplayExtent();
this->GetSlicer(i)->Render();
}
- mImageTransformInverse->Delete();
+ imageTransformInverse->Delete();
mSlicingPreset = preset;
}
void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlKey)
{
double min, max;
- int t = this->mSlicers[slicer]->GetTSlice();
+ int t = this->GetTSlice();
if(bCtrlKey && this->mSlicers[slicer]->GetFusion()) {
this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
this->mSlicers[slicer]->GetFusion()->GetVTKImages()[t],
- this->mSlicers[slicer]->GetFusion()->GetTransform());
+ this->mSlicers[slicer]->GetFusion()->GetTransform()[t]);
this->SetFusionWindow(max-min);
this->SetFusionLevel(0.5*(min+max));
this->SetColorMap(mColorMap);
else if(bCtrlKey && this->mSlicers[slicer]->GetOverlay()) {
this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
this->mSlicers[slicer]->GetOverlay()->GetVTKImages()[t],
- this->mSlicers[slicer]->GetOverlay()->GetTransform());
+ this->mSlicers[slicer]->GetOverlay()->GetTransform()[t]);
if(this->mSlicers[slicer]->GetLinkOverlayWindowLevel()){
this->SetColorWindow(max-min);
this->SetColorLevel(0.5*(min+max));
Q_OBJECT
public:
+ typedef enum {WORLD_SLICING, VOXELS_SLICING} SlicingPresetType;
vvSlicerManager(int numberOfSlicers);
~vvSlicerManager();
void SetFilename(std::string f, int number=0);
void SetSliceOrientation(int slicer, int orientation);
+ int GetTSlice();
void SetTSlice(int slice);
void SetNextTSlice(int originating_slicer);
void SetPreviousTSlice(int originating_slicer);
int GetPreset() {
return mPreset;
}
- int GetSlicingPreset() {
+ SlicingPresetType GetSlicingPreset() {
return mSlicingPreset;
}
int GetOverlayColor() const {
void UpdateSlice(int slicer);
void UpdateTSlice(int slicer);
void UpdateSliceRange(int slicer);
- void SetSlicingPreset(int preset);
+ void SetSlicingPreset(SlicingPresetType preset);
vvLandmarks *GetLandmarks();
void AddLandmark(float x,float y,float z,float t);
bool mFusionShowLegend;
int mPreset;
- int mSlicingPreset;
+ SlicingPresetType mSlicingPreset;
vvImageReader::LoadedImageType mType;
std::string mVFComponent;
std::string mOverlayComponent;
//backup original matrix
for(int j=0; j<4; j++)
for(int i=0; i<4; i++)
- mInitialMatrix->SetElement(i,j, mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j));
+ // TODO SR and BP: check on the list of transforms and not the first only
+ mInitialMatrix->SetElement(i,j, mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix()->GetElement(i,j));
QString origTransformString = dynamic_cast<vvMainWindow*>(mMainWindow)->Get4x4MatrixDoubleAsString(mInitialMatrix);
transformationLabel->setText(origTransformString);
SetTransform(mInitialMatrix);
}
// Compute transform and set
- vtkSmartPointer<vtkTransform> transform_final=mInput->GetImage()->GetTransform();
+ // TODO SR and BP: check on the list of transforms and not the first only
+ vtkSmartPointer<vtkTransform> transform_final=mInput->GetImage()->GetTransform()[0];
transform_final->Identity();
transform_final->PostMultiply();
QFile file(filename);
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
- vtkMatrix4x4* matrix = mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix();
+ // TODO SR and BP: check on the list of transforms and not the first only
+ vtkMatrix4x4* matrix = mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix();
QString matrixStr = dynamic_cast<vvMainWindow*>(mMainWindow)->Get4x4MatrixDoubleAsString(matrix,16);
QTextStream out(&file);
out << matrixStr;
//------------------------------------------------------------------------------
void vvToolRigidReg::ChangeOfRotationCenter()
{
- SetTransform(mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix());
+ // TODO SR and BP: check on the list of transforms and not the first only
+ SetTransform(mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix());
}
//------------------------------------------------------------------------------
void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix)
{
vtkSmartPointer<vtkTransform> transform=vtkSmartPointer<vtkTransform>::New();
- mCurrentSlicerManager->GetImage()->GetTransform()->SetMatrix(matrix);
+ // TODO SR and BP: check on the list of transforms and not the first only
+ mCurrentSlicerManager->GetImage()->GetTransform()[0]->SetMatrix(matrix);
transform->Update();
Render();
dynamic_cast<vvMainWindow*>(mMainWindow)->ImageInfoChanged();