- else legend->SetVisibility(0);
-
- if (ca->GetVisibility())
- {
- std::string worldPos = "";
- std::stringstream world1;
- std::stringstream world2;
- std::stringstream world3;
- world1 << (int)mCurrent[0];
- world2 << (int)mCurrent[1];
- world3 << (int)mCurrent[2];
- double X = (mCurrent[0] - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
- double Y = (mCurrent[1] - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
- double Z = (mCurrent[2] - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
-
- if (pdmA->GetVisibility())
- {
- double x = mCursor[0];
- double y = mCursor[1];
- double z = mCursor[2];
- double xCursor = (x - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
- double yCursor = (y - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
- double zCursor = (z - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
-
- if (xCursor >= this->GetImageActor()->GetDisplayExtent()[0] &&
- xCursor < this->GetImageActor()->GetDisplayExtent()[1]+1 &&
- yCursor >= this->GetImageActor()->GetDisplayExtent()[2] &&
- yCursor < this->GetImageActor()->GetDisplayExtent()[3]+1 &&
- zCursor >= this->GetImageActor()->GetDisplayExtent()[4] &&
- zCursor < this->GetImageActor()->GetDisplayExtent()[5]+1 )
- {
- vtkRenderer * renderer = this->Renderer;
-
- renderer->WorldToView(x,y,z);
- renderer->ViewToNormalizedViewport(x,y,z);
- renderer->NormalizedViewportToViewport(x,y);
- renderer->ViewportToNormalizedDisplay(x,y);
- renderer->NormalizedDisplayToDisplay(x,y);
- crossCursor->SetFocalPoint(x,y,z);
- }
- else
- crossCursor->SetFocalPoint(-1,-1,z);
- }
-
- if (X >= this->GetInput()->GetWholeExtent()[0] &&
- X <= this->GetInput()->GetWholeExtent()[1] &&
- Y >= this->GetInput()->GetWholeExtent()[2] &&
- Y <= this->GetInput()->GetWholeExtent()[3] &&
- Z >= this->GetInput()->GetWholeExtent()[4] &&
- Z <= this->GetInput()->GetWholeExtent()[5])
- {
- std::stringstream pixel1;
- std::stringstream pixel2;
- std::stringstream pixel3;
- std::stringstream temps;
- pixel1 << (int)X;
- pixel2 << (int)Y;
- pixel3 << (int)Z;
- temps << mCurrentTSlice;
- double value = this->GetInput()->GetScalarComponentAsDouble(
- (int)X,
- (int)Y,
- (int)Z,0);
-
- std::stringstream val;
- val << value;
- worldPos += "data value : " + val.str();
- worldPos += "\n mm : " + world1.str() + " " + world2.str() + " " + world3.str() + " " + temps.str();
- worldPos += "\n pixel : " + pixel1.str() + " " + pixel2.str() + " " + pixel3.str() + " " + temps.str();
- }
- ca->SetText(1,worldPos.c_str());
+ }
+ this->Renderer->ViewToWorld(fLocalExtents[0], fLocalExtents[2], fLocalExtents[4]);
+ this->Renderer->ViewToWorld(fLocalExtents[1], fLocalExtents[3], fLocalExtents[5]);
+
+ //Convert to image pixel coordinates (rounded)
+ int iLocalExtents[6];
+ for(int i=0; i<3; i++) {
+ fLocalExtents[i*2 ] = (fLocalExtents[i*2 ] - image->GetOrigin()[i])/image->GetSpacing()[i];
+ fLocalExtents[i*2+1] = (fLocalExtents[i*2+1] - image->GetOrigin()[i])/image->GetSpacing()[i];
+
+ iLocalExtents[i*2 ] = lrint(fLocalExtents[i*2 ]);
+ iLocalExtents[i*2+1] = lrint(fLocalExtents[i*2+1]);
+
+ if(iLocalExtents[i*2 ]>iLocalExtents[i*2+1])
+ std::swap(iLocalExtents[i*2], iLocalExtents[i*2+1]);
+ }
+
+ vtkSmartPointer<vtkExtractVOI> voiFilter = vtkSmartPointer<vtkExtractVOI>::New();
+ voiFilter->SetInput(image);
+ voiFilter->SetVOI(iLocalExtents);
+ voiFilter->Update();
+ if (!voiFilter->GetOutput()->GetNumberOfPoints()) {
+ min = 0;
+ max = 0;
+ return;
+ }
+
+ vtkSmartPointer<vtkImageAccumulate> accFilter = vtkSmartPointer<vtkImageAccumulate>::New();
+ accFilter->SetInput(voiFilter->GetOutput());
+ accFilter->Update();
+
+ min = *(accFilter->GetMin());
+ max = *(accFilter->GetMax());
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component)
+{
+ ix = lrint(X);
+ iy = lrint(Y);
+ iz = lrint(Z);
+ if (ix < image->GetWholeExtent()[0] ||
+ ix > image->GetWholeExtent()[1] ||
+ iy < image->GetWholeExtent()[2] ||
+ iy > image->GetWholeExtent()[3] ||
+ iz < image->GetWholeExtent()[4] ||
+ iz > image->GetWholeExtent()[5] )
+ return std::numeric_limits<double>::quiet_NaN();
+
+ image->SetUpdateExtent(ix, ix, iy, iy, iz, iz);
+ image->Update();
+ return image->GetScalarComponentAsDouble(ix, iy, iz, component);
+}
+//----------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------
+void vvSlicer::Render()
+{
+ if (this->mFusion) {
+ legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
+ legend->UseOpacityOn();
+ legend->SetVisibility(1);
+ }
+ else if (this->GetWindowLevel()->GetLookupTable()) {// && !this->mOverlay && !this->mFusion) {
+ legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable());
+ legend->UseOpacityOff();
+ legend->SetVisibility(1);
+ } else legend->SetVisibility(0);
+
+ if (ca->GetVisibility()) {
+ std::stringstream worldPos;
+ double X = (mCurrent[0] - this->GetInput()->GetOrigin()[0])/this->GetInput()->GetSpacing()[0];
+ double Y = (mCurrent[1] - this->GetInput()->GetOrigin()[1])/this->GetInput()->GetSpacing()[1];
+ double Z = (mCurrent[2] - this->GetInput()->GetOrigin()[2])/this->GetInput()->GetSpacing()[2];
+
+// if (X < this->GetInput()->GetWholeExtent()[0]) X = this->GetInput()->GetWholeExtent()[0];
+// else if (X > this->GetInput()->GetWholeExtent()[1]) X = this->GetInput()->GetWholeExtent()[1];
+// if (Y < this->GetInput()->GetWholeExtent()[2]) Y = this->GetInput()->GetWholeExtent()[2];
+// else if (Y > this->GetInput()->GetWholeExtent()[3]) Y = this->GetInput()->GetWholeExtent()[3];
+// if (Z < this->GetInput()->GetWholeExtent()[4]) Z = this->GetInput()->GetWholeExtent()[4];
+// else if (Z > this->GetInput()->GetWholeExtent()[5]) Z = this->GetInput()->GetWholeExtent()[5];
+
+ if (X >= this->GetInput()->GetWholeExtent()[0] &&
+ X <= this->GetInput()->GetWholeExtent()[1] &&
+ Y >= this->GetInput()->GetWholeExtent()[2] &&
+ Y <= this->GetInput()->GetWholeExtent()[3] &&
+ Z >= this->GetInput()->GetWholeExtent()[4] &&
+ Z <= this->GetInput()->GetWholeExtent()[5]) {
+
+
+ int ix, iy, iz;
+ double value = this->GetScalarComponentAsDouble(this->GetInput(), X, Y, Z, ix, iy, iz);
+
+ if(ImageActor->GetVisibility())
+ worldPos << "data value : " << value << std::endl;
+
+ worldPos << "mm : " << lrint(mCurrent[0]) << ' '
+ << lrint(mCurrent[1]) << ' '
+ << lrint(mCurrent[2]) << ' '
+ << mCurrentTSlice
+ << std::endl;
+ worldPos << "pixel : " << ix << ' '
+ << iy << ' '
+ << iz << ' '
+ << mCurrentTSlice
+ << std::endl;