1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestCubeSource.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #include <vtkCubeSource.h>
17 #include <vtkMinimalStandardRandomSequence.h>
18 #include <vtkSmartPointer.h>
19 
TestCubeSource(int vtkNotUsed (argc),char * vtkNotUsed (argv)[])20 int TestCubeSource(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
21 {
22   vtkSmartPointer<vtkMinimalStandardRandomSequence> randomSequence
23     = vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
24   randomSequence->SetSeed(1);
25 
26   vtkSmartPointer<vtkCubeSource> cubeSource
27     = vtkSmartPointer<vtkCubeSource>::New();
28 
29   cubeSource->SetOutputPointsPrecision(vtkAlgorithm::SINGLE_PRECISION);
30 
31   double center[3];
32   for(unsigned int i = 0; i < 3; ++i)
33     {
34     randomSequence->Next();
35     center[i] = randomSequence->GetValue();
36     }
37   cubeSource->SetCenter(center);
38 
39   randomSequence->Next();
40   double xLength = randomSequence->GetValue();
41   cubeSource->SetXLength(xLength);
42 
43   randomSequence->Next();
44   double yLength = randomSequence->GetValue();
45   cubeSource->SetYLength(yLength);
46 
47   randomSequence->Next();
48   double zLength = randomSequence->GetValue();
49   cubeSource->SetZLength(zLength);
50 
51   cubeSource->Update();
52 
53   vtkSmartPointer<vtkPolyData> polyData = cubeSource->GetOutput();
54   vtkSmartPointer<vtkPoints> points = polyData->GetPoints();
55 
56   if(points->GetDataType() != VTK_FLOAT)
57     {
58     return EXIT_FAILURE;
59     }
60 
61   cubeSource->SetOutputPointsPrecision(vtkAlgorithm::DOUBLE_PRECISION);
62 
63   for(unsigned int i = 0; i < 3; ++i)
64     {
65     randomSequence->Next();
66     center[i] = randomSequence->GetValue();
67     }
68   cubeSource->SetCenter(center);
69 
70   randomSequence->Next();
71   xLength = randomSequence->GetValue();
72   cubeSource->SetXLength(xLength);
73 
74   randomSequence->Next();
75   yLength = randomSequence->GetValue();
76   cubeSource->SetYLength(yLength);
77 
78   randomSequence->Next();
79   zLength = randomSequence->GetValue();
80   cubeSource->SetZLength(zLength);
81 
82   cubeSource->Update();
83 
84   polyData = cubeSource->GetOutput();
85   points = polyData->GetPoints();
86 
87   if(points->GetDataType() != VTK_DOUBLE)
88     {
89     return EXIT_FAILURE;
90     }
91 
92   return EXIT_SUCCESS;
93 }
94