17 vtkIdType numCells = grid->GetNumberOfCells();
20 vtkSmartPointer<vtkGenericCell> cell =
21 vtkSmartPointer<vtkGenericCell>::New();
23 for (vtkIdType i = 0; i < numCells; ++i)
25 grid->GetCell(i, cell);
26 int dim = cell->GetCellDimension();
48 vtkUnstructuredGrid* grid,
49 Eigen::Vector3d
const& p0,
50 Eigen::Vector3d
const& p1,
51 const double free_fraction,
54 std::vector<IntersectionResult> intersections;
58 Eigen::Vector3d transition_point = p0 + (p1 - p0) * free_fraction;
62 INFO(
"Adding transition point at t = {:.2f} for free fraction {:.2f}",
63 free_fraction, free_fraction);
64 intersections.push_back(
68 vtkSmartPointer<vtkGenericCell> cell =
69 vtkSmartPointer<vtkGenericCell>::New();
71 vtkNew<vtkIdList> filteredCellIds;
72 vtkNew<vtkCellLocator> locator;
73 vtkSmartPointer<vtkDataSet> cells_to_be_intersected;
76 vtkSmartPointer<vtkExtractEdges> extractEdges =
77 vtkSmartPointer<vtkExtractEdges>::New();
78 extractEdges->SetInputData(grid);
79 extractEdges->Update();
81 cells_to_be_intersected = extractEdges->GetOutput();
85 cells_to_be_intersected = grid;
87 locator->SetDataSet(cells_to_be_intersected);
88 locator->BuildLocator();
89 locator->FindCellsAlongLine(p0.data(), p1.data(), tol, filteredCellIds);
90 for (vtkIdType i = 0; i < filteredCellIds->GetNumberOfIds(); ++i)
92 vtkIdType cellId = filteredCellIds->GetId(i);
93 cells_to_be_intersected->GetCell(cellId, cell);
100 int intersected = cell->IntersectWithLine(p0.data(), p1.data(), tol, t,
103 Eigen::Vector3d x_vec(x[0], x[1], x[2]);
109 bool isDuplicate =
false;
110 for (
const auto& existing : intersections)
118 if (!isDuplicate && (t < tol || t > free_fraction))
122 result.
point = x_vec;
123 intersections.push_back(result);
126 std::sort(intersections.begin(), intersections.end(),
compareByT);
127 return intersections;
131 vtkUnstructuredGrid* grid,
132 Eigen::MatrixX3d
const& realcoords,
133 Eigen::VectorXd
const& free_fraction,
136 std::vector<std::vector<IntersectionResult>> ordered_intersections(
137 realcoords.rows() / 2);
138 assert(realcoords.rows() % 2 == 0);
139 assert(free_fraction.size() == realcoords.rows() / 2);
140 for (
int i = 0; i < realcoords.rows(); i += 2)
143 grid, realcoords.row(i), realcoords.row(i + 1),
144 free_fraction(i / 2), tol);
146 return ordered_intersections;
150 std::vector<std::vector<IntersectionResult>>
const& anchor_coords,
153 std::vector<IntersectionResult> all_intersections;
154 std::vector<int> anchorids;
155 for (
auto&& [anchor_id, intersections] :
156 ranges::views::enumerate(anchor_coords))
158 for (
auto&& [index, result] : ranges::views::enumerate(intersections))
160 if (index > 0 && index < intersections.size() - 1)
162 anchorids.push_back(anchor_id);
163 all_intersections.push_back(result);
165 anchorids.push_back(anchor_id);
166 all_intersections.push_back(result);
169 assert(all_intersections.size() == anchorids.size());
170 assert(all_intersections.size() % 2 == 0);
171 Eigen::MatrixXd realcoords(anchorids.size(), 3);
172 auto const number_of_anchors = anchorids.size() / 2;
173 Eigen::VectorXd initial_stress(number_of_anchors);
174 Eigen::VectorXd maximum_stress(number_of_anchors);
175 Eigen::VectorXd residual_stress(number_of_anchors);
176 Eigen::VectorXd cross_sectional_area(number_of_anchors);
177 Eigen::VectorXd stiffness(number_of_anchors);
178 for (std::size_t i = 0; i < all_intersections.size(); ++i)
180 realcoords.row(i).noalias() = all_intersections[i].point;
183 initial_stress(i / 2) =
185 maximum_stress(i / 2) =
187 residual_stress(i / 2) =
189 cross_sectional_area(i / 2) =
std::vector< std::vector< IntersectionResult > > getOrderedAnchorCoords(vtkUnstructuredGrid *grid, Eigen::MatrixX3d const &realcoords, Eigen::VectorXd const &free_fraction, double const tol)
Finds intersection points of a line segment with the cells of a vtkUnstructuredGrid....
AU::ComputeNaturalCoordsResult setPhysicalPropertiesForIntersectionPoints(std::vector< std::vector< IntersectionResult > > const &anchor_coords, AU::ComputeNaturalCoordsResult const &original_anchor_data)
fills the physical properties of the intersection points based on the original anchor data.
std::vector< IntersectionResult > findOrderedIntersections(vtkUnstructuredGrid *grid, Eigen::Vector3d const &p0, Eigen::Vector3d const &p1, const double free_fraction, double const tol)