|
@@ -0,0 +1,493 @@
|
|
1
|
+// ===========================================================================
|
|
2
|
+//
|
|
3
|
+// Filename: utFEM4EllipticPDE.cpp
|
|
4
|
+//
|
|
5
|
+// Created: 08/16/12 19:49:10
|
|
6
|
+// Compiler: Tested with g++, icpc, and MSVC 2010
|
|
7
|
+//
|
|
8
|
+// Author: Trevor Irons (ti)
|
|
9
|
+//
|
|
10
|
+// Organisation: Colorado School of Mines (CSM)
|
|
11
|
+// United States Geological Survey (USGS)
|
|
12
|
+//
|
|
13
|
+// Email: tirons@mines.edu, tirons@usgs.gov
|
|
14
|
+//
|
|
15
|
+// This program is free software: you can redistribute it and/or modify
|
|
16
|
+// it under the terms of the GNU General Public License as published by
|
|
17
|
+// the Free Software Foundation, either version 3 of the License, or
|
|
18
|
+// (at your option) any later version.
|
|
19
|
+//
|
|
20
|
+// This program is distributed in the hope that it will be useful,
|
|
21
|
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+// GNU General Public License for more details.
|
|
24
|
+//
|
|
25
|
+// You should have received a copy of the GNU General Public License
|
|
26
|
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
27
|
+//
|
|
28
|
+// ===========================================================================
|
|
29
|
+
|
|
30
|
+/**
|
|
31
|
+ @file
|
|
32
|
+ @author Trevor Irons
|
|
33
|
+ @date 08/16/12
|
|
34
|
+ @version 0.0
|
|
35
|
+ **/
|
|
36
|
+
|
|
37
|
+#include "FEM4EllipticPDE.h"
|
|
38
|
+#include "vtkSphere.h"
|
|
39
|
+#include "vtkRectilinearGrid.h"
|
|
40
|
+#include "vtkFloatArray.h"
|
|
41
|
+#include <vtkIdList.h>
|
|
42
|
+#include <vtkIdTypeArray.h>
|
|
43
|
+#include <vtkCell.h>
|
|
44
|
+#include <vtkTriangleFilter.h>
|
|
45
|
+#include <vtkDataSetSurfaceFilter.h>
|
|
46
|
+#include <vtkExtractCells.h>
|
|
47
|
+#include <vtkGeometryFilter.h>
|
|
48
|
+#include <vtkUnstructuredGrid.h>
|
|
49
|
+#include <vtkExtractEdges.h>
|
|
50
|
+#include <vtkImplicitDataSet.h>
|
|
51
|
+
|
|
52
|
+// debugging stuff
|
|
53
|
+#include <vtkDataSetMapper.h>
|
|
54
|
+#include <vtkSelectionNode.h>
|
|
55
|
+#include <vtkExtractSelection.h>
|
|
56
|
+#include <vtkSelection.h>
|
|
57
|
+#include <vtkVertexGlyphFilter.h>
|
|
58
|
+
|
|
59
|
+#define RENDERTEST
|
|
60
|
+//#define CONNECTTEST
|
|
61
|
+
|
|
62
|
+#ifdef RENDERTEST
|
|
63
|
+#include "vtkRectilinearGridGeometryFilter.h"
|
|
64
|
+#include "vtkRectilinearGridOutlineFilter.h"
|
|
65
|
+#include "vtkPolyDataMapper.h"
|
|
66
|
+#include "vtkActor.h"
|
|
67
|
+#include "vtkRenderWindowInteractor.h"
|
|
68
|
+#include "vtkRenderer.h"
|
|
69
|
+#include "vtkRenderWindow.h"
|
|
70
|
+#include "vtkCamera.h"
|
|
71
|
+#include "vtkProperty.h"
|
|
72
|
+#include <vtkDataSetMapper.h>
|
|
73
|
+#include <vtkSelectionNode.h>
|
|
74
|
+#include <vtkSelection.h>
|
|
75
|
+#include <vtkExtractSelection.h>
|
|
76
|
+#include <vtkExtractEdges.h>
|
|
77
|
+#include <vtkVertexGlyphFilter.h>
|
|
78
|
+#include <vtkTriangleFilter.h>
|
|
79
|
+#include <vtkImplicitHalo.h>
|
|
80
|
+#endif
|
|
81
|
+
|
|
82
|
+#ifdef CONNECTTEST
|
|
83
|
+#include <vtkVersion.h>
|
|
84
|
+#include <vtkSmartPointer.h>
|
|
85
|
+#include <vtkPolyData.h>
|
|
86
|
+#include <vtkCellData.h>
|
|
87
|
+#include <vtkDoubleArray.h>
|
|
88
|
+#include <vtkDataSet.h>
|
|
89
|
+#include <vtkSphereSource.h>
|
|
90
|
+#include <vtkTriangleFilter.h>
|
|
91
|
+#include <vtkExtractEdges.h>
|
|
92
|
+#include <vtkDataSetMapper.h>
|
|
93
|
+#include <vtkActor.h>
|
|
94
|
+#include <vtkRenderWindow.h>
|
|
95
|
+#include <vtkRenderer.h>
|
|
96
|
+#include <vtkRenderWindowInteractor.h>
|
|
97
|
+#include <vtkSelectionNode.h>
|
|
98
|
+#include <vtkSelection.h>
|
|
99
|
+#include <vtkExtractSelection.h>
|
|
100
|
+#include <vtkProperty.h>
|
|
101
|
+#include <vtkVertexGlyphFilter.h>
|
|
102
|
+#endif
|
|
103
|
+
|
|
104
|
+vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkDataSet> mesh, int id);
|
|
105
|
+vtkSmartPointer<vtkIdList> GetConnectedVertices2(vtkSmartPointer<vtkPolyData> mesh, int id);
|
|
106
|
+
|
|
107
|
+// This function is copyright (C) 2012 Joeseph Cappriotti
|
|
108
|
+vtkSmartPointer<vtkIdList> GetConnectedPoints(int id0, vtkSmartPointer<vtkDataSet> grid);
|
|
109
|
+
|
|
110
|
+using namespace Lemma;
|
|
111
|
+
|
|
112
|
+int main() {
|
|
113
|
+
|
|
114
|
+ // Define Sigma term
|
|
115
|
+ // Defaults to 1, (Poisson equation)
|
|
116
|
+
|
|
117
|
+ // Define source (G) term
|
|
118
|
+ //vtkSphere *Sphere = vtkSphere::New();
|
|
119
|
+ vtkImplicitHalo *Sphere = vtkImplicitHalo::New();
|
|
120
|
+ Sphere->SetCenter (0, 0, 0);
|
|
121
|
+ Sphere->SetRadius (60);
|
|
122
|
+ Sphere->SetFadeOut(.95);
|
|
123
|
+
|
|
124
|
+ ////////////////////////////////////////////
|
|
125
|
+ // Define solution mesh
|
|
126
|
+
|
|
127
|
+ // Create a rectilinear grid by defining three arrays specifying the
|
|
128
|
+ // coordinates in the x-y-z directions.
|
|
129
|
+
|
|
130
|
+ int nx = 160;
|
|
131
|
+ double dx = 2.5;
|
|
132
|
+ double ox = -200;
|
|
133
|
+ vtkFloatArray *xCoords = vtkFloatArray::New();
|
|
134
|
+ for (int i=0; i<nx+1; i++) xCoords->InsertNextValue(ox + i*dx);
|
|
135
|
+
|
|
136
|
+ int ny = 160;
|
|
137
|
+ double dy = 2.5;
|
|
138
|
+ double oy = -200;
|
|
139
|
+ vtkFloatArray *yCoords = vtkFloatArray::New();
|
|
140
|
+ for (int i=0; i<ny+1; i++) yCoords->InsertNextValue(oy + i*dy);
|
|
141
|
+
|
|
142
|
+ int nz = 160;
|
|
143
|
+ double dz = 2.5;
|
|
144
|
+ double oz = -200;
|
|
145
|
+ vtkFloatArray *zCoords = vtkFloatArray::New();
|
|
146
|
+ for (int i=0; i<nz+1; i++) zCoords->InsertNextValue(oz + i*dz);
|
|
147
|
+
|
|
148
|
+ vtkRectilinearGrid *rGrid = vtkRectilinearGrid::New();
|
|
149
|
+ rGrid->SetDimensions(nx+1, ny+1, nz+1);
|
|
150
|
+ rGrid->SetExtent(0, nx, 0, ny, 0, nz);
|
|
151
|
+ rGrid->SetXCoordinates(xCoords);
|
|
152
|
+ rGrid->SetYCoordinates(yCoords);
|
|
153
|
+ rGrid->SetZCoordinates(zCoords);
|
|
154
|
+
|
|
155
|
+ vtkRectilinearGrid *sigGrid = vtkRectilinearGrid::New();
|
|
156
|
+ sigGrid->SetDimensions(nx+1, ny+1, nz+1);
|
|
157
|
+ sigGrid->SetExtent(0, nx, 0, ny, 0, nz);
|
|
158
|
+ sigGrid->SetXCoordinates(xCoords);
|
|
159
|
+ sigGrid->SetYCoordinates(yCoords);
|
|
160
|
+ sigGrid->SetZCoordinates(zCoords);
|
|
161
|
+ vtkDoubleArray *sigArray = vtkDoubleArray::New();
|
|
162
|
+ sigArray->SetNumberOfComponents(1);
|
|
163
|
+ for (int ii=0; ii<(nx+1)*(ny+1)*(nz+1); ++ii) {
|
|
164
|
+ sigArray->InsertTuple1(ii, 1.);
|
|
165
|
+ }
|
|
166
|
+ sigArray->SetName("sigma");
|
|
167
|
+ sigGrid->GetPointData()->AddArray(sigArray);
|
|
168
|
+ sigGrid->GetPointData()->SetScalars(sigArray);
|
|
169
|
+
|
|
170
|
+ vtkImplicitDataSet* implSigma = vtkImplicitDataSet::New();
|
|
171
|
+ implSigma->SetDataSet(sigGrid);
|
|
172
|
+ implSigma->SetOutValue(0.);
|
|
173
|
+ implSigma->SetOutGradient(0., 0., 0.);
|
|
174
|
+
|
|
175
|
+ FEM4EllipticPDE *Solver = FEM4EllipticPDE::New();
|
|
176
|
+ Solver->SetGFunction(Sphere);
|
|
177
|
+ //Solver->SetSigmaFunction(implSigma);
|
|
178
|
+ Solver->SetBoundaryStep(.5);
|
|
179
|
+ Solver->SetGrid(rGrid);
|
|
180
|
+ Solver->Solve("FEM_results.vtr");
|
|
181
|
+
|
|
182
|
+ vtkXMLDataSetWriter *Writer = vtkXMLDataSetWriter::New();
|
|
183
|
+ Writer->SetInputData(sigGrid);
|
|
184
|
+ std::string fname("sigma.vtr");
|
|
185
|
+ //Writer->Update();
|
|
186
|
+ //fname.append( Writer->GetDefaultFileExtension() );
|
|
187
|
+ Writer->SetFileName(fname.c_str());
|
|
188
|
+ Writer->Write();
|
|
189
|
+ Writer->Delete();
|
|
190
|
+
|
|
191
|
+ // Clean up
|
|
192
|
+ Sphere->Delete();
|
|
193
|
+ Solver->Delete();
|
|
194
|
+ rGrid->Delete();
|
|
195
|
+ xCoords->Delete();
|
|
196
|
+ yCoords->Delete();
|
|
197
|
+ zCoords->Delete();
|
|
198
|
+
|
|
199
|
+}
|
|
200
|
+
|
|
201
|
+// This function is copyright (C) 2012 Joeseph Cappriotti
|
|
202
|
+vtkSmartPointer<vtkIdList> GetConnectedPoints(int id0, vtkSmartPointer<vtkDataSet> grid){
|
|
203
|
+ vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
|
|
204
|
+ vtkSmartPointer<vtkIdList> cellList = vtkSmartPointer<vtkIdList>::New();
|
|
205
|
+ grid->GetPointCells(id0, cellList);
|
|
206
|
+ for(int i=0;i<cellList->GetNumberOfIds();++i){
|
|
207
|
+ vtkCell* cell = grid->GetCell(cellList->GetId(i));
|
|
208
|
+ if(cell->GetNumberOfEdges() > 0){
|
|
209
|
+ for(int j=0; j<cell->GetNumberOfEdges(); ++j){
|
|
210
|
+ vtkCell* edge = cell->GetEdge(j);
|
|
211
|
+ vtkIdList* edgePoints=edge->GetPointIds();
|
|
212
|
+ if(edgePoints->GetId(0)==id0){
|
|
213
|
+ pointIds->InsertUniqueId(edgePoints->GetId(1));
|
|
214
|
+ }else if(edgePoints->GetId(1)==id0){
|
|
215
|
+ pointIds->InsertUniqueId(edgePoints->GetId(0));
|
|
216
|
+ }
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+ }
|
|
220
|
+ return pointIds;
|
|
221
|
+}
|
|
222
|
+
|
|
223
|
+vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkDataSet> mesh, int id) {
|
|
224
|
+
|
|
225
|
+ std::cout << "number of points " << mesh->GetNumberOfPoints() << std::endl;
|
|
226
|
+ std::cout << "number of cells " << mesh->GetNumberOfCells() << std::endl;
|
|
227
|
+
|
|
228
|
+ vtkSmartPointer<vtkIdList> connectedVertices = vtkSmartPointer<vtkIdList>::New();
|
|
229
|
+
|
|
230
|
+ //get all cells that vertex 'id' is a part of
|
|
231
|
+ vtkSmartPointer<vtkIdList> cellIdList = vtkSmartPointer<vtkIdList>::New();
|
|
232
|
+ mesh->GetPointCells(id, cellIdList); // cells using point
|
|
233
|
+ //mesh->GetCellPoints(id, cellIdList); // points defining cell
|
|
234
|
+
|
|
235
|
+ cout << "Vertex " << id << " is used in cell(s) ";
|
|
236
|
+ for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
|
|
237
|
+ cout << cellIdList->GetId(i) << ", ";
|
|
238
|
+ }
|
|
239
|
+ cout << endl;
|
|
240
|
+
|
|
241
|
+ // TODO this is where things don't work
|
|
242
|
+ // for each cell, figure out what vertices are connected
|
|
243
|
+ for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
|
|
244
|
+
|
|
245
|
+ cout << "\tcell id " << i << " : " << cellIdList->GetId(i) << endl;
|
|
246
|
+ std::cout << "\tcell has " << mesh->GetCell(i)->GetNumberOfPoints() << " points\n";
|
|
247
|
+
|
|
248
|
+ vtkExtractCells *Cell = vtkExtractCells::New();
|
|
249
|
+ Cell->SetInputData(mesh);
|
|
250
|
+ Cell->AddCellRange(i, i);
|
|
251
|
+ Cell->Update();
|
|
252
|
+
|
|
253
|
+ //std::cout << *Cell->GetOutput() << std::endl;
|
|
254
|
+
|
|
255
|
+ // extract surface
|
|
256
|
+ vtkDataSetSurfaceFilter *surf = vtkDataSetSurfaceFilter::New();
|
|
257
|
+ surf->UseStripsOn();
|
|
258
|
+ surf->SetInputData(Cell->GetOutput());
|
|
259
|
+ surf->Update();
|
|
260
|
+
|
|
261
|
+ //std::cout << *surf->GetOutput() << std::endl;
|
|
262
|
+
|
|
263
|
+ vtkSmartPointer<vtkTriangleFilter> triangleFilter =
|
|
264
|
+ vtkSmartPointer<vtkTriangleFilter>::New();
|
|
265
|
+ triangleFilter->SetInputData( surf->GetOutput() );
|
|
266
|
+ triangleFilter->Update();
|
|
267
|
+
|
|
268
|
+ vtkSmartPointer<vtkExtractEdges> extractEdges =
|
|
269
|
+ vtkSmartPointer<vtkExtractEdges>::New();
|
|
270
|
+ extractEdges->SetInputConnection(triangleFilter->GetOutputPort());
|
|
271
|
+ extractEdges->Update();
|
|
272
|
+
|
|
273
|
+ vtkSmartPointer<vtkPolyData> pmesh = extractEdges->GetOutput();
|
|
274
|
+ //vtkSmartPointer<vtkPolyData> pmesh = triangleFilter->GetOutput();
|
|
275
|
+ //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(surf->GetOutput(), id);
|
|
276
|
+//
|
|
277
|
+// //vtkSmartPointer<vtkIdTypeArray> ids =
|
|
278
|
+// //vtkSmartPointer<vtkIdTypeArray>::New();
|
|
279
|
+// //ids->SetNumberOfComponents(1);
|
|
280
|
+//
|
|
281
|
+ vtkSmartPointer<vtkIdList> pointIdList = vtkSmartPointer<vtkIdList>::New();
|
|
282
|
+ //mesh->GetPointCells(cellIdList->GetId(i), pointIdList); // returns cells using point
|
|
283
|
+ mesh->GetCellPoints(cellIdList->GetId(i), pointIdList); // points defining cell
|
|
284
|
+
|
|
285
|
+ //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(pmesh, id);
|
|
286
|
+ vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(surf->GetOutput(), id);
|
|
287
|
+ //vtkSmartPointer<vtkIdList> pconnectedVertices = GetConnectedVertices2(triangleFilter->GetOutput(), 1);
|
|
288
|
+ std::cout << "\tPoly Connected vertices: ";
|
|
289
|
+ for(vtkIdType ip = 0; ip < pconnectedVertices->GetNumberOfIds(); ip++) {
|
|
290
|
+ std::cout << pconnectedVertices->GetId(ip) << " ";
|
|
291
|
+ //ids->InsertNextValue(connectedVertices->GetId(i));
|
|
292
|
+ connectedVertices->InsertNextId( pointIdList->GetId( pconnectedVertices->GetId(ip) ) );
|
|
293
|
+ }
|
|
294
|
+ std::cout << std::endl;
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+ cout << "\tcell " << i << " contains these points ";
|
|
298
|
+ for(vtkIdType ii = 0; ii < pointIdList->GetNumberOfIds(); ii++) {
|
|
299
|
+ cout << pointIdList->GetId(ii) << ", ";
|
|
300
|
+ }
|
|
301
|
+ cout << endl;
|
|
302
|
+
|
|
303
|
+ /*
|
|
304
|
+ cout << "\tEnd points are " << pointIdList->GetId(0) << " and " << pointIdList->GetId(1) << endl;
|
|
305
|
+
|
|
306
|
+ if(pointIdList->GetId(0) != id) {
|
|
307
|
+ //cout << "Connected to " << pointIdList->GetId(0) << endl;
|
|
308
|
+ connectedVertices->InsertNextId(pointIdList->GetId(0));
|
|
309
|
+ } else {
|
|
310
|
+ //cout << "Connected to " << pointIdList->GetId(1) << endl;
|
|
311
|
+ connectedVertices->InsertNextId(pointIdList->GetId(1));
|
|
312
|
+ }
|
|
313
|
+ */
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+ #ifdef RENDERTEST
|
|
317
|
+ vtkSmartPointer<vtkDataSetMapper> sphereMapper =
|
|
318
|
+ vtkSmartPointer<vtkDataSetMapper>::New();
|
|
319
|
+ sphereMapper->SetInputConnection(extractEdges->GetOutputPort());
|
|
320
|
+ vtkSmartPointer<vtkActor> sphereActor =
|
|
321
|
+ vtkSmartPointer<vtkActor>::New();
|
|
322
|
+ sphereActor->SetMapper(sphereMapper);
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+ vtkSmartPointer<vtkIdTypeArray> ids =
|
|
326
|
+ vtkSmartPointer<vtkIdTypeArray>::New();
|
|
327
|
+ ids->SetNumberOfComponents(1);
|
|
328
|
+
|
|
329
|
+ std::cout << "RENDERTEST Connected vertices: ";
|
|
330
|
+ for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); i++) {
|
|
331
|
+ std::cout << connectedVertices->GetId(i) << " ";
|
|
332
|
+ ids->InsertNextValue(connectedVertices->GetId(i));
|
|
333
|
+ }
|
|
334
|
+ std::cout << std::endl;
|
|
335
|
+
|
|
336
|
+ vtkSmartPointer<vtkDataSetMapper> connectedVertexMapper =
|
|
337
|
+ vtkSmartPointer<vtkDataSetMapper>::New();
|
|
338
|
+
|
|
339
|
+ {
|
|
340
|
+ vtkSmartPointer<vtkSelectionNode> selectionNode =
|
|
341
|
+ vtkSmartPointer<vtkSelectionNode>::New();
|
|
342
|
+ selectionNode->SetFieldType(vtkSelectionNode::POINT);
|
|
343
|
+ selectionNode->SetContentType(vtkSelectionNode::INDICES);
|
|
344
|
+ selectionNode->SetSelectionList(ids);
|
|
345
|
+
|
|
346
|
+ vtkSmartPointer<vtkSelection> selection =
|
|
347
|
+ vtkSmartPointer<vtkSelection>::New();
|
|
348
|
+ selection->AddNode(selectionNode);
|
|
349
|
+
|
|
350
|
+ vtkSmartPointer<vtkExtractSelection> extractSelection =
|
|
351
|
+ vtkSmartPointer<vtkExtractSelection>::New();
|
|
352
|
+
|
|
353
|
+ extractSelection->SetInputConnection(0, extractEdges->GetOutputPort());
|
|
354
|
+ extractSelection->SetInputData(1, selection);
|
|
355
|
+ extractSelection->Update();
|
|
356
|
+
|
|
357
|
+ vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
|
|
358
|
+ vtkSmartPointer<vtkVertexGlyphFilter>::New();
|
|
359
|
+ glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
|
|
360
|
+ glyphFilter->Update();
|
|
361
|
+
|
|
362
|
+ connectedVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
|
|
363
|
+ }
|
|
364
|
+
|
|
365
|
+ vtkSmartPointer<vtkActor> connectedVertexActor =
|
|
366
|
+ vtkSmartPointer<vtkActor>::New();
|
|
367
|
+ connectedVertexActor->SetMapper(connectedVertexMapper);
|
|
368
|
+ connectedVertexActor->GetProperty()->SetColor(1,0,0);
|
|
369
|
+ connectedVertexActor->GetProperty()->SetPointSize(5);
|
|
370
|
+
|
|
371
|
+ vtkSmartPointer<vtkDataSetMapper> queryVertexMapper =
|
|
372
|
+ vtkSmartPointer<vtkDataSetMapper>::New();
|
|
373
|
+
|
|
374
|
+ {
|
|
375
|
+ vtkSmartPointer<vtkIdTypeArray> ids =
|
|
376
|
+ vtkSmartPointer<vtkIdTypeArray>::New();
|
|
377
|
+ ids->SetNumberOfComponents(1);
|
|
378
|
+ ids->InsertNextValue(id);
|
|
379
|
+
|
|
380
|
+ vtkSmartPointer<vtkSelectionNode> selectionNode =
|
|
381
|
+ vtkSmartPointer<vtkSelectionNode>::New();
|
|
382
|
+ selectionNode->SetFieldType(vtkSelectionNode::POINT);
|
|
383
|
+ selectionNode->SetContentType(vtkSelectionNode::INDICES);
|
|
384
|
+ selectionNode->SetSelectionList(ids);
|
|
385
|
+
|
|
386
|
+ vtkSmartPointer<vtkSelection> selection =
|
|
387
|
+ vtkSmartPointer<vtkSelection>::New();
|
|
388
|
+ selection->AddNode(selectionNode);
|
|
389
|
+
|
|
390
|
+ vtkSmartPointer<vtkExtractSelection> extractSelection =
|
|
391
|
+ vtkSmartPointer<vtkExtractSelection>::New();
|
|
392
|
+
|
|
393
|
+ extractSelection->SetInputConnection(0, extractEdges->GetOutputPort());
|
|
394
|
+ extractSelection->SetInputData(1, selection);
|
|
395
|
+ extractSelection->Update();
|
|
396
|
+
|
|
397
|
+ vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
|
|
398
|
+ vtkSmartPointer<vtkVertexGlyphFilter>::New();
|
|
399
|
+ glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
|
|
400
|
+ glyphFilter->Update();
|
|
401
|
+
|
|
402
|
+ queryVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
|
|
403
|
+ }
|
|
404
|
+
|
|
405
|
+ vtkSmartPointer<vtkActor> queryVertexActor =
|
|
406
|
+ vtkSmartPointer<vtkActor>::New();
|
|
407
|
+ queryVertexActor->SetMapper(queryVertexMapper);
|
|
408
|
+ queryVertexActor->GetProperty()->SetColor(0,1,0);
|
|
409
|
+ queryVertexActor->GetProperty()->SetPointSize(5);
|
|
410
|
+
|
|
411
|
+ // Create the usual rendering stuff.
|
|
412
|
+ vtkRenderer *renderer = vtkRenderer::New();
|
|
413
|
+ vtkRenderWindow *renWin = vtkRenderWindow::New();
|
|
414
|
+ renWin->AddRenderer(renderer);
|
|
415
|
+ vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
|
|
416
|
+ iren->SetRenderWindow(renWin);
|
|
417
|
+
|
|
418
|
+ renderer->AddActor(queryVertexActor);
|
|
419
|
+ renderer->AddActor(connectedVertexActor);
|
|
420
|
+ renderer->AddActor(sphereActor);
|
|
421
|
+
|
|
422
|
+ //renderer->AddActor(wireActor);
|
|
423
|
+ //renderer->AddActor(owireActor);
|
|
424
|
+ renderer->SetBackground(.3,.2,.1);
|
|
425
|
+ renderer->ResetCamera();
|
|
426
|
+ renderer->GetActiveCamera()->Elevation(-150.0);
|
|
427
|
+ renderer->GetActiveCamera()->Azimuth(0.0);
|
|
428
|
+ renderer->GetActiveCamera()->Roll(0.0);
|
|
429
|
+ //renderer->GetActiveCamera()->Pitch(-45.0);
|
|
430
|
+ renderer->GetActiveCamera()->Zoom(1.0);
|
|
431
|
+
|
|
432
|
+ renWin->SetSize(300,300);
|
|
433
|
+
|
|
434
|
+ // interact with data
|
|
435
|
+ renWin->Render();
|
|
436
|
+ iren->Start();
|
|
437
|
+
|
|
438
|
+ // clean up rendering stuff
|
|
439
|
+ //plane->Delete();
|
|
440
|
+ //rgridMapper->Delete();
|
|
441
|
+ //wireActor->Delete();
|
|
442
|
+ //owireActor->Delete();
|
|
443
|
+ //outline->Delete();
|
|
444
|
+ //outlineMapper->Delete();
|
|
445
|
+ renderer->Delete();
|
|
446
|
+ renWin->Delete();
|
|
447
|
+ iren->Delete();
|
|
448
|
+ #endif // RENDERTEST
|
|
449
|
+
|
|
450
|
+ surf->Delete();
|
|
451
|
+ Cell->Delete();
|
|
452
|
+ }
|
|
453
|
+
|
|
454
|
+ return connectedVertices;
|
|
455
|
+}
|
|
456
|
+
|
|
457
|
+// from http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity
|
|
458
|
+vtkSmartPointer<vtkIdList> GetConnectedVertices2(vtkSmartPointer<vtkPolyData> mesh, int id) {
|
|
459
|
+
|
|
460
|
+ std::cout << "mesh points " << mesh->GetNumberOfPoints() << std::endl;
|
|
461
|
+
|
|
462
|
+ vtkSmartPointer<vtkIdList> connectedVertices =
|
|
463
|
+ vtkSmartPointer<vtkIdList>::New();
|
|
464
|
+
|
|
465
|
+ //get all cells that vertex 'id' is a part of
|
|
466
|
+ vtkSmartPointer<vtkIdList> cellIdList =
|
|
467
|
+ vtkSmartPointer<vtkIdList>::New();
|
|
468
|
+ mesh->GetPointCells(id, cellIdList);
|
|
469
|
+
|
|
470
|
+ /*
|
|
471
|
+ for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
|
|
472
|
+ cout << cellIdList->GetId(i) << ", ";
|
|
473
|
+ }
|
|
474
|
+ cout << endl;
|
|
475
|
+ */
|
|
476
|
+
|
|
477
|
+ for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++) {
|
|
478
|
+ //cout << "id " << i << " : " << cellIdList->GetId(i) << endl;
|
|
479
|
+
|
|
480
|
+ vtkSmartPointer<vtkIdList> pointIdList =
|
|
481
|
+ vtkSmartPointer<vtkIdList>::New();
|
|
482
|
+ mesh->GetCellPoints(cellIdList->GetId(i), pointIdList);
|
|
483
|
+ //cout << "End points are " << pointIdList->GetId(0) << " and " << pointIdList->GetId(1) << endl;
|
|
484
|
+ if(pointIdList->GetId(0) != id) {
|
|
485
|
+ //cout << "Connected to " << pointIdList->GetId(0) << endl;
|
|
486
|
+ connectedVertices->InsertNextId(pointIdList->GetId(0));
|
|
487
|
+ } else {
|
|
488
|
+ //cout << "Connected to " << pointIdList->GetId(1) << endl;
|
|
489
|
+ connectedVertices->InsertNextId(pointIdList->GetId(1));
|
|
490
|
+ }
|
|
491
|
+ }
|
|
492
|
+ return connectedVertices;
|
|
493
|
+}
|