23 vtkIdType numCells = grid->GetNumberOfCells();
26 vtkSmartPointer<vtkGenericCell> cell =
27 vtkSmartPointer<vtkGenericCell>::New();
29 for (vtkIdType i = 0; i < numCells; ++i)
31 grid->GetCell(i, cell);
32 int dim = cell->GetCellDimension();
54 vtkUnstructuredGrid* grid,
55 Eigen::Vector3d
const& p0,
56 Eigen::Vector3d
const& p1,
57 const double free_fraction,
60 std::vector<IntersectionResult> intersections;
64 Eigen::Vector3d transition_point = p0 + (p1 - p0) * free_fraction;
68 INFO(
"Adding transition point at t = {:.2f} for free fraction {:.2f}",
69 free_fraction, free_fraction);
70 intersections.push_back(
74 vtkSmartPointer<vtkGenericCell> cell =
75 vtkSmartPointer<vtkGenericCell>::New();
77 vtkNew<vtkIdList> filteredCellIds;
78 vtkNew<vtkCellLocator> locator;
79 vtkSmartPointer<vtkDataSet> cells_to_be_intersected;
82 vtkSmartPointer<vtkExtractEdges> extractEdges =
83 vtkSmartPointer<vtkExtractEdges>::New();
84 extractEdges->SetInputData(grid);
85 extractEdges->Update();
87 cells_to_be_intersected = extractEdges->GetOutput();
91 cells_to_be_intersected = grid;
93 locator->SetDataSet(cells_to_be_intersected);
94 locator->BuildLocator();
95 locator->FindCellsAlongLine(p0.data(), p1.data(), tol, filteredCellIds);
96 for (vtkIdType i = 0; i < filteredCellIds->GetNumberOfIds(); ++i)
98 vtkIdType cellId = filteredCellIds->GetId(i);
99 cells_to_be_intersected->GetCell(cellId, cell);
106 int intersected = cell->IntersectWithLine(p0.data(), p1.data(), tol, t,
109 Eigen::Vector3d x_vec(x[0], x[1], x[2]);
115 bool isDuplicate =
false;
116 for (
const auto& existing : intersections)
124 if (!isDuplicate && (t < tol || t > free_fraction))
128 result.
point = x_vec;
129 intersections.push_back(result);
132 std::sort(intersections.begin(), intersections.end(),
compareByT);
133 return intersections;
137 vtkUnstructuredGrid* grid,
138 Eigen::MatrixX3d
const& realcoords,
139 Eigen::VectorXd
const& free_fraction,
142 std::vector<std::vector<IntersectionResult>> ordered_intersections(
143 realcoords.rows() / 2);
144 assert(realcoords.rows() % 2 == 0);
145 assert(free_fraction.size() == realcoords.rows() / 2);
146 for (
int i = 0; i < realcoords.rows(); i += 2)
149 grid, realcoords.row(i), realcoords.row(i + 1),
150 free_fraction(i / 2), tol);
152 return ordered_intersections;
156 std::vector<std::vector<IntersectionResult>>
const& anchor_coords,
159 std::vector<IntersectionResult> all_intersections;
160 std::vector<int> anchorids;
161 for (
auto&& [anchor_id, intersections] :
162 ranges::views::enumerate(anchor_coords))
164 for (
auto&& [index, result] : ranges::views::enumerate(intersections))
166 if (index > 0 && index < intersections.size() - 1)
168 anchorids.push_back(anchor_id);
169 all_intersections.push_back(result);
171 anchorids.push_back(anchor_id);
172 all_intersections.push_back(result);
175 assert(all_intersections.size() == anchorids.size());
176 assert(all_intersections.size() % 2 == 0);
177 Eigen::MatrixXd realcoords(anchorids.size(), 3);
178 auto const number_of_anchors = anchorids.size() / 2;
179 Eigen::VectorXd initial_stress(number_of_anchors);
180 Eigen::VectorXd maximum_stress(number_of_anchors);
181 Eigen::VectorXd residual_stress(number_of_anchors);
182 Eigen::VectorXd cross_sectional_area(number_of_anchors);
183 Eigen::VectorXd stiffness(number_of_anchors);
184 for (std::size_t i = 0; i < all_intersections.size(); ++i)
186 realcoords.row(i).noalias() = all_intersections[i].point;
189 initial_stress(i / 2) =
191 maximum_stress(i / 2) =
193 residual_stress(i / 2) =
195 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)