File: ImageAccumulate.cxx

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (104 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    ImageAccumulate.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkImageData.h"
#include "vtkImageSinusoidSource.h"
#include "vtkImageAccumulate.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"

#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"

#include <math.h>

int ImageAccumulate(int , char *[])
{
  int rval = 0;

  // Create a blank image
  vtkImageSinusoidSource *sinus = vtkImageSinusoidSource::New();
  sinus->SetWholeExtent(0,512-1,0,512-1,0,64-1);
  sinus->SetAmplitude( 0 );
  sinus->Update();

  // Set some value
  sinus->GetOutput()->SetScalarComponentFromDouble (  0,   0,  0, 0, 1);
  sinus->GetOutput()->SetScalarComponentFromDouble ( 10,  10, 10, 0, 2);
  sinus->GetOutput()->SetScalarComponentFromDouble ( 10, 100, 20, 0, 3);
  sinus->GetOutput()->SetScalarComponentFromDouble (100,  10, 30, 0, 4);
  sinus->GetOutput()->SetScalarComponentFromDouble (100, 100, 40, 0, 5);

  vtkImageAccumulate *acc = vtkImageAccumulate::New();
  acc->SetInputConnection( sinus->GetOutputPort() );
  //acc->IgnoreZeroOn();
  acc->Update();

  acc->Print(cout);
  double min[3], max[3];
  acc->GetMin(min);
  acc->GetMax(max);
  if( min[0] != 0 )
    {
    cerr << "Min: " << min[0] << endl;
    rval++;
    }
  if( max[0] != 5 )
    {
    cerr << "Max: " << max[0] << endl;
    rval++;
    }
  double mean[3];
  long int voxcount;
  voxcount = acc->GetVoxelCount();
  acc->GetMean(mean);
  double m = double(1+2+3+4+5)/voxcount;
  if( fabs(mean[0] - m) > 1e-10 )
    {
    cerr << "Mean: " << mean[0] << endl;
    rval++;
    }


  // Test IgnoreZero option
  acc->IgnoreZeroOn();
  acc->Update();
  acc->Print( cout );

  // Simple test
  acc->GetMin(min);
  acc->GetMax(max);
  if( min[0] != 1 )
    {
    cerr << "Min: " << min[0] << endl;
    rval++;
    }
  if( max[0] != 5 )
    {
    cerr << "Max: " << max[0] << endl;
    rval++;
    }
  acc->GetMean(mean);
  if( mean[0] != double(1+2+3+4+5)/5  )
    {
    cerr << "Mean: " << mean[0] << endl;
    rval++;
    }

  sinus->Delete();
  acc->Delete();

  return rval;
}