- void ImagePlanes::Process()
- {
- if (bbGetInputIn()!=0)
- {
-
- if ( bbGetInputStatus("In") != bbtk::UPTODATE )
- {
- // Input image has changed : reinitialize planes
- image = bbGetInputIn();
-
- int xMin, xMax, yMin, yMax, zMin, zMax;
- bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
-
- // Initial values : center of the volume (in real world, not in pixels!)
- double xSpacing, ySpacing, zSpacing;
- bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
-
- bbGetOutputPlaneX()->SetInput(bbGetInputIn());
- bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
- bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
-
-
-// bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing );
-// bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing);
-// bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing);
-
-
- bbGetOutputPlaneY()->SetInput(bbGetInputIn());
- bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
- bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
-
- bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
- bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
- bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
-
- if (bbGetInputWindowLevel()[0]!=0)
- {
- bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
- bbGetInputWindowLevel()[1]);
- }
- else
- {
- double *range = image->GetScalarRange();
- bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
- 0.5*(range[1]+range[0]));
- }
- }
-
- // UPDATE DES SORTIES
- bbGetOutputPlaneX()->GetResliceOutput()->Update();
- bbGetOutputPlaneY()->GetResliceOutput()->Update();
- bbGetOutputPlaneZ()->GetResliceOutput()->Update();
- }
- }
+void ImagePlanes::Process()
+{
+ if (bbGetInputIn()!=0)
+ {
+
+ if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){
+ // Input image has changed : reinitialize planes
+ image = bbGetInputIn();
+
+ int xMin, xMax, yMin, yMax, zMin, zMax;
+ bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
+
+ // Initial values : center of the volume (in real world, not in pixels!)
+ double xSpacing, ySpacing, zSpacing;
+ bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
+
+ bbGetOutputPlaneX()->SetInput(bbGetInputIn());
+ bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();
+ bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
+
+
+ // bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing );
+ // bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing);
+ // bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing);
+
+
+ bbGetOutputPlaneY()->SetInput(bbGetInputIn());
+ bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
+ bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
+
+ bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
+ bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
+ bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
+
+ if (bbGetInputWindowLevel()[0]!=0)
+ {
+ bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
+ bbGetInputWindowLevel()[1]);
+ }
+ else
+ {
+ double *range = image->GetScalarRange();
+ bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
+ 0.5*(range[1]+range[0]));
+ }
+
+ }
+ // UPDATE DES SORTIES
+ bbGetOutputPlaneX()->GetResliceOutput()->Update();
+ bbGetOutputPlaneY()->GetResliceOutput()->Update();
+ bbGetOutputPlaneZ()->GetResliceOutput()->Update();
+
+ std::vector<int> pointsx = bbGetInputPointsX();
+ std::vector<int> pointsy = bbGetInputPointsY();
+ std::vector<int> pointsz = bbGetInputPointsZ();
+
+ std::cout<<pointsx.size()<<pointsy.size()<<pointsz.size()<<std::endl;
+
+ if(pointsx.size()==pointsy.size() && pointsx.size()==pointsz.size()&&pointsx.size()>=3){
+ vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts();
+ //vtkPlaneWidget* plane3pts = (vtkPlaneWidget*)bbGetOutputPlane3Pts();
+
+ plane3pts->SetInput(bbGetInputIn());
+
+ //xSpacing = ySpacing = zSpacing = 1;
+ double xSpacing, ySpacing, zSpacing;
+ bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
+
+ plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing);
+ plane3pts->SetPoint1(pointsx[1]*xSpacing,pointsy[1]*ySpacing,pointsz[1]*zSpacing);
+ //plane3pts->SetPoint1((pointsx[1]-pointsx[0])*xSpacing,(pointsy[1]-pointsy[0])*ySpacing,(pointsz[1]-pointsz[0])*zSpacing);
+ plane3pts->SetPoint2(pointsx[2]*xSpacing,pointsy[2]*ySpacing,pointsz[2]*zSpacing);
+ //plane3pts->SetPoint2((pointsx[2]-pointsx[0])*xSpacing,(pointsy[2]-pointsy[0])*ySpacing,(pointsz[2]-pointsz[0])*zSpacing);
+ plane3pts->GetResliceOutput()->Update();
+
+
+
+ if (_imageReslicer==NULL){
+ _imageReslicer = vtkImageReslice::New();
+ _imageReslicer->SetOutputDimensionality(2);
+ _imageReslicer->SetInterpolationModeToLinear();
+ }
+
+ _imageReslicer->SetInput( bbGetInputIn() );
+ _imageReslicer->SetInformationInput(bbGetInputIn());
+
+ double origin[3];
+ origin[0] = pointsx[0];
+ origin[1] = pointsy[0];
+ origin[2] = pointsz[0];
+
+ double point1[3];
+ point1[0] = pointsx[1];
+ point1[1] = pointsy[1];
+ point1[2] = pointsz[1];
+ double point2[3];
+ point2[0]= pointsx[2];
+ point2[1]= pointsy[2];
+ point2[2]= pointsz[2];
+
+ double* vect1= getNormal(makeVector(origin, point1));
+ double* vect2= getNormal(makeVector(origin, point2));
+ double* crossp = getCrossProduct(vect1, vect2);
+
+ /*std::cout<<"origin "<<origin[0]<<" "<<origin[1]<<" "<<origin[2]<<" "<<std::endl;
+ std::cout<<"point1 "<<point1[0]<<" "<<point1[1]<<" "<<point1[2]<<" "<<std::endl;
+ std::cout<<"point2 "<<point2[0]<<" "<<point2[1]<<" "<<point2[2]<<" "<<std::endl;
+ std::cout<<"vect1 "<<vect1[0]<<" "<<vect1[1]<<" "<<vect1[2]<<" "<<std::endl;
+ std::cout<<"vect2 "<<vect2[0]<<" "<<vect2[1]<<" "<<vect2[2]<<" "<<std::endl;
+ std::cout<<"crossp "<<crossp[0]<<" "<<crossp[1]<<" "<<crossp[2]<<" "<<std::endl;*/
+
+
+ _imageReslicer->SetResliceAxesDirectionCosines(vect1[0],vect1[1],vect1[2],
+ vect2[0],vect2[1],vect2[2],
+ crossp[0],crossp[1],crossp[2]);
+ //_imageReslicer->SetResliceAxesOrigin(0,0,0);
+ _imageReslicer->SetResliceAxesOrigin(origin[0],origin[1],origin[2]);
+
+ _imageReslicer->GetOutput()->Update;
+ _imageReslicer->GetOutput()->UpdateInformation();
+
+ bbSetOutputImage3Pts(_imageReslicer->GetOutput());
+
+
+ }
+
+ }
+}