Commit 1cc978f2 authored by Maxime Calka's avatar Maxime Calka

Modify CamiTK code to arbitrary_slice

parent 0a121c22
......@@ -75,7 +75,6 @@ void ApplicationActionExtension::init() {
registerNewAction(ShowSagittalViewer);
registerNewAction(Show3DViewer);
registerNewAction(ShowAllViewers);
// disabled as long as this viewer is not working
// registerNewAction(ShowArbitraryViewer);
registerNewAction(ShowArbitraryViewer);
registerNewAction(LoggerParameters);
}
......@@ -66,9 +66,7 @@ AnglesSetterWidget::AnglesSetterWidget(QWidget* parent): QWidget(parent) {
}
// -------------------- destructor --------------------
AnglesSetterWidget::~AnglesSetterWidget() {
;
}
AnglesSetterWidget::~AnglesSetterWidget() {}
// -------------------- updateSlice --------------------
void AnglesSetterWidget::updateSlice(int sliceNumber) {
......
......@@ -690,6 +690,8 @@ public:
delegate0(mySlice, updatePickPlane)
delegate0(mySlice, updateReslice)
delegate1(mySlice, setSlice, int)
delegate3(mySlice, setSlice, double, double, double)
......@@ -700,6 +702,9 @@ public:
delegate1(mySlice, setImageWorldTransform, vtkSmartPointer<vtkTransform>)
delegate1(mySlice, setReslicerTransform, vtkSmartPointer<vtkTransform>)
/// see Component.cpp
int getNumberOfSlices() const override;
......
......@@ -85,6 +85,10 @@ public:
/** Return the vtkActor used to pick pixels in the slices. */
virtual vtkSmartPointer<vtkActor> getPixelActor() = 0;
virtual void updateReslice() = 0;
virtual void setReslicerTransform(vtkSmartPointer<vtkTransform>) = 0;
/** Return 2D Axes at the proper slice origin */
// virtual vtkSmartPointer<vtkAxesActor> get2DAxesActor() = 0;
......
......@@ -102,11 +102,18 @@ void Slice::init() {
imgToMapFilter = vtkSmartPointer<vtkImageMapToColors>::New();
image3DActor = vtkSmartPointer<vtkImageActor>::New();
image2DActor = vtkSmartPointer<vtkImageActor>::New();
image2DChangeInfo = vtkSmartPointer<vtkImageChangeInformation>::New();
image2DReslicer = vtkSmartPointer<vtkImageReslice>::New();
transformReslicer = vtkSmartPointer<vtkTransform>::New();
resliceTransform = vtkSmartPointer<vtkTransform>::New();
pickPlane = vtkSmartPointer<vtkPlaneSource>::New();
pickPlaneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
pickPlaneActor = vtkSmartPointer<vtkActor>::New();
transformReslicer->Identity();
resliceTransform->Identity();
}
// -------------------- getImageData --------------------
......@@ -158,6 +165,15 @@ void Slice::initActors() {
imgToMapFilter->SetLookupTable(lut);
}
image2DChangeInfo->SetInputData(imgToMapFilter->GetOutput());
image2DChangeInfo->SetOutputOrigin(0.0, 0.0, 0.0);
image2DReslicer->SetInputConnection(image2DChangeInfo->GetOutputPort());
image2DReslicer->SetInformationInput(imgToMapFilter->GetOutput());
image2DReslicer->AutoCropOutputOn();
image2DReslicer->SetOutputOriginToDefault();
image2DReslicer->SetOutputExtentToDefault();
image2DReslicer->SetOutputSpacingToDefault();
/* 3D Actor case: directly pluged to the output of imgToMapFilter */
image3DActor->GetMapper()->SetInputConnection(imgToMapFilter->GetOutputPort());
image3DActor->InterpolateOn();
......@@ -176,6 +192,10 @@ void Slice::initActors() {
switch (sliceOrientation) {
default:
break;
case ARBITRARY:
pickPlaneActor->GetProperty()->SetColor(1.0, 1.0, 0.0);
pickPlaneActor->GetProperty()->SetEdgeColor(1.0, 1.0, 1.0);
break;
case AXIAL:
pickPlaneActor->GetProperty()->SetColor(0.0, 0.0, 1.0);
pickPlaneActor->GetProperty()->SetEdgeColor(0.0, 0.0, 1.0);
......@@ -281,6 +301,9 @@ int Slice::getNumberOfSlices() const {
switch (sliceOrientation) {
default:
break;
case ARBITRARY:
nbSlices = max(max(extent[1] - extent[0], extent[3] - extent[2]), extent[5] - extent[4]) + 1;
break;
case AXIAL:
case AXIAL_NEURO:
nbSlices = extent[5] - extent[4] + 1;
......@@ -317,31 +340,34 @@ void Slice::setSlice(int s) {
switch (sliceOrientation) {
default:
break;
case ARBITRARY:
updateReslice();
break;
case AXIAL:
image3DActor->SetDisplayExtent(
extent[0], extent[1],
extent[2], extent[3],
s, s);
currentSliceIndex, currentSliceIndex);
image2DActor->SetDisplayExtent(
extent[0], extent[1],
extent[2], extent[3],
s, s);
currentSliceIndex, currentSliceIndex);
break;
case CORONAL:
image3DActor->SetDisplayExtent(
extent[0], extent[1],
s, s,
currentSliceIndex, currentSliceIndex,
extent[4], extent[5]);
image2DActor->SetDisplayExtent(
extent[0], extent[1],
s, s,
currentSliceIndex, currentSliceIndex,
extent[4], extent[5]);
break;
case SAGITTAL:
image3DActor->SetDisplayExtent(
s, s,
currentSliceIndex, currentSliceIndex,
extent[2], extent[3],
extent[4], extent[5]);
image2DActor->SetDisplayExtent(
......@@ -394,6 +420,44 @@ void Slice::setPixelRealPosition(double x, double y, double z) {
updatePixelActorPosition(x, y, z);
}
void Slice::setReslicerTransform(vtkSmartPointer<vtkTransform> t) {
resliceTransform = t;
}
void Slice::updateReslice() {
if (sliceOrientation == ARBITRARY) {
double wxyz[4];
transformReslicer->Identity();
transformReslicer->Translate(originalDimensions[0] / 2, originalDimensions[1] / 2, originalDimensions[2] / 2);
resliceTransform->GetOrientationWXYZ(wxyz);
transformReslicer->RotateWXYZ(wxyz[0], wxyz[1], wxyz[2], wxyz[3]);
transformReslicer->Translate(-originalDimensions[0] / 2, -originalDimensions[1] / 2, -originalDimensions[2] / 2);
transformReslicer->Translate(0.0, 0.0, currentSliceIndex);
image2DReslicer->SetResliceAxes(transformReslicer->GetMatrix());
image2DReslicer->Update();
image3DActor->SetUserMatrix(resliceTransform->GetMatrix());
image3DActor->SetInputData(image2DReslicer->GetOutput());
image3DActor->Update();
}
updateLocalTransformation();
updatePickPlane();
}
void Slice::updateLocalTransformation() {
image2DReslicer->SetOutputDimensionality(3);
image2DReslicer->UpdateInformation();
image2DReslicer->SetOutputDimensionality(2);
image2DReslicer->UpdateInformation();
}
// -------------------- initPixelActor --------------------
void Slice::initPixelActor() {
double xMin = 0.0;
......
......@@ -211,6 +211,12 @@ public:
/// move the pixel selection green indicator (pixelActor) to the given real position
void setPixelRealPosition(double, double, double) override;
void updateReslice() override;
void setReslicerTransform(vtkSmartPointer<vtkTransform>) override;
void updateLocalTransformation();
/// get the current image data
vtkSmartPointer<vtkImageData> getImageData() const override;
......@@ -283,6 +289,9 @@ protected:
/** Real size (originalDimension * originalSpacing in x, y and z) of the original image */
double originalSize[3];
vtkSmartPointer<vtkTransform> transformReslicer;
vtkSmartPointer<vtkTransform> resliceTransform;
/// To be able to extract a slice
vtkSmartPointer<vtkImageMapToColors> imgToMapFilter;
......@@ -293,6 +302,10 @@ protected:
vtkSmartPointer<vtkImageActor> image2DActor;
/**@} */
vtkSmartPointer<vtkImageChangeInformation> image2DChangeInfo;
vtkSmartPointer<vtkImageReslice> image2DReslicer;
/**@} */
/**@name Uses for picking */
......
......@@ -545,7 +545,7 @@ void ImageComponent::buildImageComponents() {
if (!arbitrarySlices) {
// TODO implement arbitrary slice orientation
arbitrarySlices = nullptr; // new SingleImageComponent(this, Slice::ARBITRARY, "Arbitrary view", lut);
arbitrarySlices = new SingleImageComponent(this, Slice::ARBITRARY, "Arbitrary view", lut);
}
if (volumeRenderingChild) {
......
......@@ -101,7 +101,7 @@ void SingleImageComponent::initRepresentation() {
break;
case Slice::ARBITRARY:
setVisibility(InteractiveViewer::getArbitraryViewer(), true);
mySlice->setReslicerTransform(this->getTransform());
mySlice->setReslicerTransform(getTransform());
break;
}
}
......
......@@ -150,9 +150,9 @@ InteractiveViewer* InteractiveViewer::getViewer(QString name) {
}
else
if (name == defaultNames[4]) { // Arbitrary Viewer
// singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN );
singletonInstance->toggleOrientationDecorations(false);
// singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN );
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
}
......
......@@ -185,9 +185,8 @@ QMenu* MedicalImageViewer::getMenu() {
layoutMenu->addAction(Application::getAction("Show Sagittal Viewer")->getQAction());
Application::getAction("Show Coronal Viewer")->getQAction()->setActionGroup(viewerGroup);
layoutMenu->addAction(Application::getAction("Show Coronal Viewer")->getQAction());
// disabled the arbitrary slice as long as it does not work correctly
// Application::getAction("Show Arbitrary Viewer")->getQAction()->setActionGroup(viewerGroup);
// layoutMenu->addAction(Application::getAction("Show Arbitrary Viewer")->getQAction());
Application::getAction("Show Arbitrary Viewer")->getQAction()->setActionGroup(viewerGroup);
layoutMenu->addAction(Application::getAction("Show Arbitrary Viewer")->getQAction());
for (unsigned int i = 0; viewerVisibility[i] != VIEWER_ALL; i++) {
// and viewer menu as submenu
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment