KWHelloWorldExample-alex.cxx: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
 
Line 1: Line 1:
<pre><nowiki>#if defined(_MSC_VER)
<pre><nowiki>#include "vtkKWApplication.h"
#pragma warning ( disable : 4786 )
#include "vtkKWWindowBase.h"
#endif
#include "vtkKWLabel.h"
#include "vtkKWFrame.h"
#include "vtkKWRenderWidget.h"
#include "vtkKWHistogram.h"
#include "vtkKWPiecewiseFunctionEditor.h"


#ifdef __BORLANDC__
#include <vtksys/SystemTools.hxx>
#define ITK_LEAN_AND_MEAN
#include <vtksys/CommandLineArguments.hxx>
#endif


#include "itkImageToVTKImageFilter.h"
#include "itkImage.h"
#include "itkImage.h"
#include "itkGeodesicActiveContourLevelSetImageFilter.h"
#include "itkCurvatureAnisotropicDiffusionImageFilter.h"
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"
#include "itkSigmoidImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"


#include "vtkRenderer.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkCamera.h"
#include "vtkPointData.h"


int main( int argc, char *argv[] )
int my_main(int argc, char *argv[])
{
{
   if( argc < 12 )
  // Initialize Tcl
 
  Tcl_Interp *interp = vtkKWApplication::InitializeTcl(argc, argv, &cerr);
   if (!interp)
     {
     {
     std::cerr << "Missing Parameters " << std::endl;
     cerr << "Error: InitializeTcl failed" << endl ;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " inputImageFile  outputImageFile";
    std::cerr << " Sigma SigmoidAlpha SigmoidBeta";
    std::cerr << " PropagationScaling CurvatureScaling";
    std::cerr << " AdvectionScaling maxRMSError maxIterations";
    std::cerr << " initialThreshold" << std::endl;
     return 1;
     return 1;
     }
     }


   // We define the image type using a particular pixel type and
   // Load the Image via ITK
  //  dimension. In this case the \code{float} type is used for the pixels
  //  due to the requirements of the smoothing filter.


  typedef  float            InternalPixelType;
   const unsigned int Dimension = 3;
   const     unsigned char    Dimension = 3;
   typedef unsigned char InputPixelType;
  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
                                   
   typedef unsigned char OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
 
  //  This is the initial Threshold to determine the initial level set.
  typedef itk::BinaryThresholdImageFilter<
                        InternalImageType,
                        InternalImageType    >    ThresholdingFilterType2;
  ThresholdingFilterType2::Pointer inThresholder = ThresholdingFilterType2::New();
                       
  inThresholder->SetLowerThreshold( 0 );
  inThresholder->SetUpperThreshold( atoi(argv[11]) );
  inThresholder->SetOutsideValue(  0  );
  inThresholder->SetInsideValue(  255 );
 
  // Define the reader and writer.
  typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;


  typedef itk::Image<InputPixelType, Dimension> InputImageType;
  typedef itk::ImageFileReader<InputImageType> ReaderType;
   ReaderType::Pointer reader = ReaderType::New();
   ReaderType::Pointer reader = ReaderType::New();
   WriterType::Pointer writer = WriterType::New();
//  reader->SetFileName( "/home/alex/interp/61457548-roi-8bit.tif" );
   reader->SetFileName( "/home/alex/interp/61457548-roi-8bit-x4-ga-40-0.05-10-no_edges.tif" );


   reader->SetFileName( argv[1] );
   try
   writer->SetFileName( argv[2] );
    {
        reader->Update();
    }
   catch( itk::ExceptionObject & excep )
    {
        std::cerr << "Exception while reading input!"<< std::endl;
        std::cerr << excep << std::endl;
    }


  //  The RescaleIntensityImageFilter type is declared below. This filter will
   typedef itk::ImageToVTKImageFilter<InputImageType> FilterType;
  //  renormalize image before sending them to writers.
  FilterType::Pointer imtoimfilt = FilterType::New();
   typedef itk::RescaleIntensityImageFilter<  
  imtoimfilt->SetInput( reader->GetOutput() );
                              InternalImageType,
                              OutputImageType >   CastFilterType;


   //  The types of the
   try
   //  GradientMagnitudeRecursiveGaussianImageFilter and
    {
  //  SigmoidImageFilter are instantiated using the internal image
            imtoimfilt->Update();
  //  type.
    }
   //
   catch( itk::ExceptionObject & except)
   typedef  itk::GradientMagnitudeRecursiveGaussianImageFilter<
    {
                              InternalImageType,  
            std::cerr << "Exception while converting!"<< std::endl;
                              InternalImageType > GradientFilterType;
            std::cerr << except << std::endl;
    }
 
   // Create transfer mapping scalar value to opacity
   vtkPiecewiseFunction *opacTransFunc = vtkPiecewiseFunction::New();
    opacTransFunc->AddPoint(0, 1.0);
    opacTransFunc->AddPoint(100, 0.0);
    opacTransFunc->AddPoint(255, 0.0);


   GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
   // The property describes how the data will look
 
  vtkVolumeProperty *vp = vtkVolumeProperty::New();
  //  The sigma of this Gaussian can be used to control
    vp->SetScalarOpacity(opacTransFunc);
  //  the range of influence of the image edges. This filter has been discussed
    vp->ShadeOn();
  //  in Section~\ref{sec:GradientMagnitudeRecursiveGaussianImageFilter}
    vp->SetInterpolationTypeToLinear();


   const double sigma = atof( argv[3] );
   vtkFixedPointVolumeRayCastMapper *rcm = vtkFixedPointVolumeRayCastMapper::New();
  gradientMagnitude->SetSigma( sigma  );
    rcm->SetInput( imtoimfilt->GetOutput());
    
   // The volume holds the mapper and the property and
   typedef   itk::SigmoidImageFilter<                             
   // can be used to position/orient the volume
                              InternalImageType,
   vtkVolume *volHead= vtkVolume::New();
                              InternalImageType > SigmoidFilterType;
  volHead->SetMapper(rcm);
  volHead->SetProperty(vp);


   SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
   // Create the application
  // If --test was provided, ignore all registry settings, and exit silently
  // Restore the settings that have been saved to the registry, like
  // the geometry of the user interface so far.


   //  The minimum and maximum values of the SigmoidImageFilter output
   vtkKWApplication *app = vtkKWApplication::New();
   //  are defined with the methods \code{SetOutputMinimum()} and
   app->SetName("KWHelloWorldExample-alex");
   //  \code{SetOutputMaximum()}. In our case, we want these two values to be
   app->RestoreApplicationSettingsFromRegistry();
  //  $0.0$ and $1.0$ respectively in order to get a nice speed image to feed
  //  the \code{FastMarchingImageFilter}. Additional details on the user of the
  //  \doxygen{SigmoidImageFilter} are presented in
  //  section~\ref{sec:IntensityNonLinearMapping}.


   sigmoid->SetOutputMinimum( 0.0  );
   // Set a help link. Can be a remote link (URL), or a local file
   sigmoid->SetOutputMaximum( 1.);
  // vtksys::SystemTools::GetFilenamePath(__FILE__) + "/help.html";
   app->SetHelpDialogStartingPage("http://www.kwwidgets.org");


   // The SigmoidImageFilter requires two parameters that define the linear
   // Add a window
   // transformation to be applied to the sigmoid argument. This parameters
   // Set 'SupportHelp' to automatically add a menu entry for the help link
  //  have been discussed in Sections~\ref{sec:IntensityNonLinearMapping} and
  //  \ref{sec:FastMarchingImageFilter}.


   const double alpha = atof( argv[4] );
   vtkKWWindowBase *win = vtkKWWindowBase::New();
   const double beta  =  atof( argv[5] );
   win->SupportHelpOn();
  app->AddWindow(win);
  win->Create();


   sigmoid->SetAlpha( alpha );
   vtkKWRenderWidget *hello_renderwidget = vtkKWRenderWidget::New();
   sigmoid->SetBeta( beta  );
   hello_renderwidget->SetParent(win->GetViewFrame());
    
   hello_renderwidget->Create();
  typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
                InternalImageType >   GeodesicActiveContourFilterType;
  GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
                                    GeodesicActiveContourFilterType::New();
    
    
   //  For the GeodesicActiveContourLevelSetImageFilter, scaling parameters
   vtkRenderer *hello_renderer = hello_renderwidget->GetRenderer();
  //  are used to trade off between the propagation (inflation), the
   hello_renderer->AddViewProp(volHead);  
  //  curvature (smoothing) and the advection terms. These parameters are set
   hello_renderer->SetBackground(0.3, 0.6, 1.0);
  //  using methods \code{SetPropagationScaling()},
   hello_renderer->GetActiveCamera()->ParallelProjectionOff();
  //  \code{SetCurvatureScaling()} and \code{SetAdvectionScaling()}. In this
   hello_renderer->ResetCamera();
  //  example, we will set the curvature and advection scales to one and let
  //  the propagation scale be a command-line argument.
 
  const double propagationScaling = atof( argv[6] );
  const double curvatureScaling = atof( argv[7] );
  const double advectionScaling = atof( argv[8] );
 
  geodesicActiveContour->SetPropagationScaling( propagationScaling );
   geodesicActiveContour->SetCurvatureScaling( curvatureScaling );
   geodesicActiveContour->SetAdvectionScaling( advectionScaling );
 
  //  Once activated the level set evolution will stop if the convergence
  //  criteria or if the maximum number of iterations is reached. The
  //  convergence criteria is defined in terms of the root mean squared (RMS)
  //  change in the level set function. The evolution is said to have
  //  converged if the RMS change is below a user specified threshold.  In a
  //  real application is desirable to couple the evolution of the zero set
  //  to a visualization module allowing the user to follow the evolution of
  //  the zero set. With this feedback, the user may decide when to stop the
  //  algorithm before the zero set leaks through the regions of low gradient
  //  in the contour of the anatomical structure to be segmented.
  //  !!!!!
 
  const double maxRMSError = atof( argv[9] );
   const unsigned int maxIter = atoi( argv[10] );
  geodesicActiveContour->SetMaximumRMSError( maxRMSError );
   geodesicActiveContour->SetNumberOfIterations( maxIter );
 
  //  The following lines instantiate the thresholding filter that will
  //  process the final level set at the output of the
  //  GeodesicActiveContourLevelSetImageFilter.
  typedef itk::BinaryThresholdImageFilter<
                        InternalImageType,
                        OutputImageType    >    ThresholdingFilterType;
    
    
   ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
   app->Script("pack %s -side left -fill both -anchor c -expand y",
                       
                  hello_renderwidget->GetWidgetName());
  thresholder->SetLowerThreshold( -1000.0 );
   hello_renderwidget->Delete();
  thresholder->SetUpperThreshold(     0.0 );
 
  thresholder->SetOutsideValue(  0  );
   thresholder->SetInsideValue( 255 );
    
    
// build an histogram of the data, it will be used inside the editor
// as if we were trying to tune a tfunc based on the real values
   
   
   // Configure the pipeline.
  vtkKWHistogram *pfed_hist = vtkKWHistogram::New();
  pfed_hist->BuildHistogram(
    imtoimfilt->GetOutput()->GetPointData()->GetScalars(), 0);
  double *range = pfed_hist->GetRange();
 
   // Assign our tfunc to the editor
  // Make sure we show the whole range of the tfunc
  // Use an histogram


   gradientMagnitude->SetInput( reader->GetOutput() );
   vtkKWPiecewiseFunctionEditor *pfed_tfunc2_editor =
   sigmoid->SetInput( gradientMagnitude->GetOutput() );
    vtkKWPiecewiseFunctionEditor::New();
  pfed_tfunc2_editor->SetParent(win->GetViewFrame());
   pfed_tfunc2_editor->Create();
  pfed_tfunc2_editor->SetBorderWidth(2);
  pfed_tfunc2_editor->SetReliefToGroove();
  pfed_tfunc2_editor->SetPadX(2);
  pfed_tfunc2_editor->SetPadY(2);
  pfed_tfunc2_editor->ExpandCanvasWidthOff();
  pfed_tfunc2_editor->SetCanvasWidth(250);
  pfed_tfunc2_editor->SetCanvasHeight(150);
  pfed_tfunc2_editor->SetLabelText("Opacity Function Editor");
  pfed_tfunc2_editor->SetBalloonHelpString(
    "Piecewise transfer function editor. Guidelines are dispayed "
    "for each midpoint, ticks are displayed in the "
    "parameter space at the bottom, the width is set explicitly. "
    "The range and histogram are based on a real image data.");


   inThresholder->SetInput( reader->GetOutput() );
   pfed_tfunc2_editor->SetPiecewiseFunction(opacTransFunc);
   geodesicActiveContour->SetInput(  inThresholder->GetOutput() );
   pfed_tfunc2_editor->SetWholeParameterRangeToFunctionRange();
   geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
   pfed_tfunc2_editor->SetVisibleParameterRangeToWholeParameterRange();


  thresholder->SetInput( geodesicActiveContour->GetOutput() );
//  pfed_tfunc2_editor->PointIndexVisibilityOff();
   writer->SetInput( thresholder->GetOutput() );
//  pfed_tfunc2_editor->SelectedPointIndexVisibilityOn();
//  pfed_tfunc2_editor->MidPointVisibilityOn();
//  pfed_tfunc2_editor->PointGuidelineVisibilityOff();
//  pfed_tfunc2_editor->MidPointGuidelineVisibilityOn();
//  pfed_tfunc2_editor->MidPointGuidelineValueVisibilityOn();
//  pfed_tfunc2_editor->SetMidPointGuidelineValueFormat("%-#6.0f");
//  pfed_tfunc2_editor->MidPointEntryVisibilityOn();
//  pfed_tfunc2_editor->SharpnessEntryVisibilityOn();
   pfed_tfunc2_editor->ValueRangeVisibilityOff();
  pfed_tfunc2_editor->ParameterRangeVisibilityOff();
  pfed_tfunc2_editor->SetLabelPositionToTop();
  pfed_tfunc2_editor->LockEndPointsParameterOn();


  pfed_tfunc2_editor->SetHistogram(pfed_hist);


   //  Here we configure all the writers required to see the intermediate
   pfed_tfunc2_editor->ParameterTicksVisibilityOn();
   //  outputs of the pipeline. This is added here only for
   pfed_tfunc2_editor->ComputeValueTicksFromHistogramOn();
  //  pedagogical/debugging purposes. These intermediate output are normaly not
//  pfed_tfunc2_editor->SetParameterTicksFormat(
  // required. Only the output of the final thresholding filter should be
//   pfed_tfunc2_editor->GetMidPointGuidelineValueFormat());
  //  relevant.  Observing intermediate output is helpful in the process of
  //  fine tuning the parameters of filters in the pipeline.
  //
  CastFilterType::Pointer caster2 = CastFilterType::New();
  CastFilterType::Pointer caster3 = CastFilterType::New();
  CastFilterType::Pointer caster4 = CastFilterType::New();


   WriterType::Pointer writer2 = WriterType::New();
   app->Script(
   WriterType::Pointer writer3 = WriterType::New();
    "pack %s -side top -anchor nw -expand n -padx 2 -pady 20",
   WriterType::Pointer writer4 = WriterType::New();
    pfed_tfunc2_editor->GetWidgetName());
 
  pfed_tfunc2_editor->Delete();
   opacTransFunc->Delete();
   pfed_hist->Delete();


   caster2->SetInput( gradientMagnitude->GetOutput() );
   /*
   writer2->SetInput( caster2->GetOutput() );
  // Add a label, attach it to the view frame, and pack
   writer2->SetFileName("GeodesicActiveContourImageFilterOutput-grad.tif");
 
   caster2->SetOutputMinimum(   0 );
  vtkKWLabel *hello_label = vtkKWLabel::New();
   caster2->SetOutputMaximum( 255 );
   hello_label->SetParent(win->GetViewFrame());
  writer2->Update();
   hello_label->Create();
   caster2->ReleaseDataFlagOn();
   hello_label->SetText("Hello, World!");
  writer2->ReleaseDataFlagOn();
   app->Script("pack %s -side left -anchor c -expand y",
              hello_label->GetWidgetName());
   hello_label->Delete();
*/
    
    
  caster3->SetInput( sigmoid->GetOutput() );
   // Start the application
  writer3->SetInput( caster3->GetOutput() );
   // If --test was provided, do not enter the event loop and run this example
  writer3->SetFileName("GeodesicActiveContourImageFilterOutput-sigmoid.tif");
   // as a non-interactive test for software quality purposes.
  caster3->SetOutputMinimum(  0 );
  caster3->SetOutputMaximum( 255 );
  writer3->Update();
  caster3->ReleaseDataFlagOn();
  writer3->ReleaseDataFlagOn();
   
  caster4->SetInput( inThresholder->GetOutput() );
  writer4->SetInput( caster4->GetOutput() );
  writer4->SetFileName("GeodesicActiveContourImageFilterOutput-inThresh.tif");
  caster4->SetOutputMinimum(  0 );
  caster4->SetOutputMaximum( 255 );
  writer4->Update();
  caster4->ReleaseDataFlagOn();
  writer4->ReleaseDataFlagOn();
   
   // Software Guide : BeginLatex
  // 
  //  The invocation of the \code{Update()} method on the writer triggers the
   // execution of the pipeline.  As usual, the call is placed in a
   // \code{try/catch} block should any errors occur or exceptions be thrown.
  //
  //  Software Guide : EndLatex


   // Software Guide : BeginCodeSnippet
   int ret = 0;
   try
   win->Display();
    {
   app->Start(argc, argv);
    writer->Update();
  ret = app->GetExitStatus();
    }
   win->Close();
   catch(itk::ExceptionObject & excep)
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }
   // Software Guide : EndCodeSnippet


   // Print out some useful information
   // Deallocate and exit
  std::cout << std::endl;
  std::cout << "Max. no. iterations: " << geodesicActiveContour->GetNumberOfIterations() << std::endl;
  std::cout << "Max. RMS error: " << geodesicActiveContour->GetMaximumRMSError() << std::endl;
  std::cout << std::endl;
  std::cout << "No. elapsed iterations: " << geodesicActiveContour->GetElapsedIterations() << std::endl;
  std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange() << std::endl;


   return 0;
  win->Delete();
  app->Delete();
 
   return ret;
}
}


