VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataManifoldExtendedNeighborhood.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataManifoldExtendedNeighborhood.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.3 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23
24#include "vtkObjectFactory.h"
25#include "vtkIdList.h"
26#include "vtkCell.h"
27#include "vtkMath.h"
28
29
31
33 {
34 vtkIdType i, j, k;
35 vtkIdType p, p1, p2, outerP;
36 vtkIdType pointId;
37 double outerPoint[3], point1[3], point2[3];
38 double edgeVector[3], outerVector1[3], outerVector2[3];
39 vtkIdList *cellIds, *ptIds, *extendedStencilIds;
40 vtkCell* cell;
41 vtkPolyData* pdata = vtkPolyData::SafeDownCast(this->DataSet);
42
43 if (pdata==NULL)
44 {
45 vtkErrorMacro(<< "Input data NULL or not poly data");
46 }
47
48 pointId = this->DataSetPointId;
49
50 this->Superclass::Build();
51
52 cellIds = vtkIdList::New();
53 ptIds = vtkIdList::New();
54 extendedStencilIds = vtkIdList::New();
55
56 if (!this->IsBoundary)
57 {
58 if ((this->NPoints==3)||(this->NPoints==4))
59 {
60 for (i=0; i<this->NPoints; i++)
61 {
62 extendedStencilIds->InsertNextId(this->PointIds[i]);
63
64 p1 = this->PointIds[i];
65 p2 = this->PointIds[(i+1)%this->NPoints];
66 pdata->GetCellEdgeNeighbors (-1, p1, p2, cellIds);
67 if (cellIds->GetNumberOfIds()>1)
68 {
69 outerP = -1;
70 for (j=0; j<2; j++)
71 {
72 cell = pdata->GetCell(cellIds->GetId(j));
73 for (k=0; k<3; k++)
74 {
75 p = cell->GetPointId(k);
76 if (p!=pointId && p!=p1 && p!=p2)
77 {
78 outerP = p;
79 break;
80 }
81 }
82 if (outerP != -1)
83 {
84 break;
85 }
86 }
87
88 pdata->GetPoint(p1,point1);
89 pdata->GetPoint(p2,point2);
90 pdata->GetPoint(outerP,outerPoint);
91 edgeVector[0] = point1[0] - point2[0];
92 edgeVector[1] = point1[1] - point2[1];
93 edgeVector[2] = point1[2] - point2[2];
94 outerVector1[0] = outerPoint[0] - point1[0];
95 outerVector1[1] = outerPoint[1] - point1[1];
96 outerVector1[2] = outerPoint[2] - point1[2];
97 outerVector2[0] = outerPoint[0] - point2[0];
98 outerVector2[1] = outerPoint[1] - point2[1];
99 outerVector2[2] = outerPoint[2] - point2[2];
100
101 if (vtkMath::Dot(edgeVector,outerVector1)*vtkMath::Dot(edgeVector,outerVector2) < 0.0)
102 extendedStencilIds->InsertNextId(outerP);
103 }
104 }
105
106 this->NPoints = extendedStencilIds->GetNumberOfIds();
107 if (this->PointIds!=NULL)
108 {
109 delete[] this->PointIds;
110 this->PointIds = NULL;
111 }
112 this->PointIds = new vtkIdType[this->NPoints];
113 memcpy(this->PointIds,extendedStencilIds->GetPointer(0),this->NPoints*sizeof(vtkIdType));
114 }
115 }
116
117 cellIds->Delete();
118 ptIds->Delete();
119 extendedStencilIds->Delete();
120}
121
Apply a an extended neighborhood to the points of a manifold surface.
vtkStandardNewMacro(vtkvmtkPolyDataManifoldExtendedNeighborhood)