MCPcopy Create free account
hub / github.com/SimVascular/SimVascular / ConvertFaceIdsToNodeIds

Function ConvertFaceIdsToNodeIds

Code/Source/PythonAPI/Vmtk_PyModule.cxx:99–167  ·  view source on GitHub ↗

------------------------- ConvertFaceIdsToNodeIds ------------------------- Convert a list of face IDs to node IDs. The face ID is mapped to the node ID that is closest to the face center.

Source from the content-addressed store, hash-verified

97// The face ID is mapped to the node ID that is closest to the face center.
98//
99static std::vector<int>
100ConvertFaceIdsToNodeIds(PyUtilApiFunction& api, vtkPolyData* polydata, std::vector<int>& faceIds)
101{
102 std::vector<int> nodeIds;
103 int numCells = polydata->GetNumberOfCells();
104 auto points = polydata->GetPoints();
105 auto cellData = vtkIntArray::SafeDownCast(polydata->GetCellData()->GetArray("ModelFaceID"));
106 if (cellData == nullptr) {
107 api.error("No 'ModelFaceID' data found for the input polydata.");
108 return nodeIds;
109 }
110
111 // Find the node ID for each face ID.
112 //
113 for (auto const& faceID : faceIds) {
114 int cellID = -1;
115 std::vector<int> cellIds;
116 for (int i = 0; i < numCells; i++) {
117 if (cellData->GetValue(i) == faceID) {
118 cellIds.push_back(i);
119 }
120 }
121 if (cellIds.size() == 0) {
122 api.error("No node found for face ID '" + std::to_string(faceID) + "'.");
123 return nodeIds;
124 }
125
126 // Get face center.
127 std::vector<int> faceNodeIds;
128 int numFacePts = 0;
129 double point[3];
130 double center[3] = {0.0, 0.0, 0.0};
131 for (auto const& cellID : cellIds) {
132 auto cell = polydata->GetCell(cellID);
133 auto ids = cell->GetPointIds();
134 for (vtkIdType i = 0; i < ids->GetNumberOfIds(); i++) {
135 int id = ids->GetId(i);
136 faceNodeIds.push_back(id);
137 points->GetPoint(id, point);
138 center[0] += point[0];
139 center[1] += point[1];
140 center[2] += point[2];
141 numFacePts += 1;
142 }
143 }
144
145 center[0] /= numFacePts;
146 center[1] /= numFacePts;
147 center[2] /= numFacePts;
148
149 // Find the closest node.
150 double min_d = 1e6;
151 int min_id = -1;
152 for (auto const& id : faceNodeIds) {
153 points->GetPoint(id, point);
154 auto dx = point[0] - center[0];
155 auto dy = point[1] - center[1];
156 auto dz = point[2] - center[2];

Callers 1

Vmtk_centerlinesFunction · 0.85

Calls 4

errorMethod · 0.80
sizeMethod · 0.80
GetCellMethod · 0.80
GetPointMethod · 0.45

Tested by

no test coverage detected