-void wxContourMainFrame::onThreshold()
-{
- int z = _theViewPanel->GetZ();
- double range[2];
-
- vtkImageData * img = getImageData();
- img->GetScalarRange(range);
-
- int minTot = floor (range[0]);
- int maxTot = ceil (range[1]);
-
- double minMax[2];
- _pannew->onThresholdInstantChange(minMax);
- int minVal = floor (minMax[0]);
- int maxVal = floor (minMax[1]);
-
- if (!_actorPresent)
- {
- if (_imageReslicer==NULL)
- {
- _imageReslicer = vtkImageReslice::New();
- _imageReslicer->SetInput( img );
- _imageReslicer->SetInformationInput(img);
- _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
- _imageReslicer->SetOutputDimensionality(2);
- _imageReslicer->SetInterpolationModeToLinear();
- }
-
- _imageReslicer->SetResliceAxesOrigin(0,0,z);
-
- img = _imageReslicer->GetOutput();
- img->Update();
- img->UpdateInformation();
-
- wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
-
- if (_thresholdTable==NULL)
- {
- //Lookup Table
- _thresholdTable = vtkLookupTable::New();
- _thresholdTable->SetNumberOfTableValues(maxTot+1);
- _thresholdTable->SetTableRange(range);
- _thresholdTable->SetAlphaRange(0, 1);
- _thresholdTable->SetValueRange(0, 1);
- _thresholdTable->SetSaturationRange(0, 0);
- _thresholdTable->SetRampToLinear( );
- }
-
- //Assign a fake color for the upper image, and set the white as transparent
- int i;
- for(i = minTot; i <= maxTot; i++)
- {
- if( i >= minVal && i <= maxVal )
- {
- _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
- }
- else if( i >= minTot && i < minVal )
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- else if( i > maxVal && i < maxTot )
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- else
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- }
- _thresholdTable->Build( );
-
- if (_thresholdMapper==NULL)
- {
- _thresholdMapper = vtkImageMapToColors::New( );
- }
-
- _thresholdMapper->SetLookupTable( _thresholdTable );
- _thresholdMapper->SetInput( img );
-
- if (_thresholdActor==NULL)
- {
- _thresholdActor = vtkImageActor::New( );
- _thresholdActor->SetOpacity( 0.6 );
- _thresholdActor->InterpolateOn( );
- _thresholdActor->SetPosition( 0,0, 900-1 );
- }
-
- _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-
- baseView->GetRenderer()->AddActor( _thresholdActor );
- _actorPresent = true;
- }
-
- else
- {
- _imageReslicer->SetResliceAxesOrigin(0,0,z);
- img = _imageReslicer->GetOutput();
- img->Update();
- img->UpdateInformation();
-
- //Assign a fake color for the upper image, and set the white as transparent
- int i;
- for(i = minTot; i <= maxTot; i++)
- {
- if( i >= minVal && i <= maxVal )
- {
- _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
- }
- else if( i >= minTot && i < minVal )
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- else if( i > maxVal && i < maxTot )
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- else
- {
- _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
- }
- }
-
- _thresholdTable->Build( );
- _thresholdMapper->SetLookupTable( _thresholdTable );
- _thresholdMapper->SetInput( img );
- _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
- }
- /*
- vtkImageViewer2* viewer = vtkImageViewer2::New();
- viewer->SetInput( upperImageActor->GetInput() );
- viewer->SetColorLevel((range[1]-range[0])/2);
- viewer->SetColorWindow(range[1]);
- viewer->GetRenderer()->AddActor( upperImageActor );
- viewer->Render();
- */
- _theViewPanel->RefreshInterface();
-}
-
-
-void wxContourMainFrame::onThresholdChange()
-{
- if (_actorPresent)
- {
- onThreshold();
- }
-}
-
-void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
-{
- if (_thresholdActor!=NULL)
- {
- if (interpolate)
- {
- _thresholdActor->InterpolateOn( );
- }
-
- else
- {
- _thresholdActor->InterpolateOff( );
- }
-
- _theViewPanel->RefreshInterface();
- }
-}
-
-void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
-{
- if (_actorPresent)
- {
- _thresholdActor->SetOpacity(opacity*0.1);
- }
-
- _theViewPanel->RefreshInterface();
-}
-
-void wxContourMainFrame::onThresholdRemove()
-{
- if (_actorPresent)
- {
- wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
- baseView->GetRenderer()->RemoveActor( _thresholdActor );
- _actorPresent = false;
- }
-
- _theViewPanel->RefreshInterface();
-}