</nowiki></pre>
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)
{
  int argc;
  char **argv;
  vtksys::SystemTools::ConvertWindowsCommandLineToUnixArguments(
    lpCmdLine, &argc, &argv);
  int ret = my_main(argc, argv);
  for (int i = 0; i < argc; i++) { delete [] argv[i]; }
  delete [] argv;
  return ret;
}
#else
int main(int argc, char *argv[])
{
  return my_main(argc, argv);
}
#endif</nowiki></pre>


{{CompleteSetup/Template/Footer}}
{{CompleteSetup/Template/Footer}}

Latest revision as of 16:41, 5 May 2006

#include "vtkKWApplication.h"
#include "vtkKWWindowBase.h"
#include "vtkKWLabel.h"
#include "vtkKWFrame.h"
#include "vtkKWRenderWidget.h"
#include "vtkKWHistogram.h"
#include "vtkKWPiecewiseFunctionEditor.h"

#include <vtksys/SystemTools.hxx>
#include <vtksys/CommandLineArguments.hxx>

#include "itkImageToVTKImageFilter.h"
#include "itkImage.h"
#include "itkImageFileReader.h"

#include "vtkRenderer.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkCamera.h"
#include "vtkPointData.h"

int my_main(int argc, char *argv[])
{
  // Initialize Tcl

  Tcl_Interp *interp = vtkKWApplication::InitializeTcl(argc, argv, &cerr);
  if (!interp)
    {
    cerr << "Error: InitializeTcl failed" << endl ;
    return 1;
    }

  // Load the Image via ITK

  const unsigned int Dimension = 3;
  typedef unsigned char InputPixelType;

  typedef itk::Image<InputPixelType, Dimension> InputImageType;
  typedef itk::ImageFileReader<InputImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
//  reader->SetFileName( "/home/alex/interp/61457548-roi-8bit.tif" );
  reader->SetFileName( "/home/alex/interp/61457548-roi-8bit-x4-ga-40-0.05-10-no_edges.tif" );

  try
    {
        reader->Update();
    }
  catch( itk::ExceptionObject & excep )
     {
        std::cerr << "Exception while reading input!"<< std::endl;
        std::cerr << excep << std::endl;
     }

  typedef itk::ImageToVTKImageFilter<InputImageType> FilterType;
  FilterType::Pointer imtoimfilt = FilterType::New();
  imtoimfilt->SetInput( reader->GetOutput() );

  try
    {
            imtoimfilt->Update();
    }
  catch( itk::ExceptionObject & except)
    {
            std::cerr << "Exception while converting!"<< std::endl;
            std::cerr << except << std::endl;
    }

  // Create transfer mapping scalar value to opacity
  vtkPiecewiseFunction *opacTransFunc = vtkPiecewiseFunction::New();
    opacTransFunc->AddPoint(0, 1.0);
    opacTransFunc->AddPoint(100, 0.0);
    opacTransFunc->AddPoint(255, 0.0);

  // The property describes how the data will look
  vtkVolumeProperty *vp = vtkVolumeProperty::New();
    vp->SetScalarOpacity(opacTransFunc);
    vp->ShadeOn();
    vp->SetInterpolationTypeToLinear();

  vtkFixedPointVolumeRayCastMapper *rcm = vtkFixedPointVolumeRayCastMapper::New();
    rcm->SetInput( imtoimfilt->GetOutput());
  // The volume holds the mapper and the property and
  // can be used to position/orient the volume
  vtkVolume *volHead= vtkVolume::New();
  volHead->SetMapper(rcm);
  volHead->SetProperty(vp);

  // Create the application
  // If --test was provided, ignore all registry settings, and exit silently
  // Restore the settings that have been saved to the registry, like
  // the geometry of the user interface so far.

  vtkKWApplication *app = vtkKWApplication::New();
  app->SetName("KWHelloWorldExample-alex");
  app->RestoreApplicationSettingsFromRegistry();

  // Set a help link. Can be a remote link (URL), or a local file
  // vtksys::SystemTools::GetFilenamePath(__FILE__) + "/help.html";
  app->SetHelpDialogStartingPage("http://www.kwwidgets.org");

  // Add a window
  // Set 'SupportHelp' to automatically add a menu entry for the help link

  vtkKWWindowBase *win = vtkKWWindowBase::New();
  win->SupportHelpOn();
  app->AddWindow(win);
  win->Create();

  vtkKWRenderWidget *hello_renderwidget = vtkKWRenderWidget::New();
  hello_renderwidget->SetParent(win->GetViewFrame());
  hello_renderwidget->Create();
  
  vtkRenderer *hello_renderer = hello_renderwidget->GetRenderer();
  hello_renderer->AddViewProp(volHead); 
  hello_renderer->SetBackground(0.3, 0.6, 1.0);
  hello_renderer->GetActiveCamera()->ParallelProjectionOff();
  hello_renderer->ResetCamera();
  
  app->Script("pack %s -side left -fill both -anchor c -expand y",
                  hello_renderwidget->GetWidgetName());
  hello_renderwidget->Delete();
  
 // build an histogram of the data, it will be used inside the editor
 // as if we were trying to tune a tfunc based on the real values
 
   vtkKWHistogram *pfed_hist = vtkKWHistogram::New();
   pfed_hist->BuildHistogram( 
     imtoimfilt->GetOutput()->GetPointData()->GetScalars(), 0);
   double *range = pfed_hist->GetRange();
  
  // Assign our tfunc to the editor
  // Make sure we show the whole range of the tfunc
  // Use an histogram

  vtkKWPiecewiseFunctionEditor *pfed_tfunc2_editor = 
    vtkKWPiecewiseFunctionEditor::New();
  pfed_tfunc2_editor->SetParent(win->GetViewFrame());
  pfed_tfunc2_editor->Create();
  pfed_tfunc2_editor->SetBorderWidth(2);
  pfed_tfunc2_editor->SetReliefToGroove();
  pfed_tfunc2_editor->SetPadX(2);
  pfed_tfunc2_editor->SetPadY(2);
  pfed_tfunc2_editor->ExpandCanvasWidthOff();
  pfed_tfunc2_editor->SetCanvasWidth(250);
  pfed_tfunc2_editor->SetCanvasHeight(150);
  pfed_tfunc2_editor->SetLabelText("Opacity Function Editor");
  pfed_tfunc2_editor->SetBalloonHelpString(
    "Piecewise transfer function editor. Guidelines are dispayed "
    "for each midpoint, ticks are displayed in the "
    "parameter space at the bottom, the width is set explicitly. "
    "The range and histogram are based on a real image data.");

  pfed_tfunc2_editor->SetPiecewiseFunction(opacTransFunc);
  pfed_tfunc2_editor->SetWholeParameterRangeToFunctionRange();
  pfed_tfunc2_editor->SetVisibleParameterRangeToWholeParameterRange();

//  pfed_tfunc2_editor->PointIndexVisibilityOff();
//  pfed_tfunc2_editor->SelectedPointIndexVisibilityOn();
//  pfed_tfunc2_editor->MidPointVisibilityOn();
//  pfed_tfunc2_editor->PointGuidelineVisibilityOff();
//  pfed_tfunc2_editor->MidPointGuidelineVisibilityOn();
//  pfed_tfunc2_editor->MidPointGuidelineValueVisibilityOn();
//  pfed_tfunc2_editor->SetMidPointGuidelineValueFormat("%-#6.0f");
//  pfed_tfunc2_editor->MidPointEntryVisibilityOn();
//  pfed_tfunc2_editor->SharpnessEntryVisibilityOn();
  pfed_tfunc2_editor->ValueRangeVisibilityOff();
  pfed_tfunc2_editor->ParameterRangeVisibilityOff();
  pfed_tfunc2_editor->SetLabelPositionToTop();
  pfed_tfunc2_editor->LockEndPointsParameterOn();

  pfed_tfunc2_editor->SetHistogram(pfed_hist);

  pfed_tfunc2_editor->ParameterTicksVisibilityOn();
  pfed_tfunc2_editor->ComputeValueTicksFromHistogramOn();
//  pfed_tfunc2_editor->SetParameterTicksFormat(
//    pfed_tfunc2_editor->GetMidPointGuidelineValueFormat());

  app->Script(
    "pack %s -side top -anchor nw -expand n -padx 2 -pady 20", 
    pfed_tfunc2_editor->GetWidgetName());
  
  pfed_tfunc2_editor->Delete();
  opacTransFunc->Delete();
  pfed_hist->Delete();

  /*
  // Add a label, attach it to the view frame, and pack
  
  vtkKWLabel *hello_label = vtkKWLabel::New();
  hello_label->SetParent(win->GetViewFrame());
  hello_label->Create();
  hello_label->SetText("Hello, World!");
  app->Script("pack %s -side left -anchor c -expand y", 
              hello_label->GetWidgetName());
  hello_label->Delete();
*/
  
  // Start the application
  // If --test was provided, do not enter the event loop and run this example
  // as a non-interactive test for software quality purposes.

  int ret = 0;
  win->Display();
  app->Start(argc, argv);
  ret = app->GetExitStatus();
  win->Close();

  // Deallocate and exit

  win->Delete();
  app->Delete();
  
  return ret;
}

#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)
{
  int argc;
  char **argv;
  vtksys::SystemTools::ConvertWindowsCommandLineToUnixArguments(
    lpCmdLine, &argc, &argv);
  int ret = my_main(argc, argv);
  for (int i = 0; i < argc; i++) { delete [] argv[i]; }
  delete [] argv;
  return ret;
}
#else
int main(int argc, char *argv[])
{
  return my_main(argc, argv);
}
#endif



Complete Setup: [Welcome | Site Map]