TestSelectEnclosedPoints.cxx 4.06 KB
Newer Older
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestSelectEnclosedPoints.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.

=========================================================================*/
// This example demonstrates the use of vtkGenerateSurfaceIntersectionLines
// 
// The command line arguments are:
// -I        => run in interactive mode; unless this is used, the program will
//              not allow interaction and exit
// -D <path> => path to the data; the data should be in <path>/Data/

// If WRITE_RESULT is defined, the result of the surface filter is saved.
//#define WRITE_RESULT

#include "vtkActor.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkSelectEnclosedPoints.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkMath.h"
#include "vtkGlyph3D.h"
#include "vtkPolyData.h"
#include "vtkThresholdPoints.h"

int TestSelectEnclosedPoints(int argc, char* argv[])
{
  // Standard rendering classes
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(renderer);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  
  // Create a containing surface
  vtkSphereSource *ss = vtkSphereSource::New();
  ss->SetPhiResolution(25);
  ss->SetThetaResolution(38);
  ss->SetCenter(4.5, 5.5, 5.0);
  ss->SetRadius(2.5);
  vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
  mapper->SetInputConnection(ss->GetOutputPort());
  vtkActor *actor = vtkActor::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetRepresentationToWireframe();

  // Generate some random points
62
  vtkMath::RandomSeed(1177);
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
  vtkPoints *points = vtkPoints::New();
  for (int i=0; i < 500; i++) 
    {
    points->InsertPoint(i, vtkMath::Random(2.25,7.0),
                        vtkMath::Random(1,10), vtkMath::Random(0.5,10.5));
    }
  points->SetPoint(0,4.5,5.5,5.0);
  vtkPolyData *profile = vtkPolyData::New();
  profile->SetPoints(points);
  
  vtkSelectEnclosedPoints *select = vtkSelectEnclosedPoints::New();
  select->SetInput(profile);
  select->SetSurfaceConnection(ss->GetOutputPort());
//  select->InsideOutOn();

  vtkThresholdPoints *thresh = vtkThresholdPoints::New();
  thresh->SetInputConnection(select->GetOutputPort());
  thresh->SetInputArrayToProcess(0,0,0, 
                                 vtkDataObject::FIELD_ASSOCIATION_POINTS,
                                 "SelectedPoints");
  thresh->ThresholdByUpper(0.9);

  vtkSphereSource *glyph = vtkSphereSource::New();
  vtkGlyph3D *glypher = vtkGlyph3D::New();
  glypher->SetInputConnection(thresh->GetOutputPort());
  glypher->SetSourceConnection(glyph->GetOutputPort());
  glypher->SetScaleFactor(0.25);

  vtkPolyDataMapper *pointsMapper = vtkPolyDataMapper::New();
  pointsMapper->SetInputConnection(glypher->GetOutputPort());
  
  vtkActor *pointsActor = vtkActor::New();
  pointsActor->SetMapper(pointsMapper);
  pointsActor->GetProperty()->SetColor(1,0,0);

  // Add actors
99
//  renderer->AddActor(actor);
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  renderer->AddActor(pointsActor);
  
  // Standard testing code.
  renWin->SetSize(300,300);
  renWin->Render();
  
  int retVal = vtkRegressionTestImage( renWin );
  if ( retVal == vtkRegressionTester::DO_INTERACTOR)
    {
    iren->Start();
    }

  // Cleanup
  renderer->Delete();
  renWin->Delete();
  iren->Delete();
  
  ss->Delete();
  mapper->Delete();
  actor->Delete();
  
  points->Delete();
  profile->Delete();
  thresh->Delete();
  select->Delete();
  glyph->Delete();
  glypher->Delete();
  pointsMapper->Delete();
  pointsActor->Delete();
  
  return !retVal;
}