- void ImagePlanes::Process()
- {
- if (bbGetInputIn()!=0)
- {
- Init();
-
- 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);
-
- planeWidgetX->SetInput(bbGetInputIn());
- planeWidgetX->SetPlaneOrientationToXAxes();
- planeWidgetX->SetSlicePosition((xMax+xMin)/2.*xSpacing);
- planeWidgetX->GetResliceOutput()->Update();
- bbSetOutput("ImageX", planeWidgetX->GetResliceOutput());
-
-
- vtkMetaImageWriter *writer = vtkMetaImageWriter::New();
-
- std::string newFilenameX("newFilenameX.mhd");
- writer->SetInput(planeWidgetX->GetResliceOutput());
- writer->SetFileName(newFilenameX.c_str());
- writer->Update();
-
- //planeWidgetX->GetResliceOutput()->Print(std::cout);
-
- planeWidgetY->SetInput(bbGetInputIn());
- planeWidgetY->SetPlaneOrientationToYAxes();
- planeWidgetY->SetSlicePosition((yMax+yMin)/2.*ySpacing);
- planeWidgetY->GetResliceOutput()->Update();
- bbSetOutput("ImageY", planeWidgetY->GetResliceOutput());
- //planeWidgetY->GetResliceOutput()->Print(std::cout);
-
- std::string newFilenameY("newFilenameY.mhd");
- writer->SetInput(planeWidgetY->GetResliceOutput());
- writer->SetFileName(newFilenameY.c_str());
- writer->Update();
-
- planeWidgetZ->SetInput(bbGetInputIn());
- planeWidgetZ->SetPlaneOrientationToZAxes();
- planeWidgetZ->SetSlicePosition((zMax+zMin)/2.*zSpacing);
- planeWidgetZ->GetResliceOutput()->Update();
- bbSetOutput("ImageZ", planeWidgetZ->GetResliceOutput());
- // planeWidgetZ->GetResliceOutput()->Print(std::cout);
+void ImagePlanes::Process()
+{
+ if (bbGetInputIn()!=0)
+ {
+
+ int xMin, xMax, yMin, yMax, zMin, zMax;
+ bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
+
+ if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){
+ // Input image has changed : reinitialize planes
+ image = bbGetInputIn();
+
+
+ // 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){
+
+
+ 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);
+
+ double *newx = getCrossProduct(vect2, crossp);
+
+ int ext[6],factor=0;
+ bbGetInputIn()->GetExtent(ext);
+
+ factor = ext[0]<ext[3]? ext[3] : ext[0];
+ factor = factor<ext[5]? ext[5] : factor;
+
+
+ vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts();
+ plane3pts->SetInput(bbGetInputIn());
+ double xSpacing, ySpacing, zSpacing;
+ bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
+ plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing);
+ plane3pts->SetPoint1((origin[0]+newx[0]*factor)*xSpacing,
+ (origin[1]+newx[1]*factor)*ySpacing,
+ (origin[2]+newx[2]*factor)*zSpacing);
+ plane3pts->SetPoint2((origin[0]+vect2[0]*factor)*xSpacing,
+ (origin[1]+vect2[1]*factor)*ySpacing,
+ (origin[2]+vect2[2]*factor)*zSpacing);
+ plane3pts->GetResliceOutput()->Update();
+
+ if (_imageReslicer==NULL){
+ _imageReslicer = vtkImageReslice::New();
+ _imageReslicer->SetOutputDimensionality(2);
+ _imageReslicer->SetInterpolationModeToLinear();
+ _transform = vtkTransform::New();
+ _matrix = vtkMatrix4x4::New();
+ }
+ _imageReslicer->SetInput( bbGetInputIn() );
+ _imageReslicer->SetInformationInput(bbGetInputIn());
+ _imageReslicer->SetResliceAxesDirectionCosines(newx[0],newx[1],newx[2],
+ vect2[0],vect2[1],vect2[2],
+ crossp[0],crossp[1],crossp[2]);
+ _imageReslicer->SetResliceAxesOrigin(origin[0]*xSpacing,origin[1]*ySpacing,origin[2]*zSpacing);
+ _imageReslicer->GetOutput()->Update();
+ _imageReslicer->GetOutput()->UpdateInformation();
+
+
+ bbSetOutputImage3Pts(_imageReslicer->GetOutput());
+
+
+
+ _matrix->Identity();
+
+ _matrix->SetElement(0,0,newx[0]);
+ _matrix->SetElement(1,0,newx[1]);
+ _matrix->SetElement(2,0,newx[2]);
+ _matrix->SetElement(0,1,vect2[0]);
+ _matrix->SetElement(1,1,vect2[1]);
+ _matrix->SetElement(2,1,vect2[2]);
+ _matrix->SetElement(0,2,crossp[0]);
+ _matrix->SetElement(1,2,crossp[1]);
+ _matrix->SetElement(2,2,crossp[2]);
+ _matrix->SetElement(0,3,origin[0]);
+ _matrix->SetElement(1,3,origin[1]);
+ _matrix->SetElement(2,3,origin[2]);
+
+
+ _transform->SetMatrix(_matrix);
+
+ bbSetOutputTransform3Pts((vtkLinearTransform*)_transform);
+
+
+
+ }
+ }
+}