VMTK
Loading...
Searching...
No Matches
vtkvmtkConcaveAnnularCapPolyData.cxx File Reference
#include "vtkvmtkConcaveAnnularCapPolyData.h"
#include "vtkvmtkPolyDataBoundaryExtractor.h"
#include "vtkvmtkBoundaryLabels.h"
#include "vtkNew.h"
#include "vtkvmtkBoundaryReferenceSystems.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkPolygon.h"
#include "vtkPolyLine.h"
#include "vtkIdTypeArray.h"
#include "vtkIntArray.h"
#include "vtkMath.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkVersion.h"
#include <iostream>
#include <limits>
#include <vector>
#include <utility>
Include dependency graph for vtkvmtkConcaveAnnularCapPolyData.cxx:

Go to the source code of this file.

Typedefs

typedef pair< vtkIdType, vtkIdType > IdPair

Functions

 vtkStandardNewMacro (vtkvmtkConcaveAnnularCapPolyData)
vector< IdPair > build_closest_pairs (vtkSmartPointer< vtkPoints > barycenters, vtkIdList *boundaryIds)
IdPair find_closest_points (vtkPolyData *points, vtkSmartPointer< vtkIdList > pointIds0, vtkSmartPointer< vtkIdList > pointIds1)

Typedef Documentation

◆ IdPair

typedef pair<vtkIdType,vtkIdType> IdPair

Definition at line 109 of file vtkvmtkConcaveAnnularCapPolyData.cxx.

Function Documentation

◆ vtkStandardNewMacro()

vtkStandardNewMacro ( vtkvmtkConcaveAnnularCapPolyData )

◆ build_closest_pairs()

vector< IdPair > build_closest_pairs ( vtkSmartPointer< vtkPoints > barycenters,
vtkIdList * boundaryIds )

Definition at line 111 of file vtkvmtkConcaveAnnularCapPolyData.cxx.

112{
113 int numberOfBoundaries = barycenters->GetNumberOfPoints();
114
115 vector<IdPair> pairs;
116
117 // Allocate array for marking visited boundaries
118 vector<bool> visited(numberOfBoundaries);
119 if (boundaryIds)
120 {
121 // Skip ids not in boundaryIds list
122 for (int i=0; i<numberOfBoundaries; i++)
123 {
124 visited[i] = true;
125 }
126 for (int i=0; i<boundaryIds->GetNumberOfIds(); i++)
127 {
128 visited[boundaryIds->GetId(i)] = false;
129 }
130 }
131 else
132 {
133 // Skip nothing
134 for (int i=0; i<numberOfBoundaries; i++)
135 {
136 visited[i] = false;
137 }
138 }
139
140 // Find the closest pairs of boundaries by comparing barycenter distances
141 for (int i=0; i<numberOfBoundaries; i++)
142 {
143 if (visited[i])
144 {
145 continue;
146 }
147 double barycenter[3];
148 barycenters->GetPoint(i, barycenter);
149
150 // Find which boundary j is closest to boundary i
151 double minBarycenterDistance2 = std::numeric_limits<double>::max();
152 vtkIdType closest = -1;
153 for (int j=i+1; j<numberOfBoundaries; j++)
154 {
155 if (visited[j])
156 {
157 continue;
158 }
159
160 // Fetch barycenter j
161 double currentBarycenter[3];
162 barycenters->GetPoint(j, currentBarycenter);
163
164 // Pick boundary j if the distance to boundary i is the smallest so far
165 double distance2 = vtkMath::Distance2BetweenPoints(barycenter,currentBarycenter);
166 if (distance2 < minBarycenterDistance2)
167 {
168 minBarycenterDistance2 = distance2;
169 closest = j;
170 }
171 }
172
173 // Mark as visited and add pair
174 //std::cout << "i, closest = " << i << ", " << closest << std::endl;
175 visited[i] = true;
176 visited[closest] = true;
177 pairs.push_back(make_pair(i, closest));
178 }
179 return pairs;
180}

◆ find_closest_points()

IdPair find_closest_points ( vtkPolyData * points,
vtkSmartPointer< vtkIdList > pointIds0,
vtkSmartPointer< vtkIdList > pointIds1 )

Definition at line 182 of file vtkvmtkConcaveAnnularCapPolyData.cxx.

183{
184 vtkIdType i0 = -1;
185 vtkIdType i1 = -1;
186 double minPointDistance2 = std::numeric_limits<double>::max();
187 int n0 = pointIds0->GetNumberOfIds();
188 int n1 = pointIds1->GetNumberOfIds();
189 for (int j0=0; j0<n0; j0++)
190 {
191 double point0[3];
192 points->GetPoint(pointIds0->GetId(j0), point0);
193 for (int j1=0; j1<n1; j1++)
194 {
195 double point1[3];
196 points->GetPoint(pointIds1->GetId(j1), point1);
197 double distance2 = vtkMath::Distance2BetweenPoints(point0, point1);
198 if (distance2 < minPointDistance2)
199 {
200 i0 = j0;
201 i1 = j1;
202 minPointDistance2 = distance2;
203 }
204 }
205 }
206 return make_pair(i0, i1);
207}